Bazaar developer reference

CvUnit::UnitMove(CvPlot *, bool, CvUnit *, bool)

Defined in
CvUnit.cpp, line 22960
Class
CvUnit
Hook name
CivHooks::CvUnit_UnitMove

Hooks

static bool BeforeCvUnit_UnitMove(CvUnit* self, CvPlot* pPlot, bool bCombat, CvUnit* pCombatUnit, bool bEndMove, bool& result);static void AfterCvUnit_UnitMove(CvUnit* self, CvPlot* pPlot, bool bCombat, CvUnit* pCombatUnit, bool bEndMove, bool& result);static bool ReplaceCvUnit_UnitMove(bool (*original)(CvUnit*, CvPlot*, bool, CvUnit*, bool), CvUnit* self, CvPlot* pPlot, bool bCombat, CvUnit* pCombatUnit, bool bEndMove);CivRegisterBefore<CivHooks::CvUnit_UnitMove>(host, &BeforeCvUnit_UnitMove);CivRegisterAfter<CivHooks::CvUnit_UnitMove>(host, &AfterCvUnit_UnitMove);CivRegisterReplace<CivHooks::CvUnit_UnitMove>(host, &ReplaceCvUnit_UnitMove);

Code

22960bool CvUnit::UnitMove(CvPlot* pPlot, bool bCombat, CvUnit* pCombatUnit, bool bEndMove)22961{22962	VALIDATE_OBJECT22963	bool bCanMoveIntoPlot = false;22964	if(canMove() && pPlot)22965	{22966		// if it's a combat and the attacking unit can capture things or the city is an enemy city.22967		if(bCombat && (!(isNoCapture()) || !(pPlot->isEnemyCity(*this))))22968		{22969			bCanMoveIntoPlot = canMoveOrAttackInto(*pPlot, CvUnit::MOVEFLAG_PRETEND_CORRECT_EMBARK_STATE);22970		}22971		else	VALIDATE_OBJECT2297222973		{22974			bCanMoveIntoPlot = canMoveInto(*pPlot, CvUnit::MOVEFLAG_PRETEND_CORRECT_EMBARK_STATE);22975		}22976	}22977	VALIDATE_OBJECT229782297922980	bool bIsNoCapture = isNoCapture();22981	bool bEnemyCity = pPlot && pPlot->isEnemyCity(*this);2298222983	bool bIsCombatUnit = (this == pCombatUnit);22984	bool bExecuteMove = false;2298522986	if(pPlot && (bCanMoveIntoPlot || (bIsCombatUnit && !(bIsNoCapture && bEnemyCity))))22987	{22988		// execute move22989		LOG_UNIT_MOVES_MESSAGE_OSTR(std::string("UnitMove() : player ") << GET_PLAYER(getOwner()).getName(); << std::string(" ") << getName() << std::string(" id=") << GetID() << std::string(" moving to ") << pPlot->getX() << std::string(", ") << pPlot->getY());22990		move(*pPlot, true);22991	}22992	else22993	{22994		bExecuteMove = true;22995	}2299622997	//execute move22998	if(bEndMove || !canMove() || IsDoingPartialMove())22999	{23000		bExecuteMove = true;23001	}2300223003	if(CvPreGame::quickMovement())23004	{23005		bExecuteMove = false;23006	}2300723008	if(bExecuteMove)23009	{23010		PublishQueuedVisualizationMoves();23011	}2301223013	return bCanMoveIntoPlot;23014}

Calls

Called by