Resolve random players and spawn points in server replays.
This commit is contained in:
@@ -13,6 +13,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -24,14 +25,22 @@ namespace OpenRA.Mods.Common.Traits
|
||||
/// Returns a list of GameInformation.Players that matches the indexing of ICreatePlayers.CreatePlayers.
|
||||
/// Non-playable players appear as null in the list.
|
||||
/// </summary>
|
||||
void ICreatePlayersInfo.CreateServerPlayers(MapPreview map, Session lobbyInfo, List<GameInformation.Player> players)
|
||||
void ICreatePlayersInfo.CreateServerPlayers(MapPreview map, Session lobbyInfo, List<GameInformation.Player> players, MersenneTwister playerRandom)
|
||||
{
|
||||
var worldInfo = map.Rules.Actors["world"];
|
||||
var factions = worldInfo.TraitInfos<FactionInfo>().ToArray();
|
||||
var assignSpawnLocations = worldInfo.TraitInfoOrDefault<IAssignSpawnPointsInfo>();
|
||||
var spawnState = assignSpawnLocations?.InitializeState(map, lobbyInfo);
|
||||
|
||||
// Create the unplayable map players -- neutral, shellmap, scripted, etc.
|
||||
foreach (var p in map.Players.Players.Where(p => !p.Value.Playable))
|
||||
{
|
||||
// We need to resolve the faction, even though we don't use it, to match the RNG state with clients
|
||||
Player.ResolveFaction(p.Value.Faction, factions, playerRandom, false);
|
||||
players.Add(null);
|
||||
}
|
||||
|
||||
// Create the regular playable players.
|
||||
var factions = map.Rules.Actors["world"].TraitInfos<FactionInfo>().ToArray();
|
||||
var bots = map.Rules.Actors["player"].TraitInfos<IBotInfo>().ToArray();
|
||||
|
||||
foreach (var kv in lobbyInfo.Slots)
|
||||
@@ -41,19 +50,19 @@ namespace OpenRA.Mods.Common.Traits
|
||||
continue;
|
||||
|
||||
var clientFaction = factions.First(f => client.Faction == f.InternalName);
|
||||
|
||||
// TODO: Resolve random SpawnPoint and Faction to real values
|
||||
var resolvedFaction = Player.ResolveFaction(client.Faction, factions, playerRandom, !kv.Value.LockFaction);
|
||||
var resolvedSpawnPoint = assignSpawnLocations?.AssignSpawnPoint(spawnState, lobbyInfo, client, playerRandom) ?? 0;
|
||||
var player = new GameInformation.Player
|
||||
{
|
||||
ClientIndex = client.Index,
|
||||
Name = Player.ResolvePlayerName(client, lobbyInfo.Clients, bots),
|
||||
IsHuman = client.Bot == null,
|
||||
IsBot = client.Bot != null,
|
||||
FactionName = clientFaction.Name,
|
||||
FactionId = clientFaction.InternalName,
|
||||
FactionName = resolvedFaction.Name,
|
||||
FactionId = resolvedFaction.InternalName,
|
||||
Color = client.Color,
|
||||
Team = client.Team,
|
||||
SpawnPoint = client.SpawnPoint,
|
||||
SpawnPoint = resolvedSpawnPoint,
|
||||
IsRandomFaction = clientFaction.RandomFactionMembers.Any(),
|
||||
IsRandomSpawnPoint = client.SpawnPoint == 0,
|
||||
Fingerprint = client.Fingerprint,
|
||||
@@ -63,13 +72,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
// Create a player that is allied with everyone for shared observer shroud.
|
||||
// We need to resolve the faction, even though we don't use it, to match the RNG state with clients
|
||||
Player.ResolveFaction("Random", factions, playerRandom, false);
|
||||
players.Add(null);
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateMPPlayers : ICreatePlayers
|
||||
{
|
||||
void ICreatePlayers.CreatePlayers(World w)
|
||||
void ICreatePlayers.CreatePlayers(World w, MersenneTwister playerRandom)
|
||||
{
|
||||
var players = new MapPlayers(w.Map.PlayerDefinitions).Players;
|
||||
var worldPlayers = new List<Player>();
|
||||
@@ -78,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Create the unplayable map players -- neutral, shellmap, scripted, etc.
|
||||
foreach (var kv in players.Where(p => !p.Value.Playable))
|
||||
{
|
||||
var player = new Player(w, null, kv.Value);
|
||||
var player = new Player(w, null, kv.Value, playerRandom);
|
||||
worldPlayers.Add(player);
|
||||
|
||||
if (kv.Value.OwnsWorld)
|
||||
@@ -100,7 +111,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (client == null)
|
||||
continue;
|
||||
|
||||
var player = new Player(w, client, players[kv.Value.PlayerReference]);
|
||||
var player = new Player(w, client, players[kv.Value.PlayerReference], playerRandom);
|
||||
worldPlayers.Add(player);
|
||||
|
||||
if (client.Index == Game.LocalClientId)
|
||||
@@ -115,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Spectating = true,
|
||||
Faction = "Random",
|
||||
Allies = worldPlayers.Where(p => !p.NonCombatant && p.Playable).Select(p => p.InternalName).ToArray()
|
||||
}));
|
||||
}, playerRandom));
|
||||
|
||||
w.SetPlayers(worldPlayers, localPlayer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user