Bazaar developer reference

getTurnMonthForGame(int, int, CalendarTypes, GameSpeedTypes)

Defined in
CvGameCoreUtils.cpp, line 923
Hook name
CivHooks::getTurnMonthForGame

Hooks

static bool BeforegetTurnMonthForGame(int iGameTurn, int iStartYear, CalendarTypes eCalendar, GameSpeedTypes eSpeed, int& result);static void AftergetTurnMonthForGame(int iGameTurn, int iStartYear, CalendarTypes eCalendar, GameSpeedTypes eSpeed, int& result);static int ReplacegetTurnMonthForGame(int (*original)(int, int, CalendarTypes, GameSpeedTypes), int iGameTurn, int iStartYear, CalendarTypes eCalendar, GameSpeedTypes eSpeed);CivRegisterBefore<CivHooks::getTurnMonthForGame>(host, &BeforegetTurnMonthForGame);CivRegisterAfter<CivHooks::getTurnMonthForGame>(host, &AftergetTurnMonthForGame);CivRegisterReplace<CivHooks::getTurnMonthForGame>(host, &ReplacegetTurnMonthForGame);

Code

923int getTurnMonthForGame(int iGameTurn, int iStartYear, CalendarTypes eCalendar, GameSpeedTypes eSpeed)924{925	int iTurnMonth;926	int iTurnCount;927	int iI;928929	CvGameSpeedInfo* pkGameSpeedInfo = GC.getGameSpeedInfo(eSpeed);930	if(pkGameSpeedInfo == NULL)931	{932		//This function requires a valid game speed type!933		CvAssert(pkGameSpeedInfo);934		return 0;935	}936937	const int iNumMonths = DB.Count("Months");938939	iTurnMonth = iStartYear * iNumMonths;940941	switch(eCalendar)942	{943	case CALENDAR_DEFAULT:944		{945			iTurnCount = 0;946			const int iGameSpeedNumTurnIncrements = pkGameSpeedInfo->getNumTurnIncrements();947948			for(iI = 0; iI < iGameSpeedNumTurnIncrements; iI++)949			{950				const GameTurnInfo& gameTurnInfo = pkGameSpeedInfo->getGameTurnInfo(iI);951952				if(iGameTurn > (iTurnCount + gameTurnInfo.iNumGameTurnsPerIncrement))953				{954					iTurnMonth += (gameTurnInfo.iMonthIncrement * gameTurnInfo.iNumGameTurnsPerIncrement);955					iTurnCount += gameTurnInfo.iNumGameTurnsPerIncrement;956				}957				else958				{959					iTurnMonth += (gameTurnInfo.iMonthIncrement * (iGameTurn - iTurnCount));960					iTurnCount += (iGameTurn - iTurnCount);961					break;962				}963			}964965			if(iGameTurn > iTurnCount)966			{967				iTurnMonth += (pkGameSpeedInfo->getGameTurnInfo(iGameSpeedNumTurnIncrements - 1).iMonthIncrement * (iGameTurn - iTurnCount));968			}969		}970		break;971972	case CALENDAR_BI_YEARLY:973		iTurnMonth += (2 * iGameTurn * iNumMonths);974		break;975976	case CALENDAR_YEARS:977	case CALENDAR_TURNS:978		iTurnMonth += iGameTurn * iNumMonths;979		break;980981	case CALENDAR_SEASONS:982		iTurnMonth += (iGameTurn * iNumMonths) / DB.Count("Seasons");983		break;984985	case CALENDAR_MONTHS:986		iTurnMonth += iGameTurn;987		break;988989	case CALENDAR_WEEKS:990		iTurnMonth += iGameTurn / GC.getWEEKS_PER_MONTHS();991		break;992993	default:994		CvAssert(false);995	}996997	return iTurnMonth;998}

Calls

Called by