Implement ground-level bridge destruction and repair.

This commit is contained in:
Paul Chote
2016-11-11 19:07:12 +00:00
parent 1101218962
commit 69e3c538d9
15 changed files with 648 additions and 156 deletions

View File

@@ -16,27 +16,47 @@ namespace OpenRA.Mods.Common.Activities
{ {
class RepairBridge : Enter class RepairBridge : Enter
{ {
readonly Actor target;
readonly LegacyBridgeHut legacyHut; readonly LegacyBridgeHut legacyHut;
readonly BridgeHut hut;
readonly string notification; readonly string notification;
public RepairBridge(Actor self, Actor target, EnterBehaviour enterBehaviour, string notification) public RepairBridge(Actor self, Actor target, EnterBehaviour enterBehaviour, string notification)
: base(self, target, enterBehaviour) : base(self, target, enterBehaviour)
{ {
legacyHut = target.Trait<LegacyBridgeHut>(); this.target = target;
legacyHut = target.TraitOrDefault<LegacyBridgeHut>();
hut = target.TraitOrDefault<BridgeHut>();
this.notification = notification; this.notification = notification;
} }
protected override bool CanReserve(Actor self) protected override bool CanReserve(Actor self)
{ {
return legacyHut.BridgeDamageState != DamageState.Undamaged && !legacyHut.Repairing && legacyHut.Bridge.GetHut(0) != null && legacyHut.Bridge.GetHut(1) != null; if (legacyHut != null)
return legacyHut.BridgeDamageState != DamageState.Undamaged && !legacyHut.Repairing && legacyHut.Bridge.GetHut(0) != null && legacyHut.Bridge.GetHut(1) != null;
if (hut != null)
return hut.BridgeDamageState != DamageState.Undamaged && !hut.Repairing;
return false;
} }
protected override void OnInside(Actor self) protected override void OnInside(Actor self)
{ {
if (legacyHut.BridgeDamageState == DamageState.Undamaged || legacyHut.Repairing || legacyHut.Bridge.GetHut(0) == null || legacyHut.Bridge.GetHut(1) == null) if (legacyHut != null)
return; {
if (legacyHut.BridgeDamageState == DamageState.Undamaged || legacyHut.Repairing || legacyHut.Bridge.GetHut(0) == null || legacyHut.Bridge.GetHut(1) == null)
return;
legacyHut.Repair(self); legacyHut.Repair(self);
}
else if (hut != null)
{
if (hut.BridgeDamageState == DamageState.Undamaged || hut.Repairing)
return;
hut.Repair(target, self);
}
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", notification, self.Owner.Faction.InternalName); Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", notification, self.Owner.Faction.InternalName);
} }

View File

@@ -777,6 +777,10 @@
<Compile Include="Traits\Upgrades\GrantCondition.cs" /> <Compile Include="Traits\Upgrades\GrantCondition.cs" />
<Compile Include="Traits\Upgrades\ExternalConditions.cs" /> <Compile Include="Traits\Upgrades\ExternalConditions.cs" />
<Compile Include="Traits\Upgrades\StackedCondition.cs" /> <Compile Include="Traits\Upgrades\StackedCondition.cs" />
<Compile Include="Traits\Buildings\BridgeHut.cs" />
<Compile Include="Traits\Buildings\BridgePlaceholder.cs" />
<Compile Include="Traits\Buildings\GroundLevelBridge.cs" />
<Compile Include="Traits\World\BridgeLayer.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild"> <Target Name="AfterBuild">

View File

@@ -0,0 +1,223 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Allows bridges to be targeted for demolition and repair.")]
class BridgeHutInfo : IDemolishableInfo, ITraitInfo
{
[Desc("Bridge types to act on")]
public readonly string[] Types = { "GroundLevelBridge" };
[Desc("Offsets to look for adjacent bridges to act on")]
public readonly CVec[] NeighbourOffsets = { };
[Desc("Delay between each segment repair step")]
public readonly int RepairPropagationDelay = 20;
[Desc("Delay between each segment demolish step")]
public readonly int DemolishPropagationDelay = 5;
[Desc("Hide the repair cursor if the bridge is only damaged (not destroyed)")]
public readonly bool RequireForceAttackForHeal = false;
public bool IsValidTarget(ActorInfo actorInfo, Actor saboteur) { return false; } // TODO: bridges don't support frozen under fog
public object Create(ActorInitializer init) { return new BridgeHut(init.World, this); }
}
class BridgeHut : INotifyCreated, IDemolishable, ITick
{
public readonly BridgeHutInfo Info;
readonly BridgeLayer bridgeLayer;
// Fixed at map load
readonly List<CPos[]> segmentLocations = new List<CPos[]>();
// Changes as segments are killed and repaired
readonly Dictionary<CPos, IBridgeSegment> segments = new Dictionary<CPos, IBridgeSegment>();
readonly HashSet<CPos> dirtyLocations = new HashSet<CPos>();
// Enabled during a repair action
int repairStep;
int repairDelay;
Actor repairRepairer;
// Enabled during a demolish action
int demolishStep;
int demolishDelay;
Actor demolishSaboteur;
public BridgeHut(World world, BridgeHutInfo info)
{
Info = info;
bridgeLayer = world.WorldActor.Trait<BridgeLayer>();
}
void INotifyCreated.Created(Actor self)
{
self.World.AddFrameEndTask(w =>
{
// Bridge segments and huts are expected to be placed in the map
// editor or spawned during the normal actor loading
//
// The number and location of bridge segments are calculated here,
// and assumed to not change for the remaining lifetime of the world
//
// Bridge segment footprints and neighbour offsets are assumed to remain
// the same when a segment is destroyed or repaired.
var seed = Info.NeighbourOffsets.Select(v => self.Location + v);
var processed = new HashSet<CPos>();
while (true)
{
var step = NextNeighbourStep(seed, processed).ToList();
if (!step.Any())
break;
foreach (var s in step)
segments[s.Location] = s;
segmentLocations.Add(step.Select(s => s.Location).ToArray());
seed = step.SelectMany(s => s.NeighbourOffsets.Select(n => s.Location + n)).ToList();
}
repairStep = demolishStep = segmentLocations.Count;
});
}
void ITick.Tick(Actor self)
{
// Update any dead segments
dirtyLocations.Clear();
foreach (var kv in segments)
if (!kv.Value.Valid)
dirtyLocations.Add(kv.Key);
foreach (var c in dirtyLocations)
segments[c] = bridgeLayer[c].TraitOrDefault<IBridgeSegment>();
if (repairStep < segmentLocations.Count && --repairDelay <= 0)
RepairStep();
if (demolishStep < segmentLocations.Count && --demolishDelay <= 0)
DemolishStep();
}
IEnumerable<IBridgeSegment> NextNeighbourStep(IEnumerable<CPos> seed, HashSet<CPos> processed)
{
foreach (var c in seed)
{
var bridge = bridgeLayer[c];
if (bridge == null)
continue;
var segment = bridge.TraitOrDefault<IBridgeSegment>();
if (segment != null && Info.Types.Contains(segment.Type) && processed.Add(segment.Location))
yield return segment;
}
}
public void Repair(Actor self, Actor repairer)
{
if (Info.RepairPropagationDelay > 0)
{
repairStep = 0;
repairRepairer = repairer;
RepairStep();
}
else
foreach (var s in segments.Values)
s.Repair(repairer);
}
public void RepairStep()
{
// Find the next segment that needs to be repaired
while (repairStep < segmentLocations.Count)
{
var stepDamage = segmentLocations[repairStep]
.Select(c => segments[c])
.Max(s => s.DamageState);
if (stepDamage > DamageState.Undamaged)
break;
repairStep++;
}
if (repairStep < segmentLocations.Count)
foreach (var c in segmentLocations[repairStep])
segments[c].Repair(repairRepairer);
repairDelay = Info.RepairPropagationDelay;
}
public void Demolish(Actor self, Actor saboteur)
{
if (Info.DemolishPropagationDelay > 0)
{
demolishStep = 0;
demolishSaboteur = saboteur;
DemolishStep();
}
else
foreach (var s in segments.Values)
s.Demolish(saboteur);
}
public void DemolishStep()
{
// Find the next segment to demolish
while (demolishStep < segmentLocations.Count)
{
var stepDamage = segmentLocations[demolishStep]
.Select(c => segments[c])
.Max(s => s.DamageState);
if (stepDamage < DamageState.Dead)
break;
demolishStep++;
}
if (demolishStep < segmentLocations.Count)
foreach (var c in segmentLocations[demolishStep])
segments[c].Demolish(demolishSaboteur);
demolishDelay = Info.DemolishPropagationDelay;
// Always advance at least one step (prevents sticking on placeholders)
demolishStep++;
}
public bool IsValidTarget(Actor self, Actor saboteur)
{
return true;
}
public DamageState BridgeDamageState
{
get
{
if (!segments.Any())
return DamageState.Undamaged;
return segments.Values.Max(s => s.DamageState);
}
}
public bool Repairing { get { return repairStep < segmentLocations.Count; } }
}
}

View File

@@ -0,0 +1,80 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Placeholder actor that transforms into another actor type when repaired.")]
class BridgePlaceholderInfo : ITraitInfo
{
public readonly string Type = "GroundLevelBridge";
[FieldLoader.Require]
[Desc("Actor type to replace with on repair.")]
[ActorReference] public readonly string ReplaceWithActor = null;
public readonly CVec[] NeighbourOffsets = { };
public object Create(ActorInitializer init) { return new BridgePlaceholder(init.Self, this); }
}
class BridgePlaceholder : IBridgeSegment, INotifyAddedToWorld, INotifyRemovedFromWorld
{
public readonly BridgePlaceholderInfo Info;
readonly Actor self;
readonly BridgeLayer bridgeLayer;
public BridgePlaceholder(Actor self, BridgePlaceholderInfo info)
{
Info = info;
this.self = self;
bridgeLayer = self.World.WorldActor.Trait<BridgeLayer>();
}
void INotifyAddedToWorld.AddedToWorld(Actor self)
{
bridgeLayer.Add(self);
}
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
{
bridgeLayer.Remove(self);
}
void IBridgeSegment.Repair(Actor repairer)
{
self.World.AddFrameEndTask(w =>
{
self.Dispose();
w.CreateActor(Info.ReplaceWithActor, new TypeDictionary
{
new LocationInit(self.Location),
new OwnerInit(self.Owner),
});
});
}
void IBridgeSegment.Demolish(Actor saboteur)
{
// Do nothing, we're already dead
}
string IBridgeSegment.Type { get { return Info.Type; } }
DamageState IBridgeSegment.DamageState { get { return DamageState.Dead; } }
bool IBridgeSegment.Valid { get { return self.IsInWorld; } }
CVec[] IBridgeSegment.NeighbourOffsets { get { return Info.NeighbourOffsets; } }
CPos IBridgeSegment.Location { get { return self.Location; } }
}
}

View File

@@ -0,0 +1,119 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Bridge actor that can't be passed underneath.")]
class GroundLevelBridgeInfo : ITraitInfo, IRulesetLoaded, Requires<BuildingInfo>, Requires<HealthInfo>
{
public readonly string TerrainType = "Bridge";
public readonly string Type = "GroundLevelBridge";
public readonly CVec[] NeighbourOffsets = { };
[Desc("The name of the weapon to use when demolishing the bridge")]
[WeaponReference] public readonly string DemolishWeapon = "Demolish";
public WeaponInfo DemolishWeaponInfo { get; private set; }
public void RulesetLoaded(Ruleset rules, ActorInfo ai) { DemolishWeaponInfo = rules.Weapons[DemolishWeapon.ToLowerInvariant()]; }
public object Create(ActorInitializer init) { return new GroundLevelBridge(init.Self, this); }
}
class GroundLevelBridge : IBridgeSegment, INotifyAddedToWorld, INotifyRemovedFromWorld
{
public readonly GroundLevelBridgeInfo Info;
readonly Actor self;
readonly BridgeLayer bridgeLayer;
readonly IEnumerable<CPos> cells;
readonly Health health;
public GroundLevelBridge(Actor self, GroundLevelBridgeInfo info)
{
Info = info;
this.self = self;
health = self.Trait<Health>();
bridgeLayer = self.World.WorldActor.Trait<BridgeLayer>();
var buildingInfo = self.Info.TraitInfo<BuildingInfo>();
cells = FootprintUtils.PathableTiles(self.Info.Name, buildingInfo, self.Location);
}
void UpdateTerrain(Actor self, byte terrainIndex)
{
foreach (var cell in cells)
self.World.Map.CustomTerrain[cell] = terrainIndex;
var domainIndex = self.World.WorldActor.TraitOrDefault<DomainIndex>();
if (domainIndex != null)
domainIndex.UpdateCells(self.World, cells);
}
void INotifyAddedToWorld.AddedToWorld(Actor self)
{
bridgeLayer.Add(self);
var tileSet = self.World.Map.Rules.TileSet;
var terrainIndex = tileSet.GetTerrainIndex(Info.TerrainType);
UpdateTerrain(self, terrainIndex);
KillInvalidActorsInFootprint(self);
}
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
{
bridgeLayer.Remove(self);
UpdateTerrain(self, byte.MaxValue);
KillInvalidActorsInFootprint(self);
}
void KillInvalidActorsInFootprint(Actor self)
{
foreach (var c in cells)
foreach (var a in self.World.ActorMap.GetActorsAt(c))
if (a.Info.HasTraitInfo<IPositionableInfo>() && !a.Trait<IPositionable>().CanEnterCell(c))
a.Kill(self);
}
void IBridgeSegment.Repair(Actor repairer)
{
health.InflictDamage(self, repairer, new Damage(-health.MaxHP), true);
}
void IBridgeSegment.Demolish(Actor saboteur)
{
self.World.AddFrameEndTask(w =>
{
if (self.IsDead)
return;
// Use .FromPos since this actor is dead. Cannot use Target.FromActor
Info.DemolishWeaponInfo.Impact(Target.FromPos(self.CenterPosition), saboteur, Enumerable.Empty<int>());
self.World.WorldActor.Trait<ScreenShaker>().AddEffect(15, self.CenterPosition, 6);
self.Kill(saboteur);
});
}
string IBridgeSegment.Type { get { return Info.Type; } }
DamageState IBridgeSegment.DamageState { get { return self.GetDamageState(); } }
bool IBridgeSegment.Valid { get { return self.IsInWorld; } }
CVec[] IBridgeSegment.NeighbourOffsets { get { return Info.NeighbourOffsets; } }
CPos IBridgeSegment.Location { get { return self.Location; } }
}
}

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Can enter a LegacyBridgeHut to trigger a repair.")] [Desc("Can enter a BridgeHut or LegacyBridgeHut to trigger a repair.")]
class RepairsBridgesInfo : ITraitInfo class RepairsBridgesInfo : ITraitInfo
{ {
[VoiceReference] public readonly string Voice = "Action"; [VoiceReference] public readonly string Voice = "Action";
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
"Possible values are Exit, Suicide, Dispose.")] "Possible values are Exit, Suicide, Dispose.")]
public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Dispose; public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Dispose;
[Desc("Cursor to use when targeting a LegacyBridgeHut of an unrepaired bridge.")] [Desc("Cursor to use when targeting an unrepaired bridge.")]
public readonly string TargetCursor = "goldwrench"; public readonly string TargetCursor = "goldwrench";
[Desc("Cursor to use when repairing is denied.")] [Desc("Cursor to use when repairing is denied.")]
@@ -66,10 +66,14 @@ namespace OpenRA.Mods.Common.Traits
return null; return null;
var legacyHut = order.TargetActor.TraitOrDefault<LegacyBridgeHut>(); var legacyHut = order.TargetActor.TraitOrDefault<LegacyBridgeHut>();
if (legacyHut == null) if (legacyHut != null)
return null; return legacyHut.BridgeDamageState == DamageState.Undamaged || legacyHut.Repairing || legacyHut.Bridge.IsDangling ? null : info.Voice;
return legacyHut.BridgeDamageState == DamageState.Undamaged || legacyHut.Repairing || legacyHut.Bridge.IsDangling ? null : info.Voice; var hut = order.TargetActor.TraitOrDefault<BridgeHut>();
if (hut != null)
return hut.BridgeDamageState == DamageState.Undamaged || hut.Repairing ? null : info.Voice;
return null;
} }
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)
@@ -77,10 +81,18 @@ namespace OpenRA.Mods.Common.Traits
if (order.OrderString == "RepairBridge") if (order.OrderString == "RepairBridge")
{ {
var legacyHut = order.TargetActor.TraitOrDefault<LegacyBridgeHut>(); var legacyHut = order.TargetActor.TraitOrDefault<LegacyBridgeHut>();
if (legacyHut == null) var hut = order.TargetActor.TraitOrDefault<BridgeHut>();
return; if (legacyHut != null)
{
if (legacyHut.BridgeDamageState == DamageState.Undamaged || legacyHut.Repairing || legacyHut.Bridge.IsDangling) if (legacyHut.BridgeDamageState == DamageState.Undamaged || legacyHut.Repairing || legacyHut.Bridge.IsDangling)
return;
}
else if (hut != null)
{
if (hut.BridgeDamageState == DamageState.Undamaged || hut.Repairing)
return;
}
else
return; return;
self.SetTargetLine(Target.FromOrder(self.World, order), Color.Yellow); self.SetTargetLine(Target.FromOrder(self.World, order), Color.Yellow);
@@ -102,22 +114,36 @@ namespace OpenRA.Mods.Common.Traits
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor) public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{ {
var legacyHut = target.TraitOrDefault<LegacyBridgeHut>();
if (legacyHut == null)
return false;
// Require force attack to heal partially damaged bridges to avoid unnecessary cursor noise
var damage = legacyHut.BridgeDamageState;
if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && damage != DamageState.Dead)
return false;
// Obey force moving onto bridges // Obey force moving onto bridges
if (modifiers.HasModifier(TargetModifiers.ForceMove)) if (modifiers.HasModifier(TargetModifiers.ForceMove))
return false; return false;
// Can't repair a bridge that is undamaged, already under repair, or dangling var legacyHut = target.TraitOrDefault<LegacyBridgeHut>();
if (damage == DamageState.Undamaged || legacyHut.Repairing || legacyHut.Bridge.IsDangling) var hut = target.TraitOrDefault<BridgeHut>();
cursor = info.TargetBlockedCursor; if (legacyHut != null)
{
// Require force attack to heal partially damaged bridges to avoid unnecessary cursor noise
var damage = legacyHut.BridgeDamageState;
if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && damage != DamageState.Dead)
return false;
// Can't repair a bridge that is undamaged, already under repair, or dangling
if (damage == DamageState.Undamaged || legacyHut.Repairing || legacyHut.Bridge.IsDangling)
cursor = info.TargetBlockedCursor;
}
else if (hut != null)
{
// Require force attack to heal partially damaged bridges to avoid unnecessary cursor noise
var damage = hut.BridgeDamageState;
if (hut.Info.RequireForceAttackForHeal && !modifiers.HasModifier(TargetModifiers.ForceAttack) && damage != DamageState.Dead)
return false;
// Can't repair a bridge that is undamaged, already under repair, or dangling
if (damage == DamageState.Undamaged || hut.Repairing)
cursor = info.TargetBlockedCursor;
}
else
return false;
return true; return true;
} }

