Replace usage of the Stances dict by a method call

This commit is contained in:
abcdefg30
2020-09-25 17:02:25 +02:00
committed by Paul Chote
parent eda9966d27
commit 10f645bf77
55 changed files with 104 additions and 107 deletions

View File

@@ -230,10 +230,22 @@ namespace OpenRA
} }
public Dictionary<Player, PlayerRelationship> Stances = new Dictionary<Player, PlayerRelationship>(); public Dictionary<Player, PlayerRelationship> Stances = new Dictionary<Player, PlayerRelationship>();
public PlayerRelationship RelationshipWith(Player other)
{
if (this == other)
return PlayerRelationship.Ally;
// Observers are considered allies to active combatants
if (other == null || other.Spectating)
return NonCombatant ? PlayerRelationship.Neutral : PlayerRelationship.Ally;
return Stances[other];
}
public bool IsAlliedWith(Player p) public bool IsAlliedWith(Player p)
{ {
// Observers are considered allies to active combatants return RelationshipWith(p) == PlayerRelationship.Ally;
return p == null || Stances[p] == PlayerRelationship.Ally || (p.Spectating && !NonCombatant);
} }
public Color PlayerStanceColor(Actor a) public Color PlayerStanceColor(Actor a)

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Traits
if (a.Owner == viewer || viewer == null) if (a.Owner == viewer || viewer == null)
return basePriority; return basePriority;
switch (viewer.Stances[a.Owner]) switch (viewer.RelationshipWith(a.Owner))
{ {
case PlayerRelationship.Ally: return basePriority - PriorityRange; case PlayerRelationship.Ally: return basePriority - PriorityRange;
case PlayerRelationship.Neutral: return basePriority - 2 * PriorityRange; case PlayerRelationship.Neutral: return basePriority - 2 * PriorityRange;

View File

@@ -90,8 +90,7 @@ namespace OpenRA
public static bool AreMutualAllies(Player a, Player b) public static bool AreMutualAllies(Player a, Player b)
{ {
return a.Stances[b] == PlayerRelationship.Ally && return a.RelationshipWith(b) == PlayerRelationship.Ally && b.RelationshipWith(a) == PlayerRelationship.Ally;
b.Stances[a] == PlayerRelationship.Ally;
} }
} }
} }

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Cnc.Activities
if (rearmableInfo != null && ammoPools.Any(p => p.Info.Name == minelayer.Info.AmmoPoolName && !p.HasAmmo)) if (rearmableInfo != null && ammoPools.Any(p => p.Info.Name == minelayer.Info.AmmoPoolName && !p.HasAmmo))
{ {
// Rearm (and possibly repair) at rearm building, then back out here to refill the minefield some more // Rearm (and possibly repair) at rearm building, then back out here to refill the minefield some more
rearmTarget = self.World.Actors.Where(a => self.Owner.Stances[a.Owner] == PlayerRelationship.Ally && rearmableInfo.RearmActors.Contains(a.Info.Name)) rearmTarget = self.World.Actors.Where(a => self.Owner.RelationshipWith(a.Owner) == PlayerRelationship.Ally && rearmableInfo.RearmActors.Contains(a.Info.Name))
.ClosestTo(self); .ClosestTo(self);
if (rearmTarget == null) if (rearmTarget == null)

View File

@@ -298,8 +298,7 @@ namespace OpenRA.Mods.Cnc.Traits
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor) public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{ {
var stance = self.Owner.Stances[target.Owner]; var stance = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidStances.HasStance(stance)) if (!info.ValidStances.HasStance(stance))
return false; return false;
@@ -308,8 +307,7 @@ namespace OpenRA.Mods.Cnc.Traits
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor) public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{ {
var stance = self.Owner.Stances[target.Owner]; var stance = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidStances.HasStance(stance)) if (!info.ValidStances.HasStance(stance))
return false; return false;

View File

@@ -48,8 +48,7 @@ namespace OpenRA.Mods.Cnc.Traits
protected override bool ShouldRender(Actor self) protected override bool ShouldRender(Actor self)
{ {
return self.World.RenderPlayer == null || infiltrators.Any(i => return infiltrators.Any(i => Info.ValidStances.HasStance(i.RelationshipWith(self.World.RenderPlayer)));
Info.ValidStances.HasStance(i.Stances[self.World.RenderPlayer]));
} }
} }
} }

View File

