Skip to content

Commit

Permalink
Add DamageTypes to Kill() and make some traits use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR committed Feb 4, 2018
1 parent b0b2325 commit 4004f17
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 22 deletions.
4 changes: 2 additions & 2 deletions OpenRA.Game/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ public void InflictDamage(Actor attacker, Damage damage)
health.InflictDamage(this, attacker, damage, false);
}

public void Kill(Actor attacker)
public void Kill(Actor attacker, HashSet<string> damageTypes = null)
{
if (Disposed || health == null)
return;

health.Kill(this, attacker);
health.Kill(this, attacker, damageTypes);
}

public bool CanBeViewedByPlayer(Player player)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Traits/TraitsInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface IHealth
bool IsDead { get; }

void InflictDamage(Actor self, Actor attacker, Damage damage, bool ignoreModifiers);
void Kill(Actor self, Actor attacker);
void Kill(Actor self, Actor attacker, HashSet<string> damageTypes);
}

// depends on the order of pips in WorldRenderer.cs!
Expand Down
7 changes: 5 additions & 2 deletions OpenRA.Mods.Cnc/Activities/Leap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.GameRules;
Expand All @@ -29,15 +30,17 @@ class Leap : Activity
WPos to;
int ticks;
WAngle angle;
HashSet<string> damageTypes;

public Leap(Actor self, Actor target, Armament a, WDist speed, WAngle angle)
public Leap(Actor self, Actor target, Armament a, WDist speed, WAngle angle, HashSet<string> damageTypes)
{
var targetMobile = target.TraitOrDefault<Mobile>();
if (targetMobile == null)
throw new InvalidOperationException("Leap requires a target actor with the Mobile trait");

this.weapon = a.Weapon;
this.angle = angle;
this.damageTypes = damageTypes;
mobile = self.Trait<Mobile>();
mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, targetMobile.FromCell, targetMobile.FromSubCell);
mobile.IsMoving = true;
Expand Down Expand Up @@ -67,7 +70,7 @@ public override Activity Tick(Actor self)

self.World.ActorMap.GetActorsAt(mobile.ToCell, mobile.ToSubCell)
.Except(new[] { self }).Where(t => weapon.IsValidAgainst(t, self))
.Do(t => t.Kill(self));
.Do(t => t.Kill(self, damageTypes));

return NextActivity;
}
Expand Down
5 changes: 4 additions & 1 deletion OpenRA.Mods.Cnc/Traits/Attack/AttackLeap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class AttackLeapInfo : AttackFrontalInfo

public readonly WAngle Angle = WAngle.FromDegrees(20);

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

public override object Create(ActorInitializer init) { return new AttackLeap(init.Self, this); }
}

Expand All @@ -51,7 +54,7 @@ public override void DoAttack(Actor self, Target target, IEnumerable<Armament> a
return;

self.CancelActivity();
self.QueueActivity(new Leap(self, target.Actor, a, info.Speed, info.Angle));
self.QueueActivity(new Leap(self, target.Actor, a, info.Speed, info.Angle, info.DamageTypes));
}
}
}
7 changes: 6 additions & 1 deletion OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

using System.Collections.Generic;
using System.Drawing;
using OpenRA.Mods.Cnc.Activities;
using OpenRA.Mods.Common.Traits;
Expand All @@ -22,6 +23,10 @@ public class ChronoshiftableInfo : ITraitInfo
{
[Desc("Should the actor die instead of being teleported?")]
public readonly bool ExplodeInstead = false;

[Desc("Types of damage that this trait causes to self when 'ExplodeInstead' is true. Leave empty for no damage types.")]
public readonly HashSet<string> DamageTypes = new HashSet<string>();

public readonly string ChronoshiftSound = "chrono2.aud";

[Desc("Should the actor return to its previous location after the chronoshift wore out?")]
Expand Down Expand Up @@ -95,7 +100,7 @@ public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool
{
// Damage is inflicted by the chronosphere
if (!self.Disposed)
self.InflictDamage(chronosphere, new Damage(int.MaxValue));
self.Kill(chronosphere, info.DamageTypes);
});
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion OpenRA.Mods.Cnc/Traits/MadTank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class MadTankInfo : ITraitInfo, IRulesetLoaded, Requires<ExplodesInfo>, Requires
public WeaponInfo ThumpDamageWeaponInfo { get; private set; }
public WeaponInfo DetonationWeaponInfo { get; private set; }

