Skip to content

Commit

Permalink
Add DamageTypes to Demolition
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR authored and abcdefg30 committed Oct 21, 2020
1 parent 54c4a05 commit 8aeec24
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 21 deletions.
6 changes: 4 additions & 2 deletions OpenRA.Mods.Common/Activities/Demolish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ class Demolish : Enter
readonly int flashes;
readonly int flashesDelay;
readonly int flashInterval;
readonly BitSet<DamageType> damageTypes;
readonly INotifyDemolition[] notifiers;
readonly EnterBehaviour enterBehaviour;

Actor enterActor;
IDemolishable[] enterDemolishables;

public Demolish(Actor self, Target target, EnterBehaviour enterBehaviour, int delay,
int flashes, int flashesDelay, int flashInterval)
int flashes, int flashesDelay, int flashInterval, BitSet<DamageType> damageTypes)
: base(self, target, Color.Crimson)
{
notifiers = self.TraitsImplementing<INotifyDemolition>().ToArray();
this.delay = delay;
this.flashes = flashes;
this.flashesDelay = flashesDelay;
this.flashInterval = flashInterval;
this.damageTypes = damageTypes;
this.enterBehaviour = enterBehaviour;
}

Expand Down Expand Up @@ -75,7 +77,7 @@ protected override void OnEnterComplete(Actor self, Actor targetActor)
ind.Demolishing(self);
foreach (var d in enterDemolishables)
d.Demolish(enterActor, self, delay);
d.Demolish(enterActor, self, delay, damageTypes);
if (enterBehaviour == EnterBehaviour.Dispose)
self.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DemolitionProperties(ScriptContext context, Actor self)
public void Demolish(Actor target)
{
Self.QueueActivity(new Demolish(Self, Target.FromActor(target), info.EnterBehaviour, info.DetonationDelay,
info.Flashes, info.FlashesDelay, info.FlashInterval));
info.Flashes, info.FlashesDelay, info.FlashInterval, info.DamageTypes));
}
}
}
6 changes: 3 additions & 3 deletions OpenRA.Mods.Common/Traits/Buildings/Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ public DamageState AggregateDamageState()
return damage;
}

public void Demolish(Actor saboteur, int direction)
public void Demolish(Actor saboteur, int direction, BitSet<DamageType> damageTypes)
{
var initialDamage = health.DamageState;
self.World.AddFrameEndTask(w =>
{
// Use .FromPos since this actor is killed. Cannot use Target.FromActor
info.DemolishWeaponInfo.Impact(Target.FromPos(self.CenterPosition), saboteur);
self.Kill(saboteur);
self.Kill(saboteur, damageTypes);
});

// Destroy adjacent spans between (including) huts
Expand All @@ -386,7 +386,7 @@ public void Demolish(Actor saboteur, int direction)
0 : info.RepairPropagationDelay;

self.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, () =>
neighbours[direction].Demolish(saboteur, direction))));
neighbours[direction].Demolish(saboteur, direction, damageTypes))));
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions OpenRA.Mods.Common/Traits/Buildings/BridgeHut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
Expand Down Expand Up @@ -60,6 +61,7 @@ class BridgeHut : INotifyCreated, IDemolishable, ITick
int demolishStep;
int demolishDelay;
Actor demolishSaboteur;
BitSet<DamageType> demolishDamageTypes;

public BridgeHut(World world, BridgeHutInfo info)
{
Expand Down Expand Up @@ -170,7 +172,7 @@ bool IDemolishable.IsValidTarget(Actor self, Actor saboteur)
return true;
}

void IDemolishable.Demolish(Actor self, Actor saboteur, int delay)
void IDemolishable.Demolish(Actor self, Actor saboteur, int delay, BitSet<DamageType> damageTypes)
{
// TODO: Handle using ITick
self.World.Add(new DelayedAction(delay, () =>
Expand All @@ -188,11 +190,12 @@ void IDemolishable.Demolish(Actor self, Actor saboteur, int delay)
{
demolishStep = 0;
demolishSaboteur = saboteur;
demolishDamageTypes = damageTypes;
DemolishStep();
}
else
foreach (var s in segments.Values)
s.Demolish(saboteur);
s.Demolish(saboteur, damageTypes);
}
}));
}
Expand All @@ -214,7 +217,7 @@ public void DemolishStep()

if (demolishStep < segmentLocations.Count)
foreach (var c in segmentLocations[demolishStep])
segments[c].Demolish(demolishSaboteur);
segments[c].Demolish(demolishSaboteur, demolishDamageTypes);

demolishDelay = Info.DemolishPropagationDelay;

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Buildings/BridgePlaceholder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void IBridgeSegment.Repair(Actor repairer)
});
}

void IBridgeSegment.Demolish(Actor saboteur)
void IBridgeSegment.Demolish(Actor saboteur, BitSet<DamageType> damageTypes)
{
// Do nothing
}
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void IBridgeSegment.Repair(Actor repairer)
health.InflictDamage(self, repairer, new Damage(-health.MaxHP), true);
}

