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 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)

View File

@@ -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;

View File

@@ -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;
}
}
}

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))
{
// 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)

View File

@@ -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;

View File

@@ -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)));
}
}
}

View File

@@ -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;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Traits
if (!info.CrushClasses.Overlaps(crushClasses))
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;
var mobile = crusher.TraitOrDefault<Mobile>();
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Cnc.Traits
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 info.CrushClasses.Overlaps(crushClasses);

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common
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();
}

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var t in enterActor.TraitsImplementing<INotifyCapture>())
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);
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
// (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;

View File

@@ -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<IgnoresDisguiseInfo>())
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<IgnoresDisguiseInfo>())
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<Actor> blockers)
{
foreach (var blocker in blockers)
{
foreach (var moveBlocked in blocker.TraitsImplementing<INotifyBlockingMove>())
moveBlocked.OnNotifyBlockingMove(blocker, self);
}
}
public static void NotifyBlocker(this Actor self, CPos position)

View File

@@ -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)

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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<Mobile>() != null && otherActor.CurrentActivity == null)
return false;

View File

@@ -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);

View File

@@ -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

View File

@@ -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<ITargetableInfo>())

View File

@@ -409,7 +409,7 @@ namespace OpenRA.Mods.Common.Traits
case BuildingType.Defense:
// 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));
var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter;

View File

@@ -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;
}

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
// 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<RepairableBuilding>();

View File

@@ -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<HuskInfo>()
&& unit.Info.HasTraitInfo<ITargetableInfo>();
@@ -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)

View File

@@ -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));

View File

@@ -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<HuskInfo>())
if (a == null || a.IsDead || Player.RelationshipWith(a.Owner) != PlayerRelationship.Enemy || a.Info.HasTraitInfo<HuskInfo>())
return false;
var targetTypes = a.GetEnabledTargetTypes();

View File

@@ -167,7 +167,7 @@ namespace OpenRA.Mods.Common.Traits
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())
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))

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits
: base(info)
{
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]

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
// 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<CapturableInfo>()
.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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
var type = self.Info.TraitInfo<DeliversCashInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
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<DeliversCashInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredCashInfo>();
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)));
}

View File

@@ -103,16 +103,14 @@ namespace OpenRA.Mods.Common.Traits
var type = self.Info.TraitInfo<DeliversExperienceInfo>().Type;
var targetInfo = target.Info.TraitInfoOrDefault<AcceptsDeliveredExperienceInfo>();
var targetGainsExperience = target.TraitOrDefault<GainsExperience>();
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)));
}
}
}

View File

@@ -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;

View File

@@ -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)

View File

@@ -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))

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<ExternalCondition>()

View File

@@ -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

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 (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)

View File

@@ -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;

View File

@@ -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;

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var flag = item.Get<ImageWidget>("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<LabelWidget>("FACTION").GetText = () => pp.Faction.Name;

View File

@@ -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;
}

View File

@@ -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 =>