Bazaar developer reference

CvMinorCivAI::CanMajorGiftTileImprovement(PlayerTypes)

Defined in
CvMinorCivAI.cpp, line 10046
Class
CvMinorCivAI
Hook name
CivHooks::CvMinorCivAI_CanMajorGiftTileImprovement
Lua events
GameEvents.PlayerCanGiftImprovement

Hooks

static bool BeforeCvMinorCivAI_CanMajorGiftTileImprovement(CvMinorCivAI* self, PlayerTypes eMajor, bool& result);static void AfterCvMinorCivAI_CanMajorGiftTileImprovement(CvMinorCivAI* self, PlayerTypes eMajor, bool& result);static bool ReplaceCvMinorCivAI_CanMajorGiftTileImprovement(bool (*original)(CvMinorCivAI*, PlayerTypes), CvMinorCivAI* self, PlayerTypes eMajor);CivRegisterBefore<CivHooks::CvMinorCivAI_CanMajorGiftTileImprovement>(host, &BeforeCvMinorCivAI_CanMajorGiftTileImprovement);CivRegisterAfter<CivHooks::CvMinorCivAI_CanMajorGiftTileImprovement>(host, &AfterCvMinorCivAI_CanMajorGiftTileImprovement);CivRegisterReplace<CivHooks::CvMinorCivAI_CanMajorGiftTileImprovement>(host, &ReplaceCvMinorCivAI_CanMajorGiftTileImprovement);

Code

10045// Can this major gift us a tile improvement?10046bool CvMinorCivAI::CanMajorGiftTileImprovement(PlayerTypes eMajor)10047{10048	CvAssertMsg(eMajor >= 0, "eMajor is expected to be non-negative (invalid Index)");10049	CvAssertMsg(eMajor < MAX_MAJOR_CIVS, "eMajor is expected to be within maximum bounds (invalid Index)");10050	if(eMajor < 0 || eMajor >= MAX_MAJOR_CIVS) return false;10051	CvPlayer* pPlayer = &GET_PLAYER(eMajor);10052	if(pPlayer == NULL)10053	{10054		CvAssertMsg(false, "pPlayer not expected to be NULL. Please send Anton your save file and version.");10055		return false;10056	}1005710058	// Must have enough gold10059	const int iCost = GetGiftTileImprovementCost(eMajor);10060	if(pPlayer->GetTreasury()->GetGold() < iCost)10061		return false;1006210063	// Must own an improveable plot10064	bool bHasValidPlot = false;10065	CvPlotsVector& aiPlots = GetPlayer()->GetPlots();10066	for(uint ui = 0; ui < aiPlots.size(); ui++)10067	{10068		// at the end of the plot list10069		if(aiPlots[ui] == -1)10070		{10071			break;10072		}1007310074		CvPlot* pPlot = GC.getMap().plotByIndex(aiPlots[ui]);10075		if (IsLackingGiftableTileImprovementAtPlot(eMajor, pPlot->getX(), pPlot->getY()))10076		{10077			bHasValidPlot = true;10078			break;10079		}10080	}1008110082	if (!bHasValidPlot)10083		return false;1008410085#if defined(MOD_EVENTS_MINORS_INTERACTION)10086	if (MOD_EVENTS_MINORS_INTERACTION) {10087		if (GAMEEVENTINVOKE_TESTALL(GAMEEVENT_PlayerCanGiftImprovement, eMajor, GetPlayer()->GetID()) == GAMEEVENTRETURN_FALSE) {10088			return false;10089		}10090	}10091#endif				10092	10093	return true;10094}

Calls

Called by