Unhardcode terrain types. Needs a bit more work re initialization and bridges
This commit is contained in:
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA
|
||||
public object Create(ActorInitializer init) { return new Bridge(init.self); }
|
||||
}
|
||||
|
||||
class Bridge: IRender, INotifyDamage
|
||||
class Bridge //: IRender, INotifyDamage
|
||||
{
|
||||
Dictionary<int2, int> Tiles;
|
||||
List<Dictionary<int2, Sprite>> TileSprites = new List<Dictionary<int2,Sprite>>();
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
|
||||
Bridge northNeighbour, southNeighbour;
|
||||
|
||||
public Bridge(Actor self) { this.self = self; self.RemoveOnDeath = false; }
|
||||
|
||||
|
||||
static string cachedTileset;
|
||||
static Cache<TileReference<ushort,byte>, Sprite> sprites;
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public int StateFromTemplate(TileTemplate t)
|
||||
{
|
||||
/*
|
||||
var info = self.Info.Traits.Get<BridgeInfo>();
|
||||
if (info.UseAlternateNames)
|
||||
{
|
||||
@@ -89,19 +90,23 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
else
|
||||
return t.Name[t.Name.Length - 1] - 'a';
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
public string NameFromState(TileTemplate t, int state)
|
||||
{
|
||||
var info = self.Info.Traits.Get<BridgeInfo>();
|
||||
/*var info = self.Info.Traits.Get<BridgeInfo>();
|
||||
if (info.UseAlternateNames)
|
||||
return t.Bridge + new[] { "", "h", "d" }[state];
|
||||
else
|
||||
return t.Bridge + (char)(state + 'a');
|
||||
return t.Bridge + (char)(state + 'a');*/
|
||||
return "";
|
||||
}
|
||||
|
||||
public void SetTiles(World world, TileTemplate template, Dictionary<int2, int> replacedTiles)
|
||||
{
|
||||
/*
|
||||
Tiles = replacedTiles;
|
||||
state = StateFromTemplate(template);
|
||||
|
||||
@@ -125,12 +130,14 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
|
||||
self.Health = (int)(self.GetMaxHP() * template.HP);
|
||||
*/
|
||||
}
|
||||
|
||||
public string GetTerrainType(int2 cell)
|
||||
{
|
||||
return "";
|
||||
// Ugly hack until terraintypes are converted from enums
|
||||
return Enum.GetName( typeof(TerrainType), Templates[state].TerrainType[Tiles[cell]]);
|
||||
//return Enum.GetName( typeof(TerrainType), Templates[state].TerrainType[Tiles[cell]]);
|
||||
}
|
||||
|
||||
static bool IsIntact(Bridge b)
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
|
||||
void ConvertBridgeToActor(World w, int i, int j)
|
||||
{
|
||||
Log.Write("debug", "Converting bridge at {0} {1}", i, j);
|
||||
|
||||
/*
|
||||
var tile = w.Map.MapTiles[i, j].type;
|
||||
var image = w.Map.MapTiles[i, j].image;
|
||||
var template = w.TileSet.walk[tile];
|
||||
@@ -88,18 +88,20 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
br.SetTiles(w, template, replacedTiles);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public string GetTerrainType(int2 cell)
|
||||
{
|
||||
if (bridges[ cell.X, cell.Y ] != null)
|
||||
return bridges[ cell.X, cell.Y ].GetTerrainType(cell);
|
||||
/*if (bridges[ cell.X, cell.Y ] != null)
|
||||
return bridges[ cell.X, cell.Y ].GetTerrainType(cell);*/
|
||||
return null;
|
||||
}
|
||||
|
||||
static bool IsBridge(World w, ushort t)
|
||||
{
|
||||
return w.TileSet.walk[t].Bridge != null;
|
||||
return false;
|
||||
//return w.TileSet.walk[t].Bridge != null;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w)
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA
|
||||
if (++ticks >= self.Info.Traits.Get<CrateInfo>().Lifetime * 25)
|
||||
self.World.AddFrameEndTask(w => w.Remove(self));
|
||||
|
||||
var seq = self.World.GetTerrainType(cell) == TerrainType.Water ? "water" : "idle";
|
||||
var seq = self.World.GetTerrainType(cell) == "Water" ? "water" : "idle";
|
||||
if (seq != self.traits.Get<RenderSimple>().anim.CurrentSequence.Name)
|
||||
self.traits.Get<RenderSimple>().anim.PlayRepeating(seq);
|
||||
}
|
||||
|
||||
@@ -70,10 +70,8 @@ namespace OpenRA.Mods.RA
|
||||
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
||||
|
||||
// Is this valid terrain?
|
||||
// Ugly hack until terraintypes are converted from enums
|
||||
var terrainType = self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y]);
|
||||
var terrain = Enum.GetName( typeof(TerrainType), terrainType);
|
||||
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrain)) continue;
|
||||
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue;
|
||||
|
||||
// Don't drop on any actors
|
||||
if (self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(p) != null) continue;
|
||||
|
||||
@@ -70,10 +70,8 @@ namespace OpenRA.Mods.RA
|
||||
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
||||
|
||||
// Is this valid terrain?
|
||||
// Ugly hack until terraintypes are converted from enums
|
||||
var terrainType = self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y]);
|
||||
var terrain = Enum.GetName( typeof(TerrainType), terrainType);
|
||||
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrain)) continue;
|
||||
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue;
|
||||
|
||||
// Don't spawn on any actors
|
||||
if (self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(p) != null) continue;
|
||||
|
||||
Reference in New Issue
Block a user