#1108 changed BuildingInfo.WaterBound to a list of terraintypes. makes it possible to have buildings with custom terrain requirements

This commit is contained in:
Chris Forbes
2011-08-16 18:42:05 +12:00
parent 55ec88316a
commit 67b4ef3084
15 changed files with 27 additions and 84 deletions

View File

@@ -16,20 +16,17 @@ namespace OpenRA.Mods.RA.Buildings
{
public static class BuildingUtils
{
public static bool IsCellBuildable(this World world, int2 a, bool waterBound)
public static bool IsCellBuildable(this World world, int2 a, BuildingInfo bi)
{
return world.IsCellBuildable(a, waterBound, null);
return world.IsCellBuildable(a, bi, null);
}
public static bool IsCellBuildable(this World world, int2 a, bool waterBound, Actor toIgnore)
public static bool IsCellBuildable(this World world, int2 a, BuildingInfo bi, Actor toIgnore)
{
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false;
if (world.ActorMap.GetUnitsAt(a).Any(b => b != toIgnore)) return false;
if (waterBound)
return world.Map.IsInMap(a.X,a.Y) && world.GetTerrainInfo(a).IsWater;
return world.Map.IsInMap(a.X, a.Y) && world.GetTerrainInfo(a).Buildable;
return world.Map.IsInMap(a) && bi.TerrainTypes.Contains(world.GetTerrainType(a));
}
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
@@ -37,7 +34,7 @@ namespace OpenRA.Mods.RA.Buildings
var res = world.WorldActor.Trait<ResourceLayer>();
return FootprintUtils.Tiles(name, building, topLeft).All(
t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null &&
world.IsCellBuildable(t, building.WaterBound, toIgnore));
world.IsCellBuildable(t, building, toIgnore));
}
public static IEnumerable<int2> GetLineBuildCells(World world, int2 location, string name, BuildingInfo bi)
@@ -45,7 +42,7 @@ namespace OpenRA.Mods.RA.Buildings
int range = Rules.Info[name].Traits.Get<LineBuildInfo>().Range;
var topLeft = location; // 1x1 assumption!
if (world.IsCellBuildable(topLeft, bi.WaterBound))
if (world.IsCellBuildable(topLeft, bi))
yield return topLeft;
// Start at place location, search outwards
@@ -60,7 +57,7 @@ namespace OpenRA.Mods.RA.Buildings
continue;
int2 cell = topLeft + i * vecs[d];
if (world.IsCellBuildable(cell, bi.WaterBound))
if (world.IsCellBuildable(cell, bi))
continue; // Cell is empty; continue search
// Cell contains an actor. Is it the type we want?