prevent allied units from autoattack building which is being captured…
This commit is contained in:
Oliver Brakmann
2015-11-12 21:42:39 +01:00
4 changed files with 24 additions and 3 deletions

View File

@@ -168,7 +168,8 @@ namespace OpenRA.Mods.Common.Traits
Actor ChooseTarget(Actor self, WDist range, bool allowMove)
{
var inRange = self.World.FindActorsInCircle(self.CenterPosition, range)
.Where(a => !a.Info.HasTraitInfo<AutoTargetIgnoreInfo>());
.Where(a =>
!a.TraitsImplementing<IPreventsAutoTarget>().Any(t => t.PreventsAutoTarget(a, self)));
// Armaments are enumerated in attack.Armaments in construct order
// When autotargeting, first choose targets according to the used armament construct order
@@ -207,7 +208,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Will not get automatically targeted by enemy (like walls)")]
class AutoTargetIgnoreInfo : TraitInfo<AutoTargetIgnore> { }
class AutoTargetIgnore { }
class AutoTargetIgnore : IPreventsAutoTarget
{
public bool PreventsAutoTarget(Actor self, Actor attacker)
{
return true;
}
}
public class StanceInit : IActorInit<UnitStance>
{

View File

@@ -24,6 +24,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Seconds it takes to change the owner.", "You might want to add a ExternalCapturableBar: trait, too.")]
public readonly int CaptureCompleteTime = 15;
[Desc("Whether to prevent autotargeting this actor while it is being captured by an ally.")]
public readonly bool PreventsAutoTarget = true;
public bool CanBeTargetedBy(Actor captor, Player owner)
{
var c = captor.Info.TraitInfoOrDefault<ExternalCapturesInfo>();
@@ -49,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new ExternalCapturable(init.Self, this); }
}
public class ExternalCapturable : ITick, ISync
public class ExternalCapturable : ITick, ISync, IPreventsAutoTarget
{
[Sync] public int CaptureProgressTime = 0;
[Sync] public Actor Captor;
@@ -91,5 +94,10 @@ namespace OpenRA.Mods.Common.Traits
else
CaptureProgressTime++;
}
public bool PreventsAutoTarget(Actor self, Actor attacker)
{
return Info.PreventsAutoTarget && Captor != null && attacker.AppearsFriendlyTo(Captor);
}
}
}

View File

@@ -121,4 +121,9 @@ namespace OpenRA.Mods.Common.Traits
{
void ModifyDeathActorInit(Actor self, TypeDictionary init);
}
public interface IPreventsAutoTarget
{
bool PreventsAutoTarget(Actor self, Actor attacker);
}
}