Add a DamagesConcreteWarhead to remove buildable concrete.

This commit is contained in:
Matthias Mailänder
2018-09-13 21:17:32 +02:00
committed by abcdefg30
parent 7438af8266
commit 399e451ada
8 changed files with 104 additions and 0 deletions

View File

@@ -21,6 +21,9 @@ namespace OpenRA.Mods.D2k.Traits
[Desc("Palette to render the layer sprites in.")]
public readonly string Palette = TileSet.TerrainPaletteInternalName;
[Desc("The hitpoints, which can be reduced by the DamagesConcreteWarhead.")]
public readonly int MaxStrength = 9000;
public object Create(ActorInitializer init) { return new BuildableTerrainLayer(init.Self, this); }
}
@@ -29,6 +32,7 @@ namespace OpenRA.Mods.D2k.Traits
readonly BuildableTerrainLayerInfo info;
readonly Dictionary<CPos, Sprite> dirty = new Dictionary<CPos, Sprite>();
readonly Map map;
readonly CellLayer<int> strength;
TerrainSpriteLayer render;
Theater theater;
@@ -38,6 +42,7 @@ namespace OpenRA.Mods.D2k.Traits
{
this.info = info;
map = self.World.Map;
strength = new CellLayer<int>(self.World.Map);
}
public void WorldLoaded(World w, WorldRenderer wr)
@@ -49,12 +54,30 @@ namespace OpenRA.Mods.D2k.Traits
public void AddTile(CPos cell, TerrainTile tile)
{
map.CustomTerrain[cell] = map.Rules.TileSet.GetTerrainIndex(tile);
strength[cell] = info.MaxStrength;
// Terrain tiles define their origin at the topleft
var s = theater.TileSprite(tile);
dirty[cell] = new Sprite(s.Sheet, s.Bounds, s.ZRamp, float2.Zero, s.Channel, s.BlendMode);
}
public void HitTile(CPos cell, int damage)
{
if (strength[cell] == 0)
return;
strength[cell] = strength[cell] - damage;
if (strength[cell] < 1)
RemoveTile(cell);
}
public void RemoveTile(CPos cell)
{
map.CustomTerrain[cell] = byte.MaxValue;
strength[cell] = 0;
dirty[cell] = null;
}
void ITickRender.TickRender(WorldRenderer wr, Actor self)
{
var remove = new List<CPos>();