Skip to content

Commit

Permalink
Replace EjectOnDeath with EjectOnDeathDamage.
Browse files Browse the repository at this point in the history
Allows me to create the original behaviour where most passengers get
damaged by 10, and for some transport 50% damage. 100 makes the
passengers get killed.
  • Loading branch information
MustaphaTR committed Jun 13, 2018
1 parent fc758b7 commit a44f93c
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions OpenRA.Mods.Common/Traits/Cargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class CargoInfo : PausableConditionalTraitInfo, Requires<IOccupySpaceInfo
[Desc("When this actor is sold should all of its passengers be unloaded?")]
public readonly bool EjectOnSell = true;

[Desc("When this actor dies should all of its passengers be unloaded?")]
public readonly bool EjectOnDeath = false;
[Desc("When this actor dies this much percent of passengers total health is dealt to them.")]
public readonly int EjectOnDeathDamage = 100;

[Desc("Terrain types that this actor is allowed to eject actors onto. Leave empty for all terrain types.")]
public readonly HashSet<string> UnloadTerrainTypes = new HashSet<string>();
Expand Down Expand Up @@ -378,28 +378,31 @@ public void Load(Actor self, Actor a)

void INotifyKilled.Killed(Actor self, AttackInfo e)
{
if (Info.EjectOnDeath)
while (!IsEmpty(self) && CanUnload())
while (!IsEmpty(self) && CanUnload())
{
var passenger = Unload(self);
var cp = self.CenterPosition;
var inAir = self.World.Map.DistanceAboveTerrain(cp).Length != 0;
var positionable = passenger.Trait<IPositionable>();
var health = passenger.TraitOrDefault<Health>();
positionable.SetPosition(passenger, self.Location);

if (self.Owner.WinState != WinState.Lost && !inAir && positionable.CanEnterCell(self.Location, self, false))
{
var passenger = Unload(self);
var cp = self.CenterPosition;
var inAir = self.World.Map.DistanceAboveTerrain(cp).Length != 0;
var positionable = passenger.Trait<IPositionable>();
positionable.SetPosition(passenger, self.Location);
self.World.AddFrameEndTask(w => w.Add(passenger));
var nbm = passenger.TraitOrDefault<INotifyBlockingMove>();
if (nbm != null)
nbm.OnNotifyBlockingMove(passenger, passenger);

if (self.Owner.WinState != WinState.Lost && !inAir && positionable.CanEnterCell(self.Location, self, false))
if (Info.EjectOnDeathDamage > 0 && health != null)
{
self.World.AddFrameEndTask(w => w.Add(passenger));
var nbm = passenger.TraitOrDefault<INotifyBlockingMove>();
if (nbm != null)
nbm.OnNotifyBlockingMove(passenger, passenger);
var damage = (health.MaxHP * Info.EjectOnDeathDamage) / 100;
health.InflictDamage(passenger, e.Attacker, new Damage(damage, e.Damage.DamageTypes), true);
}
else
passenger.Kill(e.Attacker);
}

foreach (var c in cargo)
c.Kill(e.Attacker);
else
passenger.Kill(e.Attacker);
}

cargo.Clear();
}
Expand Down

0 comments on commit a44f93c

Please sign in to comment.