diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index 0145eb209..53a3280b1 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -688,6 +688,61 @@ const CGObjectInstance * CGameInfoCallback::getObjInstance( ObjectInstanceID oid return gs->map->objects[oid.num]; } +std::vector CGameInfoCallback::getTeleportChannelEntraces(TeleportChannelID id, ObjectInstanceID excludeId, PlayerColor Player) const +{ + std::vector ret; + auto channel = gs->map->teleportChannels[id]; + for(auto entrance : channel->entrances) + { + auto obj = getObj(entrance); + if(obj && (Player == PlayerColor::UNFLAGGABLE || isVisible(obj->pos, Player))) + ret.push_back(entrance); + } + + return ret; +} + +std::vector CGameInfoCallback::getTeleportChannelExits(TeleportChannelID id, ObjectInstanceID excludeId, PlayerColor Player) const +{ + std::vector ret; + auto channel = gs->map->teleportChannels[id]; + for(auto exit : channel->exits) + { + auto obj = getObj(exit); + if(obj && (Player == PlayerColor::UNFLAGGABLE || isVisible(obj->pos, Player))) + ret.push_back(exit); + } + + return ret; +} + +ETeleportChannelType::ETeleportChannelType CGameInfoCallback::getTeleportChannelType(TeleportChannelID id, PlayerColor Player) const +{ + std::vector entrances = getTeleportChannelEntraces(id, ObjectInstanceID(), Player); + std::vector exits = getTeleportChannelExits(id, ObjectInstanceID(), Player); + if((!entrances.size() || !exits.size()) + || (entrances.size() == 1 && entrances == exits)) + { + return ETeleportChannelType::IMPASSABLE; + } + + auto intersection = vstd::intersection(entrances, exits); + if(intersection.size() == entrances.size() && intersection.size() == exits.size()) + return ETeleportChannelType::BIDIRECTIONAL; + else if(!intersection.size()) + return ETeleportChannelType::UNIDIRECTIONAL; + else + return ETeleportChannelType::MIXED; +} + +bool CGameInfoCallback::isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor Player) const +{ + if(obj && obj->isEntrance() && ETeleportChannelType::IMPASSABLE != getTeleportChannelType(obj->channel, Player)) + return true; + else + return false; +} + void IGameEventRealizer::showInfoDialog( InfoWindow *iw ) { commitPackage(iw); diff --git a/lib/CGameInfoCallback.h b/lib/CGameInfoCallback.h index 1daf4fb50..17383d7b8 100644 --- a/lib/CGameInfoCallback.h +++ b/lib/CGameInfoCallback.h @@ -25,6 +25,7 @@ struct InfoAboutTown; struct UpgradeInfo; struct SThievesGuildInfo; class CGDwelling; +class CGTeleport; class CMapHeader; struct TeamState; struct QuestInfo; @@ -106,6 +107,12 @@ public: const TeamState *getTeam(TeamID teamID) const; const TeamState *getPlayerTeam(PlayerColor color) const; EBuildingState::EBuildingState canBuildStructure(const CGTownInstance *t, BuildingID ID) const;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements + + //teleport + std::vector getTeleportChannelEntraces(TeleportChannelID id, ObjectInstanceID excludeId = ObjectInstanceID(), PlayerColor Player = PlayerColor::UNFLAGGABLE) const; + std::vector getTeleportChannelExits(TeleportChannelID id, ObjectInstanceID excludeId = ObjectInstanceID(), PlayerColor Player = PlayerColor::UNFLAGGABLE) const; + ETeleportChannelType::ETeleportChannelType getTeleportChannelType(TeleportChannelID id, PlayerColor Player = PlayerColor::UNFLAGGABLE) const; + bool isTeleportEntrancePassable(const CGTeleport * obj, PlayerColor Player) const; }; class DLL_LINKAGE CPlayerSpecificInfoCallback : public CGameInfoCallback