CvUnit::CanWithdrawFromMelee(CvUnit &)
- Defined in
- CvUnit.cpp, line 24191
- Class
- CvUnit
- Hook name
CivHooks::CvUnit_CanWithdrawFromMelee
Hooks
static bool BeforeCvUnit_CanWithdrawFromMelee(CvUnit* self, CvUnit& attacker, bool& result);static void AfterCvUnit_CanWithdrawFromMelee(CvUnit* self, CvUnit& attacker, bool& result);static bool ReplaceCvUnit_CanWithdrawFromMelee(bool (*original)(CvUnit*, CvUnit&), CvUnit* self, CvUnit& attacker);CivRegisterBefore<CivHooks::CvUnit_CanWithdrawFromMelee>(host, &BeforeCvUnit_CanWithdrawFromMelee);CivRegisterAfter<CivHooks::CvUnit_CanWithdrawFromMelee>(host, &AfterCvUnit_CanWithdrawFromMelee);CivRegisterReplace<CivHooks::CvUnit_CanWithdrawFromMelee>(host, &ReplaceCvUnit_CanWithdrawFromMelee);
Code
24191bool CvUnit::CanWithdrawFromMelee(CvUnit& attacker)24192{24193 VALIDATE_OBJECT24194 int iWithdrawChance = getExtraWithdrawal();2419524196 // Does attacker have a speed greater than 1?24197 int iAttackerMovementRange = attacker.maxMoves() / GC.getMOVE_DENOMINATOR();24198 if(iAttackerMovementRange > 0)24199 {24200 iWithdrawChance += (GC.getWITHDRAW_MOD_ENEMY_MOVES() * (iAttackerMovementRange - 2));24201 }2420224203 // Are some of the retreat hexes away from the attacker blocked?24204 int iBlockedHexes = 0;24205 CvPlot* pAttackerFromPlot = attacker.plot();24206 DirectionTypes eAttackDirection = directionXY(pAttackerFromPlot, plot());24207 int iBiases[3] = {0,-1,1};24208 int x = plot()->getX();24209 int y = plot()->getY();2421024211 for(int i = 0; i < 3; i++)24212 {24213 int iMovementDirection = (NUM_DIRECTION_TYPES + eAttackDirection + iBiases[i]) % NUM_DIRECTION_TYPES;24214 CvPlot* pDestPlot = plotDirection(x, y, (DirectionTypes) iMovementDirection);2421524216 if(pDestPlot && !canMoveInto(*pDestPlot, MOVEFLAG_DESTINATION))24217 {24218 iBlockedHexes++;24219 }24220 }2422124222 // If all three hexes away from attacker blocked, we can't withdraw24223 if(iBlockedHexes >= 3)24224 {24225 return false;24226 }2422724228 iWithdrawChance += (GC.getWITHDRAW_MOD_BLOCKED_TILE() * iBlockedHexes);2422924230 int iRoll = GC.getGame().getJonRandNum(100, "Withdraw from Melee attempt");2423124232 return iRoll < iWithdrawChance;24233}
Calls
- CvGame::getJonRandNum(int, const char *)
- CvGlobals::getGame()
- CvGlobals::getMOVE_DENOMINATOR()
- CvGlobals::getWITHDRAW_MOD_BLOCKED_TILE()
- CvGlobals::getWITHDRAW_MOD_ENEMY_MOVES()
- CvPlot::getX() const
- CvPlot::getY() const
- CvUnit::canMoveInto(const CvPlot &, byte) const
- CvUnit::getExtraWithdrawal() const
- CvUnit::maxMoves() const
- CvUnit::plot() const
- directionXY(const CvPlot *, const CvPlot *)
- plotDirection(int, int, DirectionTypes)