Hooks
static bool BeforeCvUnitMovement_IsSlowedByZOC(const CvUnit* pUnit, const CvPlot* pFromPlot, const CvPlot* pToPlot, bool& result);static void AfterCvUnitMovement_IsSlowedByZOC(const CvUnit* pUnit, const CvPlot* pFromPlot, const CvPlot* pToPlot, bool& result);static bool ReplaceCvUnitMovement_IsSlowedByZOC(bool (*original)(const CvUnit*, const CvPlot*, const CvPlot*), const CvUnit* pUnit, const CvPlot* pFromPlot, const CvPlot* pToPlot);CivRegisterBefore<CivHooks::CvUnitMovement_IsSlowedByZOC>(host, &BeforeCvUnitMovement_IsSlowedByZOC);CivRegisterAfter<CivHooks::CvUnitMovement_IsSlowedByZOC>(host, &AfterCvUnitMovement_IsSlowedByZOC);CivRegisterReplace<CivHooks::CvUnitMovement_IsSlowedByZOC>(host, &ReplaceCvUnitMovement_IsSlowedByZOC);
Code
286bool CvUnitMovement::IsSlowedByZOC(const CvUnit* pUnit, const CvPlot* pFromPlot, const CvPlot* pToPlot)287{288 if (pUnit->IsIgnoreZOC() || CostsOnlyOne(pUnit, pFromPlot, pToPlot))289 {290 return false;291 }292293 // Zone of Control294 if(GC.getZONE_OF_CONTROL_ENABLED() > 0)295 {296 IDInfo* pAdjUnitNode;297 CvUnit* pLoopUnit;298299 int iFromPlotX = pFromPlot->getX();300 int iFromPlotY = pFromPlot->getY();301 int iToPlotX = pToPlot->getX();302 int iToPlotY = pToPlot->getY();303 TeamTypes unit_team_type = pUnit->getTeam();304 DomainTypes unit_domain_type = pUnit->getDomainType();305 bool bIsVisibleEnemyUnit = pToPlot->isVisibleEnemyUnit(pUnit);306 CvTeam& kUnitTeam = GET_TEAM(unit_team_type);307308 for(int iDirection0 = 0; iDirection0 < NUM_DIRECTION_TYPES; iDirection0++)309 {310 CvPlot* pAdjPlot = plotDirection(iFromPlotX, iFromPlotY, ((DirectionTypes)iDirection0));311 if(NULL != pAdjPlot)312 {313 // check city zone of control314 if(pAdjPlot->isEnemyCity(*pUnit))315 {316 // Loop through plots adjacent to the enemy city and see if it's the same as our unit's Destination Plot317 for(int iDirection = 0; iDirection < NUM_DIRECTION_TYPES; iDirection++)318 {319 CvPlot* pEnemyAdjPlot = plotDirection(pAdjPlot->getX(), pAdjPlot->getY(), ((DirectionTypes)iDirection));320 if(NULL != pEnemyAdjPlot)321 {322 // Destination adjacent to enemy city?323 if(pEnemyAdjPlot->getX() == iToPlotX && pEnemyAdjPlot->getY() == iToPlotY)324 {325 return true;326 }327 }328 }329 }330331 pAdjUnitNode = pAdjPlot->headUnitNode();332 // Loop through all units to see if there's an enemy unit here333 while(pAdjUnitNode != NULL)334 {335 if((pAdjUnitNode->eOwner >= 0) && pAdjUnitNode->eOwner < MAX_PLAYERS)336 {337 pLoopUnit = (GET_PLAYER(pAdjUnitNode->eOwner).getUnit(pAdjUnitNode->iID));338 }339 else340 {341 pLoopUnit = NULL;342 }343344 pAdjUnitNode = pAdjPlot->nextUnitNode(pAdjUnitNode);345346 if(!pLoopUnit) continue;347348 TeamTypes unit_loop_team_type = pLoopUnit->getTeam();349350 if(pLoopUnit->isInvisible(unit_team_type,false)) continue;351352 // Combat unit?353 if(!pLoopUnit->IsCombatUnit())354 {355 continue;356 }357358 // At war with this unit's team?359 if(unit_loop_team_type == BARBARIAN_TEAM || kUnitTeam.isAtWar(unit_loop_team_type))360 {361362 // Same Domain?363364 DomainTypes loop_unit_domain_type = pLoopUnit->getDomainType();365 if(loop_unit_domain_type != unit_domain_type)366 {367 // this is valid368 if(loop_unit_domain_type == DOMAIN_SEA && unit_domain_type)369 {370 // continue on371 }372#if defined(MOD_BUGFIX_HOVERING_PATHFINDER)373 // hovering units always exert a ZOC374 else if (pLoopUnit->IsHoveringUnit()) {375 // continue on376 }377#endif378 else379 {380 continue;381 }382 }383384 // Embarked?385 if(unit_domain_type == DOMAIN_LAND && pLoopUnit->isEmbarked())386 {387 continue;388 }389390 // Loop through plots adjacent to the enemy unit and see if it's the same as our unit's Destination Plot391 for(int iDirection2 = 0; iDirection2 < NUM_DIRECTION_TYPES; iDirection2++)392 {393 CvPlot* pEnemyAdjPlot = plotDirection(pAdjPlot->getX(), pAdjPlot->getY(), ((DirectionTypes)iDirection2));394 if(!pEnemyAdjPlot)395 {396 continue;397 }398399 // Don't check Enemy Unit's plot400 if(!bIsVisibleEnemyUnit)401 {402 // Destination adjacent to enemy unit?403 if(pEnemyAdjPlot->getX() == iToPlotX && pEnemyAdjPlot->getY() == iToPlotY)404 {405 return true;406 }407 }408 }409 }410 }411 }412 }413 }414 return false;415}