@@ -98,10 +98,10 @@ namespace OpenRA.Mods.Cnc.Traits
{ {
case TargetType.Actor: case TargetType.Actor:
return Info.Types.Overlaps(target.Actor.GetEnabledTargetTypes()) && return Info.Types.Overlaps(target.Actor.GetEnabledTargetTypes()) &&
Info.ValidStances.HasStance(self.Owner.Stances[target.Actor.Owner]); Info.ValidStances.HasStance(self.Owner.RelationshipWith(target.Actor.Owner));
case TargetType.FrozenActor: case TargetType.FrozenActor:
return target.FrozenActor.IsValid && Info.Types.Overlaps(target.FrozenActor.TargetTypes) && return target.FrozenActor.IsValid && Info.Types.Overlaps(target.FrozenActor.TargetTypes) &&
Info.ValidStances.HasStance(self.Owner.Stances[target.FrozenActor.Owner]); Info.ValidStances.HasStance(self.Owner.RelationshipWith(target.FrozenActor.Owner));
default: default:
return false; return false;
} }
@@ -132,8 +132,7 @@ namespace OpenRA.Mods.Cnc.Traits
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor) public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{ {
var stance = self.Owner.Stances[target.Owner]; var stance = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidStances.HasStance(stance)) if (!info.ValidStances.HasStance(stance))
return false; return false;
@@ -142,8 +141,7 @@ namespace OpenRA.Mods.Cnc.Traits
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor) public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{ {
var stance = self.Owner.Stances[target.Owner]; var stance = self.Owner.RelationshipWith(target.Owner);
if (!info.ValidStances.HasStance(stance)) if (!info.ValidStances.HasStance(stance))
return false; return false;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Traits
if (!info.CrushClasses.Overlaps(crushClasses)) if (!info.CrushClasses.Overlaps(crushClasses))
return; return;
if (crusher.Info.HasTraitInfo<MineImmuneInfo>() || (self.Owner.Stances[crusher.Owner] == PlayerRelationship.Ally && info.AvoidFriendly)) if (crusher.Info.HasTraitInfo<MineImmuneInfo>() || (self.Owner.RelationshipWith(crusher.Owner) == PlayerRelationship.Ally && info.AvoidFriendly))
return; return;
var mobile = crusher.TraitOrDefault<Mobile>(); var mobile = crusher.TraitOrDefault<Mobile>();
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Cnc.Traits
bool ICrushable.CrushableBy(Actor self, Actor crusher, BitSet<CrushClass> crushClasses) bool ICrushable.CrushableBy(Actor self, Actor crusher, BitSet<CrushClass> crushClasses)
{ {
if (info.BlockFriendly && !crusher.Info.HasTraitInfo<MineImmuneInfo>() && self.Owner.Stances[crusher.Owner] == PlayerRelationship.Ally) if (info.BlockFriendly && !crusher.Info.HasTraitInfo<MineImmuneInfo>() && self.Owner.RelationshipWith(crusher.Owner) == PlayerRelationship.Ally)
return false; return false;
return info.CrushClasses.Overlaps(crushClasses); return info.CrushClasses.Overlaps(crushClasses);

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common
public static List<Actor> FindEnemiesByCommonName(HashSet<string> commonNames, Player player) public static List<Actor> FindEnemiesByCommonName(HashSet<string> commonNames, Player player)
{ {
return player.World.Actors.Where(a => !a.IsDead && player.Stances[a.Owner] == PlayerRelationship.Enemy && return player.World.Actors.Where(a => !a.IsDead && player.RelationshipWith(a.Owner) == PlayerRelationship.Enemy &&
commonNames.Contains(a.Info.Name)).ToList(); commonNames.Contains(a.Info.Name)).ToList();
} }

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var t in enterActor.TraitsImplementing<INotifyCapture>()) foreach (var t in enterActor.TraitsImplementing<INotifyCapture>())
t.OnCapture(enterActor, self, oldOwner, self.Owner, captures.Info.CaptureTypes); t.OnCapture(enterActor, self, oldOwner, self.Owner, captures.Info.CaptureTypes);
if (self.Owner.Stances[oldOwner].HasStance(captures.Info.PlayerExperienceStances)) if (self.Owner.RelationshipWith(oldOwner).HasStance(captures.Info.PlayerExperienceStances))
self.Owner.PlayerActor.TraitOrDefault<PlayerExperience>()?.GiveExperience(captures.Info.PlayerExperience); self.Owner.PlayerActor.TraitOrDefault<PlayerExperience>()?.GiveExperience(captures.Info.PlayerExperience);
if (captures.Info.ConsumedByCapture) if (captures.Info.ConsumedByCapture)

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities
// Make sure we can still repair the target before entering // Make sure we can still repair the target before entering
// (but not before, because this may stop the actor in the middle of nowhere) // (but not before, because this may stop the actor in the middle of nowhere)
var stance = self.Owner.Stances[enterActor.Owner]; var stance = self.Owner.RelationshipWith(enterActor.Owner);
if (enterHealth == null || enterHealth.DamageState == DamageState.Undamaged || enterEngineerRepariable == null || enterEngineerRepariable.IsTraitDisabled || !info.ValidStances.HasStance(stance)) if (enterHealth == null || enterHealth.DamageState == DamageState.Undamaged || enterEngineerRepariable == null || enterEngineerRepariable.IsTraitDisabled || !info.ValidStances.HasStance(stance))
{ {
Cancel(self, true); Cancel(self, true);
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Activities
if (enterHealth.DamageState == DamageState.Undamaged) if (enterHealth.DamageState == DamageState.Undamaged)
return; return;
var stance = self.Owner.Stances[enterActor.Owner]; var stance = self.Owner.RelationshipWith(enterActor.Owner);
if (!info.ValidStances.HasStance(stance)) if (!info.ValidStances.HasStance(stance))
return; return;

View File

@@ -36,24 +36,24 @@ namespace OpenRA.Mods.Common
public static bool AppearsFriendlyTo(this Actor self, Actor toActor) public static bool AppearsFriendlyTo(this Actor self, Actor toActor)
{ {
var stance = toActor.Owner.Stances[self.Owner]; var stance = toActor.Owner.RelationshipWith(self.Owner);
if (stance == PlayerRelationship.Ally) if (stance == PlayerRelationship.Ally)
return true; return true;
if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.Info.HasTraitInfo<IgnoresDisguiseInfo>()) if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.Info.HasTraitInfo<IgnoresDisguiseInfo>())
return toActor.Owner.Stances[self.EffectiveOwner.Owner] == PlayerRelationship.Ally; return toActor.Owner.RelationshipWith(self.EffectiveOwner.Owner) == PlayerRelationship.Ally;
return false; return false;
} }
public static bool AppearsHostileTo(this Actor self, Actor toActor) public static bool AppearsHostileTo(this Actor self, Actor toActor)
{ {
var stance = toActor.Owner.Stances[self.Owner]; var stance = toActor.Owner.RelationshipWith(self.Owner);
if (stance == PlayerRelationship.Ally) if (stance == PlayerRelationship.Ally)
return false; /* otherwise, we'll hate friendly disguised spies */ return false;
if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.Info.HasTraitInfo<IgnoresDisguiseInfo>()) if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.Info.HasTraitInfo<IgnoresDisguiseInfo>())
return toActor.Owner.Stances[self.EffectiveOwner.Owner] == PlayerRelationship.Enemy; return toActor.Owner.RelationshipWith(self.EffectiveOwner.Owner) == PlayerRelationship.Enemy;
return stance == PlayerRelationship.Enemy; return stance == PlayerRelationship.Enemy;
} }
@@ -61,10 +61,8 @@ namespace OpenRA.Mods.Common
public static void NotifyBlocker(this Actor self, IEnumerable<Actor> blockers) public static void NotifyBlocker(this Actor self, IEnumerable<Actor> blockers)
{ {
foreach (var blocker in blockers) foreach (var blocker in blockers)
{
foreach (var moveBlocked in blocker.TraitsImplementing<INotifyBlockingMove>()) foreach (var moveBlocked in blocker.TraitsImplementing<INotifyBlockingMove>())
moveBlocked.OnNotifyBlockingMove(blocker, self); moveBlocked.OnNotifyBlockingMove(blocker, self);
}
} }
public static void NotifyBlocker(this Actor self, CPos position) public static void NotifyBlocker(this Actor self, CPos position)

View File

@@ -41,7 +41,11 @@ namespace OpenRA.Mods.Common.Effects
ticks = -delay; ticks = -delay;
} }
void AddCellsToPlayerShroud(Player p, PPos[] uv) { if (!validStances.HasStance(p.Stances[player])) return; p.Shroud.AddSource(this, sourceType, uv); } void AddCellsToPlayerShroud(Player p, PPos[] uv)
{
if (validStances.HasStance(player.RelationshipWith(p)))
p.Shroud.AddSource(this, sourceType, uv);
}
void RemoveCellsFromPlayerShroud(Player p) { p.Shroud.RemoveSource(this); } void RemoveCellsFromPlayerShroud(Player p) { p.Shroud.RemoveSource(this); }
@@ -52,8 +56,7 @@ namespace OpenRA.Mods.Common.Effects
if (range == WDist.Zero) if (range == WDist.Zero)
return NoCells; return NoCells;
return Shroud.ProjectedCellsInRange(map, pos, WDist.Zero, range) return Shroud.ProjectedCellsInRange(map, pos, WDist.Zero, range).ToArray();
.ToArray();
} }
public void Tick(World world) public void Tick(World world)

