Resource Quantity

tiemanj

Chieftain
Joined
Jan 24, 2011
Messages
13
I'm trying to increase the quantity of resources in a given mine (or whatever). It seems that iron is always 6 or 2. If I wanted to change those numbers where would I do that?

I found the table <Resource_QuantityTypes>, but it doesn't seem to have any impact

Spoiler :
<GameData>
<Resource_QuantityTypes>
<Delete />
<Row>
<ResourceType>RESOURCE_IRON</ResourceType>
<Quantity>8</Quantity>
</Row>
<Row>
<ResourceType>RESOURCE_IRON</ResourceType>
<Quantity>3</Quantity>
</Row>
<Row>
<ResourceType>RESOURCE_HORSE</ResourceType>
<Quantity>6</Quantity>
</Row>
<Row>
<ResourceType>RESOURCE_HORSE</ResourceType>
<Quantity>3</Quantity>
</Row>
<Row>
<ResourceType>RESOURCE_COAL</ResourceType>
<Quantity>10</Quantity>
</Row>
<Row>
<ResourceType>RESOURCE_OIL</ResourceType>
<Quantity>8</Quantity>
</Row>
<Row>
<ResourceType>RESOURCE_ALUMINUM</ResourceType>
<Quantity>8</Quantity>
</Row>
<Row>
<ResourceType>RESOURCE_URANIUM</ResourceType>
<Quantity>3</Quantity>
</Row>
<Row>
<ResourceType>RESOURCE_URANIUM</ResourceType>
<Quantity>2</Quantity>
</Row>

</Resource_QuantityTypes>
</GameData>


But when I start a new game, the iron still comes in quantities of 6.
 
It's possible that the Resource_QuantityTypes values are scaled based on map size, but I wouldn't be surprised if instead AssignStartingPlots.lua just does its own thing entirely. I'd take a look there, but be warned that it is probably the largest and most complicated lua file in the original game.
 
Those XML entries aren't used. The only thing that sets resource quantities is AssignStartingPlots.lua, although certain map scripts (Lakes, Great Plains, Highlands) override certain parts of it.

For strategic resources, there are three subroutines that set these quantities:

GetMajorStrategicResourceQuantityValues: sets the number of units in a "large" deposit.
GetSmallStrategicResourceQuantityValues: sets the number of units in a "small" deposit.
PlaceOilInTheSea: adds a number of oil deposits to the ocean. The size of these is hard-coded to 4 or 6 depending on whether you've got resources set to Abundant or not.

If all you want to do is change the number of units in a single deposit, then this is easy to change, although you're still only going to have two sizes for each resource (so you can't have some Irons be 6s, some be 4s, and some be 2s). If you want to change the number of deposits, that's more work.

Also note that because this is a Lua file, you'll need to update it every time there's a patch that changes anything resource-related. And in this case, it's extremely painful to do that if you've made any substantial changes.
 
thanks. I found the code to modify.

Spoiler :
------------------------------------------------------------------------------
function AssignStartingPlots:GetMajorStrategicResourceQuantityValues()
-- This function determines quantity per tile for each strategic resource's major deposit size.
-- Note: scripts that cannot place Oil in the sea need to increase amounts on land to compensate.
local uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 4, 4, 7, 6, 7, 8;
-- Check the resource setting.
if self.resource_setting == 1 then -- Sparse
uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 2, 4, 5, 4, 5, 5;
elseif self.resource_setting == 3 then -- Abundant
uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 4, 6, 9, 9, 10, 10;
end
return uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt
end
------------------------------------------------------------------------------
function AssignStartingPlots:GetSmallStrategicResourceQuantityValues()
-- This function determines quantity per tile for each strategic resource's small deposit size.
local uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 2, 2, 3, 2, 3, 3;
-- Check the resource setting.
if self.resource_setting == 1 then -- Sparse
uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 1, 1, 2, 1, 2, 2;
elseif self.resource_setting == 3 then -- Abundant
uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 3, 3, 3, 3, 3, 3;
end
return uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt
end
------------------------------------------------------------------------------


My last (hopefully) question is how do I add the modified code to my project? Is it the same as with xml - ie, just add a file to the project, put the modded code in the project, and tell modbuilder to use it "onmodactivate"? Or is it more involved?
 
