From 4af271aeced5c1dcdcb765fd9cc44763143515c5 Mon Sep 17 00:00:00 2001 From: mortenlyhr Date: Thu, 19 Nov 2026 14:34:22 +0100 Subject: [PATCH] Scenarios: free starting units only for players the scenario leaves without units startScenario called CvGame::setInitialItems before the scenario's own units were placed, so CvGame::initFreeUnits (which skips players with units or cities) found every player empty and gave each the era's and difficulty's free units on top of the scenario's. Run the steps one by one, as the original does for a World Builder scenario: free state (techs, gold), starting plots, then the scenario's items (its units, cities and gold), and only then initFreeUnits. Co-Authored-By: Claude Opus 5.5 --- apps/oc4core/GameSession.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/oc4core/GameSession.cpp b/apps/oc4core/GameSession.cpp index b083979..e6563fd 100644 --- a/apps/oc4core/GameSession.cpp +++ b/apps/oc4core/GameSession.cpp @@ -439,15 +439,17 @@ namespace oc4::host player(p).init(static_cast(p)); game.initDiplomacy(); - // As the original engine plays a scenario: its map, its starting plots, the era's - // free units (where none are), then its own items. CvGame::setInitialItems without - // initFreeState: a scenario's teams have only the techs it lists (no civilization, - // handicap or era free techs) and its players the gold it gives them. + // As the original engine plays a scenario: its map, its starting plots, then the scenario's + // own items (units, cities, its gold), and only then free units, for players the scenario + // left without units or cities. No initFreeState: a scenario's teams have only the techs it + // lists (no civilization, handicap or era free techs). CvGame::setInitialItems would give + // free units before the scenario's are placed, so every player would get them. if (wb.attr("applyMapDesc")().cast() < 0) throw std::runtime_error("cannot apply the scenario's map"); wb.attr("getAssignedStartingPlots")(); game.assignStartingPlots(); game.normalizeStartingPlots(); + wb.attr("applyInitialItems")(); game.initFreeUnits(); // (CvPlayerAI::AI_updateFoundValues isn't exported: through its Python binding) if (!m_python.run("import CvPythonExtensions\n" @@ -457,7 +459,6 @@ namespace oc4::host " _gc.getPlayer(_p).AI_updateFoundValues(False)\n" "del _gc, _p\n")) throw std::runtime_error("CyPlayer.AI_updateFoundValues failed"); - wb.attr("applyInitialItems")(); game.initScoreCalculation(); game.setFinalInitialized(true); game.initEvents();