Bazaar developer reference

CvUnit::rebase(int, int)

Defined in
CvUnit.cpp, line 7619
Class
CvUnit
Hook name
CivHooks::CvUnit_rebase
Lua events
GameEvents.RebaseTo

Hooks

static bool BeforeCvUnit_rebase(CvUnit* self, int iX, int iY, bool& result);static void AfterCvUnit_rebase(CvUnit* self, int iX, int iY, bool& result);static bool ReplaceCvUnit_rebase(bool (*original)(CvUnit*, int, int), CvUnit* self, int iX, int iY);CivRegisterBefore<CivHooks::CvUnit_rebase>(host, &BeforeCvUnit_rebase);CivRegisterAfter<CivHooks::CvUnit_rebase>(host, &AfterCvUnit_rebase);CivRegisterReplace<CivHooks::CvUnit_rebase>(host, &ReplaceCvUnit_rebase);

Code

7619bool CvUnit::rebase(int iX, int iY)7620{7621	if(!canRebaseAt(plot(), iX, iY))7622	{7623		return false;7624	}76257626	CvPlot* oldPlot = plot();76277628	CvPlot* pTargetPlot = GC.getMap().plot(iX, iY);7629	CvAssert(pTargetPlot != NULL);7630	if(pTargetPlot == NULL)7631		return false;76327633	finishMoves();76347635	// Loses sight bonus for this turn7636	setReconPlot(NULL);76377638	bool bShow = true;7639	// Do the rebase first to keep the visualization in sequence7640	if ((plot()->isVisibleToWatchingHuman() || pTargetPlot->isVisibleToWatchingHuman()) && !CvPreGame::quickMovement())7641	{7642		SpecialUnitTypes eSpecialUnitPlane = (SpecialUnitTypes) GC.getInfoTypeForString("SPECIALUNIT_FIGHTER");7643		if(getSpecialUnitType() == eSpecialUnitPlane)7644		{7645			auto_ptr<ICvPlot1> pDllOldPlot(new CvDllPlot(oldPlot));7646			auto_ptr<ICvPlot1> pDllTargetPlot(new CvDllPlot(pTargetPlot));76477648			auto_ptr<ICvUnit1> pDllUnit(new CvDllUnit(this));7649			gDLL->GameplayUnitRebased(pDllUnit.get(), pDllOldPlot.get(), pDllTargetPlot.get());7650			bShow = false;		// Tell the setXY to not bother showing the move7651		}7652	}76537654#if defined(MOD_EVENTS_REBASE)7655	if (MOD_EVENTS_REBASE) {7656		GAMEEVENTINVOKE_HOOK(GAMEEVENT_RebaseTo, getOwner(), GetID(), iX, iY);7657	} else {7658#endif7659	ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();7660	if (pkScriptSystem)7661	{7662		CvLuaArgsHandle args;7663		args->Push(getOwner());7664		args->Push(GetID());7665		args->Push(iX);7666		args->Push(iY);76677668		bool bResult;7669		LuaSupport::CallHook(pkScriptSystem, "RebaseTo", args.get(), bResult);7670	}7671#if defined(MOD_EVENTS_REBASE)7672	}7673#endif76747675	setXY(pTargetPlot->getX(), pTargetPlot->getY(), false, bShow, false);76767677	return true;7678}

Calls

Called by