Explorar o código

Fix cursor & add way to access danger info for HotA-like DD cursor

Dydzio hai 1 ano
pai
achega
3f94d316cb

+ 12 - 0
client/adventureMap/AdventureMapInterface.cpp

@@ -650,7 +650,19 @@ void AdventureMapInterface::onTileHovered(const int3 &targetPosition)
 			return;
 		case SpellID::DIMENSION_DOOR:
 			if(isValidAdventureSpellTarget(targetPosition, objAtTile, SpellID::DIMENSION_DOOR))
+			{
+				if(VLC->settings()->getBoolean(EGameSettings::DIMENSION_DOOR_TRIGGERS_GUARDS))
+				{
+					auto isGuarded = LOCPLINT->cb->isTileGuardedAfterDimensionDoorUse(targetPosition, LOCPLINT->localState->getCurrentHero());
+					if(isGuarded)
+					{
+						CCS->curh->set(Cursor::Map::T1_ATTACK);
+						return;
+					}
+				}
+
 				CCS->curh->set(Cursor::Map::TELEPORT);
+			}
 			else
 				CCS->curh->set(Cursor::Map::POINTER);
 			return;

+ 18 - 0
lib/CGameInfoCallback.cpp

@@ -287,6 +287,24 @@ std::vector<const CGObjectInstance*> CGameInfoCallback::getGuardingCreatures (in
 	return ret;
 }
 
+bool CGameInfoCallback::isTileGuardedAfterDimensionDoorUse(int3 tile, const CGHeroInstance * castingHero) const
+{
+	//for known tiles this is just potential convenience info, for tiles behind fog of war this info matches HotA but not H3 so make it accessible only with proper setting on
+	bool canAccessInfo = false;
+
+	if(isVisible(tile))
+		canAccessInfo = true;
+	else if(VLC->settings()->getBoolean(EGameSettings::DIMENSION_DOOR_TRIGGERS_GUARDS) //TODO: check if available casts > 0
+		&& isInScreenRange(castingHero->getSightCenter(), tile)
+		&& castingHero->canCastThisSpell(static_cast<SpellID>(SpellID::DIMENSION_DOOR).toSpell()))
+		canAccessInfo = true;
+
+	if(canAccessInfo)
+		return !gs->guardingCreatures(tile).empty();
+
+	return false;
+}
+
 bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero & dest, const CGObjectInstance * selectedObject) const
 {
 	const auto * h = dynamic_cast<const CGHeroInstance *>(hero);

+ 1 - 0
lib/CGameInfoCallback.h

@@ -193,6 +193,7 @@ public:
 	//map
 	virtual int3 guardingCreaturePosition (int3 pos) const;
 	virtual std::vector<const CGObjectInstance*> getGuardingCreatures (int3 pos) const;
+	virtual bool isTileGuardedAfterDimensionDoorUse(int3 tile, const CGHeroInstance * castingHero) const;
 	virtual const CMapHeader * getMapHeader()const;
 	virtual int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
 	virtual const TerrainTile * getTile(int3 tile, bool verbose = true) const;

+ 2 - 2
server/CGameHandler.cpp

@@ -1196,7 +1196,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
 		sendAndApply(&tmh);
 
 		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 is staying on even if there are guards around
 			visitObjectOnTile(t, h);
 		}
 		else if (lookForGuards == CHECK_FOR_GUARDS && isInTheMap(guardPos))
@@ -1351,7 +1351,7 @@ void CGameHandler::setOwner(const CGObjectInstance * obj, const PlayerColor owne
 
 		if (oldOwner.isValidPlayer()) //old owner is real player
 		{
-			if (getPlayerState(oldOwner)->towns.empty() && getPlayerState(oldOwner)->status != EPlayerStatus::LOSER) //previous player lost last last town
+			if (getPlayerState(oldOwner)->towns.empty() && getPlayerState(oldOwner)->status != EPlayerStatus::LOSER) //previous player lost last town
 			{
 				InfoWindow iw;
 				iw.player = oldOwner;