Hooks
static bool BeforeCvUnit_canAirliftAt(const CvUnit* self, const CvPlot* pPlot, int iX, int iY, bool& result);static void AfterCvUnit_canAirliftAt(const CvUnit* self, const CvPlot* pPlot, int iX, int iY, bool& result);static bool ReplaceCvUnit_canAirliftAt(bool (*original)(const CvUnit*, const CvPlot*, int, int), const CvUnit* self, const CvPlot* pPlot, int iX, int iY);CivRegisterBefore<CivHooks::CvUnit_canAirliftAt>(host, &BeforeCvUnit_canAirliftAt);CivRegisterAfter<CivHooks::CvUnit_canAirliftAt>(host, &AfterCvUnit_canAirliftAt);CivRegisterReplace<CivHooks::CvUnit_canAirliftAt>(host, &ReplaceCvUnit_canAirliftAt);
Code
6247bool CvUnit::canAirliftAt(const CvPlot* pPlot, int iX, int iY) const6248{6249 VALIDATE_OBJECT6250 CvPlot* pTargetPlot;6251#if defined(MOD_GLOBAL_RELOCATION)6252 const CvPlot* pFromPlot = getAirliftFromPlot(pPlot);6253 6254 if(pFromPlot == NULL)6255#else6256 CvCity* pStartCity;6257 CvCity* pTargetCity;62586259 if(!canAirlift(pPlot))6260#endif6261 {6262 return false;6263 }62646265#if !defined(MOD_GLOBAL_RELOCATION)6266 pStartCity = pPlot->getPlotCity();6267 if(pStartCity == NULL)6268 {6269 pStartCity = pPlot->GetAdjacentCity();6270 if (pStartCity == NULL)6271 {6272 return false;6273 }6274 }6275#endif62766277 pTargetPlot = GC.getMap().plot(iX, iY);6278 byte bMoveFlags = CvUnit::MOVEFLAG_DESTINATION;6279#if defined(MOD_GLOBAL_RELOCATION)6280 // Remove the water check as we could teleport onto a pontoon bridge6281 if(!pTargetPlot || !canMoveInto(*pTargetPlot, bMoveFlags))6282#else6283 if(!pTargetPlot || !canMoveInto(*pTargetPlot, bMoveFlags) || pTargetPlot->isWater())6284#endif6285 {6286 return false;6287 }62886289#if defined(MOD_GLOBAL_RELOCATION)6290 const CvPlot* pToPlot = getAirliftToPlot(pTargetPlot, pFromPlot->isCity());6291 if(pToPlot == NULL)6292 {6293 return false;6294 }6295#else6296 pTargetCity = pTargetPlot->getPlotCity();6297 if(pTargetCity == NULL)6298 {6299 pTargetCity = pTargetPlot->GetAdjacentFriendlyCity(getTeam());6300 if (pTargetCity == NULL)6301 {6302 return false;6303 }6304 }6305#endif63066307#if defined(MOD_GLOBAL_RELOCATION)6308 if (pToPlot == pFromPlot)6309#else6310 if (pTargetCity == pStartCity)6311#endif6312 {6313 return false;6314 }63156316#if !defined(MOD_GLOBAL_RELOCATION)6317 if (!pTargetCity->CanAirlift())6318 {6319 return false;6320 }6321#endif63226323 // No enemy units adjacent6324 CvPlot* pAdjacentPlot;6325 int iI;6326 for(iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)6327 {6328 pAdjacentPlot = plotDirection(iX, iY, ((DirectionTypes)iI));6329 if(pAdjacentPlot != NULL)6330 {6331 UnitHandle pDefender = pAdjacentPlot->getBestDefender(NO_PLAYER, getOwner(), NULL, true);6332 if (pDefender)6333 {6334 return false;6335 }6336 }6337 }63386339#if !defined(MOD_GLOBAL_RELOCATION)6340 if(pTargetCity->getTeam() != getTeam())6341 {6342 return false;6343 }6344#endif63456346 return true;6347}