コード例 #1
0
////////////////// PathInfo //////////////////
PathInfo::PathInfo(const Unit* owner, const float destX, const float destY, const float destZ, bool useStraightPath) :
    m_polyLength(0), m_type(PATHFIND_BLANK), m_useStraightPath(useStraightPath),
    m_sourceUnit(owner), m_navMesh(NULL), m_navMeshQuery(NULL)
{
    PathNode endPoint(destX, destY, destZ);
    setEndPosition(endPoint);

    float x,y,z;
    m_sourceUnit->GetPosition(x, y, z);
    PathNode startPoint(x, y, z);
    setStartPosition(startPoint);

    DEBUG_FILTER_LOG(LOG_FILTER_PATHFINDING, "++ PathInfo::PathInfo for %u \n", m_sourceUnit->GetGUID());

    uint32 mapId = m_sourceUnit->GetMapId();
    if (MMAP::MMapFactory::IsPathfindingEnabled(mapId))
    {
        MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
        m_navMesh = mmap->GetNavMesh(mapId);
        m_navMeshQuery = mmap->GetNavMeshQuery(mapId, m_sourceUnit->GetInstanceId());
    }

    createFilter();

    if (m_navMesh && m_navMeshQuery && !m_sourceUnit->hasUnitState(UNIT_STAT_IGNORE_PATHFINDING))
    {
        BuildPolyPath(startPoint, endPoint);
    }
    else
    {
        BuildShortcut();
        m_type = PathType(PATHFIND_NORMAL | PATHFIND_NOT_USING_PATH);
    }
}
コード例 #2
0
ファイル: PathFinder.cpp プロジェクト: nerzhul/MangosFX
////////////////// PathInfo //////////////////
PathInfo::PathInfo(const Unit* owner, const float destX, const float destY, const float destZ, bool useStraightPath) :
    m_pathPolyRefs(NULL), m_polyLength(0), m_type(PATHFIND_BLANK), m_useStraightPath(useStraightPath),
    m_sourceUnit(owner), m_navMesh(NULL), m_navMeshQuery(NULL)
{
    PathNode endPoint(destX, destY, destZ);
    setEndPosition(endPoint);

    float x,y,z;
    m_sourceUnit->GetPosition(x, y, z);
    PathNode startPoint(x, y, m_sourceUnit->GetMap()->GetHeight(x,y,z,100.0f));
    setStartPosition(startPoint);

    PATH_DEBUG("++ PathInfo::PathInfo for %u \n", m_sourceUnit->GetGUID());

    uint32 mapId = m_sourceUnit->GetMapId();
    MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
    m_navMesh = mmap->GetNavMesh(mapId);
    m_navMeshQuery = mmap->GetNavMeshQuery(mapId);

    if (m_navMesh && m_navMeshQuery)
    {
        BuildPolyPath(startPoint, endPoint);
    }
    else
    {
        BuildShortcut();
        m_type = PathType(PATHFIND_NORMAL | PATHFIND_NOT_USING_PATH);
    }
}
コード例 #3
0
ファイル: cs_mmaps.cpp プロジェクト: 090809/TrinityCore
    static bool HandleMmapStatsCommand(ChatHandler* handler, char const* /*args*/)
    {
        Player* player = handler->GetSession()->GetPlayer();
        uint32 terrainMapId = PhasingHandler::GetTerrainMapId(player->GetPhaseShift(), player->GetMap(), player->GetPositionX(), player->GetPositionY());
        handler->PSendSysMessage("mmap stats:");
        handler->PSendSysMessage("  global mmap pathfinding is %sabled", DisableMgr::IsPathfindingEnabled(player->GetMapId()) ? "en" : "dis");

        MMAP::MMapManager* manager = MMAP::MMapFactory::createOrGetMMapManager();
        handler->PSendSysMessage(" %u maps loaded with %u tiles overall", manager->getLoadedMapsCount(), manager->getLoadedTilesCount());

        dtNavMesh const* navmesh = manager->GetNavMesh(terrainMapId);
        if (!navmesh)
        {
            handler->PSendSysMessage("NavMesh not loaded for current map.");
            return true;
        }

        uint32 tileCount = 0;
        uint32 nodeCount = 0;
        uint32 polyCount = 0;
        uint32 vertCount = 0;
        uint32 triCount = 0;
        uint32 triVertCount = 0;
        uint32 dataSize = 0;
        for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
        {
            dtMeshTile const* tile = navmesh->getTile(i);
            if (!tile || !tile->header)
                continue;

            tileCount++;
            nodeCount += tile->header->bvNodeCount;
            polyCount += tile->header->polyCount;
            vertCount += tile->header->vertCount;
            triCount += tile->header->detailTriCount;
            triVertCount += tile->header->detailVertCount;
            dataSize += tile->dataSize;
        }

        handler->PSendSysMessage("Navmesh stats:");
        handler->PSendSysMessage(" %u tiles loaded", tileCount);
        handler->PSendSysMessage(" %u BVTree nodes", nodeCount);
        handler->PSendSysMessage(" %u polygons (%u vertices)", polyCount, vertCount);
        handler->PSendSysMessage(" %u triangles (%u vertices)", triCount, triVertCount);
        handler->PSendSysMessage(" %.2f MB of data (not including pointers)", ((float)dataSize / sizeof(unsigned char)) / 1048576);

        return true;
    }