View File

@@ -0,0 +1,59 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
interface IBridgeSegment
{
void Repair(Actor repairer);
void Demolish(Actor saboteur);
string Type { get; }
DamageState DamageState { get; }
CVec[] NeighbourOffsets { get; }
bool Valid { get; }
CPos Location { get; }
}
class BridgeLayerInfo : ITraitInfo
{
public object Create(ActorInitializer init) { return new BridgeLayer(init.World); }
}
class BridgeLayer
{
readonly CellLayer<Actor> bridges;
public BridgeLayer(World world)
{
bridges = new CellLayer<Actor>(world.Map);
}
public Actor this[CPos cell] { get { return bridges[cell]; } }
public void Add(Actor b)
{
var buildingInfo = b.Info.TraitInfo<BuildingInfo>();
foreach (var c in FootprintUtils.PathableTiles(b.Info.Name, buildingInfo, b.Location))
bridges[c] = b;
}
public void Remove(Actor b)
{
var buildingInfo = b.Info.TraitInfo<BuildingInfo>();
foreach (var c in FootprintUtils.PathableTiles(b.Info.Name, buildingInfo, b.Location))
if (bridges[c] == b)
bridges[c] = null;
}
}
}

View File

@@ -56,7 +56,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="Activities\VoxelHarvesterDockSequence.cs" /> <Compile Include="Activities\VoxelHarvesterDockSequence.cs" />
<Compile Include="SpriteLoaders\TmpTSLoader.cs" /> <Compile Include="SpriteLoaders\TmpTSLoader.cs" />
<Compile Include="Traits\Buildings\GroundLevelBridge.cs" />
<Compile Include="Traits\Buildings\TiberianSunRefinery.cs" /> <Compile Include="Traits\Buildings\TiberianSunRefinery.cs" />
<Compile Include="Traits\Render\WithDockingOverlay.cs" /> <Compile Include="Traits\Render\WithDockingOverlay.cs" />
<Compile Include="Traits\Render\WithPermanentInjury.cs" /> <Compile Include="Traits\Render\WithPermanentInjury.cs" />

