diff --git a/OpenRa.Game/GameRules/GeneralInfo.cs b/OpenRa.Game/GameRules/GeneralInfo.cs index 8d55eb5c38..e351a7be66 100644 --- a/OpenRa.Game/GameRules/GeneralInfo.cs +++ b/OpenRa.Game/GameRules/GeneralInfo.cs @@ -121,5 +121,6 @@ namespace OpenRa.Game.GameRules /* OpenRA-specific */ public readonly float OreChance; /* chance of spreading to a * particular eligible cell */ + public readonly int LowPowerSlowdown; /* build time multiplier */ } } diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs index 53d6ced39c..ff981178a4 100644 --- a/OpenRa.Game/Player.cs +++ b/OpenRa.Game/Player.cs @@ -6,6 +6,8 @@ using OpenRa.Game.Traits; namespace OpenRa.Game { + enum PowerState { Normal, Low, Critical }; + class Player { public int Palette; @@ -65,6 +67,13 @@ namespace OpenRa.Game return (float)Ore / GetOreCapacity(); } + public PowerState GetPowerState() + { + if (powerProvided >= powerDrained) return PowerState.Normal; + if (powerProvided > powerDrained / 2) return PowerState.Low; + return PowerState.Critical; + } + public int GetOreCapacity() { return Game.world.Actors diff --git a/OpenRa.Game/ProductionItem.cs b/OpenRa.Game/ProductionItem.cs index 58695503e9..cc2ad552ea 100644 --- a/OpenRa.Game/ProductionItem.cs +++ b/OpenRa.Game/ProductionItem.cs @@ -14,6 +14,8 @@ namespace OpenRa.Game public bool Paused = false, Done = false; public Action OnComplete; + int slowdown = 0; + public ProductionItem(string item, int time, int cost, Action onComplete) { Item = item; @@ -32,6 +34,14 @@ namespace OpenRa.Game if (Paused) return; + if (player.GetPowerState() != PowerState.Normal) + { + if (--slowdown <= 0) + slowdown = Rules.General.LowPowerSlowdown; + else + return; + } + var costThisFrame = RemainingCost / RemainingTime; if (costThisFrame != 0 && !player.TakeCash(costThisFrame)) return; diff --git a/OpenRa.Game/UnitOrders.cs b/OpenRa.Game/UnitOrders.cs index bc1c05b7a3..cf82d039c8 100755 --- a/OpenRa.Game/UnitOrders.cs +++ b/OpenRa.Game/UnitOrders.cs @@ -56,9 +56,9 @@ namespace OpenRa.Game string group = Rules.UnitCategory[ order.TargetString ]; var ui = Rules.UnitInfo[ order.TargetString ]; var time = ui.Cost - * .8f /* Game.BuildSpeed */ /* todo: country-specific build speed bonus */ - * ( 25 * 60 ) /* frames per min */ /* todo: build acceleration, if we do that */ - / 1000; + * Rules.General.BuildSpeed /* todo: country-specific build speed bonus */ + * (25 * 60) /* frames per min */ /* todo: build acceleration, if we do that */ + / 1000; time = .08f * time; /* temporary hax so we can build stuff fast for test */ diff --git a/units.ini b/units.ini index f4b26a067e..c9a405dd94 100755 --- a/units.ini +++ b/units.ini @@ -574,6 +574,7 @@ WaterImpactSound=splash9 [General] OreChance=.02 +LowPowerSlowdown=3 [VoiceTypes] GenericVoice