View File

@@ -50,8 +50,7 @@ namespace OpenRA.Mods.Common.Orders
return false; return false;
var owner = type == TargetType.FrozenActor ? target.FrozenActor.Owner : target.Actor.Owner; var owner = type == TargetType.FrozenActor ? target.FrozenActor.Owner : target.Actor.Owner;
var playerRelationship = self.Owner.Stances[owner]; var playerRelationship = self.Owner.RelationshipWith(owner);
if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == PlayerRelationship.Ally && !targetAllyUnits) if (!modifiers.HasModifier(TargetModifiers.ForceAttack) && playerRelationship == PlayerRelationship.Ally && !targetAllyUnits)
return false; return false;

View File

@@ -319,7 +319,7 @@ namespace OpenRA.Mods.Common.Projectiles
if (checkTargetType && !Target.FromActor(victim).IsValidFor(firedBy)) if (checkTargetType && !Target.FromActor(victim).IsValidFor(firedBy))
continue; continue;
if (!info.ValidBounceBlockerStances.HasStance(victim.Owner.Stances[firedBy.Owner])) if (!info.ValidBounceBlockerStances.HasStance(firedBy.Owner.RelationshipWith(victim.Owner)))
continue; continue;
// If the impact position is within any actor's HitShape, we have a direct hit // If the impact position is within any actor's HitShape, we have a direct hit

View File

@@ -429,7 +429,7 @@ namespace OpenRA.Mods.Common.Projectiles
if ((tp.Actor.CenterPosition - pos).HorizontalLengthSquared > tp.Trait.Range.LengthSquared) if ((tp.Actor.CenterPosition - pos).HorizontalLengthSquared > tp.Trait.Range.LengthSquared)
return false; return false;
if (!tp.Trait.DeflectionStances.HasStance(tp.Actor.Owner.Stances[args.SourceActor.Owner])) if (!tp.Trait.DeflectionStances.HasStance(tp.Actor.Owner.RelationshipWith(args.SourceActor.Owner)))
return false; return false;
return tp.Actor.World.SharedRandom.Next(100) < tp.Trait.Chance; return tp.Actor.World.SharedRandom.Next(100) < tp.Trait.Chance;

View File

@@ -670,7 +670,7 @@ namespace OpenRA.Mods.Common.Traits
// We are not blocked by actors we can nudge out of the way // We are not blocked by actors we can nudge out of the way
// TODO: Generalize blocker checks and handling here and in Locomotor // TODO: Generalize blocker checks and handling here and in Locomotor
if (!blockedByMobile && self.Owner.Stances[otherActor.Owner] == PlayerRelationship.Ally && if (!blockedByMobile && self.Owner.RelationshipWith(otherActor.Owner) == PlayerRelationship.Ally &&
otherActor.TraitOrDefault<Mobile>() != null && otherActor.CurrentActivity == null) otherActor.TraitOrDefault<Mobile>() != null && otherActor.CurrentActivity == null)
return false; return false;

View File

@@ -377,8 +377,7 @@ namespace OpenRA.Mods.Common.Traits
return Armaments.Where(a => return Armaments.Where(a =>
!a.IsTraitDisabled !a.IsTraitDisabled
&& (owner == null || (forceAttack ? a.Info.ForceTargetStances : a.Info.TargetStances) && (owner == null || (forceAttack ? a.Info.ForceTargetStances : a.Info.TargetStances).HasStance(self.Owner.RelationshipWith(owner)))
.HasStance(self.Owner.Stances[owner]))
&& a.Weapon.IsValidAgainst(t, self.World, self)); && a.Weapon.IsValidAgainst(t, self.World, self));
} }
@@ -444,7 +443,7 @@ namespace OpenRA.Mods.Common.Traits
// targeting and attacking logic (which should be logically separate) // targeting and attacking logic (which should be logically separate)
// to use the same code // to use the same code
if (target.Type == TargetType.Actor && target.Actor.EffectiveOwner != null && if (target.Type == TargetType.Actor && target.Actor.EffectiveOwner != null &&
target.Actor.EffectiveOwner.Disguised && self.Owner.Stances[target.Actor.Owner] == PlayerRelationship.Enemy) target.Actor.EffectiveOwner.Disguised && self.Owner.RelationshipWith(target.Actor.Owner) == PlayerRelationship.Enemy)
modifiers |= TargetModifiers.ForceAttack; modifiers |= TargetModifiers.ForceAttack;
var forceAttack = modifiers.HasModifier(TargetModifiers.ForceAttack); var forceAttack = modifiers.HasModifier(TargetModifiers.ForceAttack);

View File

@@ -326,7 +326,7 @@ namespace OpenRA.Mods.Common.Traits
return activeTargetPriorities.Any(ati => return activeTargetPriorities.Any(ati =>
{ {
// Incompatible stances // Incompatible stances
if (!ati.ValidStances.HasStance(self.Owner.Stances[owner])) if (!ati.ValidStances.HasStance(self.Owner.RelationshipWith(owner)))
return false; return false;
// Incompatible target types // Incompatible target types
@@ -362,7 +362,7 @@ namespace OpenRA.Mods.Common.Traits
// can bail early and avoid the more expensive targeting checks and armament selection. For groups of // can bail early and avoid the more expensive targeting checks and armament selection. For groups of
// allied units, this helps significantly reduce the cost of auto target scans. This is important as // allied units, this helps significantly reduce the cost of auto target scans. This is important as
// these groups will continuously rescan their allies until an enemy finally comes into range. // these groups will continuously rescan their allies until an enemy finally comes into range.
if (attackStances == OpenRA.Traits.PlayerRelationship.Enemy && !target.Actor.AppearsHostileTo(self)) if (attackStances == PlayerRelationship.Enemy && !target.Actor.AppearsHostileTo(self))
continue; continue;
// Check whether we can auto-target this actor // Check whether we can auto-target this actor
@@ -375,7 +375,7 @@ namespace OpenRA.Mods.Common.Traits
} }
else if (target.Type == TargetType.FrozenActor) else if (target.Type == TargetType.FrozenActor)
{ {
if (attackStances == OpenRA.Traits.PlayerRelationship.Enemy && self.Owner.Stances[target.FrozenActor.Owner] == OpenRA.Traits.PlayerRelationship.Ally) if (attackStances == PlayerRelationship.Enemy && self.Owner.RelationshipWith(target.FrozenActor.Owner) == PlayerRelationship.Ally)
continue; continue;
targetTypes = target.FrozenActor.TargetTypes; targetTypes = target.FrozenActor.TargetTypes;
@@ -391,7 +391,7 @@ namespace OpenRA.Mods.Common.Traits
return false; return false;
// Incompatible stances // Incompatible stances
if (!ati.ValidStances.HasStance(self.Owner.Stances[owner])) if (!ati.ValidStances.HasStance(self.Owner.RelationshipWith(owner)))
return false; return false;
// Incompatible target types // Incompatible target types

View File

@@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Traits
if (e.Attacker == null || e.Attacker.Disposed) if (e.Attacker == null || e.Attacker.Disposed)
return; return;
if (e.Attacker.Owner.Stances[self.Owner] != PlayerRelationship.Enemy) if (e.Attacker.Owner.RelationshipWith(self.Owner) != PlayerRelationship.Enemy)
return; return;
if (!e.Attacker.Info.HasTraitInfo<ITargetableInfo>()) if (!e.Attacker.Info.HasTraitInfo<ITargetableInfo>())

View File

@@ -409,7 +409,7 @@ namespace OpenRA.Mods.Common.Traits
case BuildingType.Defense: case BuildingType.Defense:
// Build near the closest enemy structure // Build near the closest enemy structure
var closestEnemy = world.ActorsHavingTrait<Building>().Where(a => !a.Disposed && player.Stances[a.Owner] == PlayerRelationship.Enemy) var closestEnemy = world.ActorsHavingTrait<Building>().Where(a => !a.Disposed && player.RelationshipWith(a.Owner) == PlayerRelationship.Enemy)
.ClosestTo(world.Map.CenterOfCell(baseBuilder.DefenseCenter)); .ClosestTo(world.Map.CenterOfCell(baseBuilder.DefenseCenter));
var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter; var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter;

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
var checkActors = world.FindActorsInCircle(pos, radiusToUse); var checkActors = world.FindActorsInCircle(pos, radiusToUse);
foreach (var scrutinized in checkActors) foreach (var scrutinized in checkActors)
answer += consideration.GetAttractiveness(scrutinized, firedBy.Stances[scrutinized.Owner], firedBy); answer += consideration.GetAttractiveness(scrutinized, firedBy.RelationshipWith(scrutinized.Owner), firedBy);
var delta = new WVec(radiusToUse, radiusToUse, WDist.Zero); var delta = new WVec(radiusToUse, radiusToUse, WDist.Zero);
var tl = world.Map.CellContaining(pos - delta); var tl = world.Map.CellContaining(pos - delta);
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
// IsValid check filters out Frozen Actors that have not initizialized their Owner // IsValid check filters out Frozen Actors that have not initizialized their Owner
foreach (var scrutinized in checkFrozen) foreach (var scrutinized in checkFrozen)
answer += consideration.GetAttractiveness(scrutinized, firedBy.Stances[scrutinized.Owner], firedBy); answer += consideration.GetAttractiveness(scrutinized, firedBy.RelationshipWith(scrutinized.Owner), firedBy);
} }
return answer; return answer;
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var consideration in Considerations) foreach (var consideration in Considerations)
foreach (var scrutinized in actors) foreach (var scrutinized in actors)
answer += consideration.GetAttractiveness(scrutinized, firedBy.Stances[scrutinized.Owner], firedBy); answer += consideration.GetAttractiveness(scrutinized, firedBy.RelationshipWith(scrutinized.Owner), firedBy);
return answer; return answer;
} }
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var consideration in Considerations) foreach (var consideration in Considerations)
foreach (var scrutinized in frozenActors) foreach (var scrutinized in frozenActors)
if (scrutinized.IsValid && scrutinized.Visible) if (scrutinized.IsValid && scrutinized.Visible)
answer += consideration.GetAttractiveness(scrutinized, firedBy.Stances[scrutinized.Owner], firedBy); answer += consideration.GetAttractiveness(scrutinized, firedBy.RelationshipWith(scrutinized.Owner), firedBy);
return answer; return answer;
} }

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
// HACK: We don't want D2k bots to repair all their buildings on placement // HACK: We don't want D2k bots to repair all their buildings on placement
// where half their HP is removed via neutral terrain damage. // where half their HP is removed via neutral terrain damage.
// TODO: Implement concrete placement for D2k bots and remove this hack. // TODO: Implement concrete placement for D2k bots and remove this hack.
if (e.Attacker.Owner.Stances[self.Owner] == PlayerRelationship.Neutral) if (self.Owner.RelationshipWith(e.Attacker.Owner) == PlayerRelationship.Neutral)
return; return;
var rb = self.TraitOrDefault<RepairableBuilding>(); var rb = self.TraitOrDefault<RepairableBuilding>();

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
isEnemyUnit = unit => isEnemyUnit = unit =>
player.Stances[unit.Owner] == PlayerRelationship.Enemy player.RelationshipWith(unit.Owner) == PlayerRelationship.Enemy
&& !unit.Info.HasTraitInfo<HuskInfo>() && !unit.Info.HasTraitInfo<HuskInfo>()
&& unit.Info.HasTraitInfo<ITargetableInfo>(); && unit.Info.HasTraitInfo<ITargetableInfo>();
@@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
var randPlayer = world.Players.Where(p => !p.Spectating var randPlayer = world.Players.Where(p => !p.Spectating
&& Info.CapturableStances.HasStance(player.Stances[p])).Random(world.LocalRandom); && Info.CapturableStances.HasStance(player.RelationshipWith(p))).Random(world.LocalRandom);
var targetOptions = Info.CheckCaptureTargetsForVisibility var targetOptions = Info.CheckCaptureTargetsForVisibility
? GetVisibleActorsBelongingToPlayer(randPlayer) ? GetVisibleActorsBelongingToPlayer(randPlayer)

