From 542a9ef2fc8d2626c342cda732b36aef36b36585 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 13 Jan 2010 19:23:56 +1300 Subject: [PATCH] Gap behaves like real-ra --- OpenRa.Game/Graphics/Minimap.cs | 2 +- OpenRa.Game/Shroud.cs | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/OpenRa.Game/Graphics/Minimap.cs b/OpenRa.Game/Graphics/Minimap.cs index f80cb3a066..021abe1a8c 100644 --- a/OpenRa.Game/Graphics/Minimap.cs +++ b/OpenRa.Game/Graphics/Minimap.cs @@ -103,7 +103,7 @@ namespace OpenRa.Game.Graphics { for (var y = 0; y < 128; y++) for (var x = 0; x < 128; x++) - if (!Game.LocalPlayer.Shroud.IsExplored(new int2(x, y))) + if (!Game.LocalPlayer.Shroud.DisplayOnRadar(x,y)) *(c + (y * bitmapData.Stride >> 2) + x) = shroudColor.ToArgb(); } } diff --git a/OpenRa.Game/Shroud.cs b/OpenRa.Game/Shroud.cs index 6ee7456142..eb7dc5c196 100644 --- a/OpenRa.Game/Shroud.cs +++ b/OpenRa.Game/Shroud.cs @@ -11,12 +11,15 @@ namespace OpenRa.Game class Shroud { bool[,] explored = new bool[128, 128]; - int[,] gapField = new int[128, 128]; Sprite[] shadowBits = SpriteSheetBuilder.LoadAllSprites("shadow"); Sprite[,] sprites = new Sprite[128, 128]; bool dirty; bool hasGPS = false; + float gapOpaqueTicks = (int)(Rules.General.GapRegenInterval * 25 * 60); + int[,] gapField = new int[128, 128]; + bool[,] gapActive = new bool[128, 128]; + public bool HasGPS { get { return hasGPS; } @@ -25,8 +28,8 @@ namespace OpenRa.Game public void Tick() { - // This is probably slow - bool[,] gapActive = new bool[128, 128]; + // Clear active flags + gapActive = new bool[128, 128]; foreach (var a in Game.world.Actors.Where(a => a.traits.Contains())) { foreach (var t in a.traits.Get().GetShroudedTiles()) @@ -36,11 +39,17 @@ namespace OpenRa.Game for (int j = 1; j < 127; j++) for (int i = 1; i < 127; i++) { - if (gapField[i, j] > 0 && !gapActive[i, j]) /*0 >= --gapField[i, j]*/ + if (gapField[i, j] > 0 && !gapActive[i, j]) { + // Convert gap to shroud + if (gapField[i, j] >= gapOpaqueTicks && explored[i, j]) + explored[i, j] = false; + + // Clear gap gapField[i, j] = 0; dirty = true; } + // Increase gap tick; rerender if necessary if (gapActive[i, j] && 0 == gapField[i, j]++) dirty = true; } @@ -58,6 +67,15 @@ namespace OpenRa.Game return explored[ x, y ]; } + public bool DisplayOnRadar(int x, int y) + { + // Active gap is never shown on radar, even if a unit is in range + if (gapActive[x , y]) + return false; + + return IsExplored(x,y); + } + public void Explore(Actor a) { foreach (var t in Game.FindTilesInCircle((1f / Game.CellSize * a.CenterLocation).ToInt2(), a.Info.Sight)) @@ -68,6 +86,7 @@ namespace OpenRa.Game dirty = true; } + static readonly byte[] ShroudTiles = { 0xf,0xf,0xf,0xf, @@ -87,7 +106,7 @@ namespace OpenRa.Game 40, 37, 44, 34, 36, 33, 32, 47, }; - + Sprite ChooseShroud(int i, int j) { // bits are for exploredness: left, right, up, down, self @@ -101,7 +120,7 @@ namespace OpenRa.Game var x = ShroudTiles[v]; if (x != 0) return shadowBits[x]; - + // bits are for exploredness: TL, TR, BR, BL var u = 0; if (IsExplored(i - 1, j - 1)) u |= 1;