void IBridgeSegment.Demolish(Actor saboteur)
void IBridgeSegment.Demolish(Actor saboteur, BitSet<DamageType> damageTypes)
{
self.World.AddFrameEndTask(w =>
{
Expand All @@ -114,7 +114,7 @@ void IBridgeSegment.Demolish(Actor saboteur)
// Use .FromPos since this actor is dead. Cannot use Target.FromActor
Info.DemolishWeaponInfo.Impact(Target.FromPos(self.CenterPosition), saboteur);
self.Kill(saboteur);
self.Kill(saboteur, damageTypes);
});
}

Expand Down
5 changes: 3 additions & 2 deletions OpenRA.Mods.Common/Traits/Buildings/LegacyBridgeHut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using System.Linq;
using OpenRA.Effects;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
Expand Down Expand Up @@ -53,7 +54,7 @@ bool IDemolishable.IsValidTarget(Actor self, Actor saboteur)
return BridgeDamageState != DamageState.Dead;
}

void IDemolishable.Demolish(Actor self, Actor saboteur, int delay)
void IDemolishable.Demolish(Actor self, Actor saboteur, int delay, BitSet<DamageType> damageTypes)
{
// TODO: Handle using ITick
self.World.Add(new DelayedAction(delay, () =>
Expand All @@ -66,7 +67,7 @@ void IDemolishable.Demolish(Actor self, Actor saboteur, int delay)
.Select(t => t.GetDamageModifier(self, null));
if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
Bridge.Do((b, d) => b.Demolish(saboteur, d));
Bridge.Do((b, d) => b.Demolish(saboteur, d, damageTypes));
}));
}
}
Expand Down
11 changes: 7 additions & 4 deletions OpenRA.Mods.Common/Traits/Demolishable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
Expand All @@ -34,12 +35,14 @@ class DemolishAction
public readonly Actor Saboteur;
public readonly int Token;
public int Delay;
public readonly BitSet<DamageType> DamageTypes;

public DemolishAction(Actor saboteur, int delay, int token)
public DemolishAction(Actor saboteur, int delay, int token, BitSet<DamageType> damageTypes)
{
Saboteur = saboteur;
Delay = delay;
Token = token;
DamageTypes = damageTypes;
}
}

Expand All @@ -54,13 +57,13 @@ bool IDemolishable.IsValidTarget(Actor self, Actor saboteur)
return !IsTraitDisabled;
}

void IDemolishable.Demolish(Actor self, Actor saboteur, int delay)
void IDemolishable.Demolish(Actor self, Actor saboteur, int delay, BitSet<DamageType> damageTypes)
{
if (IsTraitDisabled)
return;

var token = self.GrantCondition(Info.Condition);
actions.Add(new DemolishAction(saboteur, delay, token));
actions.Add(new DemolishAction(saboteur, delay, token, damageTypes));
}

void ITick.Tick(Actor self)
Expand All @@ -77,7 +80,7 @@ void ITick.Tick(Actor self)
.Select(t => t.GetDamageModifier(self, null));

if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
self.Kill(a.Saboteur);
self.Kill(a.Saboteur, a.DamageTypes);
else if (a.Token != Actor.InvalidConditionToken)
{
self.RevokeCondition(a.Token);
Expand Down
6 changes: 5 additions & 1 deletion OpenRA.Mods.Common/Traits/Demolition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Linq;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
Expand All @@ -36,6 +37,9 @@ class DemolitionInfo : TraitInfo
"Possible values are Exit, Suicide, Dispose.")]
public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Exit;

[Desc("Types of damage that this trait causes. Leave empty for no damage types.")]
public readonly BitSet<DamageType> DamageTypes = default(BitSet<DamageType>);

[VoiceReference]
[Desc("Voice string when planting explosive charges.")]
public readonly string Voice = "Action";
Expand Down Expand Up @@ -84,7 +88,7 @@ public void ResolveOrder(Actor self, Order order)
}

self.QueueActivity(order.Queued, new Demolish(self, order.Target, info.EnterBehaviour, info.DetonationDelay,
info.Flashes, info.FlashesDelay, info.FlashInterval));
info.Flashes, info.FlashesDelay, info.FlashInterval, info.DamageTypes));

self.ShowTargetLines();
}
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Traits/World/BridgeLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
*/
#endregion

using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
{
interface IBridgeSegment
{
void Repair(Actor repairer);
void Demolish(Actor saboteur);
void Demolish(Actor saboteur, BitSet<DamageType> damageTypes);

string Type { get; }
DamageState DamageState { get; }
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/TraitsInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public interface IDemolishableInfo : ITraitInfoInterface { bool IsValidTarget(Ac
public interface IDemolishable
{
bool IsValidTarget(Actor self, Actor saboteur);
void Demolish(Actor self, Actor saboteur, int delay);
void Demolish(Actor self, Actor saboteur, int delay, BitSet<DamageType> damageTypes);
}

// Type tag for crush class bits
Expand Down

0 comments on commit 8aeec24

Please sign in to comment.