[BNW] Could I maintain promotions during constant time from the points of gaining or removing them?

Lenin1870

Chieftain
Joined
Mar 16, 2013
Messages
50
Code:
function YuyukoFunction(iPlayerID)
    local pPlayer = Players[iPlayerID]
    if pPlayer:GetCivilizationType() == pYuyukoCiv and pPlayer:IsAlive() then
        for pUnit in pPlayer:Units() do
            if not pUnit:IsHasPromotion(GameInfoTypes["PROMOTION_RINMEIKAN_YUYUKO"]) then
                save(pUnit, "iCurrentTurn", Game.GetGameTurn())
            end
            save(pUnit, "iTurnThree", load(pUnit, "iCurrentTurn") + 2)
            iTurnThree = load(pUnit, "iTurnThree")
            local ActivityType = pUnit:GetActivityType()
            if pUnit:IsCombatUnit() then
                if (ActivityType == ActivityTypes["NO_ACTIVITY"] or ActivityType == ActivityTypes["ACTIVITY_SLEEP"] or ActivityType == ActivityTypes["ACTIVITY_HOLD"] or ActivityType == ActivityTypes["ACTIVITY_HEAL"] or ActivityType == ActivityTypes["ACTIVITY_SENTRY"]) and (pUnit:GetGarrisonedCity() or (not pUnit:IsInCombat() and iTurnThree <= load(pUnit, "iCurrentTurn"))) then
                    save(pUnit, "iCurrentTurnReceivePromotion", Game.GetGameTurn())
                    pUnit:SetHasPromotion(GameInfoTypes["PROMOTION_RINMEIKAN_YUYUKO"], true)
                elseif pUnit:IsHasPromotion(GameInfoTypes["PROMOTION_RINMEIKAN_YUYUKO"]) then
                    save(pUnit, "iCurrentTurnDeletePromotion", Game.GetGameTurn())
                    save(pUnit, "GainDebuff", Game.GetGameTurn() + 4)
                    ActDebuff = load(pUnit, "GainDebuff")
                    if not (ActivityType == ActivityTypes["NO_ACTIVITY"] or ActivityType == ActivityTypes["ACTIVITY_SLEEP"] or ActivityType == ActivityTypes["ACTIVITY_HOLD"] or ActivityType == ActivityTypes["ACTIVITY_HEAL"] or ActivityType == ActivityTypes["ACTIVITY_SENTRY"]) and ((not pUnit:GetGarrisonedCity() and load(pUnit, "iCurrentTurnReceivePromotion") > 14) or (pUnit:IsInCombat() and load(pUnit, "iCurrentTurnReceivePromotion") - iTurnThree > 14)) then
                        pUnit:SetHasPromotion(GameInfoTypes["PROMOTION_RINMEIKAN_YUYUKO"], false)
                    end
                end
                if iCurrentTurn ~= nil and ActDebuff ~= nil then
                    if not pUnit:IsHasPromotion(GameInfoTypes["PROMOTION_RINMEIKAN_YUYUKO"]) and load(pUnit, "iCurrentTurnDeletePromotion") > ActDebuff then
                        pUnit:SetHasPromotion(GameInfoTypes["PROMOTION_RINMEIKAN_YUYUKO_DEBUFF"], true)
                    else
                        pUnit:SetHasPromotion(GameInfoTypes["PROMOTION_RINMEIKAN_YUYUKO_DEBUFF"], false)
                    end
                end
            end
        end
    end
end
GameEvents.PlayerDoTurn.Add(YuyukoFunction)

Achieving the aim, I first attempted to find Lua API about 'constant' turn. But the functions did not find. So I second try to 'constrain' Game.GetGameTurn() using SaveUtils and if statements. Likewise, I failed.

So I have a question to be equivalent to title. How to give and maintain promotions during constant time? Is it possible from Lua?
 
I've read this four times now and still have no idea what you're trying to achieve :(

Rather than giving code that doesn't work, it would be better to give (as simply as possible) the sequence of effects you're trying to achieve, eg

Unit stops on hills, unit given promotion X for free, unit doesn't move next turn so given promotion Y (as well / instead of). If unit moves, promotions X and Y are removed.
 
Back
Top Bottom