Hooks
static bool BeforeCvMinorCivAI_GetBestNearbyCampToKill(CvMinorCivAI* self, CvPlot*& result);static void AfterCvMinorCivAI_GetBestNearbyCampToKill(CvMinorCivAI* self, CvPlot*& result);static CvPlot* ReplaceCvMinorCivAI_GetBestNearbyCampToKill(CvPlot* (*original)(CvMinorCivAI*), CvMinorCivAI* self);CivRegisterBefore<CivHooks::CvMinorCivAI_GetBestNearbyCampToKill>(host, &BeforeCvMinorCivAI_GetBestNearbyCampToKill);CivRegisterAfter<CivHooks::CvMinorCivAI_GetBestNearbyCampToKill>(host, &AfterCvMinorCivAI_GetBestNearbyCampToKill);CivRegisterReplace<CivHooks::CvMinorCivAI_GetBestNearbyCampToKill>(host, &ReplaceCvMinorCivAI_GetBestNearbyCampToKill);
Code
5511/// Any Camps near us?5512/// NOTE: This should pick a camp deterministically, given the current implementation of distributing global quests5513CvPlot* CvMinorCivAI::GetBestNearbyCampToKill()5514{5515 CvCity* pCapital = GetPlayer()->getCapitalCity();55165517 // Minor must have Capital5518 if(pCapital == NULL)5519 {5520 return NULL;5521 }55225523 CvWeightedVector<int, 64, true> viPlotIndexes; // 64 camps in 12 hex radius should be enough55245525 int iRange = /*12*/ GC.getMINOR_CIV_QUEST_KILL_CAMP_RANGE();55265527 CvPlot* pLoopPlot;55285529 // Loop in all plots in range5530 int iDX, iDY;5531 for(iDX = -(iRange); iDX <= iRange; iDX++)5532 {5533 for(iDY = -(iRange); iDY <= iRange; iDY++)5534 {5535 pLoopPlot = plotXY(pCapital->getX(), pCapital->getY(), iDX, iDY);55365537 if(pLoopPlot != NULL)5538 {5539 // Camp must be in the same Area as us5540 if(pLoopPlot->getArea() != pCapital->getArea())5541 {5542 continue;5543 }55445545 int iDistance = plotDistance(pCapital->getX(), pCapital->getY(), pLoopPlot->getX(), pLoopPlot->getY());55465547 if(iDistance <= iRange)5548 {5549 // Can't be owned by anyone5550 if(pLoopPlot->getOwner() == NO_PLAYER)5551 {5552 // Camp here?5553 if(pLoopPlot->getImprovementType() == GC.getBARBARIAN_CAMP_IMPROVEMENT())5554 {5555 int iWeight = 1 + (iRange - iDistance); // Closer camps have higher weight5556 viPlotIndexes.push_back(pLoopPlot->GetPlotIndex(), iWeight);5557 }5558 }5559 }5560 }5561 }5562 }55635564 // Didn't find any nearby5565 if(viPlotIndexes.size() == 0)5566 {5567 return NULL;5568 }55695570 // Choose the best plot5571 viPlotIndexes.SortItems();5572 CvPlot* pBestPlot = GC.getMap().plotByIndex(viPlotIndexes.GetElement(0));55735574 return pBestPlot;5575}