Fix retaliation against garrisoned actors.
This commit is contained in:
@@ -72,27 +72,33 @@ namespace OpenRA.Mods.RA
|
||||
if (!self.IsIdle || !info.TargetWhenDamaged)
|
||||
return;
|
||||
|
||||
if (e.Attacker.Destroyed)
|
||||
var attacker = e.Attacker;
|
||||
if (attacker.Destroyed || Stance < UnitStance.ReturnFire)
|
||||
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?
|
||||
if (!attack.HasAnyValidWeapons(Target.FromActor(e.Attacker)))
|
||||
if (!attack.HasAnyValidWeapons(Target.FromActor(attacker)))
|
||||
return;
|
||||
|
||||
// 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;
|
||||
|
||||
// don't retaliate against healers
|
||||
if (e.Damage < 0)
|
||||
return;
|
||||
|
||||
Aggressor = e.Attacker;
|
||||
|
||||
Aggressor = attacker;
|
||||
if (at == null || !at.IsReachableTarget(at.Target, info.AllowMovement && Stance != UnitStance.Defend))
|
||||
Attack(self, e.Attacker);
|
||||
Attack(self, Aggressor);
|
||||
}
|
||||
|
||||
public void TickIdle(Actor self)
|
||||
|
||||
@@ -144,6 +144,7 @@ namespace OpenRA.Mods.RA
|
||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerExited>())
|
||||
npe.PassengerExited(self, a);
|
||||
|
||||
a.Trait<Passenger>().Transport = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -178,6 +179,8 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||
npe.PassengerEntered(self, a);
|
||||
|
||||
a.Trait<Passenger>().Transport = self;
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
@@ -205,10 +208,13 @@ namespace OpenRA.Mods.RA
|
||||
// Notify initial cargo load
|
||||
if (!initialized)
|
||||
{
|
||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||
foreach (var c in cargo)
|
||||
npe.PassengerEntered(self, c);
|
||||
foreach (var c in cargo)
|
||||
{
|
||||
c.Trait<Passenger>().Transport = self;
|
||||
|
||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||
npe.PassengerEntered(self, c);
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
public readonly PassengerInfo info;
|
||||
public Passenger( PassengerInfo info ) { this.info = info; }
|
||||
public Actor Transport;
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user