mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
compute movement cost using PathNodeInfo layer info when possible
This commit is contained in:
@@ -1215,7 +1215,9 @@ int CPathfinderHelper::getMovementCost(
|
||||
const TerrainTile * ct,
|
||||
const TerrainTile * dt,
|
||||
const int remainingMovePoints,
|
||||
const bool checkLast) const
|
||||
const bool checkLast,
|
||||
boost::logic::tribool isDstSailLayer,
|
||||
boost::logic::tribool isDstWaterLayer) const
|
||||
{
|
||||
if(src == dst) //same tile
|
||||
return 0;
|
||||
@@ -1228,15 +1230,27 @@ int CPathfinderHelper::getMovementCost(
|
||||
dt = hero->cb->getTile(dst);
|
||||
}
|
||||
|
||||
bool isSailLayer;
|
||||
if(indeterminate(isDstSailLayer))
|
||||
isSailLayer = hero->boat != nullptr && dt->terType->isWater();
|
||||
else
|
||||
isSailLayer = static_cast<bool>(isDstSailLayer);
|
||||
|
||||
bool isWaterLayer;
|
||||
if(indeterminate(isDstWaterLayer))
|
||||
isWaterLayer = dt->terType->isWater();
|
||||
else
|
||||
isWaterLayer = static_cast<bool>(isDstWaterLayer);
|
||||
|
||||
int ret = hero->getTileCost(*dt, *ct, ti);
|
||||
if(hero->boat != nullptr && dt->terType->isWater())
|
||||
if(isSailLayer)
|
||||
{
|
||||
if(ct->hasFavorableWinds())
|
||||
ret = static_cast<int>(ret * 2.0 / 3);
|
||||
}
|
||||
else if(ti->hasBonusOfType(Bonus::FLYING_MOVEMENT))
|
||||
vstd::amin(ret, GameConstants::BASE_MOVEMENT_COST + ti->valOfBonuses(Bonus::FLYING_MOVEMENT));
|
||||
else if(hero->boat == nullptr && dt->terType->isWater() && ti->hasBonusOfType(Bonus::WATER_WALKING))
|
||||
else if(isWaterLayer && ti->hasBonusOfType(Bonus::WATER_WALKING))
|
||||
ret = static_cast<int>(ret * (100.0 + ti->valOfBonuses(Bonus::WATER_WALKING)) / 100.0);
|
||||
|
||||
if(src.x != dst.x && src.y != dst.y) //it's diagonal move
|
||||
|
@@ -591,8 +591,10 @@ public:
|
||||
const int3 & dst,
|
||||
const TerrainTile * ct,
|
||||
const TerrainTile * dt,
|
||||
const int remainingMovePoints =- 1,
|
||||
const bool checkLast = true) const;
|
||||
const int remainingMovePoints = -1,
|
||||
const bool checkLast = true,
|
||||
boost::logic::tribool isDstSailLayer = boost::logic::indeterminate,
|
||||
boost::logic::tribool isDstWaterLayer = boost::logic::indeterminate) const;
|
||||
|
||||
int getMovementCost(
|
||||
const PathNodeInfo & src,
|
||||
@@ -606,7 +608,9 @@ public:
|
||||
src.tile,
|
||||
dst.tile,
|
||||
remainingMovePoints,
|
||||
checkLast
|
||||
checkLast,
|
||||
dst.node->layer == EPathfindingLayer::SAIL,
|
||||
dst.node->layer == EPathfindingLayer::WATER
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user