[BTS] get buildings of every city

Louis the XIV

Sun King
Joined
Jun 23, 2020
Messages
837
Location
Court of Versailles
How can I loop through all the buildings in all the cities of a player? Or maybe just check if the city has a building.
I managed to make the looping through all cities work

Code:
                (loopCity, iter) = player.firstCity(false)
        
            while(loopCity):
                        if ( not loopCity.isNone()):
but I don't know how to check if the loopCity has a building.
Any help appreciated, thanks!
 
Code:
while loopCity:
    if not loopCity.isNone():
        for iBuilding in range(gc.getNumBuildingInfos()):
            if loopCity.getBuildingCount(iBuilding) > 0:
                # whatever you want to to when the city has the building
For a specific building do e.g.
Code:
iBuilding = GC.getInfoTypeForString("BUILDING_GRANARY")

Be aware that there are multiple buildings of the same building class, like unique buildings. So depending on what you want to achieve you may need to go via building classes instead.
 
Code:
while loopCity:
    if not loopCity.isNone():
        for iBuilding in range(gc.getNumBuildingInfos()):
            if loopCity.getBuildingCount(iBuilding) > 0:
                # whatever you want to to when the city has the building
For a specific building do e.g.
Code:
iBuilding = GC.getInfoTypeForString("BUILDING_GRANARY")

Be aware that there are multiple buildings of the same building class, like unique buildings. So depending on what you want to achieve you may need to go via building classes instead.
Thanks!
Yeah I think I'll go with building classes instead then.
 
Top Bottom