CvMap::findUnit(int, int, PlayerTypes, bool, bool)
- Defined in
- CvMap.cpp, line 912
- Class
- CvMap
- Hook name
CivHooks::CvMap_findUnit
Hooks
static bool BeforeCvMap_findUnit(CvMap* self, int iX, int iY, PlayerTypes eOwner, bool bReadyToSelect, bool bWorkers, CvUnit*& result);static void AfterCvMap_findUnit(CvMap* self, int iX, int iY, PlayerTypes eOwner, bool bReadyToSelect, bool bWorkers, CvUnit*& result);static CvUnit* ReplaceCvMap_findUnit(CvUnit* (*original)(CvMap*, int, int, PlayerTypes, bool, bool), CvMap* self, int iX, int iY, PlayerTypes eOwner, bool bReadyToSelect, bool bWorkers);CivRegisterBefore<CivHooks::CvMap_findUnit>(host, &BeforeCvMap_findUnit);CivRegisterAfter<CivHooks::CvMap_findUnit>(host, &AfterCvMap_findUnit);CivRegisterReplace<CivHooks::CvMap_findUnit>(host, &ReplaceCvMap_findUnit);
Code
912CvUnit* CvMap::findUnit(int iX, int iY, PlayerTypes eOwner, bool bReadyToSelect, bool bWorkers)913{914 CvUnit* pLoopUnit;915 CvUnit* pBestUnit;916 int iValue;917 int iBestValue;918 int iLoop;919 int iI;920921 iBestValue = INT_MAX;922 pBestUnit = NULL;923924 for(iI = 0; iI < MAX_PLAYERS; iI++)925 {926 CvPlayer& thisPlayer = GET_PLAYER((PlayerTypes)iI);927 if(thisPlayer.isAlive())928 {929 if((eOwner == NO_PLAYER) || (iI == eOwner))930 {931 for(pLoopUnit = thisPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = thisPlayer.nextUnit(&iLoop))932 {933 if(!bReadyToSelect || pLoopUnit->ReadyToSelect())934 {935 if(!bWorkers || pLoopUnit->AI_getUnitAIType() == UNITAI_WORKER || pLoopUnit->AI_getUnitAIType() == UNITAI_WORKER_SEA)936 {937 iValue = plotDistance(iX, iY, pLoopUnit->getX(), pLoopUnit->getY());938939 if(iValue < iBestValue)940 {941 iBestValue = iValue;942 pBestUnit = pLoopUnit;943 }944 }945 }946 }947 }948 }949 }950951 return pBestUnit;952}