void NPC::MoveAction(void) { if ((g_waypoint->g_waypointPointFlag[m_currentWaypointIndex] & WAYPOINT_LADDER && GetDistance2D(pev->origin, g_waypoint->g_waypointPointOrigin[m_currentWaypointIndex]) <= 10.0f) || (m_oldNavIndex != -1 && g_waypoint->g_waypointPointFlag[m_oldNavIndex] & WAYPOINT_LADDER && GetDistance2D(pev->origin, g_waypoint->g_waypointPointOrigin[m_oldNavIndex]) <= 10.0f)) pev->movetype = MOVETYPE_FLY; else pev->movetype = MOVETYPE_PUSHSTEP; float oldSpeed = pev->speed; pev->speed = m_moveSpeed; if (m_moveSpeed == 0.0f || !IsAlive (GetEntity ())) { if (!IsOnLadder(GetEntity()) && pev->solid != SOLID_NOT) DROP_TO_FLOOR(GetEntity()); return; } if (IsOnLadder(GetEntity()) || pev->solid == SOLID_NOT) { pev->velocity = GetSpeedVector(pev->origin, m_destOrigin, pev->speed); if (pev->solid == SOLID_NOT) goto lastly; } else { Vector vecMove = m_destOrigin - pev->origin; Vector vecFwd, vecAng; VEC_TO_ANGLES(vecMove, vecAng); vecAng = Vector(0.0f, vecAng.y, 0.0f); UTIL_MakeVectorsPrivate(vecAng, vecFwd, null, null); pev->velocity.x = vecFwd.x * pev->speed; pev->velocity.y = vecFwd.y * pev->speed; } if (m_jumpAction) { pev->velocity.z = (270.0f * pev->gravity) + 32.0f; // client gravity 1 = 270.0f , and jump+duck + 32.0f m_jumpAction = false; } CheckStuck(oldSpeed); lastly: float speed = GetDistance2D(pev->velocity); if (speed > 10.0f || speed < -10.0f) g_npcAS |= ASC_MOVE; MakeVectors(pev->angles); }
//----------------------------------------------------------------------------- // Run this Bot's AI for one tick. //----------------------------------------------------------------------------- void CSDKBot::BotThink() { // Make sure we stay being a bot AddFlag( FL_FAKECLIENT ); if ( IsEFlagSet(EFL_BOT_FROZEN) ) return; CUserCmd cmd; Q_memset( &cmd, 0, sizeof( cmd ) ); ConVarRef bot_freeze("bot_freeze"); if ( !IsAlive() ) { HandleRespawn(cmd); } else if (bot_mimic.GetBool()) { CBasePlayer *pPlayer = UTIL_PlayerByIndex( bot_mimic.GetInt() ); if ( pPlayer && pPlayer->GetLastUserCommand() ) { cmd = *pPlayer->GetLastUserCommand(); ConVarRef bot_mimic_yaw_offset("bot_mimic_yaw_offset"); cmd.viewangles[YAW] += bot_mimic_yaw_offset.GetFloat(); ConVarRef bot_crouch("bot_crouch"); if( bot_crouch.GetInt() ) cmd.buttons |= IN_DUCK; } } else if (!bot_freeze.GetBool()) { trace_t tr_front; Vector Forward; AngleVectors(GetLocalAngles(), &Forward); UTIL_TraceHull( GetLocalOrigin()+Vector(0,0,5), GetLocalOrigin() + Vector(0,0,5) + (Forward * 50), GetPlayerMins(), GetPlayerMaxs(), MASK_PLAYERSOLID, this, COLLISION_GROUP_NONE, &tr_front ); // enemy acquisition if( !GetEnemy() || RecheckEnemy() || !GetEnemy()->IsAlive() ) { if( GetEnemy() && !GetEnemy()->IsAlive() ) ResetNavigationParams(); AcquireEnemy(); m_flTimeToRecheckEnemy = gpGlobals->curtime + 1.0f; } // assume we have an enemy from now on InfoGathering(); Attack(cmd); if( m_flTimeToRecheckStuck < gpGlobals->curtime ) CheckStuck(cmd); if( m_flNextDealObstacles < gpGlobals->curtime ) DealWithObstacles(tr_front.m_pEnt, cmd); Navigation(cmd); CheckNavMeshAttrib(&tr_front, cmd); } // debug waypoint related position /*for( int i=0; i<m_Waypoints.Count(); i++ ) { NDebugOverlay::Cross3DOriented( m_Waypoints[i].Center, QAngle(0,0,0), 5*i+1, 200, 0, 0, false, -1 ); }*/ RunPlayerMove( cmd, gpGlobals->frametime ); }