Rewrite spawn point assignment logic.

This commit is contained in:
Paul Chote
2020-10-13 19:17:25 +01:00
committed by teinarss
parent b2b639434c
commit a375f0e58a
9 changed files with 101 additions and 72 deletions

View File

@@ -122,7 +122,7 @@ namespace OpenRA
Team = client.Team,
SpawnPoint = runtimePlayer.SpawnPoint,
IsRandomFaction = runtimePlayer.Faction.InternalName != client.Faction,
IsRandomSpawnPoint = runtimePlayer.SpawnPoint != client.SpawnPoint,
IsRandomSpawnPoint = runtimePlayer.DisplaySpawnPoint == 0,
Fingerprint = client.Fingerprint
};

View File

@@ -32,7 +32,19 @@ namespace OpenRA
public bool LockColor = false;
public Color Color = Game.ModData.Manifest.Get<DefaultPlayer>().Color;
/// <summary>
/// Sets the "Home" location, which can be used by traits and scripts to e.g. set the initial camera
/// location or choose the map edge for reinforcements.
/// This will usually be overridden for client (lobby slot) players with a location based on the Spawn index
/// </summary>
public CPos HomeLocation = CPos.Zero;
public bool LockSpawn = false;
/// <summary>
/// Sets the initial spawn point index that is used to override the "Home" location for client (lobby slot) players.
/// Map players always ignore this and use HomeLocation directly.
/// </summary>
public int Spawn = 0;
public bool LockTeam = false;

View File

@@ -56,6 +56,7 @@ namespace OpenRA
public readonly bool NonCombatant = false;
public readonly bool Playable = true;
public readonly int ClientIndex;
public readonly CPos HomeLocation;
public readonly PlayerReference PlayerReference;
public readonly bool IsBot;
public readonly string BotType;
@@ -65,8 +66,13 @@ namespace OpenRA
/// <summary>The faction (including Random, etc) that was selected in the lobby.</summary>
public readonly FactionInfo DisplayFaction;
/// <summary>The spawn point index that was assigned for client-based players.</summary>
public readonly int SpawnPoint;
/// <summary>The spawn point index (including 0 for Random) that was selected in the lobby for client-based players.</summary>
public readonly int DisplaySpawnPoint;
public WinState WinState = WinState.Undefined;
public int SpawnPoint;
public bool HasObjectives = false;
public bool Spectating;
@@ -153,6 +159,11 @@ namespace OpenRA
BotType = client.Bot;
Faction = ChooseFaction(world, client.Faction, !pr.LockFaction);
DisplayFaction = ChooseDisplayFaction(world, client.Faction);
var assignSpawnPoints = world.WorldActor.TraitOrDefault<IAssignSpawnPoints>();
HomeLocation = assignSpawnPoints?.AssignHomeLocation(world, client) ?? pr.HomeLocation;
SpawnPoint = assignSpawnPoints?.SpawnPointForPlayer(this) ?? client.SpawnPoint;
DisplaySpawnPoint = client.SpawnPoint;
}
else
{
@@ -166,6 +177,8 @@ namespace OpenRA
BotType = pr.Bot;
Faction = ChooseFaction(world, pr.Faction, false);
DisplayFaction = ChooseDisplayFaction(world, pr.Faction);
HomeLocation = pr.HomeLocation;
SpawnPoint = DisplaySpawnPoint = 0;
}
if (!Spectating)

View File

@@ -373,6 +373,13 @@ namespace OpenRA.Traits
void CreateServerPlayers(MapPreview map, Session lobbyInfo, List<GameInformation.Player> players);
}
[RequireExplicitImplementation]
public interface IAssignSpawnPoints
{
CPos AssignHomeLocation(World world, Session.Client client);
int SpawnPointForPlayer(Player player);
}
public interface IBotInfo : ITraitInfoInterface
{
string Type { get; }

View File

@@ -314,6 +314,7 @@ namespace OpenRA
using (new PerfTimer(iwl.GetType().Name + ".WorldLoaded"))
iwl.WorldLoaded(this, wr);
var assignSpawnLocations = WorldActor.TraitOrDefault<IAssignSpawnPoints>();
gameInfo.StartTimeUtc = DateTime.UtcNow;
foreach (var player in Players)
gameInfo.AddPlayer(player, OrderManager.LobbyInfo);