Bazaar developer reference

CvGame::update()

Defined in
CvGame.cpp, line 1451
Class
CvGame
Hook name
CivHooks::CvGame_update
Changed in
0.5.0
Lua events
GameEvents.GameCoreUpdateBegin, GameEvents.GameCoreUpdateEnd

Hooks

static bool BeforeCvGame_update(CvGame* self);static void AfterCvGame_update(CvGame* self);static void ReplaceCvGame_update(void (*original)(CvGame*), CvGame* self);CivRegisterBefore<CivHooks::CvGame_update>(host, &BeforeCvGame_update);CivRegisterAfter<CivHooks::CvGame_update>(host, &AfterCvGame_update);CivRegisterReplace<CivHooks::CvGame_update>(host, &ReplaceCvGame_update);

Code

1451void CvGame::update()1452{1453#if defined(CIV_HOST_API)1454	CivHostOnGameUpdate();1455#endif1456#if defined(CIV_TURN_BENCH)1457	CivTurnBench::UpdateScope benchScope(*this);1458#endif1459	if(IsWaitingForBlockingInput())1460	{1461		if(!GC.GetEngineUserInterface()->isDiploActive())1462		{1463			GET_PLAYER(m_eWaitDiploPlayer).doTurnPostDiplomacy();1464			SetWaitingForBlockingInput(NO_PLAYER);1465		}1466		else1467		{1468			return;1469		}1470	}14711472	// Send a Lua event at the start of the update1473	{1474		ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();1475		if(pkScriptSystem)1476		{1477			CvLuaArgsHandle args;1478			bool bResult;1479			LuaSupport::CallHook(pkScriptSystem, "GameCoreUpdateBegin", args.get(), bResult);1480		}1481	}14821483	// if the game is single player, it's ok to block all processing until1484	// the user selects an extended match or quits.1485	if(getGameState() == GAMESTATE_OVER && !CvPreGame::isNetworkMultiplayerGame())1486	{1487		testExtendedGame();1488	}1489	else1490	{1491		// allow extended games in MP without blocking processing. The game1492		// may be "over" for 1 player in a match with more than 2 players,1493		// when the player is defeated, for example, but not over for the1494		// rest of the players. It may also be over for everyone in the match1495		// but they may still have units/cities (science/cultural victories)1496		if(getGameState() == GAMESTATE_OVER && CvPreGame::isNetworkMultiplayerGame())1497		{1498			testExtendedGame();1499		}15001501		{1502			sendPlayerOptions();15031504			if(getTurnSlice() == 0 && !isPaused())1505			{1506#if defined(CIV_HOST_API)1507				if (CivHostSavingAllowed())1508#endif1509				gDLL->AutoSave(true);1510			}15111512			// If there are no active players, move on to the AI1513			if(getNumGameTurnActive() == 0)1514			{1515				if(gDLL->CanAdvanceTurn())1516					doTurn();1517			}15181519			if(!isPaused())	// Check for paused again, the doTurn call might have called something that paused the game and we don't want an update to sneak through1520			{1521				updateScore();15221523				updateWar();15241525				updateMoves();15261527				if(!isPaused())	// And again, the player can change after the automoves and that can pause the game1528				{1529					updateTimers();15301531					UpdatePlayers(); // slewis added!15321533					testAlive();15341535					if((getAIAutoPlay() == 0) && !(gDLL->GetAutorun()) && GAMESTATE_EXTENDED != getGameState())1536					{1537						if(CvPreGame::slotStatus(getActivePlayer()) != SS_OBSERVER && !GET_PLAYER(getActivePlayer()).isAlive())1538						{1539							setGameState(GAMESTATE_OVER);1540						}1541					}15421543					CheckPlayerTurnDeactivate();15441545					changeTurnSlice(1);15461547#if defined(MOD_AI_MP_DIPLOMACY)1548					if (MOD_AI_MP_DIPLOMACY) {1549						// JdH: humans may have been activated, check for AI diplomacy1550						CvDiplomacyRequests::DoAIDiplomacyWithHumans();1551					}1552#endif15531554					gDLL->FlushTurnReminders();1555				}1556			}15571558			PlayerTypes activePlayerID = getActivePlayer();1559			const CvPlayer& activePlayer = GET_PLAYER(activePlayerID);1560			if(NO_PLAYER != activePlayerID && activePlayer.getAdvancedStartPoints() >= 0 && !GC.GetEngineUserInterface()->isInAdvancedStart())1561			{1562				GC.GetEngineUserInterface()->setInAdvancedStart(true);1563			}1564		}1565	}15661567	// Send a Lua event at the end of the update1568	{1569		ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();1570		if(pkScriptSystem)1571		{1572			CvLuaArgsHandle args;1573			bool bResult;1574			LuaSupport::CallHook(pkScriptSystem, "GameCoreUpdateEnd", args.get(), bResult);1575		}1576	}1577}

Calls

Called by