Hooks
static bool BeforeCvUnit_DoFallBackFromMelee(CvUnit* self, CvUnit& attacker, bool& result);static void AfterCvUnit_DoFallBackFromMelee(CvUnit* self, CvUnit& attacker, bool& result);static bool ReplaceCvUnit_DoFallBackFromMelee(bool (*original)(CvUnit*, CvUnit&), CvUnit* self, CvUnit& attacker);CivRegisterBefore<CivHooks::CvUnit_DoFallBackFromMelee>(host, &BeforeCvUnit_DoFallBackFromMelee);CivRegisterAfter<CivHooks::CvUnit_DoFallBackFromMelee>(host, &AfterCvUnit_DoFallBackFromMelee);CivRegisterReplace<CivHooks::CvUnit_DoFallBackFromMelee>(host, &ReplaceCvUnit_DoFallBackFromMelee);
Code
24295bool CvUnit::DoFallBackFromMelee(CvUnit& attacker)24296{24297 VALIDATE_OBJECT2429824299 CvPlot* pAttackerFromPlot = attacker.plot();24300 DirectionTypes eAttackDirection = directionXY(pAttackerFromPlot, plot());2430124302 int iRightOrLeftBias = (GC.getGame().getJonRandNum(100, "right or left bias") < 50) ? 1 : -1;24303 int iBiases[5] = {0,-1,1,-2,2};24304 int x = plot()->getX();24305 int y = plot()->getY();2430624307 // try to retreat as close to away from the attacker as possible24308 for(int i = 0; i < 5; i++)24309 {24310 int iMovementDirection = (NUM_DIRECTION_TYPES + eAttackDirection + (iBiases[i] * iRightOrLeftBias)) % NUM_DIRECTION_TYPES;24311 CvPlot* pDestPlot = plotDirection(x, y, (DirectionTypes) iMovementDirection);2431224313 if(pDestPlot && canMoveInto(*pDestPlot, MOVEFLAG_DESTINATION))24314 {24315 setXY(pDestPlot->getX(), pDestPlot->getY(), false, false, true, false);24316 return true;24317 }24318 }24319 return false;24320}