CvUnit::CanFallBackFromMelee(CvUnit &)
- Defined in
- CvUnit.cpp, line 24263
- Class
- CvUnit
- Hook name
CivHooks::CvUnit_CanFallBackFromMelee
Hooks
static bool BeforeCvUnit_CanFallBackFromMelee(CvUnit* self, CvUnit& attacker, bool& result);static void AfterCvUnit_CanFallBackFromMelee(CvUnit* self, CvUnit& attacker, bool& result);static bool ReplaceCvUnit_CanFallBackFromMelee(bool (*original)(CvUnit*, CvUnit&), CvUnit* self, CvUnit& attacker);CivRegisterBefore<CivHooks::CvUnit_CanFallBackFromMelee>(host, &BeforeCvUnit_CanFallBackFromMelee);CivRegisterAfter<CivHooks::CvUnit_CanFallBackFromMelee>(host, &AfterCvUnit_CanFallBackFromMelee);CivRegisterReplace<CivHooks::CvUnit_CanFallBackFromMelee>(host, &ReplaceCvUnit_CanFallBackFromMelee);
Code
24263bool CvUnit::CanFallBackFromMelee(CvUnit& attacker)24264{24265 VALIDATE_OBJECT24266 // Are some of the retreat hexes away from the attacker blocked?24267 int iBlockedHexes = 0;24268 CvPlot* pAttackerFromPlot = attacker.plot();24269 DirectionTypes eAttackDirection = directionXY(pAttackerFromPlot, plot());24270 int iBiases[3] = {0,-1,1};24271 int x = plot()->getX();24272 int y = plot()->getY();2427324274 for(int i = 0; i < 3; i++)24275 {24276 int iMovementDirection = (NUM_DIRECTION_TYPES + eAttackDirection + iBiases[i]) % NUM_DIRECTION_TYPES;24277 CvPlot* pDestPlot = plotDirection(x, y, (DirectionTypes) iMovementDirection);2427824279 if(pDestPlot && !canMoveInto(*pDestPlot, MOVEFLAG_DESTINATION))24280 {24281 iBlockedHexes++;24282 }24283 }2428424285 // If all three hexes away from attacker blocked, we can't withdraw24286 if(iBlockedHexes >= 3)24287 {24288 return false;24289 }2429024291 return true;24292}