本文整理汇总了C++中CNavArea类的典型用法代码示例。如果您正苦于以下问题:C++ CNavArea类的具体用法?C++ CNavArea怎么用?C++ CNavArea使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CNavArea类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetNavAreasAtBB
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
boost::python::list GetNavAreasAtBB( const Vector &mins, const Vector &maxs )
{
boost::python::list l;
CNavArea *area;
Extent extent;
Vector vAbsMins2, vAbsMaxs2;
// TODO: Use ForAllAreasOverlappingExtent?
FOR_EACH_VEC( TheNavAreas, it )
{
area = TheNavAreas[ it ];
area->GetExtent( &extent );
vAbsMins2 = extent.lo;
vAbsMaxs2 = extent.hi;
if( vAbsMins2[2] > vAbsMaxs2[2] )
{
float z = vAbsMaxs2[2];
vAbsMaxs2[2] = vAbsMins2[2];
vAbsMins2[2] = z;
}
else if( vAbsMins2[2] == vAbsMaxs2[2] )
{
vAbsMaxs2[2] += 1.0f;
}
// Does it intersects with our bounding box?
if( IsBoxIntersectingBox( mins, maxs,
vAbsMins2, vAbsMaxs2 ) )
{
l.append( area->GetID() );
}
}
示例2: func
/**
* Escape from the bomb.
*/
void EscapeFromBombState::OnUpdate( CCSBot *me )
{
const Vector *bombPos = me->GetGameState()->GetBombPosition();
// if we don't know where the bomb is, we shouldn't be in this state
if (bombPos == NULL)
{
me->Idle();
return;
}
// grab our knife to move quickly
me->EquipKnife();
// look around
me->UpdateLookAround();
if (me->UpdatePathMovement() != CCSBot::PROGRESSING)
{
// we have no path, or reached the end of one - create a new path far away from the bomb
FarAwayFromPositionFunctor func( *bombPos );
CNavArea *goalArea = FindMinimumCostArea( me->GetLastKnownArea(), func );
// if this fails, we'll try again next time
me->ComputePath( goalArea->GetCenter(), FASTEST_ROUTE );
}
}
示例3: BuildTrivialPath
/**
* Build trivial path when start and goal are in the same nav area
*/
bool CNavPath::BuildTrivialPath( const Vector *start, const Vector *goal )
{
m_segmentCount = 0;
CNavArea *startArea = TheNavAreaGrid.GetNearestNavArea( start );
if (startArea == NULL)
return false;
CNavArea *goalArea = TheNavAreaGrid.GetNearestNavArea( goal );
if (goalArea == NULL)
return false;
m_segmentCount = 2;
m_path[0].area = startArea;
m_path[0].pos.x = start->x;
m_path[0].pos.y = start->y;
m_path[0].pos.z = startArea->GetZ( start );
m_path[0].ladder = NULL;
m_path[0].how = NUM_TRAVERSE_TYPES;
m_path[1].area = goalArea;
m_path[1].pos.x = goal->x;
m_path[1].pos.y = goal->y;
m_path[1].pos.z = goalArea->GetZ( goal );
m_path[1].ladder = NULL;
m_path[1].how = NUM_TRAVERSE_TYPES;
return true;
}
示例4: GetActiveNavMesh
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int GetActiveNavMesh()
{
CNavArea *pArea = TheNavMesh->GetSelectedArea();
if( !pArea )
return -1;
return pArea->GetID();
}
示例5: GetNavAreaAt
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int GetNavAreaAt( const Vector &pos, float beneathlimit )
{
CNavArea *pArea = TheNavMesh->GetNavArea( pos, beneathlimit );
if( !pArea )
return -1;
return pArea->GetID();
}
示例6: LoadLocationFile
/* <4f169d> ../game_shared/bot/nav_file.cpp:811 */
void LoadLocationFile(const char *filename)
{
char locFilename[256];
Q_strcpy(locFilename, filename);
char *dot = Q_strchr(locFilename, '.');
if (dot)
{
Q_strcpy(dot, ".loc");
int locDataLength;
char *locDataFile = (char *)LOAD_FILE_FOR_ME(const_cast<char *>(locFilename), &locDataLength);
char *locData = locDataFile;
if (locData)
{
CONSOLE_ECHO("Loading legacy 'location file' '%s'\n", locFilename);
// read directory
locData = MP_COM_Parse(locData);
int dirSize = Q_atoi(MP_COM_GetToken());
if (dirSize)
{
std::vector<unsigned int> directory;
directory.reserve(dirSize);
for (int i = 0; i < dirSize; ++i)
{
locData = MP_COM_Parse(locData);
directory.push_back(TheBotPhrases->NameToID(MP_COM_GetToken()));
}
// read places for each nav area
unsigned int areaID, locDirIndex;
while (true)
{
locData = MP_COM_Parse(locData);
if (locData == NULL)
break;
areaID = Q_atoi(MP_COM_GetToken());
locData = MP_COM_Parse(locData);
locDirIndex = Q_atoi(MP_COM_GetToken());
CNavArea *area = TheNavAreaGrid.GetNavAreaByID(areaID);
unsigned int place = (locDirIndex > 0) ? directory[locDirIndex - 1] : UNDEFINED_PLACE;
if (area)
area->SetPlace(place);
}
}
FREE_FILE(locDataFile);
}
}
}
示例7: NavMeshGetPositionNearestNavArea
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Vector NavMeshGetPositionNearestNavArea( const Vector &pos, float beneathlimit, bool bCheckBlocked )
{
CNavArea *pArea;
//pArea = TheNavMesh->GetNearestNavArea(pos, false, 64.0f);
pArea = TheNavMesh->GetNavArea(pos, beneathlimit, bCheckBlocked);
if( pArea ) {
Vector vAreaPos(pos);
vAreaPos.z = pArea->GetZ(pos);
return vAreaPos;
}
return vec3_origin;
}
示例8: collector
//--------------------------------------------------------------------------------------------------------
void CFuncNavBlocker::UpdateBlocked()
{
NavAreaCollector collector( true );
Extent extent;
extent.Init( this );
TheNavMesh->ForAllAreasOverlappingExtent( collector, extent );
for ( int i=0; i<collector.m_area.Count(); ++i )
{
CNavArea *area = collector.m_area[i];
area->UpdateBlocked( true );
}
}
示例9: StayOnNavMesh
// If we are not on the navigation mesh (m_currentArea == nullptr),
// move towards last known area.
// Return false if off mesh.
bool CCSBot::StayOnNavMesh()
{
if (m_currentArea)
return true;
// move back onto the area map
// if we have no lastKnownArea, we probably started off
// of the nav mesh - find the closest nav area and use it
CNavArea *goalArea;
if (!m_currentArea && !m_lastKnownArea)
{
goalArea = TheNavAreaGrid.GetNearestNavArea(&pev->origin);
PrintIfWatched("Started off the nav mesh - moving to closest nav area...\n");
}
else
{
goalArea = m_lastKnownArea;
PrintIfWatched("Getting out of NULL area...\n");
}
if (goalArea)
{
Vector pos;
goalArea->GetClosestPointOnArea(&pev->origin, &pos);
// move point into area
Vector to = pos - pev->origin;
to.NormalizeInPlace();
// how far to "step into" an area - must be less than min area size
const float stepInDist = 5.0f;
pos = pos + (stepInDist * to);
MoveTowardsPosition(&pos);
}
// if we're stuck, try to get un-stuck
// do stuck movements last, so they override normal movement
if (m_isStuck)
{
Wiggle();
}
return false;
}
示例10: RandomNavAreaPositionWithin
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Vector RandomNavAreaPositionWithin( const Vector &mins, const Vector &maxs, float minimumarea, int maxtries )
{
if( maxtries < 0 )
maxtries = 1;
Vector random;
CNavArea *pArea = NULL;
Extent extent;
for( int i = 0; i < maxtries; i++ )
{
random.Init(
mins.x + ((float)rand() / RAND_MAX) * (maxs.x - mins.x),
mins.y + ((float)rand() / RAND_MAX) * (maxs.y - mins.y),
maxs.z
);
pArea = TheNavMesh->GetNearestNavArea( random, false, 10000.0f, false, false );
if( pArea )
{
pArea->GetExtent( &extent );
if( extent.Area() >= minimumarea )
break;
}
// Reset
pArea = NULL;
}
if( !pArea )
{
if( g_pynavmesh_debug.GetBool() )
DevMsg("RandomNavAreaPosition: No area found within Mins: %f %f %f, Maxs: %f %f %f, Random: %f %f %f\n",
mins.x, mins.y, mins.z, maxs.x, maxs.y, maxs.z, random.x, random.y, random.z);
return vec3_origin;
}
Vector vRandomPoint = pArea->GetRandomPoint();
vRandomPoint.z += 32.0f;
if( g_pynavmesh_debug.GetBool() )
DevMsg("RandomNavAreaPosition: Found position %f %f %f\n", vRandomPoint.x, vRandomPoint.y, vRandomPoint.z);
return vRandomPoint;
}
示例11: GetGlobalTeam
//-----------------------------------------------------------------------------------------------------
int CFuncNavBlocker::DrawDebugTextOverlays( void )
{
int offset = BaseClass::DrawDebugTextOverlays();
if (m_debugOverlays & OVERLAY_TEXT_BIT)
{
CFmtStr str;
// FIRST_GAME_TEAM skips TEAM_SPECTATOR and TEAM_UNASSIGNED, so we can print
// useful team names in a non-game-specific fashion.
for ( int i=FIRST_GAME_TEAM; i<FIRST_GAME_TEAM + MAX_NAV_TEAMS; ++i )
{
if ( IsBlockingNav( i ) )
{
CTeam *team = GetGlobalTeam( i );
if ( team )
{
EntityText( offset++, str.sprintf( "blocking team %s", team->GetName() ), 0 );
}
else
{
EntityText( offset++, str.sprintf( "blocking team %d", i ), 0 );
}
}
}
NavAreaCollector collector( true );
Extent extent;
extent.Init( this );
TheNavMesh->ForAllAreasOverlappingExtent( collector, extent );
for ( int i=0; i<collector.m_area.Count(); ++i )
{
CNavArea *area = collector.m_area[i];
Extent areaExtent;
area->GetExtent( &areaExtent );
debugoverlay->AddBoxOverlay( vec3_origin, areaExtent.lo, areaExtent.hi, vec3_angle, 0, 255, 0, 10, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
return offset;
}
示例12: ToBasePlayer
void CEventLog::FormatPlayer( CBaseEntity *ent, char *str, int len ) const
{
if ( !str || len <= 0 )
{
return;
}
CBasePlayer *player = ToBasePlayer( ent );
const char *playerName = "Unknown";
int userID = 0;
const char *networkIDString = "";
const char *teamName = "";
int areaID = 0;
if ( player )
{
playerName = player->GetPlayerName();
userID = player->GetUserID();
networkIDString = player->GetNetworkIDString();
CTeam *team = player->GetTeam();
if ( team )
{
teamName = team->GetName();
}
}
#ifdef USE_NAV_MESH
if ( ent && ent->MyCombatCharacterPointer() )
{
CNavArea *area = ent->MyCombatCharacterPointer()->GetLastKnownArea();
if ( area )
{
areaID = area->GetID();
}
}
#endif // USE_NAV_MESH
V_snprintf( str, len, "\"%s<%i><%s><%s><Area %d>\"", playerName, userID, networkIDString, teamName, areaID );
}
示例13: FOR_EACH_VEC
// tell the other areas we are going away
FOR_EACH_VEC( TheNavAreas, it )
{
CNavArea *area = TheNavAreas[ it ];
area->OnDestroyNotify( this );
}
示例14: LoadNavigationMap
/* <4f19c7> ../game_shared/bot/nav_file.cpp:947 */
NavErrorType LoadNavigationMap()
{
// since the navigation map is destroyed on map change,
// if it exists it has already been loaded for this map
if (!TheNavAreaList.empty())
return NAV_OK;
// nav filename is derived from map filename
char filename[256];
Q_sprintf(filename, "maps\\%s.nav", STRING(gpGlobals->mapname));
// free previous navigation map data
DestroyNavigationMap();
placeDirectory.Reset();
IMPL_CLASS(CNavArea, m_nextID) = 1;
SteamFile navFile(filename);
if (!navFile.IsValid())
return NAV_CANT_ACCESS_FILE;
// check magic number
bool result;
unsigned int magic;
result = navFile.Read(&magic, sizeof(unsigned int));
if (!result || magic != NAV_MAGIC_NUMBER)
{
CONSOLE_ECHO("ERROR: Invalid navigation file '%s'.\n", filename);
return NAV_INVALID_FILE;
}
// read file version number
unsigned int version;
result = navFile.Read(&version, sizeof(unsigned int));
if (!result || version > 5)
{
CONSOLE_ECHO("ERROR: Unknown navigation file version.\n");
return NAV_BAD_FILE_VERSION;
}
if (version >= 4)
{
// get size of source bsp file and verify that the bsp hasn't changed
unsigned int saveBspSize;
navFile.Read(&saveBspSize, sizeof(unsigned int));
// verify size
char *bspFilename = GetBspFilename(filename);
if (bspFilename == NULL)
return NAV_INVALID_FILE;
unsigned int bspSize = (unsigned int)GET_FILE_SIZE(bspFilename);
if (bspSize != saveBspSize)
{
// this nav file is out of date for this bsp file
char *msg = "*** WARNING ***\nThe AI navigation data is from a different version of this map.\nThe CPU players will likely not perform well.\n";
HintMessageToAllPlayers(msg);
CONSOLE_ECHO("\n-----------------\n");
CONSOLE_ECHO(msg);
CONSOLE_ECHO("-----------------\n\n");
}
}
// load Place directory
if (version >= 5)
{
placeDirectory.Load(&navFile);
}
// get number of areas
unsigned int count;
result = navFile.Read(&count, sizeof(unsigned int));
Extent extent;
extent.lo.x = 9999999999.9f;
extent.lo.y = 9999999999.9f;
extent.hi.x = -9999999999.9f;
extent.hi.y = -9999999999.9f;
// load the areas and compute total extent
for (unsigned int i = 0; i < count; ++i)
{
CNavArea *area = new CNavArea;
area->Load(&navFile, version);
TheNavAreaList.push_back(area);
const Extent *areaExtent = area->GetExtent();
// check validity of nav area
if (areaExtent->lo.x >= areaExtent->hi.x || areaExtent->lo.y >= areaExtent->hi.y)
CONSOLE_ECHO("WARNING: Degenerate Navigation Area #%d at ( %g, %g, %g )\n",
area->GetID(), area->m_center.x, area->m_center.y, area->m_center.z);
if (areaExtent->lo.x < extent.lo.x)
extent.lo.x = areaExtent->lo.x;
if (areaExtent->lo.y < extent.lo.y)
//.........这里部分代码省略.........
示例15: SaveNavigationMap
/* <4f3e47> ../game_shared/bot/nav_file.cpp:702 */
bool SaveNavigationMap(const char *filename)
{
if (filename == NULL)
return false;
// Store the NAV file
COM_FixSlashes(const_cast<char *>(filename));
#ifdef WIN32
int fd = _open(filename, _O_BINARY | _O_CREAT | _O_WRONLY, _S_IREAD | _S_IWRITE);
#else
int fd = creat(filename, S_IRUSR | S_IWUSR | S_IRGRP);
#endif // WIN32
if (fd < 0)
return false;
// store "magic number" to help identify this kind of file
unsigned int magic = NAV_MAGIC_NUMBER;
Q_write(fd, &magic, sizeof(unsigned int));
// store version number of file
// 1 = hiding spots as plain vector array
// 2 = hiding spots as HidingSpot objects
// 3 = Encounter spots use HidingSpot ID's instead of storing vector again
// 4 = Includes size of source bsp file to verify nav data correlation
// ---- Beta Release at V4 -----
// 5 = Added Place info
unsigned int version = 5;
Q_write(fd, &version, sizeof(unsigned int));
// get size of source bsp file and store it in the nav file
// so we can test if the bsp changed since the nav file was made
char *bspFilename = GetBspFilename(filename);
if (bspFilename == NULL)
return false;
unsigned int bspSize = (unsigned int)GET_FILE_SIZE(bspFilename);
CONSOLE_ECHO("Size of bsp file '%s' is %u bytes.\n", bspFilename, bspSize);
Q_write(fd, &bspSize, sizeof(unsigned int));
// Build a directory of the Places in this map
placeDirectory.Reset();
NavAreaList::iterator it;
for (it = TheNavAreaList.begin(); it != TheNavAreaList.end(); ++it)
{
CNavArea *area = *it;
Place place = area->GetPlace();
if (place)
{
placeDirectory.AddPlace(place);
}
}
placeDirectory.Save(fd);
// Store navigation areas
// store number of areas
unsigned int count = TheNavAreaList.size();
Q_write(fd, &count, sizeof(unsigned int));
// store each area
for (it = TheNavAreaList.begin(); it != TheNavAreaList.end(); ++it)
{
CNavArea *area = *it;
area->Save(fd, version);
}
Q_close(fd);
#ifdef _WIN32
// output a simple Wavefront file to visualize the generated areas in 3DSMax
FILE *fp = fopen("c:\\tmp\\nav.obj", "w");
if (fp)
{
for (NavAreaList::iterator iter = TheNavAreaList.begin(); iter != TheNavAreaList.end(); ++iter)
{
(*iter)->Save(fp);
}
fclose(fp);
}
#endif // _WIN32
return true;
}