Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Player.js
/** | /** | ||||
* Used to create player entities prior to reading the rest of a map, | * Used to create player entities prior to reading the rest of a map, | ||||
* all other initialization must be done after loading map (terrain/entities). | * all other initialization must be done after loading map (terrain/entities). | ||||
* DO NOT use other components here, as they may fail unpredictably. | * DO NOT use other components here, as they may fail unpredictably. | ||||
* settings is the object containing settings for this map. | * settings is the object containing settings for this map. | ||||
* newPlayers if true will remove old player entities or add new ones until | * newPlayers if true will remove old player entities or add new ones until | ||||
* the new number of player entities is obtained | * the new number of player entities is obtained | ||||
* (used when loading a map or when Atlas changes the number of players). | * (used when loading a map or when Atlas changes the number of players). | ||||
*/ | */ | ||||
function LoadPlayerSettings(settings, newPlayers) | function LoadPlayerSettings(settings, newPlayers) | ||||
{ | { | ||||
var playerDefaults = Engine.ReadJSONFile("simulation/data/settings/player_defaults.json").PlayerData; | |||||
// Default settings | // Default settings | ||||
if (!settings) | if (!settings) | ||||
settings = {}; | settings = {}; | ||||
// Get default player data | |||||
var rawData = Engine.ReadJSONFile("settings/player_defaults.json"); | |||||
if (!(rawData && rawData.PlayerData)) | |||||
throw new Error("Player.js: Error reading player_defaults.json"); | |||||
wraitii: Is that file just always supposed to be present? | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsCertainly it cant be removed at this point and is relied upon by many places. elexis: Certainly it cant be removed at this point and is relied upon by many places.
if you ask me it… | |||||
// Add gaia to simplify iteration | // Add gaia to simplify iteration | ||||
if (settings.PlayerData && settings.PlayerData[0]) | if (settings.PlayerData && settings.PlayerData[0]) | ||||
settings.PlayerData.unshift(null); | settings.PlayerData.unshift(null); | ||||
var playerDefaults = rawData.PlayerData; | |||||
var playerData = settings.PlayerData; | var playerData = settings.PlayerData; | ||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); | var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); | ||||
var numPlayers = cmpPlayerManager.GetNumPlayers(); | var numPlayers = cmpPlayerManager.GetNumPlayers(); | ||||
var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||
// Remove existing players or add new ones | // Remove existing players or add new ones | ||||
if (newPlayers) | if (newPlayers) | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | else | ||||
if (i == j) | if (i == j) | ||||
cmpPlayer.SetAlly(j); | cmpPlayer.SetAlly(j); | ||||
else | else | ||||
cmpPlayer.SetEnemy(j); | cmpPlayer.SetEnemy(j); | ||||
} | } | ||||
cmpPlayer.SetTeam(myTeam === undefined ? -1 : myTeam); | cmpPlayer.SetTeam(myTeam === undefined ? -1 : myTeam); | ||||
} | } | ||||
// If formations explicitly defined, use that; otherwise use civ defaults | cmpPlayer.SetFormations( | ||||
var formations = getSetting(playerData, playerDefaults, i, "Formations"); | getSetting(playerData, playerDefaults, i, "Formations") || | ||||
if (formations !== undefined) | Engine.ReadJSONFile("simulation/data/civs/" + cmpPlayer.GetCiv() + ".json").Formations); | ||||
cmpPlayer.SetFormations(formations); | |||||
else | |||||
{ | |||||
var rawFormations = Engine.ReadCivJSONFile(cmpPlayer.GetCiv()+".json"); | |||||
if (!(rawFormations && rawFormations.Formations)) | |||||
throw new Error("Player.js: Error reading " + cmpPlayer.GetCiv() + ".json"); | |||||
cmpPlayer.SetFormations(rawFormations.Formations); | |||||
} | |||||
var startCam = getSetting(playerData, playerDefaults, i, "StartingCamera"); | var startCam = getSetting(playerData, playerDefaults, i, "StartingCamera"); | ||||
if (startCam !== undefined) | if (startCam !== undefined) | ||||
cmpPlayer.SetStartingCamera(startCam.Position, startCam.Rotation); | cmpPlayer.SetStartingCamera(startCam.Position, startCam.Rotation); | ||||
} | } | ||||
// NOTE: We need to do the team locking here, as otherwise | // NOTE: We need to do the team locking here, as otherwise | ||||
// SetTeam can't ally the players. | // SetTeam can't ally the players. | ||||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Is that file just always supposed to be present?