Skip to content

Great Wall: laid and drawn as the original does - #78

Open
MortenLyhr wants to merge 2 commits into
bssth:masterfrom
MortenLyhr:fix/great-wall
Open

MortenLyhr wants to merge 2 commits into
bssth:masterfrom
MortenLyhr:fix/great-wall

Conversation

@MortenLyhr

@MortenLyhr MortenLyhr commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The Great Wall on the map now follows the original engine's rules and look (backlog: the original doesn't wall the border towards the barbarian city in the test map; the wall looked much heavier than the original's).

How the rules were found. Scripted cases in the original game (Wine): the wonder built in different cities, borders grown afterwards, roads, territories joined by owned plots, rivers along the border into the sea, save and load. The original also keeps the wall it laid in its saves (its points and the plot corners they come from), which gave the exact geometry. All of it is observation of the running game and its save files.

Rules

  • The engine lays the wall once, when the game core calls AddGreatWall, along the borders as they are then (at its next update: a World Builder scenario sets the buildings before the borders follow). Later border changes, another AddGreatWall while a wall stands, and a save + load leave it as it was. (RemoveGreatWall is never reached in practice: CvCity counts the other border-obstacle buildings.)
  • Walled: the builder's territory joined to the wonder city, plots side by side (the owner's sea plots included), not the owner's other territories. Borders towards barbarians are walled.
  • The line starts south of the city, follows the border clockwise; an edge is walled when both its plots are land of the city's landmass (getAreaIdForGreatWall), so at the coast the loop opens into pieces.

Look

  • 15 points per plot edge, smoothed by a moving average of 15, then 5 (pieces repeat their end points): matches the original's saved points to 1e-4 plot. The wall runs on the border line with rounded corners.
  • One ART_GREAT_WALL_SEGMENT per step at 12/37 scale (it was drawn at scale 1: three times too big, five per plot edge, a post at every corner), a tower every 11th point and at a piece's end; heights smoothed along the line, segments tilted along the slope.

Saves. OpenCiv4 doesn't keep the wall in its saves. The original keeps its wall in its own section of the save, whose layout isn't fully known, so a block of OpenCiv4's own after the MD5 would make a format the original doesn't have. After a load, the wall is laid again for the city with the Great Wall, along the borders as they are then. The original's saves are handled the same way. So unlike the original, a load can move the wall onto borders that grew after it was first laid. Saves made with this PR's earlier version, which had a GWAL block after the MD5, still load: the block is ignored. (Changed 2026-11-23, after the review of #154.)

Pictures: Wine (original) | OpenCiv4, the OpenCiv4 side with #62's camera.

Case Wine (original) | OpenCiv4
Test map, Roma's wall: shape, corners, scale, over a peak
Backlog: no wall at Neapolis (its land doesn't touch Roma's)
Wonder built in Neapolis: the wall runs towards the barbarian camp
Same game: Roma (joined by road only) gets no wall
Wonder in coastal Antium, joined to Roma by a strip of plots
The strip
The wall runs on round Roma
River along the border into the sea (east): the wall ends at the coast with a tower
The same, west
A river crossing the border
Over a peak
Along a river
Border grown after the wall was laid: the wall stays
Then saved and loaded: the wall stays

OpenCiv4 alone, wall built, border grown, saved and loaded:
(These pictures are from the earlier version with the GWAL block. With this version a load lays the wall again along the borders as they are then; see Saves above.)

Built Grown Loaded

Before (master), for contrast: the old wall, heavy, with posts at every corner.

Checks: ctest 13/13; --turns 100 --map Fractal --size STANDARD --seed 7 checksums equal master on all 100 turns. No shader changes. After dropping the block: ctest 13/13 and D7D43800 at turn 100; a save with the old block loads and the wall is drawn after the load; the wall is also drawn with #154 merged (ctest 16/16). Host code calls only DllExport game-core functions.

🤖 Generated with Claude Code

The original engine lays the wall once, when the game core asks for it
(AddGreatWall), along the borders as they are then, and keeps it: later
border changes, another AddGreatWall while it stands, and a save and load
leave it as it was (its saves hold the wall's points). Observed in the
original game and read from its saves:

- Plots: the builder's territory joined to the city plot (plots side by
  side, the owner's sea plots too), not the owner's other territories. So
  a city whose land does not touch the builder's gets no wall; the border
  towards barbarians is walled.
- Line: from the city south to the territory's last plot, its south edge
  heading west, then round with the territory on the right, turning right
  first. An edge is walled when both its plots are land of the city's
  landmass (getAreaIdForGreatWall); at the coast the loop opens into pieces.
- Points: 15 per plot edge, smoothed by a moving average of 15 then of 5
  (pieces repeat their ends): corners rounded, the line on the border.
- Pieces: a segment per step at 12/37 scale (it was 1: three times too
  big), a tower every 11th point and at a piece's end; heights smoothed
  along the line and segments tilted along it.

OpenCiv4 keeps the wall with its saves (a block after the MD5); a save
without one (the original's) gets the wall laid along its borders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The save kept the wall as laid in a 'GWAL' block after the MD5 string,
which the original's format doesn't have (the original keeps its wall in
its own section of the save). Saves no longer write or read it; after a
load the wall is laid again for the city with the wonder, along the
borders as they are then, as for the original's saves. Saves that have
the block still load (the reader stops at the MD5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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