Sfoglia il codice sorgente

Slight refactoring of CGHeroInstance::movementPointsAfterEmbark()

Andrey Filipenkov 2 anni fa
parent
commit
a0cd69e944
1 ha cambiato i file con 7 aggiunte e 10 eliminazioni
  1. 7 10
      lib/mapObjects/CGHeroInstance.cpp

+ 7 - 10
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<TurnInfo> turnInfoLocal;
 	if(!ti)
 	{
-		localTi = true;
-		ti = new TurnInfo(this);
+		turnInfoLocal = std::make_unique<TurnInfo>(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<int>((MPsBefore - basicCost) * static_cast<double>(mp1) / mp2);
-
-	if(localTi)
-		delete ti;
-
+	int ret = static_cast<int>((MPsBefore - basicCost) * static_cast<double>(mp1) / mp2);
 	return ret;
 }