diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index d82457a64..1726794b6 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -1106,22 +1106,19 @@ CBonusSystemNode & CGHeroInstance::whereShouldBeAttached(CGameState * gs) int CGHeroInstance::movementPointsAfterEmbark(int MPsBefore, int basicCost, bool disembark, const TurnInfo * ti) const { - int ret = 0; //take all MPs by default - bool localTi = false; + std::unique_ptr turnInfoLocal; if(!ti) { - localTi = true; - ti = new TurnInfo(this); + turnInfoLocal = std::make_unique(this); + ti = turnInfoLocal.get(); } + if(!ti->hasBonusOfType(Bonus::FREE_SHIP_BOARDING)) + return 0; // take all MPs by default + int mp1 = ti->getMaxMovePoints(disembark ? EPathfindingLayer::LAND : EPathfindingLayer::SAIL); int mp2 = ti->getMaxMovePoints(disembark ? EPathfindingLayer::SAIL : EPathfindingLayer::LAND); - if(ti->hasBonusOfType(Bonus::FREE_SHIP_BOARDING)) - ret = static_cast((MPsBefore - basicCost) * static_cast(mp1) / mp2); - - if(localTi) - delete ti; - + int ret = static_cast((MPsBefore - basicCost) * static_cast(mp1) / mp2); return ret; }