GameEvents.CityCanConstruct (Civ5 API)

From Civilization Modding Wiki
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 GameEvents.

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


Similar to CanDeclareWar, this allows provision of critera for the ability to construct a particular building (including Wonders, presumably) in a particular city. Based on the behaviour in the 1066 scenario, it seems that returns of false lead to the building not appearing in the list of buildings available to construct, rather than being greyed out, but this hasn't been specifically checked. It makes some sense, though, as there's no way to provide a tooltip to explain the greying out under this mechanism. As with CanDeclareWar, it's unclear whether multiple listeners' returns are combined with AND or OR; either seems possible according to the detailed explanation of how these events are handled.


Usage

void GameEvents.CityCanConstruct(PlayerID player, CityID city, BuildingType buildingType)


Event Type

Unknown

Parameters

player: the index identifying the player who might or might not be able to construct
city: the index identifying the city that might or might not be able to construct
buildingType: the ID of the building that might or might not be able to be constructed


Source code samples

TurnsRemaining.lua - DLC_04 DLC

DLC/DLC_04/Scenarios/1066Scenario/TurnsRemaining.lua
0080
GameEvents.CityCanConstruct.Add(function(iPlayer, iCity, iBuildingType)
0082
local iEngland = -1;
0083
local iLondonX = 43;
0084
local iLondonY = 17;
0086
for iPlayer = 0, 3, 1 do
0088
   local pPlayer = Players[iPlayer];
0089
   local playerStartPlot = pPlayer:GetStartingPlot();
0091
   -- London?
0092
   if (playerStartPlot:GetX() == iLondonX and playerStartPlot:GetY() == iLondonY) then
0093
   iEngland = iPlayer;
0096
   break;
0099
   end
0100
   end
0102
   local pPlayer = Players[iPlayer];
0103
   local pCity = pPlayer:GetCityByID(iCity);
0105
   -- Shire Courts
0106
   if (iBuildingType == GameInfo.Buildings["BUILDING_COURTHOUSE"].ID) then
0108
   -- Only 8+ tiles from London
0109
   if (Map.PlotDistance(pCity:GetX(), pCity:GetY(), iLondonX, iLondonY) < 8) then
0110
   return false;
0111
   end
0113
   -- Only in originally Anglo-Saxon cities
0114
   if (pCity:GetOriginalOwner() ~= iEngland) then
0115
   return false;
0116
   end
0118
   end
0120
   -- Domesday Book (only in London)
0121
   if (iBuildingType == GameInfo.Buildings["BUILDING_NATIONAL_COLLEGE"].ID) then
0123
   if (pCity:GetX() ~= iLondonX or pCity:GetY() ~= iLondonY) then
0124
   return false;
0125
   end
0127
   end
0129
   return true;
0132
   end);



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.