Fix retaliation against garrisoned actors.
This commit is contained in:
@@ -72,27 +72,33 @@ namespace OpenRA.Mods.RA
|
|||||||
if (!self.IsIdle || !info.TargetWhenDamaged)
|
if (!self.IsIdle || !info.TargetWhenDamaged)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (e.Attacker.Destroyed)
|
var attacker = e.Attacker;
|
||||||
|
if (attacker.Destroyed || Stance < UnitStance.ReturnFire)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Stance < UnitStance.ReturnFire) return;
|
if (!attacker.IsInWorld && !attacker.Destroyed)
|
||||||
|
{
|
||||||
|
// If the aggressor is in a transport, then attack the transport instead
|
||||||
|
var passenger = attacker.TraitOrDefault<Passenger>();
|
||||||
|
if (passenger != null && passenger.Transport != null)
|
||||||
|
attacker = passenger.Transport;
|
||||||
|
}
|
||||||
|
|
||||||
// not a lot we can do about things we can't hurt... although maybe we should automatically run away?
|
// not a lot we can do about things we can't hurt... although maybe we should automatically run away?
|
||||||
if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker)))
|
if (!attack.HasAnyValidWeapons(Target.FromActor(attacker)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// don't retaliate against own units force-firing on us. It's usually not what the player wanted.
|
// don't retaliate against own units force-firing on us. It's usually not what the player wanted.
|
||||||
if (e.Attacker.AppearsFriendlyTo(self))
|
if (attacker.AppearsFriendlyTo(self))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// don't retaliate against healers
|
// don't retaliate against healers
|
||||||
if (e.Damage < 0)
|
if (e.Damage < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Aggressor = e.Attacker;
|
Aggressor = attacker;
|
||||||
|
|
||||||
if (at == null || !at.IsReachableTarget(at.Target, info.AllowMovement && Stance != UnitStance.Defend))
|
if (at == null || !at.IsReachableTarget(at.Target, info.AllowMovement && Stance != UnitStance.Defend))
|
||||||
Attack(self, e.Attacker);
|
Attack(self, Aggressor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TickIdle(Actor self)
|
public void TickIdle(Actor self)
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ namespace OpenRA.Mods.RA
|
|||||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerExited>())
|
foreach (var npe in self.TraitsImplementing<INotifyPassengerExited>())
|
||||||
npe.PassengerExited(self, a);
|
npe.PassengerExited(self, a);
|
||||||
|
|
||||||
|
a.Trait<Passenger>().Transport = null;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +179,8 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||||
npe.PassengerEntered(self, a);
|
npe.PassengerEntered(self, a);
|
||||||
|
|
||||||
|
a.Trait<Passenger>().Transport = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
public void Killed(Actor self, AttackInfo e)
|
||||||
@@ -205,10 +208,13 @@ namespace OpenRA.Mods.RA
|
|||||||
// Notify initial cargo load
|
// Notify initial cargo load
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
foreach (var c in cargo)
|
||||||
foreach (var c in cargo)
|
{
|
||||||
npe.PassengerEntered(self, c);
|
c.Trait<Passenger>().Transport = self;
|
||||||
|
|
||||||
|
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||||
|
npe.PassengerEntered(self, c);
|
||||||
|
}
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
public readonly PassengerInfo info;
|
public readonly PassengerInfo info;
|
||||||
public Passenger( PassengerInfo info ) { this.info = info; }
|
public Passenger( PassengerInfo info ) { this.info = info; }
|
||||||
|
public Actor Transport;
|
||||||
|
|
||||||
public IEnumerable<IOrderTargeter> Orders
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user