Change terrain type from string based dictionaries to arrays

This commit is contained in:
Pavlos Touboulidis
2014-05-25 15:46:36 +03:00
parent b8cdb224d1
commit 092352729f
23 changed files with 265 additions and 137 deletions

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Buildings
var cellOffset = new CVec(i % width, i / width + bibOffset);
// Some mods may define terrain-specific bibs
var terrain = self.World.GetTerrainType(location + cellOffset);
var terrain = self.World.GetTerrainInfo(location + cellOffset).Type;
var testSequence = info.Sequence + "-" + terrain;
var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence;
anim.PlayFetchIndex(sequence, () => index);

View File

@@ -54,34 +54,34 @@ namespace OpenRA.Mods.RA.Buildings
foreach (var c in FootprintUtils.Tiles(self))
{
// Only place on allowed terrain types
if (!info.TerrainTypes.Contains(self.World.GetTerrainType(c)))
if (!info.TerrainTypes.Contains(self.World.GetTerrainInfo(c).Type))
continue;
// Don't place under other buildings or custom terrain
if (bi.GetBuildingAt(c) != self || self.World.Map.CustomTerrain[c.X, c.Y] != null)
if (bi.GetBuildingAt(c) != self || self.World.Map.CustomTerrain[c.X, c.Y] != -1)
continue;
var index = template.Tiles.Keys.Random(Game.CosmeticRandom);
layer.AddTile(c, new TileReference<ushort, byte>(template.Id, index));
var index = Game.CosmeticRandom.Next(template.TilesCount);
layer.AddTile(c, new TileReference<ushort, byte>(template.Id, (byte)index));
}
return;
}
var origin = self.Location + info.Offset;
foreach (var i in template.Tiles.Keys)
for (var i = 0; i < template.TilesCount; i++)
{
var c = origin + new CVec(i % template.Size.X, i / template.Size.X);
// Only place on allowed terrain types
if (!info.TerrainTypes.Contains(self.World.GetTerrainType(c)))
if (!info.TerrainTypes.Contains(self.World.GetTerrainInfo(c).Type))
continue;
// Don't place under other buildings or custom terrain
if (bi.GetBuildingAt(c) != self || self.World.Map.CustomTerrain[c.X, c.Y] != null)
if (bi.GetBuildingAt(c) != self || self.World.Map.CustomTerrain[c.X, c.Y] != -1)
continue;
layer.AddTile(c, new TileReference<ushort, byte>(template.Id, i));
layer.AddTile(c, new TileReference<ushort, byte>(template.Id, (byte)i));
}
}
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Buildings
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false;
if (world.ActorMap.GetUnitsAt(a).Any(b => b != toIgnore)) return false;
return world.Map.IsInMap(a) && bi.TerrainTypes.Contains(world.GetTerrainType(a));
return world.Map.IsInMap(a) && bi.TerrainTypes.Contains(world.GetTerrainInfo(a).Type);
}
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore)