Hooks
static bool BeforeCvPlayerAI_AI_captureUnit(CvPlayerAI* self, UnitTypes arg0, CvPlot* pPlot, bool& result);static void AfterCvPlayerAI_AI_captureUnit(CvPlayerAI* self, UnitTypes arg0, CvPlot* pPlot, bool& result);static bool ReplaceCvPlayerAI_AI_captureUnit(bool (*original)(CvPlayerAI*, UnitTypes, CvPlot*), CvPlayerAI* self, UnitTypes arg0, CvPlot* pPlot);CivRegisterBefore<CivHooks::CvPlayerAI_AI_captureUnit>(host, &BeforeCvPlayerAI_AI_captureUnit);CivRegisterAfter<CivHooks::CvPlayerAI_AI_captureUnit>(host, &AfterCvPlayerAI_AI_captureUnit);CivRegisterReplace<CivHooks::CvPlayerAI_AI_captureUnit>(host, &ReplaceCvPlayerAI_AI_captureUnit);
Code
357bool CvPlayerAI::AI_captureUnit(UnitTypes, CvPlot* pPlot)358{359 CvCity* pNearestCity;360361 CvAssert(!isHuman());362363 // Barbs always capture364 if (isBarbarian())365 return true;366367 // we own it368 if (pPlot->getTeam() == getTeam())369 return true;370371 // no man's land - may as well372 if (pPlot->getTeam() == NO_TEAM)373 return true;374375 // friendly, sure (okay, this is pretty much just means open borders)376 if (pPlot->IsFriendlyTerritory(GetID()))377 return true;378379 // not friendly, but "near" us380 pNearestCity = GC.getMap().findCity(pPlot->getX(), pPlot->getY(), NO_PLAYER, getTeam());381 if (pNearestCity != NULL)382 {383 if (plotDistance(pPlot->getX(), pPlot->getY(), pNearestCity->getX(), pNearestCity->getY()) <= 7)384 return true;385 }386387 // very near someone we aren't friends with (and far from our nearest city)388 pNearestCity = GC.getMap().findCity(pPlot->getX(), pPlot->getY());389 if (pNearestCity != NULL)390 {391 if (plotDistance(pPlot->getX(), pPlot->getY(), pNearestCity->getX(), pNearestCity->getY()) <= 4)392 return false;393 }394395 // I'd rather we grab it and run than destroy it396 return true;397}