GameEvents.PlayerDoTurn (Civ5 API)

From Civilization Modding Wiki
Revision as of 20:27, 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 GameEvents.

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


Fired once per turn for each player (not just active/human player). Modder experimentation has found that it is fired at the start of turn; also, it seems not to run for the first turn of the game (for all players), runs only for human player on the second turn, and thereafter it runs for all players. There is no indication as to why this is.


Usage

void GameEvents.PlayerDoTurn(PlayerID player)


Event Type

Unknown

Parameters

player: The ID of the player whose turn is in question


Source code samples

Too many occurences. Only 50 out of 5 are listed.

TurnsRemaining.lua - DLC_02 DLC

DLC/DLC_02/Scenarios/NewWorldScenario/TurnsRemaining.lua
0302
GameEvents.PlayerDoTurn.Add(function(iPlayer)
0304
-- Only on first player's turn
0305
if (iPlayer > 0) then
0306
return false;
0307
end
0309
--(KLUDGE - using an unused modern era CvGame data field as a counter)
0310
local iGenerateTreasureTurn = Game:GetNoNukesCount();
0311
local iGameTurn = Game.GetGameTurn();
0312
local iFeatureID;
0314
-- Time to generate a treasure?
0315
if (iGameTurn > iGenerateTreasureTurn) then
0317
iFeatureID = GameInfoTypes["FEATURE_EL_DORADO"];
0318
SpawnTreasure(iFeatureID);
0320
iFeatureID = GameInfoTypes["FEATURE_POTOSI"];
0321
SpawnTreasure(iFeatureID);
0323
-- Reset turn of next treasure generation
0324
local iRandom = Game.Rand(20, "Delay between natural wonder treasures");
0325
Game:ChangeNoNukesCount(5 + iRandom);
0326
end
0328
-- AI units on high difficulty
0329
local unit;
0330
local iHandicap = Game:GetHandicapType();
0332
if (iGameTurn == 10) then
0333
for iLoopPlayer = 1, 5, 1 do
0334
   local pLoopPlayer = Players[iLoopPlayer];
0335
   if (pLoopPlayer:IsAlive() and pLoopPlayer:GetStartingPlot():GetX() > 50) then
0336
   if (iHandicap > 5) then
0337
   iUnitID = GameInfoTypes["UNIT_SETTLER"];
0338
   unit = pLoopPlayer:InitUnit (iUnitID, pLoopPlayer:GetStartingPlot():GetX(), pLoopPlayer:GetStartingPlot():GetY());
0339
   unit:JumpToNearestValidPlot();
0340
   iUnitID = GameInfoTypes["UNIT_PIKEMAN"];
0341
   unit = pLoopPlayer:InitUnit (iUnitID, pLoopPlayer:GetStartingPlot():GetX(), pLoopPlayer:GetStartingPlot():GetY());
0342
   unit:JumpToNearestValidPlot();
0343
   end
0344
   if (iHandicap > 6) then
0345
   iUnitID = GameInfoTypes["UNIT_CARAVEL"];
0346
   unit = pLoopPlayer:InitUnit (iUnitID, pLoopPlayer:GetStartingPlot():GetX(), pLoopPlayer:GetStartingPlot():GetY(), GameInfoTypes.UNITAI_EXPLORE_SEA, DirectionTypes.DIRECTION_WEST);
0347
   unit:JumpToNearestValidPlot();
0348
   end
0349
   end
0350
   end
0351
   end
0353
   if (iGameTurn == 15) then
0354
   for iLoopPlayer = 1, 5, 1 do
0355
   local pLoopPlayer = Players[iLoopPlayer];
0356
   if (pLoopPlayer:IsAlive()and pLoopPlayer:GetStartingPlot():GetX() > 50) then
0357
   if (iHandicap > 6) then
0358
   iUnitID = GameInfoTypes["UNIT_SETTLER"];
0359
   unit = pLoopPlayer:InitUnit (iUnitID, pLoopPlayer:GetStartingPlot():GetX(), pLoopPlayer:GetStartingPlot():GetY());
0360
   unit:JumpToNearestValidPlot();
0361
   iUnitID = GameInfoTypes["UNIT_PIKEMAN"];
0362
   unit = pLoopPlayer:InitUnit (iUnitID, pLoopPlayer:GetStartingPlot():GetX(), pLoopPlayer:GetStartingPlot():GetY());
0363
   unit:JumpToNearestValidPlot();
0364
   end
0365
   end
0366
   end
0367
   end
0369
   if (iGameTurn == 20) then
0370
   for iLoopPlayer = 1, 5, 1 do
0371
   local pLoopPlayer = Players[iLoopPlayer];
0372
   if (pLoopPlayer:IsAlive() and pLoopPlayer:GetStartingPlot():GetX() > 50) then
0373
   if (iHandicap > 3) then
0374
   iUnitID = GameInfoTypes["UNIT_SETTLER"];
0375
   unit = pLoopPlayer:InitUnit (iUnitID, pLoopPlayer:GetStartingPlot():GetX(), pLoopPlayer:GetStartingPlot():GetY());
0376
   unit:JumpToNearestValidPlot();
0377
   iUnitID = GameInfoTypes["UNIT_PIKEMAN"];
0378
   unit = pLoopPlayer:InitUnit (iUnitID, pLoopPlayer:GetStartingPlot():GetX(), pLoopPlayer:GetStartingPlot():GetY());
0379
   unit:JumpToNearestValidPlot();
0380
   end
0381
   end
0382
   end
0383
   end
0385
   return false;
0386
   end);