コード例 #4
0
ファイル: PathFinder.cpp プロジェクト: Darkelmo/MythCore
////////////////// PathFinder //////////////////
PathFinder::PathFinder(const Unit* owner) :
    m_polyLength(0), m_type(PATHFIND_BLANK),
    m_useStraightPath(false), m_forceDestination(false), m_pointPathLimit(MAX_POINT_PATH_LENGTH),
    m_sourceUnit(owner), m_navMesh(NULL), m_navMeshQuery(NULL)
{
    sLog->outDebug(LOG_FILTER_PATHFINDING, "++ PathFinder::PathInfo for %u \n", m_sourceUnit->GetGUIDLow());

    uint32 mapId = m_sourceUnit->GetMapId();
    if(MMAP::MMapFactory::IsPathfindingEnabled(mapId))
    {
        MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
        m_navMesh = mmap->GetNavMesh(mapId);
        m_navMeshQuery = mmap->GetNavMeshQuery(mapId, m_sourceUnit->GetInstanceId());
    }

    createFilter();
}
コード例 #5
0
        static bool HandleMmapStatsCommand(ChatHandler* handler, const char* /*args*/)
        {
            handler->PSendSysMessage("mmap stats:");
            handler->PSendSysMessage("global mmap pathfinding is %sabled", sWorld->getBoolConfig(CONFIG_BOOL_MMAP_ENABLED) ? "en" : "dis");

            MMAP::MMapManager *manager = MMAP::MMapFactory::createOrGetMMapManager();
            handler->PSendSysMessage(" %u maps loaded with %u tiles overall", manager->getLoadedMapsCount(), manager->getLoadedTilesCount());

            const dtNavMesh* navmesh = manager->GetNavMesh(handler->GetSession()->GetPlayer()->GetMapId());
            if (!navmesh)
            {
                handler->PSendSysMessage("NavMesh not loaded for current map.");
                return true;
            }

            uint32 tileCount = 0;
            uint32 nodeCount = 0;
            uint32 polyCount = 0;
            uint32 vertCount = 0;
            uint32 triCount = 0;
            uint32 triVertCount = 0;
            uint32 dataSize = 0;
            for (int32 i = 0; i < navmesh->getMaxTiles(); ++i)
            {
                const dtMeshTile* tile = navmesh->getTile(i);
                if (!tile || !tile->header)
                    continue;

                tileCount ++;
                nodeCount += tile->header->bvNodeCount;
                polyCount += tile->header->polyCount;
                vertCount += tile->header->vertCount;
                triCount += tile->header->detailTriCount;
                triVertCount += tile->header->detailVertCount;
                dataSize += tile->dataSize;
            }

            handler->PSendSysMessage(" Navmesh stats on current map:");
            handler->PSendSysMessage(" %u tiles loaded", tileCount);
            handler->PSendSysMessage(" %u BVTree nodes", nodeCount);
            handler->PSendSysMessage(" %u polygons (%u vertices)", polyCount, vertCount);
            handler->PSendSysMessage(" %u triangles (%u vertices)", triCount, triVertCount);
            handler->PSendSysMessage(" %.2f MB of data (not including pointers)", ((float)dataSize / sizeof(unsigned char)) / 1048576);

            return true;
        }
