Skip to content

Stacks: the plot shows the unit the game core puts at its centre - #152

Open
MortenLyhr wants to merge 1 commit into
bssth:masterfrom
MortenLyhr:fix/stack-center-unit
Open

MortenLyhr wants to merge 1 commit into
bssth:masterfrom
MortenLyhr:fix/stack-center-unit

Conversation

@MortenLyhr

@MortenLyhr MortenLyhr commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A plot with several units drew the first unit of the plot's own domain. So a selected settler standing with a warrior, or a selected work boat in a city, stayed hidden behind the other unit, and only the unit bar showed what was selected.

The original draws the plot's centre unit, which the game core picks in CvPlot::updateCenterUnit:

  1. the first selected unit on the plot;
  2. else the active player's best defender that can still move, then any of its own;
  3. else the best defender against the active player (at war with it, then any), with the head selected unit as the attacker, then without it.

In OpenCiv4 that function returns at once, because the host keeps the graphics flag off. So MapCapture now follows the same order itself, through the exported CvPlot::getBestDefender. The special cases stay as they were: a unit in a fight, a plane flying a mission, a unit intercepting.

The stack's other units now travel with the shown one in the snapshot (UnitView::hidden: owner, id, resting). When one of them becomes the shown unit (a click in the unit bar, W), it stands on its plot, fortified if it is. Before, it walked in from wherever it was last drawn.

The original (Wine)

The kit's testgames/shots/stacks/ scripts (views-stacks.txt) build a small coast with a stack in each case and select one unit per view:

View Selected Drawn in the original
st-none nothing warrior over settler (flat and forest hill), warrior over work boat in the city, spearman of six, the enemy's spearman, the galley
st-settler settler under a warrior the settler
st-cycle then the warrior (unit bar) the warrior
st-hill settler on a forest hill the settler
st-boat work boat in a coastal city the work boat
st-citywarrior warrior in that city the warrior
st-mixed worker in a stack of six the worker
st-galley galley carrying two warriors the galley
st-cargo one of its warriors the warriors, standing on the sea; no galley

Checks

  • macOS build (Release), ctest 15/15 passed (rebased on master 8b7d8557).
  • Sync checksums --turns 100 --map Fractal --size STANDARD --seed 7 at turn 100: D7D43800, equal to master's.
  • On the play branch (merged with the other open fixes): ctest 23/23, checksums D7D43800.
  • Only DllExport calls from the host (getBestDefender, getHeadSelectedUnit through the host's own interface).

Not in this PR

  • The round button bubble the original puts over a selected unit at sea; to come in a separate PR.

Pictures

Each picture is the original (Wine) on the left and OpenCiv4 after this PR on the right. The before | after pictures are OpenCiv4 alone.

The settler is selected under a warrior:
Wine | after
before | after

The settler on a forest hill:
Wine | after
before | after

A work boat in a coastal city:
Wine | after
before | after

The warrior is chosen from the unit bar:
Wine | after

A worker in a stack of six:
Wine | after

Nothing selected:
Wine | after

The galley, and one of its warriors (see Left):
Wine | after
Wine | after

Left

  • In the cargo view OpenCiv4 ends with the galley selected. That is likely the test script, not the game: each OpenCiv4 view loads the game fresh, and its start-of-turn cycling picks the galley.

🤖 Generated with Claude Code

A plot with several units drew the first unit of the plot's own domain,
so a selected settler under a warrior, or a selected work boat in a
city, stayed hidden behind the other unit. The original draws the plot's
centre unit, which CvPlot::updateCenterUnit picks: the first selected
unit, else the active player's best defender that can still move, else
any of its own, else the best defender against the active player. That
function does nothing in the host (the graphics flag is off), so the
host now follows the same order with the exported getBestDefender.
Checked in Wine with a settler under a warrior (also on a forest hill),
a work boat and a warrior in a coastal city, a stack of six, an
enemy stack, and a galley with its cargo.

The stack's other units now travel with it in the snapshot
(UnitView::hidden): a unit that becomes the shown one, say by a click
in the unit bar, stands on the plot, fortified if it is, instead of
walking in from where it was last shown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MortenLyhr
MortenLyhr force-pushed the fix/stack-center-unit branch from 92985bd to fd5950a 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