View File

@@ -152,7 +152,7 @@ namespace OpenRA.Mods.Common.Traits
var path = pathfinder.FindPath( var path = pathfinder.FindPath(
PathSearch.Search(world, harv.Locomotor, actor, BlockedByActor.Stationary, isValidResource) PathSearch.Search(world, harv.Locomotor, actor, BlockedByActor.Stationary, isValidResource)
.WithCustomCost(loc => world.FindActorsInCircle(world.Map.CenterOfCell(loc), Info.HarvesterEnemyAvoidanceRadius) .WithCustomCost(loc => world.FindActorsInCircle(world.Map.CenterOfCell(loc), Info.HarvesterEnemyAvoidanceRadius)
.Where(u => !u.IsDead && actor.Owner.Stances[u.Owner] == PlayerRelationship.Enemy) .Where(u => !u.IsDead && actor.Owner.RelationshipWith(u.Owner) == PlayerRelationship.Enemy)
.Sum(u => Math.Max(WDist.Zero.Length, Info.HarvesterEnemyAvoidanceRadius.Length - (world.Map.CenterOfCell(loc) - u.CenterPosition).Length))) .Sum(u => Math.Max(WDist.Zero.Length, Info.HarvesterEnemyAvoidanceRadius.Length - (world.Map.CenterOfCell(loc) - u.CenterPosition).Length)))
.FromPoint(actor.Location)); .FromPoint(actor.Location));

View File

