Bazaar developer reference

CvMinorCivAI::CanMajorProtect(PlayerTypes)

Defined in
CvMinorCivAI.cpp, line 7409
Class
CvMinorCivAI
Hook name
CivHooks::CvMinorCivAI_CanMajorProtect
Lua events
GameEvents.PlayerCanProtect

Hooks

static bool BeforeCvMinorCivAI_CanMajorProtect(CvMinorCivAI* self, PlayerTypes eMajor, bool& result);static void AfterCvMinorCivAI_CanMajorProtect(CvMinorCivAI* self, PlayerTypes eMajor, bool& result);static bool ReplaceCvMinorCivAI_CanMajorProtect(bool (*original)(CvMinorCivAI*, PlayerTypes), CvMinorCivAI* self, PlayerTypes eMajor);CivRegisterBefore<CivHooks::CvMinorCivAI_CanMajorProtect>(host, &BeforeCvMinorCivAI_CanMajorProtect);CivRegisterAfter<CivHooks::CvMinorCivAI_CanMajorProtect>(host, &AfterCvMinorCivAI_CanMajorProtect);CivRegisterReplace<CivHooks::CvMinorCivAI_CanMajorProtect>(host, &ReplaceCvMinorCivAI_CanMajorProtect);

Code

7409bool CvMinorCivAI::CanMajorProtect(PlayerTypes eMajor)7410{7411	CvAssertMsg(eMajor >= 0, "eMajor is expected to be non-negative (invalid Index)");7412	CvAssertMsg(eMajor < MAX_MAJOR_CIVS, "eMajor is expected to be within maximum bounds (invalid Index)");7413	if(eMajor < 0 || eMajor >= MAX_MAJOR_CIVS) return false;74147415	// If at war, may not protect7416	if(GET_TEAM(GET_PLAYER(eMajor).getTeam()).isAtWar(GetPlayer()->getTeam()))7417		return false;74187419	// Must have positive INF7420	if(GetEffectiveFriendshipWithMajor(eMajor) < /*0*/ GC.getFRIENDSHIP_THRESHOLD_CAN_PLEDGE_TO_PROTECT())7421		return false;74227423	// Must not be too soon after a previous pledge was broken7424	int iCurrentTurn = GC.getGame().getGameTurn();7425	int iLastPledgeBrokenTurn = GetTurnLastPledgeBrokenByMajor(eMajor);7426	const int iGracePeriod = 20; //antonjs: todo: xml7427	if(iLastPledgeBrokenTurn >= 0 && iLastPledgeBrokenTurn + iGracePeriod > iCurrentTurn)7428		return false;74297430#if defined(MOD_EVENTS_MINORS_INTERACTION)7431	if (MOD_EVENTS_MINORS_INTERACTION) {7432		if (GAMEEVENTINVOKE_TESTALL(GAMEEVENT_PlayerCanProtect, eMajor, GetPlayer()->GetID()) == GAMEEVENTRETURN_FALSE) {7433			return false;7434		}7435	}7436#endif				7437	7438	return true;7439}

Calls

Called by