Resource Generator (Lua component)

Is there some code that pushes all the resources out of the vicinity of the player? If I ramp up the resource generation enough then I can see the player surrounded by maybe 3-8 resources, but outside that start zone nearly every tile can be covered in resources.

This cant be done because my code divides the map into equal Areas to avoid clustered resources and to distribute resources on the map.

Also, is there any way to modify the generation rate of individual resources?

Yes this can be easily done, add the Code in Red after Quantity formula:
Code:
	-- Now multiply quantity with modifiers
	iQuantity = iQuantity * option_modifier *NumCivs_modifier;
[COLOR="Red"][B]
	-- Reduce Copper by 50%
	if New_ResourceType == "RESOURCE_COPPER" then
		iQuantity = iQuantity * 0.5;
	end[/B][/COLOR]

Here I reduced Copper quantity by 50%.
 
This cant be done because my code divides the map into equal Areas to avoid clustered resources and to distribute resources on the map.

Well if that were working as intended, then I wouldn't see large open spaces surrounded by walls of resources. It seems like there is something keeping the resources from spawning near the start locations.

I can jam pack the start zones with resources, but only if leave the resource modifier at 1. I have added 13 resources and moved the 27 vanilla resources to your generator so with a modifier of 1 it basically fills every tile on the map. So what I am seeing is that the start locations seem to be the last tiles to be filled by the wall to wall resources.

What the players will see in the game(with normal modifiers) is perhaps 3-5 resources near their start zone, and once they reach the edge, the resource density increases rapidly.


Yes this can be easily done, add the Code in Red after Quantity formula:
Code:
	-- Now multiply quantity with modifiers
	iQuantity = iQuantity * option_modifier *NumCivs_modifier;
[COLOR="Red"][B]
	-- Reduce Copper by 50%
	if New_ResourceType == "RESOURCE_COPPER" then
		iQuantity = iQuantity * 0.5;
	end[/B][/COLOR]

Here I reduced Copper quantity by 50%.

Awesome, thanks. :)
 
Here is a screenshot of what I am talking about with the distribution.

As you can see, start location has a handful of resources, and the outlying edges are jam packed.

This is a huge map but it is actually worse on smaller maps which makes me thing the scaling on generation is a little off. Playing with legendary resources on a standard map would have most every tile covered. So the huge map has a lot more space, but it does show the scattering a little better.

Of course, this screenshot shows what the generator is doing without the presence of the Vanilla resource distribution, so it is all from the generator.
 

Attachments

  • Resources.jpg
    Resources.jpg
    522.8 KB · Views: 230
Well if that were working as intended, then I wouldn't see large open spaces surrounded by walls of resources. It seems like there is something keeping the resources from spawning near the start locations.

Actually in same cases resources get clustered at the areas boundaries, in my first post I posted a screen shot of how the map will be divided. In some cases up to 4 resources can be very near to each other at the boundaries of 4 rectangles.

This happens when for example you define a Jungle as TerrainBoolean then a jungle is placed at the boundary like in the following picture:

attachment.php


The optimal placement is shown as cross, but because the jungle in green fell at the borders the 4 resources get clustered.

In short there is randomness in the generation because the map features and terrains are random.
 

Attachments

  • Image111.jpg
    Image111.jpg
    14.1 KB · Views: 448
Here is a screenshot of what I am talking about with the distribution.

As you can see, start location has a handful of resources, and the outlying edges are jam packed.

This is a huge map but it is actually worse on smaller maps which makes me thing the scaling on generation is a little off. Playing with legendary resources on a standard map would have most every tile covered. So the huge map has a lot more space, but it does show the scattering a little better.

The code it self is blind it doesnt know or check the start locations, the results you got are just random, if you repeat with another map you will get different results. In the same image you posted if the starting location was moved to the area that is jammed with resources nothing should change in the distribution of the resources.

Maybe this is related to AssignStartingPlots, but you said you have removed all vanilla resources, and the Generator works after the game starts so the starting locations are set before the Generator code starts. There is no relation between the generator and starting locations at all.

Edit: Try this: for small maps give different modifiers for individual resources, this will result in different Map Divisions Scenarios for each resource and thus adds more randomness to resource scattering. Also Playing with Terrain Booleans and Feature Booleans can give the effect that you need.
 
After looking over some of my resources, I realized that maybe 20-25% have NoRiverSide. As rivers are guaranteed for America, that is why I have been seeing the disparity.
 
@Decimatus

I have good news for you I have released V3, in the new version I added advanced options to Exclude particular terrain types or feature types. Also now Only_Hills and Only_Flatland are available. Plus the code now checks MaxLatitude when distributing the resource.