View File

@@ -1,70 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.TS.Traits
{
[Desc("Bridge actor that can't be passed underneath.")]
class GroundLevelBridgeInfo : ITraitInfo, Requires<BuildingInfo>
{
public readonly string TerrainType = "Bridge";
public object Create(ActorInitializer init) { return new GroundLevelBridge(init.Self, this); }
}
class GroundLevelBridge : INotifyAddedToWorld, INotifyRemovedFromWorld
{
readonly GroundLevelBridgeInfo info;
readonly IEnumerable<CPos> cells;
public GroundLevelBridge(Actor self, GroundLevelBridgeInfo info)
{
this.info = info;
var buildingInfo = self.Info.TraitInfo<BuildingInfo>();
cells = FootprintUtils.PathableTiles(self.Info.Name, buildingInfo, self.Location);
}
void UpdateTerrain(Actor self, byte terrainIndex)
{
foreach (var cell in cells)
self.World.Map.CustomTerrain[cell] = terrainIndex;
var domainIndex = self.World.WorldActor.TraitOrDefault<DomainIndex>();
if (domainIndex != null)
domainIndex.UpdateCells(self.World, cells);
}
void INotifyAddedToWorld.AddedToWorld(Actor self)
{
var tileSet = self.World.Map.Rules.TileSet;
var terrainIndex = tileSet.GetTerrainIndex(info.TerrainType);
UpdateTerrain(self, terrainIndex);
}
void KillUnitsOnBridge(Actor self)
{
foreach (var c in cells)
foreach (var a in self.World.ActorMap.GetActorsAt(c))
if (a.Info.HasTraitInfo<IPositionableInfo>() && !a.Trait<IPositionable>().CanEnterCell(c))
a.Kill(self);
}
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
{
UpdateTerrain(self, byte.MaxValue);
KillUnitsOnBridge(self);
}
}
}

