From 9ffd9cea54e2edafbae834e5d0d1ad6210efbb20 Mon Sep 17 00:00:00 2001 From: azum4roll Date: Sun, 22 Oct 2023 18:43:35 +0800 Subject: [PATCH] use saner values for trade path valuation (#10380) --- CvGameCoreDLL_Expansion2/CvAStar.cpp | 49 ++++++++++++++++------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/CvGameCoreDLL_Expansion2/CvAStar.cpp b/CvGameCoreDLL_Expansion2/CvAStar.cpp index ace3bb519e..da61bdcf8e 100644 --- a/CvGameCoreDLL_Expansion2/CvAStar.cpp +++ b/CvGameCoreDLL_Expansion2/CvAStar.cpp @@ -3235,38 +3235,47 @@ int TradePathLandCost(const CvAStarNode* parent, const CvAStarNode* node, const const TradePathCacheData* pCacheData = reinterpret_cast(finder->GetScratchBuffer()); FeatureTypes eFeature = pToPlot->getFeatureType(); + TerrainTypes eTerrain = pToPlot->getTerrainType(); - // default - int iRouteDiscountPercent = 0; + int iRouteDiscountTimes120 = 0; + bool bIgnoreTerrain = false; - // super duper low costs for moving along routes - don't check for pillaging + // low costs for moving along routes - don't check for pillaging if (pFromPlot->getRouteType() == ROUTE_RAILROAD && pToPlot->isRoute()) - iRouteDiscountPercent = (pToPlot->getRouteType() == ROUTE_RAILROAD) ? 40 : 20; + iRouteDiscountTimes120 = (pToPlot->getRouteType() == ROUTE_RAILROAD) ? 70 : 54; + // make sure discount is big enough to force caravans onto roads else if (pFromPlot->getRouteType() == ROUTE_ROAD && pToPlot->isRoute()) - iRouteDiscountPercent = 20; //can't get better than this even if next plot is railroad - // low costs for moving along rivers - else if (pFromPlot->isRiver() && pToPlot->isRiver() && (pFromPlot->isCity() || pToPlot->isCity() || !(pFromPlot->isRiverCrossing(directionXY(pFromPlot, pToPlot))))) - iRouteDiscountPercent = 20; + iRouteDiscountTimes120 = 54; //can't get better than this even if next plot is railroad // Iroquois ability else if (((eFeature == FEATURE_FOREST || eFeature == FEATURE_JUNGLE) && pCacheData->IsWoodlandMovementBonus()) && (MOD_BALANCE_VP || pToPlot->getTeam() == GET_PLAYER(finder->GetData().ePlayer).getTeam()) && !(pFromPlot->isRiverCrossing(directionXY(pFromPlot, pToPlot)))) - iRouteDiscountPercent = 20; + iRouteDiscountTimes120 = 40; + // ignore terrain cost for moving along rivers + else if (pFromPlot->isRiver() && pToPlot->isRiver() && (pFromPlot->isCity() || pToPlot->isCity() || !(pFromPlot->isRiverCrossing(directionXY(pFromPlot, pToPlot))))) + { + // Songhai ability + if (pCacheData->IsRiverTradeRoad()) + iRouteDiscountTimes120 = 40; + else + bIgnoreTerrain = true; + } - // do not use extreme discounts here because we also need to use these paths for military target selection - int iCost = (PATH_BASE_COST*(100-iRouteDiscountPercent))/100; + if (iRouteDiscountTimes120 > 0) + bIgnoreTerrain = true; - //try to avoid rough plots - if (pToPlot->isRoughGround() && iRouteDiscountPercent == 0) - iCost += PATH_BASE_COST/10; + // do not use extreme discounts here because we also need to use these paths for military target selection + int iCost = PATH_BASE_COST * (120 - iRouteDiscountTimes120) / 120; - //avoid hills when in doubt - if (!pToPlot->isFlatlands() && iRouteDiscountPercent == 0) - iCost += PATH_BASE_COST/10; + // try to avoid difficult terrains/features + if ((eTerrain == TERRAIN_DESERT || eTerrain == TERRAIN_SNOW || eFeature == FEATURE_FOREST || eFeature == FEATURE_JUNGLE || eFeature == FEATURE_MARSH) && + eFeature != FEATURE_FLOOD_PLAINS && + bIgnoreTerrain) + iCost += PATH_BASE_COST / 4; - //bonus for oasis - if (eFeature == FEATURE_OASIS && iRouteDiscountPercent == 0) - iCost -= PATH_BASE_COST/10; + // avoid hills also if not Inca + if (!pToPlot->isFlatlands() && bIgnoreTerrain && !pCacheData->CanCrossMountain()) + iCost += PATH_BASE_COST / 4; return iCost; }