diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 6e69caf944..7aacabe1f6 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -47,6 +47,7 @@ namespace OpenRa.Game readonly List>> buttons = new List>>(); readonly List digitSprites; readonly Dictionary tabSprites; + readonly Dictionary spsprites; readonly Sprite[] shimSprites; readonly Sprite blank; @@ -55,6 +56,12 @@ namespace OpenRa.Game bool hadRadar = false; bool optionsPressed = false; const int MinRows = 4; + + string currentTab = "Building"; + static string[] groups = new string[] { "Building", "Defense", "Infantry", "Vehicle", "Plane", "Ship" }; + readonly Dictionary sprites; + + const int NumClockFrames = 54; public Chrome(Renderer r) { @@ -116,6 +123,11 @@ namespace OpenRa.Game u => u, u => SpriteSheetBuilder.LoadAllSprites(Rules.UnitInfo[u].Icon ?? (u + "icon"))[0]); + spsprites = Rules.SupportPowerInfo + .ToDictionary( + u => u.Key, + u => SpriteSheetBuilder.LoadAllSprites(u.Value.Image)[0]); + tabSprites = groups.Select( (g, i) => Pair.New(g, OpenRa.Game.Graphics.Util.MakeArray(3, @@ -163,7 +175,6 @@ namespace OpenRa.Game DrawMinimap(); - chromeRenderer.DrawSprite(specialBinSprite, float2.Zero, PaletteType.Chrome); chromeRenderer.DrawSprite(moneyBinSprite, new float2(Game.viewport.Width - 320, 0), PaletteType.Chrome); DrawMoney(); @@ -172,6 +183,7 @@ namespace OpenRa.Game DrawButtons(); int paletteHeight = DrawBuildPalette(currentTab); + DrawSupportPowers(); DrawBuildTabs(paletteHeight); DrawChat(); DrawOptionsMenu(); @@ -220,15 +232,11 @@ namespace OpenRa.Game // Don't let tabs overlap the bevel if (y > paletteOrigin.Y + paletteHeight - tabHeight - 9 && y < paletteOrigin.Y + paletteHeight) - { y += tabHeight; - } // Stick tabs to the edge of the screen if (y > paletteOrigin.Y + paletteHeight) - { x = Game.viewport.Width - tabWidth; - } chromeRenderer.DrawSprite(q.Value[index], new float2(x, y), PaletteType.Chrome); @@ -321,10 +329,8 @@ namespace OpenRa.Game if (!hasChronosphere) repairButton.ReplaceAnim("disabled"); else - { - //repairButton.ReplaceAnim(Game.controller.orderGenerator is RepairOrderGenerator ? "pressed" : "normal"); AddButton(chronoshiftRect, isLmb => HandleChronosphereButton()); - } + buildPaletteRenderer.DrawSprite(repairButton.Image, chronoshiftDrawPos, PaletteType.Chrome); // Iron Curtain @@ -336,13 +342,10 @@ namespace OpenRa.Game if (!hasCurtain) repairButton.ReplaceAnim("disabled"); else - { - //repairButton.ReplaceAnim(Game.controller.orderGenerator is RepairOrderGenerator ? "pressed" : "normal"); AddButton(curtainRect, isLmb => HandleIronCurtainButton()); - } + buildPaletteRenderer.DrawSprite(repairButton.Image, curtainDrawPos, PaletteType.Chrome); - // Repair Rectangle repairRect = new Rectangle(Game.viewport.Width - 120, 5, repairButton.Image.bounds.Width, repairButton.Image.bounds.Height); var repairDrawPos = Game.viewport.Location + new float2(repairRect.Location); @@ -386,7 +389,7 @@ namespace OpenRa.Game buildPaletteRenderer.Flush(); //Options - Rectangle optionsRect = new Rectangle(0 + 40,0, optionsButton.Image.bounds.Width, + Rectangle optionsRect = new Rectangle(0,0, optionsButton.Image.bounds.Width, optionsButton.Image.bounds.Height); var optionsDrawPos = Game.viewport.Location + new float2(optionsRect.Location); @@ -464,22 +467,6 @@ namespace OpenRa.Game renderer.DrawText(line.b, p, line.a); renderer.DrawText(line.c, p + new int2(size.X + 10, 0), Color.White); } - - string currentTab = "Building"; - static string[] groups = new string[] { "Building", "Defense", "Infantry", "Vehicle", "Plane", "Ship" }; - Dictionary sprites; - - const int NumClockFrames = 54; - Func ClockAnimFrame(string group) - { - return () => - { - var queue = Game.LocalPlayer.PlayerActor.traits.Get(); - var producing = queue.CurrentItem( group ); - if (producing == null) return 0; - return (producing.TotalTime - producing.RemainingTime) * NumClockFrames / producing.TotalTime; - }; - } // Return an int telling us the y coordinate at the bottom of the palette int DrawBuildPalette(string queueName) @@ -717,5 +704,40 @@ namespace OpenRa.Game renderer.DrawText(info.LongDesc.Replace( "\\n", "\n" ), p.ToInt2(), Color.White); } } + + void DrawSupportPowers() + { + chromeRenderer.DrawSprite(specialBinSprite, new float2(0,14), PaletteType.Chrome); + chromeRenderer.Flush(); + var y = 24; + foreach (var sp in Game.LocalPlayer.SupportPowers) + { + var image = spsprites[sp.Key]; + if (sp.Value.IsAvailable) + { + var drawPos = Game.viewport.Location + new float2(5, y); + buildPaletteRenderer.DrawSprite(image, drawPos, PaletteType.Chrome); + + clock.PlayFetchIndex("idle", + () => (sp.Value.TotalTime - sp.Value.RemainingTime) + * NumClockFrames / sp.Value.TotalTime); + clock.Tick(); + + buildPaletteRenderer.DrawSprite(clock.Image, drawPos, PaletteType.Chrome); + + if (sp.Value.IsDone) + { + ready.Play("ready"); + buildPaletteRenderer.DrawSprite(ready.Image, + drawPos + new float2((64 - ready.Image.size.X) / 2, 2), + PaletteType.Chrome); + } + + y += 51; + } + } + + buildPaletteRenderer.Flush(); + } } } diff --git a/OpenRa.Game/GameRules/InfoLoader.cs b/OpenRa.Game/GameRules/InfoLoader.cs index 8ce668a69c..6a35b9b510 100644 --- a/OpenRa.Game/GameRules/InfoLoader.cs +++ b/OpenRa.Game/GameRules/InfoLoader.cs @@ -5,10 +5,11 @@ using System.Text; using OpenRa.FileFormats; using OpenRa.Game.Graphics; using IjwFramework.Types; +using System.Collections; namespace OpenRa.Game.GameRules { - class InfoLoader + class InfoLoader : IEnumerable> { readonly Dictionary infos = new Dictionary(); @@ -28,9 +29,7 @@ namespace OpenRa.Game.GameRules get { return infos[name.ToLowerInvariant()]; } } - public IEnumerator> GetEnumerator() - { - return infos.GetEnumerator(); - } + public IEnumerator> GetEnumerator() { return infos.GetEnumerator(); } + IEnumerator IEnumerable.GetEnumerator() { return infos.GetEnumerator(); } } } diff --git a/OpenRa.Game/GameRules/TechTree.cs b/OpenRa.Game/GameRules/TechTree.cs index af0fd79ce4..c2cfb0c230 100755 --- a/OpenRa.Game/GameRules/TechTree.cs +++ b/OpenRa.Game/GameRules/TechTree.cs @@ -43,7 +43,7 @@ namespace OpenRa.Game.GameRules return false; return true; - } + } public IEnumerable BuildableItems( Player player, params string[] categories ) { diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 80e5bc199f..913dd4655d 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -119,6 +119,7 @@ + diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs index bae1f38aa5..b84e10f668 100644 --- a/OpenRa.Game/Player.cs +++ b/OpenRa.Game/Player.cs @@ -28,6 +28,7 @@ namespace OpenRa.Game public bool IsReady; public Shroud Shroud = new Shroud(); + public Dictionary SupportPowers; public Player( Actor playerActor, int index, PaletteType palette, string playerName, Race race, string internalName ) { @@ -37,6 +38,10 @@ namespace OpenRa.Game this.InternalName = internalName; this.PlayerName = playerName; this.Race = race; + + SupportPowers = Rules.SupportPowerInfo.ToDictionary( + spi => spi.Key, + spi => new SupportPower(spi.Value, this)); } void UpdatePower() @@ -126,6 +131,9 @@ namespace OpenRa.Game UpdatePower(); UpdateOreCapacity(); + foreach (var sp in SupportPowers.Values) + sp.Tick(); + if (this == Game.LocalPlayer) { var totalMoney = Cash + Ore; diff --git a/OpenRa.Game/SupportPower.cs b/OpenRa.Game/SupportPower.cs new file mode 100644 index 0000000000..2a6ff5ba56 --- /dev/null +++ b/OpenRa.Game/SupportPower.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Game.GameRules; + +namespace OpenRa.Game +{ + class SupportPower + { + public readonly SupportPowerInfo Info; + public readonly Player Owner; + + public SupportPower(SupportPowerInfo info, Player owner) + { + Info = info; + Owner = owner; + + RemainingTime = TotalTime = (int)info.ChargeTime * 60 * 25; + } + + public bool IsAvailable { get; private set; } + public bool IsDone { get { return RemainingTime == 0; } } + public int RemainingTime { get; private set; } + public int TotalTime { get; private set; } + + public void Tick() + { + if (Info.GivenAuto) + { + var buildings = Rules.TechTree.GatherBuildings(Owner); + var effectivePrereq = Info.Prerequisite + .Select( a => a.ToLowerInvariant() ) + .Where( a => Rules.UnitInfo[a].Owner + .Any( r => r == Owner.Race )); + + IsAvailable = Info.TechLevel > -1 + && effectivePrereq.Any() + && effectivePrereq.All(a => buildings[a].Count > 0); + } + + if (IsAvailable && (!Info.Powered || Owner.GetPowerState() == PowerState.Normal)) + { + if (RemainingTime > 0) --RemainingTime; + } + } + } +} diff --git a/units.ini b/units.ini index 5c39efaabf..fac05d0bd8 100644 --- a/units.ini +++ b/units.ini @@ -857,6 +857,7 @@ Description=Chronoshift LongDesc=Temporarily teleports a vehicle across the map. Prerequisite=PDOX Image=warpicon +TechLevel=12 [SpyPlanePower] ; free with first AFLD ChargeTime=3 @@ -872,6 +873,7 @@ Description=Atom Bomb LongDesc=Launches a nuclear missile at your target Prerequisite=MSLO Image=atomicon +TechLevel=12 [GpsSatellitePower] ; free with ATEK ChargeTime=8 @@ -880,10 +882,12 @@ LongDesc=Reveals the entire map OneShot=yes Prerequisite=ATEK Image=gpssicon +TechLevel=12 [InvulnerabilityPower] ; the point of IRON ChargeTime=11 Description=Invulnerability LongDesc=Makes a single unit invulnerable for a short time. Image=infxicon -Prerequisite=IRON \ No newline at end of file +Prerequisite=IRON +TechLevel=12 \ No newline at end of file