merged pchote/master

This commit is contained in:
Chris Forbes
2010-01-15 17:30:37 +13:00
10 changed files with 175 additions and 54 deletions

View File

@@ -16,31 +16,78 @@ namespace OpenRa.Game
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; }
set { hasGPS = value; dirty = true;}
}
public void Tick()
{
// Clear active flags
gapActive = new bool[128, 128];
foreach (var a in Game.world.Actors.Where(a => a.traits.Contains<GeneratesGap>()))
{
foreach (var t in a.traits.Get<GeneratesGap>().GetShroudedTiles())
gapActive[t.X, t.Y] = true;
}
for (int j = 1; j < 127; j++)
for (int i = 1; i < 127; i++)
{
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;
}
}
public bool IsExplored(int2 xy) { return IsExplored(xy.X, xy.Y); }
public bool IsExplored(int x, int y)
{
if (gapField[ x, y ] >= Rules.General.GapRegenInterval * 25 * 60)
return false;
if (hasGPS)
return true;
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.Traits.Get<OwnedActorInfo>().Sight))
a.Info.Traits.Get<OwnedActorInfo>().Sight))
{
explored[t.X, t.Y] = true;
gapField[t.X, t.Y] = 0;
}
dirty = true;
}
static readonly byte[][] SpecialShroudTiles =
{
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
@@ -60,7 +107,7 @@ namespace OpenRa.Game
new byte[] { 41 },
new byte[] { 46 },
};
Sprite ChooseShroud(int i, int j)
{
if( !IsExplored( i, j ) ) return shadowBits[ 0xf ];
@@ -69,7 +116,7 @@ namespace OpenRa.Game
var v = 0;
// bits are for unexploredness: TL, TR, BR, BL
var u = 0;
if( !IsExplored( i, j - 1 ) ) { v |= 1; u |= 3; }
if( !IsExplored( i + 1, j ) ) { v |= 2; u |= 6; }
if( !IsExplored( i, j + 1 ) ) { v |= 4; u |= 12; }
@@ -82,7 +129,7 @@ namespace OpenRa.Game
if( !IsExplored( i + 1, j + 1 ) ) u |= 4;
if( !IsExplored( i - 1, j + 1 ) ) u |= 8;
return shadowBits[ SpecialShroudTiles[ u ^ uSides ][ v ] ];
return shadowBits[ SpecialShroudTiles[ u ^ uSides ][ v ] ];
}
public void Draw(SpriteRenderer r)