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