Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/GameSetup/GameSetup.cpp
Show First 20 Lines • Show All 518 Lines • ▼ Show 20 Lines | |||||
void InitPsAutostart(bool networked, JS::HandleValue attrs) | void InitPsAutostart(bool networked, JS::HandleValue attrs) | ||||
{ | { | ||||
// The GUI has not been initialized yet, so use the simulation scriptinterface for this variable | // The GUI has not been initialized yet, so use the simulation scriptinterface for this variable | ||||
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue playerAssignments(cx); | JS::RootedValue playerAssignments(cx); | ||||
scriptInterface.Eval("({})", &playerAssignments); | scriptInterface.CreateObject(&playerAssignments); | ||||
if (!networked) | if (!networked) | ||||
{ | { | ||||
JS::RootedValue localPlayer(cx); | JS::RootedValue localPlayer(cx); | ||||
scriptInterface.Eval("({})", &localPlayer); | scriptInterface.CreateObject(&localPlayer, "player", g_Game->GetPlayerID()); | ||||
scriptInterface.SetProperty(localPlayer, "player", g_Game->GetPlayerID()); | |||||
scriptInterface.SetProperty(playerAssignments, "local", localPlayer); | scriptInterface.SetProperty(playerAssignments, "local", localPlayer); | ||||
} | } | ||||
JS::RootedValue sessionInitData(cx); | JS::RootedValue sessionInitData(cx); | ||||
scriptInterface.Eval("({})", &sessionInitData); | |||||
scriptInterface.SetProperty(sessionInitData, "attribs", attrs); | scriptInterface.CreateObject( | ||||
scriptInterface.SetProperty(sessionInitData, "playerAssignments", playerAssignments); | &sessionInitData, | ||||
"attribs", attrs, | |||||
"playerAssignments", playerAssignments); | |||||
InitPs(true, L"page_loading.xml", &scriptInterface, sessionInitData); | InitPs(true, L"page_loading.xml", &scriptInterface, sessionInitData); | ||||
} | } | ||||
static void InitInput() | static void InitInput() | ||||
{ | { | ||||
g_Joystick.Initialise(); | g_Joystick.Initialise(); | ||||
▲ Show 20 Lines • Show All 553 Lines • ▼ Show 20 Lines | if (!AutostartVisualReplay(args.Get("replay-visual")) && !Autostart(args)) | ||||
const bool setup_gui = ((flags & INIT_NO_GUI) == 0); | const bool setup_gui = ((flags & INIT_NO_GUI) == 0); | ||||
// We only want to display the splash screen at startup | // We only want to display the splash screen at startup | ||||
shared_ptr<ScriptInterface> scriptInterface = g_GUI->GetScriptInterface(); | shared_ptr<ScriptInterface> scriptInterface = g_GUI->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface->GetContext(); | JSContext* cx = scriptInterface->GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue data(cx); | JS::RootedValue data(cx); | ||||
if (g_GUI) | if (g_GUI) | ||||
{ | { | ||||
scriptInterface->Eval("({})", &data); | scriptInterface->CreateObject(&data); | ||||
scriptInterface->SetProperty(data, "isStartup", true); | scriptInterface->SetProperty(data, "isStartup", true); | ||||
if (!installedMods.empty()) | if (!installedMods.empty()) | ||||
scriptInterface->SetProperty(data, "installedMods", installedMods); | scriptInterface->SetProperty(data, "installedMods", installedMods); | ||||
} | } | ||||
InitPs(setup_gui, installedMods.empty() ? L"page_pregame.xml" : L"page_modmod.xml", g_GUI->GetScriptInterface().get(), data); | InitPs(setup_gui, installedMods.empty() ? L"page_pregame.xml" : L"page_modmod.xml", g_GUI->GetScriptInterface().get(), data); | ||||
} | } | ||||
} | } | ||||
catch (PSERROR_Game_World_MapLoadFailed& e) | catch (PSERROR_Game_World_MapLoadFailed& e) | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | bool Autostart(const CmdLineArgs& args) | ||||
const bool nonVisual = args.Has("autostart-nonvisual"); | const bool nonVisual = args.Has("autostart-nonvisual"); | ||||
g_Game = new CGame(nonVisual, !args.Has("autostart-disable-replay")); | g_Game = new CGame(nonVisual, !args.Has("autostart-disable-replay")); | ||||
ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue attrs(cx); | JS::RootedValue attrs(cx); | ||||
scriptInterface.Eval("({})", &attrs); | |||||
JS::RootedValue settings(cx); | JS::RootedValue settings(cx); | ||||
scriptInterface.Eval("({})", &settings); | |||||
JS::RootedValue playerData(cx); | JS::RootedValue playerData(cx); | ||||
scriptInterface.Eval("([])", &playerData); | |||||
scriptInterface.CreateObject(&attrs); | |||||
scriptInterface.CreateObject(&settings); | |||||
scriptInterface.CreateArray(&playerData); | |||||
// The directory in front of the actual map name indicates which type | // The directory in front of the actual map name indicates which type | ||||
// of map is being loaded. Drawback of this approach is the association | // of map is being loaded. Drawback of this approach is the association | ||||
// of map types and folders is hard-coded, but benefits are: | // of map types and folders is hard-coded, but benefits are: | ||||
// - No need to pass the map type via command line separately | // - No need to pass the map type via command line separately | ||||
// - Prevents mixing up of scenarios and skirmish maps to some degree | // - Prevents mixing up of scenarios and skirmish maps to some degree | ||||
Path mapPath = Path(autoStartName); | Path mapPath = Path(autoStartName); | ||||
std::wstring mapDirectory = mapPath.Parent().Filename().string(); | std::wstring mapDirectory = mapPath.Parent().Filename().string(); | ||||
Show All 36 Lines | if (args.Has("autostart-players")) | ||||
CStr num = args.Get("autostart-players"); | CStr num = args.Get("autostart-players"); | ||||
numPlayers = num.ToUInt(); | numPlayers = num.ToUInt(); | ||||
} | } | ||||
// Set up player data | // Set up player data | ||||
for (size_t i = 0; i < numPlayers; ++i) | for (size_t i = 0; i < numPlayers; ++i) | ||||
{ | { | ||||
JS::RootedValue player(cx); | JS::RootedValue player(cx); | ||||
scriptInterface.Eval("({})", &player); | |||||
// We could load player_defaults.json here, but that would complicate the logic | // We could load player_defaults.json here, but that would complicate the logic | ||||
// even more and autostart is only intended for developers anyway | // even more and autostart is only intended for developers anyway | ||||
scriptInterface.SetProperty(player, "Civ", std::string("athen")); | scriptInterface.CreateObject(&player, "Civ", std::string("athen")); | ||||
scriptInterface.SetPropertyInt(playerData, i, player); | scriptInterface.SetPropertyInt(playerData, i, player); | ||||
} | } | ||||
mapType = "random"; | mapType = "random"; | ||||
} | } | ||||
else if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") | else if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") | ||||
{ | { | ||||
// Initialize general settings from the map data so some values | // Initialize general settings from the map data so some values | ||||
// (e.g. name of map) are always present, even when autostart is | // (e.g. name of map) are always present, even when autostart is | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < civArgs.size(); ++i) | ||||
if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | ||||
{ | { | ||||
if (mapDirectory == L"skirmishes") | if (mapDirectory == L"skirmishes") | ||||
{ | { | ||||
// playerID is certainly bigger than this map player number | // playerID is certainly bigger than this map player number | ||||
LOGWARNING("Autostart: Invalid player %d in autostart-team option", playerID); | LOGWARNING("Autostart: Invalid player %d in autostart-team option", playerID); | ||||
continue; | continue; | ||||
} | } | ||||
scriptInterface.Eval("({})", &player); | scriptInterface.CreateObject(&player); | ||||
} | } | ||||
int teamID = civArgs[i].AfterFirst(":").ToInt() - 1; | int teamID = civArgs[i].AfterFirst(":").ToInt() - 1; | ||||
scriptInterface.SetProperty(player, "Team", teamID); | scriptInterface.SetProperty(player, "Team", teamID); | ||||
scriptInterface.SetPropertyInt(playerData, playerID-offset, player); | scriptInterface.SetPropertyInt(playerData, playerID-offset, player); | ||||
} | } | ||||
} | } | ||||
Show All 14 Lines | for (size_t i = 0; i < aiArgs.size(); ++i) | ||||
if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | ||||
{ | { | ||||
if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") | if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") | ||||
{ | { | ||||
// playerID is certainly bigger than this map player number | // playerID is certainly bigger than this map player number | ||||
LOGWARNING("Autostart: Invalid player %d in autostart-ai option", playerID); | LOGWARNING("Autostart: Invalid player %d in autostart-ai option", playerID); | ||||
continue; | continue; | ||||
} | } | ||||
scriptInterface.Eval("({})", &player); | scriptInterface.CreateObject(&player); | ||||
} | } | ||||
CStr name = aiArgs[i].AfterFirst(":"); | CStr name = aiArgs[i].AfterFirst(":"); | ||||
scriptInterface.SetProperty(player, "AI", std::string(name)); | scriptInterface.SetProperty(player, "AI", std::string(name)); | ||||
scriptInterface.SetProperty(player, "AIDiff", 3); | scriptInterface.SetProperty(player, "AIDiff", 3); | ||||
scriptInterface.SetProperty(player, "AIBehavior", std::string("balanced")); | scriptInterface.SetProperty(player, "AIBehavior", std::string("balanced")); | ||||
scriptInterface.SetPropertyInt(playerData, playerID-offset, player); | scriptInterface.SetPropertyInt(playerData, playerID-offset, player); | ||||
} | } | ||||
Show All 11 Lines | for (size_t i = 0; i < civArgs.size(); ++i) | ||||
if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | ||||
{ | { | ||||
if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") | if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") | ||||
{ | { | ||||
// playerID is certainly bigger than this map player number | // playerID is certainly bigger than this map player number | ||||
LOGWARNING("Autostart: Invalid player %d in autostart-aidiff option", playerID); | LOGWARNING("Autostart: Invalid player %d in autostart-aidiff option", playerID); | ||||
continue; | continue; | ||||
} | } | ||||
scriptInterface.Eval("({})", &player); | scriptInterface.CreateObject(&player); | ||||
} | } | ||||
int difficulty = civArgs[i].AfterFirst(":").ToInt(); | int difficulty = civArgs[i].AfterFirst(":").ToInt(); | ||||
scriptInterface.SetProperty(player, "AIDiff", difficulty); | scriptInterface.SetProperty(player, "AIDiff", difficulty); | ||||
scriptInterface.SetPropertyInt(playerData, playerID-offset, player); | scriptInterface.SetPropertyInt(playerData, playerID-offset, player); | ||||
} | } | ||||
} | } | ||||
// Set player data for Civs | // Set player data for Civs | ||||
Show All 11 Lines | if (mapDirectory != L"scenarios") | ||||
if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | ||||
{ | { | ||||
if (mapDirectory == L"skirmishes") | if (mapDirectory == L"skirmishes") | ||||
{ | { | ||||
// playerID is certainly bigger than this map player number | // playerID is certainly bigger than this map player number | ||||
LOGWARNING("Autostart: Invalid player %d in autostart-civ option", playerID); | LOGWARNING("Autostart: Invalid player %d in autostart-civ option", playerID); | ||||
continue; | continue; | ||||
} | } | ||||
scriptInterface.Eval("({})", &player); | scriptInterface.CreateObject(&player); | ||||
} | } | ||||
CStr name = civArgs[i].AfterFirst(":"); | CStr name = civArgs[i].AfterFirst(":"); | ||||
scriptInterface.SetProperty(player, "Civ", std::string(name)); | scriptInterface.SetProperty(player, "Civ", std::string(name)); | ||||
scriptInterface.SetPropertyInt(playerData, playerID-offset, player); | scriptInterface.SetPropertyInt(playerData, playerID-offset, player); | ||||
} | } | ||||
} | } | ||||
else | else | ||||
▲ Show 20 Lines • Show All 175 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator