Hooks
static bool BeforeCvUnit_DoWithdrawFromMelee(CvUnit* self, CvUnit& attacker, bool& result);static void AfterCvUnit_DoWithdrawFromMelee(CvUnit* self, CvUnit& attacker, bool& result);static bool ReplaceCvUnit_DoWithdrawFromMelee(bool (*original)(CvUnit*, CvUnit&), CvUnit* self, CvUnit& attacker);CivRegisterBefore<CivHooks::CvUnit_DoWithdrawFromMelee>(host, &BeforeCvUnit_DoWithdrawFromMelee);CivRegisterAfter<CivHooks::CvUnit_DoWithdrawFromMelee>(host, &AfterCvUnit_DoWithdrawFromMelee);CivRegisterReplace<CivHooks::CvUnit_DoWithdrawFromMelee>(host, &ReplaceCvUnit_DoWithdrawFromMelee);
Code
24236bool CvUnit::DoWithdrawFromMelee(CvUnit& attacker)24237{24238 VALIDATE_OBJECT24239 CvPlot* pAttackerFromPlot = attacker.plot();24240 DirectionTypes eAttackDirection = directionXY(pAttackerFromPlot, plot());2424124242 int iRightOrLeftBias = (GC.getGame().getJonRandNum(100, "right or left bias") < 50) ? 1 : -1;24243 int iBiases[5] = {0,-1,1,-2,2};24244 int x = plot()->getX();24245 int y = plot()->getY();2424624247 // try to retreat as close to away from the attacker as possible24248 for(int i = 0; i < 5; i++)24249 {24250 int iMovementDirection = (NUM_DIRECTION_TYPES + eAttackDirection + (iBiases[i] * iRightOrLeftBias)) % NUM_DIRECTION_TYPES;24251 CvPlot* pDestPlot = plotDirection(x, y, (DirectionTypes) iMovementDirection);2425224253 if(pDestPlot && canMoveInto(*pDestPlot, MOVEFLAG_DESTINATION))24254 {24255 setXY(pDestPlot->getX(), pDestPlot->getY(), false, false, true, false);24256 return true;24257 }24258 }24259 return false;24260}