Remove the Stances dictionary

This commit is contained in:
abcdefg30
2020-09-26 16:49:10 +02:00
committed by Paul Chote
parent 718cf37146
commit ea3c7a3c34
3 changed files with 26 additions and 55 deletions

View File

@@ -229,8 +229,6 @@ namespace OpenRA
return "{0} ({1})".F(PlayerName, ClientIndex); return "{0} ({1})".F(PlayerName, ClientIndex);
} }
public Dictionary<Player, PlayerRelationship> Stances = new Dictionary<Player, PlayerRelationship>();
public PlayerRelationship RelationshipWith(Player other) public PlayerRelationship RelationshipWith(Player other)
{ {
if (this == other) if (this == other)
@@ -240,7 +238,13 @@ namespace OpenRA
if (other == null || other.Spectating) if (other == null || other.Spectating)
return NonCombatant ? PlayerRelationship.Neutral : PlayerRelationship.Ally; return NonCombatant ? PlayerRelationship.Neutral : PlayerRelationship.Ally;
return Stances[other]; if (AlliedPlayersMask.Overlaps(other.PlayerMask))
return PlayerRelationship.Ally;
if (EnemyPlayersMask.Overlaps(other.PlayerMask))
return PlayerRelationship.Enemy;
return PlayerRelationship.Neutral;
} }
public bool IsAlliedWith(Player p) public bool IsAlliedWith(Player p)

View File

@@ -207,30 +207,13 @@ namespace OpenRA
Selection = WorldActor.Trait<ISelection>(); Selection = WorldActor.Trait<ISelection>();
OrderValidators = WorldActor.TraitsImplementing<IValidateOrder>().ToArray(); OrderValidators = WorldActor.TraitsImplementing<IValidateOrder>().ToArray();
// Reset mask
LongBitSet<PlayerBitMask>.Reset(); LongBitSet<PlayerBitMask>.Reset();
// Add players
// Create an isolated RNG to simplify synchronization between client and server player faction/spawn assignments // Create an isolated RNG to simplify synchronization between client and server player faction/spawn assignments
var playerRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed); var playerRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed);
foreach (var cmp in WorldActor.TraitsImplementing<ICreatePlayers>()) foreach (var cmp in WorldActor.TraitsImplementing<ICreatePlayers>())
cmp.CreatePlayers(this, playerRandom); cmp.CreatePlayers(this, playerRandom);
// Set defaults for any unset stances
foreach (var p in Players)
{
if (!p.Spectating)
AllPlayersMask = AllPlayersMask.Union(p.PlayerMask);
foreach (var q in Players)
{
SetUpPlayerMask(p, q);
if (!p.Stances.ContainsKey(q))
p.Stances[q] = PlayerRelationship.Neutral;
}
}
Game.Sound.SoundVolumeModifier = 1.0f; Game.Sound.SoundVolumeModifier = 1.0f;
gameInfo = new GameInformation gameInfo = new GameInformation
@@ -245,25 +228,6 @@ namespace OpenRA
RulesContainTemporaryBlocker = map.Rules.Actors.Any(a => a.Value.HasTraitInfo<ITemporaryBlockerInfo>()); RulesContainTemporaryBlocker = map.Rules.Actors.Any(a => a.Value.HasTraitInfo<ITemporaryBlockerInfo>());
} }
void SetUpPlayerMask(Player p, Player q)
{
if (q.Spectating)
return;
var bitSet = q.PlayerMask;
switch (p.Stances[q])
{
case PlayerRelationship.Enemy:
case PlayerRelationship.Neutral:
p.EnemyPlayersMask = p.EnemyPlayersMask.Union(bitSet);
break;
case PlayerRelationship.Ally:
p.AlliedPlayersMask = p.AlliedPlayersMask.Union(bitSet);
break;
}
}
public void AddToMaps(Actor self, IOccupySpace ios) public void AddToMaps(Actor self, IOccupySpace ios)
{ {
ActorMap.AddInfluence(self, ios); ActorMap.AddInfluence(self, ios);

View File

@@ -132,23 +132,25 @@ namespace OpenRA.Mods.Common.Traits
foreach (var p in w.Players) foreach (var p in w.Players)
foreach (var q in w.Players) foreach (var q in w.Players)
if (!p.Stances.ContainsKey(q)) SetupPlayerMasks(p, q);
p.Stances[q] = ChooseInitialStance(p, q);
} }
static PlayerRelationship ChooseInitialStance(Player p, Player q) static void SetupPlayerMasks(Player p, Player q)
{ {
if (p == q) if (!p.Spectating)
return PlayerRelationship.Ally; p.World.AllPlayersMask = p.World.AllPlayersMask.Union(p.PlayerMask);
if (q.Spectating && !p.NonCombatant && p.Playable) if (p == q || p.PlayerReference.Allies.Contains(q.InternalName))
return PlayerRelationship.Ally; {
p.AlliedPlayersMask = p.AlliedPlayersMask.Union(q.PlayerMask);
return;
}
// Stances set via PlayerReference
if (p.PlayerReference.Allies.Contains(q.InternalName))
return PlayerRelationship.Ally;
if (p.PlayerReference.Enemies.Contains(q.InternalName)) if (p.PlayerReference.Enemies.Contains(q.InternalName))
return PlayerRelationship.Enemy; {
p.EnemyPlayersMask = p.EnemyPlayersMask.Union(q.PlayerMask);
return;
}
// HACK: Map players share a ClientID with the host, so would // HACK: Map players share a ClientID with the host, so would
// otherwise take the host's team stance instead of being neutral // otherwise take the host's team stance instead of being neutral
@@ -158,12 +160,13 @@ namespace OpenRA.Mods.Common.Traits
var pc = GetClientForPlayer(p); var pc = GetClientForPlayer(p);
var qc = GetClientForPlayer(q); var qc = GetClientForPlayer(q);
if (pc != null && qc != null) if (pc != null && qc != null)
return pc.Team != 0 && pc.Team == qc.Team {
? PlayerRelationship.Ally : PlayerRelationship.Enemy; if (pc.Team != 0 && pc.Team == qc.Team)
p.AlliedPlayersMask = p.AlliedPlayersMask.Union(q.PlayerMask);
else
p.EnemyPlayersMask = p.EnemyPlayersMask.Union(q.PlayerMask);
}
} }
// Otherwise, default to neutral
return PlayerRelationship.Neutral;
} }
static Session.Client GetClientForPlayer(Player p) static Session.Client GetClientForPlayer(Player p)