diff --git a/OpenRa.FileFormats/IPaletteRemap.cs b/OpenRa.FileFormats/IPaletteRemap.cs
new file mode 100644
index 0000000000..321596490a
--- /dev/null
+++ b/OpenRa.FileFormats/IPaletteRemap.cs
@@ -0,0 +1,9 @@
+using System;
+using System.Drawing;
+namespace OpenRa.FileFormats
+{
+ public interface IPaletteRemap
+ {
+ Color GetRemappedColor(Color original, int index);
+ }
+}
diff --git a/OpenRa.FileFormats/OpenRa.FileFormats.csproj b/OpenRa.FileFormats/OpenRa.FileFormats.csproj
index ce057e867c..26f9983855 100644
--- a/OpenRa.FileFormats/OpenRa.FileFormats.csproj
+++ b/OpenRa.FileFormats/OpenRa.FileFormats.csproj
@@ -55,6 +55,7 @@
+
@@ -62,6 +63,7 @@
+
diff --git a/OpenRa.FileFormats/Palette.cs b/OpenRa.FileFormats/Palette.cs
index 6244913786..5016372a8a 100644
--- a/OpenRa.FileFormats/Palette.cs
+++ b/OpenRa.FileFormats/Palette.cs
@@ -31,7 +31,7 @@ namespace OpenRa.FileFormats
colors[4] = Color.FromArgb(140, 0, 0, 0);
}
- public Palette(Palette p, PaletteRemap r)
+ public Palette(Palette p, IPaletteRemap r)
{
for (int i = 0; i < 256; i++)
colors.Add(r.GetRemappedColor(p.GetColor(i), i));
diff --git a/OpenRa.FileFormats/PaletteRemap.cs b/OpenRa.FileFormats/PaletteRemap.cs
index ecd6de41cb..635c0d5653 100644
--- a/OpenRa.FileFormats/PaletteRemap.cs
+++ b/OpenRa.FileFormats/PaletteRemap.cs
@@ -4,7 +4,7 @@ using System.IO;
namespace OpenRa.FileFormats
{
- public class PaletteRemap
+ public class PaletteRemap : IPaletteRemap
{
int offset;
List remapColors = new List();
diff --git a/OpenRa.FileFormats/ShroudPaletteRemap.cs b/OpenRa.FileFormats/ShroudPaletteRemap.cs
new file mode 100644
index 0000000000..be08298412
--- /dev/null
+++ b/OpenRa.FileFormats/ShroudPaletteRemap.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Drawing;
+
+namespace OpenRa.FileFormats
+{
+ public class ShroudPaletteRemap : IPaletteRemap
+ {
+ public Color GetRemappedColor(Color original, int index)
+ {
+ // false-color version for debug
+
+ //return new[] {
+ // Color.Orange, Color.Green,
+ // Color.Blue, Color.Yellow,
+ // Color.Black,
+ // Color.Red,
+ // Color.Purple,
+ // Color.Cyan}[index % 8];
+
+ return new[] {
+ Color.Transparent, Color.Green,
+ Color.Blue, Color.Yellow,
+ Color.Black,
+ Color.FromArgb(192,0,0,0),
+ Color.FromArgb(128,0,0,0),
+ Color.FromArgb(64,0,0,0)}[index % 8];
+ }
+ }
+}
diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs
index cb2e3fed1b..777a0d8169 100644
--- a/OpenRa.Game/Game.cs
+++ b/OpenRa.Game/Game.cs
@@ -102,6 +102,12 @@ namespace OpenRa.Game
oreFrequency = (int)(Rules.General.GrowthRate * 60 * 1000);
oreTicks = oreFrequency;
+
+ foreach (var a in Game.world.Actors)
+ if (a.Info != null && a.Owner == players[0])
+ players[0].Shroud.Explore(a);
+
+ Game.world.ActorAdded += a => players[0].Shroud.Explore(a);
}
public static void Initialize(string mapName, Renderer renderer, int2 clientSize,
diff --git a/OpenRa.Game/Graphics/HardwarePalette.cs b/OpenRa.Game/Graphics/HardwarePalette.cs
index 9c0538e61f..2092291dd0 100644
--- a/OpenRa.Game/Graphics/HardwarePalette.cs
+++ b/OpenRa.Game/Graphics/HardwarePalette.cs
@@ -3,7 +3,12 @@ using OpenRa.FileFormats;
namespace OpenRa.Game.Graphics
{
- public enum PaletteType { Gold, Blue, Red, Orange, Teal, Salmon, Green, Gray, Shadow, Invuln, Chrome };
+ public enum PaletteType
+ {
+ Gold, Blue, Red, Orange, Teal, Salmon, Green, Gray,
+ Shadow, Invuln, Chrome, Shroud,
+ };
+
class HardwarePalette : Sheet
{
const int maxEntries = 16;
@@ -21,6 +26,7 @@ namespace OpenRa.Game.Graphics
AddPalette(new Palette(pal, new PaletteRemap(Color.FromArgb(140, 0, 0, 0))));
AddPalette(pal); // iron curtain. todo: remap!
AddPalette(pal); // chrome (it's like gold, but we're not going to hax it in palettemods)
+ AddPalette(new Palette(pal, new ShroudPaletteRemap()));
}
int AddPalette(Palette p)
diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs
index 14bbff4afe..0ababf0272 100644
--- a/OpenRa.Game/Graphics/WorldRenderer.cs
+++ b/OpenRa.Game/Graphics/WorldRenderer.cs
@@ -87,6 +87,8 @@ namespace OpenRa.Game.Graphics
if (Game.controller.orderGenerator != null)
Game.controller.orderGenerator.Render();
+ Game.LocalPlayer.Shroud.Draw(spriteRenderer);
+
lineRenderer.Flush();
spriteRenderer.Flush();
}
diff --git a/OpenRa.Game/Shroud.cs b/OpenRa.Game/Shroud.cs
index a194ecdb15..01d353245e 100644
--- a/OpenRa.Game/Shroud.cs
+++ b/OpenRa.Game/Shroud.cs
@@ -3,15 +3,85 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using IjwFramework.Types;
+using OpenRa.Game.Graphics;
namespace OpenRa.Game
{
class Shroud
{
bool[,] explored = new bool[128, 128];
+ Sprite[] shadowBits = SpriteSheetBuilder.LoadAllSprites("shadow");
+ Sprite[,] sprites = new Sprite[128, 128];
+ bool dirty;
public void Explore(Actor a)
{
+ foreach (var t in Game.FindTilesInCircle(a.Location, a.Info.Sight))
+ explored[t.X, t.Y] = true;
+
+ dirty = true;
+ }
+
+ Sprite ChooseShroud(int i, int j)
+ {
+ // bits are for exploredness: left, right, up, down, self
+ var n = new[] {
+ 0xf,0xf,0xf,0xf,
+ 0xf,0x0f,0x0f,0xf,
+ 0xf,0x0f,0x0f,0xf,
+ 0xf,0xf,0xf,0xf,
+ 0,7,13,0,
+ 14,6,12,4,
+ 11,3,9,1,
+ 0,2,8,0,
+ };
+
+ 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;
+
+ var x = n[v];
+
+ if (x == 0)
+ {
+ // bits are for exploredness: TL, TR, BR, BL
+ var m = new[] {
+ 46, 41, 42, 38,
+ 43, 45, 39, 35,
+ 40, 37, 44, 34,
+ 36, 33, 32, 47,
+ };
+
+ 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;
+ return shadowBits[m[u]];
+ }
+
+ return shadowBits[x];
+ }
+
+ public void Draw(SpriteRenderer r)
+ {
+ if (dirty)
+ {
+ dirty = false;
+ for (int j = 1; j < 127; j++)
+ for (int i = 1; i < 127; i++)
+ sprites[i, j] = ChooseShroud(i, j);
+ }
+
+ for (var j = 0; j < 128; j++)
+ for (var i = 0; i < 128; i++)
+ if (sprites[i,j] != null)
+ r.DrawSprite(sprites[i, j],
+ Game.CellSize * new float2(i, j),
+ PaletteType.Shroud);
}
}
}
diff --git a/OpenRa.Game/Traits/Mobile.cs b/OpenRa.Game/Traits/Mobile.cs
index 4bf3a76e1f..e917df2610 100644
--- a/OpenRa.Game/Traits/Mobile.cs
+++ b/OpenRa.Game/Traits/Mobile.cs
@@ -18,7 +18,16 @@ namespace OpenRa.Game.Traits
public int2 toCell
{
get { return self.Location; }
- set { Game.UnitInfluence.Remove(self, this); self.Location = value; Game.UnitInfluence.Add(self, this); }
+ set
+ {
+ if (self.Location != value)
+ {
+ Game.UnitInfluence.Remove(self, this);
+ self.Location = value;
+ self.Owner.Shroud.Explore(self);
+ }
+ Game.UnitInfluence.Add(self, this);
+ }
}
public Mobile(Actor self)
diff --git a/SequenceEditor/Program.cs b/SequenceEditor/Program.cs
index cdef4b4285..90d01db517 100644
--- a/SequenceEditor/Program.cs
+++ b/SequenceEditor/Program.cs
@@ -83,7 +83,8 @@ namespace SequenceEditor
Doc = new XmlDocument();
Doc.Load(XmlFilename);
- Pal = new Palette(FileSystem.Open("temperat.pal"));
+ var tempPal = new Palette(FileSystem.Open("temperat.pal"));
+ Pal = new Palette(tempPal, new ShroudPaletteRemap());
UnitName = args.FirstOrDefault( x => !x.EndsWith(".xml") );
if (UnitName == null)