diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 7b08b01857..444ea4ca9d 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -230,10 +230,22 @@ namespace OpenRA } public Dictionary Stances = new Dictionary(); + + 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) { - // Observers are considered allies to active combatants - return p == null || Stances[p] == PlayerRelationship.Ally || (p.Spectating && !NonCombatant); + return RelationshipWith(p) == PlayerRelationship.Ally; } public Color PlayerStanceColor(Actor a) diff --git a/OpenRA.Game/SelectableExts.cs b/OpenRA.Game/SelectableExts.cs index 0b6cfbbdb5..09d509665b 100644 --- a/OpenRA.Game/SelectableExts.cs +++ b/OpenRA.Game/SelectableExts.cs @@ -36,7 +36,7 @@ namespace OpenRA.Traits if (a.Owner == viewer || viewer == null) return basePriority; - switch (viewer.Stances[a.Owner]) + switch (viewer.RelationshipWith(a.Owner)) { case PlayerRelationship.Ally: return basePriority - PriorityRange; case PlayerRelationship.Neutral: return basePriority - 2 * PriorityRange; diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index b8f547f797..252d112bee 100644 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -90,8 +90,7 @@ namespace OpenRA public static bool AreMutualAllies(Player a, Player b) { - return a.Stances[b] == PlayerRelationship.Ally && - b.Stances[a] == PlayerRelationship.Ally; + return a.RelationshipWith(b) == PlayerRelationship.Ally && b.RelationshipWith(a) == PlayerRelationship.Ally; } } } diff --git a/OpenRA.Mods.Cnc/Activities/LayMines.cs b/OpenRA.Mods.Cnc/Activities/LayMines.cs index 4efc0fe297..a34c21ad66 100644 --- a/OpenRA.Mods.Cnc/Activities/LayMines.cs +++ b/OpenRA.Mods.Cnc/Activities/LayMines.cs @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Cnc.Activities 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 - 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); if (rearmTarget == null) diff --git a/OpenRA.Mods.Cnc/Traits/Disguise.cs b/OpenRA.Mods.Cnc/Traits/Disguise.cs index 9150028811..3e76387438 100644 --- a/OpenRA.Mods.Cnc/Traits/Disguise.cs +++ b/OpenRA.Mods.Cnc/Traits/Disguise.cs @@ -298,8 +298,7 @@ namespace OpenRA.Mods.Cnc.Traits 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)) return false; @@ -308,8 +307,7 @@ namespace OpenRA.Mods.Cnc.Traits 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)) return false; diff --git a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForDecoration.cs b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForDecoration.cs index f3d4d39493..82a02031ea 100644 --- a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForDecoration.cs +++ b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForDecoration.cs @@ -48,8 +48,7 @@ namespace OpenRA.Mods.Cnc.Traits protected override bool ShouldRender(Actor self) { - return self.World.RenderPlayer == null || infiltrators.Any(i => - Info.ValidStances.HasStance(i.Stances[self.World.RenderPlayer])); + return infiltrators.Any(i => Info.ValidStances.HasStance(i.RelationshipWith(self.World.RenderPlayer))); } } } diff --git a/OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs b/OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs index 1392309c64..1bbe3fbb28 100644 --- a/OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs +++ b/OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs @@ -98,10 +98,10 @@ namespace OpenRA.Mods.Cnc.Traits { case TargetType.Actor: 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: 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: return false; } @@ -132,8 +132,7 @@ namespace OpenRA.Mods.Cnc.Traits 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)) return false; @@ -142,8 +141,7 @@ namespace OpenRA.Mods.Cnc.Traits 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)) return false; diff --git a/OpenRA.Mods.Cnc/Traits/Mine.cs b/OpenRA.Mods.Cnc/Traits/Mine.cs index 38b04ff5f9..3fbeccc551 100644 --- a/OpenRA.Mods.Cnc/Traits/Mine.cs +++ b/OpenRA.Mods.Cnc/Traits/Mine.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Traits if (!info.CrushClasses.Overlaps(crushClasses)) return; - if (crusher.Info.HasTraitInfo() || (self.Owner.Stances[crusher.Owner] == PlayerRelationship.Ally && info.AvoidFriendly)) + if (crusher.Info.HasTraitInfo() || (self.Owner.RelationshipWith(crusher.Owner) == PlayerRelationship.Ally && info.AvoidFriendly)) return; var mobile = crusher.TraitOrDefault(); @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Cnc.Traits bool ICrushable.CrushableBy(Actor self, Actor crusher, BitSet crushClasses) { - if (info.BlockFriendly && !crusher.Info.HasTraitInfo() && self.Owner.Stances[crusher.Owner] == PlayerRelationship.Ally) + if (info.BlockFriendly && !crusher.Info.HasTraitInfo() && self.Owner.RelationshipWith(crusher.Owner) == PlayerRelationship.Ally) return false; return info.CrushClasses.Overlaps(crushClasses); diff --git a/OpenRA.Mods.Common/AIUtils.cs b/OpenRA.Mods.Common/AIUtils.cs index 768c8171d7..ac1976c3df 100644 --- a/OpenRA.Mods.Common/AIUtils.cs +++ b/OpenRA.Mods.Common/AIUtils.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common public static List FindEnemiesByCommonName(HashSet 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(); } diff --git a/OpenRA.Mods.Common/Activities/CaptureActor.cs b/OpenRA.Mods.Common/Activities/CaptureActor.cs index b2f5340d97..9dba81848b 100644 --- a/OpenRA.Mods.Common/Activities/CaptureActor.cs +++ b/OpenRA.Mods.Common/Activities/CaptureActor.cs @@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Activities foreach (var t in enterActor.TraitsImplementing()) 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()?.GiveExperience(captures.Info.PlayerExperience); if (captures.Info.ConsumedByCapture) diff --git a/OpenRA.Mods.Common/Activities/RepairBuilding.cs b/OpenRA.Mods.Common/Activities/RepairBuilding.cs index e6261b51eb..3d03680393 100644 --- a/OpenRA.Mods.Common/Activities/RepairBuilding.cs +++ b/OpenRA.Mods.Common/Activities/RepairBuilding.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities // 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.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)) { Cancel(self, true); @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Activities if (enterHealth.DamageState == DamageState.Undamaged) return; - var stance = self.Owner.Stances[enterActor.Owner]; + var stance = self.Owner.RelationshipWith(enterActor.Owner); if (!info.ValidStances.HasStance(stance)) return; diff --git a/OpenRA.Mods.Common/ActorExts.cs b/OpenRA.Mods.Common/ActorExts.cs index 1237a5d075..ee2322fe1a 100644 --- a/OpenRA.Mods.Common/ActorExts.cs +++ b/OpenRA.Mods.Common/ActorExts.cs @@ -36,24 +36,24 @@ namespace OpenRA.Mods.Common 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) return true; if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.Info.HasTraitInfo()) - return toActor.Owner.Stances[self.EffectiveOwner.Owner] == PlayerRelationship.Ally; + return toActor.Owner.RelationshipWith(self.EffectiveOwner.Owner) == PlayerRelationship.Ally; return false; } 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) - return false; /* otherwise, we'll hate friendly disguised spies */ + return false; if (self.EffectiveOwner != null && self.EffectiveOwner.Disguised && !toActor.Info.HasTraitInfo()) - return toActor.Owner.Stances[self.EffectiveOwner.Owner] == PlayerRelationship.Enemy; + return toActor.Owner.RelationshipWith(self.EffectiveOwner.Owner) == PlayerRelationship.Enemy; return stance == PlayerRelationship.Enemy; } @@ -61,10 +61,8 @@ namespace OpenRA.Mods.Common public static void NotifyBlocker(this Actor self, IEnumerable blockers) { foreach (var blocker in blockers) - { foreach (var moveBlocked in blocker.TraitsImplementing()) moveBlocked.OnNotifyBlockingMove(blocker, self); - } } public static void NotifyBlocker(this Actor self, CPos position) diff --git a/OpenRA.Mods.Common/Effects/RevealShroudEffect.cs b/OpenRA.Mods.Common/Effects/RevealShroudEffect.cs index 633f054c5c..0999528e82 100644 --- a/OpenRA.Mods.Common/Effects/RevealShroudEffect.cs +++ b/OpenRA.Mods.Common/Effects/RevealShroudEffect.cs @@ -41,7 +41,11 @@ namespace OpenRA.Mods.Common.Effects 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); } @@ -52,8 +56,7 @@ namespace OpenRA.Mods.Common.Effects if (range == WDist.Zero) return NoCells; - return Shroud.ProjectedCellsInRange(map, pos, WDist.Zero, range) - .ToArray(); + return Shroud.ProjectedCellsInRange(map, pos, WDist.Zero, range).ToArray(); } public void Tick(World world) diff --git a/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs b/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs index 14b50b4491..e9f10b670c 100644 --- a/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs +++ b/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs @@ -50,8 +50,7 @@ namespace OpenRA.Mods.Common.Orders return false; 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) return false; diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs index 3b9caf6ee4..ba0450cd63 100644 --- a/OpenRA.Mods.Common/Projectiles/Bullet.cs +++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs @@ -319,7 +319,7 @@ namespace OpenRA.Mods.Common.Projectiles if (checkTargetType && !Target.FromActor(victim).IsValidFor(firedBy)) continue; - if (!info.ValidBounceBlockerStances.HasStance(victim.Owner.Stances[firedBy.Owner])) + if (!info.ValidBounceBlockerStances.HasStance(firedBy.Owner.RelationshipWith(victim.Owner))) continue; // If the impact position is within any actor's HitShape, we have a direct hit diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index 978968b665..98ad379a1a 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -429,7 +429,7 @@ namespace OpenRA.Mods.Common.Projectiles if ((tp.Actor.CenterPosition - pos).HorizontalLengthSquared > tp.Trait.Range.LengthSquared) 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 tp.Actor.World.SharedRandom.Next(100) < tp.Trait.Chance; diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index f4c1ddd536..bfc1589b59 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -670,7 +670,7 @@ namespace OpenRA.Mods.Common.Traits // We are not blocked by actors we can nudge out of the way // 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() != null && otherActor.CurrentActivity == null) return false; diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index 6dac7f68e8..81d49ca47a 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -377,8 +377,7 @@ namespace OpenRA.Mods.Common.Traits return Armaments.Where(a => !a.IsTraitDisabled - && (owner == null || (forceAttack ? a.Info.ForceTargetStances : a.Info.TargetStances) - .HasStance(self.Owner.Stances[owner])) + && (owner == null || (forceAttack ? a.Info.ForceTargetStances : a.Info.TargetStances).HasStance(self.Owner.RelationshipWith(owner))) && 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) // to use the same code 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; var forceAttack = modifiers.HasModifier(TargetModifiers.ForceAttack); diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index c17cee3d7c..cba778901e 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -326,7 +326,7 @@ namespace OpenRA.Mods.Common.Traits return activeTargetPriorities.Any(ati => { // Incompatible stances - if (!ati.ValidStances.HasStance(self.Owner.Stances[owner])) + if (!ati.ValidStances.HasStance(self.Owner.RelationshipWith(owner))) return false; // 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 // 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. - if (attackStances == OpenRA.Traits.PlayerRelationship.Enemy && !target.Actor.AppearsHostileTo(self)) + if (attackStances == PlayerRelationship.Enemy && !target.Actor.AppearsHostileTo(self)) continue; // Check whether we can auto-target this actor @@ -375,7 +375,7 @@ namespace OpenRA.Mods.Common.Traits } 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; targetTypes = target.FrozenActor.TargetTypes; @@ -391,7 +391,7 @@ namespace OpenRA.Mods.Common.Traits return false; // Incompatible stances - if (!ati.ValidStances.HasStance(self.Owner.Stances[owner])) + if (!ati.ValidStances.HasStance(self.Owner.RelationshipWith(owner))) return false; // Incompatible target types diff --git a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs index 6ecd7c0314..8e8a12c7f9 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs @@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Traits if (e.Attacker == null || e.Attacker.Disposed) return; - if (e.Attacker.Owner.Stances[self.Owner] != PlayerRelationship.Enemy) + if (e.Attacker.Owner.RelationshipWith(self.Owner) != PlayerRelationship.Enemy) return; if (!e.Attacker.Info.HasTraitInfo()) diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs index 4b3736f21e..f646e58d90 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs @@ -409,7 +409,7 @@ namespace OpenRA.Mods.Common.Traits case BuildingType.Defense: // Build near the closest enemy structure - var closestEnemy = world.ActorsHavingTrait().Where(a => !a.Disposed && player.Stances[a.Owner] == PlayerRelationship.Enemy) + var closestEnemy = world.ActorsHavingTrait().Where(a => !a.Disposed && player.RelationshipWith(a.Owner) == PlayerRelationship.Enemy) .ClosestTo(world.Map.CenterOfCell(baseBuilder.DefenseCenter)); var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter; diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/SupportPowerDecision.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/SupportPowerDecision.cs index 044c7ff16f..e46b2d9143 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/SupportPowerDecision.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/SupportPowerDecision.cs @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits var checkActors = world.FindActorsInCircle(pos, radiusToUse); 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 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 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; @@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var consideration in Considerations) 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; } @@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var consideration in Considerations) foreach (var scrutinized in frozenActors) 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; } diff --git a/OpenRA.Mods.Common/Traits/BotModules/BuildingRepairBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BuildingRepairBotModule.cs index 5d886a933c..46f73ff760 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BuildingRepairBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BuildingRepairBotModule.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits // HACK: We don't want D2k bots to repair all their buildings on placement // where half their HP is removed via neutral terrain damage. // 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; var rb = self.TraitOrDefault(); diff --git a/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs index b960b3a079..68d1752b43 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/CaptureManagerBotModule.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits return; isEnemyUnit = unit => - player.Stances[unit.Owner] == PlayerRelationship.Enemy + player.RelationshipWith(unit.Owner) == PlayerRelationship.Enemy && !unit.Info.HasTraitInfo() && unit.Info.HasTraitInfo(); @@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Traits return; 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 ? GetVisibleActorsBelongingToPlayer(randPlayer) diff --git a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs index 8121580ede..5bcd4e7670 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/HarvesterBotModule.cs @@ -152,7 +152,7 @@ namespace OpenRA.Mods.Common.Traits var path = pathfinder.FindPath( PathSearch.Search(world, harv.Locomotor, actor, BlockedByActor.Stationary, isValidResource) .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))) .FromPoint(actor.Location)); diff --git a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs index ca2c0139d7..d37b697101 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs @@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits // Use for proactive targeting. public bool IsPreferredEnemyUnit(Actor a) { - if (a == null || a.IsDead || Player.Stances[a.Owner] != PlayerRelationship.Enemy || a.Info.HasTraitInfo()) + if (a == null || a.IsDead || Player.RelationshipWith(a.Owner) != PlayerRelationship.Enemy || a.Info.HasTraitInfo()) return false; var targetTypes = a.GetEnabledTargetTypes(); diff --git a/OpenRA.Mods.Common/Traits/Buildings/Building.cs b/OpenRA.Mods.Common/Traits/Buildings/Building.cs index 9f1900131f..7ea1257dad 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Building.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Building.cs @@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var bp in world.ActorsWithTrait()) { - 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()) continue; @@ -211,13 +211,12 @@ namespace OpenRA.Mods.Common.Traits for (var x = scanStart.X; x < scanEnd.X; x++) { var pos = new CPos(x, y); - foreach (var a in world.ActorMap.GetActorsAt(pos)) { if (!a.IsInWorld) continue; - if (a.Owner != p && (!allyBuildEnabled || a.Owner.Stances[p] != PlayerRelationship.Ally)) + if (a.Owner != p && (!allyBuildEnabled || a.Owner.RelationshipWith(p) != PlayerRelationship.Ally)) continue; if (ActorGrantsValidArea(a, requiresBuildableArea)) diff --git a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs index 93caaa8d09..c44573dd08 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs @@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits : base(info) { health = self.Trait(); - 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] diff --git a/OpenRA.Mods.Common/Traits/CaptureManager.cs b/OpenRA.Mods.Common/Traits/CaptureManager.cs index 2fac0f25fb..0126f18e6b 100644 --- a/OpenRA.Mods.Common/Traits/CaptureManager.cs +++ b/OpenRA.Mods.Common/Traits/CaptureManager.cs @@ -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 // This therefore assumes that all Capturable traits are enabled, which is probably wrong. // 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() - .Any(c => c.ValidStances.HasStance(stance) && - captures.Info.CaptureTypes.Overlaps(c.Types)); + .Any(c => c.ValidStances.HasStance(stance) && captures.Info.CaptureTypes.Overlaps(c.Types)); } } @@ -129,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits 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)) return captorManager.capturesTypes.Overlaps(enemyCapturableTypes); @@ -147,7 +146,7 @@ namespace OpenRA.Mods.Common.Traits if (captures.IsTraitDisabled) return false; - var stance = self.Owner.Stances[captor.Owner]; + var stance = captor.Owner.RelationshipWith(self.Owner); if (stance.HasStance(PlayerRelationship.Enemy)) return captures.Info.CaptureTypes.Overlaps(enemyCapturableTypes); diff --git a/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs index 0f6f801afd..fabaec49b8 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/ProximityExternalCondition.cs @@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits if (tokens.ContainsKey(a)) return; - var stance = self.Owner.Stances[a.Owner]; + var stance = self.Owner.RelationshipWith(a.Owner); if (!Info.ValidStances.HasStance(stance)) return; @@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Traits // Work around for actors produced within the region not triggering until the second tick 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)) return; diff --git a/OpenRA.Mods.Common/Traits/CreatesShroud.cs b/OpenRA.Mods.Common/Traits/CreatesShroud.cs index 3e60f9cd28..306771b3c1 100644 --- a/OpenRA.Mods.Common/Traits/CreatesShroud.cs +++ b/OpenRA.Mods.Common/Traits/CreatesShroud.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits 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; p.Shroud.AddSource(this, Shroud.SourceType.Shroud, uv); diff --git a/OpenRA.Mods.Common/Traits/DeliversCash.cs b/OpenRA.Mods.Common/Traits/DeliversCash.cs index 09fe3b7a53..3b706e5937 100644 --- a/OpenRA.Mods.Common/Traits/DeliversCash.cs +++ b/OpenRA.Mods.Common/Traits/DeliversCash.cs @@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits var type = self.Info.TraitInfo().Type; var targetInfo = target.Info.TraitInfoOrDefault(); return targetInfo != null - && targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) + && targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)) && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); } @@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits var type = self.Info.TraitInfo().Type; var targetInfo = target.Info.TraitInfoOrDefault(); return targetInfo != null - && targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) + && targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)) && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); } diff --git a/OpenRA.Mods.Common/Traits/DeliversExperience.cs b/OpenRA.Mods.Common/Traits/DeliversExperience.cs index e9ca4fbc00..a3cfad81ee 100644 --- a/OpenRA.Mods.Common/Traits/DeliversExperience.cs +++ b/OpenRA.Mods.Common/Traits/DeliversExperience.cs @@ -103,16 +103,14 @@ namespace OpenRA.Mods.Common.Traits var type = self.Info.TraitInfo().Type; var targetInfo = target.Info.TraitInfoOrDefault(); var targetGainsExperience = target.TraitOrDefault(); - if (targetGainsExperience == null || targetInfo == null) return false; if (targetGainsExperience.Level == targetGainsExperience.MaxLevel) return false; - return targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) - && (targetInfo.ValidTypes.Count == 0 - || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); + return targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)) + && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); } 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) return false; - return targetInfo.ValidStances.HasStance(target.Owner.Stances[self.Owner]) - && (targetInfo.ValidTypes.Count == 0 - || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); + return targetInfo.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner)) + && (targetInfo.ValidTypes.Count == 0 || (!string.IsNullOrEmpty(type) && targetInfo.ValidTypes.Contains(type))); } } } diff --git a/OpenRA.Mods.Common/Traits/Demolition.cs b/OpenRA.Mods.Common/Traits/Demolition.cs index edae6555ee..7759e9f784 100644 --- a/OpenRA.Mods.Common/Traits/Demolition.cs +++ b/OpenRA.Mods.Common/Traits/Demolition.cs @@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Traits if (modifiers.HasModifier(TargetModifiers.ForceMove)) 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)) return false; @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits 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)) return false; diff --git a/OpenRA.Mods.Common/Traits/EngineerRepair.cs b/OpenRA.Mods.Common/Traits/EngineerRepair.cs index 6c34e486e6..68885b7b70 100644 --- a/OpenRA.Mods.Common/Traits/EngineerRepair.cs +++ b/OpenRA.Mods.Common/Traits/EngineerRepair.cs @@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Traits if (!engineerRepairable.Info.Types.IsEmpty && !engineerRepairable.Info.Types.Overlaps(info.Types)) return false; - if (!info.ValidStances.HasStance(self.Owner.Stances[target.Owner])) + if (!info.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))) return false; if (target.GetDamageState() == DamageState.Undamaged) @@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Traits if (!engineerRepairable.Types.IsEmpty && !engineerRepairable.Types.Overlaps(info.Types)) return false; - if (!info.ValidStances.HasStance(self.Owner.Stances[target.Owner])) + if (!info.ValidStances.HasStance(target.Owner.RelationshipWith(self.Owner))) return false; if (target.DamageState == DamageState.Undamaged) diff --git a/OpenRA.Mods.Common/Traits/GivesBounty.cs b/OpenRA.Mods.Common/Traits/GivesBounty.cs index 895df9fddf..df2fac8c6b 100644 --- a/OpenRA.Mods.Common/Traits/GivesBounty.cs +++ b/OpenRA.Mods.Common/Traits/GivesBounty.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits if (e.Attacker == null || e.Attacker.Disposed || IsTraitDisabled) return; - if (!Info.ValidStances.HasStance(e.Attacker.Owner.Stances[self.Owner])) + if (!Info.ValidStances.HasStance(e.Attacker.Owner.RelationshipWith(self.Owner))) return; if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) diff --git a/OpenRA.Mods.Common/Traits/GivesExperience.cs b/OpenRA.Mods.Common/Traits/GivesExperience.cs index 17bec58ecb..0deb4ee47d 100644 --- a/OpenRA.Mods.Common/Traits/GivesExperience.cs +++ b/OpenRA.Mods.Common/Traits/GivesExperience.cs @@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits if (exp == 0 || e.Attacker == null || e.Attacker.Disposed) return; - if (!info.ValidStances.HasStance(e.Attacker.Owner.Stances[self.Owner])) + if (!info.ValidStances.HasStance(e.Attacker.Owner.RelationshipWith(self.Owner))) return; exp = Util.ApplyPercentageModifiers(exp, experienceModifiers); diff --git a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs index d5f48611d8..94b87ec6d3 100644 --- a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs +++ b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs @@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Traits if (byPlayer == null) return true; - var stance = self.Owner.Stances[byPlayer]; + var stance = self.Owner.RelationshipWith(byPlayer); return info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer); } diff --git a/OpenRA.Mods.Common/Traits/Modifiers/HiddenUnderShroud.cs b/OpenRA.Mods.Common/Traits/Modifiers/HiddenUnderShroud.cs index 7b4853e3fb..49a5355976 100644 --- a/OpenRA.Mods.Common/Traits/Modifiers/HiddenUnderShroud.cs +++ b/OpenRA.Mods.Common/Traits/Modifiers/HiddenUnderShroud.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits if (byPlayer == null) return true; - var stance = self.Owner.Stances[byPlayer]; + var stance = self.Owner.RelationshipWith(byPlayer); return Info.AlwaysVisibleStances.HasStance(stance) || IsVisibleInner(self, byPlayer); } diff --git a/OpenRA.Mods.Common/Traits/Radar/AppearsOnRadar.cs b/OpenRA.Mods.Common/Traits/Radar/AppearsOnRadar.cs index e7f5305dc2..5d799c0341 100644 --- a/OpenRA.Mods.Common/Traits/Radar/AppearsOnRadar.cs +++ b/OpenRA.Mods.Common/Traits/Radar/AppearsOnRadar.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits.Radar public void PopulateRadarSignatureCells(Actor self, List<(CPos Cell, Color Color)> destinationBuffer) { 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; var color = Game.Settings.Game.UsePlayerStanceColors ? self.Owner.PlayerStanceColor(self) : self.Owner.Color; diff --git a/OpenRA.Mods.Common/Traits/Render/CashTricklerBar.cs b/OpenRA.Mods.Common/Traits/Render/CashTricklerBar.cs index 20a262e3b7..a51cf9498e 100644 --- a/OpenRA.Mods.Common/Traits/Render/CashTricklerBar.cs +++ b/OpenRA.Mods.Common/Traits/Render/CashTricklerBar.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits.Render float ISelectionBar.GetValue() { 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; var complete = cashTricklers.Min(ct => (float)ct.Ticks / ct.Info.Interval); diff --git a/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs b/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs index ae71dd553b..d1c27faef8 100644 --- a/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs +++ b/OpenRA.Mods.Common/Traits/Render/SupportPowerChargeBar.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits.Render return 0; 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 1 - (float)power.RemainingTicks / power.TotalTicks; diff --git a/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs b/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs index db8eb84b25..a342868dea 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs @@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits.Render 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)) return false; } diff --git a/OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs b/OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs index 0e80d370ad..b480fa590c 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithRangeCircle.cs @@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits.Render return false; 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); } } diff --git a/OpenRA.Mods.Common/Traits/RevealsMap.cs b/OpenRA.Mods.Common/Traits/RevealsMap.cs index 28cbc0109b..40ec09684f 100644 --- a/OpenRA.Mods.Common/Traits/RevealsMap.cs +++ b/OpenRA.Mods.Common/Traits/RevealsMap.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits 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; p.Shroud.AddSource(this, type, uv); diff --git a/OpenRA.Mods.Common/Traits/RevealsShroud.cs b/OpenRA.Mods.Common/Traits/RevealsShroud.cs index e9147959bc..9d3355cf86 100644 --- a/OpenRA.Mods.Common/Traits/RevealsShroud.cs +++ b/OpenRA.Mods.Common/Traits/RevealsShroud.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits 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; p.Shroud.AddSource(this, type, uv); diff --git a/OpenRA.Mods.Common/Traits/Sound/VoiceAnnouncement.cs b/OpenRA.Mods.Common/Traits/Sound/VoiceAnnouncement.cs index fad8e1aa5e..6e681b1591 100644 --- a/OpenRA.Mods.Common/Traits/Sound/VoiceAnnouncement.cs +++ b/OpenRA.Mods.Common/Traits/Sound/VoiceAnnouncement.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits.Sound if (player == null) return; - if (Info.ValidStances.HasStance(self.Owner.Stances[player])) + if (Info.ValidStances.HasStance(self.Owner.RelationshipWith(player))) self.PlayVoice(Info.Voice); else if (Info.PlayToOwner && self.Owner == player) self.PlayVoice(Info.Voice); diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs index 587a9ad3bc..3a09464582 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs @@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits 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 a.TraitsImplementing() diff --git a/OpenRA.Mods.Common/Traits/TooltipDescription.cs b/OpenRA.Mods.Common/Traits/TooltipDescription.cs index 17fe92e7bc..e2690c44da 100644 --- a/OpenRA.Mods.Common/Traits/TooltipDescription.cs +++ b/OpenRA.Mods.Common/Traits/TooltipDescription.cs @@ -53,10 +53,7 @@ namespace OpenRA.Mods.Common.Traits if (Owner == null || forPlayer == null) return false; - if (!Info.ValidStances.HasStance(Owner.Stances[forPlayer])) - return false; - - return true; + return Info.ValidStances.HasStance(Owner.RelationshipWith(forPlayer)); } public string TooltipText diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs index 7aed696e5f..a0b885a7d7 100644 --- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs @@ -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 (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; if (mobile != null && !mobile.IsTraitDisabled && !mobile.IsTraitPaused && !mobile.IsImmovable) diff --git a/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs b/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs index acba4aebfc..9ae73da2a1 100644 --- a/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/CreateEffectWarhead.cs @@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Warheads // (and to prevent returning ImpactActorType.Invalid on AffectsParent=false) 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)) return false; diff --git a/OpenRA.Mods.Common/Warheads/Warhead.cs b/OpenRA.Mods.Common/Warheads/Warhead.cs index 7ab7b7f15d..78b54d1ebc 100644 --- a/OpenRA.Mods.Common/Warheads/Warhead.cs +++ b/OpenRA.Mods.Common/Warheads/Warhead.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Warheads if (!AffectsParent && victim == firedBy) return false; - var stance = firedBy.Owner.Stances[victim.Owner]; + var stance = firedBy.Owner.RelationshipWith(victim.Owner); if (!ValidStances.HasStance(stance)) return false; @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Warheads return false; // 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)) return false; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index b8aad20016..10e7b06b60 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var flag = item.Get("FACTIONFLAG"); 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; item.Get("FACTION").GetText = () => pp.Faction.Name; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs index 7637436538..e4372d1a23 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic o = viewport.ActorTooltip.Owner; 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); break; } @@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic o = viewport.FrozenActorTooltip.TooltipOwner; 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); break; } diff --git a/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs b/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs index 580b89060f..9a0ca911ed 100644 --- a/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/SupportPowerTimerWidget.cs @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Widgets { var owner = p.Instances[0].Self.Owner; 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 =>