Is it the same as with xml

No, not even remotely similar, beyond having them both be within the mod directory. You do NOT use the OnModActivated functionality for Lua, because it's not modifying the game's database.

First of all, when you modify a Lua function, you modify the ENTIRE function. There's no partial update system in place. There's a small exception where map scripts are involved, but generally speaking, you need to duplicate the whole thing.

Second, the name of the replacement file must be the same as the original. In XML you can name things whatever you want, in Lua you can't. (This only applies to Lua that modifies an existing function; new Lua routines can be named whatever you want, as long as it's not a name that's being used by an existing function.)

Third, if you're altering an existing Lua function, you have to set "Import into VFS" (Virtual File System?) on your version to True. This is in the Properties window for each mod element (right-click on the file name in ModBuddy); the default is False, so you MUST change it.
If you're adding an entirely new Lua function, something that doesn't override any existing logic, it's totally different. You'd leave VFS=false, but go into the Content tab of the mod's Properties (NOT the Actions tab where you loaded the XML) and put InGameUIAddin / (name) / (description) / the Lua filename.
 
You found the code to modify? What exactly did you modify? The numbers on this...??

local uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 4, 4, 7, 6, 7, 8;

uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 2, 4, 5, 4, 5, 5;

uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 4, 6, 9, 9, 10, 10;
end
return uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt
end
local uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 2, 2, 3, 2, 3, 3;
-- Check the resource setting.
if self.resource_setting == 1 then -- Sparse
uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 1, 1, 2, 1, 2, 2;
elseif self.resource_setting == 3 then -- Abundant
uran_amt, horse_amt, oil_amt, iron_amt, coal_amt, alum_amt = 3, 3, 3, 3, 3, 3;

'Cause I modified them and still the game starts as if nothing changed. The resources are still at the same amount as before. What am I doing wrong or what am I missing?
 
If you're making a mod, make sure you didn't change the filename and it's set to VFS=True. If you're just editing your game installation files, make sure you're editing the one from the latest expansion that you have (e.g., within Assets\DLC\Expansion2... for BNW).
 
Yeah, all I'm doing is editing the game installation files. File name has not been changed. The DLC/Expansion 2 (BNW) is the one being edited and still it will not work. When I restart the game the resource quantities return to 2, 4, 10, 6, etc. What I'm trying to do is get all strategic resources to be the same quantity.

And while we're at it, how do you edit unit maintenance costs and/or road maintenance costs?
 
And while we're at it, how do you edit unit maintenance costs and/or road maintenance costs?

Try toying around with these for unit maintenance:

Code:
-- Maintenance!
UPDATE Defines SET Value = 100 WHERE Name = "INITIAL_GOLD_PER_UNIT_TIMES_100"; 
UPDATE Defines SET Value = 2 WHERE Name = "INITIAL_FREE_OUTSIDE_UNITS"; 
UPDATE Defines SET Value = 0 WHERE Name = "INITIAL_OUTSIDE_UNIT_GOLD_PERCENT"; 
UPDATE Defines SET Value = 8 WHERE Name = "UNIT_MAINTENANCE_GAME_MULTIPLIER"; 
UPDATE Defines SET Value = 6 WHERE Name = "UNIT_MAINTENANCE_GAME_EXPONENT_DIVISOR"; 
UPDATE Defines SET Value = 0 WHERE Name = "FREE_UNIT_HAPPINESS";

and I think this is the modifier for road maintenance

Code:
<Table name="HandicapInfos">
<Column name="ImprovementCostPercent" type="integer" default="0"/>
</Table>
 
Yo Thor! You pointed me in the correct direction with that Handicapinfos code. The former one that you said was from Globaldefines was a dead end but I found the right lines in that Handicapinfos file...

<RouteCostPercent>100</RouteCostPercent>
<UnitCostPercent>100</UnitCostPercent>
<BuildingCostPercent>100</BuildingCostPercent>
<ImprovementCostPercent>100</ImprovementCostPercent>

All I had to do was modify those numbers...

Thanks again! Cheers.
 
Back
Top Bottom