Planet Simulator

What was your expected result?

The only thing that method does is turn deep water tiles into shallow water tiles. It's both for visual purposes, information purposes (knowing you're sailing or ported on a smallish inland sea), and it prevents atolls but promotes fish/luxury tiles.

Aright, thanks. I thought this line was shifting ocean tiles away from inland seas into oceans, effectively reducing both the size and likelihood of having inland seas.

My goal was to increase the probability of having large lakes and inland seas.
 
Is there a code I can add to randomize if its Pangaea or Continents ?
I have no Lua experience.


Thanks
 
Last edited:
I made this change in my version, with the idea of adding to the mystery element. However, I found I could usually tell pretty quickly which one i had got.

In routine GetMapScriptInfo add an entry for random to the map preset section:

Code:
                Values =
                {
                    "Continents",
                    "Pangaea",
                    "Random"
                },

Then change SimulateTectonics to look like this:

Code:
function SimulateTectonics(W,H,xWrap,yWrap)
    local Plates = 10+math.ceil(H*0.625)

    GeneratePlates(W,H,xWrap,yWrap,Plates)

    GenerateFaults()

    local shelf = Map.GetCustomOption(6)
    if shelf == 3 then
        shelf = 1 + Map.Rand(2, "Random Shelf - Planet Simulator");
    end
 
    if shelf == 1 then
        print("Generating Continents style map")
        CreateContinentalShelf(W,H)
    else
        print("Generating Pangea style map.")
        CreatePangealShelf(W,H)
    end

    GenerateElevations(W,H,xWrap,yWrap)

    return PlateMap
end
 
Thanks psparky.

One more question. For the continents map, is there any way to reduce the number of continents ? I don't like having one civ on a continent alone, very snowbally.

I have played with this code, but no luck.

function GenerateElevationMap(width,height,xWrap,yWrap)
--local twistMinFreq = 128/width * mc.twistMinFreq --0.001/128
--local twistMaxFreq = 128/width * mc.twistMaxFreq --0.002/128
--local twistVar = 128/width * mc.twistVar --0.002/128
 
Sorry, that's beyond my understanding. The authors might still see this though so you might get a response.

But yes, I agree that in terms of game balance, it's undesirable.
 
This map is the only one I use but I do have one pet peeve about it. The amount of desert tiles there are. I frequently spawn maps that have 3/4 of a continent just of desert. It wouldn't be so bad if there were actually RIVERS on the tiles but it's just barren. When AI settles on them it just cripples them. No way in hell I'm gonna settle on them.

Please, if there's a fix for this, please let me know! Perfect map otherwise.
 
@PapaRockett

Play around with these desert settings, depending on your map peference types. As you can see here ive lowered the desert tile amount.

function MapConstants:InitializeTemperature()
local temp = Map.GetCustomOption(2)
if temp == 4 then
temp = 1 + Map.Rand(3, "Random World Temperature Option - Planet Simulator");
end
if temp == 1 then --Cold
print("Setting cold world constants - Planet Simulator")
self.desertMinTemperature = 0.40
self.tundraTemperature = 0.35
self.snowTemperature = 0.29

self.treesMinTemperature = 0.30
self.jungleMinTemperature = 0.75

self.atollNorthLatitudeLimit = 42
self.atollSouthLatitudeLimit = -42
self.iceNorthLatitudeLimit = 60
self.iceSouthLatitudeLimit = -60
elseif temp == 3 then --Warm
print("Setting warm world constants - Planet Simulator")
self.desertMinTemperature = 0.32
self.tundraTemperature = 0.26
self.snowTemperature = 0.20

self.treesMinTemperature = 0.21
self.jungleMinTemperature = 0.60

self.atollNorthLatitudeLimit = 51
self.atollSouthLatitudeLimit = -51
self.iceNorthLatitudeLimit = 65
self.iceSouthLatitudeLimit = -65
else --Standard
print("Setting temperate world constants - Planet Simulator")
self.desertMinTemperature = 0.6 --Coldest absolute temperature allowed to be desert, plains if colder.
self.tundraTemperature = 0.25 --Absolute temperature below which is tundra.
self.snowTemperature = 0.1 --Absolute temperature below which is snow.






function MapConstants:InitializeRainfall()
local rain = Map.GetCustomOption(3)
if rain == 4 then
rain = 1 + Map.Rand(3, "Random World Rainfall Option - Planet Simulator");
end
if rain == 1 then --Arid
print("Setting arid world constants - Planet Simulator")
self.desertPercent = 0.33
self.plainsPercent = 0.55
self.zeroTreesPercent = 0.78
self.junglePercent = 0.94

self.riverPercent = 0.14
self.riverRainCheatFactor = 1.2
self.minRiverSize = 32
self.marshElevation = 0.04
elseif rain == 3 then --Wet
print("Setting wet world constants - Planet Simulator")
self.desertPercent = 0.20
self.plainsPercent = 0.45
self.zeroTreesPercent = 0.62
self.junglePercent = 0.80

