Remove obsolete Player index cruft
This commit is contained in:
@@ -128,7 +128,7 @@ namespace OpenRA
|
||||
{
|
||||
if( player != null )
|
||||
return player;
|
||||
return world.players.Values.First( x => x.InternalName == PlayerName );
|
||||
return world.Players.First( x => x.InternalName == PlayerName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace OpenRA.Network
|
||||
/* todo: this is still a hack.
|
||||
* the cases we're trying to avoid are the extra players on the host's client -- Neutral, other MapPlayers,
|
||||
* bots,.. */
|
||||
return world.players.Values.FirstOrDefault(
|
||||
p => p.ClientIndex == c.Index && p.PlayerName == c.Name);
|
||||
return world.Players.FirstOrDefault(
|
||||
p => (p.ClientIndex == c.Index && p.PlayerRef.Playable && !p.IsBot));
|
||||
}
|
||||
|
||||
public static void ProcessOrder(OrderManager orderManager, World world, int clientId, Order order)
|
||||
@@ -151,8 +151,8 @@ namespace OpenRA.Network
|
||||
if (Game.orderManager.LobbyInfo.GlobalSettings.LockTeams)
|
||||
return;
|
||||
|
||||
var targetPlayer = order.Player.World.players[order.TargetLocation.X];
|
||||
var newStance = (Stance)order.TargetLocation.Y;
|
||||
var targetPlayer = order.Player.World.Players.FirstOrDefault(p => p.InternalName == order.TargetString);
|
||||
var newStance = (Stance)order.TargetLocation.X;
|
||||
|
||||
SetPlayerStance(world, order.Player, targetPlayer, newStance);
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace OpenRA
|
||||
public readonly string PlayerName;
|
||||
public readonly string InternalName;
|
||||
public readonly CountryInfo Country;
|
||||
public readonly int Index;
|
||||
public readonly bool NonCombatant = false;
|
||||
public readonly int ClientIndex;
|
||||
public readonly PlayerReference PlayerRef;
|
||||
@@ -40,10 +39,9 @@ namespace OpenRA
|
||||
public Shroud Shroud { get { return World.LocalShroud; }}
|
||||
public World World { get; private set; }
|
||||
|
||||
public Player(World world, Session.Client client, PlayerReference pr, int index)
|
||||
public Player(World world, Session.Client client, PlayerReference pr)
|
||||
{
|
||||
World = world;
|
||||
Index = index;
|
||||
InternalName = pr.Name;
|
||||
PlayerRef = pr;
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace OpenRA
|
||||
public static int hash_player( Player p )
|
||||
{
|
||||
if( p != null )
|
||||
return p.Index * 0x567;
|
||||
return (int)( p.PlayerActor.ActorID << 16 ) * 0x567;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
var anim = new Animation(RenderSimple.GetImage(building, Tileset), () => 0);
|
||||
anim.PlayRepeating("idle");
|
||||
yield return new Renderable(anim.Image, 0.5f * anim.Image.size * (1 - Scale), Palette ?? PlayerPalette + owner.Index, 0, Scale);
|
||||
yield return new Renderable(anim.Image, 0.5f * anim.Image.size * (1 - Scale), Palette ?? PlayerPalette + owner.InternalName, 0, Scale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace OpenRA.Traits
|
||||
Info = self.Info.Traits.Get<RenderSimpleInfo>();
|
||||
}
|
||||
|
||||
public string Palette(Player p) { return Info.Palette ?? Info.PlayerPalette + p.Index; }
|
||||
public string Palette(Player p) { return Info.Palette ?? Info.PlayerPalette + p.InternalName; }
|
||||
|
||||
public virtual IEnumerable<Renderable> Render(Actor self)
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public void InitPalette( WorldRenderer wr )
|
||||
{
|
||||
var paletteName = "{0}{1}".F( info.BaseName, owner.Index );
|
||||
var paletteName = "{0}{1}".F( info.BaseName, owner.InternalName );
|
||||
var newpal = new Palette(wr.GetPalette(info.BasePalette),
|
||||
new PlayerColorRemap(owner.ColorRamp, info.PaletteFormat));
|
||||
wr.AddPalette(paletteName, newpal);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Collections;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.FileFormats;
|
||||
@@ -35,21 +36,16 @@ namespace OpenRA
|
||||
|
||||
public XRandom SharedRandom;
|
||||
|
||||
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||
public readonly List<Player> Players = new List<Player>();
|
||||
|
||||
public void AddPlayer(Player p) { players[p.Index] = p; }
|
||||
|
||||
int localPlayerIndex = -999;
|
||||
public Player LocalPlayer
|
||||
{
|
||||
get { return players.ContainsKey(localPlayerIndex) ? players[localPlayerIndex] : null; }
|
||||
}
|
||||
public void AddPlayer(Player p) { Players.Add(p); }
|
||||
public Player LocalPlayer { get; private set; }
|
||||
public readonly Shroud LocalShroud;
|
||||
|
||||
public void SetLocalPlayer(int index)
|
||||
public void SetLocalPlayer(string pr)
|
||||
{
|
||||
if (!(orderManager.Connection is ReplayConnection))
|
||||
localPlayerIndex = index;
|
||||
LocalPlayer = Players.FirstOrDefault(p => p.InternalName == pr);
|
||||
}
|
||||
|
||||
public readonly Actor WorldActor;
|
||||
@@ -108,8 +104,8 @@ namespace OpenRA
|
||||
cmp.CreatePlayers(this);
|
||||
|
||||
// Set defaults for any unset stances
|
||||
foreach (var p in players.Values)
|
||||
foreach (var q in players.Values)
|
||||
foreach (var p in Players)
|
||||
foreach (var q in Players)
|
||||
if (!p.Stances.ContainsKey(q))
|
||||
p.Stances[q] = Stance.Neutral;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Cnc
|
||||
|
||||
public void WorldLoaded(World w)
|
||||
{
|
||||
Players = w.players.Values.ToDictionary(p => p.InternalName);
|
||||
Players = w.Players.ToDictionary(p => p.InternalName);
|
||||
Actors = w.WorldActor.Trait<SpawnMapActors>().Actors;
|
||||
var b = w.Map.Bounds;
|
||||
Game.MoveViewport(new int2(b.Left + b.Width/2, b.Top + b.Height/2));
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Cnc
|
||||
var td = new TypeDictionary
|
||||
{
|
||||
new LocationInit( self.Location ),
|
||||
new OwnerInit( self.World.players.Values.First(p => p.InternalName == Info.Owner) )
|
||||
new OwnerInit( self.World.Players.First(p => p.InternalName == Info.Owner) )
|
||||
};
|
||||
|
||||
if (self.HasTrait<IFacing>())
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
var itemTemplate = scrollpanel.GetWidget("PLAYER_TEMPLATE");
|
||||
scrollpanel.RemoveChildren();
|
||||
|
||||
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))
|
||||
{
|
||||
Player pp = p;
|
||||
var item = itemTemplate.Clone();
|
||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
var item = ScrollItemWidget.Setup(template,
|
||||
() => s == world.LocalPlayer.Stances[ pp ],
|
||||
() => world.IssueOrder(new Order("SetStance", world.LocalPlayer.PlayerActor, false)
|
||||
{ TargetLocation = new int2(pp.Index, (int)s) }));
|
||||
{ TargetLocation = new int2((int)s, 0), TargetString = pp.InternalName }));
|
||||
|
||||
item.GetWidget<LabelWidget>("LABEL").GetText = () => s.ToString();
|
||||
return item;
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
widget.GetWidget("PLAYER_WIDGETS").IsVisible = () => true;
|
||||
|
||||
var diplomacyButton = ingameRoot.GetWidget<ButtonWidget>("DIPLOMACY_BUTTON");
|
||||
var diplomacyAvailable = world.players.Values.Any(a => a != world.LocalPlayer && !a.NonCombatant);
|
||||
var diplomacyAvailable = world.Players.Any(a => a != world.LocalPlayer && !a.NonCombatant);
|
||||
diplomacyButton.IsDisabled = () => !diplomacyAvailable;
|
||||
diplomacyButton.OnClick = () =>
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>();
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user