Move LaysTerrain functionality to D2kBuilding
This commit is contained in:
committed by
Matthias Mailänder
parent
6b2920cc91
commit
99ec119ffd
@@ -36,17 +36,27 @@ namespace OpenRA.Mods.D2k.Traits.Buildings
|
|||||||
[Desc("Inflict damage down to the DamageThreshold when the actor gets created on damaging terrain.")]
|
[Desc("Inflict damage down to the DamageThreshold when the actor gets created on damaging terrain.")]
|
||||||
public readonly bool StartOnThreshold = true;
|
public readonly bool StartOnThreshold = true;
|
||||||
|
|
||||||
|
[Desc("The terrain template to place when adding a concrete foundation. " +
|
||||||
|
"If the template is PickAny, then the actor footprint will be filled with this tile.")]
|
||||||
|
public readonly ushort ConcreteTemplate = 88;
|
||||||
|
|
||||||
|
[Desc("List of required prerequisites to place a terrain template.")]
|
||||||
|
public readonly string[] ConcretePrerequisites = { };
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new D2kBuilding(init, this); }
|
public override object Create(ActorInitializer init) { return new D2kBuilding(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class D2kBuilding : Building, ITick, INotifyCreated
|
public class D2kBuilding : Building, ITick, INotifyCreated
|
||||||
{
|
{
|
||||||
readonly D2kBuildingInfo info;
|
readonly D2kBuildingInfo info;
|
||||||
|
|
||||||
|
BuildableTerrainLayer layer;
|
||||||
IHealth health;
|
IHealth health;
|
||||||
int safeTiles;
|
int safeTiles;
|
||||||
int totalTiles;
|
int totalTiles;
|
||||||
int damageThreshold;
|
int damageThreshold;
|
||||||
int damageTicks;
|
int damageTicks;
|
||||||
|
TechTree techTree;
|
||||||
|
|
||||||
public D2kBuilding(ActorInitializer init, D2kBuildingInfo info)
|
public D2kBuilding(ActorInitializer init, D2kBuildingInfo info)
|
||||||
: base(init, info)
|
: base(init, info)
|
||||||
@@ -57,12 +67,51 @@ namespace OpenRA.Mods.D2k.Traits.Buildings
|
|||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
{
|
{
|
||||||
health = self.TraitOrDefault<IHealth>();
|
health = self.TraitOrDefault<IHealth>();
|
||||||
|
layer = self.World.WorldActor.TraitOrDefault<BuildableTerrainLayer>();
|
||||||
|
techTree = self.Owner.PlayerActor.TraitOrDefault<TechTree>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void AddedToWorld(Actor self)
|
protected override void AddedToWorld(Actor self)
|
||||||
{
|
{
|
||||||
base.AddedToWorld(self);
|
base.AddedToWorld(self);
|
||||||
|
|
||||||
|
if (layer != null && (!info.ConcretePrerequisites.Any() || techTree == null || techTree.HasPrerequisites(info.ConcretePrerequisites)))
|
||||||
|
{
|
||||||
|
var map = self.World.Map;
|
||||||
|
var template = map.Rules.TileSet.Templates[info.ConcreteTemplate];
|
||||||
|
if (template.PickAny)
|
||||||
|
{
|
||||||
|
// Fill the footprint with random variants
|
||||||
|
foreach (var c in info.Tiles(self.Location))
|
||||||
|
{
|
||||||
|
if (!map.Contains(c) || map.CustomTerrain[c] != byte.MaxValue)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Don't place under other buildings
|
||||||
|
if (self.World.ActorMap.GetActorsAt(c).Any(a => a != self && a.TraitOrDefault<Building>() != null))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var index = Game.CosmeticRandom.Next(template.TilesCount);
|
||||||
|
layer.AddTile(c, new TerrainTile(template.Id, (byte)index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (var i = 0; i < template.TilesCount; i++)
|
||||||
|
{
|
||||||
|
var c = self.Location + new CVec(i % template.Size.X, i / template.Size.X);
|
||||||
|
if (!map.Contains(c) || map.CustomTerrain[c] != byte.MaxValue)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Don't place under other buildings
|
||||||
|
if (self.World.ActorMap.GetActorsAt(c).Any(a => a != self && a.TraitOrDefault<Building>() != null))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
layer.AddTile(c, new TerrainTile(template.Id, (byte)i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (health == null)
|
if (health == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -409,6 +409,7 @@
|
|||||||
Footprint: x
|
Footprint: x
|
||||||
TerrainTypes: Rock, Concrete
|
TerrainTypes: Rock, Concrete
|
||||||
BuildSounds: BUILD1.WAV
|
BuildSounds: BUILD1.WAV
|
||||||
|
ConcretePrerequisites: global-auto-concrete
|
||||||
D2kActorPreviewPlaceBuildingPreview:
|
D2kActorPreviewPlaceBuildingPreview:
|
||||||
RequiresPrerequisites: !global-auto-concrete
|
RequiresPrerequisites: !global-auto-concrete
|
||||||
OverridePalette: placebuilding
|
OverridePalette: placebuilding
|
||||||
@@ -448,13 +449,6 @@
|
|||||||
SellSounds: BUILD1.WAV
|
SellSounds: BUILD1.WAV
|
||||||
Guardable:
|
Guardable:
|
||||||
Range: 3c0
|
Range: 3c0
|
||||||
GrantConditionOnPrerequisite@AUTOCONCRETE:
|
|
||||||
Condition: auto-concrete
|
|
||||||
Prerequisites: global-auto-concrete
|
|
||||||
LaysTerrain:
|
|
||||||
RequiresCondition: auto-concrete
|
|
||||||
TerrainTypes: Rock
|
|
||||||
Template: 88
|
|
||||||
ThrowsShrapnel:
|
ThrowsShrapnel:
|
||||||
Weapons: Debris, Debris2, Debris3, Debris4
|
Weapons: Debris, Debris2, Debris3, Debris4
|
||||||
Pieces: 2, 5
|
Pieces: 2, 5
|
||||||
|
|||||||
@@ -9,9 +9,6 @@
|
|||||||
RequiresBuildableArea:
|
RequiresBuildableArea:
|
||||||
AreaTypes: building
|
AreaTypes: building
|
||||||
Adjacent: 4
|
Adjacent: 4
|
||||||
LaysTerrain:
|
|
||||||
Template: 88
|
|
||||||
TerrainTypes: Rock
|
|
||||||
Tooltip:
|
Tooltip:
|
||||||
Name: Concrete
|
Name: Concrete
|
||||||
GenericName: Structure
|
GenericName: Structure
|
||||||
@@ -63,9 +60,7 @@ construction_yard:
|
|||||||
Footprint: xxx xxx ===
|
Footprint: xxx xxx ===
|
||||||
Dimensions: 3,3
|
Dimensions: 3,3
|
||||||
LocalCenterOffset: 0,-512,0
|
LocalCenterOffset: 0,-512,0
|
||||||
LaysTerrain:
|
-ConcretePrerequisites:
|
||||||
-RequiresCondition:
|
|
||||||
-GrantConditionOnPrerequisite@AUTOCONCRETE:
|
|
||||||
WithBuildingBib:
|
WithBuildingBib:
|
||||||
Selectable:
|
Selectable:
|
||||||
Bounds: 96,64
|
Bounds: 96,64
|
||||||
|
|||||||
Reference in New Issue
Block a user