self.riverPercent = 0.25
self.riverRainCheatFactor = 1.6
self.minRiverSize = 16
self.marshElevation = 0.10
else --Standard
print("Setting normal rainfall constants - Planet Simulator")
self.desertPercent = 0.25 --Percent of land that is below the desert rainfall threshold.
 
Thanks psparky.

One more question. For the continents map, is there any way to reduce the number of continents ? I don't like having one civ on a continent alone, very snowbally.

I have played with this code, but no luck.

function GenerateElevationMap(width,height,xWrap,yWrap)
--local twistMinFreq = 128/width * mc.twistMinFreq --0.001/128
--local twistMaxFreq = 128/width * mc.twistMaxFreq --0.002/128
--local twistVar = 128/width * mc.twistVar --0.002/128

It would take rewriting the CreateContinentalShelf(W,H) method to be able to control how many continents spawned. You'd need to add a landNeighbor check as seen in CreatePangealShelf(W,H) but it wouldn't be a simple copy and paste job. From the other side of preventing civs spawning on a continent alone, the script uses the game's default start placement and incorporating and modifying that is a nightmare.

The code you copied there is all commented out (the -- denotes comments) so it gets ignored. I highly recommend using Notepadd++ or a similar program to delve into Lua as it both highlights syntax and objects (variable, comments, etc.) and has a much more powerful Find feature
 
What would I have to tweak to make this script prefer to place hills next to mountains?
 
I've just found out about this mod today (using LL's version), does this work with multiplayer if everyone's using this script?
 
How would I create an mostly desert map, with low resources? Goal is the have a low level of units late game (slow computer), fighting over sparse resources. Figured desert is best way to reduce food and hammers. If anyone could give me the exact numbers to feed into the edit file I would appreciate that as I am horrible at configuring files. Awesome mod!
 
I've noticed that there are virtually no forests on plains (using standard settings). I think what there is is the result of a cleanup phase to avoid things like tundra next to desert. Does anyone have any idea about how to change it so that forests are more evenly split between grass and plains, as you get in most other maps?

