From ecf48d6c12c12775cb22afd3bca055a604edac05 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 28 Dec 2009 15:28:02 +1300 Subject: [PATCH] supporting cheap queues --- OpenRa.Game/Chrome.cs | 19 ++++++++++++++++--- OpenRa.Game/ProductionItem.cs | 10 ++++++++++ OpenRa.Game/Traits/ProductionQueue.cs | 23 +++++++++++++++++++---- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index e17d5b9fbb..d9a71dda78 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -175,7 +175,8 @@ namespace OpenRa.Game var queue = Game.LocalPlayer.PlayerActor.traits.Get(); var item = queue.Producing( groupName ); if (item != null) - Game.controller.AddOrder(Order.CancelProduction(Game.LocalPlayer, item.Item)); + for( var n = 0; n <= item.Repeats; n++ ) + Game.controller.AddOrder(Order.CancelProduction(Game.LocalPlayer, item.Item)); } void ChooseAvailableTab() @@ -294,6 +295,13 @@ namespace OpenRa.Game ready.Play("hold"); overlayBits.Add(Pair.New(ready.Image, overlayPos)); } + + if (currentItem.Repeats > 0) + { + ready.PlayFetchIndex("groups", () => currentItem.Repeats + 1); + ready.Tick(); + overlayBits.Add(Pair.New(ready.Image, overlayPos)); + } } var closureItem = item; @@ -349,7 +357,7 @@ namespace OpenRa.Game if (producing == null) { Game.controller.AddOrder(Order.StartProduction(player, item)); - Sound.Play("abldgin1.aud"); + Sound.Play((group == "Building" || group == "Defense") ? "abldgin1.aud" : "train1.aud"); } else if (producing.Item == item) { @@ -358,8 +366,13 @@ namespace OpenRa.Game if (group == "Building" || group == "Defense") Game.controller.orderGenerator = new PlaceBuilding(player.PlayerActor, item); } - else + else if (producing.Paused) Game.controller.AddOrder(Order.PauseProduction(player, item, false)); + else + { + Sound.Play((group == "Building" || group == "Defense") ? "abldgin1.aud" : "train1.aud"); + Game.controller.AddOrder(Order.StartProduction(player, item)); + } } else { diff --git a/OpenRa.Game/ProductionItem.cs b/OpenRa.Game/ProductionItem.cs index cc2ad552ea..27449c7f9b 100644 --- a/OpenRa.Game/ProductionItem.cs +++ b/OpenRa.Game/ProductionItem.cs @@ -11,6 +11,8 @@ namespace OpenRa.Game public int RemainingTime { get; private set; } public int RemainingCost { get; private set; } + public int Repeats; + public bool Paused = false, Done = false; public Action OnComplete; @@ -24,6 +26,14 @@ namespace OpenRa.Game OnComplete = onComplete; } + public void DoRepeat() + { + RemainingTime = TotalTime; + RemainingCost = TotalCost; + Done = false; + --Repeats; + } + public void Tick(Player player) { if (Done) diff --git a/OpenRa.Game/Traits/ProductionQueue.cs b/OpenRa.Game/Traits/ProductionQueue.cs index 5e122f645b..c3bea23640 100755 --- a/OpenRa.Game/Traits/ProductionQueue.cs +++ b/OpenRa.Game/Traits/ProductionQueue.cs @@ -99,18 +99,33 @@ namespace OpenRa.Game.Traits { var item = production[ category ]; if( item == null ) return; - self.Owner.GiveCash( item.TotalCost - item.RemainingCost ); // refund what's been paid so far. - FinishProduction( category ); + if (item.Repeats > 0) + --item.Repeats; + else + { + self.Owner.GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far. + FinishProduction(category); + } } public void FinishProduction( string category ) { - production[ category ] = null; + var item = production[category]; + if (item == null) return; + if (item.Repeats > 0) + item.DoRepeat(); + else + production[category] = null; } public void BeginProduction( string group, ProductionItem item ) { - if( production[ group ] != null ) return; + if (production[group] != null) + { + if (production[group].Item == item.Item) + ++production[group].Repeats; + return; + } production[ group ] = item; }