From b332785d2eb92b01f279b25ceeabb02250807e46 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 8 Jan 2010 19:35:43 +1300 Subject: [PATCH 1/4] Initial GpsSatellite support --- OpenRa.Game/OpenRa.Game.csproj | 1 + OpenRa.Game/Shroud.cs | 14 ++++++++++++++ OpenRa.Game/Traits/GpsSatellite.cs | 22 ++++++++++++++++++++++ units.ini | 2 +- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 OpenRa.Game/Traits/GpsSatellite.cs diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 80e5bc199f..c9317d181a 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -216,6 +216,7 @@ + diff --git a/OpenRa.Game/Shroud.cs b/OpenRa.Game/Shroud.cs index 56cc9efb59..400075390a 100644 --- a/OpenRa.Game/Shroud.cs +++ b/OpenRa.Game/Shroud.cs @@ -26,6 +26,20 @@ namespace OpenRa.Game dirty = true; } + + public void RevealAll() + { + for (int x = 0; x < 128; x++) + for (int y = 0; y < 128; y++) + explored[x, y] = true; + } + + public void HideAll() + { + for (int x = 0; x < 128; x++) + for (int y = 0; y < 128; y++) + explored[x, y] = false; + } Sprite ChooseShroud(int i, int j) { diff --git a/OpenRa.Game/Traits/GpsSatellite.cs b/OpenRa.Game/Traits/GpsSatellite.cs new file mode 100644 index 0000000000..4cb62d968f --- /dev/null +++ b/OpenRa.Game/Traits/GpsSatellite.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRa.Game.Traits +{ + class GpsSatellite + { + public GpsSatellite(Actor self) + { + // TODO: connect this to a special power that calls Activate(); + Activate(self); + } + + public void Activate(Actor self) + { + // TODO: Launch satellite + self.Owner.Shroud.RevealAll(); + } + } +} diff --git a/units.ini b/units.ini index 6ed539a5f0..3b156254a1 100644 --- a/units.ini +++ b/units.ini @@ -345,7 +345,7 @@ MINV ; `Produces` is a category of objects that this building can produce. [ATEK] Description=Allied Tech Center -Traits=Building, RenderBuilding, IronCurtainable +Traits=Building, RenderBuilding, IronCurtainable, GpsSatellite Dimensions=2,2 Footprint=xx xx SelectionPriority=3 From 9b4959bbb2783fcc7d70120de8782038ad0426e4 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 8 Jan 2010 20:49:25 +1300 Subject: [PATCH 2/4] GPS satellite launch animation --- OpenRa.Game/Effects/GpsSatellite.cs | 33 +++++++++++++++++++++++ OpenRa.Game/Effects/SatelliteLaunch.cs | 37 ++++++++++++++++++++++++++ OpenRa.Game/OpenRa.Game.csproj | 2 ++ OpenRa.Game/Shroud.cs | 2 ++ OpenRa.Game/Traits/GpsSatellite.cs | 31 ++++++++++++--------- sequences.xml | 4 +++ 6 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 OpenRa.Game/Effects/GpsSatellite.cs create mode 100644 OpenRa.Game/Effects/SatelliteLaunch.cs diff --git a/OpenRa.Game/Effects/GpsSatellite.cs b/OpenRa.Game/Effects/GpsSatellite.cs new file mode 100644 index 0000000000..55f58d3200 --- /dev/null +++ b/OpenRa.Game/Effects/GpsSatellite.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using OpenRa.Game.Graphics; +using OpenRa.Game.Traits; + +namespace OpenRa.Game.Effects +{ + class GpsSatellite : IEffect + { + readonly float heightPerTick = 10; + float2 offset; + Animation anim = new Animation("sputnik"); + + public GpsSatellite(float2 offset) + { + this.offset = offset; + anim.PlayRepeating("idle"); + } + + public void Tick() + { + anim.Tick(); + offset.Y -= heightPerTick; + + if (offset.Y < 0) + Game.world.AddFrameEndTask(w => w.Remove(this)); + } + + public IEnumerable Render() + { + yield return new Renderable(anim.Image,offset, PaletteType.Gold); + } + } +} diff --git a/OpenRa.Game/Effects/SatelliteLaunch.cs b/OpenRa.Game/Effects/SatelliteLaunch.cs new file mode 100644 index 0000000000..7cc0d36dca --- /dev/null +++ b/OpenRa.Game/Effects/SatelliteLaunch.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using OpenRa.Game.Graphics; +using OpenRa.Game.Traits; + +namespace OpenRa.Game.Effects +{ + class SatelliteLaunch : IEffect + { + int frame = 0; + Actor a; + Animation doors = new Animation("atek"); + float2 doorOffset = new float2(-4,0); + + public SatelliteLaunch(Actor a) + { + this.a = a; + doors.PlayThen("active", + () => Game.world.AddFrameEndTask(w => w.Remove(this))); + } + + public void Tick() + { + doors.Tick(); + + if (++frame == 19) + { + Game.world.AddFrameEndTask(w => w.Add(new GpsSatellite(a.CenterLocation - .5f * doors.Image.size + doorOffset))); + } + } + + public IEnumerable Render() + { + yield return new Renderable(doors.Image, + a.CenterLocation - .5f * doors.Image.size + doorOffset, PaletteType.Gold); + } + } +} diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index c9317d181a..d78bfb97c2 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -83,10 +83,12 @@ + + diff --git a/OpenRa.Game/Shroud.cs b/OpenRa.Game/Shroud.cs index 400075390a..c6ec79a662 100644 --- a/OpenRa.Game/Shroud.cs +++ b/OpenRa.Game/Shroud.cs @@ -32,6 +32,7 @@ namespace OpenRa.Game for (int x = 0; x < 128; x++) for (int y = 0; y < 128; y++) explored[x, y] = true; + dirty = true; } public void HideAll() @@ -39,6 +40,7 @@ namespace OpenRa.Game for (int x = 0; x < 128; x++) for (int y = 0; y < 128; y++) explored[x, y] = false; + dirty = true; } Sprite ChooseShroud(int i, int j) diff --git a/OpenRa.Game/Traits/GpsSatellite.cs b/OpenRa.Game/Traits/GpsSatellite.cs index 4cb62d968f..e71f8a3455 100644 --- a/OpenRa.Game/Traits/GpsSatellite.cs +++ b/OpenRa.Game/Traits/GpsSatellite.cs @@ -1,22 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using OpenRa.Game.Effects; namespace OpenRa.Game.Traits { - class GpsSatellite + class GpsSatellite : ITick { - public GpsSatellite(Actor self) - { - // TODO: connect this to a special power that calls Activate(); - Activate(self); - } + int frame = 0; + int revealTicks = 30 * 25; // 30 second delay between launch and reveal + bool fired = false; + public GpsSatellite(Actor self) {} + public void Tick(Actor self) + { + // HACK: Launch after 5 seconds + if (++frame == 150) + Activate(self); + + if (fired && --revealTicks == 0) + { + self.Owner.Shroud.RevealAll(); + } + } public void Activate(Actor self) { - // TODO: Launch satellite - self.Owner.Shroud.RevealAll(); + Game.world.AddFrameEndTask(w => w.Add(new SatelliteLaunch(self))); + fired = true; } } } diff --git a/sequences.xml b/sequences.xml index ba46bfa4a9..252a584725 100644 --- a/sequences.xml +++ b/sequences.xml @@ -94,6 +94,7 @@ + @@ -1030,4 +1031,7 @@ + + + \ No newline at end of file From 7fff532ca1ae109474d4337f1b4abebefc537df3 Mon Sep 17 00:00:00 2001 From: Alli Date: Fri, 8 Jan 2010 21:21:20 +1300 Subject: [PATCH 3/4] some of Thief Steal --- OpenRa.Game/OpenRa.Game.csproj | 2 ++ OpenRa.Game/Orders/UnitOrderGenerator.cs | 1 + OpenRa.Game/Traits/Activities/StealOre.cs | 35 +++++++++++++++++++++++ OpenRa.Game/Traits/ThiefSteal.cs | 30 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 OpenRa.Game/Traits/Activities/StealOre.cs create mode 100644 OpenRa.Game/Traits/ThiefSteal.cs diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 80e5bc199f..c4148588d1 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -162,6 +162,7 @@ + @@ -255,6 +256,7 @@ + diff --git a/OpenRa.Game/Orders/UnitOrderGenerator.cs b/OpenRa.Game/Orders/UnitOrderGenerator.cs index dc4019ceea..95ad375bbb 100644 --- a/OpenRa.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRa.Game/Orders/UnitOrderGenerator.cs @@ -86,6 +86,7 @@ namespace OpenRa.Game.Orders case "Infiltrate": return Cursor.Enter; case "Capture": return Cursor.Capture; case "Harvest": return Cursor.AttackMove; + case "Steal" : return Cursor.Enter; default: return null; } diff --git a/OpenRa.Game/Traits/Activities/StealOre.cs b/OpenRa.Game/Traits/Activities/StealOre.cs new file mode 100644 index 0000000000..9b343e1e30 --- /dev/null +++ b/OpenRa.Game/Traits/Activities/StealOre.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRa.Game.Traits.Activities +{ + class StealOre : IActivity + { + Actor target; + public const int CashStolen = 100; //todo: push this out to Rules + + public StealOre(Actor target) { this.target = target; } + + public IActivity NextActivity { get; set; } + + public IActivity Tick(Actor self) + { + if (target == null || target.IsDead) return NextActivity; + + if (target.Owner == self.Owner) return NextActivity; + + target.Owner.TakeCash(CashStolen); + self.Owner.GiveCash(CashStolen); + + // the thief is sacrificed. + self.Health = 0; + Game.world.AddFrameEndTask(w => w.Remove(self)); + + return NextActivity; + } + + public void Cancel(Actor self) { target = null; NextActivity = null; } + } +} diff --git a/OpenRa.Game/Traits/ThiefSteal.cs b/OpenRa.Game/Traits/ThiefSteal.cs new file mode 100644 index 0000000000..4b3f016c26 --- /dev/null +++ b/OpenRa.Game/Traits/ThiefSteal.cs @@ -0,0 +1,30 @@ +using OpenRa.Game.Traits.Activities; + +namespace OpenRa.Game.Traits +{ + class ThiefSteal : IOrder + { + public ThiefSteal(Actor self) { } + + public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) + { + if (mi.Button != MouseButton.Right) return null; + if (underCursor == null) return null; + if (!underCursor.traits.Contains()) return null; + + // todo: other bits + + return new Order("Steal", self, underCursor, int2.Zero, null); + } + + public void ResolveOrder(Actor self, Order order) + { + if (order.OrderString == "Steal") + { + self.CancelActivity(); + self.QueueActivity(new Move(order.TargetActor, 1)); + self.QueueActivity(new StealOre(order.TargetActor)); + } + } + } +} From 0738c4ebe38ab155789c5a53f00d2b6d578864dd Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 8 Jan 2010 21:24:52 +1300 Subject: [PATCH 4/4] Allow GPS to be revoked --- OpenRa.Game/Shroud.cs | 51 ++++++++++++++---------------- OpenRa.Game/Traits/GpsSatellite.cs | 2 +- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/OpenRa.Game/Shroud.cs b/OpenRa.Game/Shroud.cs index b2f60a891b..697e774406 100644 --- a/OpenRa.Game/Shroud.cs +++ b/OpenRa.Game/Shroud.cs @@ -13,10 +13,21 @@ namespace OpenRa.Game Sprite[] shadowBits = SpriteSheetBuilder.LoadAllSprites("shadow"); Sprite[,] sprites = new Sprite[128, 128]; bool dirty; - - public bool IsExplored(int2 xy) + bool hasGPS = false; + + public bool HasGPS { - return explored[ xy.X, xy.Y ]; + get { return hasGPS; } + set { hasGPS = value; dirty = true;} + } + + public bool IsExplored(int2 xy) { return IsExplored(xy.X, xy.Y); } + public bool IsExplored(int x, int y) + { + if (hasGPS) + return true; + + return explored[ x, y ]; } public void Explore(Actor a) @@ -26,22 +37,6 @@ namespace OpenRa.Game dirty = true; } - - public void RevealAll() - { - for (int x = 0; x < 128; x++) - for (int y = 0; y < 128; y++) - explored[x, y] = true; - dirty = true; - } - - public void HideAll() - { - for (int x = 0; x < 128; x++) - for (int y = 0; y < 128; y++) - explored[x, y] = false; - dirty = true; - } static readonly byte[] ShroudTiles = { @@ -67,11 +62,11 @@ namespace OpenRa.Game { // bits are for exploredness: left, right, up, down, self var v = 0; - if (explored[i - 1, j]) v |= 1; - if (explored[i + 1, j]) v |= 2; - if (explored[i, j - 1]) v |= 4; - if (explored[i, j + 1]) v |= 8; - if (explored[i, j]) v |= 16; + if (IsExplored(i - 1, j)) v |= 1; + if (IsExplored(i + 1, j)) v |= 2; + if (IsExplored(i, j - 1)) v |= 4; + if (IsExplored(i, j + 1)) v |= 8; + if (IsExplored(i, j)) v |= 16; var x = ShroudTiles[v]; if (x != 0) @@ -79,10 +74,10 @@ namespace OpenRa.Game // bits are for exploredness: TL, TR, BR, BL var u = 0; - if (explored[i - 1, j - 1]) u |= 1; - if (explored[i + 1, j - 1]) u |= 2; - if (explored[i + 1, j + 1]) u |= 4; - if (explored[i - 1, j + 1]) u |= 8; + if (IsExplored(i - 1, j - 1)) u |= 1; + if (IsExplored(i + 1, j - 1)) u |= 2; + if (IsExplored(i + 1, j + 1)) u |= 4; + if (IsExplored(i - 1, j + 1)) u |= 8; return shadowBits[ExtraShroudTiles[u]]; } diff --git a/OpenRa.Game/Traits/GpsSatellite.cs b/OpenRa.Game/Traits/GpsSatellite.cs index e71f8a3455..f735f941be 100644 --- a/OpenRa.Game/Traits/GpsSatellite.cs +++ b/OpenRa.Game/Traits/GpsSatellite.cs @@ -17,7 +17,7 @@ namespace OpenRa.Game.Traits if (fired && --revealTicks == 0) { - self.Owner.Shroud.RevealAll(); + self.Owner.Shroud.HasGPS = true; } } public void Activate(Actor self)