Events.SerialEventCityPopulationChanged (Civ5 API)

From Civilization Modding Wiki
Revision as of 18:48, 19 September 2012 by DonQuich (talk | contribs) (Bot update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This page is a part of the Lua and UI Reference (Civ5).


Function.png This function is a member of Events.

This is a static method, invoke it with a dot.


This event is triggered every time the population of a city changes. The triggering city need not belong to the active (human) player, although the city needs to have been discovered by that player. Cities that the active player has no knowledge of will not trigger this event.


Usage

void Events.SerialEventCityPopulationChanged(float hexX, int hexY, int newPop, int unknown)


Event Type

Regular event: you can subscribe to it through Events.SerialEventCityPopulationChanged.Add(<function handler>) or invoke it directly through Events.SerialEventCityPopulationChanged(<arguments list>).

Parameters

hexX: Hex x-coordinate of the city whose population changed which can be converted to map grid coordinates with the ToGridFromHex function (see example)
hexY: Hex y-coordinate of the city whose population changed which can be converted to map grid coordinates with the ToGridFromHex function (see example)
newPop: the new population of the city whose population changed
unknown: unsure what the meaning of this argument is, although it would always seem to be half of iNewPop, rounded up; possibly related to city graphics


Examples

function onCityPopulationChanged(iHexX, iHexY, iPopulation, iUnknown )
local pPlot = Map.GetPlot(ToGridFromHex(iHexX, iHexY))
local pCity = pPlot:GetPlotCity()
local iOwner = pCity:GetOwner()
print(string.format("%s (owned by %s) has grown to size %d", pCity:GetName(), Players[iOwner]:GetName(), iPopulation))
end
Events.SerialEventCityPopulationChanged.Add(onCityPopulationChanged)


Source code samples

DebugMode.lua

UI/InGame/DebugMode.lua
0167
Events.SerialEventCityPopulationChanged( g_iHexX, g_iHexY, g_iPopulation, iCitySize );



The initial version of this page was created by the Civ5 API Bot, see the Civ5 API Reference FAQ. Some of the texts come from the 2kgames' wiki and most of code samples are copyrighted to Firaxis.
Functions' signatures were either copied from the 2kgames' wiki, or infered from the Lua source files and the binaries. Errors are possible.
Contributors may find help in the Contributors guide to the Civ5 API.