Also, during my own investigations I came across the following code (I don't think it is directly related to problem above):

local treeModifier = (math.abs(mc.topLatitude/rainfallMap:GetLatitudeForY(y))/mc.topLatitude)^1/2

This looks like nonsense to me :confused:. I imagine the intention was to take the square root of the bracketed part, but it will actually raise it to the power 1, then divide by 2. Also, the expression in the brackets is basically abs(A/B)/A, which is just abs(1/B). I'm guessing this code is meant to make forests more or less likely as you move away from the equator, but it sure looks wrong :crazyeye: Kind of worrying thing to find in my favourite map script :eek:
 
I got an idea to look at it not as a bug, but as a feature - so we got jungles on plains and forest on grassland - do not know about realism, but it's quite fine for gameplay - choice is much more straightforward. :D
 
By the way the real problems I got with the script is:
1. One-tile rivers
2. Crap load of desert
3. Not balanced distribution on continents preset (last game there was 3 nations on one continent, 1 on the other, and 6 on the last one).

As I understand, it can be tweaked inside mod's settings, but I think it'll be much better, if standard settings were more suitable for a balanced game.
 
How would I create an mostly desert map, with low resources? Goal is the have a low level of units late game (slow computer), fighting over sparse resources. Figured desert is best way to reduce food and hammers. If anyone could give me the exact numbers to feed into the edit file I would appreciate that as I am horrible at configuring files. Awesome mod!
Raise desertPercent, lower desertMinTemperature, lower the other numbers for other terrain types and probably lower tree and jungle percentages to avoid them spawning on strange tiles.

I've noticed that there are virtually no forests on plains (using standard settings). I think what there is is the result of a cleanup phase to avoid things like tundra next to desert. Does anyone have any idea about how to change it so that forests are more evenly split between grass and plains, as you get in most other maps?

Also, during my own investigations I came across the following code (I don't think it is directly related to problem above):

local treeModifier = (math.abs(mc.topLatitude/rainfallMap:GetLatitudeForY(y))/mc.topLatitude)^1/2

This looks like nonsense to me :confused:. I imagine the intention was to take the square root of the bracketed part, but it will actually raise it to the power 1, then divide by 2. Also, the expression in the brackets is basically abs(A/B)/A, which is just abs(1/B). I'm guessing this code is meant to make forests more or less likely as you move away from the equator, but it sure looks wrong :crazyeye: Kind of worrying thing to find in my favourite map script :eek:
Forests and Grasslands are largely tied to rainfall amounts so clearing forest nets you grasslands the vast majority of the time. It would probably take reworking how they spawn entirely to get them to spawn on plains frequently. Jungles deforested typically have poor soil hence Jungle forces the tiles underneath to convert to plains (as is default in all Civ V maps).

Also, That math is top-tier work my friend. I don't recall writing it 4++ years ago, but it's doing it's job (keeping trees out of the snow band). And in Lua, the constant (1/2) is handled pre-compilation as it actually compiles on the fly. This isn't the only place int he scripte where I'm taking a root like this either. In other languages your observation may be correct.

By the way the real problems I got with the script is:
1. One-tile rivers
2. Crap load of desert
3. Not balanced distribution on continents preset (last game there was 3 nations on one continent, 1 on the other, and 6 on the last one).

As I understand, it can be tweaked inside mod's settings, but I think it'll be much better, if standard settings were more suitable for a balanced game.

1. One tile rivers should be rare/nonexistant (depends on map size possibly). Lowering riverRainCheatFactor and/or raising minRiverSize should reduce these. I also do not like these.
2. Deserts are good and the land totals for deserts are taken from Earth surface area totals IIRC. Lower them. :goodjob:
3. You'll have this. It's not particularly common but it's more common than the default scripts as getting an Australia/seperated India-sized continent is pretty likely. Unforturnately, AssingStartingPlots.lua is a four letter word around here and trying to write a new script to handle that would be a huge undertaking in and of itself (like 6k+ lines in Communitas Mapscript IIRC).
 
Last edited:
Forests and Grasslands are largely tied to rainfall amounts so clearing forest nets you grasslands the vast majority of the time. It would probably take reworking how they spawn entirely to get them to spawn on plains frequently. Jungles deforested typically have poor soil hence Jungle forces the tiles underneath to convert to plains (as is default in all Civ V maps).

Also, That math is top-tier work my friend. I don't recall writing it 4++ years ago, but it's doing it's job (keeping trees out of the snow band). And in Lua, the constant (1/2) is handled pre-compilation as it actually compiles on the fly. This isn't the only place int he scripte where I'm taking a root like this either. In other languages your observation may be correct.


Thank you for the reply! Regarding forests, from my reading of the code, I suspected that rainfall was the key and no easy change would be available. The reason I'm interested in this is not for the result of chopping a forest. I'm playing the popular Vox Populi mod which changes the way yields from forests are calculated so that it depends on the underlying terrain. A forest gives +1 production, so on grass it's 2F 1P while on plains it's 1F 2P. Having almost all forest on grass reduces the strategic element of deciding which to work and which to chop.

What I plan to try is to add an extra late pass that replaces the terrain under some the forests with plains and see how that looks. As I mentioned, overall this is my favourite map script so I'd like to make it better from a gameplay point of view, even at the cost of some realism.

With regard to the coding question, I've looked at the LUA manual and also tried an example and I believe you are incorrect. I also note that elsewhere (in this file at least) you use math.sqrt - there are no other examples of the x^1/2 code. It is true that compilers will usually evaluate constant expressions and subexpressions, but not in a way that changes the meaning. For example, if you write x*(3+5), most compilers would replace that with x*8. But if you write x*3+5 they cannot evaluate anything here without changing the meaning from (x*3)+5. In the actual case, the ^ operator has precedence so the meaning is (x^1)/2 - the compiler doesn't change that.

In any case, as you say, the code is working OK, but probably not as intended.
 
Putting this at the end of the Cleanup() function should do the trick:
Spoiler :
Code:
   for k = 1, #landTab do
        local i = landTab[k]
       local plot = Map.GetPlotByIndex(i)
       if plot:GetFeatureType() == featureForest then
           local roll = PWRandInt(1,100)
           if roll > 25 then
               plot:SetTerrainType(terrainPlains,true,true)
               table.insert(plainsTab,i)
               table.remove(grassTab,k)
           end
        end
    end
That's a 1 in 4 chance of forcing Plains under Forest. You could substitute in different logic. Also, it may or may not require more robust code to guarantee that the plot underneath is grass for the purposes of tracking. I'm not even sure where all I'm using those tables anymore but I do know they sped things up substantially so keeping them accurate is probably ideal.

I'm 100% sure that both the Lua compiler built-in to Civ V and the Lua-JIT compiler available here on CivFanatics both treat "1/2" (or any fraction containing integers or even constants) as a single entity. It creates a token for it (read makes it a secret variable/constant) and passes it to the C compiler running underneath Lua as a single floating point value. You can even test it with the string.format printout if you've got the Firetuner Lua console installed from the dev kit.
 
Thank you very much for the code, you're a top man! I'll be trying it soon.

I had already tried printing to the lua.log file to see the effect. I have a variable 'target' that I was already printing so I added target^1/2. I got 236 and 118, not 15.36...

I just tried using the firetuner with this example:

print((Game.GetActivePlayer()+9)^1/2)

which gave 4.5, not 3.
It seems there is something very odd (and somewhat troubling) going on if you get different results.:confused:
 
Top Bottom