View File

@@ -1247,11 +1247,3 @@ Rules:
World: World:
GlobalLightingPaletteEffect: GlobalLightingPaletteEffect:
Ambient: 0.75 Ambient: 0.75
LOBRDG_A:
Targetable:
TargetTypes: Ground, Building
RequiresForceFire: true
Health:
HP: 1000
Armor:
Type: Concrete

View File

@@ -1,8 +1,57 @@
CABHUT:
Inherits: ^BasicBuilding
Tooltip:
Name: Bridge repair hut
Building:
Adjacent: 0
Footprint: x
Dimensions: 1, 1
BridgeHut:
NeighbourOffsets: -1,-1, -1,0, -1,1, 0,-1, 0,1, 1,-1, 1,0, 1,1
RenderSprites:
Palette: player
Targetable:
TargetTypes: C4
-SelectionDecorations:
-Demolishable:
^LowBridgeRamp:
AlwaysVisible:
RenderSprites:
Palette: terraindecoration
WithSpriteBody:
AutoSelectionSize:
AppearsOnRadar:
RadarColorFromTerrain:
Terrain: Bridge
BodyOrientation:
UseClassicPerspectiveFudge: false
QuantizedFacings: 1
Tooltip:
Name: Bridge
^LowBridge:
Inherits: ^LowBridgeRamp
Targetable:
TargetTypes: Ground, Building
RequiresForceFire: true
Health:
HP: 500
Armor:
Type: Concrete
LOBRDG_A: LOBRDG_A:
Inherits: ^LowBridge_A Inherits: ^LowBridge
Building:
Footprint: ___
Dimensions: 3, 1
GroundLevelBridge:
NeighbourOffsets: 1,-1, 1,1
SpawnActorOnDeath:
Actor: lobrdg_a_d
LOBRDG_A_D: LOBRDG_A_D:
Inherits: ^LowBridge_A Inherits: LOBRDG_A
-RenderSprites: -RenderSprites:
RenderSpritesEditorOnly: RenderSpritesEditorOnly:
Palette: terrainalpha Palette: terrainalpha
@@ -10,12 +59,22 @@ LOBRDG_A_D:
Name: Dead Bridge Name: Dead Bridge
-GroundLevelBridge: -GroundLevelBridge:
-AppearsOnRadar: -AppearsOnRadar:
BridgePlaceholder:
ReplaceWithActor: lobrdg_a
NeighbourOffsets: 1,-1, 1,1
LOBRDG_B: LOBRDG_B:
Inherits: ^LowBridge_B Inherits: ^LowBridge
Building:
Footprint: _ _ _
Dimensions: 1, 3
GroundLevelBridge:
NeighbourOffsets: -1,1, 1,1
SpawnActorOnDeath:
Actor: lobrdg_b_d
LOBRDG_B_D: LOBRDG_B_D:
Inherits: ^LowBridge_B Inherits: LOBRDG_B
-RenderSprites: -RenderSprites:
RenderSpritesEditorOnly: RenderSpritesEditorOnly:
Palette: terrainalpha Palette: terrainalpha
@@ -23,27 +82,42 @@ LOBRDG_B_D:
Name: Dead Bridge Name: Dead Bridge
-GroundLevelBridge: -GroundLevelBridge:
-AppearsOnRadar: -AppearsOnRadar:
BridgePlaceholder:
ReplaceWithActor: lobrdg_b
NeighbourOffsets: -1,1, 1,1
LOBRDG_R_SE: LOBRDG_R_SE:
Inherits: ^LowBridge_B Inherits: ^LowBridgeRamp
Building:
Footprint: _ _ _
Dimensions: 1, 3
EditorOnlyTooltip: EditorOnlyTooltip:
Name: Bridge Ramp Name: Bridge Ramp
Description: South East Description: South East
LOBRDG_R_NW: LOBRDG_R_NW:
Inherits: ^LowBridge_B Inherits: ^LowBridgeRamp
Building:
Footprint: _ _ _
Dimensions: 1, 3
EditorOnlyTooltip: EditorOnlyTooltip:
Name: Bridge Ramp Name: Bridge Ramp
Description: North West Description: North West
LOBRDG_R_NE: LOBRDG_R_NE:
Inherits: ^LowBridge_A Inherits: ^LowBridgeRamp
Building:
Footprint: ___
Dimensions: 3, 1
EditorOnlyTooltip: EditorOnlyTooltip:
Name: Bridge Ramp Name: Bridge Ramp
Description: North East Description: North East
LOBRDG_R_SW: LOBRDG_R_SW:
Inherits: ^LowBridge_A Inherits: ^LowBridgeRamp
Building:
Footprint: ___
Dimensions: 3, 1
EditorOnlyTooltip: EditorOnlyTooltip:
Name: Bridge Ramp Name: Bridge Ramp
Description: South West Description: South West

