[BNW] Reimplementing Dance of the Aurora as a building bonus

clamlol

Chieftain
Joined
Feb 10, 2022
Messages
20
As part of my balance mod, I have nerfed tundra hills to only give +1 Production, changed Dance of the Aurora (pantheon belief, +1 Faith from tundra tiles without forest) to grant Culture instead of Faith and added a new, cheap building called the Inuksuk which grants all treeless tundra tiles grant +1 Faith. To my great annoyance, I discovered that <Building_TerrainYieldChanges> affects forested tiles even though <Belief_TerrainYieldChanges> doesn't, so I was compelled to implement the Inuksuk so that it would create dummy features on the appropriate tiles (including the city center, if applicable) when built, and buff these features. (This is the same approach I took with Petra, although with that I left the city center unbuffed, as it is in vanilla.) The issue is that it's possible a forest on a tundra tile may get cut down later on, and as of right now I'm not sure how to hook into that event. Looking through this list of game events, I see HexYieldMightHaveChanged, UnitStateChangeDetected and a couple other interesting names, but I'm still too unfamiliar withLua and with this API to figure out how to make use of them. Could anyone offer some assistance?
 
Not certain but BuildFinished could fire on chops, but you could also use PlayerDoTurn and just recalculate every turn, its a bit heavy if its in multiple cities however. Also CityBoughtPlot could be of use.
 
Turns out HexYieldMightHaveChanged works fine:
Code:
function ValidForAuroraPower(plot)
    return plot:GetTerrainType() == GameInfoTypes["TERRAIN_TUNDRA"] and plot:GetFeatureType() == -1 and not plot:IsMountain()
end

-- Applies Aurora Power when a forest on a tundra tile is removed, if a city with an Inuksuk is nearby
function HexYieldMightHaveChanged(hex_x, hex_y)
    local plot = Map.GetPlot(hex_x, hex_y)
    if not plot or not ValidForAuroraPower(plot) then return end
    for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
        local player = Players[iPlayer]
        if player:IsAlive() then
            for city in player:Cities() do
                local city_plot = city:Plot()
                if city:IsHasBuilding(GameInfoTypes["BUILDING_INUKSUK"]) and Map.PlotDistance(hex_x, hex_y, city_plot:GetX(), city_plot:GetY()) <= 3 then
                    -- print("Applying Aurora Power at ", hex_x, hex_y, " due to ", city:GetName(), "'s Inuksuk")
                    plot:SetFeatureType(GameInfoTypes["FEATURE_AURORA_POWER"], -1)
                    return
                end
            end
        end
    end
end

Events.HexYieldMightHaveChanged.Add(HexYieldMightHaveChanged)
Still not really sure what API functions are available but ChatGPT seems to know so I will continue using it ¯\_(ツ)_/¯
 
Still not really sure what API functions are available
 
Back
Top Bottom