Added fully random spawn position option.

This commit is contained in:
Voidwalker
2018-06-03 10:51:51 +00:00
committed by Paul Chote
parent 1408fb74b2
commit 398ae75525
9 changed files with 56 additions and 11 deletions

View File

@@ -18,24 +18,65 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public class MPStartLocationsInfo : ITraitInfo [Desc("Allows the map to have working spawnpoints. Also controls the 'Separate Team Spawns' checkbox in the lobby options.")]
public class MPStartLocationsInfo : ITraitInfo, ILobbyOptions
{ {
public readonly WDist InitialExploreRange = WDist.FromCells(5); public readonly WDist InitialExploreRange = WDist.FromCells(5);
[Translate]
[Desc("Descriptive label for the spawn positions checkbox in the lobby.")]
public readonly string SeparateTeamSpawnsCheckboxLabel = "Separate Team Spawns";
[Translate]
[Desc("Tooltip description for the spawn positions checkbox in the lobby.")]
public readonly string SeparateTeamSpawnsCheckboxDescription = "Players without assigned spawn points will start as far as possible from enemy players.";
[Desc("Default value of the spawn positions checkbox in the lobby.")]
public readonly bool SeparateTeamSpawnsCheckboxEnabled = true;
[Desc("Prevent the spawn positions state from being changed in the lobby.")]
public readonly bool SeparateTeamSpawnsCheckboxLocked = false;
[Desc("Whether to display the spawn positions checkbox in the lobby.")]
public readonly bool SeparateTeamSpawnsCheckboxVisible = true;
[Desc("Display order for the spawn positions checkbox in the lobby.")]
public readonly int SeparateTeamSpawnsCheckboxDisplayOrder = 0;
public virtual object Create(ActorInitializer init) { return new MPStartLocations(this); } public virtual object Create(ActorInitializer init) { return new MPStartLocations(this); }
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
{
yield return new LobbyBooleanOption(
"randomspawnpositions",
SeparateTeamSpawnsCheckboxLabel,
SeparateTeamSpawnsCheckboxDescription,
SeparateTeamSpawnsCheckboxVisible,
SeparateTeamSpawnsCheckboxDisplayOrder,
SeparateTeamSpawnsCheckboxEnabled,
SeparateTeamSpawnsCheckboxLocked);
}
} }
public class MPStartLocations : IWorldLoaded public class MPStartLocations : IWorldLoaded, INotifyCreated
{ {
readonly MPStartLocationsInfo info; readonly MPStartLocationsInfo info;
public readonly Dictionary<Player, CPos> Start = new Dictionary<Player, CPos>(); public readonly Dictionary<Player, CPos> Start = new Dictionary<Player, CPos>();
bool separateTeamSpawns;
public MPStartLocations(MPStartLocationsInfo info) public MPStartLocations(MPStartLocationsInfo info)
{ {
this.info = info; this.info = info;
} }
void INotifyCreated.Created(Actor self)
{
separateTeamSpawns = self.World.LobbyInfo.GlobalSettings
.OptionOrDefault("separateteamspawns", info.SeparateTeamSpawnsCheckboxEnabled);
}
public void WorldLoaded(World world, WorldRenderer wr) public void WorldLoaded(World world, WorldRenderer wr)
{ {
var spawns = world.Actors.Where(a => a.Info.Name == "mpspawn") var spawns = world.Actors.Where(a => a.Info.Name == "mpspawn")
@@ -84,12 +125,12 @@ namespace OpenRA.Mods.Common.Traits
return world.Players.FirstOrDefault(p => p.PlayerReference.Name == pr); return world.Players.FirstOrDefault(p => p.PlayerReference.Name == pr);
} }
static CPos ChooseSpawnPoint(World world, List<CPos> available, List<CPos> taken) CPos ChooseSpawnPoint(World world, List<CPos> available, List<CPos> taken)
{ {
if (available.Count == 0) if (available.Count == 0)
throw new InvalidOperationException("No free spawnpoint."); throw new InvalidOperationException("No free spawnpoint.");
var n = taken.Count == 0 var n = taken.Count == 0 || !separateTeamSpawns
? world.SharedRandom.Next(available.Count) ? world.SharedRandom.Next(available.Count)
: available // pick the most distant spawnpoint from everyone else : available // pick the most distant spawnpoint from everyone else
.Select((k, i) => Pair.New(k, i)) .Select((k, i) => Pair.New(k, i))

View File

@@ -17,7 +17,7 @@ Player:
AllyRepair: AllyRepair:
PlayerResources: PlayerResources:
DeveloperMode: DeveloperMode:
CheckboxDisplayOrder: 7 CheckboxDisplayOrder: 8
BaseAttackNotifier: BaseAttackNotifier:
Shroud: Shroud:
FogCheckboxDisplayOrder: 3 FogCheckboxDisplayOrder: 3
@@ -26,7 +26,7 @@ Player:
Label: Redeployable MCVs Label: Redeployable MCVs
Description: Allow undeploying Construction Yard. Description: Allow undeploying Construction Yard.
Enabled: True Enabled: True
DisplayOrder: 6 DisplayOrder: 7
Prerequisites: global-factundeploy Prerequisites: global-factundeploy
PlayerStatistics: PlayerStatistics:
FrozenActorLayer: FrozenActorLayer:

View File

@@ -196,6 +196,7 @@ World:
TechLevelDropdownDisplayOrder: 2 TechLevelDropdownDisplayOrder: 2
GameSpeedDropdownDisplayOrder: 3 GameSpeedDropdownDisplayOrder: 3
MPStartLocations: MPStartLocations:
SeparateTeamSpawnsCheckboxDisplayOrder: 6
CreateMPPlayers: CreateMPPlayers:
MPStartUnits@mcvonly: MPStartUnits@mcvonly:
Class: none Class: none

View File

@@ -69,7 +69,7 @@ Player:
SelectableCash: 2500, 5000, 7000, 10000, 20000 SelectableCash: 2500, 5000, 7000, 10000, 20000
InsufficientFundsNotification: InsufficientFunds InsufficientFundsNotification: InsufficientFunds
DeveloperMode: DeveloperMode:
CheckboxDisplayOrder: 6 CheckboxDisplayOrder: 7
BaseAttackNotifier: BaseAttackNotifier:
Shroud: Shroud:
FogCheckboxDisplayOrder: 3 FogCheckboxDisplayOrder: 3

View File

@@ -167,6 +167,7 @@ World:
GameSpeedDropdownDisplayOrder: 3 GameSpeedDropdownDisplayOrder: 3
CreateMPPlayers: CreateMPPlayers:
MPStartLocations: MPStartLocations:
SeparateTeamSpawnsCheckboxDisplayOrder: 6
MPStartUnits@mcv: MPStartUnits@mcv:
Class: none Class: none
ClassName: MCV Only ClassName: MCV Only

View File

@@ -56,7 +56,7 @@ Player:
PlayerResources: PlayerResources:
InsufficientFundsNotification: InsufficientFunds InsufficientFundsNotification: InsufficientFunds
DeveloperMode: DeveloperMode:
CheckboxDisplayOrder: 8 CheckboxDisplayOrder: 9
GpsWatcher: GpsWatcher:
Shroud: Shroud:
FogCheckboxDisplayOrder: 3 FogCheckboxDisplayOrder: 3
@@ -65,7 +65,7 @@ Player:
Label: Kill Bounties Label: Kill Bounties
Description: Players receive cash bonuses when killing enemy units Description: Players receive cash bonuses when killing enemy units
Enabled: False Enabled: False
DisplayOrder: 6 DisplayOrder: 8
Prerequisites: global-bounty Prerequisites: global-bounty
LobbyPrerequisiteCheckbox@GLOBALFACTUNDEPLOY: LobbyPrerequisiteCheckbox@GLOBALFACTUNDEPLOY:
ID: factundeploy ID: factundeploy

View File

@@ -252,6 +252,7 @@ World:
InnerSupportRadius: 3 InnerSupportRadius: 3
OuterSupportRadius: 5 OuterSupportRadius: 5
MPStartLocations: MPStartLocations:
SeparateTeamSpawnsCheckboxDisplayOrder: 6
SpawnMPUnits: SpawnMPUnits:
DropdownDisplayOrder: 1 DropdownDisplayOrder: 1
PathFinder: PathFinder:

View File

@@ -61,7 +61,7 @@ Player:
InsufficientFundsNotification: InsufficientFunds InsufficientFundsNotification: InsufficientFunds
DeveloperMode: DeveloperMode:
CheckboxEnabled: true CheckboxEnabled: true
CheckboxDisplayOrder: 7 CheckboxDisplayOrder: 8
Shroud: Shroud:
FogCheckboxDisplayOrder: 3 FogCheckboxDisplayOrder: 3
LobbyPrerequisiteCheckbox@GLOBALFACTUNDEPLOY: LobbyPrerequisiteCheckbox@GLOBALFACTUNDEPLOY:
@@ -69,7 +69,7 @@ Player:
Label: Redeployable MCVs Label: Redeployable MCVs
Description: Allow undeploying Construction Yard. Description: Allow undeploying Construction Yard.
Enabled: True Enabled: True
DisplayOrder: 6 DisplayOrder: 7
Prerequisites: global-factundeploy Prerequisites: global-factundeploy
FrozenActorLayer: FrozenActorLayer:
BaseAttackNotifier: BaseAttackNotifier:

View File

@@ -346,6 +346,7 @@ World:
InnerSupportRadius: 3 InnerSupportRadius: 3
OuterSupportRadius: 5 OuterSupportRadius: 5
MPStartLocations: MPStartLocations:
SeparateTeamSpawnsCheckboxDisplayOrder: 6
SpawnMPUnits: SpawnMPUnits:
DropdownDisplayOrder: 1 DropdownDisplayOrder: 1
CrateSpawner: CrateSpawner: