Modding Civ I - tweaking random maps

darkpanda

Dark Prince
Joined
Oct 28, 2007
Messages
823
I spent quite some time analyzing how CIV.EXE generates random maps, and described the whole thing in this thread. Of course I could not help pushing it a step further :) So I started to patch the random map generation code in order to spice up the Civ experience a little bit.

This post aims to present several patches to the random map generation process, and will be updated from time to time as new ideas come up. Basically, almost any step of the processs can be patched, but I want to focus on patches that results in significant and interesting changes in the process behaviour.

1. Land mass hack: from Pangea to a thousand islands

This hack patches the land mass distribution, by modifying the maximum path length of random land chunks (see section A.1.1 of ]this post for algorithm details):
  • originally, Civ chooses a random value from 1 to 64 (included) as the maximum chunk length, which gives the results that we know
  • by decreasing this value, Civ will generate shorter chunks, tending to create many small separate islands; the extreme is to make Civ generate chunks of length just 1, resulting in a ton of tiny islands
  • by increasing this value, Civ will generate bigger chunks, tending to create a few large land masses; the extreme is to make Civ generate chunks of the maximum possible length 65535, resulting in 1 or 2 enormous continents

In order to change this value, you must patch your CIV.EXE as follows:
Code:
[color=red]Original[/color] hex chain an offsets:
         FR 47405: 0003618dh: 04 56 B8 [color=red]40 00[/color] 50 9A
  EN 47401 and 05: 00034d8dh: 04 56 B8 [color=red]40 00[/color] 50 9A

[color=blue][b]Patched[/b][/color] hex chain: 
         FR 47405: 0003618dh: 04 56 B8 [color=blue][b]xx xx[/b][/color] 50 9A
  EN 47401 and 05: 00034d8dh: 04 56 B8 [color=blue][b]xx xx[/b][/color] 50 9A
  
replace [color=blue][b]xx xx[/b][/color] above with the value of your choice written
as a little-endian hexadecimal 2-byte word; for example:
      1 = [color=blue][b]01 00[/b][/color]
     64 = [color=blue][b]40 00[/b][/color] (original CIV value)
  12345 = [color=blue][b]39 30[/b][/color]
  65535 = [color=blue][b]FF FF[/b][/color]

Hereunder are 2 screenshots illustrating maximum path lengths of 1 and 65535, when starting a new game with default parameters (1,1,1,1):





Using custom Earth parameters still affects the result, for example using "Small" land size with a big path length will result in a small single continent...

Enjoy !
 

Attachments

  • islands.gif
    islands.gif
    236.4 KB · Views: 884
  • pangea.gif
    pangea.gif
    211.5 KB · Views: 936
cool! wht is the thing with the Huts in the water? will you see them when you play or they would be huts if it was land mass there or?
 
Hahaha just noticed the starting points on the big landmass... the Aztecs got a very bad starting point, their second city could be good but the first one looks not good. I would say the Russians would be hard to beat, they got a lot of land to build on and Americans be locked in a corner... Enland got problem to get a second city with Russians so close unless they go south-west but they often build towards Human player direction.
 
Hi,
This is a geat patch. I should have had it years ago. Thanks for sharing it. Perhaps you have something on the on adjusting temperature, climate and planet age as well? Just asking. It would be great.

Nb
I benefitted a lot from your sve file layout. Thanks for that too.
 
Do you know what would be the correct value to obtain a land mass percentage identical to the one when playing on EARTH ? The usual value leaves too much sea for my taste but having several continents remains a good deal.
 
Do you know what would be the correct value to obtain a land mass percentage identical to the one when playing on EARTH ? The usual value leaves too much sea for my taste but having several continents remains a good deal.

Interestingly enough, the Earth map contains 1510 land squares (not counting the poles), all the while the maximum land squares you can get with custom earth is a little above 1280...

If you want Earth-like games then, you can't have them by changing the parameter I talked about in the first post. This parameter only changes the land shape, i.e. islands vs. pangea, but not the total number of squares.

In this thread, I explained how the limit is calculated:
3. Check whether land mass is sufficient

There is simple formula to verify whether the map contains enough squares compared to the land mass parameter:

