Changeset View
Changeset View
Standalone View
Standalone View
source/ps/GameSetup/GameSetup.cpp
Show First 20 Lines • Show All 1,109 Lines • ▼ Show 20 Lines | const char *pathToSettings[] = | ||||
"Scenario", "ScriptSettings", "" // Path to JSON data in map | "Scenario", "ScriptSettings", "" // Path to JSON data in map | ||||
}; | }; | ||||
Status loadResult = mapFile.Load(g_VFS, mapPath); | Status loadResult = mapFile.Load(g_VFS, mapPath); | ||||
if (INFO::OK != loadResult) | if (INFO::OK != loadResult) | ||||
{ | { | ||||
LOGERROR("LoadSettingsOfScenarioMap: Unable to load map file '%s'", mapPath.string8()); | LOGERROR("LoadSettingsOfScenarioMap: Unable to load map file '%s'", mapPath.string8()); | ||||
throw PSERROR_Game_World_MapLoadFailed("Unable to load map file, check the path for typos."); | throw PSERROR_Game_World_MapLoadFailed("Unable to load map file, check the path for typos."); | ||||
elexis: here | |||||
} | } | ||||
XMBElement mapElement = mapFile.GetRoot(); | XMBElement mapElement = mapFile.GetRoot(); | ||||
// Select the ScriptSettings node in the map file... | // Select the ScriptSettings node in the map file... | ||||
for (int i = 0; pathToSettings[i][0]; ++i) | for (int i = 0; pathToSettings[i][0]; ++i) | ||||
{ | { | ||||
int childId = mapFile.GetElementID(pathToSettings[i]); | int childId = mapFile.GetElementID(pathToSettings[i]); | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if (!scriptData.isUndefined() && scriptInterface.GetProperty(scriptData, "settings", &settings)) | ||||
std::wstring scriptFile; | std::wstring scriptFile; | ||||
scriptInterface.GetProperty(settings, "Script", scriptFile); | scriptInterface.GetProperty(settings, "Script", scriptFile); | ||||
scriptInterface.SetProperty(attrs, "script", scriptFile); // RMS filename | scriptInterface.SetProperty(attrs, "script", scriptFile); // RMS filename | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// Problem with JSON file | // Problem with JSON file | ||||
LOGERROR("Autostart: Error reading random map script '%s'", utf8_from_wstring(scriptPath)); | LOGERROR("Autostart: Error reading random map script '%s'", utf8_from_wstring(scriptPath)); | ||||
throw PSERROR_Game_World_MapLoadFailed("Error reading random map script.\nCheck application log for details."); | throw PSERROR_Game_World_MapLoadFailed("Error reading random map script.\nCheck application log for details."); | ||||
elexisUnsubmitted Not Done Inline Actionsand here elexis: and here | |||||
} | } | ||||
// Get optional map size argument (default 192) | // Get optional map size argument (default 192) | ||||
uint mapSize = 192; | uint mapSize = 192; | ||||
if (args.Has("autostart-size")) | if (args.Has("autostart-size")) | ||||
{ | { | ||||
CStr size = args.Get("autostart-size"); | CStr size = args.Get("autostart-size"); | ||||
mapSize = size.ToUInt(); | mapSize = size.ToUInt(); | ||||
Show All 37 Lines | else if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") | ||||
if (mapDirectory == L"scenarios") | if (mapDirectory == L"scenarios") | ||||
mapType = "scenario"; | mapType = "scenario"; | ||||
else | else | ||||
mapType = "skirmish"; | mapType = "skirmish"; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
LOGERROR("Autostart: Unrecognized map type '%s'", utf8_from_wstring(mapDirectory)); | LOGERROR("Autostart: Unrecognized map type '%s'", utf8_from_wstring(mapDirectory)); | ||||
throw PSERROR_Game_World_MapLoadFailed("Unrecognized map type.\nConsult readme.txt for the currently supported types."); | throw PSERROR_Game_World_MapLoadFailed("Unrecognized map type.\nConsult readme.txt for the currently supported types."); | ||||
elexisUnsubmitted Not Done Inline Actionsand here elexis: and here | |||||
} | } | ||||
scriptInterface.SetProperty(attrs, "mapType", mapType); | scriptInterface.SetProperty(attrs, "mapType", mapType); | ||||
scriptInterface.SetProperty(attrs, "map", std::string("maps/" + autoStartName)); | scriptInterface.SetProperty(attrs, "map", std::string("maps/" + autoStartName)); | ||||
scriptInterface.SetProperty(settings, "mapType", mapType); | scriptInterface.SetProperty(settings, "mapType", mapType); | ||||
scriptInterface.SetProperty(settings, "CheatsEnabled", true); | scriptInterface.SetProperty(settings, "CheatsEnabled", true); | ||||
// The seed is used for both random map generation and simulation | // The seed is used for both random map generation and simulation | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | bool Autostart(const CmdLineArgs& args) | ||||
{ | { | ||||
std::vector<CStr> aiArgs = args.GetMultiple("autostart-ai"); | std::vector<CStr> aiArgs = args.GetMultiple("autostart-ai"); | ||||
for (size_t i = 0; i < aiArgs.size(); ++i) | for (size_t i = 0; i < aiArgs.size(); ++i) | ||||
{ | { | ||||
int playerID = aiArgs[i].BeforeFirst(":").ToInt(); | int playerID = aiArgs[i].BeforeFirst(":").ToInt(); | ||||
// Instead of overwriting existing player data, modify the array | // Instead of overwriting existing player data, modify the array | ||||
JS::RootedValue player(cx); | JS::RootedValue player(cx); | ||||
if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | ||||
elexisUnsubmitted Not Done Inline ActionsThis part extends the object elexis: This part extends the object | |||||
{ | { | ||||
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.Eval("({})", &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); | ||||
} | } | ||||
if (mapType == "random" && aiArgs.size() > 2 && !args.Has("autostart-players")) | |||||
elexisUnsubmitted Not Done Inline Actionslooks like 2 should have would have to be replaced with numPlayers, so we don't have to keep it in sync elexis: looks like `2` should have would have to be replaced with `numPlayers`, so we don't have to… | |||||
LOGERROR("Autostart: Random maps with more than 2 players need the autostart-players argument"); | |||||
elexisUnsubmitted Not Done Inline Actionsmore than 2 AI players elexis: `more than 2 AI players` | |||||
} | } | ||||
// Set AI difficulty | // Set AI difficulty | ||||
if (args.Has("autostart-aidiff")) | if (args.Has("autostart-aidiff")) | ||||
{ | { | ||||
std::vector<CStr> civArgs = args.GetMultiple("autostart-aidiff"); | std::vector<CStr> civArgs = args.GetMultiple("autostart-aidiff"); | ||||
for (size_t i = 0; i < civArgs.size(); ++i) | for (size_t i = 0; i < civArgs.size(); ++i) | ||||
{ | { | ||||
int playerID = civArgs[i].BeforeFirst(":").ToInt(); | int playerID = civArgs[i].BeforeFirst(":").ToInt(); | ||||
Show All 23 Lines | if (args.Has("autostart-civ")) | ||||
{ | { | ||||
std::vector<CStr> civArgs = args.GetMultiple("autostart-civ"); | std::vector<CStr> civArgs = args.GetMultiple("autostart-civ"); | ||||
for (size_t i = 0; i < civArgs.size(); ++i) | for (size_t i = 0; i < civArgs.size(); ++i) | ||||
{ | { | ||||
int playerID = civArgs[i].BeforeFirst(":").ToInt(); | int playerID = civArgs[i].BeforeFirst(":").ToInt(); | ||||
// Instead of overwriting existing player data, modify the array | // Instead of overwriting existing player data, modify the array | ||||
JS::RootedValue player(cx); | JS::RootedValue player(cx); | ||||
if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | if (!scriptInterface.GetPropertyInt(playerData, playerID-offset, &player) || player.isUndefined()) | ||||
elexisUnsubmitted Not Done Inline ActionsSo does this. elexis: So does this. | |||||
{ | { | ||||
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.Eval("({})", &player); | ||||
▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
here