浏览代码

Fixed movement through teleporters by AI

Ivan Savenko 2 年之前
父节点
当前提交
3ea807fb8d
共有 2 个文件被更改,包括 5 次插入5 次删除
  1. 1 1
      lib/mapObjects/MiscObjects.cpp
  2. 4 4
      server/CGameHandler.cpp

+ 1 - 1
lib/mapObjects/MiscObjects.cpp

@@ -372,7 +372,7 @@ ObjectInstanceID CGTeleport::getRandomExit(const CGHeroInstance * h) const
 
 
 bool CGTeleport::isTeleport(const CGObjectInstance * obj)
 bool CGTeleport::isTeleport(const CGObjectInstance * obj)
 {
 {
-	return ((dynamic_cast<const CGTeleport *>(obj)));
+	return dynamic_cast<const CGTeleport *>(obj) != nullptr;
 }
 }
 
 
 bool CGTeleport::isConnected(const CGTeleport * src, const CGTeleport * dst)
 bool CGTeleport::isConnected(const CGTeleport * src, const CGTeleport * dst)

+ 4 - 4
server/CGameHandler.cpp

@@ -1163,7 +1163,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
 	if(h->movementPointsRemaining() < cost && dst != h->pos && !teleporting)
 	if(h->movementPointsRemaining() < cost && dst != h->pos && !teleporting)
 		complainRet("Hero doesn't have any movement points left!");
 		complainRet("Hero doesn't have any movement points left!");
 
 
-	if (transit && !canFly && !(canWalkOnSea && t.terType->isWater()))
+	if (transit && !canFly && !(canWalkOnSea && t.terType->isWater()) && !CGTeleport::isTeleport(objectToVisit))
 		complainRet("Hero cannot transit over this tile!");
 		complainRet("Hero cannot transit over this tile!");
 
 
 	//several generic blocks of code
 	//several generic blocks of code
@@ -1195,7 +1195,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
 		tmh.result = result;
 		tmh.result = result;
 		sendAndApply(&tmh);
 		sendAndApply(&tmh);
 
 
-		if (visitDest == VISIT_DEST && t.topVisitableObj() && t.topVisitableObj()->id == h->id)
+		if (visitDest == VISIT_DEST && objectToVisit && objectToVisit->id == h->id)
 		{ // Hero should be always able to visit any object he staying on even if there guards around
 		{ // Hero should be always able to visit any object he staying on even if there guards around
 			visitObjectOnTile(t, h);
 			visitObjectOnTile(t, h);
 		}
 		}
@@ -1279,7 +1279,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
 		EVisitDest visitDest = VISIT_DEST;
 		EVisitDest visitDest = VISIT_DEST;
 		if (transit)
 		if (transit)
 		{
 		{
-			if (CGTeleport::isTeleport(t.topVisitableObj()))
+			if (CGTeleport::isTeleport(objectToVisit))
 				visitDest = DONT_VISIT_DEST;
 				visitDest = DONT_VISIT_DEST;
 
 
 			if (canFly || (canWalkOnSea && t.terType->isWater()))
 			if (canFly || (canWalkOnSea && t.terType->isWater()))
@@ -1292,7 +1292,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
 			return true;
 			return true;
 		
 		
 		if(h->boat && !h->boat->onboardAssaultAllowed)
 		if(h->boat && !h->boat->onboardAssaultAllowed)
-		   lookForGuards = IGNORE_GUARDS;
+			lookForGuards = IGNORE_GUARDS;
 
 
 		turnTimerHandler.setEndTurnAllowed(h->getOwner(), !standAtWater && !standAtObstacle);
 		turnTimerHandler.setEndTurnAllowed(h->getOwner(), !standAtWater && !standAtObstacle);
 		doMove(TryMoveHero::SUCCESS, lookForGuards, visitDest, LEAVING_TILE);
 		doMove(TryMoveHero::SUCCESS, lookForGuards, visitDest, LEAVING_TILE);