Merge pull request #10557 from abcdefg30/queueCleanup
More cleanup in the production logic
This commit is contained in:
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public override object Create(ActorInitializer init) { return new ClassicProductionQueue(init, this); }
|
||||
}
|
||||
|
||||
public class ClassicProductionQueue : ProductionQueue, ISync
|
||||
public class ClassicProductionQueue : ProductionQueue
|
||||
{
|
||||
static readonly ActorInfo[] NoItems = { };
|
||||
|
||||
@@ -85,14 +85,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
protected override bool BuildUnit(string name)
|
||||
protected override bool BuildUnit(ActorInfo unit)
|
||||
{
|
||||
// Find a production structure to build this actor
|
||||
var ai = self.World.Map.Rules.Actors[name];
|
||||
var bi = ai.TraitInfoOrDefault<BuildableInfo>();
|
||||
var bi = unit.TraitInfo<BuildableInfo>();
|
||||
|
||||
// Some units may request a specific production type, which is ignored if the AllTech cheat is enabled
|
||||
var type = bi == null || developerMode.AllTech ? Info.Type : bi.BuildAtProductionType ?? Info.Type;
|
||||
var type = developerMode.AllTech ? Info.Type : bi.BuildAtProductionType ?? Info.Type;
|
||||
|
||||
var producers = self.World.ActorsWithTrait<Production>()
|
||||
.Where(x => x.Actor.Owner == self.Owner
|
||||
@@ -102,13 +101,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (!producers.Any())
|
||||
{
|
||||
CancelProduction(name, 1);
|
||||
CancelProduction(unit.Name, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var p in producers.Where(p => !p.Actor.IsDisabled()))
|
||||
{
|
||||
if (p.Trait.Produce(p.Actor, ai, p.Trait.Faction))
|
||||
if (p.Trait.Produce(p.Actor, unit, p.Trait.Faction))
|
||||
{
|
||||
FinishProduction();
|
||||
return true;
|
||||
@@ -120,19 +119,19 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override int GetBuildTime(string unitString)
|
||||
{
|
||||
var ai = self.World.Map.Rules.Actors[unitString];
|
||||
var bi = ai.TraitInfoOrDefault<BuildableInfo>();
|
||||
if (bi == null)
|
||||
return 0;
|
||||
return GetBuildTime(self.World.Map.Rules.Actors[unitString]);
|
||||
}
|
||||
|
||||
public override int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
|
||||
{
|
||||
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
|
||||
return 0;
|
||||
|
||||
var time = (int)(ai.GetBuildTime() * Info.BuildSpeed);
|
||||
var time = (int)(unit.GetBuildTime() * Info.BuildSpeed);
|
||||
|
||||
if (info.SpeedUp)
|
||||
{
|
||||
var type = bi.BuildAtProductionType ?? info.Type;
|
||||
var type = (bi ?? unit.TraitInfo<BuildableInfo>()).BuildAtProductionType ?? info.Type;
|
||||
|
||||
var selfsameProductionsCount = self.World.ActorsWithTrait<Production>()
|
||||
.Count(p => p.Actor.Owner == self.Owner && p.Trait.Info.Produces.Contains(type));
|
||||
|
||||
@@ -232,7 +232,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
while (queue.Count > 0 && BuildableItems().All(b => b.Name != queue[0].Item))
|
||||
{
|
||||
playerResources.GiveCash(queue[0].TotalCost - queue[0].RemainingCost); // refund what's been paid so far.
|
||||
// Refund what's been paid so far
|
||||
playerResources.GiveCash(queue[0].TotalCost - queue[0].RemainingCost);
|
||||
FinishProduction();
|
||||
}
|
||||
|
||||
@@ -256,9 +257,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!bi.Queue.Contains(Info.Type))
|
||||
return;
|
||||
|
||||
var cost = unit.HasTraitInfo<ValuedInfo>() ? unit.TraitInfo<ValuedInfo>().Cost : 0;
|
||||
var time = GetBuildTime(order.TargetString);
|
||||
|
||||
// You can't build that
|
||||
if (BuildableItems().All(b => b.Name != order.TargetString))
|
||||
return;
|
||||
@@ -275,6 +273,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
}
|
||||
|
||||
var valued = unit.TraitInfoOrDefault<ValuedInfo>();
|
||||
var cost = valued != null ? valued.Cost : 0;
|
||||
var time = GetBuildTime(unit, bi);
|
||||
var amountToBuild = Math.Min(fromLimit, order.ExtraData);
|
||||
for (var n = 0; n < amountToBuild; n++)
|
||||
{
|
||||
@@ -287,7 +288,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
hasPlayedSound = Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Faction.InternalName);
|
||||
else if (!isBuilding)
|
||||
{
|
||||
if (BuildUnit(order.TargetString))
|
||||
if (BuildUnit(unit))
|
||||
Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Faction.InternalName);
|
||||
else if (!hasPlayedSound && time > 0)
|
||||
hasPlayedSound = Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.BlockedAudio, self.Owner.Faction.InternalName);
|
||||
@@ -309,15 +310,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public virtual int GetBuildTime(string unitString)
|
||||
{
|
||||
var unit = self.World.Map.Rules.Actors[unitString];
|
||||
if (unit == null || !unit.HasTraitInfo<BuildableInfo>())
|
||||
return 0;
|
||||
return GetBuildTime(self.World.Map.Rules.Actors[unitString]);
|
||||
}
|
||||
|
||||
public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
|
||||
{
|
||||
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
|
||||
return 0;
|
||||
|
||||
var time = unit.GetBuildTime() * Info.BuildSpeed;
|
||||
|
||||
return (int)time;
|
||||
}
|
||||
|
||||
@@ -336,7 +337,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
else if (lastIndex == 0)
|
||||
{
|
||||
var item = queue[0];
|
||||
playerResources.GiveCash(item.TotalCost - item.RemainingCost); // refund what has been paid
|
||||
|
||||
// Refund what has been paid
|
||||
playerResources.GiveCash(item.TotalCost - item.RemainingCost);
|
||||
FinishProduction();
|
||||
}
|
||||
}
|
||||
@@ -361,17 +364,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Builds a unit from the actor that holds this queue (1 queue per building)
|
||||
// Returns false if the unit can't be built
|
||||
protected virtual bool BuildUnit(string name)
|
||||
protected virtual bool BuildUnit(ActorInfo unit)
|
||||
{
|
||||
// Cannot produce if I'm dead
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
{
|
||||
CancelProduction(name, 1);
|
||||
CancelProduction(unit.Name, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
var sp = self.TraitsImplementing<Production>().FirstOrDefault(p => p.Info.Produces.Contains(Info.Type));
|
||||
if (sp != null && !self.IsDisabled() && sp.Produce(self, self.World.Map.Rules.Actors[name], Faction))
|
||||
if (sp != null && !self.IsDisabled() && sp.Produce(self, unit, Faction))
|
||||
{
|
||||
FinishProduction();
|
||||
return true;
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
powerIcon.IsVisible = () => power != 0;
|
||||
|
||||
var lowpower = pm.PowerState != PowerState.Normal;
|
||||
var time = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor.Name)
|
||||
var time = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor, buildable)
|
||||
* (lowpower ? palette.CurrentQueue.Info.LowPowerSlowdown : 1);
|
||||
var timeString = WidgetUtils.FormatTime(time, world.Timestep);
|
||||
timeLabel.GetText = () => timeString;
|
||||
|
||||
Reference in New Issue
Block a user