Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename remaining Stance references to PlayerRelationship. #19129

Merged
merged 1 commit into from Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenRA.Game/Player.cs
Expand Up @@ -265,7 +265,7 @@ public bool IsAlliedWith(Player p)
return RelationshipWith(p) == PlayerRelationship.Ally;
}

public Color PlayerStanceColor(Actor a)
public Color PlayerRelationshipColor(Actor a)
{
var player = a.World.RenderPlayer ?? a.World.LocalPlayer;
if (player != null && !player.Spectating)
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Game/Traits/TraitsInterfaces.cs
Expand Up @@ -76,12 +76,12 @@ public enum PlayerRelationship
Ally = 4,
}

public static class StanceExts
public static class PlayerRelationshipExts
{
public static bool HasStance(this PlayerRelationship s, PlayerRelationship stance)
public static bool HasRelationship(this PlayerRelationship r, PlayerRelationship relationship)
{
// PERF: Enum.HasFlag is slower and requires allocations.
return (s & stance) == stance;
return (r & relationship) == relationship;
}
}

Expand Down
10 changes: 5 additions & 5 deletions OpenRA.Mods.Cnc/Traits/Disguise.cs
Expand Up @@ -167,7 +167,7 @@ Color IRadarColorModifier.RadarColorOverride(Actor self, Color color)
if (!Disguised || self.Owner.IsAlliedWith(self.World.RenderPlayer))
return color;

return color = Game.Settings.Game.UsePlayerStanceColors ? AsPlayer.PlayerStanceColor(self) : AsPlayer.Color;
return color = Game.Settings.Game.UsePlayerStanceColors ? AsPlayer.PlayerRelationshipColor(self) : AsPlayer.Color;
}

public void DisguiseAs(Actor target)
Expand Down Expand Up @@ -298,17 +298,17 @@ public DisguiseOrderTargeter(DisguiseInfo info)

public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{
var stance = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidRelationships.HasStance(stance))
var relationship = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidRelationships.HasRelationship(relationship))
return false;

return info.TargetTypes.Overlaps(target.GetAllTargetTypes());
}

public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
var stance = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidRelationships.HasStance(stance))
var relationship = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidRelationships.HasRelationship(relationship))
return false;

return info.TargetTypes.Overlaps(target.Info.GetAllTargetTypes());
Expand Down
Expand Up @@ -48,7 +48,7 @@ void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, BitSet<Target

protected override bool ShouldRender(Actor self)
{
return infiltrators.Any(i => Info.ValidRelationships.HasStance(i.RelationshipWith(self.World.RenderPlayer)));
return infiltrators.Any(i => Info.ValidRelationships.HasRelationship(i.RelationshipWith(self.World.RenderPlayer)));
}
}
}
8 changes: 4 additions & 4 deletions OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs
Expand Up @@ -101,10 +101,10 @@ public bool CanInfiltrateTarget(Actor self, in Target target)
{
case TargetType.Actor:
return Info.Types.Overlaps(target.Actor.GetEnabledTargetTypes()) &&
Info.ValidRelationships.HasStance(self.Owner.RelationshipWith(target.Actor.Owner));
Info.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(target.Actor.Owner));
case TargetType.FrozenActor:
return target.FrozenActor.IsValid && Info.Types.Overlaps(target.FrozenActor.TargetTypes) &&
Info.ValidRelationships.HasStance(self.Owner.RelationshipWith(target.FrozenActor.Owner));
Info.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(target.FrozenActor.Owner));
default:
return false;
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public InfiltrationOrderTargeter(InfiltratesInfo info)
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{
var stance = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidRelationships.HasStance(stance))
if (!info.ValidRelationships.HasRelationship(stance))
return false;

return info.Types.Overlaps(target.GetAllTargetTypes());
Expand All @@ -145,7 +145,7 @@ public override bool CanTargetActor(Actor self, Actor target, TargetModifiers mo
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
var stance = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidRelationships.HasStance(stance))
if (!info.ValidRelationships.HasRelationship(stance))
return false;

return info.Types.Overlaps(target.Info.GetAllTargetTypes());
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/CaptureActor.cs
Expand Up @@ -124,7 +124,7 @@ void DoCapture(Actor self, Captures captures)
foreach (var t in enterActor.TraitsImplementing<INotifyCapture>())
t.OnCapture(enterActor, self, oldOwner, self.Owner, captures.Info.CaptureTypes);

