[Guide] Adding a "regenerate map" feature.

DonQuiche

Emperor
Joined
May 23, 2011
Messages
1,122
Someone asked me about this topic in a PM since IGE provided me a good experience about map manipulation and I made this detailled answer. Unfortunately it won't be used but I thought it could interest some people, so I chose to make it public rather than go to waste, who knows...

EDIT: In the end I was wrong on one of my assumptions and such a feature was actually quite straightforward to achieve, see post #10.


So, the basic idea, would be to just recall the map generation script (seems possible) but it has a very difficult flaw: if you change the terrain to put water under a land unit (and vice-versa), the unit is destroyed. And if both the two units of a civ disappear, then it's dead. While it may be possible to resurrect a civ (there is a function for that I think, at least for city-states), if it's your civ, it's automatic game over. So basically it seems to not be a workable way. A few notes though:
  • The map script's filename can be gotten from PreGame.GetMapScript (not sure it works once the game has been started though - if it does not, this basic solution is hopeless). After that one may be able to use "include" or something like that to import it, then run it due to the interpreted nature of LUA.
  • The insta gameover is what I see when I manually use IGE. Maybe, if you do everything in a row and do not leave civ5 the chance to run its algorithms, you can avoid it but I doubt that.
  • You could add one warrior of every civ on every tile. Tow units of different civs can overlap, no problem. But units close to each other trigger diplomatic contact, you would reveal ruins (and trigger notifications, you would need to replace the standard notifications stack) and fog (but fog can be restored) and such, etc. See previous remark though: the triggers may not be event-driven but something civ5 only check once in a while, although I think it is unlikely. And you can also not put a warrior on *every* tile.
  • You could bet on the first and last rows of tiles to be always oceans, embark your units and spread them on those rows (units can be teleported without consuming movements points). Some maps won't work with that, though and there would be a problem with crowded maps.
As you can see, it *may* work or, more likely, it may work most of the times. But it's dirty and hard. Second solution, a perfectly reliable one, would be to write your custom map script. Or just slightly modify an existing map script: anytime a hex is going to be modified, embark/disembark units as need, move them to the neighbor tile (strangely enough, land units can be safely teleported on water and vice-versa), etc. It would work, you would not have to bother to get the map script used to generate the map, but the map would not be regenerated with the map script selected by the user. Besides, can Pregame be used after the game has been started to get the map generation parameters (humidity, etc)? If it does not, the only parameter you would respect would be the map size. Also, to make things perfect, you may actually have to change the map script in a larger way than what I said, to update fog and deal with ruins and such: same problems than the first solution but easier to deal with.

Third solution: all standard map scripts, and many custom map scripts, rely on a common file full of functions dedicated to map generation. Maybe you can use that to mix the first two solutions : use standard map scripts and just modify the common file to make units embark/move/etc before the hex modification.


Anyway, the first thing you may want to check is whether you can get the map script and run it. Whether it is possible or not, the first and third solutions may not be achievable at all. The second one, however, is 100% doable, I guarantee it, but it imposes a map script on the user and may ignore his settings.
 
There is one major flaw in any regenerate map solution and that is that the FOW on the mini-map is not updated until you save and reload the game
 
@whoward69
Indeed, but nothing prevents you to automatically save and reload (actually, there is something smelly with saves management, at least since a recent patch, I need to give a closer look).
And, well, it does not look like a "major" flaw anyway. I guess plenty of users would still be pretty happy with that. ;)
 
In game re-load (ie the option from the top right menu) also misbehaves - which is why a number of the "larger" mods (eg VEM) disable it - so that's not a viable solution.
 
See http://forums.civfanatics.com/showthread.php?t=442597 (and several other threads along similar lines) - technically it's not a "bug" but "unexpected behaviour" caused by the mods using features of Lua that the game designers never envisaged would be used in that way.
 
Thank you for clarifying it. Still a mod just has to not use global variables from what I understand. It may be mandatory for large mods who deeply change civ5's UI but I guess a map script can live with that (as IGE does for example).

mods using features of Lua that the game designers never envisaged would be used in that way
Sigh, this is the story of my modding experience with civ5. :(
 
Thank you for clarifying it. Still a mod just has to not use global variables from what I understand. It may be mandatory for large mods who deeply change civ5's UI but I guess a map script can live with that (as IGE does for example).

Except the nano-second after you post "Here is a regenerate map mod" someone *WILL* post "Can I use this with UP/VEM" - which makes any save/reload approach pointless/useless for clearing the MiniMap

Sigh, this is the story of my modding experience with civ5. :(

It's the story of *all* software development - as for every 1 clever person writing the base code, you have 100's, if not 1000's, of equally clever people trying to "bend" it.
 
Except the nano-second after you post "Here is a regenerate map mod" someone *WILL* post "Can I use this with UP/VEM" - which makes any save/reload approach pointless/useless for clearing the MiniMap.
Indeed.

It's the story of *all* software development - as for every 1 clever person writing the base code, you have 100's, if not 1000's, of equally clever people trying to "bend" it.
I've got to disagree: I never or rarely had such a strong feeling to work with a black box before. Not being able to read a documentation or look at the source code is very frustrating. ;)
 
I just released Reseed!, a mod that allows you to quickly regenerate the map in-game. Here are some technical details.

it has a very difficult flaw: if you change the terrain to put water under a land unit (and vice-versa), the unit is destroyed. And if both the two units of a civ disappear, then it's dead.
This was indeed the problem. But it can easily be overcame.

Maybe, if you do everything in a row and do not leave civ5 the chance to run its algorithms, you can avoid it but I doubt that.
This assumption was actually correct: civ5 unexpectedly decided to be nice. As long as you not give a chance to civ5 to render a frame, you can delete all units, regenerate the map then respawn new units, all of that without leaving a chance to civ5 to consider a civ is dead.
 
Back
Top Bottom