Skip to content

Commit

Permalink
Add AttackSource enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote authored and teinarss committed Jan 18, 2020
1 parent 6f52365 commit 51870a4
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/Attack/AttackLeap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void RevokeLeapCondition(Actor self)
leapToken = conditionManager.RevokeCondition(self, leapToken);
}

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
{
return new LeapAttack(self, newTarget, allowMove, forceAttack, this, info, targetLineColor);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/Attack/AttackTDGunboatTurreted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AttackTDGunboatTurreted : AttackTurreted
public AttackTDGunboatTurreted(Actor self, AttackTDGunboatTurretedInfo info)
: base(self, info) { }

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
{
return new AttackTDGunboatTurretedActivity(self, newTarget, allowMove, forceAttack, targetLineColor);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/Attack/AttackTesla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barre

void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel) { }

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
return new ChargeAttack(this, newTarget, forceAttack, targetLineColor);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/SupportPowers/AttackOrderPower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void Activate(Actor self, Order order, SupportPowerManager manag
{
base.Activate(self, order, manager);

attack.AttackTarget(order.Target, false, false, true);
attack.AttackTarget(order.Target, AttackSource.Default, false, false, true);
}

protected override void Created(Actor self)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override bool Tick(Actor self)
ChildActivity.Cancel(self);
var attackBases = autoTarget.ActiveAttackBases;
foreach (var ab in attackBases)
QueueChild(ab.GetAttackActivity(self, target, false, false));
QueueChild(ab.GetAttackActivity(self, AttackSource.AttackMove, target, false, false));

// Make sure to continue moving when the attack activities have finished.
QueueChild(getInner());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void Attack(Actor targetActor, bool allowMove = true, bool forceAttack =
Log.Write("lua", "{1} is not revealed for player {0}!", Self.Owner, targetActor);

foreach (var attack in attackBases)
attack.AttackTarget(target, true, allowMove, forceAttack);
attack.AttackTarget(target, AttackSource.Default, true, allowMove, forceAttack);
}

[Desc("Checks if the targeted actor is a valid target for this actor.")]
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Air/AttackAircraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public AttackAircraft(Actor self, AttackAircraftInfo info)
aircraftInfo = self.Info.TraitInfo<AircraftInfo>();
}

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
return new FlyAttack(self, newTarget, forceAttack, targetLineColor);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Air/AttackBomber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
OnRemovedFromWorld(self);
}

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
{
throw new NotImplementedException("AttackBomber requires a scripted target");
}
Expand Down
10 changes: 6 additions & 4 deletions OpenRA.Mods.Common/Traits/Attack/AttackBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace OpenRA.Mods.Common.Traits
{
public enum AttackSource { Default, AutoTarget, AttackMove }

public abstract class AttackBaseInfo : PausableConditionalTraitInfo
{
[Desc("Armament names")]
Expand Down Expand Up @@ -199,7 +201,7 @@ void IResolveOrder.ResolveOrder(Actor self, Order order)
if (!order.Target.IsValidFor(self))
return;

AttackTarget(order.Target, order.Queued, true, forceAttack, Info.TargetLineColor);
AttackTarget(order.Target, AttackSource.Default, order.Queued, true, forceAttack, Info.TargetLineColor);
self.ShowTargetLines();
}

Expand All @@ -224,7 +226,7 @@ string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
return order.OrderString == attackOrderName || order.OrderString == forceAttackOrderName ? Info.Voice : null;
}

public abstract Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null);
public abstract Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null);

public bool HasAnyValidWeapons(Target t, bool checkForCenterTargetingWeapons = false)
{
Expand Down Expand Up @@ -391,15 +393,15 @@ public IEnumerable<Armament> ChooseArmamentsForTarget(Target t, bool forceAttack
&& a.Weapon.IsValidAgainst(t, self.World, self));
}

public void AttackTarget(Target target, bool queued, bool allowMove, bool forceAttack = false, Color? targetLineColor = null)
public void AttackTarget(Target target, AttackSource source, bool queued, bool allowMove, bool forceAttack = false, Color? targetLineColor = null)
{
if (IsTraitDisabled)
return;

if (!target.IsValidFor(self))
return;

var activity = GetAttackActivity(self, target, allowMove, forceAttack, targetLineColor);
var activity = GetAttackActivity(self, source, target, allowMove, forceAttack, targetLineColor);
self.QueueActivity(queued, activity);
OnResolveAttackOrder(self, activity, target, queued, forceAttack);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected override void Tick(Actor self)
base.Tick(self);
}

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
return new AttackActivity(self, newTarget, allowMove, forceAttack, targetLineColor);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackFrontal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override bool CanAttack(Actor self, Target target)
return TargetInFiringArc(self, target, Info.FacingTolerance);
}

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
return new Activities.Attack(self, newTarget, allowMove, forceAttack, targetLineColor);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackOmni.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AttackOmni : AttackBase
public AttackOmni(Actor self, AttackOmniInfo info)
: base(self, info) { }

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
{
return new SetTarget(this, newTarget, allowMove, forceAttack, targetLineColor);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/AutoTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void ScanAndAttack(Actor self, bool allowMove, bool allowTurn)
void Attack(Actor self, Target target, bool allowMove)
{
foreach (var ab in ActiveAttackBases)
ab.AttackTarget(target, false, allowMove);
ab.AttackTarget(target, AttackSource.AutoTarget, false, allowMove);
}

public bool HasValidTargetPriority(Actor self, Player owner, BitSet<TargetableType> targetTypes)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.D2k/Traits/AttackSwallow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override void DoAttack(Actor self, Target target)
self.QueueActivity(false, new SwallowActor(self, target, a, facing));
}

public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)
{
return new SwallowTarget(self, newTarget, allowMove, forceAttack);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.D2k/Traits/Sandworm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void RescanForTargets(Actor self)

if (target.Type == TargetType.Actor)
{
attackTrait.AttackTarget(target, false, true, false);
attackTrait.AttackTarget(target, AttackSource.AutoTarget, false, true, false);
return;
}

Expand Down

0 comments on commit 51870a4

Please sign in to comment.