Skip to content

Feature/random map mountains - #2016

Open
vader1986 wants to merge 11 commits into
Return-To-The-Roots:masterfrom
vader1986:feature/random-map-mountains
Open

vader1986 wants to merge 11 commits into
Return-To-The-Roots:masterfrom
vader1986:feature/random-map-mountains

Conversation

@vader1986

@vader1986 vader1986 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

A few visual improvements for the random map generator to fill out massive open land masses.

If not obvious, got a "little" help (Fable).

Related to #1530

image image image image image

@Flamefire

Copy link
Copy Markdown
Member

Can you describe what exactly is/should be changed/added by this PR?

@vader1986

Copy link
Copy Markdown
Contributor Author

Improve random map generation with additional terrain features

This PR enriches randomly generated maps by filling large, otherwise empty land areas with a variety of terrain features and special scenes.

Terrain generation

  • Mountains: Automatically fill large open land areas with mountain ranges. Their size gradually decreases as needed, while maintaining enough free space for building and keeping passages between areas accessible.
  • Desert hills: Add smooth, low hills with desert terrain and bones around their centres.
  • Swamps: Generate smaller, mostly flat swamp areas, with surrounding terrain smoothly sloping towards them.
  • Desert transitions: Ensure deserts are separated from lush terrain by steppe and savannah.
  • Special objects: Optionally populate buildable areas with themed scenes, including castle ruins, tower ruins, graveyards, camps and stone circles. Each scene gets a randomly selected layout.

New generator settings

Three sliders control how much of the available land is occupied by mountains, deserts and swamps. Their combined values determine how much open land is filled.

A separate checkbox enables or disables the generation of special scenes.

The default settings preserve sufficient free space for headquarters placement, while allowing players to adjust the amount and variety of terrain features to their liking.

Generation improvements

  • Keep islands and player starting areas on water maps untouched.
  • Avoid placing trees, stone piles, animals, fish and harbors in unsuitable terrain.
  • Blend special scenes naturally into their surroundings, with smooth terrain transitions.
  • Allow special scenes to adapt to obstacles instead of requiring a completely unobstructed area.
  • Ensure the generated terrain remains suitable for gameplay, including mining and harbor placement.

Tests

Add and adjust random map generation tests to cover terrain generation, available building space, special scenes and harbor placement.

Comment thread libs/s25main/mapGenerator/FreeLand.h Resolved
Flamefire
Flamefire previously approved these changes Nov 15, 2026

@Flamefire Flamefire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust your AI and your judgement of its output and just scrolled over the code.
A bit verbose docstrings and * @param rnd random number generator doesn't really add much additional context but nothing really stuck out.

We should really enforce our naming scheme more as documented at https://github.com/Return-To-The-Roots/s25client/wiki/Coding-conventions

Parameters, local variables, member functions: lowerCamelCase

we violate that already (historically) but such large AI-PRs make it worse.

So either we change our style (guide) or enforce it for new code at least.
I'd say a (larger) PR just renaming where we currently violate that would be best and with AI likely automat-able.
AI will then pick up the existing style for new code automatically.
Or we decide for UpperCamel member methods and update the code for that.
I'd really like to keep that for classes though which allows FooBarGen fooBarGen; to be unambiguous.
I can see an advantage of having UpperCamel member methods but lowerCamel free functions.
But foremost I'd like to have consistency to avoid confusion. @Flow86 your opinion on the direction for this?

@Flow86

Flow86 commented Nov 15, 2026

Copy link
Copy Markdown
Member

we should probably at least try to enforce it for new code.

lowerCamel free functions + methods make it more readable,
CamelCase classes allow it to use FooBarGen fooBarGen; which is great

@vader1986

Copy link
Copy Markdown
Contributor Author

Yeah fair enough, would actually be good to have that as part of the repo, so AI automatically picks up the correct coding style. Also not quite sure how to deal with large AI PRs either, I spent most time testing and trying to understand what it had done, rather than changing the output code. The comments are mostly AI slope, will rework that (or let it rework it)

Timm Hoffmeister and others added 8 commits November 16, 2026 20:31
Especially on large maps, random maps contain big empty areas. Repeatedly
start a new mountain at the node furthest away from water and mountains
until no node exceeds the free land to keep. Mountains shrink with each
iteration and keep a margin to obstacles, so passages stay open.