[Desc("Types of damage that this trait causes to self while self-destructing. Leave empty for no damage types.")]
public readonly HashSet<string> DamageTypes = new HashSet<string>();

public object Create(ActorInitializer init) { return new MadTank(init.Self, this); }
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
Expand Down Expand Up @@ -146,7 +149,7 @@ void Detonate()
info.DetonationWeaponInfo.Impact(Target.FromPos(self.CenterPosition), self, Enumerable.Empty<int>());
}
self.Kill(self);
self.Kill(self, info.DamageTypes);
});
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/Mine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClas
if (mobile != null && !info.DetonateClasses.Overlaps(mobile.Info.Crushes))
return;

self.Kill(crusher);
self.Kill(crusher, mobile != null ? mobile.Info.CrushDamageTypes : new HashSet<string>());
}

bool ICrushable.CrushableBy(Actor self, Actor crusher, HashSet<string> crushClasses)
Expand Down
7 changes: 5 additions & 2 deletions OpenRA.Mods.Common/Traits/Attack/AttackSuicides.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Does a suicide attack where it moves next to the target when used in combination with `Explodes`.")]
class AttackSuicidesInfo : ConditionalTraitInfo, Requires<IMoveInfo>
{
[Desc("Types of damage that this trait causes to self while suiciding. Leave empty for no damage types.")]
public readonly HashSet<string> DamageTypes = new HashSet<string>();

[VoiceReference] public readonly string Voice = "Action";

public override object Create(ActorInitializer init) { return new AttackSuicides(init.Self, this); }
Expand Down Expand Up @@ -82,10 +85,10 @@ public void ResolveOrder(Actor self, Order order)

self.QueueActivity(move.MoveToTarget(self, target));

self.QueueActivity(new CallFunc(() => self.Kill(self)));
self.QueueActivity(new CallFunc(() => self.Kill(self, Info.DamageTypes)));
}
else if (order.OrderString == "Detonate")
self.Kill(self);
self.Kill(self, Info.DamageTypes);
}
}
}
5 changes: 4 additions & 1 deletion OpenRA.Mods.Common/Traits/Buildings/Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class BridgeInfo : ITraitInfo, IRulesetLoaded, Requires<HealthInfo>, Requires<Bu

public WeaponInfo DemolishWeaponInfo { get; private set; }

[Desc("Types of damage that this bridge causes to units over/in path of it while being destroyed/repaired. Leave empty for no damage types.")]
public readonly HashSet<string> DamageTypes = new HashSet<string>();

public object Create(ActorInitializer init) { return new Bridge(init.Self, this); }

public void RulesetLoaded(Ruleset rules, ActorInfo ai)
Expand Down Expand Up @@ -241,7 +244,7 @@ void KillUnitsOnBridge()
foreach (var c in footprint.Keys)
foreach (var a in self.World.ActorMap.GetActorsAt(c))
if (a.Info.HasTraitInfo<IPositionableInfo>() && !a.Trait<IPositionable>().CanEnterCell(c))
a.Kill(self);
a.Kill(self, info.DamageTypes);
}

bool NeighbourIsDeadShore(Bridge neighbour)
Expand Down
5 changes: 4 additions & 1 deletion OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class GroundLevelBridgeInfo : ITraitInfo, IRulesetLoaded, Requires<BuildingInfo>

public WeaponInfo DemolishWeaponInfo { get; private set; }

[Desc("Types of damage that this bridge causes to units over/in path of it while being destroyed/repaired. Leave empty for no damage types.")]
public readonly HashSet<string> DamageTypes = new HashSet<string>();

public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
WeaponInfo weapon;
Expand Down Expand Up @@ -95,7 +98,7 @@ 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);
a.Kill(self, Info.DamageTypes);
}

void IBridgeSegment.Repair(Actor repairer)
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Traits/Crushable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void INotifyCrushed.OnCrush(Actor self, Actor crusher, HashSet<string> crushClas

Game.Sound.Play(SoundType.World, Info.CrushSound, crusher.CenterPosition);

self.Kill(crusher);
var crusherMobile = crusher.TraitOrDefault<Mobile>();
self.Kill(crusher, crusherMobile != null ? crusherMobile.Info.CrushDamageTypes : new HashSet<string>());
}

