Bazaar developer reference

CvMinorCivAI::DoChangeAliveStatus(bool)

Defined in
CvMinorCivAI.cpp, line 2356
Class
CvMinorCivAI
Hook name
CivHooks::CvMinorCivAI_DoChangeAliveStatus

Hooks

static bool BeforeCvMinorCivAI_DoChangeAliveStatus(CvMinorCivAI* self, bool bAlive);static void AfterCvMinorCivAI_DoChangeAliveStatus(CvMinorCivAI* self, bool bAlive);static void ReplaceCvMinorCivAI_DoChangeAliveStatus(void (*original)(CvMinorCivAI*, bool), CvMinorCivAI* self, bool bAlive);CivRegisterBefore<CivHooks::CvMinorCivAI_DoChangeAliveStatus>(host, &BeforeCvMinorCivAI_DoChangeAliveStatus);CivRegisterAfter<CivHooks::CvMinorCivAI_DoChangeAliveStatus>(host, &AfterCvMinorCivAI_DoChangeAliveStatus);CivRegisterReplace<CivHooks::CvMinorCivAI_DoChangeAliveStatus>(host, &ReplaceCvMinorCivAI_DoChangeAliveStatus);

Code

2355/// Minor is now dead or alive (haha, get it?)2356void CvMinorCivAI::DoChangeAliveStatus(bool bAlive)2357{2358	if (!bAlive)2359	{2360		// Final check for quests2361		DoTestActiveQuests(/*bTestComplete*/ true, /*bTestObsolete*/ true);23622363		std::vector<int> vNewInfluence;2364		for (int i = 0; i < MAX_MAJOR_CIVS; ++i)2365		{2366			PlayerTypes e = (PlayerTypes)i;23672368			// Cancel quests and PtPs2369			DoChangeProtectionFromMajor(e, false);2370			EndAllActiveQuestsForPlayer(e);23712372			// Calculate new influence levels (don't set here, since that could create a false temporary ally)2373			int iOldInfluence = GetBaseFriendshipWithMajor(e);2374			int iNewInfluence = iOldInfluence;2375			if (IsFriendshipAboveAlliesThreshold(iOldInfluence))2376			{2377				iNewInfluence = GC.getFRIENDSHIP_ALLIES_ON_DEATH();2378			}2379			else if (IsFriendshipAboveFriendsThreshold(iOldInfluence))2380			{2381				iNewInfluence = GC.getFRIENDSHIP_FRIENDS_ON_DEATH();2382			}2383			else if (iOldInfluence > GC.getFRIENDSHIP_THRESHOLD_NEUTRAL())2384			{2385				iNewInfluence = GC.getFRIENDSHIP_NEUTRAL_ON_DEATH();2386			}2387			vNewInfluence.push_back(iNewInfluence);2388		}23892390		// Set new influence values2391		SetDisableNotifications(true);2392		for (unsigned int i = 0; i < vNewInfluence.size(); ++i)2393		{2394			PlayerTypes e = (PlayerTypes)i;2395			// special workaround to allow status changes despite minor already being dead2396			DoFriendshipChangeEffects(e, GetEffectiveFriendshipWithMajor(e), vNewInfluence.at(i), /*bFromQuest*/false, /*bIgnoreMinorDeath*/true);2397			SetFriendshipWithMajor(e, vNewInfluence.at(i));2398		}2399		SetDisableNotifications(false);2400	}24012402	// Apply or Remove any active bonuses2403	for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)2404	{2405		PlayerTypes ePlayer = (PlayerTypes) iPlayerLoop;24062407		bool bFriends = false;2408		bool bAllies = false;2409		if(IsFriendshipAboveFriendsThreshold(GetEffectiveFriendshipWithMajor(ePlayer)))2410		{2411			bFriends = true;2412		}2413		if(GetAlly() == ePlayer)2414		{2415			CvAssertMsg(bAlive, "A Minor about to die still has an Ally, when it should have none.");2416			bAllies = true;2417		}2418		if(bFriends || bAllies)2419		{2420			DoSetBonus(ePlayer, bAlive, bFriends, bAllies);2421		}2422	}24232424	// Death - Reset the cached ally and barbarian threat counter2425	if (!bAlive)2426	{2427		bool bHasAlly = GetAlly() != NO_PLAYER;2428		CvAssertMsg(!bHasAlly, "A Minor about to die still has an Ally, when it should have none.");2429		if(bHasAlly)2430		{2431			SetAlly(NO_PLAYER);2432		}24332434		SetTurnsSinceThreatenedAnnouncement(-1);2435	}2436}

Calls

Called by