Spawn/merge new random chunks while ( totalLandMass < ( ( landMassParam + 2 ) * 320 )

This land mass threshold has the following values for different values of the land mass parameter:
land mass param | minimum squares
0|640 squares
1|960 squares
2|1280 squares

In the CIV code, the loop condition is actually written as: totalLandMass < ( 640 + (landMassParam<<3)*40 )

You can then play with 3 parameters to modify the threshold:
  • the base offset 640: change it to 870, then when landMassParam is 2, the threshold becomes 870 + (2<<3)*40 = 870 + 640 = 1510, which is the land square count of Earth
  • the left-shift operand 3: change it to 4, then 3 different thresholds become: 640, 1280 and 1920, the latter one being above the Earth land count
  • the multiplier 40: change it to 55, then when landMassParam is 2, the threshold becomes 640 + (2<<3)*55 = 640 + 880 = 1520, which is close enough to the Earth land square count

The CIV.EXE code should be hacked as below:
Code:
offset:
  EN 47401: 0x3447E
  EN 47403: 0x33C7E
  EN 47404: 0x33C7E
  EN 47405: 0x3447E
  EN 47501: 0x3447E
  FR 47405: 0x3587E

original bytes: B1 [B][COLOR="Red"]03[/COLOR][/B] D3 E0 B9 [B][COLOR="Blue"]28 00[/COLOR][/B] F7 E9 05 [COLOR="green"][B]80 02[/B][/COLOR]

    [B][COLOR="Red"]03[/COLOR][/B]: left-shift operand
 [B][COLOR="Blue"]28 00[/COLOR][/B]: multiplier (0x0028 = 40)
 [COLOR="green"][B]80 02[/B][/COLOR]: base offset (0x0280 = 640)

Obviously, this can be combined with islands/pangea hack, although I didn't test it.
 
Thank you very much, but what are the new values I must write to obtain what I want ? :confused:

I suppose the 03 should be changed to 04, but for the two others, especially the 80 02, I have no clue about what to write. I must have missed something, but what ? :confused:
 
Thank you very much, but what are the new values I must write to obtain what I want ? :confused:

I suppose the 03 should be changed to 04, but for the two others, especially the 80 02, I have no clue about what to write. I must have missed something, but what ? :confused:

Either one of the 3 options will do the trick:
  • Change 03 to 04
  • Change 40 to 55; that is: replace 28 00 (0x28) with 37 00 (0x37)
  • Change 640 to 870; that is: replace 80 02 (0x280) with 66 03 (0x366)

Note: MS-DOS (as many Microsoft OS's) used to store data in little-endian format, so when your values take more than 1 byte, you have to reverse the order of bytes; e.g.: 870 = 0x366 becomes 66 03
 
Not to bring back an old topic, but, I was wondering what is the maximum number of squares that civ can handle? And, what would you change to get civ to generate it every time?
 
I suppose you mean "maximum number of land squares"?

You can create a map with JCivED, with land squares everywhere (and preferrably unbuildable land squares at the poles and on the "change of day" meridian (columns 0, 1, 78 and 79), and play it in CIV, see where it leads you.

I did it before, for other reasons, but I never played the full game, so I am not sure about the kind of issues or bugs that could appear with such landmass.

One way to attempt to make CIV generate it by itself, is by changing CIV.EXE as explained in the above posts, the easiest being the Option 1., replacing 640 with 2856 (in hex: 0x0B28, in CIV.EXE: 28 0B).

You're still at risk of having CIV.EXE loop forever at any point in the generation process, but you can test it if you like.
 
Hello, would it be possible to have the land types obey realistic climatic and geographical rules ? I mean it always bothered that you could get jungle/artic/tundra/hills/desert side by side virtually anywhere and seemingly at random, leading to absurdities like artic land near a jungle one, set at a latitude where both shouldn't exist, resulting sometime in junk continents which are of little to no use. :mad:

So what I would like (and possibly do) is:

- Types of land arranged according to latitude
- like on Earthn huge portions of plains/ prairies without hills not mountains.
-hills and mountains being logically arranged (as in, mountain and hills ranges. No more hill/plain/hill/plain/mountain/plain pattern making almost a whole continent useless).

The goal is to have maps as "earthlike" as possible without being our EARTH. The idea could be seen as having the current rules of Earth's climate but with landmasses of another era. For example, if the map generates a Pangea, heartland should mostly be desert, well humidified land should have forests/jungles, etc.
 
Well if you use jCivED, you can generate a map and then just change around the land types by hand. You can save different maps that you like, and then just use the program to change which map 'earth' refers to. Here's an easy link to the jCivED:
http://forums.civfanatics.com/showthread.php?t=486470

Besides that, not sure, darkpanda would surely know more about how maps are generated.
 
Well, several things to mention:

CIV's map generation algorithm is already fully deciphered, and everything is explained here: Civ1 Map generation explained
When I spent time deciphering the algorithm, I was quite pleasantly surprised by the logic behind it, which looks intended to generate a realistic "Earth".

This algorithm, being fully deciphered, was already fully ported to JCivED, in which you can generate random maps using the exact same logic as CIV. I extended it a little by allowing for different "land brushes" and "land distribution" to occur, but nothing more yet. Obviously, being fully ported to JCivED, it also makes it possible to be completely customized...

In addition, being fully deciphered/reverse-engineered from CIV.EXE, there is quite a lot of room for direct CIV.EXE hacking to implement your own map generation logic, if you want too... The thread linked above, that explained the Map generation process, is very closely following the implementation of the algorithm, so any step you'd wish to change could be hacked fairly easily, I guess.

Now, with everything said above, there are definitely ways to achieve what you want, so the main issue remains to explain your intended logic you want in full details, so that it can be implemented.
 
Thanks for answering. :)
So this is not impossible. Great ! :goodjob:

I think it would be more clear if I compare what I like/dislike between Earth/random maps.

What I like about Earth map:


1. large, homogenous areas of land squares of the same type :goodjob:
2. land squares roughly organized according to the climate of their latitude:
-> arctic/tundra
-> "taiga"
-> grassland/plains
-> desert
-> rainforest
-> desert again
-> if it was a random map with enough landmass in south hemisphere, would go the same grassland -> taiga -> tundra -> arctic
:)

3. Mountains and hills are limited to clearly defined areas. Hills are usually near mountains and organized with a pattern, some kind of progression : hills, then mountains. If hills are alone, there is generally a few. Japan is the only area with an isolated mountain. :)