if (self.Owner.RelationshipWith(oldOwner).HasStance(captures.Info.PlayerExperienceRelationships))
if (self.Owner.RelationshipWith(oldOwner).HasRelationship(captures.Info.PlayerExperienceRelationships))
self.Owner.PlayerActor.TraitOrDefault<PlayerExperience>()?.GiveExperience(captures.Info.PlayerExperience);

if (captures.Info.ConsumedByCapture)
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Activities/RepairBuilding.cs
Expand Up @@ -38,7 +38,7 @@ protected override bool TryStartEnter(Actor self, Actor targetActor)
// Make sure we can still repair the target before entering
// (but not before, because this may stop the actor in the middle of nowhere)
var stance = self.Owner.RelationshipWith(enterActor.Owner);
if (enterHealth == null || enterHealth.DamageState == DamageState.Undamaged || enterEngineerRepariable == null || enterEngineerRepariable.IsTraitDisabled || !info.ValidRelationships.HasStance(stance))
if (enterHealth == null || enterHealth.DamageState == DamageState.Undamaged || enterEngineerRepariable == null || enterEngineerRepariable.IsTraitDisabled || !info.ValidRelationships.HasRelationship(stance))
{
Cancel(self, true);
return false;
Expand All @@ -61,7 +61,7 @@ protected override void OnEnterComplete(Actor self, Actor targetActor)
return;

var stance = self.Owner.RelationshipWith(enterActor.Owner);
if (!info.ValidRelationships.HasStance(stance))
if (!info.ValidRelationships.HasRelationship(stance))
return;

if (enterHealth.DamageState == DamageState.Undamaged)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Effects/RevealShroudEffect.cs
Expand Up @@ -43,7 +43,7 @@ public RevealShroudEffect(WPos pos, WDist radius, Shroud.SourceType type, Player

void AddCellsToPlayerShroud(Player p, PPos[] uv)
{
if (validStances.HasStance(player.RelationshipWith(p)))
if (validStances.HasRelationship(player.RelationshipWith(p)))
p.Shroud.AddSource(this, sourceType, uv);
}

Expand Down
Expand Up @@ -131,7 +131,7 @@ void DrawBar(WorldRenderer wr, float value, Color barColor, int barNum, float? s
Color GetHealthColor(IHealth health)
{
if (Game.Settings.Game.UsePlayerStanceColors)
return actor.Owner.PlayerStanceColor(actor);
return actor.Owner.PlayerRelationshipColor(actor);

return health.DamageState == DamageState.Critical ? Color.Red :
health.DamageState == DamageState.Heavy ? Color.Yellow : Color.LimeGreen;
Expand Down
Expand Up @@ -87,7 +87,7 @@ void DrawSelectionBar(WorldRenderer wr, float2 start, float2 end, float value, C
Color GetHealthColor(IHealth health)
{
if (Game.Settings.Game.UsePlayerStanceColors)
return actor.Owner.PlayerStanceColor(actor);
return actor.Owner.PlayerRelationshipColor(actor);

return health.DamageState == DamageState.Critical ? Color.Red :
health.DamageState == DamageState.Heavy ? Color.Yellow : Color.LimeGreen;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Projectiles/Bullet.cs
Expand Up @@ -319,7 +319,7 @@ bool AnyValidTargetsInRadius(World world, WPos pos, WDist radius, Actor firedBy,
if (checkTargetType && !Target.FromActor(victim).IsValidFor(firedBy))
continue;

if (!info.ValidBounceBlockerRelationships.HasStance(firedBy.Owner.RelationshipWith(victim.Owner)))
if (!info.ValidBounceBlockerRelationships.HasRelationship(firedBy.Owner.RelationshipWith(victim.Owner)))
continue;

// If the impact position is within any actor's HitShape, we have a direct hit
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Projectiles/Missile.cs
Expand Up @@ -429,7 +429,7 @@ bool JammedBy(TraitPair<JamsMissiles> tp)
if ((tp.Actor.CenterPosition - pos).HorizontalLengthSquared > tp.Trait.Range.LengthSquared)
return false;

if (!tp.Trait.DeflectionStances.HasStance(tp.Actor.Owner.RelationshipWith(args.SourceActor.Owner)))
if (!tp.Trait.DeflectionStances.HasRelationship(tp.Actor.Owner.RelationshipWith(args.SourceActor.Owner)))
return false;

return tp.Actor.World.SharedRandom.Next(100) < tp.Trait.Chance;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackBase.cs
Expand Up @@ -377,7 +377,7 @@ public IEnumerable<Armament> ChooseArmamentsForTarget(Target t, bool forceAttack

return Armaments.Where(a =>
!a.IsTraitDisabled
&& (owner == null || (forceAttack ? a.Info.ForceTargetRelationships : a.Info.TargetRelationships).HasStance(self.Owner.RelationshipWith(owner)))
&& (owner == null || (forceAttack ? a.Info.ForceTargetRelationships : a.Info.TargetRelationships).HasRelationship(self.Owner.RelationshipWith(owner)))
&& a.Weapon.IsValidAgainst(t, self.World, self));
}

Expand Down
8 changes: 4 additions & 4 deletions OpenRA.Mods.Common/Traits/AutoTarget.cs
Expand Up @@ -325,8 +325,8 @@ public bool HasValidTargetPriority(Actor self, Player owner, BitSet<TargetableTy

return activeTargetPriorities.Any(ati =>
{
// Incompatible stances
if (!ati.ValidRelationships.HasStance(self.Owner.RelationshipWith(owner)))
// Incompatible relationship
if (!ati.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(owner)))
return false;

// Incompatible target types
Expand Down Expand Up @@ -393,8 +393,8 @@ Target ChooseTarget(Actor self, AttackBase ab, PlayerRelationship attackStances,
if (ati.Priority < chosenTargetPriority)
return false;

// Incompatible stances
if (!ati.ValidRelationships.HasStance(self.Owner.RelationshipWith(owner)))
// Incompatible relationship
if (!ati.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(owner)))
return false;

// Incompatible target types
Expand Down
Expand Up @@ -133,7 +133,7 @@ void QueueCaptureOrders(IBot bot)
return;

var randPlayer = world.Players.Where(p => !p.Spectating
&& Info.CapturableRelationships.HasStance(player.RelationshipWith(p))).Random(world.LocalRandom);
&& Info.CapturableRelationships.HasRelationship(player.RelationshipWith(p))).Random(world.LocalRandom);

var targetOptions = Info.CheckCaptureTargetsForVisibility
? GetVisibleActorsBelongingToPlayer(randPlayer)
Expand Down
24 changes: 12 additions & 12 deletions OpenRA.Mods.Common/Traits/CaptureManager.cs
Expand Up @@ -50,7 +50,7 @@ public bool CanBeTargetedBy(FrozenActor frozenActor, Actor captor, Captures capt
// Actors with FrozenUnderFog should therefore not disable the Capturable trait.
var stance = captor.Owner.RelationshipWith(frozenActor.Owner);
return frozenActor.Info.TraitInfos<CapturableInfo>()
.Any(c => c.ValidRelationships.HasStance(stance) && captures.Info.CaptureTypes.Overlaps(c.Types));
.Any(c => c.ValidRelationships.HasRelationship(stance) && captures.Info.CaptureTypes.Overlaps(c.Types));
}
}

Expand Down Expand Up @@ -108,13 +108,13 @@ public void RefreshCapturable(Actor self)
allyCapturableTypes = neutralCapturableTypes = enemyCapturableTypes = default(BitSet<CaptureType>);
foreach (var c in enabledCapturable)
{
if (c.Info.ValidRelationships.HasStance(PlayerRelationship.Ally))
if (c.Info.ValidRelationships.HasRelationship(PlayerRelationship.Ally))
allyCapturableTypes = allyCapturableTypes.Union(c.Info.Types);

if (c.Info.ValidRelationships.HasStance(PlayerRelationship.Neutral))
if (c.Info.ValidRelationships.HasRelationship(PlayerRelationship.Neutral))
neutralCapturableTypes = neutralCapturableTypes.Union(c.Info.Types);

if (c.Info.ValidRelationships.HasStance(PlayerRelationship.Enemy))
if (c.Info.ValidRelationships.HasRelationship(PlayerRelationship.Enemy))
enemyCapturableTypes = enemyCapturableTypes.Union(c.Info.Types);
}
}
Expand All @@ -128,14 +128,14 @@ public void RefreshCaptures(Actor self)

public bool CanBeTargetedBy(Actor self, Actor captor, CaptureManager captorManager)
{
var stance = captor.Owner.RelationshipWith(self.Owner);
if (stance.HasStance(PlayerRelationship.Enemy))
var relationship = captor.Owner.RelationshipWith(self.Owner);
if (relationship.HasRelationship(PlayerRelationship.Enemy))
return captorManager.capturesTypes.Overlaps(enemyCapturableTypes);

if (stance.HasStance(PlayerRelationship.Neutral))
if (relationship.HasRelationship(PlayerRelationship.Neutral))
return captorManager.capturesTypes.Overlaps(neutralCapturableTypes);

if (stance.HasStance(PlayerRelationship.Ally))
if (relationship.HasRelationship(PlayerRelationship.Ally))
return captorManager.capturesTypes.Overlaps(allyCapturableTypes);

return false;
Expand All @@ -146,14 +146,14 @@ public bool CanBeTargetedBy(Actor self, Actor captor, Captures captures)
if (captures.IsTraitDisabled)
return false;

var stance = captor.Owner.RelationshipWith(self.Owner);
if (stance.HasStance(PlayerRelationship.Enemy))
var relationship = captor.Owner.RelationshipWith(self.Owner);
if (relationship.HasRelationship(PlayerRelationship.Enemy))
return captures.Info.CaptureTypes.Overlaps(enemyCapturableTypes);

if (stance.HasStance(PlayerRelationship.Neutral))
if (relationship.HasRelationship(PlayerRelationship.Neutral))
return captures.Info.CaptureTypes.Overlaps(neutralCapturableTypes);

if (stance.HasStance(PlayerRelationship.Ally))
if (relationship.HasRelationship(PlayerRelationship.Ally))
return captures.Info.CaptureTypes.Overlaps(allyCapturableTypes);

return false;
Expand Down
Expand Up @@ -110,8 +110,8 @@ void ActorEntered(Actor a)
if (tokens.ContainsKey(a))
return;

var stance = self.Owner.RelationshipWith(a.Owner);
if (!Info.ValidRelationships.HasStance(stance))
var relationship = self.Owner.RelationshipWith(a.Owner);
if (!Info.ValidRelationships.HasRelationship(relationship))
return;

var external = a.TraitsImplementing<ExternalCondition>()
Expand All @@ -135,7 +135,7 @@ public void UnitProducedByOther(Actor self, Actor producer, Actor produced, stri
if ((produced.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= Info.Range.LengthSquared)
{
var stance = self.Owner.RelationshipWith(produced.Owner);
if (!Info.ValidRelationships.HasStance(stance))
if (!Info.ValidRelationships.HasRelationship(stance))
return;

var external = produced.TraitsImplementing<ExternalCondition>()
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/CreatesShroud.cs
Expand Up @@ -43,7 +43,7 @@ protected override void Created(Actor self)

protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv)
{
if (!info.ValidRelationships.HasStance(self.Owner.RelationshipWith(p)))
if (!info.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(p)))
return;

p.Shroud.AddSource(this, Shroud.SourceType.Shroud, uv);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/DeliversCash.cs
Expand Up @@ -99,7 +99,7 @@ public DeliversCashOrderTargeter(DeliversCashInfo info)
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
if (targetInfo == null || !targetInfo.ValidRelationships.HasStance(target.Owner.RelationshipWith(self.Owner)))
if (targetInfo == null || !targetInfo.ValidRelationships.HasRelationship(target.Owner.RelationshipWith(self.Owner)))
return false;

if (targetInfo.ValidTypes.Count == 0)
Expand All @@ -112,7 +112,7 @@ public override bool CanTargetActor(Actor self, Actor target, TargetModifiers mo
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
if (targetInfo == null || !targetInfo.ValidRelationships.HasStance(target.Owner.RelationshipWith(self.Owner)))
if (targetInfo == null || !targetInfo.ValidRelationships.HasRelationship(target.Owner.RelationshipWith(self.Owner)))
return false;

if (targetInfo.ValidTypes.Count == 0)
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/DeliversExperience.cs
Expand Up @@ -109,7 +109,7 @@ public override bool CanTargetActor(Actor self, Actor target, TargetModifiers mo
return false;

var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
if (targetInfo == null || !targetInfo.ValidRelationships.HasStance(target.Owner.RelationshipWith(self.Owner)))
if (targetInfo == null || !targetInfo.ValidRelationships.HasRelationship(target.Owner.RelationshipWith(self.Owner)))
return false;

if (targetInfo.ValidTypes.Count == 0)
Expand All @@ -129,7 +129,7 @@ public override bool CanTargetFrozenActor(Actor self, FrozenActor target, Target
return false;

var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
if (targetInfo == null || !targetInfo.ValidRelationships.HasStance(target.Owner.RelationshipWith(self.Owner)))
if (targetInfo == null || !targetInfo.ValidRelationships.HasRelationship(target.Owner.RelationshipWith(self.Owner)))
return false;

if (targetInfo.ValidTypes.Count == 0)
Expand Down
12 changes: 6 additions & 6 deletions OpenRA.Mods.Common/Traits/Demolition.cs
Expand Up @@ -117,23 +117,23 @@ public override bool CanTargetActor(Actor self, Actor target, TargetModifiers mo
if (modifiers.HasModifier(TargetModifiers.ForceMove))
return false;

var stance = target.Owner.RelationshipWith(self.Owner);
if (!info.TargetRelationships.HasStance(stance) && !modifiers.HasModifier(TargetModifiers.ForceAttack))
var relationship = target.Owner.RelationshipWith(self.Owner);
if (!info.TargetRelationships.HasRelationship(relationship) && !modifiers.HasModifier(TargetModifiers.ForceAttack))
return false;

if (!info.ForceTargetRelationships.HasStance(stance) && modifiers.HasModifier(TargetModifiers.ForceAttack))
if (!info.ForceTargetRelationships.HasRelationship(relationship) && modifiers.HasModifier(TargetModifiers.ForceAttack))
return false;

return target.TraitsImplementing<IDemolishable>().Any(i => i.IsValidTarget(target, self));
}

public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
var stance = target.Owner.RelationshipWith(self.Owner);
if (!info.TargetRelationships.HasStance(stance) && !modifiers.HasModifier(TargetModifiers.ForceAttack))
var relationship = target.Owner.RelationshipWith(self.Owner);
if (!info.TargetRelationships.HasRelationship(relationship) && !modifiers.HasModifier(TargetModifiers.ForceAttack))
return false;

if (!info.ForceTargetRelationships.HasStance(stance) && modifiers.HasModifier(TargetModifiers.ForceAttack))
if (!info.ForceTargetRelationships.HasRelationship(relationship) && modifiers.HasModifier(TargetModifiers.ForceAttack))
return false;

return target.Info.TraitInfos<IDemolishableInfo>().Any(i => i.IsValidTarget(target.Info, self));
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/EngineerRepair.cs
Expand Up @@ -117,7 +117,7 @@ public override bool CanTargetActor(Actor self, Actor target, TargetModifiers mo
if (!engineerRepairable.Info.Types.IsEmpty && !engineerRepairable.Info.Types.Overlaps(info.Types))
return false;

if (!info.ValidRelationships.HasStance(target.Owner.RelationshipWith(self.Owner)))
if (!info.ValidRelationships.HasRelationship(target.Owner.RelationshipWith(self.Owner)))
return false;

if (target.GetDamageState() == DamageState.Undamaged)
Expand All @@ -139,7 +139,7 @@ public override bool CanTargetFrozenActor(Actor self, FrozenActor target, Target
if (!engineerRepairable.Types.IsEmpty && !engineerRepairable.Types.Overlaps(info.Types))
return false;

if (!info.ValidRelationships.HasStance(target.Owner.RelationshipWith(self.Owner)))
if (!info.ValidRelationships.HasRelationship(target.Owner.RelationshipWith(self.Owner)))
return false;

if (target.DamageState == DamageState.Undamaged)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/GivesBounty.cs
Expand Up @@ -64,7 +64,7 @@ void INotifyKilled.Killed(Actor self, AttackInfo e)
if (e.Attacker == null || e.Attacker.Disposed || IsTraitDisabled)
return;

if (!Info.ValidRelationships.HasStance(e.Attacker.Owner.RelationshipWith(self.Owner)))
if (!Info.ValidRelationships.HasRelationship(e.Attacker.Owner.RelationshipWith(self.Owner)))
return;

if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes))
Expand Down