CvUnit::canEnterTerrain(const CvPlot &, byte) const
- Defined in
- CvUnit.cpp, line 2654
- Class
- CvUnit
- Hook name
CivHooks::CvUnit_canEnterTerrain
Hooks
static bool BeforeCvUnit_canEnterTerrain(const CvUnit* self, const CvPlot& enterPlot, byte bMoveFlags, bool& result);static void AfterCvUnit_canEnterTerrain(const CvUnit* self, const CvPlot& enterPlot, byte bMoveFlags, bool& result);static bool ReplaceCvUnit_canEnterTerrain(bool (*original)(const CvUnit*, const CvPlot&, byte), const CvUnit* self, const CvPlot& enterPlot, byte bMoveFlags);CivRegisterBefore<CivHooks::CvUnit_canEnterTerrain>(host, &BeforeCvUnit_canEnterTerrain);CivRegisterAfter<CivHooks::CvUnit_canEnterTerrain>(host, &AfterCvUnit_canEnterTerrain);CivRegisterReplace<CivHooks::CvUnit_canEnterTerrain>(host, &ReplaceCvUnit_canEnterTerrain);
Code
2654bool CvUnit::canEnterTerrain(const CvPlot& enterPlot, byte bMoveFlags) const2655{2656 VALIDATE_OBJECT2657 if(enterPlot.isImpassable())2658 {2659 if(!(m_iCanMoveImpassableCount > 0) && !canMoveAllTerrain())2660 {2661#if defined(MOD_PATHFINDER_CROSS_ICE)2662 if (enterPlot.isIce() && canCrossIce()) {2663 return true;2664 } else {2665#endif2666 return false;2667#if defined(MOD_PATHFINDER_CROSS_ICE)2668 }2669#endif2670 }2671 }26722673#if defined(MOD_GLOBAL_ALPINE_PASSES)2674 bool bMountain = enterPlot.isMountain();2675 if (bMountain && MOD_GLOBAL_ALPINE_PASSES && getDomainType() == DOMAIN_LAND && enterPlot.getRouteType() != NO_ROUTE) {2676 // Any land unit may travel over a mountain with a pass2677 bMountain = false;2678 }26792680 if(bMountain)2681#else2682 if(enterPlot.isMountain())2683#endif2684 {2685#if defined(MOD_PATHFINDER_CROSS_MOUNTAINS)2686 bool bCanCross = IsHoveringUnit() || canMoveAllTerrain() || canCrossMountains(); // Player trait is included in the canCrossMountains() method2687 if (!bCanCross)2688#else2689 CvPlayer& kPlayer = GET_PLAYER(getOwner());2690 if(!kPlayer.GetPlayerTraits()->IsAbleToCrossMountains() && !IsHoveringUnit() && !canMoveAllTerrain())2691#endif2692 {2693 return false;2694 }2695 }2696 2697#if defined(MOD_PATHFINDER_CROSS_OCEANS)2698 if (enterPlot.isWater() && !enterPlot.isShallowWater()) {2699 if (canCrossOceans()) {2700 return true;2701 }2702 }2703#endif27042705#if defined(MOD_PATHFINDER_CROSS_ICE)2706 if (enterPlot.isIce()) {2707 CvPlayer& kPlayer = GET_PLAYER(getOwner());2708 bool bCanCross = canCrossIce() || (kPlayer.GetPlayerTraits()->IsAbleToCrossIce());2709 if (bCanCross) {2710 return true;2711 }2712 }2713#endif27142715 DomainTypes eDomain = getDomainType();27162717 // Immobile Unit?27182719 if(eDomain == DOMAIN_IMMOBILE || m_bImmobile)2720 {2721 return false;2722 }27232724 bool bAllowsWalkWater = enterPlot.IsAllowsWalkWater();2725 if (enterPlot.isWater() && (bMoveFlags & CvUnit::MOVEFLAG_STAY_ON_LAND) && !bAllowsWalkWater)2726 {2727 return false;2728 }27292730 TeamTypes eTeam = getTeam();27312732 if(canEnterTerritory(enterPlot.getTeam(), false /*bIgnoreRightOfPassage*/, enterPlot.getPlotCity() != NULL, bMoveFlags & MOVEFLAG_DECLARE_WAR))2733 {2734 if(enterPlot.getFeatureType() != NO_FEATURE && enterPlot.getRouteType() == NO_ROUTE) // assume that all units can use roads and rails2735 {2736 if(isFeatureImpassable(enterPlot.getFeatureType()))2737 {2738 bool bCanPass = false;27392740#if defined(MOD_PATHFINDER_CROSS_ICE)2741 // We checked for passable ice much higher up2742#endif27432744 // Check all Promotions to see if this Unit has one which allows Impassable movement with a certain Tech2745 if(m_Promotions.GetAllowFeaturePassable(enterPlot.getFeatureType()))2746 {2747 return true;2748 }27492750 if(!bCanPass)2751 {2752 if(DOMAIN_SEA != eDomain || enterPlot.getTeam() != eTeam) // sea units can enter impassable in own cultural borders2753 {2754 if(!canLoad(enterPlot))2755 {2756 return false;2757 }2758 }2759 }2760 }2761 }2762 else2763 {2764#if defined(MOD_GLOBAL_ALPINE_PASSES)2765 if (!(MOD_GLOBAL_ALPINE_PASSES && getDomainType() == DOMAIN_LAND && (enterPlot.getRouteType() != NO_ROUTE))) {2766#endif2767 if(isTerrainImpassable(enterPlot.getTerrainType()))2768 {2769 bool bCanPass = false;27702771 // Check all Promotions to see if this Unit has one which allows Impassable movement with a certain Tech2772 bCanPass = m_Promotions.GetAllowTerrainPassable(enterPlot.getTerrainType());2773 if(!bCanPass)2774 {2775 if(DOMAIN_SEA != eDomain || enterPlot.getTeam() != eTeam) // sea units can enter impassable in own cultural borders2776 {2777 if(!canLoad(enterPlot))2778 {2779 return false;2780 }2781 }2782 }2783 }2784#if defined(MOD_GLOBAL_ALPINE_PASSES)2785 }2786#endif2787 }2788 }27892790 switch(eDomain)2791 {2792 case DOMAIN_SEA:2793 if(!enterPlot.isWater() && !canMoveAllTerrain())2794 {2795#if defined(MOD_GLOBAL_PASSABLE_FORTS)2796 bool bCanEnter = (enterPlot.isFriendlyCityOrPassableImprovement(*this, true) && (MOD_GLOBAL_PASSABLE_FORTS_ANY || enterPlot.isCoastalLand() || plot()->isLake()));2797 if(!bCanEnter && !enterPlot.isEnemyCity(*this))2798 {2799 return false;2800 }2801#else2802 if(!enterPlot.isFriendlyCity(*this, true) && !enterPlot.isEnemyCity(*this))2803 {2804 return false;2805 }2806#endif2807 }2808 break;28092810 case DOMAIN_AIR:2811 // Air units can move anywhere2812 break;28132814 case DOMAIN_LAND:2815 {2816 if (bAllowsWalkWater)2817 {2818 return true;2819 }28202821 if(bMoveFlags & MOVEFLAG_PRETEND_CORRECT_EMBARK_STATE)2822 {2823 // if this is water and this unit can embark2824 if(enterPlot.isWater() && !canMoveAllTerrain())2825 {2826 if(CanEverEmbark())2827 {2828 // Can't enter deep water until you have the appropriate Tech2829 if(enterPlot.getTerrainType() == GC.getDEEP_WATER_TERRAIN() && !GET_TEAM(eTeam).canEmbarkAllWaterPassage() && !IsEmbarkAllWater())2830 {2831 return false;2832 }2833 }2834 // Does the unit hover above coast?2835 else if(IsHoveringUnit())2836 {2837#if defined(MOD_BUGFIX_HOVERING_PATHFINDER)2838 // Ice trumps ocean!2839 if (enterPlot.getFeatureType() == FEATURE_ICE) {2840 return true;2841 } else {2842#endif2843 if(enterPlot.getTerrainType() == GC.getDEEP_WATER_TERRAIN())2844 {2845#if defined(MOD_PATHFINDER_DEEP_WATER_EMBARKATION)2846 return IsEmbarkDeepWater();2847#else2848 return false;2849#endif2850 }2851#if defined(MOD_BUGFIX_HOVERING_PATHFINDER)2852 }2853#endif2854 }2855 else2856 {2857 return false;2858 }2859 }2860 }2861 else2862 {2863 // slewis - not my best piece of logic, but yeah2864 bool bEmbarked = (isEmbarked() || (bMoveFlags & MOVEFLAG_PRETEND_EMBARKED)) && !(bMoveFlags & MOVEFLAG_PRETEND_UNEMBARKED);28652866 if(bEmbarked)2867 {2868 if(!enterPlot.isWater())2869 {2870 return false;2871 }2872 // Can't enter deep water until you have the appropriate Tech2873 if(enterPlot.getTerrainType() == GC.getDEEP_WATER_TERRAIN() && !GET_TEAM(eTeam).canEmbarkAllWaterPassage() && !IsEmbarkAllWater())2874 {2875 return false;2876 }2877 }2878 else // !bEmbarked2879 {2880 if(enterPlot.isWater() && !canMoveAllTerrain() && !enterPlot.isCity())2881 {2882 // Does the unit hover above coast?2883 if(IsHoveringUnit())2884 {2885#if defined(MOD_BUGFIX_HOVERING_PATHFINDER)2886 // Ice trumps ocean!2887 if (enterPlot.getFeatureType() == FEATURE_ICE) {2888 return true;2889 } else {2890#endif2891 if(enterPlot.getTerrainType() == GC.getDEEP_WATER_TERRAIN())2892 {2893 return false;2894 }2895#if defined(MOD_BUGFIX_HOVERING_PATHFINDER)2896 }2897#endif2898 }2899 else if(!isHuman() || (plot() && plot()->isWater()) || !canLoad(enterPlot))2900 {2901 return false;2902 }2903 }2904 }2905 }2906 }2907 break;29082909 case DOMAIN_IMMOBILE:2910 return false;2911 break;29122913 default:2914 CvAssert(false);2915 break;2916 }29172918 return true;2919}
Calls
- CustomMods::isGLOBAL_ALPINE_PASSES()
- CustomMods::isGLOBAL_PASSABLE_FORTS()
- CustomMods::isGLOBAL_PASSABLE_FORTS_ANY()
- CvGlobals::getDEEP_WATER_TERRAIN()
- CvPlayer::GetPlayerTraits() const
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPlayerTraits::IsAbleToCrossIce() const
- CvPlot::getFeatureType() const
- CvPlot::getPlotCity() const
- CvPlot::getRouteType() const
- CvPlot::getTeam() const
- CvPlot::getTerrainType() const
- CvPlot::IsAllowsWalkWater() const
- CvPlot::isCity() const
- CvPlot::isCoastalLand(int) const
- CvPlot::isEnemyCity(const CvUnit &) const
- CvPlot::isFriendlyCityOrPassableImprovement(const CvUnit &, bool) const
- CvPlot::isIce() const
- CvPlot::isImpassable() const
- CvPlot::isLake() const
- CvPlot::isMountain() const
- CvPlot::isShallowWater() const
- CvPlot::isWater() const
- CvTeam::canEmbarkAllWaterPassage() const
- CvTeam::getTeam(TeamTypes)
- CvUnit::canCrossIce() const
- CvUnit::canCrossMountains() const
- CvUnit::canCrossOceans() const
- CvUnit::canEnterTerritory(TeamTypes, bool, bool, bool) const
- CvUnit::CanEverEmbark() const
- CvUnit::canLoad(const CvPlot &) const
- CvUnit::canMoveAllTerrain() const
- CvUnit::getDomainType() const
- CvUnit::getOwner() const
- CvUnit::getTeam() const
- CvUnit::IsEmbarkAllWater() const
- CvUnit::IsEmbarkDeepWater() const
- CvUnit::isEmbarked() const
- CvUnit::isFeatureImpassable(FeatureTypes) const
- CvUnit::IsHoveringUnit() const
- CvUnit::isHuman() const
- CvUnit::isTerrainImpassable(TerrainTypes) const
- CvUnit::plot() const
- CvUnitPromotions::GetAllowFeaturePassable(FeatureTypes) const
- CvUnitPromotions::GetAllowTerrainPassable(TerrainTypes) const
FAutoVariable::operator const bool &FAutoVariable::operator const int &
Called by
- FindValidDestinationPathValid(CvAStarNode *, CvAStarNode *, int, const void *, CvAStar *)
- IgnoreUnitsDestValid(int, int, const void *, CvAStar *)
- IgnoreUnitsValid(CvAStarNode *, CvAStarNode *, int, const void *, CvAStar *)
- PathValid(CvAStarNode *, CvAStarNode *, int, const void *, CvAStar *)
- TacticalAnalysisMapPathValid(CvAStarNode *, CvAStarNode *, int, const void *, CvAStar *)
- UIPathValid(CvAStarNode *, CvAStarNode *, int, const void *, CvAStar *)
- CvTacticalAI::PlotSingleHexOperationMoves(CvAIEscortedOperation *)
- CvUnit::CanSwapWithUnitHere(CvPlot &) const
- CvUnit::PlotValid(CvPlot *, byte) const
- CvUnit::canMoveInto(const CvPlot &, byte) const
- CvUnit::convert(CvUnit *, bool)