mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
CGHeroInstance: move native terrain check into getNativeTerrain
That make it easier to use that code independently in TurnInfo
This commit is contained in:
parent
a375c86ea2
commit
438a444443
@ -732,6 +732,7 @@ TurnInfo::TurnInfo(const CGHeroInstance * Hero, const int turn)
|
||||
|
||||
bonuses = hero->getAllBonuses(Selector::days(turn), nullptr, nullptr, cachingStr.str());
|
||||
bonusCache = make_unique<BonusCache>(bonuses);
|
||||
nativeTerrain = hero->getNativeTerrain();
|
||||
}
|
||||
|
||||
bool TurnInfo::isLayerAvailable(const EPathfindingLayer layer) const
|
||||
|
@ -227,6 +227,7 @@ struct DLL_LINKAGE TurnInfo
|
||||
TBonusListPtr bonuses;
|
||||
mutable int maxMovePointsLand;
|
||||
mutable int maxMovePointsWater;
|
||||
int nativeTerrain;
|
||||
|
||||
TurnInfo(const CGHeroInstance * Hero, const int Turn = 0);
|
||||
bool isLayerAvailable(const EPathfindingLayer layer) const;
|
||||
|
@ -80,30 +80,40 @@ ui32 CGHeroInstance::getTileCost(const TerrainTile &dest, const TerrainTile &fro
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(!ti->hasBonusOfType(Bonus::NO_TERRAIN_PENALTY, from.terType))
|
||||
else if(ti->nativeTerrain != from.terType && !ti->hasBonusOfType(Bonus::NO_TERRAIN_PENALTY, from.terType))
|
||||
{
|
||||
// NOTE: in H3 neutral stacks will ignore terrain penalty only if placed as topmost stack(s) in hero army.
|
||||
// This is clearly bug in H3 however intended behaviour is not clear.
|
||||
// Current VCMI behaviour will ignore neutrals in calculations so army in VCMI
|
||||
// will always have best penalty without any influence from player-defined stacks order
|
||||
|
||||
for(auto stack : stacks)
|
||||
{
|
||||
int nativeTerrain = VLC->townh->factions[stack.second->type->faction]->nativeTerrain;
|
||||
if(nativeTerrain != -1 && nativeTerrain != from.terType)
|
||||
{
|
||||
ret = VLC->heroh->terrCosts[from.terType];
|
||||
ret -= getSecSkillLevel(SecondarySkill::PATHFINDING) * 25;
|
||||
if(ret < GameConstants::BASE_MOVEMENT_COST)
|
||||
ret = GameConstants::BASE_MOVEMENT_COST;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret = VLC->heroh->terrCosts[from.terType];
|
||||
ret -= getSecSkillLevel(SecondarySkill::PATHFINDING) * 25;
|
||||
if(ret < GameConstants::BASE_MOVEMENT_COST)
|
||||
ret = GameConstants::BASE_MOVEMENT_COST;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CGHeroInstance::getNativeTerrain() const
|
||||
{
|
||||
// NOTE: in H3 neutral stacks will ignore terrain penalty only if placed as topmost stack(s) in hero army.
|
||||
// This is clearly bug in H3 however intended behaviour is not clear.
|
||||
// Current VCMI behaviour will ignore neutrals in calculations so army in VCMI
|
||||
// will always have best penalty without any influence from player-defined stacks order
|
||||
|
||||
// TODO: What should we do if all hero stacks are neutral creatures?
|
||||
int nativeTerrain = -1;
|
||||
for(auto stack : stacks)
|
||||
{
|
||||
int stackNativeTerrain = VLC->townh->factions[stack.second->type->faction]->nativeTerrain;
|
||||
if(stackNativeTerrain == -1)
|
||||
continue;
|
||||
|
||||
if(nativeTerrain == -1)
|
||||
nativeTerrain = stackNativeTerrain;
|
||||
else if(nativeTerrain != stackNativeTerrain)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return nativeTerrain;
|
||||
}
|
||||
|
||||
int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
|
||||
{
|
||||
if (toh3m)
|
||||
|
@ -131,6 +131,7 @@ public:
|
||||
const std::string &getBiography() const;
|
||||
bool needsLastStack()const override;
|
||||
ui32 getTileCost(const TerrainTile &dest, const TerrainTile &from, const TurnInfo * ti) const; //move cost - applying pathfinding skill, road and terrain modifiers. NOT includes diagonal move penalty, last move levelling
|
||||
int getNativeTerrain() const;
|
||||
ui32 getLowestCreatureSpeed() const;
|
||||
int3 getPosition(bool h3m = false) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
|
||||
si32 manaRegain() const; //how many points of mana can hero regain "naturally" in one day
|
||||
|
Loading…
Reference in New Issue
Block a user