Skip to content

Scenarios: no free starting units for players the scenario gives units - #63

Open
MortenLyhr wants to merge 1 commit into
bssth:masterfrom
MortenLyhr:fix/scenario-free-units
Open

MortenLyhr wants to merge 1 commit into
bssth:masterfrom
MortenLyhr:fix/scenario-free-units

Conversation

@MortenLyhr

@MortenLyhr MortenLyhr commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

When OpenCiv4 opens a World Builder scenario, every player got the free starting units on top of the scenario's own: startScenario called CvGame::setInitialItems before applyInitialItems placed the scenario's units, so CvGame::initFreeUnits (which skips players that have units or cities) found every player empty.

The original game gives none to a player the scenario gives units or cities. startScenario now runs the steps one by one: assignStartingPlots, normalizeStartingPlots, then the scenario's applyInitialItems (its techs, units, cities and gold), and only then initFreeUnits and the AI's found values. (Since #142 there is no initFreeState for a scenario.) A player the scenario leaves with only a starting plot still gets the free units.

A test scenario (Rome with 119 units and 4 cities, Ragnar with 2 units and a city), units at the start:

Rome Ragnar
Original (BtS 3.19 in Wine) 119 2
master 121 (+Settler, Warrior) 7 (+Settler, 2 Scouts, 2 Archers)
this PR 119 2

The same at Settler, Noble, Emperor and Deity (on master the extras grow with the difficulty: Ragnar 4 at Settler, 11 at Deity). With Ragnar's units and city taken out of the file, he gets the difficulty's free units as before (Noble 2, Emperor 5, Deity 9).

Checked:

  • ctest 15/15 (rebased on master 8b7d8557).
  • --turns 100 --map Fractal --size STANDARD --seed 7 checksums match master on every turn (random maps don't take this path).
  • New random-map games in the original and OpenCiv4 at Noble, Emperor and Deity give the same starting units, unique units included (Mali Skirmishers, Babylonian Bowmen).

🤖 Generated with Claude Code

…ithout 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 <noreply@anthropic.com>
@MortenLyhr
MortenLyhr force-pushed the fix/scenario-free-units branch from a803d93 to 4af271a Compare November 23, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant