Skip to content

Commit

Permalink
check name for Actor.GrantCondition()
Browse files Browse the repository at this point in the history
  • Loading branch information
atlimit8 authored and abcdefg30 committed May 17, 2020
1 parent 1d2d8ed commit 1ef27d1
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 44 deletions.
8 changes: 7 additions & 1 deletion OpenRA.Game/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,16 @@ void UpdateConditionState(string condition, int token, bool isRevoke)
notify(this, readOnlyConditionCache);
}

/// <summary>Grants a specified condition.</summary>
/// <summary>
/// Grants a specified condition if it is valid.
/// Otherwise, just returns InvalidConditionToken.
/// </summary>
/// <returns>The token that is used to revoke this condition.</returns>
public int GrantCondition(string condition)
{
if (string.IsNullOrEmpty(condition))
return InvalidConditionToken;

var token = nextConditionToken++;
conditionTokens.Add(token, condition);
UpdateConditionState(condition, token, false);
Expand Down
3 changes: 1 addition & 2 deletions OpenRA.Mods.Cnc/Traits/Attack/AttackLeap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ protected override bool CanAttack(Actor self, Target target)

public void GrantLeapCondition(Actor self)
{
if (!string.IsNullOrEmpty(info.LeapCondition))
leapToken = self.GrantCondition(info.LeapCondition);
leapToken = self.GrantCondition(info.LeapCondition);
}

public void RevokeLeapCondition(Actor self)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/ConyardChronoReturn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void ReplacementConditionChanged(Actor self, IReadOnlyDictionary<string, int> co

void TriggerVortex()
{
if (!string.IsNullOrEmpty(info.Condition) && conditionToken == Actor.InvalidConditionToken)
if (conditionToken == Actor.InvalidConditionToken)
conditionToken = self.GrantCondition(info.Condition);

triggered = true;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/Disguise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void HandleDisguise(ActorInfo oldEffectiveActor, Player oldEffectiveOwner, bool

if (Disguised != oldDisguiseSetting)
{
if (Disguised && disguisedToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(info.DisguisedCondition))
if (Disguised && disguisedToken == Actor.InvalidConditionToken)
disguisedToken = self.GrantCondition(info.DisguisedCondition);
else if (!Disguised && disguisedToken != Actor.InvalidConditionToken)
disguisedToken = self.RevokeCondition(disguisedToken);
Expand Down
3 changes: 1 addition & 2 deletions OpenRA.Mods.Cnc/Traits/MadTank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ public override bool Tick(Actor self)
if (target.Type == TargetType.Invalid)
return true;

if (!string.IsNullOrEmpty(mad.info.DeployedCondition))
self.GrantCondition(mad.info.DeployedCondition);
self.GrantCondition(mad.info.DeployedCondition);

self.World.AddFrameEndTask(w => EjectDriver());
if (mad.info.ThumpSequence != null)
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ protected override void OnFirstRun(Actor self)
if (attackMove == null)
return;

if (!isAssaultMove && !string.IsNullOrEmpty(attackMove.Info.AttackMoveCondition))
token = self.GrantCondition(attackMove.Info.AttackMoveCondition);
else if (isAssaultMove && !string.IsNullOrEmpty(attackMove.Info.AssaultMoveCondition))
if (isAssaultMove)
token = self.GrantCondition(attackMove.Info.AssaultMoveCondition);
else
token = self.GrantCondition(attackMove.Info.AttackMoveCondition);
}

public override bool Tick(Actor self)
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Air/Aircraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ void OnAirborneAltitudeReached()
return;

airborne = true;
if (!string.IsNullOrEmpty(Info.AirborneCondition) && airborneToken == Actor.InvalidConditionToken)
if (airborneToken == Actor.InvalidConditionToken)
airborneToken = self.GrantCondition(Info.AirborneCondition);
}

Expand All @@ -1138,7 +1138,7 @@ void OnCruisingAltitudeReached()
return;

cruising = true;
if (!string.IsNullOrEmpty(Info.CruisingCondition) && cruisingToken == Actor.InvalidConditionToken)
if (cruisingToken == Actor.InvalidConditionToken)
cruisingToken = self.GrantCondition(Info.CruisingCondition);
}

Expand Down
3 changes: 1 addition & 2 deletions OpenRA.Mods.Common/Traits/Attack/AttackCharges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ protected override void Tick(Actor self)
var delta = charging ? info.ChargeRate : -info.DischargeRate;
ChargeLevel = (ChargeLevel + delta).Clamp(0, info.ChargeLevel);

if (ChargeLevel > 0 && !string.IsNullOrEmpty(info.ChargingCondition)
&& chargingToken == Actor.InvalidConditionToken)
if (ChargeLevel > 0 && chargingToken == Actor.InvalidConditionToken)
chargingToken = self.GrantCondition(info.ChargingCondition);

if (ChargeLevel == 0 && chargingToken != Actor.InvalidConditionToken)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Buildings/PrimaryBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void SetPrimaryProducer(Actor self, bool isPrimary)
b.Trait.SetPrimaryProducer(b.Actor, false);
}

if (primaryToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(Info.PrimaryCondition))
if (primaryToken == Actor.InvalidConditionToken)
primaryToken = self.GrantCondition(Info.PrimaryCondition);

Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Info.SelectionNotification, self.Owner.Faction.InternalName);
Expand Down
6 changes: 2 additions & 4 deletions OpenRA.Mods.Common/Traits/CaptureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,10 @@ public bool StartCapture(Actor self, Actor target, CaptureManager targetManager,
else
currentTargetDelay += 1;

if (!string.IsNullOrEmpty(info.CapturingCondition) &&
capturingToken == Actor.InvalidConditionToken)
if (capturingToken == Actor.InvalidConditionToken)
capturingToken = self.GrantCondition(info.CapturingCondition);

if (!string.IsNullOrEmpty(targetManager.info.BeingCapturedCondition) &&
targetManager.beingCapturedToken == Actor.InvalidConditionToken)
if (targetManager.beingCapturedToken == Actor.InvalidConditionToken)
targetManager.beingCapturedToken = target.GrantCondition(targetManager.info.BeingCapturedCondition);

captures = enabledCaptures
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Cargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ internal bool ReserveSpace(Actor a)
if (!HasSpace(w))
return false;

if (loadingToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(Info.LoadingCondition))
if (loadingToken == Actor.InvalidConditionToken)
loadingToken = self.GrantCondition(Info.LoadingCondition);

reserves.Add(a);
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Mods.Common/Traits/Carryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public virtual void Attached(Actor self)

attached = true;

if (carriedToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(Info.CarriedCondition))
if (carriedToken == Actor.InvalidConditionToken)
carriedToken = self.GrantCondition(Info.CarriedCondition);
}

