[GS] Unit strategic resource help

Riker13

King
Joined
Nov 9, 2001
Messages
859
Location
UK
Hi All,
Is there a way that if you don't have the resources you cant build the unit.
At the moment in GS you still can but it lowers its power and no self heals.

Regards
Riker13 :crazyeye:
 
Hi All,
Is there a way that if you don't have the resources you cant build the unit.
At the moment in GS you still can but it lowers its power and no self heals.

Regards
Riker13 :crazyeye:
There are 4 relevant attributes for a unit:
StrategicResource
ResourceCost
ResourceMaintenanceType
ResourceMaintenanceAmount

The first two govern the resource type and cost to build a unit. The second two govern the resources need to upkeep/fuel a unit.
For example, a Swordsman only has
StrategicResource = RESOURCE_IRON
ResourceCost = 20

Where a Mechanized Infantry has
StrategicResource = RESOURCE_OIL
ResourceCost = 1
ResourceMaintenanceType = RESOURCE_OIL
ResourceMaintenanceAmount = 1

If you look at the GS units xml in steamapps/common/Sid Meier's Civilization VI/DLC/Expansion 2/Data/Expansion2_Units.xml you'll see a big block at line 393 where they define the ResourceCost, ResourceMaintenanceType, ResourceMaintenanceAmount attributes in the "Units_XP2" table. Note that StrategicResource is part of base "Units" table!

In the regular game, if StrategicResource and ResourceCost are defined, you will not be allowed to build the unit if you don't have enough resources. If you don't define them, ResourceCost defaults to 0, so there won't be anything blocking construction because a stockpile of 0 allows you to pay a "cost" of 0.
 
Sostratus I have looked into this and still don't quite understand, the units do have costs and resources defined but you can still build them if you don't have the Resource Maintenance (Resource) available, eg My version of modded Redcoats need 20 Iron to build and 1 Niter for Maintenance, if I didn't have Iron then no I could not build it but it seems not having any Nitre I can still build it just with the nerf as mentioned in OP.
Any thought? :)
 
if I didn't have Iron then no I could not build it but it seems not having any Nitre I can still build it just with the nerf as mentioned in OP.
Any thought? :)
That's how the game works. You can only have one strategic resource defined as required for unit builds. The maintenance resource is a completely separate mechanism and can't be used for restricting unit builds.
 
Bugger, that's a shame, you think there might have been some way?
Oh well thanks Laurana.
 
Is it possible to have 2 different strategic resources for one cost? Because a cost of 20 iron 1 niter would do that.
 
Is it possible to have 2 different strategic resources for one cost? Because a cost of 20 iron 1 niter would do that.
Of the four parameters I mentioned,
Strategic Resource & ResourceMaintenanceType are how you define which resource is used an they indeed can be different. But you can’t have
“Costs 20 iron AND 1 oil to build.” There’s only one allowed type for cost and one for maintenance.
Of course, you’d have to ask yourself the implication of having a fuel using unit that consumes a different resource to build in the first place- that would be fairly realistic in the sense that you can build lots of tanks with steel, but you can’t drive them without gas. The current late game units all cost the same type of resource they are fueled with to prevent this issue of building without fueling.

If you absolutely wanted to get around this, I THINK you could tie being able to build a unit to possessing a positive amount of a resource. I’m not sure if regular modifiers can do it or if you would need to do it LUA (where accessing player stockpile data is very easy.)
So for example, similar to how you need a belief to make warrior monks, you’d have a condition to make the relevant units be that you have at least one oil, even though the unit itself costs iron to build.
 
In lua we even have
Code:
Player:GetUnits():SetBuildDisabled(UnitIndex, Boolean)
to directly allow or dis-allow build of a unit.

This was added as part of the Black Death Scenario. So it may not be back-compatible to RaF or Vanilla.
 
So are you saying there may be a way (Sostratus, LeeS) of doing this in lua?
Yes when they added the resources for units in GS I thought great but who builds a Battleship with Coal? So I thought no build with Iron/Steel then fuel with Oil.
Realistic to me.
I was thinking Modifiers might do it but was not sure.
 
Last edited:
So are you saying there may be a way (Sostratus, LeeS) of doing this in lua?
Lee would be the expert (make sure you read his modding guide, there are some chapter on Lua) but generally:
-You choose an appropriate thing to trigger your script. This may be when the player's resources are refreshed, or perhaps the beginning of a turn is enough.
-Your script would grab the unit indexes of the units you want this "no build without fuel" applies to. You may want it to only be units which have a material cost differing from their fuel cost. This could be looking through the units + units xp2 table, or you could hard code in a short list if there aren't that many.
-You grab the player's resources. You can see an example in steamapps\common\Sid Meier's Civilization VI\DLC\Expansion2\UI\Replacements\TopPanel_Expansion2.lua that the RefreshResources() function manipulates the player resources in a number of ways, specifically you can just ask for the current amount on hand for a given resource type:
Code:
local localPlayerID = Game.GetLocalPlayer();
local localPlayer = Players[localPlayerID];
local pPlayerResources:table    =  localPlayer:GetResources();

...

local stockpileAmount:number = pPlayerResources:GetResourceAmount(resource.ResourceType);
-You would go through the list of relevant units you're targeting that the player has unlocked or can otherwise build, and disable/enable them via the method Lee mentioned if the player has the needed fuel. I'm guessing the method lee gave is persistent so you'll need to turn units back on, too. But you don't want to enable redcoats just because Suleiman has built a niter mine.

Yes when they added the resources for units in GS I thought great but who builds a Battleship with Coal? So I thought no build with Iron/Steel then fuel with Oil.
Realistic to me.
Speaking from a game design standpoint:
You need to ask yourself if it makes sense that a civilization should be able to build things that they cannot adequately fuel. Look at German military effectiveness late in ww2 for an army that was oil constrained but could still fight. Having no oil reserves doesn't necessarily mean you have no oil income.
If you think that's okay to have the combat debuff stand in for a fuel shortage, then just the way things are now if fine.
If you feel that using iron to build, while realistic, isn't the ultimate thing you want to block construction, and you'd rather have construction be blocked by fuel, then you can follow the example of other late game units and have it require the fuel resource to build in a token amount, since that already gives the "block construction if no fuel" behavior.
If you still prefer your idea, then by all means. But a good engineer will try to think about what the end user really needs vs what they asked for. Sometimes gameplay trumps realism, and you want to make sure the mod is fun! Even if only you use it.
 
Thanks Sostratus for your replies, I will need to think on it some more or find another way round it.
All the best.
 
Since i wrote this back in 2019 has anything changed with the updates, can it be done now?
 
Back
Top Bottom