Gap generators

This commit is contained in:
Paul Chote
2010-01-12 00:03:00 +13:00
parent b86f76ce8c
commit bf1e7b86e1
6 changed files with 65 additions and 6 deletions

View File

@@ -482,8 +482,6 @@ namespace OpenRa.Game
void TickPaletteAnimation()
{
Log.Write("{0} {1} {2} {3}", paletteAnimationFrame, paletteOrigin.X, paletteAnimating, paletteOpen);
if (!paletteAnimating)
return;

View File

@@ -227,6 +227,7 @@
<Compile Include="Traits\Explodes.cs" />
<Compile Include="Traits\ChronoshiftDeploy.cs" />
<Compile Include="Traits\Fake.cs" />
<Compile Include="Traits\GeneratesGap.cs" />
<Compile Include="Traits\GpsLaunchSite.cs" />
<Compile Include="Traits\Harvester.cs" />
<Compile Include="Traits\Helicopter.cs" />

View File

@@ -130,6 +130,7 @@ namespace OpenRa.Game
{
UpdatePower();
UpdateOreCapacity();
Shroud.Tick();
foreach (var sp in SupportPowers.Values)
sp.Tick();

View File

@@ -4,12 +4,14 @@ using System.Linq;
using System.Text;
using IjwFramework.Types;
using OpenRa.Game.Graphics;
using OpenRa.Game.Traits;
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;
@@ -21,9 +23,35 @@ namespace OpenRa.Game
set { hasGPS = value; dirty = true;}
}
public void Tick()
{
// This is probably slow
bool[,] 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]) /*0 >= --gapField[i, j]*/
{
gapField[i, j] = 0;
dirty = true;
}
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;
@@ -33,8 +61,10 @@ namespace OpenRa.Game
public void Explore(Actor a)
{
foreach (var t in Game.FindTilesInCircle((1f / Game.CellSize * a.CenterLocation).ToInt2(), a.Info.Sight))
{
explored[t.X, t.Y] = true;
gapField[t.X, t.Y] = 0;
}
dirty = true;
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRa.FileFormats;
using OpenRa.Game.Support;
using OpenRa.Game.Traits;
namespace OpenRa.Game.Traits
{
class GeneratesGap
{
Actor self;
public GeneratesGap(Actor self)
{
this.self = self;
}
public IEnumerable<int2>GetShroudedTiles()
{
// Gap Generator building; powered down
if (self.traits.Contains<Building>() && self.traits.Get<Building>().Disabled)
yield break;
// It won't let me return Game.FindTilesInCircle directly...?
foreach (var t in Game.FindTilesInCircle(self.Location, Rules.General.GapRadius))
yield return t;
}
}
}

View File

@@ -77,7 +77,7 @@ Voice=VehicleVoice
LongDesc=Hides nearby units on the enemy's minimap.\n Unarmed
[MGG]
Description=Mobile Gap Generator
Traits=Unit, Mobile, RenderUnitSpinner, Repairable, Chronoshiftable, Passenger, IronCurtainable
Traits=Unit, Mobile, RenderUnitSpinner, Repairable, Chronoshiftable, Passenger, IronCurtainable, GeneratesGap
PrimaryOffset=0,6,0,-3
SelectionPriority=3
Voice=VehicleVoice
@@ -303,7 +303,7 @@ SelectionPriority=3
LongDesc=Teleports a unit from one place \nto another, for a limited time.\n Special Ability: Chronoshift
[GAP]
Description=Gap Generator
Traits=Building, RenderBuilding, IronCurtainable
Traits=Building, RenderBuilding, IronCurtainable, GeneratesGap
Dimensions=1,2
Footprint=_ x
SelectionPriority=3