1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #898 from vcmi/cache-pathfinding

Cache pathfinding
This commit is contained in:
DjWarmonger 2022-09-14 20:32:54 +02:00 committed by GitHub
commit d34dd8676e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 4 deletions

View File

@ -107,7 +107,7 @@ void ExecuteHeroChain::accept(AIGateway * ai)
|| targetNode->turns != 0)
{
logAi->error(
"Enable to complete chain. Expected hero %s to arive to %s in 0 turns but he can not do this",
"Unable to complete chain. Expected hero %s to arrive to %s in 0 turns but he cannot do this",
hero->name,
node.coord.toString());

View File

@ -1019,6 +1019,7 @@ TurnInfo::BonusCache::BonusCache(TConstBonusListPtr bl)
flyingMovementVal = bl->valOfBonuses(Selector::type()(Bonus::FLYING_MOVEMENT));
waterWalking = static_cast<bool>(bl->getFirst(Selector::type()(Bonus::WATER_WALKING)));
waterWalkingVal = bl->valOfBonuses(Selector::type()(Bonus::WATER_WALKING));
pathfindingVal = bl->valOfBonuses(Selector::typeSubtype(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::PATHFINDING));
}
TurnInfo::TurnInfo(const CGHeroInstance * Hero, const int turn)
@ -1075,6 +1076,9 @@ int TurnInfo::valOfBonuses(Bonus::BonusType type, int subtype) const
return bonusCache->flyingMovementVal;
case Bonus::WATER_WALKING:
return bonusCache->waterWalkingVal;
case Bonus::SECONDARY_SKILL_PREMY:
if (subtype == SecondarySkill::PATHFINDING)
return bonusCache->pathfindingVal;
}
return bonuses->valOfBonuses(Selector::type()(type).And(Selector::subtype()(subtype)));

View File

@ -513,6 +513,7 @@ struct DLL_LINKAGE TurnInfo
int flyingMovementVal;
bool waterWalking;
int waterWalkingVal;
int pathfindingVal;
BonusCache(TConstBonusListPtr bonusList);
};

View File

@ -103,11 +103,9 @@ ui32 CGHeroInstance::getTileCost(const TerrainTile & dest, const TerrainTile & f
&& !ti->hasBonusOfType(Bonus::NO_TERRAIN_PENALTY, from.terType.id()) //no special movement bonus
)
{
static const CSelector selectorPATHFINDING = Selector::typeSubtype(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::PATHFINDING);
static const std::string keyPATHFINDING = "type_"+std::to_string((si32)Bonus::SECONDARY_SKILL_PREMY)+"s_"+std::to_string((si32)SecondarySkill::PATHFINDING);
ret = VLC->heroh->terrCosts[from.terType];
ret -= valOfBonuses(selectorPATHFINDING, keyPATHFINDING);
ret -= ti->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, SecondarySkill::PATHFINDING);
if(ret < GameConstants::BASE_MOVEMENT_COST)
ret = GameConstants::BASE_MOVEMENT_COST;
}