Hey,
@MariusMagnus! Always good to hear from you!
It's odd, after I wrote that, in doing research on the topic, I ran into this:
https://forums.civfanatics.com/resources/resource-generator-lua-component.16131/
A program that basically does it all, as far as placing new resources on the map. It has a couple of problems: the placement of those resources is "clumped" a bit together, with large barren spots on the map. It's not toooo bad, but is a bit noticeable. Also, if you have a new Strategic Resource, be sure to either make 2 entries into the "Resource_QuantityTypes" table for it, or change line #333 in the "ResGenerator.lua" file to this:
Code:
N = Strategic_Distribution[i] or 1; -- if strategic then get quantity to place
Otherwise, the resource will never place. The 1 after the "OR" could be up to 3 if you wanted more to appear on the map. For more than 3, I ran into some odd problems - see link below (new resource inconsistent behavior).
The script is pretty good, and I've made a few changes in the version this mod uses, to make some resources appear more or less often than they otherwise would.
One quick warning: if placing a Strategic Resource with multiple copies, for some reason, every time I tried to place more than 3 of the resource on a given tile, it would act oddly (basically not appear on the map, but would behave normally in every other respect. Also, any improvements placed on the resource would not show up either, but would otherwise work. All discussed here:
https://forums.civfanatics.com/thre...l-inconsistent-behavior.665259/#post-15975318
Now, if you just want to adjust the numbers of the strategic resources already on the map, I did that in my "WW2 Scenario On Any Map" mod. I was trying to create "pockets" of large numbers of the resource to create geopolitical incentives across the map. The code that did this also increased the total number of the resources, so as not to penalize civs not lucky enough to be near these pockets. Generally speaking, the map ended up with just a bit more of the resource than normal (between 5-10% more). The code for that is here (it's a bit verbose, but could be easily be streamlined):
Code:
g_tResourceAdjustmentCoefficient = { [GameInfoTypes.RESOURCE_ALUMINUM] = 1.5, -- Adjusts the amount in each tile, based on these coefficients
[GameInfoTypes.RESOURCE_COAL] = 1.75, -- NOTE: these amounts are the MAX amount appearing; actuals randomized from 2..?
[GameInfoTypes.RESOURCE_HORSE] = 0.5,
[GameInfoTypes.RESOURCE_IRON] = 1.5,
[GameInfoTypes.RESOURCE_OIL] = 2.0,
[GameInfoTypes.RESOURCE_URANIUM] = 0.5
}
RESOURCE_NONE = -1
function SetBounds(iNumber, iLowerBound, iUpperBound) -- Ensures RetVal is inside the lower and upper bounds
if iLowerBound > iUpperBound then iLowerBound = iUpperBound end -- Ensure lower bount isn't more than upper bound
if iUpperBound < iLowerBound then iUpperBound = iLowerBound end -- Ensure upper bound isn't less than lower bound
if iNumber < iLowerBound then iNumber = iLowerBound end -- Ensure RetVal isn't less than lower bound
if iNumber > iUpperBound then iNumber = iUpperBound end -- Ensure RetVal isn't more than upper bound
return iNumber
end
function IsStrategicResource(iResourceType) -- Determines if iResourceType is a strategic resource or not
local bRetVal = false -- Default return of false
if (iResourceType == GameInfoTypes.RESOURCE_ALUMINUM) or (iResourceType == GameInfoTypes.RESOURCE_COAL) or -- Check the incoming iResourceType against known strategic resources
(iResourceType == GameInfoTypes.RESOURCE_HORSE) or (iResourceType == GameInfoTypes.RESOURCE_IRON) or
(iResourceType == GameInfoTypes.RESOURCE_OIL) or (iResourceType == GameInfoTypes.RESOURCE_URANIUM) then
bRetVal = true -- If any of these tests are true, then return TRUE; iResourceType is a strat resource
end
return bRetVal
end
function RepopulateStrategicResources() -- Randomizes strat resource amounts in each tile they appear; usually a small increase in quantity overall
local iOriginalCount = 0
local iFinalCount = 0
for PlotIndex = 0, (Map.GetNumPlots() - 1), 1 do -- Loop through all plots on map
local pPlot = Map.GetPlotByIndex(PlotIndex) -- Set up the loop plot pointer
if (pPlot ~= nil) then -- If we have a valid plot pointer, then...
local iPlotResourceType = pPlot:GetResourceType() -- Get the resource type in this plot
if iPlotResourceType ~= RESOURCE_NONE then -- If there is some kind of resource here, then...
if IsStrategicResource(iPlotResourceType) then -- If the resource here is a strategic one, then...
local iResourceAmount = pPlot:GetNumResource() -- Get the current number of resources in the tile
local iResourceMax = SetBounds( math.floor( iResourceAmount * g_tResourceAdjustmentCoefficient[iPlotResourceType] ), 3, 10 ) -- No more than 10 of any resource in a tile
local iAdjustedAmount = GetRandom(3, iResourceMax)
pPlot:SetNumResource(iAdjustedAmount)
iOriginalCount = iOriginalCount + iResourceAmount
iFinalCount = iFinalCount + iAdjustedAmount
end
end
end
end
print("RepopulateStrategicResources. Original Strat Resource Count: " .. iOriginalCount .. " Final Strat Resource Count: " .. iFinalCount)
end
Both of these code segments need to run when the mod is initiated. The mod Resource Generator Lua Component does this automatically. For the strat resource renumerator, you'd need something like this in an InGameUIAddin:
Code:
function InitializeMod()
RepopulateStrategicResources()
end
InitializeMod()
Oddly enough, it never occurred to me to try using both of these in the same mod (with the renumerator running after the Resource Generator mod. I wonder if that would have somehow fixed the "no more than 3 strat resources in a tile" problem...?
Anyways, let me know if you have any questions about any of these. Working with things like these can be deeply frustrating and time-consuming, but you probably already knew that. I've got plenty of recent experience getting these to work, so hopefully, I could offer a bit of help if needed.
EDIT: Sorry, lots of typos. I should never post in the B.C. (before coffee)...