From bb5f7dac6bc298784d6fa632faa09cb487e2b411 Mon Sep 17 00:00:00 2001 From: Bob Date: Thu, 21 Jan 2010 13:41:22 +1300 Subject: [PATCH] Ditto Player, Shroud, and Smudge --- OpenRa.Game/Combat.cs | 2 +- OpenRa.Game/Player.cs | 12 +++++++----- OpenRa.Game/Shroud.cs | 6 +++--- OpenRa.Game/Smudge.cs | 15 ++++++++------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/OpenRa.Game/Combat.cs b/OpenRa.Game/Combat.cs index efc99d224c..7146fe1fc8 100644 --- a/OpenRa.Game/Combat.cs +++ b/OpenRa.Game/Combat.cs @@ -29,7 +29,7 @@ namespace OpenRa impactSound = warhead.WaterImpactSound; if (impactSound != null) Sound.Play(impactSound + ".aud"); - if (!isWater) Smudge.AddSmudge(targetTile, warhead); + if (!isWater) world.Map.AddSmudge(targetTile, warhead); if (warhead.Ore) world.Map.DestroyOre(targetTile.X, targetTile.Y); var maxSpread = GetMaximumSpread(weapon, warhead); diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs index 492260011d..05322d4664 100644 --- a/OpenRa.Game/Player.cs +++ b/OpenRa.Game/Player.cs @@ -26,6 +26,8 @@ namespace OpenRa public int PowerProvided = 0; public int PowerDrained = 0; + public World World { get { return PlayerActor.World; } } + public Shroud Shroud; public Dictionary SupportPowers; @@ -52,7 +54,7 @@ namespace OpenRa PowerProvided = 0; PowerDrained = 0; - var myBuildings = Game.world.Actors + var myBuildings = World.Actors .Where(a => a.Owner == this && a.traits.Contains()); foreach (var a in myBuildings) @@ -83,7 +85,7 @@ namespace OpenRa void UpdateOreCapacity() { - OreCapacity = Game.world.Actors + OreCapacity = World.Actors .Where(a => a.Owner == this && a.traits.Contains()) .Select(a => a.Info.Traits.Get()) .Sum(b => b.Capacity); @@ -91,7 +93,7 @@ namespace OpenRa void GiveAdvice(string advice) { - if (this != Game.world.LocalPlayer) return; + if (this != World.LocalPlayer) return; // todo: store the condition or something. // repeat after Rules.General.SpeakDelay, as long as the condition holds. Sound.Play(advice); @@ -130,12 +132,12 @@ namespace OpenRa { UpdatePower(); UpdateOreCapacity(); - Shroud.Tick(); + Shroud.Tick( World ); foreach (var sp in SupportPowers.Values) sp.Tick(); - if (this == Game.world.LocalPlayer) + if (this == World.LocalPlayer) { var totalMoney = Cash + Ore; diff --git a/OpenRa.Game/Shroud.cs b/OpenRa.Game/Shroud.cs index 91622065cd..a0bbffae02 100644 --- a/OpenRa.Game/Shroud.cs +++ b/OpenRa.Game/Shroud.cs @@ -29,11 +29,11 @@ namespace OpenRa set { hasGPS = value; dirty = true;} } - public void Tick() + public void Tick( World world ) { // Clear active flags gapActive = new bool[128, 128]; - foreach (var a in Game.world.Actors.Where(a => a.traits.Contains() && owner != a.Owner)) + foreach (var a in world.Actors.Where(a => a.traits.Contains() && owner != a.Owner)) { foreach (var t in a.traits.Get().GetShroudedTiles()) gapActive[t.X, t.Y] = true; @@ -81,7 +81,7 @@ namespace OpenRa public void Explore(Actor a) { - foreach (var t in Game.world.FindTilesInCircle( + foreach (var t in a.World.FindTilesInCircle( (1f / Game.CellSize * a.CenterLocation).ToInt2(), a.Info.Traits.Get().Sight)) { diff --git a/OpenRa.Game/Smudge.cs b/OpenRa.Game/Smudge.cs index 24fa29b0fe..35454800c3 100644 --- a/OpenRa.Game/Smudge.cs +++ b/OpenRa.Game/Smudge.cs @@ -1,4 +1,5 @@ using OpenRa.GameRules; +using OpenRa.FileFormats; namespace OpenRa { @@ -8,11 +9,11 @@ namespace OpenRa const int firstCrater = 17; const int framesPerCrater = 5; - public static void AddSmudge(bool isCrater, int x, int y) + public static void AddSmudge(this Map map, bool isCrater, int x, int y) { - var smudge = Game.world.Map.MapTiles[x, y].smudge; + var smudge = map.MapTiles[x, y].smudge; if (smudge == 0) - Game.world.Map.MapTiles[x, y].smudge = (byte) (isCrater + map.MapTiles[x, y].smudge = (byte) (isCrater ? (firstCrater + framesPerCrater * ChooseSmudge()) : (firstScorch + ChooseSmudge())); @@ -21,21 +22,21 @@ namespace OpenRa /* deepen the crater */ var amount = (smudge - firstCrater) % framesPerCrater; if (amount < framesPerCrater - 1) - Game.world.Map.MapTiles[x, y].smudge++; + map.MapTiles[x, y].smudge++; } - public static void AddSmudge(int2 targetTile, WarheadInfo warhead) + public static void AddSmudge(this Map map, int2 targetTile, WarheadInfo warhead) { switch (warhead.Explosion) /* todo: push the scorch/crater behavior into data */ { case 4: case 5: - Smudge.AddSmudge(true, targetTile.X, targetTile.Y); + map.AddSmudge(true, targetTile.X, targetTile.Y); break; case 3: case 6: - Smudge.AddSmudge(false, targetTile.X, targetTile.Y); + map.AddSmudge(false, targetTile.X, targetTile.Y); break; } }