@@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
// Use for proactive targeting. // Use for proactive targeting.
public bool IsPreferredEnemyUnit(Actor a) public bool IsPreferredEnemyUnit(Actor a)
{ {
if (a == null || a.IsDead || Player.Stances[a.Owner] != PlayerRelationship.Enemy || a.Info.HasTraitInfo<HuskInfo>()) if (a == null || a.IsDead || Player.RelationshipWith(a.Owner) != PlayerRelationship.Enemy || a.Info.HasTraitInfo<HuskInfo>())
return false; return false;
var targetTypes = a.GetEnabledTargetTypes(); var targetTypes = a.GetEnabledTargetTypes();

View File

@@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var bp in world.ActorsWithTrait<BaseProvider>()) foreach (var bp in world.ActorsWithTrait<BaseProvider>())
{ {
var validOwner = bp.Actor.Owner == p || (allyBuildEnabled && bp.Actor.Owner.Stances[p] == PlayerRelationship.Ally); var validOwner = bp.Actor.Owner == p || (allyBuildEnabled && bp.Actor.Owner.RelationshipWith(p) == PlayerRelationship.Ally);
if (!validOwner || !bp.Trait.Ready()) if (!validOwner || !bp.Trait.Ready())
continue; continue;
@@ -211,13 +211,12 @@ namespace OpenRA.Mods.Common.Traits
for (var x = scanStart.X; x < scanEnd.X; x++) for (var x = scanStart.X; x < scanEnd.X; x++)
{ {
var pos = new CPos(x, y); var pos = new CPos(x, y);
foreach (var a in world.ActorMap.GetActorsAt(pos)) foreach (var a in world.ActorMap.GetActorsAt(pos))
{ {
if (!a.IsInWorld) if (!a.IsInWorld)
continue; continue;
if (a.Owner != p && (!allyBuildEnabled || a.Owner.Stances[p] != PlayerRelationship.Ally)) if (a.Owner != p && (!allyBuildEnabled || a.Owner.RelationshipWith(p) != PlayerRelationship.Ally))
continue; continue;
if (ActorGrantsValidArea(a, requiresBuildableArea)) if (ActorGrantsValidArea(a, requiresBuildableArea))

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits
: base(info) : base(info)
{ {
health = self.Trait<IHealth>(); health = self.Trait<IHealth>();
isNotActiveAlly = player => player.WinState != WinState.Undefined || player.Stances[self.Owner] != PlayerRelationship.Ally; isNotActiveAlly = player => player.WinState != WinState.Undefined || self.Owner.RelationshipWith(player) != PlayerRelationship.Ally;
} }
[Sync] [Sync]

View File

@@ -48,10 +48,9 @@ namespace OpenRA.Mods.Common.Traits
// TODO: FrozenActors don't yet have a way of caching conditions, so we can't filter disabled traits // TODO: FrozenActors don't yet have a way of caching conditions, so we can't filter disabled traits
// This therefore assumes that all Capturable traits are enabled, which is probably wrong. // This therefore assumes that all Capturable traits are enabled, which is probably wrong.
// Actors with FrozenUnderFog should therefore not disable the Capturable trait. // Actors with FrozenUnderFog should therefore not disable the Capturable trait.
var stance = frozenActor.Owner.Stances[captor.Owner]; var stance = captor.Owner.RelationshipWith(frozenActor.Owner);
return frozenActor.Info.TraitInfos<CapturableInfo>() return frozenActor.Info.TraitInfos<CapturableInfo>()
.Any(c => c.ValidStances.HasStance(stance) && .Any(c => c.ValidStances.HasStance(stance) && captures.Info.CaptureTypes.Overlaps(c.Types));
captures.Info.CaptureTypes.Overlaps(c.Types));
} }
} }
@@ -129,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits
public bool CanBeTargetedBy(Actor self, Actor captor, CaptureManager captorManager) public bool CanBeTargetedBy(Actor self, Actor captor, CaptureManager captorManager)
{ {
var stance = self.Owner.Stances[captor.Owner]; var stance = captor.Owner.RelationshipWith(self.Owner);
if (stance.HasStance(PlayerRelationship.Enemy)) if (stance.HasStance(PlayerRelationship.Enemy))
return captorManager.capturesTypes.Overlaps(enemyCapturableTypes); return captorManager.capturesTypes.Overlaps(enemyCapturableTypes);
@@ -147,7 +146,7 @@ namespace OpenRA.Mods.Common.Traits
if (captures.IsTraitDisabled) if (captures.IsTraitDisabled)
return false; return false;
var stance = self.Owner.Stances[captor.Owner]; var stance = captor.Owner.RelationshipWith(self.Owner);
if (stance.HasStance(PlayerRelationship.Enemy)) if (stance.HasStance(PlayerRelationship.Enemy))
return captures.Info.CaptureTypes.Overlaps(enemyCapturableTypes); return captures.Info.CaptureTypes.Overlaps(enemyCapturableTypes);

View File

@@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits
if (tokens.ContainsKey(a)) if (tokens.ContainsKey(a))
return; return;
var stance = self.Owner.Stances[a.Owner]; var stance = self.Owner.RelationshipWith(a.Owner);
if (!Info.ValidStances.HasStance(stance)) if (!Info.ValidStances.HasStance(stance))
return; return;
@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Traits
// Work around for actors produced within the region not triggering until the second tick // Work around for actors produced within the region not triggering until the second tick
if ((produced.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= Info.Range.LengthSquared) if ((produced.CenterPosition - self.CenterPosition).HorizontalLengthSquared <= Info.Range.LengthSquared)
{ {
var stance = self.Owner.Stances[produced.Owner]; var stance = self.Owner.RelationshipWith(produced.Owner);
if (!Info.ValidStances.HasStance(stance)) if (!Info.ValidStances.HasStance(stance))
return; return;

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv)
{ {
if (!info.ValidStances.HasStance(p.Stances[self.Owner])) if (!info.ValidStances.HasStance(self.Owner.RelationshipWith(p)))
return; return;
p.Shroud.AddSource(this, Shroud.SourceType.Shroud, uv); p.Shroud.AddSource(this, Shroud.SourceType.Shroud, uv);

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
var type = self.Info.TraitInfo<DeliversCashInfo>().Type; var type = self.Info.TraitInfo<DeliversCashInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>(); var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
return targetInfo != null return targetInfo != null
&& targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) && targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))
&& (targetInfo.ValidTypes.Count == 0 && (targetInfo.ValidTypes.Count == 0
|| (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
} }
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits
var type = self.Info.TraitInfo<DeliversCashInfo>().Type; var type = self.Info.TraitInfo<DeliversCashInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>(); var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
return targetInfo != null return targetInfo != null
&& targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) && targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))
&& (targetInfo.ValidTypes.Count == 0 && (targetInfo.ValidTypes.Count == 0
|| (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
} }

View File

@@ -103,16 +103,14 @@ namespace OpenRA.Mods.Common.Traits
var type = self.Info.TraitInfo<DeliversExperienceInfo>().Type; var type = self.Info.TraitInfo<DeliversExperienceInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>(); var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
var targetGainsExperience = target.TraitOrDefault<GainsExperience>(); var targetGainsExperience = target.TraitOrDefault<GainsExperience>();
if (targetGainsExperience == null || targetInfo == null) if (targetGainsExperience == null || targetInfo == null)
return false; return false;
if (targetGainsExperience.Level == targetGainsExperience.MaxLevel) if (targetGainsExperience.Level == targetGainsExperience.MaxLevel)
return false; return false;
return targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) return targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))
&& (targetInfo.ValidTypes.Count == 0 && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
|| (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
} }
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor) public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
@@ -130,9 +128,8 @@ namespace OpenRA.Mods.Common.Traits
if (targetGainsExperience.Level == targetGainsExperience.MaxLevel) if (targetGainsExperience.Level == targetGainsExperience.MaxLevel)
return false; return false;
return targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) return targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))
&& (targetInfo.ValidTypes.Count == 0 && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
|| (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type)));
} }
} }
} }

View File

