Add DamageTypes to Demolition

This commit is contained in:
Mustafa Alperen Seki
2020-10-13 19:00:05 +03:00
committed by abcdefg30
parent 54c4a05062
commit 8aeec24c9b
11 changed files with 35 additions and 21 deletions

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Mods.Common.Activities
readonly int flashes; readonly int flashes;
readonly int flashesDelay; readonly int flashesDelay;
readonly int flashInterval; readonly int flashInterval;
readonly BitSet<DamageType> damageTypes;
readonly INotifyDemolition[] notifiers; readonly INotifyDemolition[] notifiers;
readonly EnterBehaviour enterBehaviour; readonly EnterBehaviour enterBehaviour;
@@ -30,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
IDemolishable[] enterDemolishables; IDemolishable[] enterDemolishables;
public Demolish(Actor self, Target target, EnterBehaviour enterBehaviour, int delay, 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) : base(self, target, Color.Crimson)
{ {
notifiers = self.TraitsImplementing<INotifyDemolition>().ToArray(); notifiers = self.TraitsImplementing<INotifyDemolition>().ToArray();
@@ -38,6 +39,7 @@ namespace OpenRA.Mods.Common.Activities
this.flashes = flashes; this.flashes = flashes;
this.flashesDelay = flashesDelay; this.flashesDelay = flashesDelay;
this.flashInterval = flashInterval; this.flashInterval = flashInterval;
this.damageTypes = damageTypes;
this.enterBehaviour = enterBehaviour; this.enterBehaviour = enterBehaviour;
} }
@@ -75,7 +77,7 @@ namespace OpenRA.Mods.Common.Activities
ind.Demolishing(self); ind.Demolishing(self);
foreach (var d in enterDemolishables) foreach (var d in enterDemolishables)
d.Demolish(enterActor, self, delay); d.Demolish(enterActor, self, delay, damageTypes);
if (enterBehaviour == EnterBehaviour.Dispose) if (enterBehaviour == EnterBehaviour.Dispose)
self.Dispose(); self.Dispose();

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Scripting
public void Demolish(Actor target) public void Demolish(Actor target)
{ {
Self.QueueActivity(new Demolish(Self, Target.FromActor(target), info.EnterBehaviour, info.DetonationDelay, 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));
} }
} }
} }

View File

@@ -368,7 +368,7 @@ namespace OpenRA.Mods.Common.Traits
return damage; return damage;
} }
public void Demolish(Actor saboteur, int direction) public void Demolish(Actor saboteur, int direction, BitSet<DamageType> damageTypes)
{ {
var initialDamage = health.DamageState; var initialDamage = health.DamageState;
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
@@ -376,7 +376,7 @@ namespace OpenRA.Mods.Common.Traits
// Use .FromPos since this actor is killed. Cannot use Target.FromActor // Use .FromPos since this actor is killed. Cannot use Target.FromActor
info.DemolishWeaponInfo.Impact(Target.FromPos(self.CenterPosition), saboteur); info.DemolishWeaponInfo.Impact(Target.FromPos(self.CenterPosition), saboteur);
self.Kill(saboteur); self.Kill(saboteur, damageTypes);
}); });
// Destroy adjacent spans between (including) huts // Destroy adjacent spans between (including) huts
@@ -386,7 +386,7 @@ namespace OpenRA.Mods.Common.Traits
0 : info.RepairPropagationDelay; 0 : info.RepairPropagationDelay;
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, () => self.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, () =>
neighbours[direction].Demolish(saboteur, direction)))); neighbours[direction].Demolish(saboteur, direction, damageTypes))));
} }
} }
} }

View File

@@ -12,6 +12,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -60,6 +61,7 @@ namespace OpenRA.Mods.Common.Traits
int demolishStep; int demolishStep;
int demolishDelay; int demolishDelay;
Actor demolishSaboteur; Actor demolishSaboteur;
BitSet<DamageType> demolishDamageTypes;
public BridgeHut(World world, BridgeHutInfo info) public BridgeHut(World world, BridgeHutInfo info)
{ {
@@ -170,7 +172,7 @@ namespace OpenRA.Mods.Common.Traits
return true; 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 // TODO: Handle using ITick
self.World.Add(new DelayedAction(delay, () => self.World.Add(new DelayedAction(delay, () =>
@@ -188,11 +190,12 @@ namespace OpenRA.Mods.Common.Traits
{ {
demolishStep = 0; demolishStep = 0;
demolishSaboteur = saboteur; demolishSaboteur = saboteur;
demolishDamageTypes = damageTypes;
DemolishStep(); DemolishStep();
} }
else else
foreach (var s in segments.Values) foreach (var s in segments.Values)
s.Demolish(saboteur); s.Demolish(saboteur, damageTypes);
} }
})); }));
} }
@@ -214,7 +217,7 @@ namespace OpenRA.Mods.Common.Traits
if (demolishStep < segmentLocations.Count) if (demolishStep < segmentLocations.Count)
foreach (var c in segmentLocations[demolishStep]) foreach (var c in segmentLocations[demolishStep])
segments[c].Demolish(demolishSaboteur); segments[c].Demolish(demolishSaboteur, demolishDamageTypes);
demolishDelay = Info.DemolishPropagationDelay; demolishDelay = Info.DemolishPropagationDelay;

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
}); });
} }
void IBridgeSegment.Demolish(Actor saboteur) void IBridgeSegment.Demolish(Actor saboteur, BitSet<DamageType> damageTypes)
{ {
// Do nothing // Do nothing
} }

