Sostratus
Deity
After some helpful guidance in the Quick Questions thread, i felt this was getting pointed enough to warrant a little thread.
Goal:
The stated goal of this mod is to update the function RefreshResources() in the expansion2 file TopPanel_Expansion2.lua to support displaying having strategic resource costs from buildings.
Background
This effort is part of my first civ6 modding project, which adds buildings that consume strategic resources as per turn maintenance. This is done using the otherwise unused table Building_ResourceCosts. While this table is fully functional in gameplay, it is not connected to the UI at all. So when you hover over a resource like, say, oil, normally one might see a tooltip like "consuming X per turn, -Y from Power, -Z from units." This would be adding on to that "...-W from buildings."
Current State
I understand XML, C, Python type languages, but I am otherwise green to Lua. Some of the syntax is a little odd to look at but from a "pseudo code" level I see what's going on.
There are two parts in RefreshResources() which I have identified as the areas to attack. First, there are a few lines in RefreshResources() that seem to be a target:
...
local unitConsumptionPerTurn:number = pPlayerResources:GetUnitResourceDemandPerTurn(resource.ResourceType);
local powerConsumptionPerTurn:number = pPlayerResources:GetPowerResourceDemandPerTurn(resource.ResourceType);
local totalConsumptionPerTurn:number = unitConsumptionPerTurn + powerConsumptionPerTurn;
...
Where it would seem the logical thing to do would be something like so:
...
local unitConsumptionPerTurn:number = pPlayerResources:GetUnitResourceDemandPerTurn(resource.ResourceType);
local powerConsumptionPerTurn:number = pPlayerResources:GetPowerResourceDemandPerTurn(resource.ResourceType);
local buildingConsumptionPerTurn:number = pPlayerResources:GetBuildingResourceDemandPerTurn(resource.ResourceType);
local totalConsumptionPerTurn:number = unitConsumptionPerTurn + powerConsumptionPerTurn + buildingConsumptionPerTurn;
...
My first hunch was to look around and try to find where "GetXResourceDemandPerTurn" is defined, since i am assuming for eg units it is summing up the instances of a unit and multiplying by the unit's <ResourceMaintenanceAmount> column entry in the Units_XP2 table, or something to that effect. Naturally I would just change the relevant types to buildings and refer to the columns in the aforementioned Building_ResourceCosts table.
A few lines below this chunk, where things are getting processed into being displayed, we have:
if (totalConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_CONSUMPTION", totalConsumptionPerTurn);
if (unitConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_UNIT_CONSUMPTION_PER_TURN", unitConsumptionPerTurn);
end
if (powerConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_POWER_CONSUMPTION_PER_TURN", powerConsumptionPerTurn);
end
end
And again, logically, it would seem like the obvious answer would be to just extend the addition above here:
if (totalConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_CONSUMPTION", totalConsumptionPerTurn);
if (unitConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_UNIT_CONSUMPTION_PER_TURN", unitConsumptionPerTurn);
end
if (powerConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_POWER_CONSUMPTION_PER_TURN", powerConsumptionPerTurn);
end
if (buildingConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_BUILDING_CONSUMPTION_PER_TURN",buildingConsumptionPerTurn);
end
end
Outstanding Problems
-Where or how would I add the functionality "GetBuildingResourceDemandPerTurn" ? (Assuming this is the correct approach.) As I understand I will need to tell the game to replace the top panel file with my new file, but this seems like it would live somewhere else.
-How does Locale.Lookup("LOC_RESOURCE_POWER_CONSUMPTION_PER_TURN", powerConsumptionPerTurn); function? This looks like the game is using those two arguments to produce "-X resource per turn due to Power" type text.
-Alternatively to computing based on a "GetBuildingResourceDemandPerTurn" basis, I could infer the number consumed by buildings as a workaround; because if there's a difference between units+power and the total consumed, it must be buildings. (The Building_ResourceCosts table may not be hooked up to the UI, but it functions numerically, and the UI does correctly say the net income of the resource.)
Goal:
The stated goal of this mod is to update the function RefreshResources() in the expansion2 file TopPanel_Expansion2.lua to support displaying having strategic resource costs from buildings.
Background
This effort is part of my first civ6 modding project, which adds buildings that consume strategic resources as per turn maintenance. This is done using the otherwise unused table Building_ResourceCosts. While this table is fully functional in gameplay, it is not connected to the UI at all. So when you hover over a resource like, say, oil, normally one might see a tooltip like "consuming X per turn, -Y from Power, -Z from units." This would be adding on to that "...-W from buildings."
Current State
I understand XML, C, Python type languages, but I am otherwise green to Lua. Some of the syntax is a little odd to look at but from a "pseudo code" level I see what's going on.
There are two parts in RefreshResources() which I have identified as the areas to attack. First, there are a few lines in RefreshResources() that seem to be a target:
Spoiler :
...
local unitConsumptionPerTurn:number = pPlayerResources:GetUnitResourceDemandPerTurn(resource.ResourceType);
local powerConsumptionPerTurn:number = pPlayerResources:GetPowerResourceDemandPerTurn(resource.ResourceType);
local totalConsumptionPerTurn:number = unitConsumptionPerTurn + powerConsumptionPerTurn;
...
Where it would seem the logical thing to do would be something like so:
Spoiler :
...
local unitConsumptionPerTurn:number = pPlayerResources:GetUnitResourceDemandPerTurn(resource.ResourceType);
local powerConsumptionPerTurn:number = pPlayerResources:GetPowerResourceDemandPerTurn(resource.ResourceType);
local buildingConsumptionPerTurn:number = pPlayerResources:GetBuildingResourceDemandPerTurn(resource.ResourceType);
local totalConsumptionPerTurn:number = unitConsumptionPerTurn + powerConsumptionPerTurn + buildingConsumptionPerTurn;
...
My first hunch was to look around and try to find where "GetXResourceDemandPerTurn" is defined, since i am assuming for eg units it is summing up the instances of a unit and multiplying by the unit's <ResourceMaintenanceAmount> column entry in the Units_XP2 table, or something to that effect. Naturally I would just change the relevant types to buildings and refer to the columns in the aforementioned Building_ResourceCosts table.
A few lines below this chunk, where things are getting processed into being displayed, we have:
Spoiler :
if (totalConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_CONSUMPTION", totalConsumptionPerTurn);
if (unitConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_UNIT_CONSUMPTION_PER_TURN", unitConsumptionPerTurn);
end
if (powerConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_POWER_CONSUMPTION_PER_TURN", powerConsumptionPerTurn);
end
end
And again, logically, it would seem like the obvious answer would be to just extend the addition above here:
Spoiler :
if (totalConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_CONSUMPTION", totalConsumptionPerTurn);
if (unitConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_UNIT_CONSUMPTION_PER_TURN", unitConsumptionPerTurn);
end
if (powerConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_POWER_CONSUMPTION_PER_TURN", powerConsumptionPerTurn);
end
if (buildingConsumptionPerTurn > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_RESOURCE_BUILDING_CONSUMPTION_PER_TURN",buildingConsumptionPerTurn);
end
end
Outstanding Problems
-Where or how would I add the functionality "GetBuildingResourceDemandPerTurn" ? (Assuming this is the correct approach.) As I understand I will need to tell the game to replace the top panel file with my new file, but this seems like it would live somewhere else.
-How does Locale.Lookup("LOC_RESOURCE_POWER_CONSUMPTION_PER_TURN", powerConsumptionPerTurn); function? This looks like the game is using those two arguments to produce "-X resource per turn due to Power" type text.
-Alternatively to computing based on a "GetBuildingResourceDemandPerTurn" basis, I could infer the number consumed by buildings as a workaround; because if there's a difference between units+power and the total consumed, it must be buildings. (The Building_ResourceCosts table may not be hooked up to the UI, but it functions numerically, and the UI does correctly say the net income of the resource.)