@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Traits
if (modifiers.HasModifier(TargetModifiers.ForceMove)) if (modifiers.HasModifier(TargetModifiers.ForceMove))
return false; return false;
var stance = self.Owner.Stances[target.Owner]; var stance = target.Owner.RelationshipWith(self.Owner);
if (!info.TargetStances.HasStance(stance) && !modifiers.HasModifier(TargetModifiers.ForceAttack)) if (!info.TargetStances.HasStance(stance) && !modifiers.HasModifier(TargetModifiers.ForceAttack))
return false; return false;
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor) public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{ {
var stance = self.Owner.Stances[target.Owner]; var stance = target.Owner.RelationshipWith(self.Owner);
if (!info.TargetStances.HasStance(stance) && !modifiers.HasModifier(TargetModifiers.ForceAttack)) if (!info.TargetStances.HasStance(stance) && !modifiers.HasModifier(TargetModifiers.ForceAttack))
return false; return false;

View File

@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Traits
if (!engineerRepairable.Info.Types.IsEmpty && !engineerRepairable.Info.Types.Overlaps(info.Types)) if (!engineerRepairable.Info.Types.IsEmpty && !engineerRepairable.Info.Types.Overlaps(info.Types))
return false; return false;
if (!info.ValidStances.HasStance(self.Owner.Stances[target.Owner])) if (!info.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)))
return false; return false;
if (target.GetDamageState() == DamageState.Undamaged) if (target.GetDamageState() == DamageState.Undamaged)
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Traits
if (!engineerRepairable.Types.IsEmpty && !engineerRepairable.Types.Overlaps(info.Types)) if (!engineerRepairable.Types.IsEmpty && !engineerRepairable.Types.Overlaps(info.Types))
return false; return false;
if (!info.ValidStances.HasStance(self.Owner.Stances[target.Owner])) if (!info.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)))
return false; return false;
if (target.DamageState == DamageState.Undamaged) if (target.DamageState == DamageState.Undamaged)

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
if (e.Attacker == null || e.Attacker.Disposed || IsTraitDisabled) if (e.Attacker == null || e.Attacker.Disposed || IsTraitDisabled)
return; return;
if (!Info.ValidStances.HasStance(e.Attacker.Owner.Stances[self.Owner])) if (!Info.ValidStances.HasStance(e.Attacker.Owner.RelationshipWith(self.Owner)))
return; return;
if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes))

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
if (exp == 0 || e.Attacker == null || e.Attacker.Disposed) if (exp == 0 || e.Attacker == null || e.Attacker.Disposed)
return; return;
if (!info.ValidStances.HasStance(e.Attacker.Owner.Stances[self.Owner])) if (!info.ValidStances.HasStance(e.Attacker.Owner.RelationshipWith(self.Owner)))
return; return;
exp = Util.ApplyPercentageModifiers(exp, experienceModifiers); exp = Util.ApplyPercentageModifiers(exp, experienceModifiers);

View File

