How to loop a city's buildings?

You have to iterate through each row in GameInfo.Buildings() and for every row ask whether the city has the building. Like the following, which would 'unpillage' any pillaged building in all of a player's cities.
Code:
local pPlayer = Players[iPlayer]
local pCities = pPlayer:GetCities();
if pCities:GetCount() > 0 then
	for i, pCity in pCities:Members() do
		for BuildingRow in GameInfo.Buildings() do
			local iBuildingIndex = BuildingRow.Index
			if pCity:GetBuildings():HasBuilding(iBuildingIndex) then
				if pCity:GetBuildings():IsPillaged(iBuildingIndex) then
					pCity:GetBuildings():SetPillaged(iBuildingIndex, false)
				end
			end
		end
	end
end
 
You have to iterate through each row in GameInfo.Buildings() and for every row ask whether the city has the building. Like the following, which would 'unpillage' any pillaged building in all of a player's cities.
Code:
local pPlayer = Players[iPlayer]
local pCities = pPlayer:GetCities();
if pCities:GetCount() > 0 then
    for i, pCity in pCities:Members() do
        for BuildingRow in GameInfo.Buildings() do
            local iBuildingIndex = BuildingRow.Index
            if pCity:GetBuildings():HasBuilding(iBuildingIndex) then
                if pCity:GetBuildings():IsPillaged(iBuildingIndex) then
                    pCity:GetBuildings():SetPillaged(iBuildingIndex, false)
                end
            end
        end
    end
end

interesting, is it an UA of some civ?
 
Top Bottom