Summer patch broke my "more abundant resources" mod -- can anyone help?

pokiehl

Deity
Joined
Mar 5, 2017
Messages
2,701
I have a mod that adds two options past Abundant for more resource generation. Here is the part of the code from the modified ResourceGenerator.LUA:

Code:
    -- 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 == 4 then
        self.resources = TerrainBuilder.GetRandomNumber(13, "Random Resources - Lua") - 6;
    -- p0kiehl's Plentiful Resources Option
    elseif self.resources == 30 then
            self.resources = 30 ;
    -- p0kiehl's Truly Abundant Resources Option
    elseif self.resources == 45 then
            self.resources = 45;

With the summer patch, they added new tables: Resource_SeaLuxuries and Resource_SeaStrategic. This obviously changed ResourceGenerator.lua, so I brought that into my mod and inserted the code as above. What's happening, though, is that with the two new options I made ('plentiful' and 'truly abundant'), sea luxuries are not generating. I'm getting plenty of fish and crab, but never any whales or pearls.

My first guess is that the sea luxuries are not affected by the self.resources thing. That seems to make sense, since the new tables specify amounts based on map size. But that seems to be a really inelegant way of doing things since map size isn't tied to resource amount for anything else...That would mean there is no way of tying increased sea luxury generation to a resource setting like Abundant or Plentiful or whatever. Or maybe there is something else in the LUA that affects it? I can't tell at all.

My second guess is that the sea luxuries are being 'crowded out' by the fish and crabs, so they aren't being placed. Again, if that's the case, I have no idea to fix it.

Basically I'm completely lost. I know almost nothing about lua editing. Can anyone help at all?
 
Does anyone know how to ensure that my UpdateDatabase files are loaded before the ImportFiles? I think I found a solution via SQL, but I need to make sure the SQL loads before the imported ResourceGenerator.lua
 
the database is always updated by mods before any lua file is loaded (except the frontend UI files, but ResourceGenerator.lua is not one of those)
 
Thanks Gedemon! Then I guess my approach is flawed since it's still not working. One more quick question:

Resources_SeaLuxuries looks like this:
Code:
<Row Huge="0" Large="0" Standard="0" Small="0" Tiny="0" Duel="0" MapArgument="1"/>

<Row Huge="2" Large="2" Standard="2" Small="1" Tiny="1" Duel="1" MapArgument="2"/>

<Row Huge="2" Large="2" Standard="2" Small="2" Tiny="2" Duel="1" MapArgument="3"/>

<Row Huge="2" Large="2" Standard="2" Small="2" Tiny="2" Duel="2" MapArgument="4"/>

Is MapArgument the user setting for resources (Scarce, Standard, Abundant, Random?) That makes a bit of sense since there are 4 arguments.

The reason I ask is because I thought adding maparguments 5 and 6 (for my new resource options, Plentiful and Truly Abundant) and filling them out for the map sizes would fix it, but it doesn't work. I don't think the issue is the fish and crabs crowding out the sealuxuries because the lua specifies that sealuxuries are placed first.

All I can find referencing the MapArguments in the lua is:
Code:
    for row in GameInfo.Resource_SeaLuxuries() do
        if (row.MapArgument == self.iWaterLux ) then

And no other reference to self.iWaterLux
 
C:\Program Files (x86)\Steam\SteamApps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Island_Plates.lua
Code:
	local resourcesConfig = MapConfiguration.GetValue("resources");
	local args = {
		iWaterLux = 4,
		resources = resourcesConfig,
	};

C:\Program Files (x86)\Steam\SteamApps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Fractal.lua
Code:
	local resourcesConfig = MapConfiguration.GetValue("resources");
	local args = {
		iWaterLux = 2,
		resources = resourcesConfig,
	};

C:\Program Files (x86)\Steam\SteamApps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Pangaea.lua
Code:
	resourcesConfig = MapConfiguration.GetValue("resources");
	local args = {
		iWaterLux = 2,
		resources = resourcesConfig,
	}

C:\Program Files (x86)\Steam\SteamApps\common\Sid Meier's Civilization VI\Base\Assets\Maps\InlandSea.lua
Code:
	local resourcesConfig = MapConfiguration.GetValue("resources");
	local args = {
		iWaterLux = 1,
		iWaterBonus = 1.0,
		resources = resourcesConfig,
	};

The specific map-type selected by the player sets the argument value, and this is then passed into the code within C:\Program Files (x86)\Steam\SteamApps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Utility\ResourceGenerator.lua
Code:
		-- data
		iWaterLux = args.iWaterLux or 3;
		iWaterBonus = args.iWaterBonus or 1.25;
		iLuxuriesPerRegion = args.LuxuriesPerRegion or 4;
		resources = args.resources;

--------------------------------------------

What this line does
Code:
iWaterLux = args.iWaterLux or 3;
is set the value for variable iWaterLux to the value passed back as args.iWaterLux or else it defaults to "3" if no data has been passed back.

-------------------------------------------------

This is creating an lua table called args and giving certain specified values for certain specified "keys"
Code:
	local args = {
		iWaterLux = 1,
		iWaterBonus = 1.0,
		resources = resourcesConfig,
	}
Key "iWaterLux" in this case is being set to a value of "1". Key "iWaterBonus" is also being set to a vlaue of "1", while Key "resources" is being set to whatever the previously established value is for variable "resourcesConfig".

Other lua code can then access the values stored within these keys by simply referencing "args.iWaterLux" for example.

Looking at the code a little more the "args" info is passed directly into an "instance" table and then this "instance" table passes info (it looks like) into the appropriate functions under the name "self".

This is also the point where the Firaxis rabbit-holing of "self" and "instance" become a little hard to follow at times.
 
Last edited:
Column MapArgument in tables <Resource_SeaLuxuries> and <Resource_SeaStrategics> are thus being used to refer to the player-selected Map-Type (Island Plates, Inland Sea, etc.) and not the resource abundancy
 
Ahh, thank you so much LeeS! That explains quite a bit to me! You are always so helpful man! So then that approach to fixing it was obviously completely wrong.

Man, this is confusing. Something about having another resource option is not playing nice with all of this. The other unique part of the formula for placing water luxuries is iNumLuxuries

Code:
self.iOccurencesPerFrequency =  self.iTargetPercentage / 100 * self.iWaterPlots * self.iLuxuryPercentage / 100 / iNumLuxuries / 2;

That appears to be defined as

local iNumLuxuries = math.floor(self.iNumWaterLuxuries / 2);
self.bOdd = false;

-- Determine if the number of water luxuries is odd
if(self.iNumWaterLuxuries % 2 == 1) then
self.bOdd = true;
iNumLuxuries = iNumLuxuries + 1
end

I'm sorry, I only have a very basic understanding of SQL and no understanding of lua -- If I could just identify what is going wrong to cause zero sea luxuries to be placed but plenty of crabs and fish, I could start working on a solution.
 
Alright, my mod works, it's actually big map sizes that give the issue. Mods, please close this thread. I'll make a new one detailing the issue more clearly later.
 
Top Bottom