4. (not figured) Continents are massive solid areas rather than small shredded ones. :goodjob:


What I dislike about random maps



Aside from the fact that they're smaller than the EARTH map (fixed thanks to Dark Panda :goodjob: )

1. isolated squares of lone terrains. good terrains surrounded by bad terrains ; one square of bad terrain ruining the profit of an area of good terrains, three mountains but no hills and they're not lined up like a mountain range, etc. :rolleyes:

2. Seemingly random position of hills and mountains resulting in almost unworkable areas which are only hills and mountains. Wouldn't be so annoying if they wasn't so big, often screwing up almost a whole continent. Overall, too much hills and mountains, even with the default parameters. :cry:

3. maybe the biggest no-no: jungles, jungles everywhere, even near artic area where it shouldn't be possible, messing with forest areas, set near artic and swamp lands, the three of them making big chunks of the continents useless. :eek:

4. (not pictured) too much swamps seemingly randomly situated :hmm:
Swamps must be near rivers (including near estuaries to the sea/a lake) and nowhere else. On the Earth map, there are only two squares of swamp, near the Nile. I'm not against more of them, but they have to be situated logically.


I think this pretty sums up what my dream random map would be : more logical. :yup:
I'd add that it isn't so much a question of quantity than of placement.

Hope this makes what i'd like more clear :salute:
 

Attachments

  • earthmap_likes_dislikes.jpg
    earthmap_likes_dislikes.jpg
    192.2 KB · Views: 691
  • pangea_likes_dislikes.png
    pangea_likes_dislikes.png
    404.3 KB · Views: 702
Oh thank you, you're such great guys ! :love: :bowdown:
Hope you'll have much fun designing this mod ! ;)
 
I hope by now...... you know that I was kidding. :) I have no knowledge of algorithms in the slightest. Anyways, see you around.
 
Top Bottom