Remove obsolete Player index cruft

This commit is contained in:
Paul Chote
2011-06-17 22:17:03 +12:00
parent bcbd18bb52
commit 532bd42aed
20 changed files with 49 additions and 64 deletions

View File

@@ -36,12 +36,12 @@ namespace OpenRA.Mods.RA
if (!hasAnything && !self.Owner.NonCombatant)
Lose(self);
var others = self.World.players.Where( p => !p.Value.NonCombatant
&& p.Value != self.Owner && p.Value.Stances[self.Owner] != Stance.Ally );
var others = self.World.Players.Where( p => !p.NonCombatant
&& p != self.Owner && p.Stances[self.Owner] != Stance.Ally );
if (others.Count() == 0) return;
if(others.All(p => p.Value.WinState == WinState.Lost))
if(others.All(p => p.WinState == WinState.Lost))
Win(self);
}

View File

@@ -21,13 +21,10 @@ namespace OpenRA.Mods.RA
{
public void CreatePlayers(World w)
{
var playerIndex = 0;
var mapPlayerIndex = -1; // todo: unhack this, but people still rely on it.
// create the unplayable map players -- neutral, shellmap, scripted, etc.
foreach (var kv in w.Map.Players.Where(p => !p.Value.Playable))
{
var player = new Player(w, null, kv.Value, mapPlayerIndex--);
var player = new Player(w, null, kv.Value);
w.AddPlayer(player);
if (kv.Value.OwnsWorld)
w.WorldActor.Owner = player;
@@ -40,10 +37,10 @@ namespace OpenRA.Mods.RA
if (client != null)
{
/* spawn a real player in this slot. */
var player = new Player(w, client, w.Map.Players[slot.MapPlayer], playerIndex++);
var player = new Player(w, client, w.Map.Players[slot.MapPlayer]);
w.AddPlayer(player);
if (client.Index == Game.LocalClientId)
w.SetLocalPlayer(player.Index); // bind this one to the local player.
w.SetLocalPlayer(player.InternalName); // bind this one to the local player.
}
// TODO: This is shit. Merge it up into Player ctor?
else if (slot.Bot != null && slot.MapPlayer != null)
@@ -55,8 +52,7 @@ namespace OpenRA.Mods.RA
w.Map.Players[slot.MapPlayer].ColorRamp = new ColorRamp(hue, 255, 180, 25);
/* todo: pick a random name from the pool */
var player = new Player(w, null, w.Map.Players[slot.MapPlayer], playerIndex++);
var player = new Player(w, null, w.Map.Players[slot.MapPlayer]);
w.AddPlayer(player);
/* activate the bot option that's selected! */
@@ -70,8 +66,8 @@ namespace OpenRA.Mods.RA
}
}
foreach (var p in w.players.Values)
foreach (var q in w.players.Values)
foreach (var p in w.Players)
foreach (var q in w.Players)
{
if (!p.Stances.ContainsKey(q))
p.Stances[q] = ChooseInitialStance(p, q);
@@ -90,17 +86,16 @@ namespace OpenRA.Mods.RA
if (p.World.LobbyInfo.Slots[qc.Slot].Spectator) return Stance.Ally;
}
// Stances set via the player reference
if (p.PlayerRef.Allies.Contains(q.InternalName))
return Stance.Ally;
if (p.PlayerRef.Enemies.Contains(q.InternalName))
return Stance.Enemy;
// Hack: All map players are neutral wrt everyone else
if (p.Index < 0 || q.Index < 0) return Stance.Neutral;
if (p.IsBot ^ q.IsBot)
return Stance.Enemy; // bots and humans hate each other
// Otherwise, default to neutral for map-players
if (!p.PlayerRef.Playable || !q.PlayerRef.Playable) return Stance.Neutral;
// or enemy for bot vs human
if (p.IsBot ^ q.IsBot) return Stance.Enemy;
return pc.Team != 0 && pc.Team == qc.Team
? Stance.Ally : Stance.Enemy;

View File

@@ -250,7 +250,7 @@ namespace OpenRA.Mods.RA
bool HasHumanPlayers()
{
return p.World.players.Any(a => !a.Value.IsBot && !a.Value.NonCombatant);
return p.World.Players.Any(a => !a.IsBot && !a.NonCombatant);
}
int2? ChooseEnemyTarget()

View File

@@ -39,7 +39,6 @@ namespace OpenRA.Mods.RA
continue; // Skip spectator slots
var client = world.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index);
var player = FindPlayerInSlot(world, slot);
if (player == null) continue;
var spid = (client == null || client.SpawnPoint == 0)
@@ -62,7 +61,7 @@ namespace OpenRA.Mods.RA
static Player FindPlayerInSlot(World world, Session.Slot slot)
{
return world.players.Values.FirstOrDefault(p => p.PlayerRef.Name == slot.MapPlayer);
return world.Players.FirstOrDefault(p => p.PlayerRef.Name == slot.MapPlayer);
}
static int2 ChooseSpawnPoint(World world, List<int2> available, List<int2> taken)

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA
if (client.State == Session.ClientState.Disconnected)
{
Disconnected = true; /* dont call this multiple times! */
self.World.players.Do(pl => pl.Value.PlayerActor.TraitsImplementing<IResolveOrder>().Do(t => t.ResolveOrder(pl.Value.PlayerActor, new Order("Surrender", self, false))));
self.World.Players.Do(pl => pl.PlayerActor.TraitsImplementing<IResolveOrder>().Do(t => t.ResolveOrder(pl.PlayerActor, new Order("Surrender", self, false))));
}
}
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
{
// if there is no real player associated, dont spawn it.
var ownerName = actorReference.Value.InitDict.Get<OwnerInit>().PlayerName;
if (!world.players.Values.Any(p => p.InternalName == ownerName))
if (!world.Players.Any(p => p.InternalName == ownerName))
continue;
var initDict = actorReference.Value.InitDict;

View File

@@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA
{
int total = 0;
foreach (var p in Self.World.players.Select(k => k.Value))
foreach (var p in Self.World.Players)
{
if (p == Self.Owner || (p.Stances[Self.Owner] == Stance.Ally && Self.Owner.Stances[p] == Stance.Ally))
{
@@ -195,7 +195,7 @@ namespace OpenRA.Mods.RA
public void Won()
{
// Player has won
foreach (var p in Self.World.players.Select(k => k.Value))
foreach (var p in Self.World.Players)
{
var cvc = p.PlayerActor.TraitOrDefault<ConquestVictoryConditions>();

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return true;
};
validPlayers = world.players.Values.Where(a => a != world.LocalPlayer && !a.NonCombatant).Count();
validPlayers = world.Players.Where(a => a != world.LocalPlayer && !a.NonCombatant).Count();
diplomacy.IsVisible = () => (validPlayers > 0);
}
@@ -79,13 +79,12 @@ namespace OpenRA.Mods.RA.Widgets.Logic
y += 35;
foreach (var p in world.players.Values.Where(a => a != world.LocalPlayer && !a.NonCombatant))
foreach (var p in world.Players.Where(a => a != world.LocalPlayer && !a.NonCombatant))
{
var pp = p;
var label = new LabelWidget
{
Bounds = new Rectangle(margin, y, labelWidth, 25),
Id = "DIPLOMACY_PLAYER_LABEL_{0}".F(p.Index),
Text = p.PlayerName,
Align = LabelWidget.TextAlign.Left,
Font = "Bold",
@@ -97,7 +96,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var theirStance = new LabelWidget
{
Bounds = new Rectangle( margin + labelWidth + 10, y, labelWidth, 25),
Id = "DIPLOMACY_PLAYER_LABEL_THEIR_{0}".F(p.Index),
Text = p.PlayerName,
Align = LabelWidget.TextAlign.Left,
@@ -110,7 +108,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var myStance = new DropDownButtonWidget
{
Bounds = new Rectangle( margin + 2 * labelWidth + 20, y, labelWidth, 25),
Id = "DIPLOMACY_PLAYER_LABEL_MY_{0}".F(p.Index),
GetText = () => world.LocalPlayer.Stances[ pp ].ToString(),
};
@@ -145,7 +142,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
return; // team changes are banned
world.IssueOrder(new Order("SetStance", world.LocalPlayer.PlayerActor,
false) { TargetLocation = new int2(p.Index, (int)ss) });
false) { TargetLocation = new int2((int)ss, 0), TargetString = p.InternalName });
bw.Text = ss.ToString();
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Widgets
if (!IsVisible()) return;
int2 offset = int2.Zero;
var svc = world.players.Select(p => p.Value.PlayerActor.TraitOrDefault<StrategicVictoryConditions>()).FirstOrDefault();
var svc = world.Players.Select(p => p.PlayerActor.TraitOrDefault<StrategicVictoryConditions>()).FirstOrDefault();
var totalWidth = (svc.Total + svc.TotalCritical) * 32;
int curX = -(totalWidth / 2);
@@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA.Widgets
int shortest = int.MaxValue;
Player shortestPlayer = null;
foreach (var p in world.players.Select(p => p.Value).Where(p => !p.NonCombatant))
foreach (var p in world.Players.Where(p => !p.NonCombatant))
{
var svc = p.PlayerActor.Trait<StrategicVictoryConditions>();