コード例 #6
0
ファイル: PathGenerator.cpp プロジェクト: Remix99/Arena_TC
////////////////// PathGenerator //////////////////
PathGenerator::PathGenerator(const Unit* owner) :
    _polyLength(0), _type(PATHFIND_BLANK),
    _useStraightPath(false), _forceDestination(false), _pointPathLimit(MAX_POINT_PATH_LENGTH),
    _sourceUnit(owner), _navMesh(NULL), _navMeshQuery(NULL), _endPosition(Vector3::zero())
{
    sLog->outDebug(LOG_FILTER_MAPS, "++ PathGenerator::PathGenerator for %u \n", _sourceUnit->GetGUIDLow());

    uint32 mapId = _sourceUnit->GetMapId();
    if (MMAP::MMapFactory::IsPathfindingEnabled(mapId))
    {
        MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
        _navMesh = mmap->GetNavMesh(mapId);
        _navMeshQuery = mmap->GetNavMeshQuery(mapId, _sourceUnit->GetInstanceId());
    }

    CreateFilter();
}
コード例 #7
0
ファイル: PathGenerator.cpp プロジェクト: Adiss/wowserver
////////////////// PathGenerator //////////////////
PathGenerator::PathGenerator(const Unit* owner) :
    _polyLength(0), _type(PATHFIND_BLANK), _useStraightPath(false),
    _forceDestination(false), _pointPathLimit(MAX_POINT_PATH_LENGTH), _straightLine(false),
    _endPosition(G3D::Vector3::zero()), _sourceUnit(owner), _navMesh(NULL),
    _navMeshQuery(NULL)
{
    memset(_pathPolyRefs, 0, sizeof(_pathPolyRefs));

    TC_LOG_DEBUG("maps", "++ PathGenerator::PathGenerator for %u \n", _sourceUnit->GetGUIDLow());

    uint32 mapId = _sourceUnit->GetMapId();
    if (MMAP::MMapFactory::IsPathfindingEnabled(mapId))
    {
        MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
        _navMesh = mmap->GetNavMesh(mapId);
        _navMeshQuery = mmap->GetNavMeshQuery(mapId, _sourceUnit->GetInstanceId());
    }

    CreateFilter();
}
コード例 #8
0
ファイル: PathFinder.cpp プロジェクト: Tr1n1ty1/L4G_Core
////////////////// PathFinder //////////////////
PathFinder::PathFinder(const Unit* owner) :
m_polyLength(0), m_type(PATHFIND_BLANK),
    m_useStraightPath(false), m_forceDestination(false), m_pointPathLimit(MAX_POINT_PATH_LENGTH),
    m_sourceUnit(owner), m_navMesh(NULL), m_navMeshQuery(NULL)
{
    //DEBUG_FILTER_LOG(LOG_FILTER_PATHFINDING, "++ PathFinder::PathInfo for %u \n", m_sourceUnit->GetGUIDLow());

    if (m_sourceUnit->GetTypeId() == TYPEID_UNIT && m_sourceUnit->ToCreature()->isPet() && (!m_sourceUnit->getVictim() && m_sourceUnit->isInCombat()))
    {
        createFilter();
        return;
    }	

    if (m_sourceUnit->GetTerrain() && m_sourceUnit->GetTerrain()->IsPathFindingEnabled(owner))
    {
        uint32 mapId = m_sourceUnit->GetMapId();
        MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
        m_navMesh = mmap->GetNavMesh(mapId);
        m_navMeshQuery = mmap->GetNavMeshQuery(mapId, m_sourceUnit->GetInstanceId());
    }

    createFilter();
}
コード例 #9
0
void
ConfusedMovementGenerator<T>::Initialize(T &unit)
{
    const float wander_distance=11;
    float x,y,z;
    unit.GetPosition(x,y,z);
    //Get the nearest point
    i_nextMove = urand(1,MAX_CONF_WAYPOINTS);
    i_nextMoveTime.Reset(1);

    bool is_water_ok, is_land_ok;
    _InitSpecific(unit, is_water_ok, is_land_ok);

    uint32 mapId = unit.GetMapId();
    if (MMAP::MMapFactory::IsPathfindingEnabled(mapId))
    {
        MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();

        float ox=x;
        float oy=y;
        float oz=z;

        dtPolyRef originPoly;
        mmap->GetNearestValidPosition(&unit,3,3,5,ox,oy,oz,&originPoly);

        i_waypoints[0][0] = ox;
        i_waypoints[0][1] = oy;
        i_waypoints[0][2] = oz;

        for (int i = 1; i < MAX_CONF_WAYPOINTS+1;i++)
        {
            const float wanderX=wander_distance*rand_norm_f() - wander_distance/2;
            const float wanderY=wander_distance*rand_norm_f() - wander_distance/2;
            float toX = ox + wanderX;
            float toY = oy + wanderY;
            float toZ = oz;

            if (mmap->DrawRay(&unit,originPoly,ox,oy,oz,toX,toY,toZ))
            {
                i_waypoints[i][0] = toX;
                i_waypoints[i][1] = toY;
                i_waypoints[i][2] = toZ;
            } else
            {
                i_waypoints[i][0] = ox;
                i_waypoints[i][1] = oy;
                i_waypoints[i][2] = oz;
            }
        }
    } else
    {
        TerrainInfo const* map = unit.GetTerrain();
        for(unsigned int idx=0; idx < MAX_CONF_WAYPOINTS+1; ++idx)
        {
            const float wanderX=wander_distance*rand_norm_f() - wander_distance/2;
            const float wanderY=wander_distance*rand_norm_f() - wander_distance/2;

            i_waypoints[idx][0] = x + wanderX;
            i_waypoints[idx][1] = y + wanderY;

            // prevent invalid coordinates generation
            MaNGOS::NormalizeMapCoord(i_waypoints[idx][0]);
            MaNGOS::NormalizeMapCoord(i_waypoints[idx][1]);

            bool is_water = map->IsInWater(i_waypoints[idx][0],i_waypoints[idx][1],z);
            // if generated wrong path just ignore
            if ((is_water && !is_water_ok) || (!is_water && !is_land_ok))
            {
                i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx-1][0] : x;
                i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx-1][1] : y;
            }

            unit.UpdateAllowedPositionZ(i_waypoints[idx][0],i_waypoints[idx][1],z);
            i_waypoints[idx][2] =  z;
        }
    }

    unit.StopMoving();
    unit.addUnitState(UNIT_STAT_CONFUSED|UNIT_STAT_CONFUSED_MOVE);
}