Skip to content

Civilization flags as the original's: unlit cloth, medallions, health bars, the minimap's banner (builds on #56) - #73

Closed
MortenLyhr wants to merge 8 commits into
bssth:masterfrom
MortenLyhr:fix/civ-flags
Closed

MortenLyhr wants to merge 8 commits into
bssth:masterfrom
MortenLyhr:fix/civ-flags

Conversation

@MortenLyhr

@MortenLyhr MortenLyhr commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #56 (go140point6's animated civilization flags): this branch merges #56 and adds six commits on top. Please merge #56 first; this PR's own changes are the last six commits (the last two regenerate the Metal/SPIR-V shaders and fix the Windows link).

What it changes

#56 draws the era's flag model with the civilization's emblem, waving, at the original's size. Compared with the original (Beyond the Sword under Wine, the same scenario), four things still differed:

  • Cloth colour. The flag NIFs use TFlagShader_2TPP (Shaders/FX/Civ4FlagDecal.fx), which takes no light: lerp(decal × PlayerColor01, PlayerColor02, decal.a) × base. Lit, the flags came out about a quarter darker and bluer. Flag cloth is now unlit (Renderer.cpp, CPU side only, no shader change).
  • Medallions. The dots over the flag are Art/Units/Flag/Medallions.nif/.kfm: one per unit on the plot (up to 7). Event code 10·n + state picks each medallion's row in Medallions.dds. As in the original, units not selected show white, and a selected unit shows green (not moved), yellow (moved, can go on) or red (cannot move). These replace Render animated civilization unit flags #56's stack-count number. The same NIF's winged promotion coin stays hidden.
  • Texture transforms. The medallions only pick the right row if Gamebryo's "Max" transform method works in 3ds Max's V-up texture space, so UvTransform::apply now flips V for method 1. U is unchanged: a ship's damage atlas still moves to the correct (lightly damaged) half, which I checked against the Privateer's KF and texture.
  • Health bars. The original draws a flat bar as a billboard over the unit. Its length is what the engine asks the DLL for: the unit's current strength × CvUnit::getHealthBarModifier() (HEALTH_BAR_WIDTH over twice the best land unit's strength). So it shrinks as the unit is hurt, and units without strength (settlers, workers) have none. Measured with hurt units in the original: green at 75 % and above, yellow from 66 % to 40 %, red at 33 % and below. I used two thirds and one third as the edges (67–74 % and 34–39 % weren't tested). It is the same thickness at every length and shows for every unit, selected or not. It's placed by UNIT_HEALTH_BILLBOARD_RADIUS/_Z/_SCALE and drawn in the scene, so units in front can hide it. The option is the original's GRAPHICOPTION_HEALTH_BARS (Options → Graphics → Show Health Bars, off by default), which OpenCiv4's profile already kept.
  • Banner by the minimap. addFlagWidgetGFC was a flat 2D drawing with a white emblem. It now draws the player's era flag model, waving, in both player colours (ModelView with the composed decal), as the original does. The 2D drawing stays as the fallback.
Before (#56; original left, OpenCiv4 right) After
A selected settler
One of every unit
A city's stack
Another player's units
Health bars (original left, OpenCiv4 right)
Swordsmen 100 %–25 %; units from Strength 5 to 40
A hurt unit selected; a hurt barbarian

The OpenCiv4 pictures were taken with #62 (camera tilt) and #63 applied, so the framing matches the original; neither is part of this branch.

Not done:

  • The original draws fewer figures of a hurt unit (3 Swordsmen at full health, 1 at 50 %); OpenCiv4 always draws them all.
  • The second flag when two players' units share a plot (FLAG_OFFSET2_*).

How it was checked

  • ctest passes: 14/14 (macOS, Release).
  • Game results unchanged: --turns 100 --map Fractal --size STANDARD --seed 7 gives the same checksum as master on every turn, ending at D7D43800.
  • Original saves still load: not affected (drawing only), not tested.
  • Compared with the original under Wine in 7 views of the test map (3 of them with hurt units), and played on macOS.

🤖 Generated with Claude Code

go140point6 and others added 6 commits November 16, 2026 18:17
# Conflicts:
#	apps/oc4core/MapCapture.cpp
#	apps/oc4core/MapCapture.h
TFlagShader takes no light: the player's colours times the cloth's base map.
Lit, the flags came out about a quarter darker and bluer than the original's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A ship's damage atlas moves along U by +0.5 to its lightly damaged left half
(unchanged); a flag's medallions move along V by -0.2 a row, up their strip
from its empty bottom row, which only works with V flipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Over each flag, a medallion for each unit on the plot (Art/Units/Flag/
  Medallions.kfm, up to 7): white, green/yellow/red for selected units by how
  they can move. The promotion coin in the same model stays hidden.
- Health bars as the original's billboards: HEALTH_BAR_WIDTH over the
  UNIT_HEALTH_BILLBOARD_SCALE fader long, behind the unit and above the ground
  (..._RADIUS, ..._Z), drawn in the scene so the figures hide part of it.
- The flag by the minimap is the player's era flag model, waving, its cloth
  in the player's two colours, instead of a flat picture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured in the original with hurt units (Swordsmen at 100 % to 10 %, units
from Strength 2 to 40): the bar's length is what the engine gets from the DLL,
the unit's current strength times CvUnit::getHealthBarModifier
(HEALTH_BAR_WIDTH over twice the best land unit's strength), so units without
strength have none. Green from two thirds of the hit points, yellow from a
third, red below; as thick at every length. It is a billboard: the _Z fader
moves it up the screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MortenLyhr and others added 2 commits November 19, 2026 21:50
The model shader's flag branch (from bssth#56) was not yet in the generated
shaders: tools/shaders/gen_msl.py and gen_spirv.py (glslang 16.6.0,
SPIRV-Tools v2026.4, as CI's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CvGame::getBestLandUnitCombat is not exported from the Windows DLL. The
exported CvUnit::getHealthBarModifier already divides by it: a modifier that
is not finite means there is no best land unit yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MortenLyhr

MortenLyhr commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Included in bundle 3/6, #147, merged there with its own commits and with its conflicts with the other open PRs resolved (the bundle PR lists them). Closing in favour of #147.

@MortenLyhr MortenLyhr closed this Nov 21, 2026
bssth pushed a commit that referenced this pull request Nov 23, 2026
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.

2 participants