public void Damaged(Actor self, AttackInfo e) { if (!self.IsIdle || !info.TargetWhenDamaged) { return; } var attacker = e.Attacker; if (attacker.Disposed || Stance < UnitStance.ReturnFire) { return; } if (!attacker.IsInWorld && !attacker.Disposed) { // 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(attacker))) { return; } // don't retaliate against own units force-firing on us. It's usually not what the player wanted. if (attacker.AppearsFriendlyTo(self)) { return; } // don't retaliate against healers if (e.Damage < 0) { return; } Aggressor = attacker; if (at == null || !at.IsReachableTarget(at.Target, info.AllowMovement && Stance != UnitStance.Defend)) { Attack(self, Aggressor); } }
bool CanTargetActor(Actor self, Target target, TargetModifiers modifiers, ref string cursor) { IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); var a = ab.ChooseArmamentForTarget(target); cursor = a != null && !target.IsInRange(self.CenterPosition, a.Weapon.Range) ? ab.Info.OutsideRangeCursor : ab.Info.Cursor; if (target.Type == TargetType.Actor && target.Actor == self) { return(false); } if (!ab.HasAnyValidWeapons(target)) { return(false); } if (modifiers.HasModifier(TargetModifiers.ForceAttack)) { return(true); } if (modifiers.HasModifier(TargetModifiers.ForceMove)) { return(false); } if (target.RequiresForceFire) { return(false); } var targetableRelationship = negativeDamage ? Stance.Ally : Stance.Enemy; var owner = target.Type == TargetType.FrozenActor ? target.FrozenActor.Owner : target.Actor.Owner; return(self.Owner.Stances[owner] == targetableRelationship); }