IsHasBuilding: Difference between revisions
From Civilization Modding Wiki
Jump to navigationJump to search
Killmeplease (talk | contribs) |
Killmeplease (talk | contribs) No edit summary |
||
Line 10: | Line 10: | ||
-- DateCreated: 12/28/2011 | -- DateCreated: 12/28/2011 | ||
-------------------------------------------------------------- | -------------------------------------------------------------- | ||
-- add culture when wonder completed | -- add culture when wonder completed | ||
function CulturePerPop(iPlayer) | function CulturePerPop(iPlayer) | ||
Line 32: | Line 32: | ||
end | end | ||
end | end | ||
-- add/remove culture upon population change | -- add/remove culture upon population change | ||
function ChangePopCulture(iX, iY, oldPopulation, newPopulation) | function ChangePopCulture(iX, iY, oldPopulation, newPopulation) | ||
Line 56: | Line 56: | ||
end | end | ||
end | end | ||
function IsValidPlayer(player) | function IsValidPlayer(player) | ||
return player ~= nil and player:IsAlive() and not player:IsBarbarian() | return player ~= nil and player:IsAlive() and not player:IsBarbarian() | ||
end | end | ||
GameEvents.PlayerDoTurn.Add( CulturePerPop ); | GameEvents.PlayerDoTurn.Add( CulturePerPop ); | ||
GameEvents.SetPopulation.Add( ChangePopCulture ); | GameEvents.SetPopulation.Add( ChangePopCulture ); | ||
GameEvents.CityCaptureComplete.Add( SetPopCulture ); | GameEvents.CityCaptureComplete.Add( SetPopCulture ); |
Revision as of 09:41, 14 February 2012
Description
pCity:IsHasBuilding(buildingID)
Returns true if a subject city has a building with a specified ID
Example
(from Culture per Population mod)
-- culturePerPopulation -- Author: Moriboe -- DateCreated: 12/28/2011 -------------------------------------------------------------- -- add culture when wonder completed function CulturePerPop(iPlayer) local buildingID, buildingTime; local player = Players[iPlayer]; if IsValidPlayer(player) then for pCity in player:Cities() do for row in GameInfo.Building_CultureChangePerPop() do -- has wonder? buildingID = GameInfo.Buildings[row.BuildingType].ID; if pCity:IsHasBuilding(buildingID) then -- just built? buildingTime = pCity:GetBuildingOriginalTime(buildingID); if buildingTime == Game:GetGameTurnYear() then pCity:ChangeJONSCulturePerTurnFromBuildings( math.floor(pCity:GetPopulation() / row.Pop * row.Culture)); end end end end end end -- add/remove culture upon population change function ChangePopCulture(iX, iY, oldPopulation, newPopulation) local pCity = Map.GetPlot(iX, iY):GetPlotCity(); local oldCulture, newCulture, change = 0; for row in GameInfo.Building_CultureChangePerPop() do if pCity:IsHasBuilding(GameInfo.Buildings[row.BuildingType].ID) then oldCulture = math.floor(oldPopulation * row.Culture / row.Pop); newCulture = math.floor(newPopulation * row.Culture / row.Pop); pCity:ChangeJONSCulturePerTurnFromBuildings(newCulture - oldCulture); end end end -- add culture upon capture function SetPopCulture(playerID, bCapital, iX, iY, newPlayerID) local pCity = Map.GetPlot(iX, iY):GetPlotCity(); for row in GameInfo.Building_CultureChangePerPop() do if pCity:IsHasBuilding(GameInfo.Buildings[row.BuildingType].ID) then pCity:ChangeJONSCulturePerTurnFromBuildings( math.floor(pCity:GetPopulation() / row.Pop * row.Culture)); end end end function IsValidPlayer(player) return player ~= nil and player:IsAlive() and not player:IsBarbarian() end GameEvents.PlayerDoTurn.Add( CulturePerPop ); GameEvents.SetPopulation.Add( ChangePopCulture ); GameEvents.CityCaptureComplete.Add( SetPopCulture );