Bazaar developer reference

TradeRouteLandPathCost(CvAStarNode *, CvAStarNode *, int, const void *, CvAStar *)

Defined in
CvAStar.cpp, line 3959
Hook name
CivHooks::TradeRouteLandPathCost

Hooks

static bool BeforeTradeRouteLandPathCost(CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder, int& result);static void AfterTradeRouteLandPathCost(CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder, int& result);static int ReplaceTradeRouteLandPathCost(int (*original)(CvAStarNode*, CvAStarNode*, int, const void*, CvAStar*), CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder);CivRegisterBefore<CivHooks::TradeRouteLandPathCost>(host, &BeforeTradeRouteLandPathCost);CivRegisterAfter<CivHooks::TradeRouteLandPathCost>(host, &AfterTradeRouteLandPathCost);CivRegisterReplace<CivHooks::TradeRouteLandPathCost>(host, &ReplaceTradeRouteLandPathCost);

Code

3959int TradeRouteLandPathCost(CvAStarNode* parent, CvAStarNode* node, int data, const void* pointer, CvAStar* finder)3960{3961	PlayerTypes ePlayer = (PlayerTypes)finder->GetInfo();39623963	CvMap& kMap = GC.getMap();3964	int iFromPlotX = parent->m_iX;3965	int iFromPlotY = parent->m_iY;3966	CvPlot* pFromPlot = kMap.plotUnchecked(iFromPlotX, iFromPlotY);39673968	int iToPlotX = node->m_iX;3969	int iToPlotY = node->m_iY;3970	CvPlot* pToPlot = kMap.plotUnchecked(iToPlotX, iToPlotY);39713972	int iBaseCost = 100;3973	int iCost = iBaseCost;39743975	const TradePathCacheData* pCacheData = reinterpret_cast<const TradePathCacheData*>(finder->GetScratchBuffer());3976	FeatureTypes eFeature = pToPlot->getFeatureType();39773978	// super duper low costs for moving along routes3979	if (pFromPlot->getRouteType() != NO_ROUTE && pToPlot->getRouteType() != NO_ROUTE)3980	{3981		iCost = iCost / 2;3982	}3983	//// super low costs for moving along rivers3984	else if (pCacheData->IsRiverTradeRoad() && pFromPlot->isRiver() && pToPlot->isRiver())3985	{3986		iCost = iCost / 2;3987	}3988	// Iroquios ability3989	else if ((eFeature == FEATURE_FOREST || eFeature == FEATURE_JUNGLE) && pCacheData->IsMoveFriendlyWoodsAsRoad())3990	{3991		iCost = iCost / 2;3992	}3993	else3994	{3995		bool bFeaturePenalty = false;3996		if (eFeature == FEATURE_FOREST || eFeature == FEATURE_JUNGLE || eFeature == FEATURE_ICE)3997		{3998			bFeaturePenalty = true;3999		}40004001		if (pToPlot->isHills() || bFeaturePenalty)4002		{4003			iCost += 1;4004		}40054006		// extra cost for not going to an oasis! (this encourages routes to go through oasis)4007		if (eFeature != FEATURE_OASIS)4008		{4009			iCost += 1;4010		}4011	}40124013	if (pToPlot->isWater() && !pToPlot->IsAllowsWalkWater())4014	{4015		iCost += 1000;4016	}4017	4018	// Penalty for ending a turn on a mountain4019#if defined(MOD_GLOBAL_ALPINE_PASSES)4020	bool bMountain = pToPlot->isMountain();4021	if (bMountain && MOD_GLOBAL_ALPINE_PASSES && pToPlot->getRouteType() != NO_ROUTE) {4022		// Any land unit may travel over a mountain with a pass4023		bMountain = false;4024	}40254026	if (pToPlot->isImpassable() || bMountain)4027#else4028	if(pToPlot->isImpassable() || pToPlot->isMountain())4029#endif4030	{4031		iCost += 1000;4032	}40334034	FAssert(iCost != MAX_INT);4035	FAssert(iCost > 0);40364037	return iCost;4038}

Calls

Called by