@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Traits
if (byPlayer == null) if (byPlayer == null)
return true; return true;
var stance = self.Owner.Stances[byPlayer]; var stance = self.Owner.RelationshipWith(byPlayer);
return info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer); return info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer);
} }

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
if (byPlayer == null) if (byPlayer == null)
return true; return true;
var stance = self.Owner.Stances[byPlayer]; var stance = self.Owner.RelationshipWith(byPlayer);
return Info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer); return Info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer);
} }

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits.Radar
public void PopulateRadarSignatureCells(Actor self, List<(CPos Cell, Color Color)> destinationBuffer) public void PopulateRadarSignatureCells(Actor self, List<(CPos Cell, Color Color)> destinationBuffer)
{ {
var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer; var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer;
if (IsTraitDisabled || (viewer != null && !Info.ValidStances.HasStance(self.Owner.Stances[viewer]))) if (IsTraitDisabled || (viewer != null && !Info.ValidStances.HasStance(self.Owner.RelationshipWith(viewer))))
return; return;
var color = Game.Settings.Game.UsePlayerStanceColors ? self.Owner.PlayerStanceColor(self) : self.Owner.Color; var color = Game.Settings.Game.UsePlayerStanceColors ? self.Owner.PlayerStanceColor(self) : self.Owner.Color;

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits.Render
float ISelectionBar.GetValue() float ISelectionBar.GetValue()
{ {
var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer; var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer;
if (viewer != null && !info.DisplayStances.HasStance(self.Owner.Stances[viewer])) if (viewer != null && !info.DisplayStances.HasStance(self.Owner.RelationshipWith(viewer)))
return 0; return 0;
var complete = cashTricklers.Min(ct => (float)ct.Ticks / ct.Info.Interval); var complete = cashTricklers.Min(ct => (float)ct.Ticks / ct.Info.Interval);

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits.Render
return 0; return 0;
var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer; var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer;
if (viewer != null && !Info.DisplayStances.HasStance(self.Owner.Stances[viewer])) if (viewer != null && !Info.DisplayStances.HasStance(self.Owner.RelationshipWith(viewer)))
return 0; return 0;
return 1 - (float)power.RemainingTicks / power.TotalTicks; return 1 - (float)power.RemainingTicks / power.TotalTicks;

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits.Render
if (self.World.RenderPlayer != null) if (self.World.RenderPlayer != null)
{ {
var stance = self.Owner.Stances[self.World.RenderPlayer]; var stance = self.Owner.RelationshipWith(self.World.RenderPlayer);
if (!Info.ValidStances.HasStance(stance)) if (!Info.ValidStances.HasStance(stance))
return false; return false;
} }

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits.Render
return false; return false;
var p = self.World.RenderPlayer; var p = self.World.RenderPlayer;
return p == null || Info.ValidStances.HasStance(self.Owner.Stances[p]) || (p.Spectating && !p.NonCombatant); return p == null || Info.ValidStances.HasStance(self.Owner.RelationshipWith(p)) || (p.Spectating && !p.NonCombatant);
} }
} }

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
protected void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) protected void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv)
{ {
if (!Info.ValidStances.HasStance(self.Owner.Stances[p])) if (!Info.ValidStances.HasStance(self.Owner.RelationshipWith(p)))
return; return;
p.Shroud.AddSource(this, type, uv); p.Shroud.AddSource(this, type, uv);

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv) protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv)
{ {
if (!info.ValidStances.HasStance(p.Stances[self.Owner])) if (!info.ValidStances.HasStance(self.Owner.RelationshipWith(p)))
return; return;
p.Shroud.AddSource(this, type, uv); p.Shroud.AddSource(this, type, uv);

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
if (player == null) if (player == null)
return; return;
if (Info.ValidStances.HasStance(self.Owner.Stances[player])) if (Info.ValidStances.HasStance(self.Owner.RelationshipWith(player)))
self.PlayVoice(Info.Voice); self.PlayVoice(Info.Voice);
else if (Info.PlayToOwner && self.Owner == player) else if (Info.PlayToOwner && self.Owner == player)
self.PlayVoice(Info.Voice); self.PlayVoice(Info.Voice);

View File

@@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits
return units.Distinct().Where(a => return units.Distinct().Where(a =>
{ {
if (!info.ValidStances.HasStance(a.Owner.Stances[Self.Owner])) if (!info.ValidStances.HasStance(Self.Owner.RelationshipWith(a.Owner)))
return false; return false;
return a.TraitsImplementing<ExternalCondition>() return a.TraitsImplementing<ExternalCondition>()

View File

@@ -53,10 +53,7 @@ namespace OpenRA.Mods.Common.Traits
if (Owner == null || forPlayer == null) if (Owner == null || forPlayer == null)
return false; return false;
if (!Info.ValidStances.HasStance(Owner.Stances[forPlayer])) return Info.ValidStances.HasStance(Owner.RelationshipWith(forPlayer));
return false;
return true;
} }
public string TooltipText public string TooltipText

View File

@@ -301,7 +301,7 @@ namespace OpenRA.Mods.Common.Traits
// If the check allows: We are not blocked by units that we can force to move out of the way. // If the check allows: We are not blocked by units that we can force to move out of the way.
if (check <= BlockedByActor.Immovable && cellFlag.HasCellFlag(CellFlag.HasMovableActor) && if (check <= BlockedByActor.Immovable && cellFlag.HasCellFlag(CellFlag.HasMovableActor) &&
actor.Owner.Stances[otherActor.Owner] == PlayerRelationship.Ally) actor.Owner.RelationshipWith(otherActor.Owner) == PlayerRelationship.Ally)
{ {
var mobile = otherActor.OccupiesSpace as Mobile; var mobile = otherActor.OccupiesSpace as Mobile;
if (mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable) if (mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable)

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Warheads
// (and to prevent returning ImpactActorType.Invalid on AffectsParent=false) // (and to prevent returning ImpactActorType.Invalid on AffectsParent=false)
public override bool IsValidAgainst(Actor victim, Actor firedBy) public override bool IsValidAgainst(Actor victim, Actor firedBy)
{ {
var stance = firedBy.Owner.Stances[victim.Owner]; var stance = firedBy.Owner.RelationshipWith(victim.Owner);
if (!ValidStances.HasStance(stance)) if (!ValidStances.HasStance(stance))
return false; return false;

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Warheads
if (!AffectsParent && victim == firedBy) if (!AffectsParent && victim == firedBy)
return false; return false;
var stance = firedBy.Owner.Stances[victim.Owner]; var stance = firedBy.Owner.RelationshipWith(victim.Owner);
if (!ValidStances.HasStance(stance)) if (!ValidStances.HasStance(stance))
return false; return false;
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Warheads
return false; return false;
// AffectsParent checks do not make sense for FrozenActors, so skip to stance checks // AffectsParent checks do not make sense for FrozenActors, so skip to stance checks
var stance = firedBy.Owner.Stances[victim.Owner]; var stance = firedBy.Owner.RelationshipWith(victim.Owner);
if (!ValidStances.HasStance(stance)) if (!ValidStances.HasStance(stance))
return false; return false;

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var flag = item.Get<ImageWidget>("FACTIONFLAG"); var flag = item.Get<ImageWidget>("FACTIONFLAG");
flag.GetImageCollection = () => "flags"; flag.GetImageCollection = () => "flags";
if (player == null || player.Stances[pp] == PlayerRelationship.Ally || player.WinState != WinState.Undefined) if (player == null || player.RelationshipWith(pp) == PlayerRelationship.Ally || player.WinState != WinState.Undefined)
{ {
flag.GetImageName = () => pp.Faction.InternalName; flag.GetImageName = () => pp.Faction.InternalName;
item.Get<LabelWidget>("FACTION").GetText = () => pp.Faction.Name; item.Get<LabelWidget>("FACTION").GetText = () => pp.Faction.Name;

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
o = viewport.ActorTooltip.Owner; o = viewport.ActorTooltip.Owner;
showOwner = o != null && !o.NonCombatant && viewport.ActorTooltip.TooltipInfo.IsOwnerRowVisible; showOwner = o != null && !o.NonCombatant && viewport.ActorTooltip.TooltipInfo.IsOwnerRowVisible;
var stance = o == null || world.RenderPlayer == null ? PlayerRelationship.None : o.Stances[world.RenderPlayer]; var stance = o == null || world.RenderPlayer == null ? PlayerRelationship.None : o.RelationshipWith(world.RenderPlayer);
labelText = viewport.ActorTooltip.TooltipInfo.TooltipForPlayerStance(stance); labelText = viewport.ActorTooltip.TooltipInfo.TooltipForPlayerStance(stance);
break; break;
} }
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
o = viewport.FrozenActorTooltip.TooltipOwner; o = viewport.FrozenActorTooltip.TooltipOwner;
showOwner = o != null && !o.NonCombatant && viewport.FrozenActorTooltip.TooltipInfo.IsOwnerRowVisible; showOwner = o != null && !o.NonCombatant && viewport.FrozenActorTooltip.TooltipInfo.IsOwnerRowVisible;
var stance = o == null || world.RenderPlayer == null ? PlayerRelationship.None : o.Stances[world.RenderPlayer]; var stance = o == null || world.RenderPlayer == null ? PlayerRelationship.None : o.RelationshipWith(world.RenderPlayer);
labelText = viewport.FrozenActorTooltip.TooltipInfo.TooltipForPlayerStance(stance); labelText = viewport.FrozenActorTooltip.TooltipInfo.TooltipForPlayerStance(stance);
break; break;
} }

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Widgets
{ {
var owner = p.Instances[0].Self.Owner; var owner = p.Instances[0].Self.Owner;
var viewer = owner.World.RenderPlayer ?? owner.World.LocalPlayer; var viewer = owner.World.RenderPlayer ?? owner.World.LocalPlayer;
return viewer == null || p.Info.DisplayTimerStances.HasStance(owner.Stances[viewer]); return viewer == null || p.Info.DisplayTimerStances.HasStance(owner.RelationshipWith(viewer));
}); });
texts = displayedPowers.Select(p => texts = displayedPowers.Select(p =>