diff --git a/extension/bot/interfaces/movement.cpp b/extension/bot/interfaces/movement.cpp index 0a8ec25..fe3d644 100644 --- a/extension/bot/interfaces/movement.cpp +++ b/extension/bot/interfaces/movement.cpp @@ -329,7 +329,7 @@ void IMovement::ClimbLadder(const CNavLadder* ladder, CNavArea* dismount) bot->DebugPrintToConsole(BOTDEBUG_MOVEMENT, 200, 0, 200, "%s CLIMBING LADDER! \n", bot->GetDebugIdentifier()); m_ladderExit->DrawFilled(255, 0, 255, 255, 5.0f, true); - NDebugOverlay::Text(m_ladderExit->GetCenter() + Vector(0.0f, 0.0f, StepHeight), "DISMOUNT AREA!", false, 5.0f); + NDebugOverlay::Text(m_ladderExit->GetCenter() + Vector(0.0f, 0.0f, navgenparams->step_height), "DISMOUNT AREA!", false, 5.0f); } } @@ -346,7 +346,7 @@ void IMovement::DescendLadder(const CNavLadder* ladder, CNavArea* dismount) bot->DebugPrintToConsole(BOTDEBUG_MOVEMENT, 200, 0, 200, "%s DESCENDING LADDER! \n", bot->GetDebugIdentifier()); m_ladderExit->DrawFilled(255, 0, 255, 255, 5.0f, true); - NDebugOverlay::Text(m_ladderExit->GetCenter() + Vector(0.0f, 0.0f, StepHeight), "DISMOUNT AREA!", false, 5.0f); + NDebugOverlay::Text(m_ladderExit->GetCenter() + Vector(0.0f, 0.0f, navgenparams->step_height), "DISMOUNT AREA!", false, 5.0f); } } @@ -952,7 +952,7 @@ IMovement::LadderState IMovement::ApproachUpLadder() { // move to the ladder connection point (this is on the ladder) MoveTowards(m_ladderMoveGoal); - FaceTowards(m_ladderMoveGoal + Vector(0.0f, 0.0f, HumanEyeHeight), true); + FaceTowards(m_ladderMoveGoal + Vector(0.0f, 0.0f, navgenparams->human_eye_height), true); if (GetBot()->GetRangeTo(connection->GetConnectionPoint()) < CBaseExtPlayer::PLAYER_USE_RADIUS) { @@ -1284,7 +1284,7 @@ void IMovement::OnLadderStateChanged(LadderState oldState, LadderState newState) case IMovement::USING_LADDER_UP: { // calculate Z goal - m_ladderGoalZ = m_ladder->GetConnectionToArea(m_ladderExit)->GetConnectionPoint().z - (GetStepHeight() / 4.0f); + m_ladderGoalZ = m_ladder->GetConnectionToArea(m_ladderExit)->GetConnectionPoint().z - (GetStepHeight() * 0.8f); float time = m_ladder->m_length / LADDER_TIME_DIVIDER; m_ladderTimer.Start(time); return; @@ -1300,7 +1300,7 @@ void IMovement::OnLadderStateChanged(LadderState oldState, LadderState newState) case IMovement::USING_LADDER_DOWN: { // calculate Z goal - m_ladderGoalZ = m_ladder->GetConnectionToArea(m_ladderExit)->GetConnectionPoint().z + (GetStepHeight() / 4.0f); + m_ladderGoalZ = m_ladder->GetConnectionToArea(m_ladderExit)->GetConnectionPoint().z + (GetStepHeight() * 0.8f); Vector lookAt = m_ladder->m_top; lookAt.z = m_ladderGoalZ; GetBot()->GetControlInterface()->SnapAimAt(lookAt, IPlayerController::LOOK_MOVEMENT); diff --git a/extension/bot/interfaces/path/meshnavigator.cpp b/extension/bot/interfaces/path/meshnavigator.cpp index 5532941..f729662 100644 --- a/extension/bot/interfaces/path/meshnavigator.cpp +++ b/extension/bot/interfaces/path/meshnavigator.cpp @@ -103,6 +103,8 @@ void CMeshNavigator::Update(CBaseBot* bot) return; // goal reached } + CrouchIfNeeded(bot); + Vector origin = bot->GetAbsOrigin(); Vector forward = m_goal->goal - origin; auto input = bot->GetControlInterface(); @@ -1215,6 +1217,16 @@ edict_t* CMeshNavigator::FindBlocker(CBaseBot* bot) return nullptr; } +void CMeshNavigator::CrouchIfNeeded(CBaseBot* bot) +{ + constexpr auto GOAL_CROUCH_RANGE = 50.0f * 50.0f; + + if (m_goal->area->HasAttributes(static_cast(NavAttributeType::NAV_MESH_CROUCH)) || bot->GetRangeToSqr(m_goal->goal) <= GOAL_CROUCH_RANGE) + { + bot->GetControlInterface()->PressCrouchButton(0.1f); + } +} + bool CMeshNavigator::LadderUpdate(CBaseBot* bot) { auto input = bot->GetControlInterface(); diff --git a/extension/bot/interfaces/path/meshnavigator.h b/extension/bot/interfaces/path/meshnavigator.h index 650e9fe..0965d1f 100644 --- a/extension/bot/interfaces/path/meshnavigator.h +++ b/extension/bot/interfaces/path/meshnavigator.h @@ -35,6 +35,7 @@ class CMeshNavigator : public CPath virtual bool JumpOverGaps(CBaseBot* bot, const CBasePathSegment* segment, const Vector& forward, const Vector& right, const float goalRange); virtual Vector Avoid(CBaseBot* bot, const Vector& goalPos, const Vector& forward, const Vector& left); virtual edict_t* FindBlocker(CBaseBot* bot); + virtual void CrouchIfNeeded(CBaseBot* bot); private: CBaseBot* m_me; // bot that is using this navigator diff --git a/extension/concommands_debug.cpp b/extension/concommands_debug.cpp index 4bcfc14..4ebee96 100644 --- a/extension/concommands_debug.cpp +++ b/extension/concommands_debug.cpp @@ -720,7 +720,7 @@ CON_COMMAND_F(sm_navbot_debug_find_ledge, "finds the ledge", FCVAR_CHEAT) trace_t tr; Vector pos1 = start + (forward * (stepSize * static_cast(it))); Vector pos2 = pos1; - pos2.z -= StepHeight; + pos2.z -= navgenparams->step_height; trace::hull(pos1, pos2, mins, maxs, MASK_PLAYERSOLID, &filter, tr); if (trace::pointoutisdeworld(pos1)) diff --git a/extension/mods/tf2/nav/tfnavmesh.cpp b/extension/mods/tf2/nav/tfnavmesh.cpp index 4f87639..eb0bbde 100644 --- a/extension/mods/tf2/nav/tfnavmesh.cpp +++ b/extension/mods/tf2/nav/tfnavmesh.cpp @@ -29,6 +29,17 @@ CTFNavMesh::CTFNavMesh() : CNavMesh() AddWalkableEntity("trigger_capture_area", true); AddWalkableEntity("trigger_timer_door", true); AddWalkableEntity("info_powerup_spawn"); + + navgenparams->half_human_width = 24.0f; + navgenparams->half_human_height = 41.0f; + navgenparams->human_height = 82.0f; + navgenparams->human_crouch_height = 62.0f; + navgenparams->human_eye_height = 74.0f; + navgenparams->human_crouch_eye_height = 44.0f; + navgenparams->jump_height = 49.0f; + navgenparams->jump_crouch_height = 68.0f; + navgenparams->climb_up_height = 68.0f; + navgenparams->death_drop = 220.0f; // experimental } CTFNavMesh::~CTFNavMesh() diff --git a/extension/navmesh/nav.h b/extension/navmesh/nav.h index f244adb..c9e2298 100644 --- a/extension/navmesh/nav.h +++ b/extension/navmesh/nav.h @@ -20,42 +20,30 @@ struct edict_t; /** - * Below are several constants used by the navigation system. - * @todo Move these into TheNavMesh singleton. + * @brief Parameters used during nav mesh generation. */ -constexpr float GenerationStepSize = 25.0f; // (30) was 20, but bots can't fit always fit -constexpr float JumpHeight = 41.8f; // if delta Z is less than this, we can jump up on it - -#if defined(CSTRIKE_DLL) -constexpr float JumpCrouchHeight = 58.0f; // (48) if delta Z is less than or equal to this, we can jumpcrouch up on it -#else -constexpr float JumpCrouchHeight = 64.0f; // (48) if delta Z is less than or equal to this, we can jumpcrouch up on it -#endif - -// There are 3 different definitions of StepHeight throughout the code, waiting to produce bugs if the 18.0 is ever changed. -constexpr float StepHeight = 18.0f; // if delta Z is greater than this, we have to jump to get up - -// TERROR: Increased DeathDrop from 200, since zombies don't take falling damage -#if defined(CSTRIKE_DLL) -constexpr float DeathDrop = 200.0f; // (300) distance at which we will die if we fall - should be about 600, and pay attention to fall damage during pathfind -#else -constexpr float DeathDrop = 400.0f; // (300) distance at which we will die if we fall - should be about 600, and pay attention to fall damage during pathfind -#endif - -#if defined(CSTRIKE_DLL) -constexpr float ClimbUpHeight = JumpCrouchHeight; // CSBots assume all jump up links are reachable -#else -constexpr float ClimbUpHeight = JumpCrouchHeight; //200.0f; // height to check for climbing up -#endif - -// TERROR: Converted these values to use the same numbers as the player bounding boxes etc -constexpr auto HalfHumanWidth = 16.0f; -constexpr auto HalfHumanHeight = 35.5f; -constexpr auto HumanHeight = 71.0f; -constexpr auto HumanEyeHeight = 62.0f; -constexpr auto HumanCrouchHeight = 55.0f; -constexpr auto HumanCrouchEyeHeight = 37.0f; +class CNavMeshGeneratorParameters +{ +public: + CNavMeshGeneratorParameters(); + + + float generation_step_size; + float jump_height; + float jump_crouch_height; + float step_height; + float death_drop; + float climb_up_height; + float half_human_width; // half player standing hull width + float half_human_height; // half player standing hull height + float human_height; // player standing hull height + float human_eye_height; // player standing view height + float human_crouch_height; // player crouching hull height + float human_crouch_eye_height; // player crouching view height +}; +// Global singleton for accessing the Navigation Mesh Generator Parameters +extern CNavMeshGeneratorParameters* navgenparams; #define NAV_MAGIC_NUMBER 0xFEEDFACE // to help identify nav files diff --git a/extension/navmesh/nav_area.cpp b/extension/navmesh/nav_area.cpp index c4ab856..8587f92 100644 --- a/extension/navmesh/nav_area.cpp +++ b/extension/navmesh/nav_area.cpp @@ -1465,12 +1465,12 @@ float CNavArea::ComputeGroundHeightChange( const CNavArea *area ) const // find actual ground height at each point in case // areas are below/above actual terrain float toZ, fromZ; - if ( TheNavMesh->GetSimpleGroundHeight( closeTo + Vector( 0, 0, StepHeight ), &toZ ) == false ) + if ( TheNavMesh->GetSimpleGroundHeight( closeTo + Vector( 0, 0, navgenparams->step_height ), &toZ ) == false ) { return 0.0f; } - if ( TheNavMesh->GetSimpleGroundHeight( closeFrom + Vector( 0, 0, StepHeight ), &fromZ ) == false ) + if ( TheNavMesh->GetSimpleGroundHeight( closeFrom + Vector( 0, 0, navgenparams->step_height ), &fromZ ) == false ) { return 0.0f; } @@ -1626,7 +1626,7 @@ void CNavArea::FinishSplitEdit( CNavArea *newArea, NavDirType ignoreEdge ) break; } - while ( !newArea->IsOverlapping( *newArea->m_node[ corner[0] ]->GetPosition(), GenerationStepSize/2 ) ) + while ( !newArea->IsOverlapping( *newArea->m_node[ corner[0] ]->GetPosition(), navgenparams->generation_step_size/2 ) ) { for ( int i=0; i<2; ++i ) { @@ -2060,7 +2060,7 @@ bool CNavArea::Contains( const Vector &pos ) const // if the nav area is above the given position, fail // allow nav area to be as much as a step height above the given position - if (myZ - StepHeight > pos.z) + if (myZ - navgenparams->step_height > pos.z) return false; Extent areaExtent; @@ -2526,8 +2526,8 @@ NavDirType CNavArea::ComputeLargestPortal( const CNavArea *to, Vector *center, f */ void CNavArea::ComputeClosestPointInPortal( const CNavArea *to, NavDirType dir, const Vector &fromPos, Vector *closePos ) const { -// const float margin = 0.0f; //GenerationStepSize/2.0f; // causes trouble with very small/narrow nav areas - const float margin = GenerationStepSize; +// const float margin = 0.0f; //navgenparams->generation_step_size/2.0f; // causes trouble with very small/narrow nav areas + const float margin = navgenparams->generation_step_size; if ( dir == NORTH || dir == SOUTH ) { @@ -2669,7 +2669,7 @@ bool CNavArea::IsContiguous( const CNavArea *other ) const other->ComputePortal( this, OppositeDirection( (NavDirType)dir ), &otherEdge, &halfWidth ); // must use stepheight because rough terrain can have gaps/cracks between adjacent nav areas - return ( myEdge - otherEdge ).IsLengthLessThan( StepHeight ); + return ( myEdge - otherEdge ).IsLengthLessThan( navgenparams->step_height ); } @@ -2982,7 +2982,7 @@ void CNavArea::Draw( void ) const Vector pos = GetCorner( (NavCornerType)i ); Vector end = pos; float lightIntensity = GetLightIntensity(pos); - end.z += HumanHeight*lightIntensity; + end.z += navgenparams->human_height*lightIntensity; lightIntensity *= 255; // for color debugoverlay->AddLineOverlay( end, pos, lightIntensity, lightIntensity, MAX( 192, lightIntensity ), true, DebugDuration ); } @@ -3111,7 +3111,7 @@ void CNavArea::Draw( void ) const float deltaEastWest = fabs( westZ - eastZ ); float deltaNorthSouth = fabs( northZ - southZ ); - float stepSize = StepHeight / 2.0f; + float stepSize = navgenparams->step_height / 2.0f; float t; if ( deltaEastWest > deltaNorthSouth ) @@ -3389,7 +3389,7 @@ void CNavArea::DrawConnectedAreas( CNavMesh* TheNavMesh ) const TheNavMesh->IsEditMode(CNavMesh::PLACE_PAINTING)); if ( !ladder->IsConnected( this, CNavLadder::LADDER_DOWN ) ) { - NavDrawLine( m_center, ladder->m_bottom + Vector( 0, 0, GenerationStepSize ), NavConnectedOneWayColor ); + NavDrawLine( m_center, ladder->m_bottom + Vector( 0, 0, navgenparams->generation_step_size ), NavConnectedOneWayColor ); } } } @@ -3697,7 +3697,7 @@ inline bool CNavArea::IsVisible( const Vector &eye, Vector *visSpot ) const Vector corner; trace_t result; trace::CTraceFilterNoNPCsOrPlayers tracefilter(nullptr, COLLISION_GROUP_NONE); - const float offset = 0.75f * HumanHeight; + const float offset = 0.75f * navgenparams->human_height; // check center first trace::line(eye, GetCenter() + Vector(0, 0, offset), MASK_BLOCKLOS_AND_NPCS | CONTENTS_IGNORE_NODRAW_OPAQUE, &tracefilter, result); @@ -3825,7 +3825,7 @@ bool IsHidingSpotInCover( const Vector &spot ) trace_t result; Vector from = spot; - from.z += HalfHumanHeight; + from.z += navgenparams->human_height; Vector to; @@ -3842,7 +3842,7 @@ bool IsHidingSpotInCover( const Vector &spot ) for( float angle = 0.0f; angle < 2.0f * M_PI; angle += inc ) { - to = from + Vector( coverRange * (float)cos(angle), coverRange * (float)sin(angle), HalfHumanHeight ); + to = from + Vector( coverRange * (float)cos(angle), coverRange * (float)sin(angle), navgenparams->human_height ); trace::line(from, to, MASK_NPCSOLID_BRUSHONLY, nullptr, COLLISION_GROUP_NONE, result); @@ -4050,12 +4050,12 @@ void ClassifySniperSpot( HidingSpot *spot ) if (hidingArea && (hidingArea->GetAttributes() & NAV_MESH_STAND)) { // we will be standing at this hiding spot - eye.z += HumanEyeHeight; + eye.z += navgenparams->human_eye_height; } else { // we are crouching when at this hiding spot - eye.z += HumanCrouchEyeHeight; + eye.z += navgenparams->human_crouch_eye_height; } Vector walkable; @@ -4078,11 +4078,11 @@ void ClassifySniperSpot( HidingSpot *spot ) area->GetExtent( &areaExtent ); // scan this area - for( walkable.y = areaExtent.lo.y + GenerationStepSize/2.0f; walkable.y < areaExtent.hi.y; walkable.y += GenerationStepSize ) + for( walkable.y = areaExtent.lo.y + navgenparams->generation_step_size/2.0f; walkable.y < areaExtent.hi.y; walkable.y += navgenparams->generation_step_size ) { - for( walkable.x = areaExtent.lo.x + GenerationStepSize/2.0f; walkable.x < areaExtent.hi.x; walkable.x += GenerationStepSize ) + for( walkable.x = areaExtent.lo.x + navgenparams->generation_step_size/2.0f; walkable.x < areaExtent.hi.x; walkable.x += navgenparams->generation_step_size ) { - walkable.z = area->GetZ( walkable ) + HalfHumanHeight; + walkable.z = area->GetZ(walkable) + navgenparams->half_human_height;; // check line of sight trace::line(eye, walkable, CONTENTS_SOLID | CONTENTS_MOVEABLE | CONTENTS_PLAYERCLIP, nullptr, COLLISION_GROUP_NONE, result); @@ -4271,11 +4271,11 @@ bool CNavArea::ComputeLighting( void ) for ( int i=0; ihuman_height - navgenparams->step_height; // players light from their centers, and we light from slightly below that, to allow for low ceilings float height; if ( TheNavMesh->GetGroundHeight( pos, &height ) ) { - pos.z = height + HalfHumanHeight - StepHeight; // players light from their centers, and we light from slightly below that, to allow for low ceilings + pos.z = height + navgenparams->human_height - navgenparams->step_height; // players light from their centers, and we light from slightly below that, to allow for low ceilings } Vector light( 0, 0, 0 ); @@ -4427,15 +4427,15 @@ void CNavArea::RaiseCorner( NavCornerType corner, int amount, bool raiseAdjacent //-------------------------------------------------------------------------------------------------------------- /** - * FindGroundZFromPoint walks from the start position to the end position in GenerationStepSize increments, + * FindGroundZFromPoint walks from the start position to the end position in navgenparams->generation_step_size increments, * checking the ground height along the way. */ float FindGroundZFromPoint( const Vector& end, const Vector& start ) { - Vector step( 0, 0, StepHeight ); + Vector step( 0, 0, navgenparams->step_height ); if ( fabs( end.x - start.x ) > fabs( end.y - start.y ) ) { - step.x = GenerationStepSize; + step.x = navgenparams->generation_step_size; if ( end.x < start.x ) { step.x = -step.x; @@ -4443,7 +4443,7 @@ float FindGroundZFromPoint( const Vector& end, const Vector& start ) } else { - step.y = GenerationStepSize; + step.y = navgenparams->generation_step_size; if ( end.y < start.y ) { step.y = -step.y; @@ -4453,7 +4453,7 @@ float FindGroundZFromPoint( const Vector& end, const Vector& start ) // step towards our end point Vector point = start; float z; - while ( point.AsVector2D().DistTo( end.AsVector2D() ) > GenerationStepSize ) + while ( point.AsVector2D().DistTo( end.AsVector2D() ) > navgenparams->generation_step_size ) { point = point + step; z = point.z; @@ -4467,7 +4467,7 @@ float FindGroundZFromPoint( const Vector& end, const Vector& start ) } } - // now do the exact one once we're within GenerationStepSize of it + // now do the exact one once we're within navgenparams->generation_step_size of it z = point.z + step.z; point = end; point.z = z; @@ -4478,14 +4478,14 @@ float FindGroundZFromPoint( const Vector& end, const Vector& start ) //-------------------------------------------------------------------------------------------------------------- /** * Finds the Z value for a corner given two other corner points. This walks along the edges of the nav area - * in GenerationStepSize increments, to increase accuracy. + * in navgenparams->generation_step_size increments, to increase accuracy. */ float FindGroundZ( const Vector& original, const Vector& corner1, const Vector& corner2 ) { float first = FindGroundZFromPoint( original, corner1 ); float second = FindGroundZFromPoint( original, corner2 ); - if ( fabs( first - second ) > StepHeight ) + if ( fabs( first - second ) > navgenparams->step_height ) { // approaching the point from the two directions didn't agree. Take the one closest to the original z. if ( fabs( original.z - first ) > fabs( original.z - second ) ) @@ -4608,7 +4608,7 @@ static void CommandNavUpdateBlocked( void ) || (player->IsDead() || player->IsObserver()) && player->GetObserverMode() == OBS_MODE_ROAMING) { Vector origin = blockedArea->GetCenter() - + Vector(0, 0, 0.75f * HumanHeight); + + Vector(0, 0, 0.75f * navgenparams->human_height); UTIL_SetOrigin(player, origin); } @@ -4809,14 +4809,14 @@ void CNavArea::UpdateBlocked( bool force, int teamID ) } Vector origin = GetCenter(); - origin.z += HalfHumanHeight; + origin.z += navgenparams->human_height; - const float sizeX = MAX( 1, MIN( GetSizeX()/2 - 5, HalfHumanWidth ) ); - const float sizeY = MAX( 1, MIN( GetSizeY()/2 - 5, HalfHumanWidth ) ); + const float sizeX = MAX(1, MIN(GetSizeX() / 2 - 5, navgenparams->half_human_width )); + const float sizeY = MAX( 1, MIN( GetSizeY()/2 - 5, navgenparams->half_human_width ) ); Extent bounds; bounds.lo.Init( -sizeX, -sizeY, 0 ); // duck height - halfhumanheight - bounds.hi.Init( sizeX, sizeY, 36.0f - HalfHumanHeight ); + bounds.hi.Init( sizeX, sizeY, 36.0f - navgenparams->human_height ); bool wasBlocked = IsBlocked( NAV_TEAM_ANY ); @@ -4908,11 +4908,11 @@ void CNavArea::CheckFloor( edict_t* ignore ) return; Vector origin = GetCenter(); - origin.z -= JumpCrouchHeight; + origin.z -= navgenparams->jump_crouch_height; - const float size = GenerationStepSize * 0.5f; + const float size = navgenparams->generation_step_size * 0.5f; Vector mins = Vector( -size, -size, 0 ); - Vector maxs = Vector( size, size, JumpCrouchHeight + 10.0f ); + Vector maxs = Vector( size, size, navgenparams->jump_crouch_height + 10.0f ); // See if spot is valid CBaseEntity* be = reinterpret_cast(ignore->GetIServerEntity()); @@ -4942,9 +4942,9 @@ bool CNavArea::HasSolidFloor() const { constexpr auto hullsize = 12.0f; Vector startPos = GetCenter(); - startPos.z += StepHeight; + startPos.z += navgenparams->step_height; Vector endPos = GetCenter(); - endPos.z -= JumpHeight; + endPos.z -= navgenparams->jump_height; Vector mins(-hullsize, -hullsize, 0.0f); Vector maxs(hullsize, hullsize, 1.0f); @@ -4972,14 +4972,14 @@ bool CNavArea::HasSolidObstruction() const trace::CTraceFilterNoNPCsOrPlayers filter(nullptr, COLLISION_GROUP_NONE); trace_t result; Vector origin = GetCenter(); - origin.z += HalfHumanHeight; + origin.z += navgenparams->human_height; - const float sizeX = std::max(1.0f, std::min(GetSizeX() / 2 - 5, HalfHumanWidth)); - const float sizeY = std::max(1.0f, std::min(GetSizeY() / 2 - 5, HalfHumanWidth)); + const float sizeX = std::max(1.0f, std::min(GetSizeX() / 2 - 5, navgenparams->half_human_width)); + const float sizeY = std::max(1.0f, std::min(GetSizeY() / 2 - 5, navgenparams->half_human_width)); Extent bounds; bounds.lo.Init(-sizeX, -sizeY, 0); // duck height - halfhumanheight - bounds.hi.Init(sizeX, sizeY, 36.0f - HalfHumanHeight); + bounds.hi.Init(sizeX, sizeY, 36.0f - navgenparams->human_height); trace::hull(origin, origin, bounds.lo, bounds.hi, MASK_PLAYERSOLID, &filter, result); @@ -5052,7 +5052,7 @@ void CNavArea::UpdateAvoidanceObstacles( void ) Vector maxs = m_seCorner; mins.z = MIN( m_nwCorner.z, m_seCorner.z ); - maxs.z = MAX( m_nwCorner.z, m_seCorner.z ) + HumanCrouchHeight; + maxs.z = MAX( m_nwCorner.z, m_seCorner.z ) + navgenparams->human_crouch_height; float obstructionHeight = 0.0f; for ( int i=0; iGetObstructions().Count(); ++i ) @@ -5180,7 +5180,7 @@ static void CommandNavCheckFloor( void ) #if SOURCE_ENGINE == SE_SDK2013 if ( area->IsBlocked( NAV_TEAM_ANY ) ) { - DevMsg( "Area #%d %s is blocked\n", area->GetID(), VecToString( area->GetCenter() + Vector( 0, 0, HalfHumanHeight ) ) ); + DevMsg( "Area #%d %s is blocked\n", area->GetID(), VecToString( area->GetCenter() + Vector( 0, 0, navgenparams->human_height ) ) ); } #endif } @@ -5194,7 +5194,7 @@ static void CommandNavCheckFloor( void ) #if SOURCE_ENGINE == SE_SDK2013 if ( area->IsBlocked( NAV_TEAM_ANY ) ) { - DevMsg( "Area #%d %s is blocked\n", area->GetID(), VecToString( area->GetCenter() + Vector( 0, 0, HalfHumanHeight ) ) ); + DevMsg( "Area #%d %s is blocked\n", area->GetID(), VecToString( area->GetCenter() + Vector( 0, 0, navgenparams->human_height ) ) ); } #endif } @@ -5216,18 +5216,18 @@ bool SelectOverlappingAreas::operator()( CNavArea *area ) Vector nw = area->GetCorner( NORTH_WEST ); Vector se = area->GetCorner( SOUTH_EAST ); Vector start = nw; - start.x += GenerationStepSize/2; - start.y += GenerationStepSize/2; + start.x += navgenparams->generation_step_size/2; + start.y += navgenparams->generation_step_size/2; while ( start.x < se.x ) { - start.y = nw.y + GenerationStepSize/2; + start.y = nw.y + navgenparams->generation_step_size/2; while ( start.y < se.y ) { start.z = area->GetZ( start.x, start.y ); Vector end = start; - start.z -= StepHeight; - end.z += HalfHumanHeight; + start.z -= navgenparams->step_height; + end.z += navgenparams->human_height; if ( TheNavMesh->FindNavAreaOrLadderAlongRay( start, end, &overlappingArea, &overlappingLadder, area ) ) { @@ -5238,9 +5238,9 @@ bool SelectOverlappingAreas::operator()( CNavArea *area ) } } - start.y += GenerationStepSize; + start.y += navgenparams->generation_step_size; } - start.x += GenerationStepSize; + start.x += navgenparams->generation_step_size; } return true; } diff --git a/extension/navmesh/nav_area.h b/extension/navmesh/nav_area.h index f02d30d..dbd5e28 100644 --- a/extension/navmesh/nav_area.h +++ b/extension/navmesh/nav_area.h @@ -380,7 +380,7 @@ class CNavArea : protected CNavAreaCriticalData void MarkObstacleToAvoid( float obstructionHeight ); void UpdateAvoidanceObstacles( void ); - bool HasAvoidanceObstacle( float maxObstructionHeight = StepHeight ) const; // is there a large, immobile object obstructing this area + bool HasAvoidanceObstacle( float maxObstructionHeight = navgenparams->step_height ) const; // is there a large, immobile object obstructing this area float GetAvoidanceObstacleHeight( void ) const; // returns the maximum height of the obstruction above the ground #ifdef NEXT_BOT diff --git a/extension/navmesh/nav_edit.cpp b/extension/navmesh/nav_edit.cpp index a8221fe..fc5eae8 100644 --- a/extension/navmesh/nav_edit.cpp +++ b/extension/navmesh/nav_edit.cpp @@ -76,7 +76,7 @@ int GetGridSize( bool forceGrid = false ) { if ( TheNavMesh->IsGenerating() ) { - return (int)GenerationStepSize; + return (int)navgenparams->generation_step_size; } int snapVal = sm_nav_snap_to_grid.GetInt(); @@ -90,7 +90,7 @@ int GetGridSize( bool forceGrid = false ) return 0; } - int scale = (int)GenerationStepSize; + int scale = (int)navgenparams->generation_step_size; switch ( snapVal ) { case 3: @@ -511,7 +511,7 @@ void CNavMesh::CommandNavBuildLadder( void ) Vector rightEdge = m_editCursorPos; // trace to the sides to find the width - Vector probe = m_surfaceNormal * -HalfHumanWidth; + Vector probe = m_surfaceNormal * -navgenparams->half_human_width; const float StepSize = 1.0f; StepAlongClimbableSurface( leftEdge, right * -StepSize, probe ); StepAlongClimbableSurface( rightEdge, right * StepSize, probe ); @@ -2073,14 +2073,14 @@ void CNavMesh::CommandNavSelectInvalidAreas( void ) if ( area ) { area->GetExtent( &areaExtent ); - for ( float x = areaExtent.lo.x; x + GenerationStepSize <= areaExtent.hi.x; x += GenerationStepSize ) + for ( float x = areaExtent.lo.x; x + navgenparams->generation_step_size <= areaExtent.hi.x; x += navgenparams->generation_step_size ) { - for ( float y = areaExtent.lo.y; y + GenerationStepSize <= areaExtent.hi.y; y += GenerationStepSize ) + for ( float y = areaExtent.lo.y; y + navgenparams->generation_step_size <= areaExtent.hi.y; y += navgenparams->generation_step_size ) { float nw = area->GetZ( x, y ); - float ne = area->GetZ( x + GenerationStepSize, y ); - float sw = area->GetZ( x, y + GenerationStepSize ); - float se = area->GetZ( x + GenerationStepSize, y + GenerationStepSize ); + float ne = area->GetZ( x + navgenparams->generation_step_size, y ); + float sw = area->GetZ( x, y + navgenparams->generation_step_size ); + float se = area->GetZ( x + navgenparams->generation_step_size, y + navgenparams->generation_step_size ); if ( !IsHeightDifferenceValid( nw, ne, sw, se ) || !IsHeightDifferenceValid( ne, nw, sw, se ) || @@ -2271,18 +2271,18 @@ bool MakeSniperSpots( CNavArea *area ) float sizeX = area->GetSizeX(); float sizeY = area->GetSizeY(); - if ( sizeX > GenerationStepSize && sizeX > sizeY ) + if ( sizeX > navgenparams->generation_step_size && sizeX > sizeY ) { - splitEdge = RoundToUnits( area->GetCorner( NORTH_WEST ).x, GenerationStepSize ); + splitEdge = RoundToUnits( area->GetCorner( NORTH_WEST ).x, navgenparams->generation_step_size ); if ( splitEdge < area->GetCorner( NORTH_WEST ).x + minSplitSize ) - splitEdge += GenerationStepSize; + splitEdge += navgenparams->generation_step_size; splitAlongX = false; } - else if ( sizeY > GenerationStepSize && sizeY > sizeX ) + else if ( sizeY > navgenparams->generation_step_size && sizeY > sizeX ) { - splitEdge = RoundToUnits( area->GetCorner( NORTH_WEST ).y, GenerationStepSize ); + splitEdge = RoundToUnits( area->GetCorner( NORTH_WEST ).y, navgenparams->generation_step_size ); if ( splitEdge < area->GetCorner( NORTH_WEST ).y + minSplitSize ) - splitEdge += GenerationStepSize; + splitEdge += navgenparams->generation_step_size; splitAlongX = true; } else @@ -2575,12 +2575,12 @@ void CNavMesh::CommandNavEndArea( void ) CNavArea *nearby = GetMarkedArea(); if ( !nearby ) { - nearby = TheNavMesh->GetNearestNavArea( m_editCursorPos + Vector( 0, 0, HalfHumanHeight ), + nearby = TheNavMesh->GetNearestNavArea( m_editCursorPos + Vector( 0, 0, navgenparams->human_height ), 10000.0f, true ); } if ( !nearby ) { - nearby = TheNavMesh->GetNearestNavArea( endPos + Vector( 0, 0, HalfHumanHeight ), 10000.0f, true ); + nearby = TheNavMesh->GetNearestNavArea( endPos + Vector( 0, 0, navgenparams->human_height ), 10000.0f, true ); } if ( !nearby ) { @@ -2667,7 +2667,7 @@ void CNavMesh::CommandNavEndArea( void ) bottom = tmp; } CreateLadder( top, bottom, m_ladderAnchor.DistTo( corner2 ), m_surfaceNormal.AsVector2D(), - HumanHeight ); + navgenparams->human_height ); } else { @@ -3374,7 +3374,7 @@ void CNavMesh::CommandNavWarpToMark( void ) IPlayerInfo* player = playerinfomanager->GetPlayerInfo(ent); if ( targetArea ) { - Vector origin = targetArea->GetCenter() + Vector( 0, 0, HumanHeight ); + Vector origin = targetArea->GetCenter() + Vector( 0, 0, navgenparams->human_height ); QAngle angles = player->GetAbsAngles(); entities::HBaseEntity be(ent); be.Teleport(origin, &angles, nullptr); @@ -3386,8 +3386,8 @@ void CNavMesh::CommandNavWarpToMark( void ) QAngle angles = player->GetAbsAngles(); Vector origin = (ladder->m_top + ladder->m_bottom)/2; - origin.x += ladder->GetNormal().x * GenerationStepSize; - origin.y += ladder->GetNormal().y * GenerationStepSize; + origin.x += ladder->GetNormal().x * navgenparams->generation_step_size; + origin.y += ladder->GetNormal().y * navgenparams->generation_step_size; entities::HBaseEntity be(ent); be.Teleport(origin, &angles, nullptr); EmitSound(ent, "EDIT_WARP_TO_MARK" ); diff --git a/extension/navmesh/nav_entities.cpp b/extension/navmesh/nav_entities.cpp index a3a430a..0a5f95d 100644 --- a/extension/navmesh/nav_entities.cpp +++ b/extension/navmesh/nav_entities.cpp @@ -554,7 +554,7 @@ int CFuncNavObstruction::DrawDebugTextOverlays( void ) } float CFuncNavObstruction::GetNavObstructionHeight(void) const { - return JumpCrouchHeight; + return navgenparams->jump_crouch_height; } //-------------------------------------------------------------------------------------------------------- diff --git a/extension/navmesh/nav_generate.cpp b/extension/navmesh/nav_generate.cpp index 7f3a84e..a5e2a51 100644 --- a/extension/navmesh/nav_generate.cpp +++ b/extension/navmesh/nav_generate.cpp @@ -35,8 +35,8 @@ static unsigned int blockedID[ MAX_BLOCKED_AREAS ]; static int blockedIDCount = 0; static float lastMsgTime = 0.0f; -bool TraceAdjacentNode( int depth, const Vector& start, const Vector& end, trace_t *trace, float zLimit = DeathDrop ); -bool StayOnFloor( trace_t *trace, float zLimit = DeathDrop ); +bool TraceAdjacentNode(int depth, const Vector& start, const Vector& end, trace_t* trace, float zLimit = navgenparams->death_drop ); +bool StayOnFloor( trace_t *trace, float zLimit = navgenparams->death_drop); ConVar sm_nav_slope_limit( "sm_nav_slope_limit", "0.7", FCVAR_CHEAT, "The ground unit normal's Z component must be greater than this for nav areas to be generated." ); ConVar sm_nav_slope_tolerance( "sm_nav_slope_tolerance", "0.1", FCVAR_CHEAT, "The ground unit normal's Z component must be this close to the nav area's Z component to be generated." ); @@ -49,9 +49,9 @@ ConVar sm_nav_area_max_size( "sm_nav_area_max_size", "50", FCVAR_CHEAT, "Max are // Common bounding box for traces Vector NavTraceMins( -0.45, -0.45, 0 ); -Vector NavTraceMaxs( 0.45, 0.45, HumanCrouchHeight ); +Vector NavTraceMaxs( 0.45, 0.45, navgenparams->human_crouch_height ); -const float MaxTraversableHeight = StepHeight; // max internal obstacle height that can occur between nav nodes and safely disregarded +const float MaxTraversableHeight = navgenparams->step_height; // max internal obstacle height that can occur between nav nodes and safely disregarded const float MinObstacleAreaWidth = 10.0f; // min width of a nav area we will generate on top of an obstacle extern IVEngineServer* engine; @@ -107,11 +107,11 @@ inline static CNavArea *findFirstAreaInDirection(const Vector *start, NavDirType ignore = reinterpret_cast(traceIgnore)->GetBaseEntity(); } - int end = (int)((range / GenerationStepSize) + 0.5f); + int end = (int)((range / navgenparams->generation_step_size) + 0.5f); for( int i=1; i<=end; i++ ) { - AddDirectionVector( &pos, dir, GenerationStepSize ); + AddDirectionVector( &pos, dir, navgenparams->generation_step_size ); // make sure we dont look thru the wall trace_t result; @@ -182,8 +182,8 @@ void CNavMesh::CreateLadder( const Vector& absMin, const Vector& absMax, float m { // ladder is facing north or south - determine which way // "pull in" traceline from bottom and top in case ladder abuts floor and/or ceiling - Vector from = ladder->m_bottom + Vector( 0.0f, GenerationStepSize, GenerationStepSize/2 ); - Vector to = ladder->m_top + Vector( 0.0f, GenerationStepSize, -GenerationStepSize/2 ); + Vector from = ladder->m_bottom + Vector( 0.0f, navgenparams->generation_step_size, navgenparams->generation_step_size/2 ); + Vector to = ladder->m_top + Vector( 0.0f, navgenparams->generation_step_size, -navgenparams->generation_step_size/2 ); trace::line(from, to, GetGenerationTraceMask(), nullptr, COLLISION_GROUP_NONE, result); @@ -193,8 +193,8 @@ void CNavMesh::CreateLadder( const Vector& absMin, const Vector& absMax, float m else { // ladder is facing east or west - determine which way - Vector from = ladder->m_bottom + Vector( GenerationStepSize, 0.0f, GenerationStepSize/2 ); - Vector to = ladder->m_top + Vector( GenerationStepSize, 0.0f, -GenerationStepSize/2 ); + Vector from = ladder->m_bottom + Vector( navgenparams->generation_step_size, 0.0f, navgenparams->generation_step_size/2 ); + Vector to = ladder->m_top + Vector( navgenparams->generation_step_size, 0.0f, -navgenparams->generation_step_size/2 ); trace::line(from, to, GetGenerationTraceMask(), nullptr, COLLISION_GROUP_NONE, result); ladder->SetDir( result.fraction != 1.0f || result.startsolid ? WEST : EAST ); @@ -351,8 +351,8 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea ) // // get approximate postion of player on ladder - Vector center = m_bottom + Vector( 0, 0, GenerationStepSize ); - AddDirectionVector( ¢er, m_dir, HalfHumanWidth ); + Vector center = m_bottom + Vector( 0, 0, navgenparams->generation_step_size ); + AddDirectionVector( ¢er, m_dir, navgenparams->half_human_width ); CNavArea* bottomArea = TheNavMesh->GetNearestNavArea( center, true ); if (!bottomArea) @@ -370,10 +370,10 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea ) // // get approximate postion of player on ladder - center = m_top + Vector( 0, 0, GenerationStepSize ); - AddDirectionVector( ¢er, m_dir, HalfHumanWidth ); + center = m_top + Vector( 0, 0, navgenparams->generation_step_size ); + AddDirectionVector( ¢er, m_dir, navgenparams->half_human_width ); - float beneathLimit = MIN( 120.0f, m_top.z - m_bottom.z + HalfHumanWidth ); + float beneathLimit = MIN( 120.0f, m_top.z - m_bottom.z + navgenparams->half_human_width ); // find "ahead" area CNavArea* topForwardArea = findFirstAreaInDirection( ¢er, OppositeDirection( m_dir ), nearLadderRange, beneathLimit, NULL ); @@ -464,7 +464,7 @@ void CNavLadder::ConnectGeneratedLadder( float maxHeightAboveTopArea ) { Vector bottomSpot; bottomArea->GetClosestPointOnArea( m_bottom, &bottomSpot ); - if (m_bottom.z - bottomSpot.z > HumanHeight) + if (m_bottom.z - bottomSpot.z > navgenparams->human_height) { bottomArea->Disconnect( this ); } @@ -565,12 +565,12 @@ class JumpConnector destArea->GetClosestPointOnArea( center, &destPos ); // No jumping up from stairs. - if ( sourceArea->HasAttributes( NAV_MESH_STAIRS ) && sourcePos.z + StepHeight < destPos.z ) + if ( sourceArea->HasAttributes( NAV_MESH_STAIRS ) && sourcePos.z + navgenparams->step_height < destPos.z ) { continue; } - if ( (sourcePos-destPos).AsVector2D().IsLengthLessThan( GenerationStepSize * 3 ) ) + if ( (sourcePos-destPos).AsVector2D().IsLengthLessThan( navgenparams->generation_step_size * 3 ) ) { sourceArea->ConnectTo( destArea, outgoingDir ); // DevMsg( "Connected %d->%d via %d (len %f)\n", @@ -629,7 +629,7 @@ void CNavMesh::MarkJumpAreas( void ) else if ( lowestNormalZ < sm_nav_slope_limit.GetFloat() + sm_nav_slope_tolerance.GetFloat() ) { Vector testPos = area->GetCenter(); - testPos.z += HalfHumanHeight; + testPos.z += navgenparams->human_height; Vector groundNormal; float dummy; if ( GetSimpleGroundHeight( testPos, &dummy, &groundNormal ) ) @@ -722,15 +722,15 @@ void CNavMesh::RaiseAreasWithInternalObstacles() { CNavArea *area = TheNavAreas[ it ]; - // any nav area with internal obstacles will be 1x1 (width and height = GenerationStepSize), so + // any nav area with internal obstacles will be 1x1 (width and height = navgenparams->generation_step_size), so // only need to consider areas of that size - if ( ( area->GetSizeX() != GenerationStepSize ) || (area->GetSizeY() != GenerationStepSize ) ) + if ( ( area->GetSizeX() != navgenparams->generation_step_size ) || (area->GetSizeY() != navgenparams->generation_step_size ) ) continue; float obstacleZ[2] = { -FLT_MAX, -FLT_MAX }; float obstacleZMax = -FLT_MAX; NavDirType obstacleDir = NORTH; - float obstacleStartDist = GenerationStepSize; + float obstacleStartDist = navgenparams->generation_step_size; float obstacleEndDist = 0; bool isStairNeighbor = false; @@ -748,7 +748,7 @@ void CNavMesh::RaiseAreasWithInternalObstacles() corner[0] = (NavCornerType) ( ( i + 3 ) % NUM_CORNERS ); // lower left-hand corner relative to current direction corner[1] = (NavCornerType) ( ( i + 2 ) % NUM_CORNERS ); // lower right-hand corner relative to current direction float obstacleZThisDir[2] = { -FLT_MAX, -FLT_MAX }; // absolute Z pos of obstacle for left and right edge in this direction - float obstacleStartDistThisDir = GenerationStepSize; // closest obstacle start distance in this direction + float obstacleStartDistThisDir = navgenparams->generation_step_size; // closest obstacle start distance in this direction float obstacleEndDistThisDir = 0; // farthest obstacle end distance in this direction // consider left and right edges of nav area relative to current direction @@ -815,7 +815,7 @@ void CNavMesh::RaiseAreasWithInternalObstacles() if ( obstacleZMax > -FLT_MAX ) { // enforce minimum obstacle width so we don't shrink to become a teensy nav area - AdjustObstacleDistances( &obstacleStartDist, &obstacleEndDist, GenerationStepSize ); + AdjustObstacleDistances( &obstacleStartDist, &obstacleEndDist, navgenparams->generation_step_size ); Assert( obstacleEndDist - obstacleStartDist >= MinObstacleAreaWidth ); // get current corner coords @@ -941,7 +941,7 @@ bool CNavMesh::CreateObstacleTopAreaIfNecessary( CNavArea *area, CNavArea *areaO float obstacleHeightMax = 0; float obstacleHeightStart = 0; float obstacleHeightEnd = 0; - float obstacleDistMin = GenerationStepSize; + float obstacleDistMin = navgenparams->generation_step_size; float obstacleDistMax = 0; Vector center; @@ -998,9 +998,9 @@ bool CNavMesh::CreateObstacleTopAreaIfNecessary( CNavArea *area, CNavArea *areaO { // if we arrived in the other area, the obstacle height to get here was the peak deltaZ of the node above to get here obstacleHeight = deltaZ; - // make a nav area MinObstacleAreaWidth wide centered on the peak node, which is GenerationStepSize away from where we started - obstacleDistStartCur = GenerationStepSize - (MinObstacleAreaWidth / 2); - obstacleDistEndCur = GenerationStepSize + (MinObstacleAreaWidth / 2); + // make a nav area MinObstacleAreaWidth wide centered on the peak node, which is navgenparams->generation_step_size away from where we started + obstacleDistStartCur = navgenparams->generation_step_size - (MinObstacleAreaWidth / 2); + obstacleDistEndCur = navgenparams->generation_step_size + (MinObstacleAreaWidth / 2); } } } @@ -1051,7 +1051,7 @@ bool CNavMesh::CreateObstacleTopAreaIfNecessary( CNavArea *area, CNavArea *areaO } // Enforce min area width for new area - AdjustObstacleDistances( &obstacleDistMin, &obstacleDistMax, bMultiNode ? GenerationStepSize * 2 : GenerationStepSize ); + AdjustObstacleDistances( &obstacleDistMin, &obstacleDistMax, bMultiNode ? navgenparams->generation_step_size * 2 : navgenparams->generation_step_size ); Assert( obstacleDistMin < obstacleDistMax ); Assert( obstacleDistMax - obstacleDistMin >= MinObstacleAreaWidth ); float newAreaWidth = obstacleDistMax - obstacleDistMin; @@ -1257,10 +1257,10 @@ static StairTestType IsStairs( const Vector &start, const Vector &end, StairTest hullMaxs.y = 8; } - Vector traceOffset( 0, 0, HalfHumanHeight ); + Vector traceOffset( 0, 0, navgenparams->human_height ); // total height change must exceed a single step to be stairs - if ( fabs( start.z - end.z ) > StepHeight ) + if ( fabs( start.z - end.z ) > navgenparams->step_height ) { // initialize the height delta trace::hull(start + traceOffset, start - traceOffset, hullMins, hullMaxs, MASK_NPCSOLID, &filter, trace); @@ -1295,9 +1295,9 @@ static StairTestType IsStairs( const Vector &start, const Vector &end, StairTest //NDebugOverlay::Cross3D( ground, 3, 0, 0, 255, true, 100.0f ); //NDebugOverlay::Box( ground, hullMins, hullMaxs, 0, 0, 255, 0.0f, 100.0f ); - if ( (t == 0.0f && fabs( height - start.z ) > StepHeight) + if ( (t == 0.0f && fabs( height - start.z ) > navgenparams->step_height) // Discontinuity at start - || (t == 1.0f && fabs( height - end.z ) > StepHeight) // Discontinuity at end + || (t == 1.0f && fabs( height - end.z ) > navgenparams->step_height) // Discontinuity at end || normal.z < MinStairNormal ) { // too steep here @@ -1307,12 +1307,12 @@ static StairTestType IsStairs( const Vector &start, const Vector &end, StairTest float deltaZ = fabs( height - priorHeight ); - if ( deltaZ >= minStepZ && deltaZ <= StepHeight ) + if ( deltaZ >= minStepZ && deltaZ <= navgenparams->step_height ) { // found a step ret = STAIRS_YES; } - else if ( deltaZ > StepHeight ) + else if ( deltaZ > navgenparams->step_height ) { // too steep here //NDebugOverlay::Cross3D( ground, 5, 255, 0, 0, true, 10.0f ); @@ -1343,7 +1343,7 @@ bool CNavArea::TestStairs( void ) // clear STAIRS attribute SetAttributes( GetAttributes() & ~NAV_MESH_STAIRS ); - if ( GetSizeX() <= GenerationStepSize && GetSizeY() <= GenerationStepSize ) + if ( GetSizeX() <= navgenparams->generation_step_size && GetSizeY() <= navgenparams->generation_step_size ) { // Don't bother with stairs on small areas return false; @@ -1582,7 +1582,7 @@ static bool testStitchConnection( CNavArea *source, CNavArea *target, const Vect { // test going up ClimbUpHeight bool success = false; - for ( float height = StepHeight; height <= ClimbUpHeight; height += 1.0f ) + for ( float height = navgenparams->step_height; height <= navgenparams->climb_up_height; height += 1.0f ) { trace_t tr; Vector start( from ); @@ -1689,7 +1689,7 @@ inline static bool testJumpDown( const Vector *fromPos, const Vector *toPos ) float dz = fromPos->z - toPos->z; // drop can't be too far, or too short (or nonexistant) - if (dz <= JumpCrouchHeight || dz >= DeathDrop) + if (dz <= navgenparams->jump_crouch_height || dz >= navgenparams->death_drop) return false; // @@ -1707,7 +1707,7 @@ inline static bool testJumpDown( const Vector *fromPos, const Vector *toPos ) trace_t result; // Try to go up and out, up to ClimbUpHeight, to get over obstacles - for ( up=1.0f; up<=ClimbUpHeight; up += 1.0f ) + for ( up = 1.0f; up <= navgenparams->climb_up_height; up += 1.0f ) { from = *fromPos; to.Init( fromPos->x, fromPos->y, fromPos->z + up ); @@ -1727,7 +1727,7 @@ inline static bool testJumpDown( const Vector *fromPos, const Vector *toPos ) break; } - if ( up > ClimbUpHeight ) + if ( up > navgenparams->climb_up_height ) return false; // We've made it up and out, so see if we can drop down @@ -1736,18 +1736,18 @@ inline static bool testJumpDown( const Vector *fromPos, const Vector *toPos ) trace::hull(from, to, NavTraceMins, NavTraceMaxs, TheNavMesh->GetGenerationTraceMask(), nullptr, COLLISION_GROUP_NONE, result); return result.fraction > 0.0f && !result.startsolid // Allow a little fudge so we can drop down onto stairs - && result.endpos.z <= to.z + StepHeight; + && result.endpos.z <= to.z + navgenparams->step_height; } //-------------------------------------------------------------------------------------------------------------- inline static CNavArea *findJumpDownArea( const Vector *fromPos, NavDirType dir ) { - Vector start( fromPos->x, fromPos->y, fromPos->z + HalfHumanHeight ); - AddDirectionVector( &start, dir, GenerationStepSize/2.0f ); + Vector start( fromPos->x, fromPos->y, fromPos->z + navgenparams->human_height ); + AddDirectionVector( &start, dir, navgenparams->generation_step_size/2.0f ); Vector toPos; - CNavArea *downArea = findFirstAreaInDirection( &start, dir, 4.0f * GenerationStepSize, DeathDrop, NULL, &toPos ); + CNavArea *downArea = findFirstAreaInDirection( &start, dir, 4.0f * navgenparams->generation_step_size, navgenparams->death_drop, NULL, &toPos ); return downArea && testJumpDown( fromPos, &toPos ) ? downArea : nullptr; @@ -1786,24 +1786,24 @@ void CNavMesh::StitchAreaIntoMesh( CNavArea *area, NavDirType dir, Functor &func float edgeLength = edgeDir.NormalizeInPlace(); - for ( float n=0; ngeneration_step_size ) { Vector sourcePos = corner1 + edgeDir * ( n + 0.5f ); - sourcePos.z += HalfHumanHeight; + sourcePos.z += navgenparams->human_height; Vector targetPos = sourcePos; switch ( dir ) { - case NORTH: targetPos.y -= GenerationStepSize * 0.5f; break; - case SOUTH: targetPos.y += GenerationStepSize * 0.5f; break; - case EAST: targetPos.x += GenerationStepSize * 0.5f; break; - case WEST: targetPos.x -= GenerationStepSize * 0.5f; break; + case NORTH: targetPos.y -= navgenparams->generation_step_size * 0.5f; break; + case SOUTH: targetPos.y += navgenparams->generation_step_size * 0.5f; break; + case EAST: targetPos.x += navgenparams->generation_step_size * 0.5f; break; + case WEST: targetPos.x -= navgenparams->generation_step_size * 0.5f; break; } CNavArea *targetArea = TheNavMesh->GetNavArea( targetPos ); if ( targetArea && !func( targetArea ) ) { - targetPos.z = targetArea->GetZ( targetPos.x, targetPos.y ) + HalfHumanHeight; + targetPos.z = targetArea->GetZ( targetPos.x, targetPos.y ) + navgenparams->human_height; // outgoing connection if ( testStitchConnection( area, targetArea, sourcePos, targetPos ) ) @@ -1819,7 +1819,7 @@ void CNavMesh::StitchAreaIntoMesh( CNavArea *area, NavDirType dir, Functor &func } else { - sourcePos.z -= HalfHumanHeight; + sourcePos.z -= navgenparams->human_height; sourcePos.z += 1; CNavArea *downArea = findJumpDownArea( &sourcePos, dir ); if ( downArea && downArea != area && !func( downArea ) ) @@ -2017,7 +2017,7 @@ void CNavMesh::MergeGeneratedAreas( void ) { CNavArea *adjArea = area->m_connect[ NORTH ][ nit ].area; if ( !area->IsAbleToMergeWith( adjArea ) // pre-existing areas in incremental generates won't have nodes - || area->GetSizeY() + adjArea->GetSizeY() > GenerationStepSize * sm_nav_area_max_size.GetInt() ) + || area->GetSizeY() + adjArea->GetSizeY() > navgenparams->generation_step_size * sm_nav_area_max_size.GetInt() ) continue; if (area->m_node[ NORTH_WEST ] == adjArea->m_node[ SOUTH_WEST ] && @@ -2047,7 +2047,7 @@ void CNavMesh::MergeGeneratedAreas( void ) { CNavArea *adjArea = area->m_connect[ SOUTH ][ sit ].area; if ( !area->IsAbleToMergeWith( adjArea ) // pre-existing areas in incremental generates won't have nodes - || area->GetSizeY() + adjArea->GetSizeY() > GenerationStepSize * sm_nav_area_max_size.GetInt() ) + || area->GetSizeY() + adjArea->GetSizeY() > navgenparams->generation_step_size * sm_nav_area_max_size.GetInt() ) continue; if (adjArea->m_node[ NORTH_WEST ] == area->m_node[ SOUTH_WEST ] && @@ -2079,7 +2079,7 @@ void CNavMesh::MergeGeneratedAreas( void ) { CNavArea *adjArea = area->m_connect[ WEST ][ wit ].area; if ( !area->IsAbleToMergeWith( adjArea ) // pre-existing areas in incremental generates won't have nodes - || area->GetSizeX() + adjArea->GetSizeX() > GenerationStepSize * sm_nav_area_max_size.GetInt() ) + || area->GetSizeX() + adjArea->GetSizeX() > navgenparams->generation_step_size * sm_nav_area_max_size.GetInt() ) continue; if (area->m_node[ NORTH_WEST ] == adjArea->m_node[ NORTH_EAST ] && @@ -2110,7 +2110,7 @@ void CNavMesh::MergeGeneratedAreas( void ) { CNavArea *adjArea = area->m_connect[ EAST ][ eit ].area; if ( !area->IsAbleToMergeWith( adjArea ) // pre-existing areas in incremental generates won't have nodes - || area->GetSizeX() + adjArea->GetSizeX() > GenerationStepSize * sm_nav_area_max_size.GetInt() ) + || area->GetSizeX() + adjArea->GetSizeX() > navgenparams->generation_step_size * sm_nav_area_max_size.GetInt() ) continue; if (adjArea->m_node[ NORTH_WEST ] == area->m_node[ NORTH_EAST ] && @@ -2200,7 +2200,7 @@ void CNavMesh::FixConnections( void ) // Flat edges of stairs need to connect. It's the slopes we don't want to climb over things for. float cornerDeltaZ = fabs( area->GetCorner( cornerType[0] ).z - area->GetCorner( cornerType[1] ).z ); - if ( cornerDeltaZ < StepHeight ) + if ( cornerDeltaZ < navgenparams->step_height ) continue; const NavConnectVector *connectedAreas = area->GetAdjacentAreas( (NavDirType)dir ); @@ -2228,21 +2228,21 @@ void CNavMesh::FixConnections( void ) GetCornerTypesInDirection( OppositeDirection((NavDirType)dir), &adjCornerType[0], &adjCornerType[1] ); // From the stair's perspective, we can't go up more than step height to reach the adjacent area. - // Also, if the adjacent area has to jump up higher than StepHeight above the stair area to reach the stairs, + // Also, if the adjacent area has to jump up higher than navgenparams->step_height above the stair area to reach the stairs, // there's an obstruction close to the adjacent area that could prevent walking from the stairs down. - if ( node->GetGroundHeightAboveNode( cornerType[0] ) > StepHeight ) + if ( node->GetGroundHeightAboveNode( cornerType[0] ) > navgenparams->step_height ) { areasToDisconnect.AddToTail( adjArea ); } - else if ( node->GetGroundHeightAboveNode( cornerType[1] ) > StepHeight ) + else if ( node->GetGroundHeightAboveNode( cornerType[1] ) > navgenparams->step_height ) { areasToDisconnect.AddToTail( adjArea ); } - else if ( adjPos.z + adjNode->GetGroundHeightAboveNode( adjCornerType[0] ) > pos.z + StepHeight ) + else if ( adjPos.z + adjNode->GetGroundHeightAboveNode( adjCornerType[0] ) > pos.z + navgenparams->step_height ) { areasToDisconnect.AddToTail( adjArea ); } - else if ( adjPos.z + adjNode->GetGroundHeightAboveNode( adjCornerType[1] ) > pos.z + StepHeight ) + else if ( adjPos.z + adjNode->GetGroundHeightAboveNode( adjCornerType[1] ) > pos.z + navgenparams->step_height ) { areasToDisconnect.AddToTail( adjArea ); } @@ -2294,7 +2294,7 @@ void CNavMesh::FixConnections( void ) */ void CNavMesh::FixCornerOnCornerAreas( void ) { - const float MaxDrop = StepHeight; // don't make corner on corner areas that are too steep + const float MaxDrop = navgenparams->step_height; // don't make corner on corner areas that are too steep FOR_EACH_VEC( TheNavAreas, it ) { @@ -2345,7 +2345,7 @@ void CNavMesh::FixCornerOnCornerAreas( void ) Vector vecDeltaOtherEdge; DirectionToVector2D( dirAlongOtherEdge, (Vector2D *) &vecDeltaOtherEdge ); vecDeltaOtherEdge.z = 0; - vecDeltaOtherEdge *= GenerationStepSize * 0.5; + vecDeltaOtherEdge *= navgenparams->generation_step_size * 0.5; Vector vecOtherEdgePos = cornerPos + vecDeltaOtherEdge; // see if there is a nav area at that location @@ -2368,7 +2368,7 @@ void CNavMesh::FixCornerOnCornerAreas( void ) Vector vecDeltaOurEdge; DirectionToVector2D( dirAlongOurEdge, (Vector2D *) &vecDeltaOurEdge ); vecDeltaOurEdge.z = 0; - vecDeltaOurEdge *= GenerationStepSize * 0.5; + vecDeltaOurEdge *= navgenparams->generation_step_size * 0.5; Vector vecOurEdgePos = cornerPos + vecDeltaOurEdge; Vector vecCorner[4]; vecCorner[0] = cornerPos + vecDeltaOtherEdge + vecDeltaOurEdge; // far corner of new nav area @@ -2452,7 +2452,7 @@ void CNavMesh::SplitAreasUnderOverhangs( void ) { // if the upper area isn't at least crouch height above the lower area, this is some weird minor // overlap, disregard it - const float flMinSeparation = HumanCrouchHeight; + const float flMinSeparation = navgenparams->human_crouch_height; if ( !( areaExtent.lo.z > otherAreaExtent.hi.z + flMinSeparation ) && !( otherAreaExtent.lo.z > areaExtent.hi.z + flMinSeparation ) ) continue; @@ -2513,16 +2513,16 @@ void CNavMesh::SplitAreasUnderOverhangs( void ) Assert( splitEdgeSize > 0 ); // if we split the lower nav area right where it's in shadow of the upper nav area, will it create a really tiny strip? - if ( splitLen < GenerationStepSize ) + if ( splitLen < navgenparams->generation_step_size ) { // if the "in shadow" part of the lower nav area is really small or the lower nav area is really small to begin with, // don't split it, we're better off as is - if ( ( splitLen < GenerationStepSize*0.3 ) || ( splitEdgeSize <= GenerationStepSize * 2 ) ) + if ( ( splitLen < navgenparams->generation_step_size*0.3 ) || ( splitEdgeSize <= navgenparams->generation_step_size * 2 ) ) continue; // Move our split point so we don't create a really tiny strip on the lower nav area. Move the split point away from - // the upper nav area so the "in shadow" area expands to be GenerationStepSize. The checks above ensure we have room to do this. - splitCoord += (GenerationStepSize - splitLen) + // the upper nav area so the "in shadow" area expands to be navgenparams->generation_step_size. The checks above ensure we have room to do this. + splitCoord += (navgenparams->generation_step_size - splitLen) * ( ( ( dirFromAboveToBelow == NORTH ) || ( dirFromAboveToBelow == WEST ) ) ? -1 : 1 ); } @@ -2587,10 +2587,10 @@ static bool TestForValidCrouchArea( CNavNode *node ) // the node for a HumanCrouchHeight space. trace_t tr; Vector end( *node->GetPosition() ); - end.z += JumpCrouchHeight; + end.z += navgenparams->human_crouch_height; CTraceFilterWalkableEntities filter(nullptr, COLLISION_GROUP_PLAYER_MOVEMENT, WALK_THRU_EVERYTHING); - trace::hull(*node->GetPosition(), end, Vector(0.0f, 0.0f, 0.0f), Vector(GenerationStepSize, GenerationStepSize, HumanCrouchHeight), + trace::hull(*node->GetPosition(), end, Vector(0.0f, 0.0f, 0.0f), Vector(navgenparams->generation_step_size, navgenparams->generation_step_size, navgenparams->human_crouch_height), TheNavMesh->GetGenerationTraceMask(), &filter, tr); @@ -2605,15 +2605,15 @@ static bool TestForValidCrouchArea( CNavNode *node ) bool IsHeightDifferenceValid( float test, float other1, float other2, float other3 ) { // Make sure the other nodes are level. - const float CloseDelta = StepHeight / 2; + const float CloseDelta = navgenparams->step_height / 2; return fabs( other1 - other2 ) > CloseDelta || fabs( other1 - other3 ) > CloseDelta || fabs( other2 - other3 ) > CloseDelta - // Now make sure the test node is near the others. If it is more than StepHeight away, + // Now make sure the test node is near the others. If it is more than navgenparams->step_height away, // it'll form a distorted jump area. - || (fabs(test - other1) <= StepHeight - && fabs(test - other2) <= StepHeight - && fabs(test - other3) <= StepHeight); + || (fabs(test - other1) <= navgenparams->step_height + && fabs(test - other2) <= navgenparams->step_height + && fabs(test - other3) <= navgenparams->step_height); } @@ -2715,18 +2715,18 @@ class TestOverlapping CNavLadder *overlappingLadder = NULL; Vector start = m_nw; - m_nw.x += GenerationStepSize/2; - m_nw.y += GenerationStepSize/2; + m_nw.x += navgenparams->generation_step_size/2; + m_nw.y += navgenparams->generation_step_size/2; while ( start.x < m_se.x ) { - start.y = m_nw.y + GenerationStepSize/2; + start.y = m_nw.y + navgenparams->generation_step_size/2; while ( start.y < m_se.y ) { start.z = GetZ( start ); Vector end = start; - start.z -= StepHeight; - end.z += HalfHumanHeight; + start.z -= navgenparams->step_height; + end.z += navgenparams->human_height; if ( TheNavMesh->FindNavAreaOrLadderAlongRay( start, end, &overlappingArea, &overlappingLadder, NULL ) && overlappingArea ) @@ -2734,9 +2734,9 @@ class TestOverlapping return true; } - start.y += GenerationStepSize; + start.y += navgenparams->generation_step_size; } - start.x += GenerationStepSize; + start.x += navgenparams->generation_step_size; } return false; } @@ -3748,11 +3748,11 @@ bool CNavMesh::UpdateGeneration( float maxTime ) float height; if ( GetGroundHeight( eyePos, &height ) ) { - eyePos.z = height + HalfHumanHeight - StepHeight; // players light from their centers, and we light from slightly below that, to allow for low ceilings + eyePos.z = height + navgenparams->human_height - navgenparams->step_height; // players light from their centers, and we light from slightly below that, to allow for low ceilings } else { - eyePos.z += HalfHumanHeight - StepHeight; // players light from their centers, and we light from slightly below that, to allow for low ceilings + eyePos.z += navgenparams->human_height - navgenparams->step_height; // players light from their centers, and we light from slightly below that, to allow for low ceilings } // TODO: host->SetAbsOrigin( eyePos ); @@ -3917,7 +3917,7 @@ CNavNode *CNavMesh::AddNode( const Vector &destPos, const Vector &normal, NavDir obstacleHeight = MAX( obstacleHeight + deltaZ, 0 ); Assert( obstacleHeight > 0 ); } - node->ConnectTo( source, OppositeDirection( dir ), obstacleHeight, GenerationStepSize - obstacleEndDist, GenerationStepSize - obstacleStartDist ); + node->ConnectTo( source, OppositeDirection( dir ), obstacleHeight, navgenparams->generation_step_size - obstacleEndDist, navgenparams->generation_step_size - obstacleStartDist ); node->MarkAsVisited( OppositeDirection( dir ) ); } @@ -3935,7 +3935,7 @@ CNavNode *CNavMesh::AddNode( const Vector &destPos, const Vector &normal, NavDir inline CNavNode *LadderEndSearch( const Vector *pos, NavDirType mountDir ) { Vector center = *pos; - AddDirectionVector( ¢er, mountDir, HalfHumanWidth ); + AddDirectionVector( ¢er, mountDir, navgenparams->half_human_width ); // // Test the ladder dismount point first, then each cardinal direction one and two steps away @@ -3945,12 +3945,12 @@ inline CNavNode *LadderEndSearch( const Vector *pos, NavDirType mountDir ) Vector tryPos = center; if (d >= NUM_DIRECTIONS) - AddDirectionVector( &tryPos, (NavDirType)(d - NUM_DIRECTIONS), 2.0f*GenerationStepSize ); + AddDirectionVector( &tryPos, (NavDirType)(d - NUM_DIRECTIONS), 2.0f*navgenparams->generation_step_size ); else if (d >= 0) - AddDirectionVector( &tryPos, (NavDirType)d, GenerationStepSize ); + AddDirectionVector( &tryPos, (NavDirType)d, navgenparams->generation_step_size ); // step up a rung, to ensure adjacent floors are below us - tryPos.z += GenerationStepSize; + tryPos.z += navgenparams->generation_step_size; tryPos.x = TheNavMesh->SnapToGrid( tryPos.x ); tryPos.y = TheNavMesh->SnapToGrid( tryPos.y ); @@ -3985,11 +3985,11 @@ bool CNavMesh::FindGroundForNode( Vector *pos, Vector *normal ) const { trace_t tr; Vector end( *pos ); - end.z -= DeathDrop; + end.z -= navgenparams->death_drop; CTraceFilterWalkableEntities filter(nullptr, COLLISION_GROUP_PLAYER_MOVEMENT, WALK_THRU_EVERYTHING); - trace::hull(Vector(pos->x, pos->y, pos->z + HalfHumanHeight - 0.1f), end, NavTraceMins, NavTraceMaxs, GetGenerationTraceMask(), &filter, tr); + trace::hull(Vector(pos->x, pos->y, pos->z + navgenparams->human_height - 0.1f), end, NavTraceMins, NavTraceMaxs, GetGenerationTraceMask(), &filter, tr); *pos = tr.endpos; *normal = tr.plane.normal; @@ -4058,7 +4058,7 @@ bool TraceAdjacentNode( int depth, const Vector& start, const Vector& end, trace // Try to go up as if we stepped up, forward, and down. Vector testEnd( trace->endpos ); - testEnd.z += StepHeight; + testEnd.z += navgenparams->step_height; trace::hull(trace->endpos, testEnd, NavTraceMins, NavTraceMaxs, TheNavMesh->GetGenerationTraceMask(), &filter, *trace); DrawTrace( trace ); @@ -4071,17 +4071,17 @@ bool TraceAdjacentNode( int depth, const Vector& start, const Vector& end, trace //-------------------------------------------------------------------------------------------------------- static bool IsNodeOverlapped( const Vector& pos, const Vector& offset ) { - bool overlap = TheNavMesh->GetNavArea( pos + offset, HumanHeight ) != NULL; + bool overlap = TheNavMesh->GetNavArea( pos + offset, navgenparams->human_height ) != NULL; if ( !overlap ) { Vector mins( -0.5f, -0.5f, -0.5f ); Vector maxs( 0.5f, 0.5f, 0.5f ); Vector start = pos; - start.z += HalfHumanHeight; + start.z += navgenparams->human_height; Vector end = start; - end.x += offset.x * GenerationStepSize; - end.y += offset.y * GenerationStepSize; + end.x += offset.x * navgenparams->generation_step_size; + end.y += offset.y * navgenparams->generation_step_size; trace_t trace; CTraceFilterWalkableEntities filter( nullptr, COLLISION_GROUP_NONE, WALK_THRU_EVERYTHING ); trace::hull(start, end, mins, maxs, TheNavMesh->GetGenerationTraceMask(), &filter, trace); @@ -4092,7 +4092,7 @@ static bool IsNodeOverlapped( const Vector& pos, const Vector& offset ) } start = trace.endpos; - end.z -= HalfHumanHeight * 2; + end.z -= navgenparams->human_height * 2; trace::hull(start, end, mins, maxs, TheNavMesh->GetGenerationTraceMask(), &filter, trace); if ( trace.startsolid || trace.allsolid || trace.fraction == 1.0f @@ -4171,10 +4171,10 @@ bool CNavMesh::SampleStep( void ) // attempt to move to adjacent node switch( dir ) { - case NORTH: cy -= GenerationStepSize; break; - case SOUTH: cy += GenerationStepSize; break; - case EAST: cx += GenerationStepSize; break; - case WEST: cx -= GenerationStepSize; break; + case NORTH: cy -= navgenparams->generation_step_size; break; + case SOUTH: cy += navgenparams->generation_step_size; break; + case EAST: cx += navgenparams->generation_step_size; break; + case WEST: cx -= navgenparams->generation_step_size; break; } pos.x = cx; @@ -4216,7 +4216,7 @@ bool CNavMesh::SampleStep( void ) Vector from( *m_currentNode->GetPosition() ); CTraceFilterWalkableEntities filter(nullptr, COLLISION_GROUP_NONE, WALK_THRU_EVERYTHING); Vector to, toNormal; - float obstacleHeight = 0, obstacleStartDist = 0, obstacleEndDist = GenerationStepSize; + float obstacleHeight = 0, obstacleStartDist = 0, obstacleEndDist = navgenparams->generation_step_size; if ( TraceAdjacentNode( 0, from, pos, &result ) ) { to = result.endpos; @@ -4226,7 +4226,7 @@ bool CNavMesh::SampleStep( void ) { // test going up ClimbUpHeight bool success = false; - for ( float height = StepHeight; height <= ClimbUpHeight; height += 1.0f ) + for ( float height = navgenparams->step_height; height <= navgenparams->climb_up_height; height += 1.0f ) { trace_t tr; Vector start( from ); @@ -4262,16 +4262,16 @@ bool CNavMesh::SampleStep( void ) // Could not trace from node to node at this height, something is in the way. // Trace in the other direction to see if we hit something Vector vecToObstacleStart = tr.endpos - start; - Assert( vecToObstacleStart.LengthSqr() <= Square( GenerationStepSize ) ); - if ( vecToObstacleStart.LengthSqr() <= Square( GenerationStepSize ) ) + + if ( vecToObstacleStart.LengthSqr() <= Square( navgenparams->generation_step_size ) ) { trace::hull(start, end, NavTraceMins, NavTraceMaxs, GetGenerationTraceMask(), &filter, tr); if ( !tr.startsolid && tr.fraction < 1.0 ) { // We hit something going the other direction. There is some obstacle between the two nodes. Vector vecToObstacleEnd = tr.endpos - start; - Assert( vecToObstacleEnd.LengthSqr() <= Square( GenerationStepSize ) ); - if ( vecToObstacleEnd.LengthSqr() <= Square( GenerationStepSize ) ) + + if ( vecToObstacleEnd.LengthSqr() <= Square( navgenparams->generation_step_size ) ) { // Remember the distances to start and end of the obstacle (with respect to the "from" node). // Keep track of the last distances to obstacle as we keep increasing the height we do a trace for. @@ -4281,7 +4281,7 @@ bool CNavMesh::SampleStep( void ) obstacleEndDist = vecToObstacleEnd.Length(); if ( obstacleEndDist == 0 ) { - obstacleEndDist = GenerationStepSize; + obstacleEndDist = navgenparams->generation_step_size; } } } @@ -4303,10 +4303,10 @@ bool CNavMesh::SampleStep( void ) // If we're incrementally generating, don't overlap existing nav areas. Vector testPos( to ); - if ( IsNodeOverlapped( testPos, Vector( 1, 1, HalfHumanHeight ) ) - && IsNodeOverlapped( testPos, Vector( -1, 1, HalfHumanHeight ) ) - && IsNodeOverlapped( testPos, Vector( 1, -1, HalfHumanHeight ) ) - && IsNodeOverlapped( testPos, Vector( -1, -1, HalfHumanHeight ) ) + if ( IsNodeOverlapped( testPos, Vector( 1, 1, navgenparams->human_height ) ) + && IsNodeOverlapped( testPos, Vector( -1, 1, navgenparams->human_height ) ) + && IsNodeOverlapped( testPos, Vector( 1, -1, navgenparams->human_height ) ) + && IsNodeOverlapped( testPos, Vector( -1, -1, navgenparams->human_height ) ) && m_generationMode != GENERATE_SIMPLIFY ) { return true; @@ -4348,8 +4348,8 @@ bool CNavMesh::SampleStep( void ) { trace::hull(result.endpos, to, NavTraceMins, NavTraceMaxs, GetGenerationTraceMask(), &filter, result); if ( result.fraction < 1 - // if we made it down to within StepHeight, maybe we're on a static prop - && result.endpos.z > to.z + StepHeight ) + // if we made it down to within navgenparams->step_height, maybe we're on a static prop + && result.endpos.z > to.z + navgenparams->step_height ) { return true; } @@ -4364,7 +4364,7 @@ bool CNavMesh::SampleStep( void ) { obstacleHeight = 0; obstacleStartDist = 0; - obstacleEndDist = GenerationStepSize; + obstacleEndDist = navgenparams->generation_step_size; } // we can move here @@ -4391,8 +4391,8 @@ void CNavMesh::AddWalkableSeed( const Vector &pos, const Vector &normal ) { WalkableSeedSpot seed; - seed.pos.x = RoundToUnits( pos.x, GenerationStepSize ); - seed.pos.y = RoundToUnits( pos.y, GenerationStepSize ); + seed.pos.x = RoundToUnits( pos.x, navgenparams->generation_step_size ); + seed.pos.y = RoundToUnits( pos.y, navgenparams->generation_step_size ); seed.pos.z = pos.z; seed.normal = normal; @@ -4477,7 +4477,7 @@ class Subdivider float split = area->GetSizeX() / 2.0f; - if (split < GenerationStepSize) + if (split < navgenparams->generation_step_size) { if (canDivideY) { @@ -4506,7 +4506,7 @@ class Subdivider float split = area->GetSizeY() / 2.0f; - if (split < GenerationStepSize) + if (split < navgenparams->generation_step_size) { if (canDivideX) { diff --git a/extension/navmesh/nav_ladder.cpp b/extension/navmesh/nav_ladder.cpp index 4658971..f51e990 100644 --- a/extension/navmesh/nav_ladder.cpp +++ b/extension/navmesh/nav_ladder.cpp @@ -95,7 +95,7 @@ void CNavLadder::ConnectTo( CNavArea *area ) newconnect.point.y = m_top.y; Vector close; area->GetClosestPointOnArea(m_top, &close); - newconnect.point.z = close.z + (StepHeight / 2.0f); + newconnect.point.z = close.z + (navgenparams->step_height / 2.0f); if (newconnect.point.z > m_top.z) { @@ -110,7 +110,7 @@ void CNavLadder::ConnectTo( CNavArea *area ) newconnect.point.y = m_bottom.y; Vector close; area->GetClosestPointOnArea(m_bottom, &close); - newconnect.point.z = close.z + (StepHeight / 2.0f); + newconnect.point.z = close.z + (navgenparams->step_height / 2.0f); if (newconnect.point.z < m_bottom.z) { @@ -333,8 +333,8 @@ void CNavLadder::DrawLadder( bool isSelected, bool isMarked, bool isEdit ) cons while ( bottomRight.z < topRight.z ) { NavDrawLine( bottomRight, bottomLeft, ladderColor ); - bottomRight += up * (GenerationStepSize/2); - bottomLeft += up * (GenerationStepSize/2); + bottomRight += up * (navgenparams->generation_step_size/2); + bottomLeft += up * (navgenparams->generation_step_size/2); } if (m_ladderType == USEABLE_LADDER) @@ -426,8 +426,8 @@ void CNavLadder::BuildUseableLadder(CBaseEntity* ladder) m_top = topPosition; m_bottom = bottomPosition; - m_top.z += StepHeight; - m_bottom.z += (StepHeight / 2.0f); + m_top.z += navgenparams->step_height; + m_bottom.z += (navgenparams->step_height / 2.0f); m_length = fabsf(topPosition.z - bottomPosition.z); m_width = 24.0f; // temporary, player hull width UpdateUseableLadderDir(NORTH); @@ -692,10 +692,10 @@ class IsLadderFreeFunctor // player is on a ladder - is it this one? const Vector& feet = player.GetAbsOrigin(); - if (feet.z > m_ladder->m_top.z + HalfHumanHeight) + if (feet.z > m_ladder->m_top.z + navgenparams->human_height) return true; - if (feet.z + HumanHeight < m_ladder->m_bottom.z - HalfHumanHeight) + if (feet.z + navgenparams->human_height < m_ladder->m_bottom.z - navgenparams->human_height) return true; Vector2D away(m_ladder->m_bottom.x - feet.x, m_ladder->m_bottom.y - feet.y); diff --git a/extension/navmesh/nav_mesh.cpp b/extension/navmesh/nav_mesh.cpp index eca07ca..f3d7497 100644 --- a/extension/navmesh/nav_mesh.cpp +++ b/extension/navmesh/nav_mesh.cpp @@ -907,11 +907,11 @@ CNavArea *CNavMesh::GetNavArea( edict_t *pEntity, int nFlags, float flBeneathLim if ( pLastNavArea && pLastNavArea->IsOverlapping( testPos ) ) { float flZ = pLastNavArea->GetZ( testPos ); - if ( ( flZ <= testPos.z + StepHeight ) && ( flZ >= testPos.z - StepHeight ) ) + if ( ( flZ <= testPos.z + navgenparams->step_height ) && ( flZ >= testPos.z - navgenparams->step_height ) ) return pLastNavArea; } */ - flStepHeight = StepHeight; + flStepHeight = navgenparams->step_height; } // get list in cell that contains position @@ -1005,7 +1005,7 @@ CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, float maxDist, bool ch } } - source.z += HalfHumanHeight; + source.z += navgenparams->human_height; // find closest nav area @@ -1063,7 +1063,7 @@ CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, float maxDist, bool ch // don't consider blocked areas || area->IsBlocked( team ) // don't consider area that is overhead - || area->GetCenter().z - pos.z > HumanHeight) + || area->GetCenter().z - pos.z > navgenparams->human_height) continue; // mark as visited @@ -1089,18 +1089,18 @@ CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, float maxDist, bool ch trace_t result; // make sure 'pos' is not embedded in the world - trace::line(pos, pos + Vector(0, 0, StepHeight), MASK_NPCSOLID_BRUSHONLY, nullptr, COLLISION_GROUP_NONE, result); + trace::line(pos, pos + Vector(0, 0, navgenparams->step_height), MASK_NPCSOLID_BRUSHONLY, nullptr, COLLISION_GROUP_NONE, result); // it was embedded - move it out Vector safePos = result.startsolid ? result.endpos + Vector( 0, 0, 1.0f ) : pos; - // Don't bother tracing from the nav area up to safePos.z if it's within StepHeight of the area, since areas can be embedded in the ground a bit + // Don't bother tracing from the nav area up to safePos.z if it's within navgenparams->step_height of the area, since areas can be embedded in the ground a bit float heightDelta = fabs(areaPos.z - safePos.z); - if ( heightDelta > StepHeight ) + if ( heightDelta > navgenparams->step_height ) { // trace to the height of the original point - trace::line(areaPos + Vector(0, 0, StepHeight), Vector(areaPos.x, areaPos.y, safePos.z), MASK_NPCSOLID_BRUSHONLY, nullptr, COLLISION_GROUP_NONE, result); + trace::line(areaPos + Vector(0, 0, navgenparams->step_height), Vector(areaPos.x, areaPos.y, safePos.z), MASK_NPCSOLID_BRUSHONLY, nullptr, COLLISION_GROUP_NONE, result); if ( result.fraction != 1.0f ) { @@ -1109,7 +1109,7 @@ CNavArea *CNavMesh::GetNearestNavArea( const Vector &pos, float maxDist, bool ch } // trace to the original point's height above the area - trace::line(safePos, Vector(areaPos.x, areaPos.y, safePos.z + StepHeight), MASK_NPCSOLID_BRUSHONLY, nullptr, COLLISION_GROUP_NONE, result); + trace::line(safePos, Vector(areaPos.x, areaPos.y, safePos.z + navgenparams->step_height), MASK_NPCSOLID_BRUSHONLY, nullptr, COLLISION_GROUP_NONE, result); if ( result.fraction != 1.0f ) { @@ -1496,13 +1496,13 @@ bool CNavMesh::GetGroundHeight( const Vector &pos, float *height, Vector *normal trace_t result; Vector to( pos.x, pos.y, pos.z - 10000.0f ); - Vector from( pos.x, pos.y, pos.z + HalfHumanHeight + 1e-3 ); + Vector from( pos.x, pos.y, pos.z + navgenparams->human_height + 1e-3 ); while( to.z - pos.z < flMaxOffset ) { trace::line(from, to, MASK_NPCSOLID_BRUSHONLY, &filter, result); - if (!result.startsolid && ((result.fraction == 1.0f) || ((from.z - result.endpos.z) >= HalfHumanHeight))) + if (!result.startsolid && ((result.fraction == 1.0f) || ((from.z - result.endpos.z) >= navgenparams->human_height))) { *height = result.endpos.z; @@ -1515,7 +1515,7 @@ bool CNavMesh::GetGroundHeight( const Vector &pos, float *height, Vector *normal } to.z = ( result.startsolid ) ? from.z : result.endpos.z; - from.z = to.z + HalfHumanHeight + 1e-3; + from.z = to.z + navgenparams->human_height + 1e-3; } *height = 0.0f; @@ -3268,7 +3268,7 @@ void HidingSpot::Load(std::fstream& filestream, uint32_t version) NavErrorType HidingSpot::PostLoad( void ) { // set our area - m_area = TheNavMesh->GetNavArea( m_pos + Vector( 0, 0, HalfHumanHeight ) ); + m_area = TheNavMesh->GetNavArea( m_pos + Vector( 0, 0, navgenparams->human_height ) ); if ( !m_area ) { diff --git a/extension/navmesh/nav_node.cpp b/extension/navmesh/nav_node.cpp index d76016c..83ceb76 100644 --- a/extension/navmesh/nav_node.cpp +++ b/extension/navmesh/nav_node.cpp @@ -353,7 +353,7 @@ float CNavNode::GetGroundHeightAboveNode( NavCornerType cornerType ) const //-------------------------------------------------------------------------------------------------------------- /** - * Look up to JumpCrouchHeight in the air to see if we can fit a whole HumanHeight box + * Look up to JumpCrouchHeight in the air to see if we can fit a whole navgenparams->human_height box */ bool CNavNode::TestForCrouchArea( NavCornerType cornerNum, const Vector& mins, const Vector& maxs, float *groundHeightAboveNode ) { @@ -362,7 +362,7 @@ bool CNavNode::TestForCrouchArea( NavCornerType cornerNum, const Vector& mins, c Vector start( m_pos ); Vector end( start ); - end.z += JumpCrouchHeight; + end.z += navgenparams->jump_crouch_height; trace::hull(start, end, NavTraceMins, NavTraceMaxs, MASK_NPCSOLID_BRUSHONLY, &filter, tr); float maxHeight = tr.endpos.z - start.z; @@ -374,7 +374,7 @@ bool CNavNode::TestForCrouchArea( NavCornerType cornerNum, const Vector& mins, c start = m_pos; start.z += height; - realMaxs.z = HumanCrouchHeight; + realMaxs.z = navgenparams->human_crouch_height; trace::hull(start, start, mins, realMaxs, MASK_NPCSOLID_BRUSHONLY, &filter, tr); @@ -383,7 +383,7 @@ bool CNavNode::TestForCrouchArea( NavCornerType cornerNum, const Vector& mins, c *groundHeightAboveNode = start.z - m_pos.z; // We found a crouch-sized space. See if we can stand up. - realMaxs.z = HumanHeight; + realMaxs.z = navgenparams->human_height; trace::hull(start, start, mins, realMaxs, MASK_NPCSOLID_BRUSHONLY, &filter, tr); @@ -411,7 +411,7 @@ bool CNavNode::TestForCrouchArea( NavCornerType cornerNum, const Vector& mins, c } } - *groundHeightAboveNode = JumpCrouchHeight; + *groundHeightAboveNode = navgenparams->jump_crouch_height; m_isBlocked[ cornerNum ] = true; return false; } @@ -432,26 +432,26 @@ void CNavNode::CheckCrouch( void ) Vector2D cornerVec; CornerToVector2D( corner, &cornerVec ); - // Build a mins/maxs pair for the HumanWidth x HalfHumanWidth box facing the appropriate direction + // Build a mins/maxs pair for the HumanWidth x navgenparams->half_human_width box facing the appropriate direction Vector mins( 0, 0, 0 ); Vector maxs( 0, 0, 0 ); if ( cornerVec.x < 0 ) { - mins.x = -HalfHumanWidth; + mins.x = -navgenparams->half_human_width; } else if ( cornerVec.x > 0 ) { - maxs.x = HalfHumanWidth; + maxs.x = navgenparams->half_human_width; } if ( cornerVec.y < 0 ) { - mins.y = -HalfHumanWidth; + mins.y = -navgenparams->half_human_width; } else if ( cornerVec.y > 0 ) { - maxs.y = HalfHumanWidth; + maxs.y = navgenparams->half_human_width; } - maxs.z = HumanHeight; + maxs.z = navgenparams->human_height; // now make sure that mins is smaller than maxs for ( int j=0; j<3; ++j ) @@ -479,10 +479,6 @@ void CNavNode::CheckCrouch( void ) */ void CNavNode::ConnectTo( CNavNode *node, NavDirType dir, float obstacleHeight, float obstacleStartDist, float obstacleEndDist ) { - Assert( obstacleStartDist >= 0 && obstacleStartDist <= GenerationStepSize ); - Assert( obstacleEndDist >= 0 && obstacleStartDist <= GenerationStepSize ); - Assert( obstacleStartDist < obstacleEndDist ); - m_to[ dir ] = node; m_obstacleHeight[ dir ] = obstacleHeight; m_obstacleStartDist[ dir ] = obstacleStartDist; @@ -496,7 +492,7 @@ void CNavNode::ConnectTo( CNavNode *node, NavDirType dir, float obstacleHeight, */ CNavNode *CNavNode::GetNode( const Vector &pos ) { - const float tolerance = 0.45f * GenerationStepSize; // 1.0f + const float tolerance = 0.45f * navgenparams->generation_step_size; // 1.0f CNavNode *pNode = NULL; if ( g_pNavNodeHash ) { diff --git a/extension/navmesh/nav_params.cpp b/extension/navmesh/nav_params.cpp new file mode 100644 index 0000000..3d72807 --- /dev/null +++ b/extension/navmesh/nav_params.cpp @@ -0,0 +1,25 @@ +#include "nav.h" + +// Default values goes here. +// From: https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/game/server/nav.h +// DO NOT IFDEF HERE! +// Override these values at the mod's specific NavMesh constructor + +CNavMeshGeneratorParameters::CNavMeshGeneratorParameters() +{ + generation_step_size = 25.0f; + jump_height = 41.8f; + jump_crouch_height = 64.0f; + step_height = 18.0f; + death_drop = 400.0f; + climb_up_height = 64.0f; + half_human_width = 16.0f; + half_human_height = 35.5f; + human_height = 71.0f; + human_eye_height = 62.0f; + human_crouch_height = 55.0f; + human_crouch_eye_height = 37.0f; +} + +static CNavMeshGeneratorParameters s_navgenparams; +CNavMeshGeneratorParameters* navgenparams = &s_navgenparams; \ No newline at end of file diff --git a/extension/navmesh/nav_pathfind.h b/extension/navmesh/nav_pathfind.h index 96d751d..094132d 100644 --- a/extension/navmesh/nav_pathfind.h +++ b/extension/navmesh/nav_pathfind.h @@ -840,7 +840,7 @@ inline void SearchSurroundingAreas( CNavArea *startArea, ISearchSurroundingAreas * Areas in the collection will be "marked", returning true for IsMarked(). * Each area in the collection's GetCostSoFar() will be approximate travel distance from 'startArea'. */ -inline void CollectSurroundingAreas( CUtlVector< CNavArea * > *nearbyAreaVector, CNavArea *startArea, float travelDistanceLimit = 1500.0f, float maxStepUpLimit = StepHeight, float maxDropDownLimit = 100.0f ) +inline void CollectSurroundingAreas( CUtlVector< CNavArea * > *nearbyAreaVector, CNavArea *startArea, float travelDistanceLimit = 1500.0f, float maxStepUpLimit = navgenparams->step_height, float maxDropDownLimit = 100.0f ) { nearbyAreaVector->RemoveAll(); @@ -1070,7 +1070,7 @@ void SelectSeparatedShuffleSet( int maxCount, float minSeparation, const CUtlVec T *area = shuffledVector[i]; CUtlVector< CNavArea * > nearVector; - CollectSurroundingAreas( &nearVector, area, minSeparation, 2.0f * StepHeight, 2.0f * StepHeight ); + CollectSurroundingAreas( &nearVector, area, minSeparation, 2.0f * navgenparams->step_height, 2.0f * navgenparams->step_height ); for( j=0; j GenerationStepSize ) + if ( sizeX > navgenparams->generation_step_size ) { - splitEdge = RoundToUnits( area->GetCorner( NORTH_WEST ).x, GenerationStepSize ); + splitEdge = RoundToUnits( area->GetCorner( NORTH_WEST ).x, navgenparams->generation_step_size ); if ( splitEdge < area->GetCorner( NORTH_WEST ).x + minSplitSize ) - splitEdge += GenerationStepSize; + splitEdge += navgenparams->generation_step_size; splitAlongX = false; didSplit = area->SplitEdit( splitAlongX, splitEdge, &first, &second ); } - if ( sizeY > GenerationStepSize ) + if ( sizeY > navgenparams->generation_step_size ) { - splitEdge = RoundToUnits( area->GetCorner( NORTH_WEST ).y, GenerationStepSize ); + splitEdge = RoundToUnits( area->GetCorner( NORTH_WEST ).y, navgenparams->generation_step_size ); if ( splitEdge < area->GetCorner( NORTH_WEST ).y + minSplitSize ) - splitEdge += GenerationStepSize; + splitEdge += navgenparams->generation_step_size; splitAlongX = true; if ( didSplit ) @@ -171,8 +171,8 @@ void CNavMesh::SimplifySelectedAreas( void ) Extent areaExtent; CNavArea *area = collector.m_area[i]; area->GetExtent( &areaExtent ); - areaExtent.lo.z -= HalfHumanHeight; - areaExtent.hi.z += 2 * HumanHeight; + areaExtent.lo.z -= navgenparams->human_height; + areaExtent.hi.z += 2 * navgenparams->human_height; bounds.Encompass( areaExtent ); Vector center = area->GetCenter(); @@ -184,7 +184,7 @@ void CNavMesh::SimplifySelectedAreas( void ) { AddWalkableSeed( center, normal ); - center.z += HumanHeight; + center.z += navgenparams->human_height; bounds.Encompass( center ); } } diff --git a/extension/navmesh/nav_waypoint.cpp b/extension/navmesh/nav_waypoint.cpp index d4a2ccf..5343fd8 100644 --- a/extension/navmesh/nav_waypoint.cpp +++ b/extension/navmesh/nav_waypoint.cpp @@ -197,7 +197,7 @@ void CWaypoint::Draw() const Vector mins{ -m_radius, -m_radius, 0.0f }; Vector maxs{ m_radius, m_radius, CWaypoint::WAYPOINT_HEIGHT }; - NDebugOverlay::Box(m_origin, mins, maxs, r, g, b, 150, NDEBUG_PERSIST_FOR_ONE_TICK); + NDebugOverlay::Box(m_origin, mins, maxs, r, g, b, 90, NDEBUG_PERSIST_FOR_ONE_TICK); } Vector cStart = m_origin + Vector(0.0f, 0.0f, CWaypoint::WAYPOINT_CONNECT_HEIGHT);