Fix map-player ctor.
This commit is contained in:
@@ -46,29 +46,34 @@ namespace OpenRA
|
|||||||
public ShroudRenderer Shroud;
|
public ShroudRenderer Shroud;
|
||||||
public World World { get; private set; }
|
public World World { get; private set; }
|
||||||
|
|
||||||
public Player( World world, Session.Client client )
|
public Player( World world, PlayerReference pr, int index )
|
||||||
{
|
{
|
||||||
World = world;
|
World = world;
|
||||||
Shroud = new ShroudRenderer(this, world.Map);
|
Shroud = new ShroudRenderer(this, world.Map);
|
||||||
|
|
||||||
PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this);
|
PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this);
|
||||||
|
|
||||||
if (client != null)
|
Index = index;
|
||||||
{
|
Palette = pr.Palette;
|
||||||
Index = client.Index;
|
Color = world.PlayerColors().Where(c => c.Name == pr.Palette).FirstOrDefault().Color;
|
||||||
Palette = world.PlayerColors()[client.PaletteIndex % world.PlayerColors().Count()].Name;
|
PlayerName = InternalName = pr.Name;
|
||||||
Color = world.PlayerColors()[client.PaletteIndex % world.PlayerColors().Count()].Color;
|
isSpecial = pr.isSpecial;
|
||||||
PlayerName = client.Name;
|
Country = world.GetCountries()
|
||||||
InternalName = "Multi{0}".F(client.Index);
|
.FirstOrDefault(c => pr.Race == c.Race);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
public Player( World world, Session.Client client )
|
||||||
Index = -1;
|
{
|
||||||
PlayerName = InternalName = "Neutral";
|
World = world;
|
||||||
Palette = "neutral";
|
Shroud = new ShroudRenderer(this, world.Map);
|
||||||
Color = Color.Gray; // HACK HACK
|
|
||||||
}
|
|
||||||
|
|
||||||
|
PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this);
|
||||||
|
|
||||||
|
Index = client.Index;
|
||||||
|
Palette = world.PlayerColors()[client.PaletteIndex % world.PlayerColors().Count()].Name;
|
||||||
|
Color = world.PlayerColors()[client.PaletteIndex % world.PlayerColors().Count()].Color;
|
||||||
|
PlayerName = client.Name;
|
||||||
|
InternalName = "Multi{0}".F(client.Index);
|
||||||
Country = world.GetCountries()
|
Country = world.GetCountries()
|
||||||
.FirstOrDefault(c => client != null && client.Country == c.Name)
|
.FirstOrDefault(c => client != null && client.Country == c.Name)
|
||||||
?? world.GetCountries().Random(world.SharedRandom);
|
?? world.GetCountries().Random(world.SharedRandom);
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index); }
|
bool PaletteAvailable(int index) { return Game.LobbyInfo.Clients.All(c => c.PaletteIndex != index) && Game.world.PlayerColors()[index % Game.world.PlayerColors().Count].Playable; }
|
||||||
bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
bool SpawnPointAvailable(int index) { return (index == 0) || Game.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
||||||
|
|
||||||
bool CyclePalette(MouseInput mi)
|
bool CyclePalette(MouseInput mi)
|
||||||
|
|||||||
@@ -94,20 +94,7 @@ namespace OpenRA
|
|||||||
int mapPlayerIndex = -1;
|
int mapPlayerIndex = -1;
|
||||||
foreach (var kv in Map.Players)
|
foreach (var kv in Map.Players)
|
||||||
{
|
{
|
||||||
var player = new Player(this, null);
|
var player = new Player(this, kv.Value, mapPlayerIndex--);
|
||||||
|
|
||||||
// Lets just pretend that i didn't do this.... Will fix later
|
|
||||||
player.GetType().GetField("Index").SetValue( player, mapPlayerIndex-- );
|
|
||||||
player.GetType().GetField("Palette").SetValue( player, kv.Value.Palette );// Todo: set Player.Color as well
|
|
||||||
player.GetType().GetField("PlayerName").SetValue( player, kv.Value.Name );
|
|
||||||
player.GetType().GetField("InternalName").SetValue( player, kv.Value.Name );
|
|
||||||
player.GetType().GetField("isSpecial").SetValue( player, kv.Value.isSpecial );
|
|
||||||
|
|
||||||
var country = WorldActor.Info.Traits.WithInterface<CountryInfo>().FirstOrDefault(c => kv.Value.Race == c.Race);
|
|
||||||
if (country == null)
|
|
||||||
throw new NotImplementedException("Invalid country: {0}".F(kv.Value.Race));
|
|
||||||
player.GetType().GetField("Country").SetValue( player, country);
|
|
||||||
|
|
||||||
AddPlayer(player);
|
AddPlayer(player);
|
||||||
|
|
||||||
if (kv.Value.OwnsWorld)
|
if (kv.Value.OwnsWorld)
|
||||||
|
|||||||
@@ -239,9 +239,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static List<PlayerColorPaletteInfo> PlayerColors(this World world)
|
public static List<PlayerColorPaletteInfo> PlayerColors(this World world)
|
||||||
{
|
{
|
||||||
return world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>()
|
return world.WorldActor.Info.Traits.WithInterface<PlayerColorPaletteInfo>().ToList();
|
||||||
.Where(p => p.Playable)
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user