PathDestValid(int, int, const void *, CvAStar *)
- Defined in
- CvAStar.cpp, line 849
- Hook name
CivHooks::PathDestValid
Hooks
static bool BeforePathDestValid(int iToX, int iToY, const void* pointer, CvAStar* finder, int& result);static void AfterPathDestValid(int iToX, int iToY, const void* pointer, CvAStar* finder, int& result);static int ReplacePathDestValid(int (*original)(int, int, const void*, CvAStar*), int iToX, int iToY, const void* pointer, CvAStar* finder);CivRegisterBefore<CivHooks::PathDestValid>(host, &BeforePathDestValid);CivRegisterAfter<CivHooks::PathDestValid>(host, &AfterPathDestValid);CivRegisterReplace<CivHooks::PathDestValid>(host, &ReplacePathDestValid);
Code
848/// Standard path finder - is this end point for the path valid?849int PathDestValid(int iToX, int iToY, const void* pointer, CvAStar* finder)850{851 CvUnit* pUnit;852 CvPlot* pToPlot;853 bool bAIControl;854855 pToPlot = GC.getMap().plotCheckInvalid(iToX, iToY);856 FAssert(pToPlot != NULL);857858 pUnit = ((CvUnit*)pointer);859 const UnitPathCacheData* pCacheData = reinterpret_cast<const UnitPathCacheData*>(finder->GetScratchBuffer());860861 if(pToPlot == NULL || pUnit == NULL)862 return FALSE;863864 if(pUnit->plot() == pToPlot)865 {866 return TRUE;867 }868869 if(pToPlot->isMountain() && (!pCacheData->isHuman() || pCacheData->IsAutomated()))870 {871 return FALSE;872 }873874 if(pCacheData->IsImmobile())875 {876 return FALSE;877 }878879 if ((finder->GetInfo() & CvUnit::MOVEFLAG_STAY_ON_LAND) && (pToPlot->isWater() && !pToPlot->IsAllowsWalkWater()))880 {881 return FALSE;882 }883884 bAIControl = pCacheData->IsAutomated();885886 if(bAIControl)887 {888 if(!(finder->GetInfo() & MOVE_UNITS_IGNORE_DANGER))889 {890 if(!pUnit->IsCombatUnit() || pUnit->getArmyID() == FFreeList::INVALID_INDEX)891 {892 if(GET_PLAYER(pUnit->getOwner()).GetPlotDanger(*pToPlot) > 0)893 {894 return FALSE;895 }896 }897 }898899 if(pCacheData->getDomainType() == DOMAIN_LAND)900 {901 int iGroupAreaID = pUnit->area()->GetID();902 if(pToPlot->getArea() != iGroupAreaID)903 {904 if(!(pToPlot->isAdjacentToArea(iGroupAreaID)) && !pUnit->CanEverEmbark())905 {906 return FALSE;907 }908 }909 }910 }911912 TeamTypes eTeam = pCacheData->getTeam();913 bool bToPlotRevealed = pToPlot->isRevealed(eTeam);914 if(!bToPlotRevealed)915 {916 if(pCacheData->isNoRevealMap())917 {918 return FALSE;919 }920 }921922#if defined(MOD_GLOBAL_BREAK_CIVILIAN_RESTRICTIONS)923 if(bToPlotRevealed && (!MOD_GLOBAL_BREAK_CIVILIAN_RESTRICTIONS || pUnit->IsCombatUnit()))924#else925 if(bToPlotRevealed)926#endif927 {928 CvCity* pCity = pToPlot->getPlotCity();929 if(pCity)930 {931 if(pCacheData->getOwner() != pCity->getOwner() && !GET_TEAM(eTeam).isAtWar(pCity->getTeam()) && !(finder->GetInfo() & MOVE_IGNORE_STACKING))932 {933 return FALSE;934 }935 }936 }937938 if(bAIControl || bToPlotRevealed)939 {940 // assume that we can change our embarking state941 byte bMoveFlags = CvUnit::MOVEFLAG_DESTINATION | CvUnit::MOVEFLAG_PRETEND_CORRECT_EMBARK_STATE;942943 if((pUnit->IsDeclareWar() || (finder->GetInfo() & MOVE_DECLARE_WAR)))944 {945 bMoveFlags |= CvUnit::MOVEFLAG_ATTACK;946 }947948 if(finder->GetInfo() & MOVE_IGNORE_STACKING)949 {950 bMoveFlags |= CvUnit::MOVEFLAG_IGNORE_STACKING;951 }952953 if(!(pUnit->canMoveOrAttackInto(*pToPlot, bMoveFlags)))954 {955 return FALSE;956 }957 }958 return TRUE;959}
Calls
- CustomMods::isGLOBAL_BREAK_CIVILIAN_1UPT()
- CustomMods::isGLOBAL_BREAK_CIVILIAN_RESTRICTIONS()
- CvArea::GetID() const
- CvAStar::GetInfo()
- CvAStar::GetScratchBuffer()
- CvCity::getOwner() const
- CvCity::getTeam() const
- CvGlobals::getMap()
- CvMap::plotCheckInvalid(int, int) const
- CvPlayer::GetPlotDanger(CvPlot &) const
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPlot::getArea() const
- CvPlot::getPlotCity() const
- CvPlot::isAdjacentToArea(int) const
- CvPlot::IsAllowsWalkWater() const
- CvPlot::isMountain() const
- CvPlot::isRevealed(TeamTypes) const
- CvPlot::isWater() const
- CvTeam::getTeam(TeamTypes)
- CvTeam::isAtWar(TeamTypes) const
- CvUnit::area() const
- CvUnit::CanEverEmbark() const
- CvUnit::canMoveOrAttackInto(const CvPlot &, byte) const
- CvUnit::getArmyID() const
- CvUnit::getOwner() const
- CvUnit::IsCombatUnit() const
- CvUnit::IsDeclareWar() const
- CvUnit::plot() const
- UnitPathCacheData::getDomainType() const
- UnitPathCacheData::getOwner() const
- UnitPathCacheData::getTeam() const
- UnitPathCacheData::IsAutomated() const
- UnitPathCacheData::isHuman() const
- UnitPathCacheData::IsImmobile() const
- UnitPathCacheData::isNoRevealMap() const