//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CNPC_VehicleDriver::PrescheduleThink( void ) { if ( !m_hVehicleEntity ) { m_pVehicleInterface = NULL; UTIL_Remove( this ); return; } // Keep up with my vehicle SetAbsOrigin( m_hVehicleEntity->WorldSpaceCenter() ); SetAbsAngles( m_hVehicleEntity->GetAbsAngles() ); BaseClass::PrescheduleThink(); if ( m_NPCState == NPC_STATE_IDLE ) { m_pVehicleInterface->NPC_Brake(); return; } // If we've been picked up by something (dropship probably), abort. if ( m_hVehicleEntity->GetParent() ) { SetState( NPC_STATE_IDLE ); ClearWaypoints(); SetGoalEnt( NULL ); return; } DriveVehicle(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CNPC_VehicleDriver::InputGotoPathCorner( inputdata_t &inputdata ) { string_t iszPathName = inputdata.value.StringID(); if ( iszPathName != NULL_STRING ) { CBaseEntity *pEntity = gEntList.FindEntityByName( NULL, iszPathName ); if ( !pEntity ) { Warning("npc_vehicledriver %s couldn't find entity named %s\n", STRING(GetEntityName()), STRING(iszPathName) ); return; } ClearWaypoints(); // Drive to the point SetGoalEnt( pEntity ); if ( m_NPCState == NPC_STATE_IDLE ) { SetState( NPC_STATE_ALERT ); } SetCondition( COND_PROVOKED ); // Force him to start forward InputStartForward( inputdata ); } }
//----------------------------------------------------------------------------- // Purpose: Check to see if we should teleport to the current path corner //----------------------------------------------------------------------------- void CNPC_VehicleDriver::CheckForTeleport( void ) { if ( !GetGoalEnt() ) return; CPathTrack *pTrack = dynamic_cast<CPathTrack *>( GetGoalEnt() ); if ( !pTrack ) return; // Does it have the teleport flag set? if ( pTrack->HasSpawnFlags( SF_PATH_TELEPORT ) ) { AddEffects( EF_NOINTERP ); // Teleport the vehicle to the pathcorner Vector vecMins, vecMaxs; vecMins = m_hVehicleEntity->CollisionProp()->OBBMins(); vecMaxs = m_hVehicleEntity->CollisionProp()->OBBMaxs(); Vector vecTarget = pTrack->GetAbsOrigin() - (vecMins + vecMaxs) * 0.5; vecTarget.z += ((vecMaxs.z - vecMins.z) * 0.5) + 8; // Safety buffer // Orient it to face the next point QAngle vecAngles = pTrack->GetAbsAngles(); Vector vecToTarget = vec3_origin; if ( pTrack->GetNext() ) { vecToTarget = (pTrack->GetNext()->GetAbsOrigin() - pTrack->GetAbsOrigin()); VectorNormalize( vecToTarget ); // Vehicles are rotated 90 degrees VectorAngles( vecToTarget, vecAngles ); vecAngles[YAW] -= 90; } m_hVehicleEntity->Teleport( &vecTarget, &vecAngles, &vec3_origin ); // Teleport the driver SetAbsOrigin( m_hVehicleEntity->WorldSpaceCenter() ); SetAbsAngles( m_hVehicleEntity->GetAbsAngles() ); m_vecPrevPoint = pTrack->GetAbsOrigin(); // Move to the next waypoint, we've reached this one if ( GetNavigator()->GetPath() ) { WaypointReached(); } // Clear our waypoints, because the next waypoint is certainly invalid now. ClearWaypoints(); } }
void Drawing::RemoveWaypoints(Waypoint points[], size_t numPoints) { // Build a list of indices of waypoints we should delete. size_t delPoints[WAYPOINT_MAX]; size_t delPointsCur = 0; for (size_t i = 0; i < numPoints; ++i) { Waypoint p = points[i]; for (size_t j = 0; j < numWaypoints; ++j) { Waypoint q = waypoints[j]; if (p.latitude == q.latitude && p.longitude == q.longitude && p.altitude == q.altitude) { delPoints[delPointsCur++] = j; break; } } } // Sort the indices so that we only have to iterate them once qsort(delPoints, delPointsCur, sizeof(size_t), cmp); // Copy the new array on top of the old array size_t copyCur = 0; size_t count = delPointsCur; delPointsCur = 0; for (size_t i = 0; i < numWaypoints; ++i) { if (i == delPoints[delPointsCur]) { ++delPointsCur; continue; } waypoints[copyCur++] = waypoints[i]; } numWaypoints -= count; if (numWaypoints == 0) { ClearWaypoints(); } }
void WP_command( int argc ) { char cmd_command[1024]; if( argc < 3) return; trap_CmdArgv( 2, cmd_command, sizeof( cmd_command ) ); if(!strcmp(cmd_command, "add")) { waypoint_t wp; if( argc < 7 ) return; memset(&wp, 0 ,sizeof(wp)); trap_CmdArgv( 3, cmd_command, sizeof( cmd_command ) ); wp.index = atoi( cmd_command ); trap_CmdArgv( 4, cmd_command, sizeof( cmd_command ) ); wp.origin[0] = atof( cmd_command ); trap_CmdArgv( 5, cmd_command, sizeof( cmd_command ) ); wp.origin[1] = atof( cmd_command ); trap_CmdArgv( 6, cmd_command, sizeof( cmd_command ) ); wp.origin[2] = atof( cmd_command ); wp.teams = 15 ;// (1<<0)+(1<<1)+(1<<2)+(1<<3); if( argc > 7 ) { trap_CmdArgv( 7, cmd_command, sizeof( cmd_command ) ); wp.flags = atoi( cmd_command ); } if( argc > 8 ) { trap_CmdArgv( 8, cmd_command, sizeof( cmd_command ) ); wp.teams = atoi( cmd_command ); } if( argc > 9 ) { trap_CmdArgv( 9, cmd_command, sizeof( cmd_command ) ); wp.radius = atof( cmd_command ); } AddWaypoint(&wp); return; } if(!strcmp(cmd_command, "link")) { wp_link_t link; int i1,i2; if( argc < 5 ) return; memset(&link, 0 ,sizeof(link)); trap_CmdArgv( 3, cmd_command, sizeof( cmd_command ) ); i1 = atoi( cmd_command ); trap_CmdArgv( 4, cmd_command, sizeof( cmd_command ) ); i2 = atoi( cmd_command ); link.teams = 15; if( argc > 5 ) { trap_CmdArgv( 5, cmd_command, sizeof( cmd_command ) ); link.flags = atoi( cmd_command ); } if( argc > 6 ) { trap_CmdArgv( 6, cmd_command, sizeof( cmd_command ) ); link.teams = atoi( cmd_command ); } if( argc > 7 ) { trap_CmdArgv( 7, cmd_command, sizeof( cmd_command ) ); link.req_velocity = atof( cmd_command ); } AddLink( i1, i2, &link); return; } if(!strcmp(cmd_command, "dlink")) { wp_link_t link; int i1,i2; if( argc < 5 ) return; memset(&link, 0 ,sizeof(link)); trap_CmdArgv( 3, cmd_command, sizeof( cmd_command ) ); i1 = atoi( cmd_command ); trap_CmdArgv( 4, cmd_command, sizeof( cmd_command ) ); i2 = atoi( cmd_command ); link.teams = 15; if( argc > 5 ) { trap_CmdArgv( 5, cmd_command, sizeof( cmd_command ) ); link.flags = atoi( cmd_command ); } if( argc > 6 ) { trap_CmdArgv( 6, cmd_command, sizeof( cmd_command ) ); link.teams = atoi( cmd_command ); } if( argc > 7 ) { trap_CmdArgv( 7, cmd_command, sizeof( cmd_command ) ); link.req_velocity = atof( cmd_command ); } AddLink( i1, i2, &link); AddLink( i2, i1, &link); return; } if(!strcmp(cmd_command, "target")) { if( argc < 6 ) return; trap_CmdArgv( 3, cmd_command, sizeof( cmd_command ) ); end_pos[0] = atof( cmd_command ); trap_CmdArgv( 4, cmd_command, sizeof( cmd_command ) ); end_pos[1] = atof( cmd_command ); trap_CmdArgv( 5, cmd_command, sizeof( cmd_command ) ); end_pos[2] = atof( cmd_command ); return; } if(!strcmp(cmd_command, "draw")) { DrawWPS(); return; } if(!strcmp(cmd_command, "clear")) { ClearWaypoints(); return; } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CNPC_VehicleDriver::~CNPC_VehicleDriver( void ) { ClearWaypoints(); }
//----------------------------------------------------------------------------- // Purpose: We've hit a waypoint. Handle it, and return true if this is the // end of the path. //----------------------------------------------------------------------------- bool CNPC_VehicleDriver::WaypointReached( void ) { // We reached our current waypoint. m_vecPrevPrevPoint = m_vecPrevPoint; m_vecPrevPoint = GetAbsOrigin(); // If we've got to our goal, we're done here. if ( GetNavigator()->CurWaypointIsGoal() ) { // Necessary for InPass outputs to be fired, is a no-op otherwise GetNavigator()->AdvancePath(); // Stop pathing ClearWaypoints(); TaskComplete(); SetGoalEnt( NULL ); return true; } AI_Waypoint_t *pCurWaypoint = GetNavigator()->GetPath()->GetCurWaypoint(); if ( !pCurWaypoint ) return false; // Check to see if the waypoint wants us to change speed if ( pCurWaypoint->Flags() & bits_WP_TO_PATHCORNER ) { CBaseEntity *pEntity = pCurWaypoint->hPathCorner; if ( pEntity ) { if ( pEntity->m_flSpeed > 0 ) { if ( pEntity->m_flSpeed <= 1.0 ) { m_flDriversMaxSpeed = pEntity->m_flSpeed; RecalculateSpeeds(); } else { Warning("path_track %s tried to tell the npc_vehicledriver to set speed to %.3f. npc_vehicledriver only accepts values between 0 and 1.\n", STRING(pEntity->GetEntityName()), pEntity->m_flSpeed ); } } } } // Get the waypoints for the next part of the path GetNavigator()->AdvancePath(); if ( !GetNavigator()->GetPath()->GetCurWaypoint() ) { ClearWaypoints(); TaskComplete(); SetGoalEnt( NULL ); return true; } m_vecDesiredPosition = GetNavigator()->GetCurWaypointPos(); CalculatePostPoints(); // Move to the next waypoint delete m_pCurrentWaypoint; m_pCurrentWaypoint = m_pNextWaypoint; m_Waypoints[1] = new CVehicleWaypoint( m_vecPrevPoint, m_vecDesiredPosition, m_vecPostPoint, m_vecPostPostPoint ); m_pNextWaypoint = m_Waypoints[1]; // Drop the spline marker back m_flDistanceAlongSpline = MAX( 0, m_flDistanceAlongSpline - 1.0 ); CheckForTeleport(); return false; }