View File

@@ -645,19 +645,6 @@ CAARMR:
Prerequisite: barracks.upgraded Prerequisite: barracks.upgraded
Capturable: Capturable:
CABHUT:
Inherits: ^CivBuilding
Tooltip:
Name: Bridge repair hut
Building:
Adjacent: 0
Footprint: x
Dimensions: 1, 1
Health:
HP: 2000
RenderSprites:
Palette: player
CACRSH01: CACRSH01:
Inherits: ^Decoration Inherits: ^Decoration
Tooltip: Tooltip:

View File

@@ -901,36 +901,6 @@
LineBuildNode: LineBuildNode:
Connections: 0,-1, 0,1 Connections: 0,-1, 0,1
^LowBridge:
AlwaysVisible:
RenderSprites:
Palette: terraindecoration
WithSpriteBody:
AutoSelectionSize:
AppearsOnRadar:
RadarColorFromTerrain:
Terrain: Bridge
BodyOrientation:
UseClassicPerspectiveFudge: false
QuantizedFacings: 1
Tooltip:
Name: Bridge
Health:
^LowBridge_A:
Inherits: ^LowBridge
Building:
Footprint: ___
Dimensions: 3, 1
GroundLevelBridge:
^LowBridge_B:
Inherits: ^LowBridge
Building:
Footprint: _ _ _
Dimensions: 1, 3
GroundLevelBridge:
^HealsOnTiberium: ^HealsOnTiberium:
DamagedByTerrain: DamagedByTerrain:
Damage: -2 Damage: -2

View File

@@ -99,6 +99,7 @@ World:
SmokeType: largesmoke SmokeType: largesmoke
Sequence: largecraters Sequence: largecraters
ResourceLayer: ResourceLayer:
BridgeLayer:
CustomTerrainDebugOverlay: CustomTerrainDebugOverlay:
ResourceClaimLayer: ResourceClaimLayer:
WarheadDebugOverlay: WarheadDebugOverlay:

View File

@@ -78,3 +78,11 @@ LargeDebris:
Image: dbrislg Image: dbrislg
Sequences: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Sequences: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Shadow: true Shadow: true
Demolish:
Warhead@1Dam: SpreadDamage
DamageTypes: DefaultDeath
Warhead@2Eff: CreateEffect
Explosions: large_twlt
ExplosionPalette: effectalpha75
ImpactSounds: expnew09.aud