Skip to content

Commit

Permalink
use saner values for trade path valuation (#10380)
Browse files Browse the repository at this point in the history
  • Loading branch information
azum4roll authored Oct 22, 2023
1 parent ff77622 commit 9ffd9ce
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions CvGameCoreDLL_Expansion2/CvAStar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3235,38 +3235,47 @@ int TradePathLandCost(const CvAStarNode* parent, const CvAStarNode* node, const

const TradePathCacheData* pCacheData = reinterpret_cast<const TradePathCacheData*>(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;
}
Expand Down

0 comments on commit 9ffd9ce

Please sign in to comment.