Klisz
King
- Joined
- Aug 18, 2014
- Messages
- 804
Oh man, that's a shame...I guess I could just make 36 dummy buildings unless you know a better way
Oh, to elaborate on what I meant by "binary logic" - you make one dummy with +1 tourism, one with +2, one with +4, and so on up to (in this case) +32 - see this thread for more information. It's perfectly doable, I just wanted to make sure you were aware that you'd need several dummy buildings and not just one. ...and now after writing this, I see that LeeS has already posted a solution. I'll leave this up for posterity, though; that way future archeologists uncovering the ancient Civfanatics culture can record exactly how much better at Lua LeeS was than Klisz.

Spoiler :
Code:
local iCultureDummy = GameInfoTypes.BUILDING_SENSHI_NENETS_CULTURE_DUMMY
local iTourismDummy1 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_1
local iTourismDummy2 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_2
local iTourismDummy4 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_4
local iTourismDummy8 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_8
local iTourismDummy16 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_16
local iTourismDummy32 = GameInfoTypes.BUILDING_SENSHI_NENETS_TOURISM_DUMMY_32
local iNenetsCiv = GameInfoTypes.CIVILIZATION_SENSHI_NENETS
local iDeer = GameInfoTypes.RESOURCE_DEER
function toBits(num)
-- returns a table of bits, least significant first.
t={} -- will contain the bits
while num>0 do
local rest=math.fmod(num,2)
t[#t+1]=rest
num=(num-rest)/2
end
return t
end
local tGreatWorkBuildings = {} -- Cache all the GWoM buildings ahead of time to avoid resource-intensive database calls every turn
for tRow in GameInfo.Buildings("GreatWorkCount > 0 AND GreatWorkSlotType = 'GREAT_WORK_SLOT_MUSIC'") do
tGreatWorkBuildings[tRow.ID] = tRow.GreatWorkCount
end
function UpdateDummyBuildings(iPlayer)
local pPlayer = Players[iPlayer]
if pPlayer:GetCivilizationType() == iNenetsCiv then
for pCity in pPlayer:Cities() do
local iWorkedDeer = 0
local iUnfilledMusic = 0
for iBuilding, iGreatWorkCount in pairs(tGreatWorkBuildings) do
if pCity:IsHasBuilding(iBuilding) then
iUnfilledMusic = iUnfilledMusic + (iGreatWorkCount - pCity:GetNumGreatWorksInBuilding(iBuilding))
end
end
for i = 0, pCity:GetNumCityPlots()-1, 1 do
local pPlot = pCity:GetCityIndexPlot(i)
if pPlot and pCity:IsWorkingPlot(pPlot) and pPlot:pPlot:GetResourceType() == iDeer then
iWorkedDeer = iWorkedDeer + 1
end
end
local iResult = iWorkedDeer
if iResult > iUnfilledMusic then iResult = iUnfilledMusic end
pCity:SetNumRealBuilding(iCultureDummy, iResult)
toBits(iResult*2)
pCity:SetNumRealBuilding(iTourismDummy1, t[1])
pCity:SetNumRealBuilding(iTourismDummy2, t[2])
pCity:SetNumRealBuilding(iTourismDummy4, t[3])
pCity:SetNumRealBuilding(iTourismDummy8, t[4])
pCity:SetNumRealBuilding(iTourismDummy16, t[5])
pCity:SetNumRealBuilding(iTourismDummy32, t[6])
pCity:SetNumRealBuilding(iCultureDummy, iResult)
end
end
end
function UpdateDummyBuildingsUI()
if bPopup then
UpdateDummyBuildings(Game:GetActivePlayer())
end
end
GameEvents.PlayerDoTurn.Add(UpdateDummyBuildings)
Events.SerialEventCityInfoDirty.Add(UpdateDummyBuildingsUI)
Yeah. I guess maybe a 5% chance would be the most ideal, considering it's Snow of all things.
Code:
local iNenetsCiv = GameInfoTypes.CIVILIZATION_SENSHI_NENETS
local iDeer = GameInfoTypes.RESOURCE_DEER
local iSnow = GameInfoTypes.TERRAIN_SNOW
local iNotification = NotificationTypes.NOTIFICATION_DISCOVERED_BONUS_RESOURCE
function DeerSpawn(iPlayer)
local pPlayer = Players[iPlayer]
if pPlayer:GetCivilizationType() == iNenetsCiv then
local CheckedPlots = {} -- to avoid having higher chances of deer spawning if a plot is within range of multiple cities
for pCity in pPlayer:Cities() do
for i = 0, pCity:GetNumCityPlots()-1, 1 do
local pPlot = pCity:GetCityIndexPlot(i)
if pPlot and pPlot:GetTerrainType() == iSnow pPlot:pPlot:GetResourceType() == -1 and (not CheckedPlots[pPlot:GetPlotIndex()]) then
CheckedPlots[pPlot:GetPlotIndex()] = 1
if Game.Rand(100, "Nenets deer spawn") < 5 then
pPlot:SetResourceType(iDeer)
pPlot:SetNumResource(1)
pPlayer:AddNotification(iNotification, Locale.ConvertTextKey("TXT_KEY_NOTIFICATION_FOUND_RESOURCE","TXT_KEY_RESOURCE_DEER"), Locale.ConvertTextKey("TXT_KEY_NOTIFICATION_SUMMARY_FOUND_RESOURCE","TXT_KEY_RESOURCE_DEER"),pPlot:GetX(),pPlot:GetY(),iDeer)
end
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(DeerSpawn)
They do.
In retrospect I now realize that that doesn't matter either way because there's a workaround to get the plot from GreatPersonExpended anyway (well, from UnitPrekill, but since a UnitPrekill always comes after a GreatPersonExpended we can set a boolean variable to detect whether a given UnitPrekill is a GP expending).
For the Tadibya:
Code:
local iTadibya = GameInfoTypes.UNIT_SENSHI_TADIBYA
local iSpawnDeer = GameInfoTypes.IMPROVEMENT_SENSHI_SPAWNDEER
local iDeer = GameInfoTypes.RESOURCE_DEER
local bTadibya = false
GameEvents.GreatPersonExpended.Add(function(iPlayer, iUnitType)
if iUnitType == iTadibya then
bTadibya = true
end
end)
GameEvents.UnitPrekill.Add(function(iPlayer, iUnitID, iUnitType, iX, iY, bDelay, iByPlayer)
if bTadibya then
local pPlot = Map.GetPlot(iX, iY)
if pPlot:GetImprovementType() == iSpawnDeer then
pPlot:SetImprovementType(-1)
pPlot:SetResourceType(iDeer)
pPlot:SetNumResource(1)
end
bTadibya = false
end
end)
And the Samoyed; I've assumed that, if a Samoyed is owned by a non-Nenets civ (via a city-state or something) it should check for that civ's territory, not for Nenets territory. Also, this one will need PlotIterators included in the mod and imported into VFS.
Code:
include("PlotIterators.lua")
local iSamoyed = GameInfoTypes.UNIT_SENSHI_SAMOYED
local iMoveDeer = GameInfoTypes.IMPROVEMENT_SENSHI_MOVEDEER
local iDeer = GameInfoTypes.RESOURCE_DEER
local iSnow = GameInfoTypes.TERRAIN_SNOW
local bSamoyed = false
GameEvents.GreatPersonExpended.Add(function(iPlayer, iUnitType)
if iUnitType == iSamoyed then
bSamoyed = true
end
end)
GameEvents.UnitPrekill.Add(function(iPlayer, iUnitID, iUnitType, iX, iY, bDelay, iByPlayer)
local pPlayer = Players[iPlayer]
if bSamoyed then
local pPlot = Map.GetPlot(iX, iY)
if pPlot:GetImprovementType() == iMoveDeer then
pPlot:SetImprovementType(-1)
pPlot:SetResourceType(-1)
pPlot:SetNumResource(0)
local pDeerPlot = nil
local iDistance = 99999
for pCity in pPlayer:Cities() do
for pAreaPlot in PlotAreaSpiralIterator(pCity:GetPlot(), 6, SECTOR_NORTH, DIRECTION_CLOCKWISE, DIRECTION_OUTWARDS, CENTRE_EXCLUDE) do -- 5 is the maximum distance a city can expand naturally, but I'm adding 1 to account for potential citadels etc
if pAreaPlot and pAreaPlot:GetOwner() == iPlayer and pPlot:GetImprovementType() == -1 and pPlot:GetTerrainType() ~= iSnow then
local iNewDistance = Map.PlotDistance(pAreaPlot:GetX(), pAreaPlot:GetY(), iX, iY)
if iNewDistance < iDistance then
pDeerPlot = pAreaPlot
iDistance = iNewDistance
end
end
end
end
if pDeerPlot then
pDeerPlot:SetResourceType(iDeer, 1)
pDeerPlot:SetNumResource(1)
end
end
bSamoyed = false
end
end)