The free land to keep is based on the mountain distance setting, so it
remains possible to place headquarters at the desired distance.

Mountains are raised relative to the surrounding land and textured
directly to avoid cliffs. Textured nodes are treated as obstacles which
leaves islands (and player start positions on water maps) untouched.

See Return-To-The-Roots#1530

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new slider controls the minimum free land to keep. The default of
50% keeps the desired HQ distance to mountains available, 0% disables
additional mountains and higher values reduce the free land down to the
space required by headquarters.

See Return-To-The-Roots#1530

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Free land of random maps is no longer filled with mountains only. Each
area found by the mountain search becomes a mountain, a desert hill or a
swamp. The new "Desert" and "Swamp" sliders set the proportions together
with "Mountains", and the sum of the three controls how much free land is
filled. Types are assigned by a running budget so the proportions hold
even for a handful of areas, and the first area is always a mountain to
keep mines available.

- Desert hills are low, smooth hills of desert (wasteland or ice in the
  other landscapes) with bones around the center.
- Swamps (stony lava or ice floes) are flat and half the size of a
  mountain. Land above a swamp descends to it by one level per node at
  most, without lowering the banks of rivers or other landscapes.
- Deserts are always separated from lush land by steppe and savannah.
  This is applied after all other texturing as coast transitions may
  replace textures set before.
- Trees, stone piles, animals, fish and harbors keep away from deserts
  and swamps.

The new "Special Objects" checkbox places a few scenes on buildable
land, depending on the map size. A scene combines a theme (castle ruin,
tower ruin, graveyard, camp, stone circle) with a random layout
(overgrown patch, avenue, crag with pond, trail). The ground of a scene
blends into the land with one ring per transition texture, hills are
smooth and the scene stays free from random trees and stone piles.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The random distributions of the standard library differ between
platforms, so maps generated from a fixed seed differ as well. Three
tests only passed for the maps generated on macOS.

Special scenes required buildable land eight nodes around their center
which many maps don't provide: maps often ended up without any scene.
Now only the middle of a scene has to be free. Water, mountains, other
landscapes and objects in the outer part are left untouched and simply
cut the scene.

- Test the limit of free land with mountains only as the foot of desert
  hills is buildable and counts as free land.
- Check that flowers don't touch the surrounding meadow instead of
  relying on the size of the patch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Restore the single-line test context which a newer clang-format had
wrapped. The CI checks formatting with clang-format 10.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The random map test only checked harbors if the generated map contained
any, which left the check uncovered. Test the search for coastlines
directly with a lake and a swamp made of water instead.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Avoids copying the nodes into a second vector just for sorting, which
clang-tidy reported as inefficient vector operation.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- Use lowerCamelCase for all new functions and methods (free functions,
  RandomMap members, SceneBuilder methods) and the matching test names
- Use maxEnumValue/EnumArray for LandFill instead of numLandFills and a
  std::array indexed by casts
- Shorten docstrings and drop @PARAM lines that add no information

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J1xFd2ZsbRhtWeVV21cLbw
@vader1986

Copy link
Copy Markdown
Contributor Author

Updated the pr last night. Also asked it to apply convections to the entire mapGenerator module to keep it consistent

@Flamefire

Copy link
Copy Markdown
Member

#2018 was just merged which includes the contribution guide in the repo and updated the names of member methods.
This caused conflicts here although they should be reasonably easy to resolve.
Let us know if you need some help with that.

Resolve conflicts with the lowerCamelCase refactoring (Return-To-The-Roots#2018, Return-To-The-Roots#2019):
keep the swamp/desert/special-object changes of this branch and use the
renamed upstream API everywhere, including the new files that merged
without textual conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J1xFd2ZsbRhtWeVV21cLbw
@vader1986

Copy link
Copy Markdown
Contributor Author

All good, rebase was straight forward

@Flamefire
Flamefire enabled auto-merge November 18, 2026 08:44
@vader1986

Copy link
Copy Markdown
Contributor Author

Let me know if I need to do anything else. Otherwise, I'll just consider it done and wait for the merge :D

@Flamefire
Flamefire disabled auto-merge November 20, 2026 07:55
@Flamefire
Flamefire enabled auto-merge November 20, 2026 07:56
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.

3 participants