Expand All @@ -102,7 +102,7 @@ public virtual bool Reserve(Actor self, Actor carrier)
state = State.Reserved;
Carrier = carrier;

if (reservedToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(Info.ReservedCondition))
if (reservedToken == Actor.InvalidConditionToken)
reservedToken = self.GrantCondition(Info.ReservedCondition);

return true;
Expand Down Expand Up @@ -134,7 +134,7 @@ public virtual LockResponse LockForPickup(Actor self, Actor carrier)
state = State.Locked;
Carrier = carrier;

if (lockedToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(Info.LockedCondition))
if (lockedToken == Actor.InvalidConditionToken)
lockedToken = self.GrantCondition(Info.LockedCondition);
}

Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Cloak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected override void Created(Actor self)
if (Cloaked)
{
wasCloaked = true;
if (cloakedToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
if (cloakedToken == Actor.InvalidConditionToken)
cloakedToken = self.GrantCondition(Info.CloakedCondition);
}

Expand Down Expand Up @@ -163,7 +163,7 @@ void ITick.Tick(Actor self)
var isCloaked = Cloaked;
if (isCloaked && !wasCloaked)
{
if (cloakedToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
if (cloakedToken == Actor.InvalidConditionToken)
cloakedToken = self.GrantCondition(Info.CloakedCondition);

// Sounds shouldn't play if the actor starts cloaked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void OnDeployStarted()

void OnDeployCompleted()
{
if (!string.IsNullOrEmpty(Info.DeployedCondition) && deployedToken == Actor.InvalidConditionToken)
if (deployedToken == Actor.InvalidConditionToken)
deployedToken = self.GrantCondition(Info.DeployedCondition);

deployState = DeployState.Deployed;
Expand All @@ -339,7 +339,7 @@ void OnUndeployStarted()

void OnUndeployCompleted()
{
if (!string.IsNullOrEmpty(Info.UndeployedCondition) && undeployedToken == Actor.InvalidConditionToken)
if (undeployedToken == Actor.InvalidConditionToken)
undeployedToken = self.GrantCondition(Info.UndeployedCondition);

deployState = DeployState.Undeployed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public GrantConditionOnLineBuildDirection(ActorInitializer init, GrantConditionO

void INotifyCreated.Created(Actor self)
{
if (direction != info.Direction)
return;

if (!string.IsNullOrEmpty(info.Condition))
if (direction == info.Direction)
self.GrantCondition(info.Condition);
}
}
Expand Down
5 changes: 1 addition & 4 deletions OpenRA.Mods.Common/Traits/Demolishable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ void IDemolishable.Demolish(Actor self, Actor saboteur, int delay)
if (IsTraitDisabled)
return;

var token = Actor.InvalidConditionToken;
if (!string.IsNullOrEmpty(Info.Condition))
token = self.GrantCondition(Info.Condition);

var token = self.GrantCondition(Info.Condition);
actions.Add(new DemolishAction(saboteur, delay, token));
}

Expand Down
3 changes: 1 addition & 2 deletions OpenRA.Mods.Common/Traits/KillsSelf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ void Kill(Actor self)
if (self.IsDead)
return;

if (!string.IsNullOrEmpty(Info.GrantsCondition))
self.GrantCondition(Info.GrantsCondition);
self.GrantCondition(Info.GrantsCondition);

if (Info.RemoveInstead || !self.Info.HasTraitInfo<IHealthInfo>())
self.Dispose();
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Parachutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void INotifyParachute.OnParachute(Actor self)
{
IsInAir = true;

if (parachutingToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(info.ParachutingCondition))
if (parachutingToken == Actor.InvalidConditionToken)
parachutingToken = self.GrantCondition(info.ParachutingCondition);

self.NotifyBlocker(self.Location);
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Passenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void INotifyEnteredCargo.OnEnteredCargo(Actor self, Actor cargo)
{
string specificCargoCondition;

if (anyCargoToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(Info.CargoCondition))
if (anyCargoToken == Actor.InvalidConditionToken)
anyCargoToken = self.GrantCondition(Info.CargoCondition);

if (specificCargoToken == Actor.InvalidConditionToken && Info.CargoConditions.TryGetValue(cargo.Info.Name, out specificCargoCondition))
Expand Down
7 changes: 3 additions & 4 deletions OpenRA.Mods.Common/Traits/Render/WithMakeAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void INotifyCreated.Created(Actor self)

public void Forward(Actor self, Action onComplete)
{
if (!string.IsNullOrEmpty(info.Condition) && token == Actor.InvalidConditionToken)
if (token == Actor.InvalidConditionToken)
token = self.GrantCondition(info.Condition);

var wsb = wsbs.FirstEnabledTraitOrDefault();
Expand All @@ -80,7 +80,7 @@ public void Forward(Actor self, Action onComplete)

public void Reverse(Actor self, Action onComplete)
{
if (!string.IsNullOrEmpty(info.Condition) && token == Actor.InvalidConditionToken)
if (token == Actor.InvalidConditionToken)
token = self.GrantCondition(info.Condition);

var wsb = wsbs.FirstEnabledTraitOrDefault();
Expand Down Expand Up @@ -114,8 +114,7 @@ public void Reverse(Actor self, Activity activity, bool queued = true)
if (wsb != null)
wsb.DefaultAnimation.PlayFetchIndex(info.Sequence, () => 0);

if (!string.IsNullOrEmpty(info.Condition))
token = self.GrantCondition(info.Condition);
token = self.GrantCondition(info.Condition);

self.QueueActivity(queued, activity);
});
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.D2k/Activities/SwallowActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ public override bool Tick(Actor self)
stance = AttackState.Burrowed;
countdown = swallow.Info.AttackDelay;
burrowLocation = self.Location;
if (attackingToken == Actor.InvalidConditionToken && !string.IsNullOrEmpty(swallow.Info.AttackingCondition))
if (attackingToken == Actor.InvalidConditionToken)
attackingToken = self.GrantCondition(swallow.Info.AttackingCondition);

break;
case AttackState.Burrowed:
if (--countdown > 0)
Expand Down

0 comments on commit 1ef27d1

Please sign in to comment.