Browse Source

removed operator bool() from HeroPtr so we can consistently use isVerified() like in most of the other places

Mircea TheHonestCTO 3 months ago
parent
commit
16cdee82fd

+ 4 - 4
AI/Nullkiller2/AIGateway.cpp

@@ -1100,7 +1100,7 @@ bool AIGateway::moveHeroToTile(const int3 dst, const HeroPtr & heroPtr)
 	auto afterMovementCheck = [&]() -> void
 	{
 		waitTillFree(); //movement may cause battle or blocking dialog
-		if(!heroPtr)
+		if(!heroPtr.isVerified())
 		{
 			lostHero(heroPtr);
 			teleportChannelProbingList.clear();
@@ -1282,10 +1282,10 @@ bool AIGateway::moveHeroToTile(const int3 dst, const HeroPtr & heroPtr)
 		{
 			// when we take resource we do not reach its position. We even might not move
 			// also guarded town is not get visited automatically after capturing
-			ret = heroPtr && i == 0;
+			ret = heroPtr.isVerified() && i == 0;
 		}
 	}
-	if(heroPtr)
+	if(heroPtr.isVerified())
 	{
 		if(auto visitedObject = vstd::frontOrNull(cc->getVisitableObjs(heroPtr->visitablePos()))) //we stand on something interesting
 		{
@@ -1296,7 +1296,7 @@ bool AIGateway::moveHeroToTile(const int3 dst, const HeroPtr & heroPtr)
 			}
 		}
 	}
-	if(heroPtr) //we could have lost hero after last move
+	if(heroPtr.isVerified()) //we could have lost hero after last move
 	{
 		ret = ret || (dst == heroPtr->visitablePos());
 

+ 0 - 5
AI/Nullkiller2/AIUtility.h

@@ -84,11 +84,6 @@ private:
 public:
 	explicit HeroPtr(const CGHeroInstance * input, std::shared_ptr<CPlayerSpecificInfoCallback> cpsic);
 
-	explicit operator bool() const
-	{
-		return isVerified();
-	}
-
 	bool operator<(const HeroPtr & rhs) const;
 	const CGHeroInstance * operator->() const;
 	const CGHeroInstance * operator*() const; //not that consistent with -> but all interfaces use CGHeroInstance*, so it's convenient

+ 2 - 2
AI/Nullkiller2/Behaviors/DefenceBehavior.cpp

@@ -164,7 +164,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
 	{
 		return;
 	}
-	if(!threatNode.fastestDanger.heroPtr)
+	if(!threatNode.fastestDanger.heroPtr.isVerified())
 	{
 #if NK2AI_TRACE_LEVEL >= 1
 		logAi->trace("No threat found for town %s", town->getNameTranslated());
@@ -192,7 +192,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta
 			town->getNameTranslated(),
 			threat.danger,
 			std::to_string(threat.turn),
-			threat.heroPtr ? threat.heroPtr->getNameTranslated() : std::string("<no hero>"));
+			threat.heroPtr.isVerified() ? threat.heroPtr->getNameTranslated() : std::string("<no hero>"));
 #endif
 		handleCounterAttack(town, threat, threatNode.maximumDanger, aiNk, tasks);