From 61ebe0d0a055dfd3816f3ca6a32127cb7dddd5ff Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 26 Aug 2010 22:10:21 +1200 Subject: [PATCH] Per-structure queues for cnc --- OpenRA.Game/Traits/Player/ProductionQueue.cs | 18 +++++++--- OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs | 4 +-- mods/cnc/structures.yaml | 37 +++++++++++++++++--- mods/cnc/system.yaml | 20 ----------- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/OpenRA.Game/Traits/Player/ProductionQueue.cs b/OpenRA.Game/Traits/Player/ProductionQueue.cs index 7df741ab62..d9d5a3d4da 100644 --- a/OpenRA.Game/Traits/Player/ProductionQueue.cs +++ b/OpenRA.Game/Traits/Player/ProductionQueue.cs @@ -77,7 +77,7 @@ namespace OpenRA.Traits for (var n = 0; n < order.TargetLocation.X; n++) // repeat count { - BeginProduction(new ProductionItem(order.TargetString, (int)time, cost, + BeginProduction(new ProductionItem(this, order.TargetString, (int)time, cost, () => self.World.AddFrameEndTask( _ => { @@ -165,6 +165,15 @@ namespace OpenRA.Traits void BuildUnit( string name ) { + // If the actor has a production trait, use it. + var sp = self.TraitsImplementing().Where(p => p.Info.Produces.Contains(Info.Type)).FirstOrDefault(); + if (sp != null) + { + if (!IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ])) + FinishProduction(); + return; + } + var producers = self.World.Queries.OwnedBy[self.Owner] .WithTrait() .Where(x => x.Trait.Info.Produces.Contains(Info.Type)) @@ -193,7 +202,7 @@ namespace OpenRA.Traits public class ProductionItem { public readonly string Item; - + public readonly ProductionQueue Queue; public readonly int TotalTime; public readonly int TotalCost; public int RemainingTime { get; private set; } @@ -204,13 +213,14 @@ namespace OpenRA.Traits int slowdown = 0; - public ProductionItem(string item, int time, int cost, Action onComplete) + public ProductionItem(ProductionQueue queue, string item, int time, int cost, Action onComplete) { if (time <= 0) time = 1; Item = item; RemainingTime = TotalTime = time; RemainingCost = TotalCost = cost; OnComplete = onComplete; + Queue = queue; Log.Write("debug", "new ProductionItem: {0} time={1} cost={2}", item, time, cost); } @@ -228,7 +238,7 @@ namespace OpenRA.Traits if (player.PlayerActor.Trait().GetPowerState() != PowerState.Normal) { if (--slowdown <= 0) - slowdown = player.PlayerActor.Info.Traits.Get().LowPowerSlowdown; + slowdown = Queue.Info.LowPowerSlowdown; else return; } diff --git a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs index 5243a6622a..0d8f5ce8bb 100755 --- a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs @@ -349,7 +349,7 @@ namespace OpenRA.Mods.RA.Widgets if (producing.Done) { if (unit.Traits.Contains()) - world.OrderGenerator = new PlaceBuildingOrderGenerator(player.PlayerActor, item); + world.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue.self, item); return; } @@ -472,7 +472,7 @@ namespace OpenRA.Mods.RA.Widgets var lowpower = resources.GetPowerState() != PowerState.Normal; var time = CurrentQueue.GetBuildTime(info.Name) - * ((lowpower)? pl.PlayerActor.Info.Traits.Get().LowPowerSlowdown : 1); + * ((lowpower)? CurrentQueue.Info.LowPowerSlowdown : 1); DrawRightAligned(WorldUtils.FormatTime(time), pos + new int2(-5, 35), lowpower ? Color.Red: Color.White); var bi = info.Traits.GetOrDefault(); diff --git a/mods/cnc/structures.yaml b/mods/cnc/structures.yaml index 4b250e3750..23563d7aa0 100644 --- a/mods/cnc/structures.yaml +++ b/mods/cnc/structures.yaml @@ -24,6 +24,15 @@ FACT: IntoActor: mcv Offset:1,1 Facing: 108 + ProductionQueue@Building: + Type: Building + BuildSpeed: .4 + LowPowerSlowdown: 3 + ProductionQueue@Defense: + Type: Defense + BuildSpeed: .4 + LowPowerSlowdown: 3 + NUKE: Inherits: ^Building Valued: @@ -173,7 +182,10 @@ PYLE: SpawnOffsets: -10,2, 7,7 ExitCells: 0,1, 1,1 PrimaryBuilding: - + ProductionQueue@Vehicle: + Type: Infantry + BuildSpeed: .4 + LowPowerSlowdown: 3 HAND: Inherits: ^Building Valued: @@ -204,7 +216,10 @@ HAND: SpawnOffsets: 12,24 ExitCells:1,2 PrimaryBuilding: - + ProductionQueue@Infantry: + Type: Infantry + BuildSpeed: .4 + LowPowerSlowdown: 3 AFLD: Inherits: ^Building Valued: @@ -237,7 +252,11 @@ AFLD: SpawnOffsets: -24,0 ExitCells:3,1 PrimaryBuilding: - + ProductionQueue@Vehicle: + Type: Vehicle + BuildSpeed: .4 + LowPowerSlowdown: 3 + WEAP: Inherits: ^Building Valued: @@ -270,7 +289,11 @@ WEAP: SpawnOffsets: -8,-8 ExitCells: 0,2 PrimaryBuilding: - + ProductionQueue@Vehicle: + Type: Vehicle + BuildSpeed: .4 + LowPowerSlowdown: 3 + HQ: RequiresPower: CanPowerDown: @@ -383,7 +406,11 @@ HPAD: Reservable: RepairsUnits: RallyPoint: - + ProductionQueue@Plane: + Type: Plane + BuildSpeed: .4 + LowPowerSlowdown: 3 + EYE: RequiresPower: CanPowerDown: diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml index 538d009938..10c271e3d9 100644 --- a/mods/cnc/system.yaml +++ b/mods/cnc/system.yaml @@ -1,24 +1,4 @@ Player: - ProductionQueue@Building: - Type: Building - BuildSpeed: .4 - LowPowerSlowdown: 3 - ProductionQueue@Defense: - Type: Defense - BuildSpeed: .4 - LowPowerSlowdown: 3 - ProductionQueue@Infantry: - Type: Infantry - BuildSpeed: .4 - LowPowerSlowdown: 3 - ProductionQueue@Vehicle: - Type: Vehicle - BuildSpeed: .4 - LowPowerSlowdown: 3 - ProductionQueue@Plane: - Type: Plane - BuildSpeed: .4 - LowPowerSlowdown: 3 PlaceBuilding: TechTreeCache: NukePower: