StandardGaussian
Chieftain
- Joined
- Mar 8, 2017
- Messages
- 15
Hey there,
A while back, I was trying to implement an odd sort of adjacency bonus detailed in this topic:
https://forums.civfanatics.com/threads/specific-resource-adjacency-bonuses-for-districts.612141
My workaround works 99% of the time, though of course it's far from ideal: you get a magic building all of a sudden, which isn't intuitive, and it's possible to stop meeting the adjacency requirements but still get the bonus (though the chances are kind of small).
However, since @Gleb Bazov kindly implemented a script to help me with culture bombs on improvements over strategic resources, I figured it would be best to re-implement that adjacency bonus in Lua, especially because I can't implement a desired leader trait in xml/sql either, so starting to learn how to mod Civ through Lua seemed like a good plan. So far, so good in terms of getting all the relevant districts and checking the surrounding plots for viable resources, but I have no idea how to actually go about setting the adjacency bonus in Lua. The limited API that's been gleaned by @Gedemon so far doesn't seem to show many setter methods, and it seems like knowledge about how to manipulate the game world (rather than just read it for UI purposes) is being done by word of mouth.
I took a stab at guessing the setter method, assuming that it would be a member method of a district object (insofar as Lua allows such things), but something like:
Where pDist comes from a table populated by:
predictably yields the result "function expected instead of nil"
Since setting plot ownership is done through WorldBuilder for the culture bomb:
I assume something similar is true for hand-crafting adjacency bonuses through Lua, but without a reliable API reference I feel pretty clueless what that might look like. What does WorldBuilder.CityManager() return? What are the parameters for the function I'm looking for? Can anyone lend a hand for this?
A while back, I was trying to implement an odd sort of adjacency bonus detailed in this topic:
https://forums.civfanatics.com/threads/specific-resource-adjacency-bonuses-for-districts.612141
My workaround works 99% of the time, though of course it's far from ideal: you get a magic building all of a sudden, which isn't intuitive, and it's possible to stop meeting the adjacency requirements but still get the bonus (though the chances are kind of small).
However, since @Gleb Bazov kindly implemented a script to help me with culture bombs on improvements over strategic resources, I figured it would be best to re-implement that adjacency bonus in Lua, especially because I can't implement a desired leader trait in xml/sql either, so starting to learn how to mod Civ through Lua seemed like a good plan. So far, so good in terms of getting all the relevant districts and checking the surrounding plots for viable resources, but I have no idea how to actually go about setting the adjacency bonus in Lua. The limited API that's been gleaned by @Gedemon so far doesn't seem to show many setter methods, and it seems like knowledge about how to manipulate the game world (rather than just read it for UI purposes) is being done by word of mouth.
I took a stab at guessing the setter method, assuming that it would be a member method of a district object (insofar as Lua allows such things), but something like:
Code:
pDist:SetAdjacencyBonuses("YIELD_PRODUCTION", 2)
Where pDist comes from a table populated by:
Code:
function GetAllPlayerDistrictsOfType(PlayerID, xDistrictType)
local tTemporaryTable = {}
local pPlayer = Players[PlayerID]
if (pPlayer == nil) then
return tTemporaryTable
end
local pPlayerCities = pPlayer:GetCities()
if (pPlayerCities == nil) then
return tTemporaryTable
end
local districtID = GameInfo.Districts[xDistrictType].Index
print ("District ID is " .. districtID)
for k, pCity in pPlayerCities:Members() do
local pDistrict = pCity:GetDistricts():GetDistrict(districtID)
if (pDistrict ~= nil) then
print ("Found appropriate district. Adding to district table.")
table.insert(tTemporaryTable,pDistrict)
else
print ("District not found.")
end
end
return tTemporaryTable
end
predictably yields the result "function expected instead of nil"
Since setting plot ownership is done through WorldBuilder for the culture bomb:
Code:
WorldBuilder.CityManager():SetPlotOwner( pPickPlot:GetX(), pPickPlot:GetY(), pPlayer, pCityID )
Last edited: