Skip to content

Commit

Permalink
Make LaysTerrain Conditional.
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR authored and abcdefg30 committed Oct 6, 2020
1 parent 3ec3eac commit 7372da1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions OpenRA.Mods.D2k/Traits/Buildings/LaysTerrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OpenRA.Mods.D2k.Traits
{
public class LaysTerrainInfo : TraitInfo, Requires<BuildingInfo>
public class LaysTerrainInfo : ConditionalTraitInfo, Requires<BuildingInfo>
{
[Desc("The terrain template to place. If the template is PickAny, then " +
"the actor footprint will be filled with this tile.")]
Expand All @@ -32,17 +32,16 @@ public class LaysTerrainInfo : TraitInfo, Requires<BuildingInfo>
public override object Create(ActorInitializer init) { return new LaysTerrain(init.Self, this); }
}

public class LaysTerrain : INotifyAddedToWorld
public class LaysTerrain : ConditionalTrait<LaysTerrainInfo>, INotifyAddedToWorld
{
readonly LaysTerrainInfo info;
readonly BuildableTerrainLayer layer;
readonly BuildingInfluence bi;
readonly TerrainTemplateInfo template;
readonly BuildingInfo buildingInfo;

public LaysTerrain(Actor self, LaysTerrainInfo info)
: base(info)
{
this.info = info;
layer = self.World.WorldActor.Trait<BuildableTerrainLayer>();
bi = self.World.WorldActor.Trait<BuildingInfluence>();
template = self.World.Map.Rules.TileSet.Templates[info.Template];
Expand All @@ -51,6 +50,9 @@ public LaysTerrain(Actor self, LaysTerrainInfo info)

void INotifyAddedToWorld.AddedToWorld(Actor self)
{
if (IsTraitDisabled)
return;

var map = self.World.Map;

if (template.PickAny)
Expand All @@ -59,7 +61,7 @@ void INotifyAddedToWorld.AddedToWorld(Actor self)
foreach (var c in buildingInfo.Tiles(self.Location))
{
// Only place on allowed terrain types
if (!map.Contains(c) || !info.TerrainTypes.Contains(map.GetTerrainInfo(c).Type))
if (!map.Contains(c) || !Info.TerrainTypes.Contains(map.GetTerrainInfo(c).Type))
continue;

// Don't place under other buildings or custom terrain
Expand All @@ -73,13 +75,13 @@ void INotifyAddedToWorld.AddedToWorld(Actor self)
return;
}

var origin = self.Location + info.Offset;
var origin = self.Location + Info.Offset;
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(map.GetTerrainInfo(c).Type))
if (!Info.TerrainTypes.Contains(map.GetTerrainInfo(c).Type))
continue;

// Don't place under other buildings or custom terrain
Expand Down

0 comments on commit 7372da1

Please sign in to comment.