Bazaar developer reference

CvUnit::canLoad(const CvPlot &) const

Defined in
CvUnit.cpp, line 4375
Class
CvUnit
Hook name
CivHooks::CvUnit_canLoad
Lua events
GameEvents.CanLoadAt

Hooks

static bool BeforeCvUnit_canLoad(const CvUnit* self, const CvPlot& targetPlot, bool& result);static void AfterCvUnit_canLoad(const CvUnit* self, const CvPlot& targetPlot, bool& result);static bool ReplaceCvUnit_canLoad(bool (*original)(const CvUnit*, const CvPlot&), const CvUnit* self, const CvPlot& targetPlot);CivRegisterBefore<CivHooks::CvUnit_canLoad>(host, &BeforeCvUnit_canLoad);CivRegisterAfter<CivHooks::CvUnit_canLoad>(host, &AfterCvUnit_canLoad);CivRegisterReplace<CivHooks::CvUnit_canLoad>(host, &ReplaceCvUnit_canLoad);

Code

4375bool CvUnit::canLoad(const CvPlot& targetPlot) const4376{4377	VALIDATE_OBJECT4378	if(NO_SPECIALUNIT != getSpecialUnitType())4379	{4380		CvSpecialUnitInfo* pkSpecialUnitInfo = GC.getSpecialUnitInfo(getSpecialUnitType());4381		if(pkSpecialUnitInfo)4382		{4383			if(pkSpecialUnitInfo->isCityLoad())4384			{4385				if(targetPlot.isCity())4386				{4387					return true;4388				}43894390#if defined(MOD_GLOBAL_RELOCATION)4391				// Is there a friendly improvement that AllowsRebaseTo4392				ImprovementTypes eImprovement = targetPlot.getImprovementType();4393				if (eImprovement != NO_IMPROVEMENT)4394				{4395					CvImprovementEntry *pkEntry = GC.getImprovementInfo(eImprovement);4396					if (pkEntry && pkEntry->IsAllowsRebaseTo() && !targetPlot.IsImprovementPillaged() && targetPlot.IsFriendlyTerritory(getOwner()) && !targetPlot.isVisibleEnemyUnit(getOwner()))4397					{4398						return true;4399					}4400				}4401#endif44024403#if defined(MOD_EVENTS_REBASE)4404				if (MOD_EVENTS_REBASE) {4405					if (GAMEEVENTINVOKE_TESTANY(GAMEEVENT_CanLoadAt, getOwner(), GetID(), targetPlot.getX(), targetPlot.getY()) == GAMEEVENTRETURN_TRUE) {4406						return true;4407					}4408				} else {4409#endif4410				ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();4411				if (pkScriptSystem)4412				{4413					CvLuaArgsHandle args;4414					args->Push(getOwner());4415					args->Push(GetID());4416					args->Push(targetPlot.getX());4417					args->Push(targetPlot.getY());44184419					// Attempt to execute the game events.4420					// Will return false if there are no registered listeners.4421					bool bResult = false;4422					if (LuaSupport::CallTestAny(pkScriptSystem, "CanLoadAt", args.get(), bResult))4423					{4424						// Check the result.4425						if (bResult == true) {4426							return true;4427						}4428					}4429				}4430#if defined(MOD_EVENTS_REBASE)4431				}4432#endif4433			}4434		}4435	}44364437	const IDInfo* pUnitNode = targetPlot.headUnitNode();4438	while(pUnitNode != NULL)4439	{4440		const CvUnit* pLoopUnit = ::getUnit(*pUnitNode);4441		pUnitNode = targetPlot.nextUnitNode(pUnitNode);44424443		if(pLoopUnit && canLoadUnit(*pLoopUnit, targetPlot))4444		{4445			return true;4446		}4447	}44484449	return false;4450}

Calls

Called by