Ticket #2798: autostart.diff
File autostart.diff, 5.8 KB (added by , 10 years ago) |
---|
-
source/ps/GameSetup/GameSetup.cpp
1276 1276 } 1277 1277 mapType = "random"; 1278 1278 } 1279 else if (mapDirectory == L"scenarios" )1279 else if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") 1280 1280 { 1281 1281 // Initialize general settings from the map data so some values 1282 1282 // (e.g. name of map) are always present, even when autostart is … … 1285 1285 // for example...) 1286 1286 CStr8 mapSettingsJSON = LoadSettingsOfScenarioMap("maps/" + autoStartName + ".xml"); 1287 1287 scriptInterface.ParseJSON(mapSettingsJSON, &settings); 1288 mapType = "scenario";1289 }1290 else if (mapDirectory == L"skirmishes")1291 {1292 // In skirmish mode, the player initialization data is taken from the1293 // game-setup settings (see CGame::RegisterInit(...)). If some player1294 // is not initialized (PlayerData[] holding fewer/more entries than1295 // defined in map), there's a crash.1296 // To prevent this, we mimic the behavior of the game setup screen by1297 // retrieving the map settings from the actual map xml...1298 CStr8 mapSettingsJSON = LoadSettingsOfScenarioMap("maps/" + autoStartName + ".xml");1299 scriptInterface.ParseJSON(mapSettingsJSON, &settings);1300 1288 1301 1289 // ...and initialize the playerData array being edited by 1302 1290 // autostart-civ et.al. with the real map data, so sensible values 1303 1291 // are always present: 1304 1292 scriptInterface.GetProperty(settings, "PlayerData", &playerData); 1305 mapType = "skirmish"; 1293 1294 if (mapDirectory == L"scenarios") 1295 mapType = "scenario"; 1296 else 1297 mapType = "skirmish"; 1306 1298 } 1299 1307 1300 if (mapType.empty()) 1308 1301 { 1309 1302 LOGERROR(L"Unrecognized map type '%ls' detected", mapType.c_str()); … … 1311 1304 } 1312 1305 scriptInterface.SetProperty(attrs, "mapType", mapType); 1313 1306 scriptInterface.SetProperty(attrs, "map", std::string("maps/" + autoStartName)); 1314 1315 1307 scriptInterface.SetProperty(settings, "mapType", mapType); 1316 1308 1317 1309 // Set player data for AIs … … 1321 1313 std::vector<CStr> aiArgs = args.GetMultiple("autostart-ai"); 1322 1314 for (size_t i = 0; i < aiArgs.size(); ++i) 1323 1315 { 1316 int playerID = aiArgs[i].BeforeFirst(":").ToInt(); 1317 1324 1318 // Instead of overwriting existing player data, modify the array 1325 1319 JS::RootedValue player(cx); 1326 if (!scriptInterface.GetPropertyInt(playerData, i, &player) || player.isUndefined())1320 if (!scriptInterface.GetPropertyInt(playerData, playerID-1, &player) || player.isUndefined()) 1327 1321 { 1322 if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") 1323 { 1324 // playerID is certainly bigger than this map player number 1325 LOGWARNING(L"Ai settings for player %d ignored.", playerID); 1326 continue; 1327 } 1328 1328 scriptInterface.Eval("({})", &player); 1329 1329 } 1330 1330 1331 int playerID = aiArgs[i].BeforeFirst(":").ToInt();1332 1331 CStr name = aiArgs[i].AfterFirst(":"); 1333 1334 1332 scriptInterface.SetProperty(player, "AI", std::string(name)); 1335 1333 scriptInterface.SetProperty(player, "AIDiff", 2); 1336 1334 scriptInterface.SetPropertyInt(playerData, playerID-1, player); … … 1342 1340 std::vector<CStr> civArgs = args.GetMultiple("autostart-aidiff"); 1343 1341 for (size_t i = 0; i < civArgs.size(); ++i) 1344 1342 { 1343 int playerID = civArgs[i].BeforeFirst(":").ToInt(); 1344 1345 1345 // Instead of overwriting existing player data, modify the array 1346 1346 JS::RootedValue player(cx); 1347 if (!scriptInterface.GetPropertyInt(playerData, i, &player) || player.isUndefined())1347 if (!scriptInterface.GetPropertyInt(playerData, playerID-1, &player) || player.isUndefined()) 1348 1348 { 1349 if (mapDirectory == L"scenarios" || mapDirectory == L"skirmishes") 1350 { 1351 // playerID is certainly bigger than this map player number 1352 LOGWARNING(L"Aidiff settings for player %d ignored.", playerID); 1353 continue; 1354 } 1349 1355 scriptInterface.Eval("({})", &player); 1350 1356 } 1351 1352 int playerID = civArgs[i].BeforeFirst(":").ToInt(); 1353 int difficulty = civArgs[i].AfterFirst(":").ToInt(); 1354 1357 1358 int difficulty = civArgs[i].AfterFirst(":").ToInt(); 1355 1359 scriptInterface.SetProperty(player, "AIDiff", difficulty); 1356 1360 scriptInterface.SetPropertyInt(playerData, playerID-1, player); 1357 1361 } … … 1359 1363 // Set player data for Civs 1360 1364 if (args.Has("autostart-civ")) 1361 1365 { 1362 std::vector<CStr> civArgs = args.GetMultiple("autostart-civ"); 1363 for (size_t i = 0; i < civArgs.size(); ++i) 1366 if (mapDirectory != L"scenarios") 1364 1367 { 1365 // Instead of overwriting existing player data, modify the array 1366 JS::RootedValue player(cx); 1367 if (!scriptInterface.GetPropertyInt(playerData, i, &player) || player.isUndefined()) 1368 std::vector<CStr> civArgs = args.GetMultiple("autostart-civ"); 1369 for (size_t i = 0; i < civArgs.size(); ++i) 1368 1370 { 1369 scriptInterface.Eval("({})", &player); 1371 int playerID = civArgs[i].BeforeFirst(":").ToInt(); 1372 1373 // Instead of overwriting existing player data, modify the array 1374 JS::RootedValue player(cx); 1375 if (!scriptInterface.GetPropertyInt(playerData, playerID-1, &player) || player.isUndefined()) 1376 { 1377 if (mapDirectory == L"skirmishes") 1378 { 1379 // playerID is certainly bigger than this map player number 1380 LOGWARNING(L"Civ settings for player %d ignored.", playerID); 1381 continue; 1382 } 1383 scriptInterface.Eval("({})", &player); 1384 } 1385 1386 CStr name = civArgs[i].AfterFirst(":"); 1387 scriptInterface.SetProperty(player, "Civ", std::string(name)); 1388 scriptInterface.SetPropertyInt(playerData, playerID-1, player); 1370 1389 } 1371 1372 int playerID = civArgs[i].BeforeFirst(":").ToInt();1373 CStr name = civArgs[i].AfterFirst(":");1374 1375 scriptInterface.SetProperty(player, "Civ", std::string(name));1376 scriptInterface.SetPropertyInt(playerData, playerID-1, player);1377 1390 } 1391 else 1392 LOGWARNING(L"For scenarios, autostart civs are ignored."); 1378 1393 } 1379 1394 1380 1395 // Add player data to map settings