Bridge destruction etc works

This commit is contained in:
Paul Chote
2010-06-27 15:58:57 +12:00
parent cdbe2d3a34
commit 25f2268f58
4 changed files with 57 additions and 35 deletions

View File

@@ -34,7 +34,6 @@ namespace OpenRA.Mods.RA
public readonly bool Long = false; public readonly bool Long = false;
public readonly ushort Template; public readonly ushort Template;
public readonly float DamagedThreshold = 0.5f;
public readonly ushort DamagedTemplate; public readonly ushort DamagedTemplate;
public readonly ushort DestroyedTemplate; public readonly ushort DestroyedTemplate;
@@ -42,6 +41,7 @@ namespace OpenRA.Mods.RA
public readonly ushort DestroyedPlusNorthTemplate; public readonly ushort DestroyedPlusNorthTemplate;
public readonly ushort DestroyedPlusSouthTemplate; public readonly ushort DestroyedPlusSouthTemplate;
public readonly ushort DestroyedPlusBothTemplate; public readonly ushort DestroyedPlusBothTemplate;
public readonly string[] ShorePieces = {"br1", "br2"};
public readonly bool UseAlternateNames = false; public readonly bool UseAlternateNames = false;
public readonly int[] NorthOffset = null; public readonly int[] NorthOffset = null;
@@ -85,21 +85,24 @@ namespace OpenRA.Mods.RA
BridgeInfo info; BridgeInfo info;
Bridge northNeighbour, southNeighbour; Bridge northNeighbour, southNeighbour;
public string Type;
public Bridge(Actor self, BridgeInfo info) public Bridge(Actor self, BridgeInfo info)
{ {
this.self = self; this.self = self;
self.RemoveOnDeath = false; self.RemoveOnDeath = false;
this.info = info; this.info = info;
this.Type = self.Info.Name;
} }
public void Create(ushort template, Dictionary<int2, byte> subtiles) public void Create(ushort template, Dictionary<int2, byte> subtiles)
{ {
currentTemplate = template; currentTemplate = template;
if (template == info.DamagedTemplate) if (template == info.DamagedTemplate)
self.Health = (int)(info.DamagedThreshold*self.GetMaxHP()); self.Health = (int)(self.World.Defaults.ConditionYellow*self.GetMaxHP());
else if (template != info.Template) else if (template != info.Template)
self.Health = 0; self.Health = 0;
// Create a new cache to store the tile data // Create a new cache to store the tile data
if (cachedTileset != self.World.Map.Tileset) if (cachedTileset != self.World.Map.Tileset)
{ {
@@ -148,7 +151,7 @@ namespace OpenRA.Mods.RA
yield return new Renderable(t.Value, Game.CellSize * t.Key, "terrain"); yield return new Renderable(t.Value, Game.CellSize * t.Key, "terrain");
} }
static bool IsIntact(Bridge b) bool IsIntact(Bridge b)
{ {
return b != null && b.self.IsInWorld && b.self.Health > 0; return b != null && b.self.IsInWorld && b.self.Health > 0;
} }
@@ -159,32 +162,44 @@ namespace OpenRA.Mods.RA
} }
void UpdateState() void UpdateState()
{ {
/*var ds = self.GetDamageState(); var ds = self.GetDamageState();
if (!self.Info.Traits.Get<BridgeInfo>().Long)
// If this is a long bridge next to a destroyed shore piece, we need die to give clean edges to the break
if (info.Long && ds != DamageState.Dead &&
((southNeighbour != null && info.ShorePieces.Contains(southNeighbour.Type) && !IsIntact(southNeighbour)) ||
(northNeighbour != null && info.ShorePieces.Contains(northNeighbour.Type) && !IsIntact(northNeighbour))))
{ {
state = (int)ds; self.Health = 0;
return; ds = DamageState.Dead;
} }
currentTemplate = (ds == DamageState.Half && info.DamagedTemplate > 0) ? info.DamagedTemplate :
(ds == DamageState.Dead && info.DestroyedTemplate > 0) ? info.DestroyedTemplate : info.Template;
bool waterToSouth = !IsIntact(southNeighbour) && (!IsLong(southNeighbour) || !IsIntact(this)); if (!(info.Long && ds == DamageState.Dead))
bool waterToNorth = !IsIntact(northNeighbour) && (!IsLong(northNeighbour) || !IsIntact(this)); return;
if (waterToSouth && waterToNorth) { state = 5; return; } // Long bridges have custom art for multiple segments being destroyed
if (waterToNorth) { state = 4; return; } bool waterToSouth = !IsIntact(southNeighbour);
if (waterToSouth) { state = 3; return; } bool waterToNorth = !IsIntact(northNeighbour);
state = (int)ds;
*/ if (waterToSouth && waterToNorth)
currentTemplate = info.DestroyedPlusBothTemplate;
else if (waterToNorth)
currentTemplate = info.DestroyedPlusNorthTemplate;
else if (waterToSouth)
currentTemplate = info.DestroyedPlusSouthTemplate;
} }
public void Damaged(Actor self, AttackInfo e) public void Damaged(Actor self, AttackInfo e)
{ {
/*if (e.DamageStateChanged) if (e.DamageStateChanged)
{ {
UpdateState(); UpdateState();
if (northNeighbour != null) northNeighbour.UpdateState(); if (northNeighbour != null) northNeighbour.UpdateState();
if (southNeighbour != null) southNeighbour.UpdateState(); if (southNeighbour != null) southNeighbour.UpdateState();
}*/ }
} }
} }
} }

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA
{ {
class BridgeLayerInfo : ITraitInfo class BridgeLayerInfo : ITraitInfo
{ {
public readonly string[] Bridges = {"br1", "br2", "br3", "bridge1", "bridge2"}; public readonly string[] Bridges = {"bridge1", "bridge2"};
public object Create(ActorInitializer init) { return new BridgeLayer(init.self, this); } public object Create(ActorInitializer init) { return new BridgeLayer(init.self, this); }
} }
@@ -95,21 +95,26 @@ namespace OpenRA.Mods.RA
var bridge = w.CreateActor(BridgeTypes[tile], new int2(ni, nj), w.WorldActor.Owner).traits.Get<Bridge>(); var bridge = w.CreateActor(BridgeTypes[tile], new int2(ni, nj), w.WorldActor.Owner).traits.Get<Bridge>();
Dictionary<int2, byte> subTiles = new Dictionary<int2, byte>(); Dictionary<int2, byte> subTiles = new Dictionary<int2, byte>();
// Loop through the cells on the bridge template; mark each cell that is part // For each subtile in the template
// of the bridge and add to the bridges array for (byte ind = 0; ind < template.Size.X*template.Size.Y; ind++)
for (var x = ni; x < ni + template.Size.X; x++) {
for (var y = nj; y < nj + template.Size.Y; y++) // Is this tile actually included in the bridge template?
{ if (!template.Tiles.Keys.Contains(ind))
// This isn't the bridge we're looking for continue;
if (!w.Map.IsInMap(x, y) || w.Map.MapTiles[x, y].type != tile)
continue; // Where do we expect to find the subtile
var x = ni + ind % template.Size.X;
Log.Write("debug", "Adding tile {0} {1} for type {2}", x,y,tile); var y = nj + ind / template.Size.X;
subTiles.Add(new int2(x,y),w.Map.MapTiles[x, y].image); // This isn't the bridge you're looking for
Bridges[x,y] = bridge; if (!w.Map.IsInMap(x, y) || w.Map.MapTiles[x, y].image != ind)
} continue;
Log.Write("debug", "Adding tile {0} {1} for type {2}", x,y,tile);
subTiles.Add(new int2(x,y),ind);
Bridges[x,y] = bridge;
}
bridge.Create(tile, subTiles); bridge.Create(tile, subTiles);
} }

View File

@@ -411,6 +411,7 @@ BR3:
Inherits: ^Bridge Inherits: ^Bridge
Bridge: Bridge:
Long: yes Long: yes
ShorePieces: br1,br2
Template: 241 Template: 241
DamagedTemplate: 242 DamagedTemplate: 242
DestroyedTemplate: 243 DestroyedTemplate: 243

View File

@@ -95,6 +95,7 @@ World:
UnitInfluence: UnitInfluence:
ChoosePaletteOnSelect: ChoosePaletteOnSelect:
BridgeLayer: BridgeLayer:
Bridges: bridge1, bridge2, br1, br2, br3
CrateDrop: CrateDrop:
Minimum: 1 Minimum: 1
Maximum: 3 Maximum: 3