Page 1 of 1

Lua map generators

Posted: Fri Oct 13, 2023 5:34 pm
by Elefant
The Lua API has most functions needed for a map gen script, so it would be nice to have the ability to write such scripts and select them in the geography tab of the new game menu.

Re: Lua map generators

Posted: Sat Oct 14, 2023 11:28 am
by Ignatus
Doubling! Actually, you can just generate any map and then edit the terrain with a script, and then turn the save into a scenario, but that is not very comfortable. We could just run a script on "map_generated" signal, but some API for starting points is needed (well, we could also run on start of the first turn and manipulate already placed units). A better solution would be actually replacing specific parts of map generation procedure with custom parts (e.g., define callbacks for creating or postprocessing height map, for selecting terrains etc.) with an ability to use binary functions for other parts.

Re: Lua map generators

Posted: Sun Oct 15, 2023 11:47 am
by Alien Valkyrie
Ignatus wrote: Sat Oct 14, 2023 11:28 am A better solution would be actually replacing specific parts of map generation procedure with custom parts (e.g., define callbacks for creating or postprocessing height map, for selecting terrains etc.) with an ability to use binary functions for other parts.
I'd be wary of things like that — anything we expose to scripts/ruleset is something that will be a lot more difficult to ever remove or majorly modify, since doing so would break compatibility. The map_generated signal we already have between generating terrain and placing initial units/cities already means that if we ever want a map generator that cheats a little by modifying terrain to make start positions better suited to each specific player and their specific starting units, it's not going to be easy. (Also, I don't know what happens if lua script makes sweeping changes at map_generated that end up invalidating previously selected start positions, but I don't expect it to be pretty.)
One could even imagine a generator that works completely backwards to what we currently have, deciding on players' starting positions first, then placing fitting starter terrain around those and building outward from there — this would make e.g. a script hook after height map but before terrain selection fundamentally nonsensical.
I'm not necessarily saying we can't do those things, but making things harder to decouple by codifying current implementation details into lasting parts of the interface is a risky endeavor.

What could be possible without that risk is the option to completely do all of map generation in lua script, just starting with an empty map made of one terrain type and calling a single script hook, which then gets left to place terrain, units, etc.

Re: Lua map generators

Posted: Sun Oct 15, 2023 2:43 pm
by Molo_Parko
Why not go at it the other way around: run a stand-alone lua script (or any executable form) to read Fc3 settings, generate the map based on user choices, save map as scenario file, and then launch Freeciv to play the scenario.

Re: Lua map generators

Posted: Sun Oct 15, 2023 9:31 pm
by Ignatus
Molo_Parko wrote: Sun Oct 15, 2023 2:43 pm Why not go at it the other way around: run a stand-alone lua script (or any executable form) to read Fc3 settings, generate the map based on user choices, save map as scenario file, and then launch Freeciv to play the scenario.
Cuz writing a new stangalone application requires extra doing something ;)