当前位置: 首页>>代码示例>>C++>>正文


C++ MMapManager::GetNearestValidPosition方法代码示例

本文整理汇总了C++中mmap::MMapManager::GetNearestValidPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ MMapManager::GetNearestValidPosition方法的具体用法?C++ MMapManager::GetNearestValidPosition怎么用?C++ MMapManager::GetNearestValidPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mmap::MMapManager的用法示例。


在下文中一共展示了MMapManager::GetNearestValidPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: urand

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);
}
开发者ID:Phatcat,项目名称:mangos,代码行数:80,代码来源:ConfusedMovementGenerator.cpp


注:本文中的mmap::MMapManager::GetNearestValidPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。