[BNW] Promotion to civilian

lucaspalasios

Chieftain
Joined
Jul 21, 2016
Messages
13
Location
Goiânia, Brazil
Is it possible to make a building that gives civilians a promotion? Cause I'm working on a wonder that gives Great Prophets and Missionaries a promotion that ignores terrein costs. Can it be done? And, if so, does anyone know how to do it?
 
Some Lua-trickery will do the job (set this as an InGame UI-addin):
Code:
local iWonder = GameInfoTypes.BUILDING_MY_WONDER; --change this one to your wonder
local tValidUnits = {[GameInfoTypes.UNIT_PROPHET]=true, [GameInfoTypes.UNIT_MISSIONARY]=true};
local iPromotion = GameInfoTypes.PROMOTION_IGNORE_TERRAIN_COST --(yes, that is the actual name of the promotion that the scout uses)
local bPlayerHasWonder = false;


function GrantWonderPromotion(iPlayer)

local pPlayer = Players[iPlayer];

for pCity in pPlayer:Cities() do --loop through the player's cities
     if pCity:IsHasBuilding(iWonder) then
         print("this player (ID="..iPlayer..") has the wonder");
         bPlayerHasWonder = true;
    end
end

if bPlayerHasWonder then --only start looping through the player's units when we know that he has the wonder!
     for pUnit in pPlayer:Units() do --loop through the player's units
          if not pUnit:IsHasPromotion(iPromotion) and tValidUnits[pUnit:GetUnitType()] then --if the unit does not have the promotion and is a 'valid unit'
                pUnit:SetHasPromotion(iPromotion,true);
                print("a unit was given the promotion");
          end
     end
end

bPlayerHasWonder = false; --reset the variable so we can use it in our check next time as well
end

GameEvents.PlayerDoTurn.Add(GrantWonderPromotion)

NOTE: Should the promotions be removed from those units if the player no longer has the wonder (which could happens if the city with the wonder was captured), because right now this isn't included!
 
Hmmm. That's either something I wrote a long time ago or it is a bit of a frankenstien code.
Code:
local iWonder = GameInfoTypes.BUILDING_MY_WONDER; --change this one to your wonder
local tValidUnits = {[GameInfoTypes.UNIT_PROPHET]=true, [GameInfoTypes.UNIT_MISSIONARY]=true};
local iPromotion = GameInfoTypes.PROMOTION_IGNORE_TERRAIN_COST --(yes, that is the actual name of the promotion that the scout uses)


function GrantWonderPromotion(iPlayer)
    local pPlayer = Players[iPlayer];
    if pPlayer:CountNumBuildings(iWonder) > 0 then --only start looping through the player's units when we know that he has the wonder!
        for pUnit in pPlayer:Units() do --loop through the player's units
            if tValidUnits[pUnit:GetUnitType()] and not pUnit:IsHasPromotion(iPromotion) then --if the unit does not have the promotion and is a 'valid unit'
                pUnit:SetHasPromotion(iPromotion,true);
                print("a unit was given the promotion");
            end
        end
    end
end
GameEvents.PlayerDoTurn.Add(GrantWonderPromotion)

Problem with the code though is that it gives the promotion to all units owned by the player and not just those units constructed in the same city.
 
Hmmm. That's either something I wrote a long time ago or it is a bit of a frankenstien code.
Code:
[..]
    if pPlayer:CountNumBuildings(iWonder) > 0 then
        [..]
I didn't know that was possible. Today I learned! :D

Problem with the code though is that it gives the promotion to all units owned by the player and not just those units constructed in the same city.
I thought that that was the intention (making it similar to the way the Great Lighthouse-promotion is applied in a sense).
 
Top Bottom