Resource Generation

Shadole

Warlord
Joined
Aug 7, 2015
Messages
116
Hey all,

I'm trying to figure out if resource generation is attached to expected map size. I looked at the resource generation in the maps directory but I can't make heads or tails of it.

I'm asking because I want to increase the size of huge maps to say, 180 x 112. With the default resource generation, will I end up with the same actual amount (not percentage!) of resources with the Huge default size of 106 X 66? If this is the case, then simply increasing map size is a poor solution to get bigger maps, as it will invite a scarcity of resources in bigger maps!

Or does the resource generation work proportionally and just fill up the land to the same percent based on what option you choose (standard, abundant, etc.)? If this is the case then it's ideal and we don't need any changes to resource generation :)

If it is indeed based on expected map size, and creating bigger maps results in scarcity of resources due to the game expecting the default size, what modifications to resource generation do we have to make to increase resource generation on larger maps?

This line of code seems to suggest at least some part of it is based on map size (defaultplayers*2, etc.) but I really have no clue.

function ResourceGenerator:__InitResourceData()

self.iResourcesInDB = 0;
self.iLuxuriesThisSizeMap = GameInfo.Maps[Map.GetMapSize()].DefaultPlayers * 2;

-- Get resource value setting input by user.
if self.resources == 1 then
self.resources = -5;
elseif self.resources == 3 then
self.resources = 5;
elseif self.resources == 5 then
self.resources = TerrainBuilder.GetRandomNumber(13, "Random Resources - Lua") - 6;
else
self.resources = 0;
end
 
So changing the multiplier in self.iLuxuriesThisSizeMap = GameInfo.Maps[Map.GetMapSize()].DefaultPlayers * 2 does not appear to change anything. I changed it to 10 and loaded a few maps and nothing seemed different about luxury AMOUNT distribution. I suspect this line may actually decide how many DIFFERENT luxuries there are...but going off of a Huge map, that equation equal 24 and there certainly aren't 24 luxury types. That line is the only instasce of that equation in the lua.

Gedemon pointed out in the map size thread that <frequency> tags seem to decide the distribution of other resources throughout the map. Most of these referance #plot, so it seems like the majority of resource generation is tied to how large map is, resulting in proportional resource generation for all map sizes (which is good!).

So the kicker is trying to figure out this self.iLuxuriesThisSizeMap business.
 
There are a fewlines to look at. Look for iTargetPercentage:
It'sused to generate iOccurencesPerFrequency based on #plots, that is, how many resources to put per continent.
It's also, well, extremely bad code.
Seriously, they declare self.iOccurencesPerFrequency = something different in several places. This means that the order in which you call methods matter. I wouldn't hire someone who writes code that bad. It is going to be a PITA to mod and maintain.
This means that you will have to change the number in a lot of different places because the same variable is used for different things at different places... Yuck.

They even put ";" all over the place!
This:
self:__ValidLuxuryPlots(eContinent); (line213)
is where the number is set. for luxuries.
Then go to __PlaceLuxuryResources:
After it's computed, you can multiply iNumToPlace by whatever factor you want.

Sorry, I would test and help but I can't realy look at the code any more. It screams for refactoring and I'd need a few hours to just clean all that.
 
Very interesting LDiCesare. Thank you for the insight. I hope someone skilled such as yourself will be able to improve it. Meanwhile, I did some rudimentary, tedious testing and figured some stuff out (also posted this in the Map Sizes thread):

Okay everyone, I've discovered a bit about resource generation for maps! Long story short, resource generation appears to keep up with customized increased map sizes! This is great news, because IIRC it wasn't the case in Civ 5, where increased map sizes resulted in pretty barren land.

Methods: I tested on Pangaea only, low water, abundant resources. I tested duel, huge, and a customized huge (141 x 88). Disclaimer: I could not figure out how to get a log listing the resources as Gedemon pointed out, so I counted by hand. This can result in error. Please keep this in mind.

  • COPIES of luxuries scale directly with map size. On a duel map, each luxury gets about 7 copies. On a huge map, there are roughly 10 copies of each luxury on the normal sized continent. One smaller continent gets only about 3 copies, and the other continent with 3 luxuries only gets 1 copy. On the customized huge map, this resulted in up 20 copies of each luxury on normal sized maps.
  • Strategic and bonus resources scale directly with map size as well. Example: Duel gets about 20 crabs. Huge gets about 114 crabs. My modified huge ended up with around 150 crab.
  • The amount of unique luxuries generated is tied to continents, and the maximum observable amount of unique luxuries a continent can have is 4. A normal-sized continent gets 4 unique luxuries, this goes for DUEL and HUGE sized pangaea. Increasing map size does NOT result in a continent with more than 4 unique luxuries. Duel maps specifiy 1 continent, so there are 4 unique luxuries. Huge pangaea maps generate 6 continents. 4 are normal-sized and get this distribution. 1 continent is smaller and gets 4 luxuries as well but with fewer copies. Another continent is even smaller and only gets 3 luxuries.
There are of course some things I have no clue about despite testing:

  • Altering the amount of continents per map is...interesting. Let's look at a duel map: 4 luxuries, 7 copies each, 1 continent. Making it have 2 continents results in one continent with 4 luxuries and 5-6 copies each, and a second continent with 4 luxuries but only 2 copies each.
  • Increasing a huge map from 6 continents to 8 continents results in two continents with ZERO luxuries, but apparently normal bonus and strategic distribution. Two continents can never share luxuries, even if the amount of continents and map size in the game push it beyond the max of 24 luxuries.
  • There is a line of code in ResourceGenerator.Lua that references default player size: self.iLuxuriesThisSizeMap = GameInfo.Maps[Map.GetMapSize()].DefaultPlayers * 2. This equation however lines up with what we observe. A duel map has a default of 2 players and so gets 4 unique luxuries (with 1 continent), and a huge map has 12 default players and gets 24 luxuries (with 6 continents). Changing the 2 to another number did not result in observable changes. Changing map sizes in maps.xml and mapsize.xml did not result in observable changes either.
If I could figure out how to get this data spit out into a log or something, it'd be much more concrete. I hope this can serve as a rough first step into figuring out how the game handles resource generation, and potentially how to force continents to generate more or less than 4 unique luxuries, etc.
 
Back
Top Bottom