TurnsRemaining.lua - DLC_04 DLC

DLC/DLC_04/Scenarios/1066Scenario/TurnsRemaining.lua
0222
GameEvents.PlayerDoTurn.Add(function(iPlayer)
0224
-- Only on first player's turn
0225
if (iPlayer > 0) then
0226
return false;
0227
end
0230
local savedData = Modding.OpenSaveData();
0231
local iValue = savedData.GetValue("TurnsBetweenBonuses");
0233
if (iValue ~= nil) then
0235
local iTemp = math.floor(Game.GetGameTurn() / iValue);
0236
if (Game.GetGameTurn() > 0 and Game.GetGameTurn()< 51 and iTemp * iValue == Game.GetGameTurn()) then
0238
for iPlayer = 0, 3, 1 do
0240
   local pPlayer = Players[iPlayer];
0241
   local playerStartPlot = pPlayer:GetStartingPlot();
0243
   -- Anglo-Saxon England?
0244
   if (playerStartPlot:GetX() == 43 and playerStartPlot:GetY() == 17) then
0245
   CollectTaxes(iPlayer);
0246
   else
0247
   NewRecruits(iPlayer);
0248
   end
0249
   end
0250
   end
0251
   end
0252
   end);


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/SteampunkScenario/TurnsRemaining.lua
0498
GameEvents.PlayerDoTurn.Add(function(iPlayer)
0499
local iTurn = Game.GetGameTurn();
0501
-- Update on Barbarian player's turn (after all major civs take their turn) so that we are fair to all players
0502
if (iPlayer == 63) then
0503
UpdateMostAdvancedUnits();
0504
UpdatePlayerStatus();
0505
end
0507
return false;
0508
end);


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/MedievalScenario/TurnsRemaining.lua
0144
GameEvents.PlayerDoTurn.Add(function(iPlayer)
0145
local iReformationTurn = GetPersistentProperty("ReformationStart");
0146
local iTurn = Game.GetGameTurn();
0148
-- Only on first player's turn
0149
if (iPlayer > 0 or iTurn < 1) then
0150
return false;
0151
end
0153
if (iReformationTurn > -1) then
0154
if (iReformationTurn == iTurn) then
0155
StartReformation();
0156
elseif (GetPersistentProperty("SecondReformer") == iTurn) then
0157
ReformationPhaseTwo();
0158
elseif (GetPersistentProperty("ThirdReformer") == iTurn) then
0159
ReformationPhaseThree();
0160
end
0161
else
0162
if (Game.GetGameTurnYear() > 1514) then
0163
SetPersistentProperty("ReformationStart", iTurn + 1);
0164
SetPersistentProperty("SecondReformer", iTurn + 4);
0165
SetPersistentProperty("ThirdReformer", iTurn + 7);
0166
end
0167
end
0169
ScoreHolyCities();
0171
if (iTurn == 40) then
0172
BringInMongols();
0173
elseif (iTurn == 50 or iTurn == 60 or iTurn == 70 or iTurn == 85 or iTurn == 110) then
0174
ReinforceMongols();
0175
elseif (iTurn == 150) then
0176
MongolsPullOut();
0177
end
0179
return false;
0180
end);


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/FallOfRomeScenario/TurnsRemaining.lua
0233
GameEvents.PlayerDoTurn.Add(function(iPlayer)
0235
--if (iPlayer ~= nil) then
0236
--   print("GameEvents.PlayerDoTurn.Add, iPlayer: " .. iPlayer);
0237
--else
0238
--   print("GameEvents.PlayerDoTurn.Add, iPlayer: nil");
0239
--end
0241
local savedData = Modding.OpenSaveData();
0242
local iCitiesCaptured = 0;
0243
if (IsWesternRoman(iPlayer)) then
0244
iCitiesCaptured = savedData.GetValue("WesternRomeCitiesCaptured");
0245
savedData.SetValue("WesternRomeCitiesCaptured", 0);
0246
elseif (IsEasternRoman(iPlayer)) then
0247
iCitiesCaptured = savedData.GetValue("EasternRomeCitiesCaptured")
0248
savedData.SetValue("EasternRomeCitiesCaptured", 0);
0249
end
0251
print("GameEvents.PlayerDoTurn.Add, iCitiesCaptured: " .. iCitiesCaptured);
0252
if (iCitiesCaptured > 0) then
0253
print("GameEvents.PlayerDoTurn.Add, rewarding culture");
0254
Players[iPlayer]:ChangeJONSCulture(20 * iCitiesCaptured);
0255
end
0257
if (Players[iPlayer]:HasPolicy(GameInfo.Policies["POLICY_BARBARIAN_FINISHER"].ID)) then
0258
if (Players[iPlayer]:GetJONSCulture() > 0) then
0259
local iDiv = Players[iPlayer]:GetJONSCulture() / 3;
0260
local iMod = Players[iPlayer]:GetJONSCulture() % 3;
0261
Players[iPlayer]:ChangeGold(iDiv);
0262
Players[iPlayer]:SetJONSCulture(iMod);
0263
end
0264
end
0266
if (Players[iPlayer]:HasPolicy(GameInfo.Policies["POLICY_SASSANID_FINISHER"].ID)) then
0267
if (Players[iPlayer]:GetJONSCulture() > 0) then
0268
local iDiv = Players[iPlayer]:GetJONSCulture() / 3;
0269
local iMod = Players[iPlayer]:GetJONSCulture() % 3;
0270
Players[iPlayer]:ChangeGold(iDiv);
0271
Players[iPlayer]:SetJONSCulture(iMod);
0272
end
0273
end
0275
-- Only on first player's turn
0276
if (iPlayer > 0) then
0277
return false;
0278
end
0280
--print("PlayerDoTurn");
0281
--print(iPlayer);
0282
--local playerStartPlot = Players[iPlayer]:GetStartingPlot();
0283
--print(playerStartPlot:GetX());
0284
--print(playerStartPlot:GetY());
0286
for iPlayerLoop = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
0287
   local pPlayer = Players[iPlayerLoop];
0288
   if (pPlayer:IsAlive() and IsEmpire(iPlayerLoop)) then
0289
   local iScore = 0;
0290
   for pCity in pPlayer:Cities() do
0291
   local iOriginalOwner = pCity:GetOriginalOwner();
0292
   -- if city owner is an empire and the original owner was an empire
0293
   if (IsEmpire(iOriginalOwner)) then
0294
   --   then give points according to how large the city is
0295
   iScore = iScore + pCity:GetPopulation();
0296
   end
0297
   end
0299
   if (IsRoman(iPlayerLoop)) then
0300
   iScore = iScore / 2;
0301
   elseif (IsSassanid(iPlayerLoop)) then
0302
   iScore = (4 * iScore) / 3;
0303
   end
0305
   pPlayer:ChangeScoreFromTechs(iScore);
0306
   end
0307
   end
0310
   if (iCitiesCaptured > 0) then
0311
   --print("Doing city popup");
0312
   local popupInfo = {
0313
   Data1 = 500,
0314
   Type = ButtonPopupTypes.BUTTONPOPUP_TEXT,
0315
   }
0316
   popupInfo.Text = Locale.ConvertTextKey("TXT_KEY_FOR_SCENARIO_ROMAN_CITY_CAPTURE_CULTURE", iCitiesCaptured, iCitiesCaptured * 20);
0317
   UI.AddPopup(popupInfo);
0318
   end
0321
   --if (not IsEmpire(iPlayer)) then
0322
   --return false;
0323
   --end
0325
   --local pPlayer = Players[iPlayer];
0326
   --for pCity in pPlayer:Cities() do
0327
   --local iOriginalOwner = pCity:GetOriginalOwner();
0328
   ---- if city owner is an empire and the original owner was an empire
0329
   --if (IsEmpire(iOriginalOwner)) then
0330
   ----   then give points according to how large the city is
0331
   --pPlayer:ChangeScoreFromTechs(pCity:GetPopulation());
0332
   --end
0333
   --end
0335
   return false;
0336
   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.