bool ICrushable.CrushableBy(Actor self, Actor crusher, HashSet<string> crushClasses)
Expand Down
8 changes: 6 additions & 2 deletions OpenRA.Mods.Common/Traits/Health.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

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

Expand Down Expand Up @@ -163,9 +164,12 @@ public void InflictDamage(Actor self, Actor attacker, Damage damage, bool ignore
}
}

public void Kill(Actor self, Actor attacker)
public void Kill(Actor self, Actor attacker, HashSet<string> damageTypes = null)
{
InflictDamage(self, attacker, new Damage(MaxHP), true);
if (damageTypes == null)
damageTypes = new HashSet<string>();

InflictDamage(self, attacker, new Damage(MaxHP, damageTypes), true);
}

void ITick.Tick(Actor self)
Expand Down
6 changes: 5 additions & 1 deletion OpenRA.Mods.Common/Traits/KillsSelf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
#endregion

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

namespace OpenRA.Mods.Common.Traits
Expand All @@ -21,6 +22,9 @@ class KillsSelfInfo : ConditionalTraitInfo
[Desc("The amount of time (in ticks) before the actor dies. Two values indicate a range between which a random value is chosen.")]
public readonly int[] Delay = { 0 };

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

[GrantedConditionReference]
[Desc("The condition to grant moments before suiciding.")]
public readonly string GrantsCondition = null;
Expand Down Expand Up @@ -81,7 +85,7 @@ void Kill(Actor self)
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
self.Dispose();
else
self.Kill(self);
self.Kill(self, Info.DamageTypes);
}
}
}
3 changes: 3 additions & 0 deletions OpenRA.Mods.Common/Traits/Mobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class MobileInfo : ConditionalTraitInfo, IMoveInfo, IPositionableInfo, IF
[Desc("e.g. crate, wall, infantry")]
public readonly HashSet<string> Crushes = new HashSet<string>();

[Desc("Types of damage that caused while crushing. Leave empty for no damage types.")]
public readonly HashSet<string> CrushDamageTypes = new HashSet<string>();

public readonly int WaitAverage = 5;

public readonly int WaitSpread = 2;
Expand Down
5 changes: 4 additions & 1 deletion OpenRA.Mods.Common/Traits/Parachutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class ParachutableInfo : ITraitInfo, Requires<IPositionableInfo>
[Desc("If we land on invalid terrain for my actor type should we be killed?")]
public readonly bool KilledOnImpassableTerrain = true;

[Desc("Types of damage that this trait causes to self when 'KilledOnImpassableTerrain' is true. Leave empty for no damage types.")]
public readonly HashSet<string> DamageTypes = new HashSet<string>();

[Desc("Image where Ground/WaterCorpseSequence is looked up.")]
public readonly string Image = "explosion";

Expand Down Expand Up @@ -101,7 +104,7 @@ void INotifyParachute.OnLanded(Actor self, Actor ignore)
if (sequence != null && palette != null)
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(self.OccupiesSpace.CenterPosition, w, info.Image, sequence, palette)));

self.Kill(self);
self.Kill(self, info.DamageTypes);
}
}
}
4 changes: 1 addition & 3 deletions OpenRA.Mods.Common/Traits/Player/DeveloperMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,13 @@ public void ResolveOrder(Actor self, Order order)
break;

var actor = order.Target.Actor;
var health = actor.TraitOrDefault<Health>();
var args = order.TargetString.Split(' ');
var damageTypes = new HashSet<string>();

foreach (var damageType in args)
damageTypes.Add(damageType);

if (health != null)
health.InflictDamage(actor, actor, new Damage(health.HP, damageTypes), true);
actor.Kill(actor, damageTypes);

break;
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Warheads/DamageWarhead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class DamageWarhead : Warhead
[Desc("How much (raw) damage to deal.")]
public readonly int Damage = 0;

[Desc("Types of damage that this warhead causes. Leave empty for no damage.")]
[Desc("Types of damage that this warhead causes. Leave empty for no damage types.")]
public readonly HashSet<string> DamageTypes = new HashSet<string>();

[Desc("Damage percentage versus each armortype.")]
Expand Down

0 comments on commit 4004f17

Please sign in to comment.