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