alpaca
King of Ungulates
- Joined
- Aug 3, 2006
- Messages
- 2,322
I wrote a small script that adds culture to plots at the start of the turn if they have a resource. The amount and resources to do this for are defined in XML.
This is the script which can be added as, for example, an InGameUIAddin:
And this is what you need to add into an XML file that's updated into the database (obviously, replace the resources and yields with your values):
This is the script which can be added as, for example, an InGameUIAddin:
Code:
--[[
ResourceCulture.lua
Creator: alpaca
Last Change: 17.01.2011
Description:
Adds culture to certain resources defined via XML
]]--
-- define extra culture for each resource
local ResourceIDsToCultureTable = {}
for pResourceCultureChange in GameInfo.Resource_CultureChanges() do
ResourceIDsToCultureTable[GameInfo.Resources[pResourceCultureChange.ResourceType].ID] = pResourceCultureChange.Yield
end
-- loop through all plots, check for applicable resources, and change them
for iPlot = 0, Map.GetNumPlots() - 1 do
local pPlot = Map.GetPlotByIndex(iPlot)
local resType = pPlot:GetResourceType()
if ResourceIDsToCultureTable[resType] ~= nil and pPlot:GetCulture() == 0 then
pPlot:ChangeCulture(ResourceIDsToCultureTable[resType])
end
end
And this is what you need to add into an XML file that's updated into the database (obviously, replace the resources and yields with your values):
Code:
<Table name="Resource_CultureChanges">
<Column name="ResourceType" type="text" reference="Resources(Type)"/>
<Column name="Yield" type="integer" default="0"/>
</Table>
<Resource_CultureChanges>
<Row>
<ResourceType>RESOURCE_GOLD</ResourceType>
<Yield>1</Yield>
</Row>
<Row>
<ResourceType>RESOURCE_DYE</ResourceType>
<Yield>1</Yield>
</Row>
<Row>
<ResourceType>RESOURCE_INCENSE</ResourceType>
<Yield>2</Yield>
</Row>
</Resource_CultureChanges>