I have updated my first post with details on the new additions.

Thanks for your feedback and ideas.
 
I am not a lua coder by any means, so let me make sure I have this right.

Spoiler :
function OnMapResourceGenerator(New_ResourceType , ExecludesTable )

OnMapResourceGenerator("RESOURCE_COPPER" , {"FEATURE_JUNGLE"} )
OnMapResourceGenerator("RESOURCE_COFFEE" , {"TERRAIN_DESERT"} )


Or do I insert my own somewhere:

Spoiler :
OnMapResourceGenerator("RESOURCE_MyResource" , Excludes )

OnMapResourceGenerator("RESOURCE_COPPER" , {"FEATURE_JUNGLE"} )
OnMapResourceGenerator("RESOURCE_COFFEE" , {"TERRAIN_DESERT"} )


I suppose my question is, how exactly is the table defined or how do I format it?
 
OnMapResourceGenerator("RESOURCE_MyResource" , Excludes )

OnMapResourceGenerator("RESOURCE_COPPER" , {"FEATURE_JUNGLE"} )
OnMapResourceGenerator("RESOURCE_COFFEE" , {"TERRAIN_DESERT"} )

I suppose my question is, how exactly is the table defined or how do I format it?

First delete the line in Red it is just an example of the function format.

"Excludes" that I put is just a tag remove it and replace with table:
Excludes = { a , b , c , d ..... } => table format

IF you have Coffee and you want to Exclude lets say: Jungle,Forest,Desert and Plains:

Then The only Code you put is:

OnMapResourceGenerator( "RESOURCE_COFFEE" ,
{ "FEATURE_JUNGLE" , "TERRAIN_DESERT" , "TERRAIN_PLAINS" , "FEATURE_FOREST" } )


You can put as many types as you want in the table in blue, and in no particular order.
 
First delete the line in Red it is just an example of the function format.

"Excludes" that I put is just a tag remove it and replace with table:
Excludes = { a , b , c , d ..... } => table format

IF you have Coffee and you want to Exclude lets say: Jungle,Forest,Desert and Plains:

Then The only Code you put is:

OnMapResourceGenerator( "RESOURCE_COFFEE" ,
{ "FEATURE_JUNGLE" , "TERRAIN_DESERT" , "TERRAIN_PLAINS" , "FEATURE_FOREST" } )


You can put as many types as you want in the table in blue, and in no particular order.

And it can pretty much be anywhere in the lua that isn't right in the middle of some other tables? Seems easier than I thought it would be I guess. I will test it out in the morning. :)

One thing I forgot to mention, is that your recent update seems to have greatly increased map creation times. I had a similar problem as this after FiresForever made a few changes to the TechPages mod. It is taking several minutes longer than it takes the guy to finish speaking before the map finishes, even for duel maps. Have you seen anything like this?
 
Nop I didnt experience and increase in loading times, the changes in the new version are simple IF conditions and do not require a lot of calculations. I think the slowness you have is because your project adds a lot of things to the game.

Right, that is part of it, but suddenly having the load time triple points to something else.
 
Just dropping a note to thank you for creating this. It will be very useful to me if I ever get back to my own modding project.
 
Right, that is part of it, but suddenly having the load time triple points to something else.

Well, you are adding close to something like 20 new resources, right? Given that the game needs to graphically represent all of these, it would probably cause a massive slowdown. Also, I am assuming that the per-resource load time addition is geometric, since each resource needs to be placed in ways that do not overlap with previous ones.
 
Well, you are adding close to something like 20 new resources, right? Given that the game needs to graphically represent all of these, it would probably cause a massive slowdown. Also, I am assuming that the per-resource load time addition is geometric, since each resource needs to be placed in ways that do not overlap with previous ones.

It wasn't that I suddenly added 40 resources and then a slowdown appeared. I simply updated to V3. I had added a few new techs between the update and my first test, but I hadn't yet added any new resources between tests.

Of course, it wouldn't be the first time I have done lots of things I have forgotten about, but I don't think this is the case. :p

But I have had this happen before, when I updated a lua file and had these vast map creation time increases.
 
Try reverting back to V2 to see if the slowness is related to the new patch.

No dice. Maybe it didn't start until after I added AssignStartingPlots.lua to the mix. Staring at walls of text has been known to fry the brain occasionally. :p
 
So, the latest problem I am having now, is that apparently the resources reload when a save is loaded. I am not yet sure if they are simply loaded on top of the old resources, or if it is completely reshuffled, but it sounds like some reshuffling is going on.

Do you know anything about why that might be happening? And could you put a line in there that keeps it from generating on a save? :)
 
Back
Top Bottom