Pass ActorInfo through building-placement-validation code.
This commit is contained in:
committed by
abcdefg30
parent
8ea1da1046
commit
6b24271a17
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public static class BuildingUtils
|
||||
{
|
||||
public static bool IsCellBuildable(this World world, CPos cell, BuildingInfo bi, Actor toIgnore = null)
|
||||
public static bool IsCellBuildable(this World world, CPos cell, ActorInfo ai, BuildingInfo bi, Actor toIgnore = null)
|
||||
{
|
||||
if (!world.Map.Contains(cell))
|
||||
return false;
|
||||
@@ -38,23 +38,23 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return bi.TerrainTypes.Contains(world.Map.GetTerrainInfo(cell).Type);
|
||||
}
|
||||
|
||||
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore)
|
||||
public static bool CanPlaceBuilding(this World world, CPos cell, ActorInfo ai, BuildingInfo bi, Actor toIgnore)
|
||||
{
|
||||
if (building.AllowInvalidPlacement)
|
||||
if (bi.AllowInvalidPlacement)
|
||||
return true;
|
||||
|
||||
var res = world.WorldActor.TraitOrDefault<ResourceLayer>();
|
||||
return building.Tiles(topLeft).All(
|
||||
return bi.Tiles(cell).All(
|
||||
t => world.Map.Contains(t) && (res == null || res.GetResource(t) == null) &&
|
||||
world.IsCellBuildable(t, building, toIgnore));
|
||||
world.IsCellBuildable(t, ai, bi, toIgnore));
|
||||
}
|
||||
|
||||
public static IEnumerable<Pair<CPos, Actor>> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
|
||||
public static IEnumerable<Pair<CPos, Actor>> GetLineBuildCells(World world, CPos cell, ActorInfo ai, BuildingInfo bi)
|
||||
{
|
||||
var lbi = world.Map.Rules.Actors[name].TraitInfo<LineBuildInfo>();
|
||||
var topLeft = location; // 1x1 assumption!
|
||||
var lbi = ai.TraitInfo<LineBuildInfo>();
|
||||
var topLeft = cell; // 1x1 assumption!
|
||||
|
||||
if (world.IsCellBuildable(topLeft, bi))
|
||||
if (world.IsCellBuildable(topLeft, ai, bi))
|
||||
yield return Pair.New<CPos, Actor>(topLeft, null);
|
||||
|
||||
// Start at place location, search outwards
|
||||
@@ -70,12 +70,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (dirs[d] != 0)
|
||||
continue;
|
||||
|
||||
var cell = topLeft + i * vecs[d];
|
||||
if (world.IsCellBuildable(cell, bi))
|
||||
var c = topLeft + i * vecs[d];
|
||||
if (world.IsCellBuildable(c, ai, bi))
|
||||
continue; // Cell is empty; continue search
|
||||
|
||||
// Cell contains an actor. Is it the type we want?
|
||||
connectors[d] = world.ActorMap.GetActorsAt(cell)
|
||||
connectors[d] = world.ActorMap.GetActorsAt(c)
|
||||
.FirstOrDefault(a => a.Info.TraitInfos<LineBuildNodeInfo>()
|
||||
.Any(info => info.Types.Overlaps(lbi.NodeTypes) && info.Connections.Contains(vecs[d])));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user