View File

@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Traits
health.InflictDamage(self, repairer, new Damage(-health.MaxHP), true); 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 => self.World.AddFrameEndTask(w =>
{ {
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Traits
// Use .FromPos since this actor is dead. Cannot use Target.FromActor // Use .FromPos since this actor is dead. Cannot use Target.FromActor
Info.DemolishWeaponInfo.Impact(Target.FromPos(self.CenterPosition), saboteur); Info.DemolishWeaponInfo.Impact(Target.FromPos(self.CenterPosition), saboteur);
self.Kill(saboteur); self.Kill(saboteur, damageTypes);
}); });
} }

View File

@@ -11,6 +11,7 @@
using System.Linq; using System.Linq;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -53,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits
return BridgeDamageState != DamageState.Dead; 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 // TODO: Handle using ITick
self.World.Add(new DelayedAction(delay, () => self.World.Add(new DelayedAction(delay, () =>
@@ -66,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
.Select(t => t.GetDamageModifier(self, null)); .Select(t => t.GetDamageModifier(self, null));
if (Util.ApplyPercentageModifiers(100, modifiers) > 0) if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
Bridge.Do((b, d) => b.Demolish(saboteur, d)); Bridge.Do((b, d) => b.Demolish(saboteur, d, damageTypes));
})); }));
} }
} }

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -34,12 +35,14 @@ namespace OpenRA.Mods.Common.Traits
public readonly Actor Saboteur; public readonly Actor Saboteur;
public readonly int Token; public readonly int Token;
public int Delay; 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; Saboteur = saboteur;
Delay = delay; Delay = delay;
Token = token; Token = token;
DamageTypes = damageTypes;
} }
} }
@@ -54,13 +57,13 @@ namespace OpenRA.Mods.Common.Traits
return !IsTraitDisabled; 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) if (IsTraitDisabled)
return; return;
var token = self.GrantCondition(Info.Condition); 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) void ITick.Tick(Actor self)
@@ -77,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
.Select(t => t.GetDamageModifier(self, null)); .Select(t => t.GetDamageModifier(self, null));
if (Util.ApplyPercentageModifiers(100, modifiers) > 0) if (Util.ApplyPercentageModifiers(100, modifiers) > 0)
self.Kill(a.Saboteur); self.Kill(a.Saboteur, a.DamageTypes);
else if (a.Token != Actor.InvalidConditionToken) else if (a.Token != Actor.InvalidConditionToken)
{ {
self.RevokeCondition(a.Token); self.RevokeCondition(a.Token);

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders; using OpenRA.Mods.Common.Orders;
using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -36,6 +37,9 @@ namespace OpenRA.Mods.Common.Traits
"Possible values are Exit, Suicide, Dispose.")] "Possible values are Exit, Suicide, Dispose.")]
public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Exit; 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] [VoiceReference]
[Desc("Voice string when planting explosive charges.")] [Desc("Voice string when planting explosive charges.")]
public readonly string Voice = "Action"; public readonly string Voice = "Action";
@@ -84,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
} }
self.QueueActivity(order.Queued, new Demolish(self, order.Target, info.EnterBehaviour, info.DetonationDelay, 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(); self.ShowTargetLines();
} }

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -16,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits
interface IBridgeSegment interface IBridgeSegment
{ {
void Repair(Actor repairer); void Repair(Actor repairer);
void Demolish(Actor saboteur); void Demolish(Actor saboteur, BitSet<DamageType> damageTypes);
string Type { get; } string Type { get; }
DamageState DamageState { get; } DamageState DamageState { get; }

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
public interface IDemolishable public interface IDemolishable
{ {
bool IsValidTarget(Actor self, Actor saboteur); 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 // Type tag for crush class bits