From 36c549a0cea8f4a4d7326f364916adfeb1961245 Mon Sep 17 00:00:00 2001 From: jeefo Date: Fri, 17 Jul 2015 19:23:31 +0300 Subject: [PATCH] some refactoring --- include/core.h | 40 +- source/basecode.cpp | 3149 ++++++++++++++++++++++-------------------- source/combat.cpp | 6 +- source/interface.cpp | 364 ++--- source/manager.cpp | 7 +- source/navigate.cpp | 185 +-- source/netmsg.cpp | 28 +- source/support.cpp | 52 +- source/waypoint.cpp | 12 +- 9 files changed, 1987 insertions(+), 1856 deletions(-) diff --git a/include/core.h b/include/core.h index f5f0367..c5f7d16 100644 --- a/include/core.h +++ b/include/core.h @@ -962,6 +962,28 @@ private: bool CanJumpUp (const Vector &normal); bool CantMoveForward (const Vector &normal, TraceResult *tr); + // split RunTask into RunTask_* functions + void RunTask_Normal (void); + void RunTask_Spray (void); + void RunTask_HuntEnemy (void); + void RunTask_SeekCover (void); + void RunTask_Attack (void); + void RunTask_Pause (void); + void RunTask_Blinded (void); + void RunTask_Camp (void); + void RunTask_Hide (void); + void RunTask_MoveToPos (void); + void RunTask_PlantBomb (void); + void RunTask_DefuseBomb (void); + void RunTask_FollowUser (void); + void RunTask_Throw_HE (void); + void RunTask_Throw_FL (void); + void RunTask_Throw_SG (void); + void RunTask_DoubleJump (void); + void RunTask_EscapeFromBomb (void); + void RunTask_PickupItem (void); + void RunTask_ShootBreakable (void); + #ifdef DEAD_CODE bool CanStrafeRight (TraceResult *tr); bool CanStrafeLeft (TraceResult *tr); @@ -1035,6 +1057,7 @@ private: bool ReactOnEnemy (void); void ResetCollideState (void); void SetConditions (void); + void UpdateEmotions (void); void SetStrafeSpeed (const Vector &moveDir, float strafeSpeed); void StartGame (void); void TaskComplete (void); @@ -1140,7 +1163,6 @@ public: bool m_canChooseAimDirection; // can choose aiming direction float m_turnAwayFromFlashbang; // bot turned away from flashbang - float m_breakableCheckTime; float m_blindTime; // time when bot is blinded float m_blindMoveSpeed; // mad speeds when bot is blind float m_blindSidemoveSpeed; // mad side move speeds when bot is blind @@ -1233,7 +1255,9 @@ public: void RemoveCertainTask (TaskID id); void PushTask (TaskID id, float desire, int data, float time, bool canContinue); + void ApplyTaskFilters (void); void ResetTasks (void); + TaskItem *GetTask (void); inline TaskID GetTaskId (void) { return GetTask ()->id; }; @@ -1563,11 +1587,13 @@ public: void PushRegisteredConVarsToEngine (bool gameVars = false); }; -#define g_netMsg NetworkMsg::GetObject () -#define g_botManager BotManager::GetObject () -#define g_localizer Localizer::GetObject () -#define g_convarWrapper ConVarWrapper::GetObject () -#define g_waypoint Waypoint::GetObject () + +// expose bot globals +#define netmsg NetworkMsg::GetObject () +#define locale Localizer::GetObject () +#define convars ConVarWrapper::GetObject () +#define waypoint Waypoint::GetObject () +#define botMgr BotManager::GetObject () // simplify access for console variables class ConVar @@ -1580,7 +1606,7 @@ public: { m_eptr = NULL; - g_convarWrapper->RegisterVariable (name, initval, type, this); + convars->RegisterVariable (name, initval, type, this); } inline bool GetBool(void) diff --git a/source/basecode.cpp b/source/basecode.cpp index 580916e..2a4c795 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -54,7 +54,7 @@ void Bot::PushMessageQueue (int message) for (int i = 0; i < GetMaxClients (); i++) { - Bot *otherBot = g_botManager->GetBot (i); + Bot *otherBot = botMgr->GetBot (i); if (otherBot != NULL && otherBot->pev != pev) { @@ -185,14 +185,14 @@ void Bot::CheckGrenadeThrow (void) searchRadius = 128.0; // search waypoints - g_waypoint->FindInRadius (enemyPredict, searchRadius, searchTab, &count); + waypoint->FindInRadius (enemyPredict, searchRadius, searchTab, &count); while (count > 0) { allowThrowing = true; // check the throwing - m_throw = g_waypoint->GetPath (searchTab[count--])->origin; + m_throw = waypoint->GetPath (searchTab[count--])->origin; Vector src = CheckThrow (EyePosition (), m_throw); if (src.GetLengthSquared () < 100.0) @@ -226,11 +226,11 @@ void Bot::CheckGrenadeThrow (void) bool allowThrowing = true; Array inRadius; - g_waypoint->FindInRadius (inRadius, 256, m_lastEnemy->v.origin + (m_lastEnemy->v.velocity * 0.5).Get2D ()); + waypoint->FindInRadius (inRadius, 256, m_lastEnemy->v.origin + (m_lastEnemy->v.velocity * 0.5).Get2D ()); FOR_EACH_AE (inRadius, i) { - Path *path = g_waypoint->GetPath (i); + Path *path = waypoint->GetPath (i); int friendCount = GetNearbyFriendsNearPosition (path->origin, 256.0f); @@ -273,7 +273,7 @@ void Bot::AvoidGrenades (void) { // checks if bot 'sees' a grenade, and avoid it - if (!g_botManager->HasActiveGrenades ()) + if (!botMgr->HasActiveGrenades ()) return; // check if old pointers to grenade is invalid @@ -287,7 +287,7 @@ void Bot::AvoidGrenades (void) m_avoidGrenade = NULL; m_needAvoidGrenade = 0; } - Array activeGrenades = g_botManager->GetActiveGrenades (); + Array activeGrenades = botMgr->GetActiveGrenades (); // find all grenades on the map FOR_EACH_AE (activeGrenades, it) @@ -346,11 +346,11 @@ void Bot::AvoidGrenades (void) bool Bot::IsBehindSmokeClouds (edict_t *ent) { - if (!g_botManager->HasActiveGrenades ()) + if (!botMgr->HasActiveGrenades ()) return false; const Vector &betweenUs = (ent->v.origin - pev->origin).Normalize (); - Array activeGrenades = g_botManager->GetActiveGrenades (); + Array activeGrenades = botMgr->GetActiveGrenades (); // find all grenades on the map FOR_EACH_AE (activeGrenades, it) @@ -460,7 +460,7 @@ bool Bot::RateGroundWeapon (edict_t *ent) void Bot::VerifyBreakable (edict_t *touch) { - if (m_breakableCheckTime < GetWorldTime () || !IsShootableBreakable (touch)) + if (!IsShootableBreakable (touch)) return; m_breakableEntity = FindBreakable (); @@ -471,7 +471,6 @@ void Bot::VerifyBreakable (edict_t *touch) m_campButtons = pev->button & IN_DUCK; PushTask (TASK_SHOOTBREAKABLE, TASKPRI_SHOOTBREAKABLE, -1, 0.0, false); - m_breakableCheckTime = GetWorldTime () + 0.5f; } edict_t *Bot::FindBreakable (void) @@ -719,7 +718,7 @@ void Bot::FindItem (void) PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (30.0, 60.0), true); // push camp task on to stack PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + Random.Float (3.0, 6.0), true); // push move command - if (g_waypoint->GetPath (index)->vis.crouch <= g_waypoint->GetPath (index)->vis.stand) + if (waypoint->GetPath (index)->vis.crouch <= waypoint->GetPath (index)->vis.stand) m_campButtons |= IN_DUCK; else m_campButtons &= ~IN_DUCK; @@ -739,10 +738,10 @@ void Bot::FindItem (void) m_defendedBomb = true; int index = FindDefendWaypoint (entityOrigin); - Path *path = g_waypoint->GetPath (index); + Path *path = waypoint->GetPath (index); float bombTimer = mp_c4timer.GetFloat (); - float timeMidBlowup = g_timeBombPlanted + (bombTimer * 0.5 + bombTimer * 0.25) - g_waypoint->GetTravelTime (pev->maxspeed, pev->origin, path->origin); + float timeMidBlowup = g_timeBombPlanted + (bombTimer * 0.5 + bombTimer * 0.25) - waypoint->GetTravelTime (pev->maxspeed, pev->origin, path->origin); if (timeMidBlowup > GetWorldTime ()) { @@ -772,7 +771,7 @@ void Bot::FindItem (void) allowPickup = false; // never pickup dead hostage else for (int i = 0; i < GetMaxClients (); i++) { - if ((bot = g_botManager->GetBot (i)) != NULL && IsAlive (bot->GetEntity ())) + if ((bot = botMgr->GetBot (i)) != NULL && IsAlive (bot->GetEntity ())) { for (int j = 0; j < MAX_HOSTAGES; j++) { @@ -796,7 +795,7 @@ void Bot::FindItem (void) if (Random.Long (0, 100) < 90) ChatterMessage (Chatter_FoundBombPlace); - allowPickup = !IsBombDefusing (g_waypoint->GetBombPosition ()) || m_hasProgressBar; + allowPickup = !IsBombDefusing (waypoint->GetBombPosition ()) || m_hasProgressBar; pickupType = PICKUP_PLANTED_C4; if (!m_defendedBomb && !allowPickup) @@ -804,9 +803,9 @@ void Bot::FindItem (void) m_defendedBomb = true; int index = FindDefendWaypoint (entityOrigin); - Path *path = g_waypoint->GetPath (index); + Path *path = waypoint->GetPath (index); - float timeToExplode = g_timeBombPlanted + mp_c4timer.GetFloat () - g_waypoint->GetTravelTime (pev->maxspeed, pev->origin, path->origin); + float timeToExplode = g_timeBombPlanted + mp_c4timer.GetFloat () - waypoint->GetTravelTime (pev->maxspeed, pev->origin, path->origin); RemoveCertainTask (TASK_MOVETOPOSITION); // remove any move tasks @@ -834,7 +833,7 @@ void Bot::FindItem (void) PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (30.0, 70.0), true); // push camp task on to stack PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + Random.Float (10.0, 30.0), true); // push move command - if (g_waypoint->GetPath (index)->vis.crouch <= g_waypoint->GetPath (index)->vis.stand) + if (waypoint->GetPath (index)->vis.crouch <= waypoint->GetPath (index)->vis.stand) m_campButtons |= IN_DUCK; else m_campButtons &= ~IN_DUCK; @@ -866,7 +865,7 @@ void Bot::FindItem (void) { for (int i = 0; i < GetMaxClients (); i++) { - if ((bot = g_botManager->GetBot (i)) != NULL && IsAlive (bot->GetEntity ()) && bot->m_pickupItem == pickupItem) + if ((bot = botMgr->GetBot (i)) != NULL && IsAlive (bot->GetEntity ()) && bot->m_pickupItem == pickupItem) { m_pickupItem = NULL; m_pickupType = PICKUP_NONE; @@ -913,14 +912,14 @@ void Bot::GetCampDirection (Vector *dest) // find nearest waypoint to bot and position for (int i = 0; i < g_numWaypoints; i++) { - float distance = (g_waypoint->GetPath (i)->origin - pev->origin).GetLengthSquared (); + float distance = (waypoint->GetPath (i)->origin - pev->origin).GetLengthSquared (); if (distance < minDistance) { minDistance = distance; tempIndex = i; } - distance = (g_waypoint->GetPath (i)->origin - *dest).GetLengthSquared (); + distance = (waypoint->GetPath (i)->origin - *dest).GetLengthSquared (); if (distance < maxDistance) { @@ -935,14 +934,14 @@ void Bot::GetCampDirection (Vector *dest) minDistance = 99999.0f; int lookAtWaypoint = -1; - Path *path = g_waypoint->GetPath (tempIndex); + Path *path = waypoint->GetPath (tempIndex); for (int i = 0; i < MAX_PATH_INDEX; i++) { if (path->index[i] == -1) continue; - float distance = g_waypoint->GetPathDistance (path->index[i], enemyIndex); + float distance = waypoint->GetPathDistance (path->index[i], enemyIndex); if (distance < minDistance) { @@ -951,7 +950,7 @@ void Bot::GetCampDirection (Vector *dest) } } if (lookAtWaypoint != -1 && lookAtWaypoint < g_numWaypoints) - *dest = g_waypoint->GetPath (lookAtWaypoint)->origin; + *dest = waypoint->GetPath (lookAtWaypoint)->origin; } } @@ -967,7 +966,7 @@ void Bot::SwitchChatterIcon (bool show) if (!(g_clients[i].flags & CF_USED) || (g_clients[i].ent->v.flags & FL_FAKECLIENT) || g_clients[i].team != m_team) continue; - MESSAGE_BEGIN (MSG_ONE, g_netMsg->GetId (NETMSG_BOTVOICE), NULL, g_clients[i].ent); // begin message + MESSAGE_BEGIN (MSG_ONE, netmsg->GetId (NETMSG_BOTVOICE), NULL, g_clients[i].ent); // begin message WRITE_BYTE (show); // switch on/off WRITE_BYTE (GetIndex ()); MESSAGE_END (); @@ -1007,7 +1006,7 @@ void Bot::InstantChatterMessage (int type) g_sendAudioFinished = false; - MESSAGE_BEGIN (MSG_ONE, g_netMsg->GetId (NETMSG_SENDAUDIO), NULL, ent); // begin message + MESSAGE_BEGIN (MSG_ONE, netmsg->GetId (NETMSG_SENDAUDIO), NULL, ent); // begin message WRITE_BYTE (GetIndex ()); if (pev->deadflag & DEAD_DYING) @@ -1159,7 +1158,7 @@ void Bot::CheckMessageQueue (void) for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot != NULL) { @@ -1180,7 +1179,7 @@ void Bot::CheckMessageQueue (void) case TASK_NORMAL: if (GetTask ()->data != -1 && Random.Long (0, 100) < 70) { - Path *path = g_waypoint->GetPath (GetTask ()->data); + Path *path = waypoint->GetPath (GetTask ()->data); if (path->flags & FLAG_GOAL) { @@ -1404,7 +1403,7 @@ void Bot::PurchaseWeapons (void) int *ptr = g_weaponPrefs[m_personality] + NUM_WEAPONS; bool isPistolMode = g_weaponSelect[25].teamStandard == -1 && g_weaponSelect[3].teamStandard == 2; - bool teamEcoValid = g_botManager->EconomicsValid (m_team); + bool teamEcoValid = botMgr->EconomicsValid (m_team); switch (m_buyState) { @@ -1516,7 +1515,7 @@ void Bot::PurchaseWeapons (void) int moneySave = Random.Long (900, 1100); - if (g_botManager->GetLastWinner () == m_team) + if (botMgr->GetLastWinner () == m_team) moneySave = 0; if (selectedWeapon->price <= (m_moneyAmount - moneySave)) @@ -1754,6 +1753,37 @@ float HysteresisDesire (float cur, float min, float max, float old) return old; } +void Bot::UpdateEmotions (void) +{ + // slowly increase/decrease dynamic emotions back to their base level + if (m_nextEmotionUpdate > GetWorldTime ()) + return; + + if (m_difficulty == 4) + { + m_agressionLevel *= 2; + m_fearLevel *= 0.5f; + } + + if (m_agressionLevel > m_baseAgressionLevel) + m_agressionLevel -= 0.10f; + else + m_agressionLevel += 0.10f; + + if (m_fearLevel > m_baseFearLevel) + m_fearLevel -= 0.05f; + else + m_fearLevel += 0.05f; + + if (m_agressionLevel < 0.0f) + m_agressionLevel = 0.0f; + + if (m_fearLevel < 0.0f) + m_fearLevel = 0.0f; + + m_nextEmotionUpdate = GetWorldTime () + 1.0f; +} + void Bot::SetConditions (void) { // this function carried out each frame. does all of the sensing, calculates emotions and finally sets the desired @@ -1761,33 +1791,7 @@ void Bot::SetConditions (void) m_aimFlags = 0; - // slowly increase/decrease dynamic emotions back to their base level - if (m_nextEmotionUpdate < GetWorldTime ()) - { - if (m_difficulty == 4) - { - m_agressionLevel *= 2; - m_fearLevel /= 2; - } - - if (m_agressionLevel > m_baseAgressionLevel) - m_agressionLevel -= 0.10; - else - m_agressionLevel += 0.10; - - if (m_fearLevel > m_baseFearLevel) - m_fearLevel -= 0.05; - else - m_fearLevel += 0.05; - - if (m_agressionLevel < 0.0) - m_agressionLevel = 0.0; - - if (m_fearLevel < 0.0) - m_fearLevel = 0.0; - - m_nextEmotionUpdate = GetWorldTime () + 1.0; - } + UpdateEmotions (); // does bot see an enemy? if (LookupEnemy ()) @@ -1804,10 +1808,10 @@ void Bot::SetConditions (void) if (GetTeam (m_lastVictim) != m_team) { // add some aggression because we just killed somebody - m_agressionLevel += 0.1; + m_agressionLevel += 0.1f; - if (m_agressionLevel > 1.0) - m_agressionLevel = 1.0; + if (m_agressionLevel > 1.0f) + m_agressionLevel = 1.0f; if (Random.Long (1, 100) < 10) ChatMessage (CHAT_KILLING); @@ -1855,7 +1859,6 @@ void Bot::SetConditions (void) if (IsPointOccupied (m_plantedBombWptIndex)) InstantChatterMessage (Chatter_BombSiteSecured); - } } else @@ -1905,6 +1908,13 @@ void Bot::SetConditions (void) m_itemCheckTime = GetWorldTime () + 0.4f; FindItem (); } + ApplyTaskFilters (); +} + +void Bot::ApplyTaskFilters (void) +{ + // initialize & calculate the desire for all actions based on distances, emotions and other stuff + GetTask (); float tempFear = m_fearLevel; float tempAgression = m_agressionLevel; @@ -1925,9 +1935,6 @@ void Bot::SetConditions (void) tempAgression = tempAgression * 0.5; } - // initialize & calculate the desire for all actions based on distances, emotions and other stuff - GetTask (); - // bot found some item to use? if (!IsEntityNull (m_pickupItem) && GetTaskId () != TASK_ESCAPEFROMBOMB) { @@ -1989,7 +1996,7 @@ void Bot::SetConditions (void) // if half of the round is over, allow hunting // FIXME: it probably should be also team/map dependant - if (GetTaskId () != TASK_ESCAPEFROMBOMB && IsEntityNull (m_enemy) && g_timeRoundMid < GetWorldTime () && !m_isUsingGrenade && m_currentWaypointIndex != g_waypoint->FindNearest (m_lastEnemyOrigin) && m_personality != PERSONALITY_CAREFUL) + if (GetTaskId () != TASK_ESCAPEFROMBOMB && IsEntityNull (m_enemy) && g_timeRoundMid < GetWorldTime () && !m_isUsingGrenade && m_currentWaypointIndex != waypoint->FindNearest (m_lastEnemyOrigin) && m_personality != PERSONALITY_CAREFUL) { float desireLevel = 4096.0 - ((1.0 - tempAgression) * distance); @@ -2038,7 +2045,7 @@ void Bot::SetConditions (void) TaskItem *taskSurvive = ThresholdDesire (&g_taskFilters[TASK_SEEKCOVER], 40.0, 0.0); taskSurvive = SubsumeDesire (&g_taskFilters[TASK_HIDE], taskSurvive); - TaskItem *def = ThresholdDesire (&g_taskFilters[TASK_HUNTENEMY], 41.0, 0.0); // don't allow hunting if desire's 60< + TaskItem *def = ThresholdDesire (&g_taskFilters[TASK_HUNTENEMY], 41.0, 0.0); // don't allow hunting if desires 60< taskOffensive = SubsumeDesire (taskOffensive, taskPickup); // if offensive task, don't allow picking up stuff TaskItem *taskSub = MaxDesire (taskOffensive, def); // default normal & careful tasks against offensive actions @@ -2207,11 +2214,11 @@ bool Bot::ReactOnEnemy (void) if (m_enemyReachableTimer < GetWorldTime ()) { - int i = g_waypoint->FindNearest (pev->origin); - int enemyIndex = g_waypoint->FindNearest (m_enemy->v.origin); + int i = waypoint->FindNearest (pev->origin); + int enemyIndex = waypoint->FindNearest (m_enemy->v.origin); float lineDist = (m_enemy->v.origin - pev->origin).GetLength (); - float pathDist = g_waypoint->GetPathDistance (i, enemyIndex); + float pathDist = waypoint->GetPathDistance (i, enemyIndex); if (pathDist - lineDist > 112.0) m_isEnemyReachable = false; @@ -2268,7 +2275,7 @@ void Bot::CheckRadioCommands (void) // Check if no more followers are allowed for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot != NULL) { @@ -2302,7 +2309,7 @@ void Bot::CheckRadioCommands (void) { for (int i = 0; (i < GetMaxClients () && numFollowers > allowedFollowers) ; i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot != NULL) { @@ -2362,7 +2369,7 @@ void Bot::CheckRadioCommands (void) TryHeadTowardRadioEntity (); } - else if (Random.Long (0, 100) < 80) + else if (Random.Long (0, 100) < 70) RadioMessage (Radio_Negative); } break; @@ -2439,6 +2446,7 @@ void Bot::CheckRadioCommands (void) } else RadioMessage (Radio_Negative); + break; case Radio_ShesGonnaBlow: @@ -2464,7 +2472,7 @@ void Bot::CheckRadioCommands (void) SelectWeaponByName ("weapon_knife"); DeleteSearchNodes (); - MoveToVector (g_waypoint->GetBombPosition ()); + MoveToVector (waypoint->GetBombPosition ()); RadioMessage (Radio_Affirmative); } @@ -2573,19 +2581,19 @@ void Bot::CheckRadioCommands (void) float minDistance = 99999.0f; // find nearest bomb waypoint to player - FOR_EACH_AE (g_waypoint->m_goalPoints, i) + FOR_EACH_AE (waypoint->m_goalPoints, i) { - distance = (g_waypoint->GetPath (g_waypoint->m_goalPoints[i])->origin - m_radioEntity->v.origin).GetLengthSquared (); + distance = (waypoint->GetPath (waypoint->m_goalPoints[i])->origin - m_radioEntity->v.origin).GetLengthSquared (); if (distance < minDistance) { minDistance = distance; - bombPoint = g_waypoint->m_goalPoints[i]; + bombPoint = waypoint->m_goalPoints[i]; } } // mark this waypoint as restricted point - if (bombPoint != -1 && !g_waypoint->IsGoalVisited (bombPoint)) + if (bombPoint != -1 && !waypoint->IsGoalVisited (bombPoint)) { // does this bot want to defuse? if (GetTaskId () == TASK_NORMAL) @@ -2598,7 +2606,7 @@ void Bot::CheckRadioCommands (void) } } - g_waypoint->SetGoalVisited (bombPoint); + waypoint->SetGoalVisited (bombPoint); } g_timeNextBombUpdate = GetWorldTime () + 0.5; } @@ -2655,7 +2663,7 @@ void Bot::CheckRadioCommands (void) // push move command PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + Random.Float (30.0, 60.0), true); - if (g_waypoint->GetPath (index)->vis.crouch <= g_waypoint->GetPath (index)->vis.stand) + if (waypoint->GetPath (index)->vis.crouch <= waypoint->GetPath (index)->vis.stand) m_campButtons |= IN_DUCK; else m_campButtons &= ~IN_DUCK; @@ -2704,7 +2712,7 @@ void Bot::SelectLeaderEachTeam (int team) } else if ((team == TEAM_TF) && !g_leaderChoosen[TEAM_TF]) { - Bot *botLeader = g_botManager->GetHighestFragsBot(team); + Bot *botLeader = botMgr->GetHighestFragsBot(team); if (botLeader != NULL && IsAlive (botLeader->GetEntity())) { @@ -2740,7 +2748,7 @@ void Bot::SelectLeaderEachTeam (int team) } else if (!g_leaderChoosen[TEAM_CF]) { - Bot *botLeader = g_botManager->GetHighestFragsBot(team); + Bot *botLeader = botMgr->GetHighestFragsBot(team); if (botLeader != NULL) { @@ -2754,7 +2762,7 @@ void Bot::SelectLeaderEachTeam (int team) } else if (g_mapType & (MAP_ES | MAP_KA | MAP_FY)) { - Bot *botLeader = g_botManager->GetHighestFragsBot (team); + Bot *botLeader = botMgr->GetHighestFragsBot (team); if (botLeader != NULL) { @@ -2766,7 +2774,7 @@ void Bot::SelectLeaderEachTeam (int team) } else { - Bot *botLeader = g_botManager->GetHighestFragsBot(team); + Bot *botLeader = botMgr->GetHighestFragsBot(team); if (botLeader != NULL) { @@ -2863,7 +2871,7 @@ void Bot::ChooseAimDirection (void) if (recalcPath) { - m_lookAt = g_waypoint->GetPath (GetAimingWaypoint (m_lastEnemyOrigin))->origin; + m_lookAt = waypoint->GetPath (GetAimingWaypoint (m_lastEnemyOrigin))->origin; m_camp = m_lookAt; m_timeNextTracking = GetWorldTime () + 0.5f; @@ -2898,7 +2906,7 @@ void Bot::ChooseAimDirection (void) { if ((g_experienceData + (index * g_numWaypoints) + index)->team0DangerIndex != -1) { - const Vector &dest = g_waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team0DangerIndex)->origin; + const Vector &dest = waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team0DangerIndex)->origin; TraceLine (pev->origin, dest, true, GetEntity (), &tr); if (tr.flFraction > 0.8 || tr.pHit != g_worldEntity) @@ -2909,7 +2917,7 @@ void Bot::ChooseAimDirection (void) { if ((g_experienceData + (index * g_numWaypoints) + index)->team1DangerIndex != -1) { - const Vector &dest = g_waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team1DangerIndex)->origin; + const Vector &dest = waypoint->GetPath ((g_experienceData + (index * g_numWaypoints) + index)->team1DangerIndex)->origin; TraceLine (pev->origin, dest, true, GetEntity (), &tr); if (tr.flFraction > 0.8 || tr.pHit != g_worldEntity) @@ -2920,7 +2928,7 @@ void Bot::ChooseAimDirection (void) if (m_canChooseAimDirection && m_prevWptIndex[0] >= 0 && m_prevWptIndex[0] < g_numWaypoints) { - Path *path = g_waypoint->GetPath (m_prevWptIndex[0]); + Path *path = waypoint->GetPath (m_prevWptIndex[0]); if (!(path->flags & FLAG_LADDER) && (fabsf (path->origin.z - m_destOrigin.z) < 30.0 || (m_waypointFlags & FLAG_CAMP))) { @@ -3018,19 +3026,11 @@ void Bot::Think (void) else if (m_buyingFinished) botMovement = true; - int team = g_clients[IndexOfEntity (GetEntity ()) - 1].realTeam;; - - // remove voice icon - if (g_lastRadioTime[team] + Random.Float (0.8, 2.1) < GetWorldTime ()) - SwitchChatterIcon (false); // hide icon - CheckMessageQueue (); // check for pending messages if (pev->maxspeed < 10 && GetTaskId () != TASK_PLANTBOMB && GetTaskId () != TASK_DEFUSEBOMB) botMovement = false; - CheckSpawnTimeConditions (); - if (m_notKilled && botMovement && !yb_freeze_bots.GetBool ()) BotAI (); // execute main code @@ -3042,464 +3042,1244 @@ void Bot::PeriodicThink (void) if (m_timePeriodicUpdate > GetWorldTime ()) return; - // this function is called from main think function every second (second not frame). + // this function is called from main think function m_numFriendsLeft = GetNearbyFriendsNearPosition (pev->origin, 99999.0f); m_numEnemiesLeft = GetNearbyEnemiesNearPosition (pev->origin, 99999.0f); - if (g_bombPlanted && m_team == TEAM_CF && (pev->origin - g_waypoint->GetBombPosition ()).GetLength () < 700 && !IsBombDefusing (g_waypoint->GetBombPosition ()) && !m_hasProgressBar && GetTaskId () != TASK_ESCAPEFROMBOMB) + if (g_bombPlanted && m_team == TEAM_CF && (pev->origin - waypoint->GetBombPosition ()).GetLength () < 700 && !IsBombDefusing (waypoint->GetBombPosition ()) && !m_hasProgressBar && GetTaskId () != TASK_ESCAPEFROMBOMB) ResetTasks (); - m_timePeriodicUpdate = GetWorldTime () + 0.65f; + CheckSpawnTimeConditions (); + + // remove voice icon + if (g_lastRadioTime[g_clients[IndexOfEntity (GetEntity ()) - 1].realTeam] + Random.Float (0.8f, 2.1f) < GetWorldTime ()) + SwitchChatterIcon (false); // hide icon + + m_timePeriodicUpdate = GetWorldTime () + 0.25f; } -void Bot::RunTask (void) +void Bot::RunTask_Normal (void) { - // this is core function that handle task execution - int destIndex, i; + m_aimFlags |= AIM_NAVPOINT; - Vector src, destination; - TraceResult tr; - - bool exceptionCaught = false; - float fullDefuseTime, timeToBlowUp, defuseRemainingTime; - - switch (GetTaskId ()) + // user forced a waypoint as a goal? + if (yb_debug_goal.GetInt () != -1 && GetTask ()->data != yb_debug_goal.GetInt ()) { - // normal task - case TASK_NORMAL: - m_aimFlags |= AIM_NAVPOINT; + DeleteSearchNodes (); + GetTask ()->data = yb_debug_goal.GetInt (); + } - // user forced a waypoint as a goal? - if (yb_debug_goal.GetInt () != -1 && GetTask ()->data != yb_debug_goal.GetInt ()) + // bots rushing with knife, when have no enemy (thanks for idea to nicebot project) + if (m_currentWeapon == WEAPON_KNIFE && (IsEntityNull (m_lastEnemy) || !IsAlive (m_lastEnemy)) && IsEntityNull (m_enemy) && m_knifeAttackTime < GetWorldTime () && !HasShield () && GetNearbyFriendsNearPosition (pev->origin, 96) == 0) + { + if (Random.Long (0, 100) < 40) + pev->button |= IN_ATTACK; + else + pev->button |= IN_ATTACK2; + + m_knifeAttackTime = GetWorldTime () + Random.Float (2.5f, 6.0f); + } + + if (m_reloadState == RELOAD_NONE && GetAmmo () != 0 && GetAmmoInClip () < 5 && g_weaponDefs[m_currentWeapon].ammo1 != -1) + m_reloadState = RELOAD_PRIMARY; + + // if bomb planted and it's a CT calculate new path to bomb point if he's not already heading for + if (g_bombPlanted && m_team == TEAM_CF && GetTask ()->data != -1 && !(waypoint->GetPath (GetTask ()->data)->flags & FLAG_GOAL) && GetTaskId () != TASK_ESCAPEFROMBOMB) + { + DeleteSearchNodes (); + GetTask ()->data = -1; + } + + if (!g_bombPlanted && m_currentWaypointIndex != -1 && (m_currentPath->flags & FLAG_GOAL) && Random.Long (0, 100) < 80 && GetNearbyEnemiesNearPosition (pev->origin, 650) == 0) + RadioMessage (Radio_SectorClear); + + // reached the destination (goal) waypoint? + if (DoWaypointNav ()) + { + TaskComplete (); + m_prevGoalIndex = -1; + + // spray logo sometimes if allowed to do so + if (m_timeLogoSpray < GetWorldTime () && yb_spraypaints.GetBool () && Random.Long (1, 100) < 80 && m_moveSpeed > GetWalkSpeed ()) + PushTask (TASK_SPRAY, TASKPRI_SPRAYLOGO, -1, GetWorldTime () + 1.0, false); + + // reached waypoint is a camp waypoint + if ((m_currentPath->flags & FLAG_CAMP) && !yb_csdm_mode.GetBool ()) { - DeleteSearchNodes (); - GetTask ()->data = yb_debug_goal.GetInt (); - } - - // bots rushing with knife, when have no enemy (thanks for idea to nicebot project) - if (m_currentWeapon == WEAPON_KNIFE && (IsEntityNull (m_lastEnemy) || !IsAlive (m_lastEnemy)) && IsEntityNull (m_enemy) && m_knifeAttackTime < GetWorldTime () && !HasShield () && GetNearbyFriendsNearPosition (pev->origin, 96) == 0) - { - if (Random.Long (0, 100) < 40) - pev->button |= IN_ATTACK; - else - pev->button |= IN_ATTACK2; - - m_knifeAttackTime = GetWorldTime () + Random.Float (2.5f, 6.0f); - } - - if (m_reloadState == RELOAD_NONE && GetAmmo () != 0 && GetAmmoInClip () < 5 && g_weaponDefs[m_currentWeapon].ammo1 != -1) - m_reloadState = RELOAD_PRIMARY; - - // if bomb planted and it's a CT calculate new path to bomb point if he's not already heading for - if (g_bombPlanted && m_team == TEAM_CF && GetTask ()->data != -1 && !(g_waypoint->GetPath (GetTask ()->data)->flags & FLAG_GOAL) && GetTaskId () != TASK_ESCAPEFROMBOMB) - { - DeleteSearchNodes (); - GetTask ()->data = -1; - } - - if (!g_bombPlanted && m_currentWaypointIndex != -1 && (m_currentPath->flags & FLAG_GOAL) && Random.Long (0, 100) < 80 && GetNearbyEnemiesNearPosition (pev->origin, 650) == 0) - RadioMessage (Radio_SectorClear); - - // reached the destination (goal) waypoint? - if (DoWaypointNav ()) - { - TaskComplete (); - m_prevGoalIndex = -1; - - // spray logo sometimes if allowed to do so - if (m_timeLogoSpray < GetWorldTime () && yb_spraypaints.GetBool () && Random.Long (1, 100) < 80 && m_moveSpeed > GetWalkSpeed ()) - PushTask (TASK_SPRAY, TASKPRI_SPRAYLOGO, -1, GetWorldTime () + 1.0, false); - - // reached waypoint is a camp waypoint - if ((m_currentPath->flags & FLAG_CAMP) && !yb_csdm_mode.GetBool ()) + // check if bot has got a primary weapon and hasn't camped before + if (HasPrimaryWeapon () && m_timeCamping + 10.0 < GetWorldTime () && !HasHostage ()) { - // check if bot has got a primary weapon and hasn't camped before - if (HasPrimaryWeapon () && m_timeCamping + 10.0 < GetWorldTime () && !HasHostage ()) + bool campingAllowed = true; + + // Check if it's not allowed for this team to camp here + if (m_team == TEAM_TF) { - bool campingAllowed = true; + if (m_currentPath->flags & FLAG_CF_ONLY) + campingAllowed = false; + } + else + { + if (m_currentPath->flags & FLAG_TF_ONLY) + campingAllowed = false; + } - // Check if it's not allowed for this team to camp here - if (m_team == TEAM_TF) - { - if (m_currentPath->flags & FLAG_CF_ONLY) - campingAllowed = false; - } + // don't allow vip on as_ maps to camp + don't allow terrorist carrying c4 to camp + if (IsPlayerVIP (GetEntity ()) || ((g_mapType & MAP_DE) && m_team == TEAM_TF && !g_bombPlanted && m_hasC4)) + campingAllowed = false; + + // check if another bot is already camping here + if (IsPointOccupied (m_currentWaypointIndex)) + campingAllowed = false; + + if (campingAllowed) + { + // crouched camping here? + if (m_currentPath->flags & FLAG_CROUCH) + m_campButtons = IN_DUCK; else - { - if (m_currentPath->flags & FLAG_TF_ONLY) - campingAllowed = false; - } + m_campButtons = 0; - // don't allow vip on as_ maps to camp + don't allow terrorist carrying c4 to camp - if (IsPlayerVIP (GetEntity ()) || ((g_mapType & MAP_DE) && m_team == TEAM_TF && !g_bombPlanted && m_hasC4)) - campingAllowed = false; + SelectBestWeapon (); - // check if another bot is already camping here - if (IsPointOccupied (m_currentWaypointIndex)) - campingAllowed = false; + if (!(m_states & (STATE_SEEING_ENEMY | STATE_HEARING_ENEMY)) && !m_reloadState) + m_reloadState = RELOAD_PRIMARY; - if (campingAllowed) - { - // crouched camping here? - if (m_currentPath->flags & FLAG_CROUCH) - m_campButtons = IN_DUCK; - else - m_campButtons = 0; + MakeVectors (pev->v_angle); - SelectBestWeapon (); + PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (20.0f, 40.0f), true); - if (!(m_states & (STATE_SEEING_ENEMY | STATE_HEARING_ENEMY)) && !m_reloadState) - m_reloadState = RELOAD_PRIMARY; + m_camp = Vector (m_currentPath->campStartX, m_currentPath->campStartY, 0.0f); + m_aimFlags |= AIM_CAMP; + m_campDirection = 0; - MakeVectors (pev->v_angle); + // tell the world we're camping + if (Random.Long (0, 100) < 80) + RadioMessage (Radio_InPosition); - PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (20.0f, 40.0f), true); + m_moveToGoal = false; + m_checkTerrain = false; - m_camp = Vector (m_currentPath->campStartX, m_currentPath->campStartY, 0.0f); - m_aimFlags |= AIM_CAMP; - m_campDirection = 0; - - // tell the world we're camping - if (Random.Long (0, 100) < 80) - RadioMessage (Radio_InPosition); - - m_moveToGoal = false; - m_checkTerrain = false; - - m_moveSpeed = 0; - m_strafeSpeed = 0; - } + m_moveSpeed = 0; + m_strafeSpeed = 0; } } - else + } + else + { + // some goal waypoints are map dependant so check it out... + if (g_mapType & MAP_CS) { - // some goal waypoints are map dependant so check it out... - if (g_mapType & MAP_CS) + // CT Bot has some hostages following? + if (HasHostage () && m_team == TEAM_CF) { - // CT Bot has some hostages following? - if (HasHostage () && m_team == TEAM_CF) + // and reached a Rescue Point? + if (m_currentPath->flags & FLAG_RESCUE) { - // and reached a Rescue Point? - if (m_currentPath->flags & FLAG_RESCUE) - { - for (i = 0; i < MAX_HOSTAGES; i++) - m_hostages[i] = NULL; // clear array of hostage pointers - } + for (int i = 0; i < MAX_HOSTAGES; i++) + m_hostages[i] = NULL; // clear array of hostage pointers } - else if (m_team == TEAM_TF && Random.Long (0, 100) < 80) + } + else if (m_team == TEAM_TF && Random.Long (0, 100) < 80) + { + int index = FindDefendWaypoint (m_currentPath->origin); + + PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (60.0, 120.0), true); // push camp task on to stack + PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + Random.Float (5.0, 10.0), true); // push move command + + if (waypoint->GetPath (index)->vis.crouch <= waypoint->GetPath (index)->vis.stand) + m_campButtons |= IN_DUCK; + else + m_campButtons &= ~IN_DUCK; + + ChatterMessage (Chatter_GoingToGuardVIPSafety); // play info about that + } + } + else if ((g_mapType & MAP_DE) && ((m_currentPath->flags & FLAG_GOAL) || m_inBombZone) && m_seeEnemyTime + 1.5f < GetWorldTime ()) + { + // is it a terrorist carrying the bomb? + if (m_hasC4) + { + if ((m_states & STATE_SEEING_ENEMY) && GetNearbyFriendsNearPosition (pev->origin, 768) == 0) + { + // request an help also + RadioMessage (Radio_NeedBackup); + InstantChatterMessage (Chatter_ScaredEmotion); + + PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (4.0, 8.0), true); + } + else + PushTask (TASK_PLANTBOMB, TASKPRI_PLANTBOMB, -1, 0.0, false); + } + else if (m_team == TEAM_CF) + { + if (!g_bombPlanted && GetNearbyFriendsNearPosition (pev->origin, 360.0f) < 3 && Random.Long (0, 100) < 85 && m_personality != PERSONALITY_RUSHER) { int index = FindDefendWaypoint (m_currentPath->origin); - PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (60.0, 120.0), true); // push camp task on to stack - PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + Random.Float (5.0, 10.0), true); // push move command + PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (25.0, 40.0), true); // push camp task on to stack + PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + Random.Float (5.0f, 11.0f), true); // push move command - if (g_waypoint->GetPath (index)->vis.crouch <= g_waypoint->GetPath (index)->vis.stand) + if (waypoint->GetPath (index)->vis.crouch <= waypoint->GetPath (index)->vis.stand) m_campButtons |= IN_DUCK; else m_campButtons &= ~IN_DUCK; - ChatterMessage (Chatter_GoingToGuardVIPSafety); // play info about that - } - } - else if ((g_mapType & MAP_DE) && ((m_currentPath->flags & FLAG_GOAL) || m_inBombZone) && m_seeEnemyTime + 1.5f < GetWorldTime ()) - { - // is it a terrorist carrying the bomb? - if (m_hasC4) - { - if ((m_states & STATE_SEEING_ENEMY) && GetNearbyFriendsNearPosition (pev->origin, 768) == 0) - { - // request an help also - RadioMessage (Radio_NeedBackup); - InstantChatterMessage (Chatter_ScaredEmotion); - - PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (4.0, 8.0), true); - } - else - PushTask (TASK_PLANTBOMB, TASKPRI_PLANTBOMB, -1, 0.0, false); - } - else if (m_team == TEAM_CF) - { - if (!g_bombPlanted && GetNearbyFriendsNearPosition (pev->origin, 360.0f) < 3 && Random.Long (0, 100) < 85 && m_personality != PERSONALITY_RUSHER) - { - int index = FindDefendWaypoint (m_currentPath->origin); - - PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (25.0, 40.0), true); // push camp task on to stack - PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + Random.Float (5.0f, 11.0f), true); // push move command - - if (g_waypoint->GetPath (index)->vis.crouch <= g_waypoint->GetPath (index)->vis.stand) - m_campButtons |= IN_DUCK; - else - m_campButtons &= ~IN_DUCK; - - ChatterMessage (Chatter_DefendingBombSite); // play info about that - } + ChatterMessage (Chatter_DefendingBombSite); // play info about that } } } } - // no more nodes to follow - search new ones (or we have a momb) - else if (!GoalIsValid ()) - { - m_moveSpeed = pev->maxspeed; - DeleteSearchNodes (); + } + // no more nodes to follow - search new ones (or we have a bomb) + else if (!GoalIsValid ()) + { + m_moveSpeed = pev->maxspeed; + DeleteSearchNodes (); - // did we already decide about a goal before? - if (GetTask ()->data != -1) - destIndex = GetTask ()->data; - else - destIndex = FindGoal (); + int destIndex = -1; - m_prevGoalIndex = destIndex; - m_chosenGoalIndex = destIndex; - - // remember index - GetTask ()->data = destIndex; - - // do pathfinding if it's not the current waypoint - if (destIndex != m_currentWaypointIndex) - FindPath (m_currentWaypointIndex, destIndex, ((g_bombPlanted && m_team == TEAM_CF) || yb_debug_goal.GetInt () != -1) ? 0 : m_pathType); - } + // did we already decide about a goal before? + if (GetTask ()->data != -1) + destIndex = GetTask ()->data; else + destIndex = FindGoal (); + + m_prevGoalIndex = destIndex; + m_chosenGoalIndex = destIndex; + + // remember index + GetTask ()->data = destIndex; + + // do pathfinding if it's not the current waypoint + if (destIndex != m_currentWaypointIndex) + FindPath (m_currentWaypointIndex, destIndex, ((g_bombPlanted && m_team == TEAM_CF) || yb_debug_goal.GetInt () != -1) ? 0 : m_pathType); + } + else + { + if (!(pev->flags & FL_DUCKING) && m_minSpeed != pev->maxspeed) + m_moveSpeed = m_minSpeed; + } + + if ((yb_walking_allowed.GetBool () && mp_footsteps.GetBool ()) && m_difficulty >= 2 && !(m_aimFlags & AIM_ENEMY) && (m_heardSoundTime + 13.0 >= GetWorldTime () || (m_states & (STATE_HEARING_ENEMY | STATE_SUSPECT_ENEMY))) && GetNearbyEnemiesNearPosition (pev->origin, 1024) >= 1 && !yb_jasonmode.GetBool () && !g_bombPlanted) + m_moveSpeed = GetWalkSpeed (); + + // bot hasn't seen anything in a long time and is asking his teammates to report in + if (m_seeEnemyTime + Random.Float (30.0, 80.0) < GetWorldTime () && Random.Long (0, 100) < 70 && g_timeRoundStart + 20.0 < GetWorldTime () && m_askCheckTime + Random.Float (20.0, 30.0) < GetWorldTime ()) + { + m_askCheckTime = GetWorldTime (); + RadioMessage (Radio_ReportTeam); + } +} + +void Bot::RunTask_Spray (void) +{ + m_aimFlags |= AIM_ENTITY; + + // bot didn't spray this round? + if (m_timeLogoSpray < GetWorldTime () && GetTask ()->time > GetWorldTime ()) + { + MakeVectors (pev->v_angle); + Vector sprayOrigin = EyePosition () + g_pGlobals->v_forward * 128.0f; + + TraceResult tr; + TraceLine (EyePosition (), sprayOrigin, true, GetEntity (), &tr); + + // no wall in front? + if (tr.flFraction >= 1.0) + sprayOrigin.z -= 128.0; + + m_entity = sprayOrigin; + + if (GetTask ()->time - 0.5f < GetWorldTime ()) { - if (!(pev->flags & FL_DUCKING) && m_minSpeed != pev->maxspeed) - m_moveSpeed = m_minSpeed; + // emit spraycan sound + EMIT_SOUND_DYN2 (GetEntity (), CHAN_VOICE, "player/sprayer.wav", 1.0, ATTN_NORM, 0, 100); + TraceLine (EyePosition (), EyePosition () + g_pGlobals->v_forward * 128, true, GetEntity (), &tr); + + // paint the actual logo decal + DecalTrace (pev, &tr, m_logotypeIndex); + m_timeLogoSpray = GetWorldTime () + Random.Float (30.0, 45.0); } + } + else + TaskComplete (); - if ((yb_walking_allowed.GetBool () && mp_footsteps.GetBool ()) && m_difficulty >= 2 && !(m_aimFlags & AIM_ENEMY) && (m_heardSoundTime + 13.0 >= GetWorldTime () || (m_states & (STATE_HEARING_ENEMY | STATE_SUSPECT_ENEMY))) && GetNearbyEnemiesNearPosition (pev->origin, 1024) >= 1 && !yb_jasonmode.GetBool () && !g_bombPlanted) - m_moveSpeed = GetWalkSpeed (); + m_moveToGoal = false; + m_checkTerrain = false; - // bot hasn't seen anything in a long time and is asking his teammates to report in - if (m_seeEnemyTime != 0.0 && m_seeEnemyTime + Random.Float (30.0, 80.0) < GetWorldTime () && Random.Long (0, 100) < 70 && g_timeRoundStart + 20.0 < GetWorldTime () && m_askCheckTime + Random.Float (20.0, 30.0) < GetWorldTime ()) + m_navTimeset = GetWorldTime (); + m_moveSpeed = 0.0f; + m_strafeSpeed = 0.0f; + + m_isStuck = false; + m_lastCollTime = GetWorldTime () + 0.5f; +} + +void Bot::RunTask_HuntEnemy (void) +{ + m_aimFlags |= AIM_NAVPOINT; + m_checkTerrain = true; + + // if we've got new enemy... + if (!IsEntityNull (m_enemy) || IsEntityNull (m_lastEnemy)) + { + // forget about it... + TaskComplete (); + m_prevGoalIndex = -1; + + m_lastEnemy = NULL; + m_lastEnemyOrigin = nullvec; + } + else if (GetTeam (m_lastEnemy) == m_team) + { + // don't hunt down our teammate... + RemoveCertainTask (TASK_HUNTENEMY); + m_prevGoalIndex = -1; + } + else if (DoWaypointNav ()) // reached last enemy pos? + { + // forget about it... + TaskComplete (); + m_prevGoalIndex = -1; + + m_lastEnemy = NULL; + m_lastEnemyOrigin = nullvec; + } + else if (!GoalIsValid ()) // do we need to calculate a new path? + { + DeleteSearchNodes (); + + int destIndex = -1; + + // is there a remembered index? + if (GetTask ()->data != -1 && GetTask ()->data < g_numWaypoints) + destIndex = GetTask ()->data; + else // no. we need to find a new one + destIndex = waypoint->FindNearest (m_lastEnemyOrigin); + + // remember index + m_prevGoalIndex = destIndex; + GetTask ()->data = destIndex; + + if (destIndex != m_currentWaypointIndex) + FindPath (m_currentWaypointIndex, destIndex, m_pathType); + } + + // bots skill higher than 60? + if (yb_walking_allowed.GetBool () && mp_footsteps.GetBool () && m_difficulty >= 1 && !yb_jasonmode.GetBool ()) + { + // then make him move slow if near enemy + if (!(m_currentTravelFlags & PATHFLAG_JUMP)) { - m_askCheckTime = GetWorldTime (); - RadioMessage (Radio_ReportTeam); - } - - break; - - // bot sprays messy logos all over the place... - case TASK_SPRAY: - m_aimFlags |= AIM_ENTITY; - - // bot didn't spray this round? - if (m_timeLogoSpray <= GetWorldTime () && GetTask ()->time > GetWorldTime ()) - { - MakeVectors (pev->v_angle); - Vector sprayOrigin = EyePosition () + (g_pGlobals->v_forward * 128); - - TraceLine (EyePosition (), sprayOrigin, true, GetEntity (), &tr); - - // no wall in front? - if (tr.flFraction >= 1.0) - sprayOrigin.z -= 128.0; - - m_entity = sprayOrigin; - - if (GetTask ()->time - 0.5 < GetWorldTime ()) + if (m_currentWaypointIndex != -1) { - // emit spraycan sound - EMIT_SOUND_DYN2 (GetEntity (), CHAN_VOICE, "player/sprayer.wav", 1.0, ATTN_NORM, 0, 100); - TraceLine (EyePosition (), EyePosition () + g_pGlobals->v_forward * 128, true, GetEntity (), &tr); - - // paint the actual logo decal - DecalTrace (pev, &tr, m_logotypeIndex); - m_timeLogoSpray = GetWorldTime () + Random.Float (30.0, 45.0); + if (m_currentPath->radius < 32 && !IsOnLadder () && !IsInWater () && m_seeEnemyTime + 4.0 > GetWorldTime () && m_difficulty == 0) + pev->button |= IN_DUCK; } + + if ((m_lastEnemyOrigin - pev->origin).GetLength () < 512.0) + m_moveSpeed = GetWalkSpeed (); + } + } +} + +void Bot::RunTask_SeekCover (void) +{ + m_aimFlags |= AIM_NAVPOINT; + + if (IsEntityNull (m_lastEnemy) || !IsAlive (m_lastEnemy)) + { + TaskComplete (); + m_prevGoalIndex = -1; + } + else if (DoWaypointNav ()) // reached final cover waypoint? + { + // yep. activate hide behaviour + TaskComplete (); + + m_prevGoalIndex = -1; + m_pathType = 0; + + // start hide task + PushTask (TASK_HIDE, TASKPRI_HIDE, -1, GetWorldTime () + Random.Float (5.0, 15.0), false); + Vector dest = m_lastEnemyOrigin; + + // get a valid look direction + GetCampDirection (&dest); + + m_aimFlags |= AIM_CAMP; + m_camp = dest; + m_campDirection = 0; + + // chosen waypoint is a camp waypoint? + if (m_currentPath->flags & FLAG_CAMP) + { + // use the existing camp wpt prefs + if (m_currentPath->flags & FLAG_CROUCH) + m_campButtons = IN_DUCK; + else + m_campButtons = 0; } else - TaskComplete (); + { + // choose a crouch or stand pos + if (m_currentPath->vis.crouch <= m_currentPath->vis.stand) + m_campButtons = IN_DUCK; + else + m_campButtons = 0; - m_moveToGoal = false; - m_checkTerrain = false; + // enter look direction from previously calculated positions + m_currentPath->campStartX = dest.x; + m_currentPath->campStartY = dest.y; + + m_currentPath->campStartX = dest.x; + m_currentPath->campEndY = dest.y; + } + + if ((m_reloadState == RELOAD_NONE) && (GetAmmoInClip () < 8) && (GetAmmo () != 0)) + m_reloadState = RELOAD_PRIMARY; - m_navTimeset = GetWorldTime (); m_moveSpeed = 0.0f; m_strafeSpeed = 0.0f; - m_isStuck = false; + m_moveToGoal = false; + m_checkTerrain = true; + } + else if (!GoalIsValid ()) // we didn't choose a cover waypoint yet or lost it due to an attack? + { + DeleteSearchNodes (); + + int destIndex = -1; + + if (GetTask ()->data != -1) + destIndex = GetTask ()->data; + else + { + destIndex = FindCoverWaypoint (1024.0f); + + if (destIndex == -1) + destIndex = waypoint->FindNearest (pev->origin, 512.0f); + } + m_campDirection = 0; + + m_prevGoalIndex = destIndex; + GetTask ()->data = destIndex; + + if (destIndex != m_currentWaypointIndex) + FindPath (m_currentWaypointIndex, destIndex, 0); + } +} + +void Bot::RunTask_Attack (void) +{ + m_moveToGoal = false; + m_checkTerrain = false; + + if (!IsEntityNull (m_enemy)) + { + ResetCollideState (); m_lastCollTime = GetWorldTime () + 0.5f; - break; - - // hunt down enemy - case TASK_HUNTENEMY: - m_aimFlags |= AIM_NAVPOINT; - m_checkTerrain = true; - - // if we've got new enemy... - if (!IsEntityNull (m_enemy) || IsEntityNull (m_lastEnemy)) - { - // forget about it... - TaskComplete (); - m_prevGoalIndex = -1; - - m_lastEnemy = NULL; - m_lastEnemyOrigin = nullvec; - } - else if (GetTeam (m_lastEnemy) == m_team) - { - // don't hunt down our teammate... - RemoveCertainTask (TASK_HUNTENEMY); - m_prevGoalIndex = -1; - } - else if (DoWaypointNav ()) // reached last enemy pos? - { - // forget about it... - TaskComplete (); - m_prevGoalIndex = -1; - - m_lastEnemy = NULL; - m_lastEnemyOrigin = nullvec; - } - else if (!GoalIsValid ()) // do we need to calculate a new path? + if (IsOnLadder ()) { + pev->button |= IN_JUMP; DeleteSearchNodes (); - - // is there a remembered index? - if (GetTask ()->data != -1 && GetTask ()->data < g_numWaypoints) - destIndex = GetTask ()->data; - else // no. we need to find a new one - destIndex = g_waypoint->FindNearest (m_lastEnemyOrigin); - - // remember index - m_prevGoalIndex = destIndex; - GetTask ()->data = destIndex; - - if (destIndex != m_currentWaypointIndex) - FindPath (m_currentWaypointIndex, destIndex, m_pathType); } + CombatFight (); + } + else + { + TaskComplete (); + m_destOrigin = m_lastEnemyOrigin; + } + m_navTimeset = GetWorldTime (); +} - // bots skill higher than 60? - if (yb_walking_allowed.GetBool () && mp_footsteps.GetBool () && m_difficulty >= 1 && !yb_jasonmode.GetBool ()) +void Bot::RunTask_Pause (void) +{ + m_moveToGoal = false; + m_checkTerrain = false; + + m_navTimeset = GetWorldTime (); + m_moveSpeed = 0.0; + m_strafeSpeed = 0.0; + + m_aimFlags |= AIM_NAVPOINT; + + // is bot blinded and above average difficulty? + if (m_viewDistance < 500.0 && m_difficulty >= 2) + { + // go mad! + m_moveSpeed = -fabsf ((m_viewDistance - 500.0) * 0.5f); + + if (m_moveSpeed < -pev->maxspeed) + m_moveSpeed = -pev->maxspeed; + + MakeVectors (pev->v_angle); + m_camp = EyePosition () + (g_pGlobals->v_forward * 500); + + m_aimFlags |= AIM_OVERRIDE; + m_wantsToFire = true; + } + else + pev->button |= m_campButtons; + + // stop camping if time over or gets hurt by something else than bullets + if (GetTask ()->time < GetWorldTime () || m_lastDamageType > 0) + TaskComplete (); +} + +void Bot::RunTask_Blinded (void) +{ + m_moveToGoal = false; + m_checkTerrain = false; + m_navTimeset = GetWorldTime (); + + // if bot remembers last enemy position + if (m_difficulty >= 2 && m_lastEnemyOrigin != nullvec && IsValidPlayer (m_lastEnemy) && !UsesSniper ()) + { + m_lookAt = m_lastEnemyOrigin; // face last enemy + m_wantsToFire = true; // and shoot it + } + + m_moveSpeed = m_blindMoveSpeed; + m_strafeSpeed = m_blindSidemoveSpeed; + pev->button |= m_blindButton; + + if (m_blindTime < GetWorldTime ()) + TaskComplete (); +} + +void Bot::RunTask_Camp (void) +{ + m_aimFlags |= AIM_CAMP; + m_checkTerrain = false; + m_moveToGoal = false; + + if (g_bombPlanted && m_defendedBomb && !IsBombDefusing (waypoint->GetBombPosition ()) && !OutOfBombTimer () && m_team == TEAM_CF) + { + m_defendedBomb = false; + TaskComplete (); + } + + // half the reaction time if camping because you're more aware of enemies if camping + SetIdealReactionTimes (); + m_idealReactionTime *= 0.5f; + + m_navTimeset = GetWorldTime (); + m_timeCamping = GetWorldTime (); + + m_moveSpeed = 0; + m_strafeSpeed = 0.0; + + GetValidWaypoint (); + + if (m_nextCampDirTime < GetWorldTime ()) + { + m_nextCampDirTime = GetWorldTime () + Random.Float (2.0, 5.0); + + if (m_currentPath->flags & FLAG_CAMP) { - // then make him move slow if near enemy - if (!(m_currentTravelFlags & PATHFLAG_JUMP)) + Vector dest; + + // switch from 1 direction to the other + if (m_campDirection < 1) { - if (m_currentWaypointIndex != -1) + dest.x = m_currentPath->campStartX; + dest.y = m_currentPath->campStartY; + + m_campDirection ^= 1; + } + else + { + dest.x = m_currentPath->campEndX; + dest.y = m_currentPath->campEndY; + m_campDirection ^= 1; + } + dest.z = 0.0f; + + // find a visible waypoint to this direction... + // i know this is ugly hack, but i just don't want to break compatiability :) + int numFoundPoints = 0; + int foundPoints[3]; + int distanceTab[3]; + + const Vector &dotA = (dest - pev->origin).Normalize2D (); + + for (int i = 0; i < g_numWaypoints; i++) + { + // skip invisible waypoints or current waypoint + if (!waypoint->IsVisible (m_currentWaypointIndex, i) || (i == m_currentWaypointIndex)) + continue; + + const Vector &dotB = (waypoint->GetPath (i)->origin - pev->origin).Normalize2D (); + + if ((dotA | dotB) > 0.9) { - if (m_currentPath->radius < 32 && !IsOnLadder () && !IsInWater () && m_seeEnemyTime + 4.0 > GetWorldTime () && m_difficulty == 0) - pev->button |= IN_DUCK; + int distance = static_cast ((pev->origin - waypoint->GetPath (i)->origin).GetLength ()); + + if (numFoundPoints >= 3) + { + for (int j = 0; j < 3; j++) + { + if (distance > distanceTab[j]) + { + distanceTab[j] = distance; + foundPoints[j] = i; + + break; + } + } + } + else + { + foundPoints[numFoundPoints] = i; + distanceTab[numFoundPoints] = distance; + + numFoundPoints++; + } } - - if ((m_lastEnemyOrigin - pev->origin).GetLength () < 512.0) - m_moveSpeed = GetWalkSpeed (); } + + if (--numFoundPoints >= 0) + m_camp = waypoint->GetPath (foundPoints[Random.Long (0, numFoundPoints)])->origin; + else + m_camp = waypoint->GetPath (GetAimingWaypoint ())->origin; } - break; + else + m_camp = waypoint->GetPath (GetAimingWaypoint ())->origin; + } + // press remembered crouch button + pev->button |= m_campButtons; - // bot seeks cover from enemy - case TASK_SEEKCOVER: - m_aimFlags |= AIM_NAVPOINT; + // stop camping if time over or gets hurt by something else than bullets + if ((GetTask ()->time < GetWorldTime ()) || (m_lastDamageType > 0)) + TaskComplete (); +} - if (IsEntityNull (m_lastEnemy) || !IsAlive (m_lastEnemy)) +void Bot::RunTask_Hide (void) +{ + m_aimFlags |= AIM_CAMP; + m_checkTerrain = false; + m_moveToGoal = false; + + // half the reaction time if camping + SetIdealReactionTimes (); + m_idealReactionTime *= 0.5f; + + m_navTimeset = GetWorldTime (); + m_moveSpeed = 0; + m_strafeSpeed = 0.0; + + GetValidWaypoint (); + + if (HasShield () && !m_isReloading) + { + if (!IsShieldDrawn ()) + pev->button |= IN_ATTACK2; // draw the shield! + else + pev->button |= IN_DUCK; // duck under if the shield is already drawn + } + + // if we see an enemy and aren't at a good camping point leave the spot + if ((m_states & STATE_SEEING_ENEMY) || m_inBombZone) + { + if (!(m_currentPath->flags & FLAG_CAMP)) { TaskComplete (); + + m_campButtons = 0; m_prevGoalIndex = -1; + + if (!IsEntityNull (m_enemy)) + CombatFight (); + + return; } - else if (DoWaypointNav ()) // reached final cover waypoint? - { - // yep. activate hide behaviour + } + else if (m_lastEnemyOrigin == nullvec) // If we don't have an enemy we're also free to leave + { + TaskComplete (); + + m_campButtons = 0; + m_prevGoalIndex = -1; + + if (GetTaskId () == TASK_HIDE) TaskComplete (); - m_prevGoalIndex = -1; - m_pathType = 0; + return; + } - // start hide task - PushTask (TASK_HIDE, TASKPRI_HIDE, -1, GetWorldTime () + Random.Float (5.0, 15.0), false); - destination = m_lastEnemyOrigin; + pev->button |= m_campButtons; + m_navTimeset = GetWorldTime (); - // get a valid look direction - GetCampDirection (&destination); + // stop camping if time over or gets hurt by something else than bullets + if (GetTask ()->time < GetWorldTime () || m_lastDamageType > 0) + TaskComplete (); +} - m_aimFlags |= AIM_CAMP; - m_camp = destination; - m_campDirection = 0; +void Bot::RunTask_MoveToPos (void) +{ + m_aimFlags |= AIM_NAVPOINT; - // chosen waypoint is a camp waypoint? - if (m_currentPath->flags & FLAG_CAMP) - { - // use the existing camp wpt prefs - if (m_currentPath->flags & FLAG_CROUCH) - m_campButtons = IN_DUCK; - else - m_campButtons = 0; - } - else - { - // choose a crouch or stand pos - if (m_currentPath->vis.crouch <= m_currentPath->vis.stand) - m_campButtons = IN_DUCK; - else - m_campButtons = 0; + if (IsShieldDrawn ()) + pev->button |= IN_ATTACK2; - // enter look direction from previously calculated positions - m_currentPath->campStartX = destination.x; - m_currentPath->campStartY = destination.y; + if (DoWaypointNav ()) // reached destination? + { + TaskComplete (); // we're done - m_currentPath->campStartX = destination.x; - m_currentPath->campEndY = destination.y; - } + m_prevGoalIndex = -1; + m_position = nullvec; + } + else if (!GoalIsValid ()) // didn't choose goal waypoint yet? + { + DeleteSearchNodes (); - if ((m_reloadState == RELOAD_NONE) && (GetAmmoInClip () < 8) && (GetAmmo () != 0)) - m_reloadState = RELOAD_PRIMARY; + int destIndex = -1; - m_moveSpeed = 0.0f; - m_strafeSpeed = 0.0f; + if (GetTask ()->data != -1 && GetTask ()->data < g_numWaypoints) + destIndex = GetTask ()->data; + else + destIndex = waypoint->FindNearest (m_position); - m_moveToGoal = false; - m_checkTerrain = true; - } - else if (!GoalIsValid ()) // we didn't choose a cover waypoint yet or lost it due to an attack? + if (destIndex >= 0 && destIndex < g_numWaypoints) { - DeleteSearchNodes (); - - if (GetTask ()->data != -1) - destIndex = GetTask ()->data; - else - { - destIndex = FindCoverWaypoint (1024); - - if (destIndex == -1) - destIndex = g_waypoint->FindNearest (pev->origin, 500); - } - - m_campDirection = 0; m_prevGoalIndex = destIndex; GetTask ()->data = destIndex; - if (destIndex != m_currentWaypointIndex) - FindPath (m_currentWaypointIndex, destIndex, 0); + FindPath (m_currentWaypointIndex, destIndex, m_pathType); } - break; + else + TaskComplete (); + } +} - // plain attacking - case TASK_ATTACK: - m_moveToGoal = false; - m_checkTerrain = false; +void Bot::RunTask_PlantBomb (void) +{ + m_aimFlags |= AIM_CAMP; - if (!IsEntityNull (m_enemy)) + if (m_hasC4) // we're still got the C4? + { + SelectWeaponByName ("weapon_c4"); + + if (IsAlive (m_enemy) || !m_inBombZone) + TaskComplete (); + else { - ResetCollideState (); - m_lastCollTime = GetWorldTime () + 0.5f; + m_moveToGoal = false; + m_checkTerrain = false; + m_navTimeset = GetWorldTime (); - if (IsOnLadder ()) + if (m_currentPath->flags & FLAG_CROUCH) + pev->button |= (IN_ATTACK | IN_DUCK); + else + pev->button |= IN_ATTACK; + + m_moveSpeed = 0; + m_strafeSpeed = 0; + } + } + else // done with planting + { + TaskComplete (); + + // tell teammates to move over here... + if (GetNearbyFriendsNearPosition (pev->origin, 1200) != 0) + RadioMessage (Radio_NeedBackup); + + DeleteSearchNodes (); + int index = FindDefendWaypoint (pev->origin); + + float bombTimer = mp_c4timer.GetFloat (); + + // push camp task on to stack + PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + (bombTimer * 0.5 + bombTimer * 0.25), true); + // push move command + PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + (bombTimer * 0.5 + bombTimer * 0.25), true); + + if (waypoint->GetPath (index)->vis.crouch <= waypoint->GetPath (index)->vis.stand) + m_campButtons |= IN_DUCK; + else + m_campButtons &= ~IN_DUCK; + } +} + +void Bot::RunTask_DefuseBomb (void) +{ + float fullDefuseTime = m_hasDefuser ? 6.0 : 11.0; + float timeToBlowUp = GetBombTimeleft (); + float defuseRemainingTime = fullDefuseTime; + + if (m_hasProgressBar /*&& IsOnFloor ()*/) + defuseRemainingTime = fullDefuseTime - GetWorldTime (); + + bool defuseError = false; + + // exception: bomb has been defused + if (waypoint->GetBombPosition () == nullvec) + { + defuseError = true; + g_bombPlanted = false; + + if (Random.Long (0, 100) < 50 && m_numFriendsLeft != 0) + { + if (timeToBlowUp <= 3.0) { - pev->button |= IN_JUMP; - DeleteSearchNodes (); + if (yb_communication_type.GetInt () == 2) + InstantChatterMessage (Chatter_BarelyDefused); + else if (yb_communication_type.GetInt () == 1) + RadioMessage (Radio_SectorClear); } - CombatFight (); + else + RadioMessage (Radio_SectorClear); + } + } + else if (defuseRemainingTime > timeToBlowUp) // exception: not time left for defusing + defuseError = true; + else if (m_states & STATE_SEEING_ENEMY) // exception: saw/seeing enemy + { + if (GetNearbyFriendsNearPosition (pev->origin, 128) == 0) + { + if (defuseRemainingTime > 0.75f) + { + if (GetNearbyFriendsNearPosition (pev->origin, 512.0f) > 0) + RadioMessage (Radio_NeedBackup); + + defuseError = true; + } + } + else if (timeToBlowUp > fullDefuseTime + 3.0 && defuseRemainingTime > 1.0) + defuseError = true; + } + else if (m_states & STATE_SUSPECT_ENEMY) // exception: suspect enemy + { + if (GetNearbyFriendsNearPosition (pev->origin, 128) == 0) + { + if (timeToBlowUp > fullDefuseTime + 10.0) + { + if (GetNearbyFriendsNearPosition (pev->origin, 512.0f) > 0) + RadioMessage (Radio_NeedBackup); + + defuseError = true; + } + } + } + + // one of exceptions is thrown. finish task. + if (defuseError) + { + m_checkTerrain = true; + m_moveToGoal = true; + + m_destOrigin = nullvec; + m_entity = nullvec; + + m_pickupItem = NULL; + m_pickupType = PICKUP_NONE; + + TaskComplete (); + return; + } + + // to revert from pause after reload waiting && just to be sure + m_moveToGoal = false; + m_checkTerrain = true; + + m_moveSpeed = pev->maxspeed; + m_strafeSpeed = 0.0; + + // bot is reloading and we close enough to start defusing + if (m_isReloading && (waypoint->GetBombPosition () - pev->origin).GetLength2D () < 80.0) + { + if (m_numEnemiesLeft == 0 || timeToBlowUp < fullDefuseTime + 7.0 || ((GetAmmoInClip () > 8 && m_reloadState == RELOAD_PRIMARY) || (GetAmmoInClip () > 5 && m_reloadState == RELOAD_SECONDARY))) + { + int weaponIndex = GetHighestWeapon (); + + // just select knife and then select weapon + SelectWeaponByName ("weapon_knife"); + + if (weaponIndex > 0 && weaponIndex < NUM_WEAPONS) + SelectWeaponbyNumber (weaponIndex); + + m_isReloading = false; + } + else // just wait here + { + m_moveToGoal = false; + m_checkTerrain = false; + + m_moveSpeed = 0.0; + m_strafeSpeed = 0.0; + } + } + + // head to bomb and press use button + m_aimFlags |= AIM_ENTITY; + + m_destOrigin = waypoint->GetBombPosition (); + m_entity = waypoint->GetBombPosition (); + + pev->button |= IN_USE; + + // if defusing is not already started, maybe crouch before + if (!m_hasProgressBar && m_duckDefuseCheckTime < GetWorldTime ()) + { + if (m_difficulty >= 2 && m_numEnemiesLeft != 0) + m_duckDefuse = true; + + Vector botDuckOrigin, botStandOrigin; + + if (pev->button & IN_DUCK) + { + botDuckOrigin = pev->origin; + botStandOrigin = pev->origin + Vector (0, 0, 18); } else { - TaskComplete (); - m_destOrigin = m_lastEnemyOrigin; + botDuckOrigin = pev->origin - Vector (0, 0, 18); + botStandOrigin = pev->origin; } - m_navTimeset = GetWorldTime (); - break; - // Bot is pausing - case TASK_PAUSE: + float duckLength = (m_entity - botDuckOrigin).GetLengthSquared (); + float standLength = (m_entity - botStandOrigin).GetLengthSquared (); + + if (duckLength > 5625 || standLength > 5625) + { + if (standLength < duckLength) + m_duckDefuse = false; // stand + else + m_duckDefuse = true; // duck + } + m_duckDefuseCheckTime = GetWorldTime () + 1.5; + } + + // press duck button + if (m_duckDefuse || (pev->oldbuttons & IN_DUCK)) + pev->button |= IN_DUCK; + else + pev->button &= ~IN_DUCK; + + // we are defusing bomb + if (m_hasProgressBar) + { + pev->button |= IN_USE; + + m_reloadState = RELOAD_NONE; + m_navTimeset = GetWorldTime (); + + // don't move when defusing + m_moveToGoal = false; + m_checkTerrain = false; + + m_moveSpeed = 0.0; + m_strafeSpeed = 0.0; + + // notify team + if (m_numFriendsLeft != 0) + { + ChatterMessage (Chatter_DefusingC4); + + if (GetNearbyFriendsNearPosition (pev->origin, 512.0f) < 2) + RadioMessage (Radio_NeedBackup); + } + } +} + +void Bot::RunTask_FollowUser (void) +{ + if (IsEntityNull (m_targetEntity) || !IsAlive (m_targetEntity)) + { + m_targetEntity = NULL; + TaskComplete (); + + return; + } + + if (m_targetEntity->v.button & IN_ATTACK) + { + MakeVectors (m_targetEntity->v.v_angle); + + TraceResult tr; + TraceLine (m_targetEntity->v.origin + m_targetEntity->v.view_ofs, g_pGlobals->v_forward * 500, true, true, GetEntity (), &tr); + + if (!IsEntityNull (tr.pHit) && IsValidPlayer (tr.pHit) && GetTeam (tr.pHit) != m_team) + { + m_targetEntity = NULL; + m_lastEnemy = tr.pHit; + m_lastEnemyOrigin = tr.pHit->v.origin; + + TaskComplete (); + return; + } + } + + if (m_targetEntity->v.maxspeed != 0 && m_targetEntity->v.maxspeed < pev->maxspeed) + m_moveSpeed = m_targetEntity->v.maxspeed; + + if (m_reloadState == RELOAD_NONE && GetAmmo () != 0) + m_reloadState = RELOAD_PRIMARY; + + if ((m_targetEntity->v.origin - pev->origin).GetLength () > 130) + m_followWaitTime = 0.0; + else + { + m_moveSpeed = 0.0; + + if (m_followWaitTime == 0.0) + m_followWaitTime = GetWorldTime (); + else + { + if (m_followWaitTime + 3.0 < GetWorldTime ()) + { + // stop following if we have been waiting too long + m_targetEntity = NULL; + + RadioMessage (Radio_YouTakePoint); + TaskComplete (); + + return; + } + } + } + m_aimFlags |= AIM_NAVPOINT; + + if (yb_walking_allowed.GetBool () && m_targetEntity->v.maxspeed < m_moveSpeed && !yb_jasonmode.GetBool ()) + m_moveSpeed = GetWalkSpeed (); + + if (IsShieldDrawn ()) + pev->button |= IN_ATTACK2; + + if (DoWaypointNav ()) // reached destination? + GetTask ()->data = -1; + + if (!GoalIsValid ()) // didn't choose goal waypoint yet? + { + DeleteSearchNodes (); + + int destIndex = waypoint->FindNearest (m_targetEntity->v.origin); + + Array points; + waypoint->FindInRadius (points, 200, m_targetEntity->v.origin); + + while (!points.IsEmpty ()) + { + int newIndex = points.Pop (); + + // if waypoint not yet used, assign it as dest + if (!IsPointOccupied (newIndex) && (newIndex != m_currentWaypointIndex)) + destIndex = newIndex; + } + + if (destIndex >= 0 && destIndex < g_numWaypoints && destIndex != m_currentWaypointIndex && m_currentWaypointIndex >= 0 && m_currentWaypointIndex < g_numWaypoints) + { + m_prevGoalIndex = destIndex; + GetTask ()->data = destIndex; + + // always take the shortest path + FindShortestPath (m_currentWaypointIndex, destIndex); + } + else + { + m_targetEntity = NULL; + TaskComplete (); + } + } +} + +void Bot::RunTask_Throw_HE (void) +{ + m_aimFlags |= AIM_GRENADE; + Vector dest = m_throw; + + if (!(m_states & STATE_SEEING_ENEMY)) + { + m_strafeSpeed = 0.0f; + m_moveSpeed = 0.0f; + m_moveToGoal = false; + } + else if (!(m_states & STATE_SUSPECT_ENEMY) && !IsEntityNull (m_enemy)) + dest = m_enemy->v.origin + (m_enemy->v.velocity.Get2D () * 0.5); + + m_isUsingGrenade = true; + m_checkTerrain = false; + + if ((pev->origin - dest).GetLengthSquared () < 400 * 400) + { + // heck, I don't wanna blow up myself + m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; + + SelectBestWeapon (); + TaskComplete (); + + return; + } + m_grenade = CheckThrow (EyePosition (), dest); + + if (m_grenade.GetLengthSquared () < 100) + m_grenade = CheckToss (EyePosition (), dest); + + if (m_grenade.GetLengthSquared () <= 100) + { + m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; + m_grenade = m_lookAt; + + SelectBestWeapon (); + TaskComplete (); + } + else + { + edict_t *ent = NULL; + + while (!IsEntityNull (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) + { + if (ent->v.owner == GetEntity () && strcmp (STRING (ent->v.model) + 9, "hegrenade.mdl") == 0) + { + // set the correct velocity for the grenade + if (m_grenade.GetLengthSquared () > 100) + ent->v.velocity = m_grenade; + + m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; + + SelectBestWeapon (); + TaskComplete (); + + break; + } + } + + if (IsEntityNull (ent)) + { + if (m_currentWeapon != WEAPON_EXPLOSIVE) + { + if (pev->weapons & (1 << WEAPON_EXPLOSIVE)) + SelectWeaponByName ("weapon_hegrenade"); + } + else if (!(pev->oldbuttons & IN_ATTACK)) + pev->button |= IN_ATTACK; + } + } + pev->button |= m_campButtons; +} + +void Bot::RunTask_Throw_FL (void) +{ + m_aimFlags |= AIM_GRENADE; + Vector dest = m_throw; + + if (!(m_states & STATE_SEEING_ENEMY)) + { + m_strafeSpeed = 0.0f; + m_moveSpeed = 0.0f; + } + else if (!(m_states & STATE_SUSPECT_ENEMY) && !IsEntityNull (m_enemy)) + dest = m_enemy->v.origin + (m_enemy->v.velocity.Get2D () * 0.5); + + m_isUsingGrenade = true; + m_checkTerrain = false; + + m_grenade = CheckThrow (EyePosition (), dest); + + if (m_grenade.GetLengthSquared () < 100) + m_grenade = CheckToss (pev->origin, dest); + + if (m_grenade.GetLengthSquared () <= 100) + { + m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; + m_grenade = m_lookAt; + + SelectBestWeapon (); + TaskComplete (); + } + else + { + edict_t *ent = NULL; + while (!IsEntityNull (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) + { + if (ent->v.owner == GetEntity () && strcmp (STRING (ent->v.model) + 9, "flashbang.mdl") == 0) + { + // set the correct velocity for the grenade + if (m_grenade.GetLengthSquared () > 100) + ent->v.velocity = m_grenade; + + m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; + + SelectBestWeapon (); + TaskComplete (); + break; + } + } + + if (IsEntityNull (ent)) + { + if (m_currentWeapon != WEAPON_FLASHBANG) + { + if (pev->weapons & (1 << WEAPON_FLASHBANG)) + SelectWeaponByName ("weapon_flashbang"); + } + else if (!(pev->oldbuttons & IN_ATTACK)) + pev->button |= IN_ATTACK; + } + } + pev->button |= m_campButtons; +} + +void Bot::RunTask_Throw_SG (void) +{ + m_aimFlags |= AIM_GRENADE; + + if (!(m_states & STATE_SEEING_ENEMY)) + { + m_strafeSpeed = 0.0f; + m_moveSpeed = 0.0f; + } + + m_checkTerrain = false; + m_isUsingGrenade = true; + + Vector src = m_lastEnemyOrigin - pev->velocity; + + // predict where the enemy is in 0.5 secs + if (!IsEntityNull (m_enemy)) + src = src + m_enemy->v.velocity * 0.5; + + m_grenade = (src - EyePosition ()).Normalize (); + + if (GetTask ()->time < GetWorldTime () + 0.5) + { + m_aimFlags &= ~AIM_GRENADE; + m_states &= ~STATE_THROW_SG; + + TaskComplete (); + return; + } + + if (m_currentWeapon != WEAPON_SMOKE) + { + if (pev->weapons & (1 << WEAPON_SMOKE)) + { + SelectWeaponByName ("weapon_smokegrenade"); + GetTask ()->time = GetWorldTime () + MAX_GRENADE_TIMER; + } + else + GetTask ()->time = GetWorldTime () + 0.1; + } + else if (!(pev->oldbuttons & IN_ATTACK)) + pev->button |= IN_ATTACK; +} + +void Bot::RunTask_DoubleJump (void) +{ + if (IsEntityNull (m_doubleJumpEntity) || !IsAlive (m_doubleJumpEntity) || (m_aimFlags & AIM_ENEMY) || (m_travelStartIndex != -1 && GetTask ()->time + (waypoint->GetTravelTime (pev->maxspeed, waypoint->GetPath (m_travelStartIndex)->origin, m_doubleJumpOrigin) + 11.0) < GetWorldTime ())) + { + ResetDoubleJumpState (); + return; + } + m_aimFlags |= AIM_NAVPOINT; + + if (m_jumpReady) + { m_moveToGoal = false; m_checkTerrain = false; @@ -3507,1130 +4287,453 @@ void Bot::RunTask (void) m_moveSpeed = 0.0; m_strafeSpeed = 0.0; - m_aimFlags |= AIM_NAVPOINT; + if (m_duckForJump < GetWorldTime ()) + pev->button |= IN_DUCK; - // is bot blinded and above average difficulty? - if (m_viewDistance < 500.0 && m_difficulty >= 2) + MakeVectors (nullvec); + + Vector dest = EyePosition () + g_pGlobals->v_forward * 500; + dest.z = 180.0; + + TraceResult tr; + TraceLine (EyePosition (), dest, false, true, GetEntity (), &tr); + + if ((tr.flFraction < 1.0) && (tr.pHit == m_doubleJumpEntity)) { - // go mad! - m_moveSpeed = -fabsf ((m_viewDistance - 500.0) * 0.5f); + if (m_doubleJumpEntity->v.button & IN_JUMP) + { + m_duckForJump = GetWorldTime () + Random.Float (3.0, 5.0); + GetTask ()->time = GetWorldTime (); + } + } + return; + } - if (m_moveSpeed < -pev->maxspeed) - m_moveSpeed = -pev->maxspeed; + if (m_currentWaypointIndex == m_prevGoalIndex) + { + m_waypointOrigin = m_doubleJumpOrigin; + m_destOrigin = m_doubleJumpOrigin; + } - MakeVectors (pev->v_angle); - m_camp = EyePosition () + (g_pGlobals->v_forward * 500); + if (DoWaypointNav ()) // reached destination? + GetTask ()->data = -1; - m_aimFlags |= AIM_OVERRIDE; - m_wantsToFire = true; + if (!GoalIsValid ()) // didn't choose goal waypoint yet? + { + DeleteSearchNodes (); + + int destIndex = waypoint->FindNearest (m_doubleJumpOrigin); + + if (destIndex >= 0 && destIndex < g_numWaypoints) + { + m_prevGoalIndex = destIndex; + GetTask ()->data = destIndex; + m_travelStartIndex = m_currentWaypointIndex; + + // Always take the shortest path + FindShortestPath (m_currentWaypointIndex, destIndex); + + if (m_currentWaypointIndex == destIndex) + m_jumpReady = true; } else - pev->button |= m_campButtons; + ResetDoubleJumpState (); + } +} - // stop camping if time over or gets hurt by something else than bullets - if (GetTask ()->time < GetWorldTime () || m_lastDamageType > 0) +void Bot::RunTask_EscapeFromBomb (void) +{ + m_aimFlags |= AIM_NAVPOINT; + + if (!g_bombPlanted) + TaskComplete (); + + if (IsShieldDrawn ()) + pev->button |= IN_ATTACK2; + + if (m_currentWeapon != WEAPON_KNIFE && m_numEnemiesLeft == 0) + SelectWeaponByName ("weapon_knife"); + + if (DoWaypointNav ()) // reached destination? + { + TaskComplete (); // we're done + + // press duck button if we still have some enemies + if (GetNearbyEnemiesNearPosition (pev->origin, 2048)) + m_campButtons = IN_DUCK; + + // we're reached destination point so just sit down and camp + PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + 10.0, true); + } + else if (!GoalIsValid ()) // didn't choose goal waypoint yet? + { + DeleteSearchNodes (); + + int lastSelectedGoal = -1; + float safeRadius = Random.Float (1248.0f, 2048.0f), minPathDistance = 99999.0f; + + for (int i = 0; i < g_numWaypoints; i++) + { + if ((waypoint->GetPath (i)->origin - waypoint->GetBombPosition ()).GetLength () < safeRadius || IsPointOccupied (i)) + continue; + + float pathDistance = waypoint->GetPathDistance (m_currentWaypointIndex, i); + + if (minPathDistance > pathDistance) + { + minPathDistance = pathDistance; + lastSelectedGoal = i; + } + } + + if (lastSelectedGoal < 0) + lastSelectedGoal = waypoint->FindFarest (pev->origin, safeRadius); + + m_prevGoalIndex = lastSelectedGoal; + GetTask ()->data = lastSelectedGoal; + + FindShortestPath (m_currentWaypointIndex, lastSelectedGoal); + } +} + +void Bot::RunTask_ShootBreakable (void) +{ + m_aimFlags |= AIM_OVERRIDE; + + // Breakable destroyed? + if (IsEntityNull (FindBreakable ())) + { + TaskComplete (); + return; + } + pev->button |= m_campButtons; + + m_checkTerrain = false; + m_moveToGoal = false; + m_navTimeset = GetWorldTime (); + + Vector src = m_breakable; + m_camp = src; + + // is bot facing the breakable? + if (GetShootingConeDeviation (GetEntity (), &src) >= 0.90) + { + m_moveSpeed = 0.0; + m_strafeSpeed = 0.0; + + if (m_currentWeapon == WEAPON_KNIFE) + SelectBestWeapon (); + + m_wantsToFire = true; + } + else + { + m_checkTerrain = true; + m_moveToGoal = true; + } +} + +void Bot::RunTask_PickupItem () +{ + if (IsEntityNull (m_pickupItem)) + { + m_pickupItem = NULL; + TaskComplete (); + + return; + } + Vector dest = GetEntityOrigin (m_pickupItem); + + m_destOrigin = dest; + m_entity = dest; + + // find the distance to the item + float itemDistance = (dest - pev->origin).GetLength (); + + switch (m_pickupType) + { + case PICKUP_WEAPON: + m_aimFlags |= AIM_NAVPOINT; + + // near to weapon? + if (itemDistance < 50) + { + for (int i = 0; i < 7; i++) + { + if (strcmp (g_weaponSelect[i].modelName, STRING (m_pickupItem->v.model) + 9) == 0) + break; + } + + if (i < 7) + { + // secondary weapon. i.e., pistol + int weaponID = 0; + + for (i = 0; i < 7; i++) + { + if (pev->weapons & (1 << g_weaponSelect[i].id)) + weaponID = i; + } + + if (weaponID > 0) + { + SelectWeaponbyNumber (weaponID); + FakeClientCommand (GetEntity (), "drop"); + + if (HasShield ()) // If we have the shield... + FakeClientCommand (GetEntity (), "drop"); // discard both shield and pistol + } + EquipInBuyzone (0); + } + else + { + // primary weapon + int weaponID = GetHighestWeapon (); + + if ((weaponID > 6) || HasShield ()) + { + SelectWeaponbyNumber (weaponID); + FakeClientCommand (GetEntity (), "drop"); + } + EquipInBuyzone (0); + } + CheckSilencer (); // check the silencer + } + break; + + case PICKUP_SHIELD: + m_aimFlags |= AIM_NAVPOINT; + + if (HasShield ()) + { + m_pickupItem = NULL; + break; + } + else if (itemDistance < 50) // near to shield? + { + // get current best weapon to check if it's a primary in need to be dropped + int weaponID = GetHighestWeapon (); + + if (weaponID > 6) + { + SelectWeaponbyNumber (weaponID); + FakeClientCommand (GetEntity (), "drop"); + } + } + break; + + case PICKUP_PLANTED_C4: + m_aimFlags |= AIM_ENTITY; + + if (m_team == TEAM_CF && itemDistance < 80.0f) + { + ChatterMessage (Chatter_DefusingC4); + + // notify team of defusing + if (m_numFriendsLeft < 3) + RadioMessage (Radio_NeedBackup); + + m_moveToGoal = false; + m_checkTerrain = false; + + m_moveSpeed = 0; + m_strafeSpeed = 0; + + PushTask (TASK_DEFUSEBOMB, TASKPRI_DEFUSEBOMB, -1, 0.0, false); + } + break; + + case PICKUP_HOSTAGE: + m_aimFlags |= AIM_ENTITY; + + if (!IsAlive (m_pickupItem)) + { + // don't pickup dead hostages + m_pickupItem = NULL; TaskComplete (); + + break; + } + + if (itemDistance < 50) + { + float angleToEntity = InFieldOfView (dest - EyePosition ()); + + if (angleToEntity <= 10) // bot faces hostage? + { + // use game dll function to make sure the hostage is correctly 'used' + MDLL_Use (m_pickupItem, GetEntity ()); + + if (Random.Long (0, 100) < 80) + ChatterMessage (Chatter_UseHostage); + + for (int i = 0; i < MAX_HOSTAGES; i++) + { + if (IsEntityNull (m_hostages[i])) // store pointer to hostage so other bots don't steal from this one or bot tries to reuse it + { + m_hostages[i] = m_pickupItem; + m_pickupItem = NULL; + + break; + } + } + } + m_lastCollTime = GetWorldTime () + 0.1; // also don't consider being stuck + } + break; + + case PICKUP_DEFUSEKIT: + m_aimFlags |= AIM_NAVPOINT; + + if (m_hasDefuser) + { + m_pickupItem = NULL; + m_pickupType = PICKUP_NONE; + } + break; + + case PICKUP_BUTTON: + m_aimFlags |= AIM_ENTITY; + + if (IsEntityNull (m_pickupItem) || m_buttonPushTime < GetWorldTime ()) // it's safer... + { + TaskComplete (); + m_pickupType = PICKUP_NONE; + + break; + } + + // find angles from bot origin to entity... + float angleToEntity = InFieldOfView (dest - EyePosition ()); + + if (itemDistance < 90) // near to the button? + { + m_moveSpeed = 0.0; + m_strafeSpeed = 0.0; + m_moveToGoal = false; + m_checkTerrain = false; + + if (angleToEntity <= 10) // facing it directly? + { + MDLL_Use (m_pickupItem, GetEntity ()); + + m_pickupItem = NULL; + m_pickupType = PICKUP_NONE; + m_buttonPushTime = GetWorldTime () + 3.0; + + TaskComplete (); + } + } + break; + } +} + +void Bot::RunTask (void) +{ + // this is core function that handle task execution + + switch (GetTaskId ()) + { + // normal task + default: + case TASK_NORMAL: + RunTask_Normal (); + break; + + // bot sprays messy logos all over the place... + case TASK_SPRAY: + RunTask_Spray (); + break; + + // hunt down enemy + case TASK_HUNTENEMY: + RunTask_HuntEnemy (); + break; + + // bot seeks cover from enemy + case TASK_SEEKCOVER: + RunTask_SeekCover (); + break; + + // plain attacking + case TASK_ATTACK: + RunTask_Attack (); + break; + + // Bot is pausing + case TASK_PAUSE: + RunTask_Pause (); break; // blinded (flashbanged) behaviour case TASK_BLINDED: - m_moveToGoal = false; - m_checkTerrain = false; - m_navTimeset = GetWorldTime (); - - // if bot remembers last enemy position - if (m_difficulty >= 2 && m_lastEnemyOrigin != nullvec && IsValidPlayer (m_lastEnemy) && !UsesSniper ()) - { - m_lookAt = m_lastEnemyOrigin; // face last enemy - m_wantsToFire = true; // and shoot it - } - - m_moveSpeed = m_blindMoveSpeed; - m_strafeSpeed = m_blindSidemoveSpeed; - pev->button |= m_blindButton; - - if (m_blindTime < GetWorldTime ()) - TaskComplete (); - + RunTask_Blinded (); break; // camping behaviour case TASK_CAMP: - m_aimFlags |= AIM_CAMP; - m_checkTerrain = false; - m_moveToGoal = false; - - if (g_bombPlanted && m_defendedBomb && !IsBombDefusing (g_waypoint->GetBombPosition ()) && !OutOfBombTimer () && m_team == TEAM_CF) - { - m_defendedBomb = false; - TaskComplete(); - } - - // half the reaction time if camping because you're more aware of enemies if camping - SetIdealReactionTimes (); - m_idealReactionTime *= 0.5f; - - m_navTimeset = GetWorldTime (); - m_timeCamping = GetWorldTime(); - - m_moveSpeed = 0; - m_strafeSpeed = 0.0; - - GetValidWaypoint (); - - if (m_nextCampDirTime < GetWorldTime ()) - { - m_nextCampDirTime = GetWorldTime () + Random.Float (2.0, 5.0); - - if (m_currentPath->flags & FLAG_CAMP) - { - destination.z = 0; - - // switch from 1 direction to the other - if (m_campDirection < 1) - { - destination.x = m_currentPath->campStartX; - destination.y = m_currentPath->campStartY; - m_campDirection ^= 1; - } - else - { - destination.x = m_currentPath->campEndX; - destination.y = m_currentPath->campEndY; - m_campDirection ^= 1; - } - - // find a visible waypoint to this direction... - // i know this is ugly hack, but i just don't want to break compatiability :) - int numFoundPoints = 0; - int foundPoints[3]; - int distanceTab[3]; - - const Vector &dotA = (destination - pev->origin).Normalize2D (); - - for (i = 0; i < g_numWaypoints; i++) - { - // skip invisible waypoints or current waypoint - if (!g_waypoint->IsVisible (m_currentWaypointIndex, i) || (i == m_currentWaypointIndex)) - continue; - - const Vector &dotB = (g_waypoint->GetPath (i)->origin - pev->origin).Normalize2D (); - - if ((dotA | dotB) > 0.9) - { - int distance = static_cast ((pev->origin - g_waypoint->GetPath (i)->origin).GetLength ()); - - if (numFoundPoints >= 3) - { - for (int j = 0; j < 3; j++) - { - if (distance > distanceTab[j]) - { - distanceTab[j] = distance; - foundPoints[j] = i; - - break; - } - } - } - else - { - foundPoints[numFoundPoints] = i; - distanceTab[numFoundPoints] = distance; - - numFoundPoints++; - } - } - } - - if (--numFoundPoints >= 0) - m_camp = g_waypoint->GetPath (foundPoints[Random.Long (0, numFoundPoints)])->origin; - else - m_camp = g_waypoint->GetPath (GetAimingWaypoint ())->origin; - } - else - m_camp = g_waypoint->GetPath (GetAimingWaypoint ())->origin; - } - // press remembered crouch button - pev->button |= m_campButtons; - - // stop camping if time over or gets hurt by something else than bullets - if ((GetTask ()->time < GetWorldTime ()) || (m_lastDamageType > 0)) - TaskComplete (); + RunTask_Camp (); break; // hiding behaviour case TASK_HIDE: - m_aimFlags |= AIM_CAMP; - m_checkTerrain = false; - m_moveToGoal = false; - - // half the reaction time if camping - SetIdealReactionTimes (); - m_idealReactionTime *= 0.5f; - - m_navTimeset = GetWorldTime (); - m_moveSpeed = 0; - m_strafeSpeed = 0.0; - - GetValidWaypoint (); - - if (HasShield () && !m_isReloading) - { - if (!IsShieldDrawn ()) - pev->button |= IN_ATTACK2; // draw the shield! - else - pev->button |= IN_DUCK; // duck under if the shield is already drawn - } - - // if we see an enemy and aren't at a good camping point leave the spot - if ((m_states & STATE_SEEING_ENEMY) || m_inBombZone) - { - if (!(m_currentPath->flags & FLAG_CAMP)) - { - TaskComplete (); - - m_campButtons = 0; - m_prevGoalIndex = -1; - - if (!IsEntityNull (m_enemy)) - CombatFight (); - - break; - } - } - else if (m_lastEnemyOrigin == nullvec) // If we don't have an enemy we're also free to leave - { - TaskComplete (); - - m_campButtons = 0; - m_prevGoalIndex = -1; - - if (GetTaskId () == TASK_HIDE) - TaskComplete (); - - break; - } - - pev->button |= m_campButtons; - m_navTimeset = GetWorldTime (); - - // stop camping if time over or gets hurt by something else than bullets - if (GetTask ()->time < GetWorldTime () || m_lastDamageType > 0) - TaskComplete (); - + RunTask_Hide (); break; // moves to a position specified in position has a higher priority than task_normal case TASK_MOVETOPOSITION: - m_aimFlags |= AIM_NAVPOINT; - - if (IsShieldDrawn ()) - pev->button |= IN_ATTACK2; - - if (DoWaypointNav ()) // reached destination? - { - TaskComplete (); // we're done - - m_prevGoalIndex = -1; - m_position = nullvec; - } - else if (!GoalIsValid ()) // didn't choose goal waypoint yet? - { - DeleteSearchNodes (); - - if (GetTask ()->data != -1 && GetTask ()->data < g_numWaypoints) - destIndex = GetTask ()->data; - else - destIndex = g_waypoint->FindNearest (m_position); - - if (destIndex >= 0 && destIndex < g_numWaypoints) - { - m_prevGoalIndex = destIndex; - GetTask ()->data = destIndex; - - FindPath (m_currentWaypointIndex, destIndex, m_pathType); - } - else - TaskComplete (); - } + RunTask_MoveToPos (); break; // planting the bomb right now case TASK_PLANTBOMB: - m_aimFlags |= AIM_CAMP; - - destination = m_lastEnemyOrigin; - GetCampDirection (&destination); - - if (m_hasC4) // we're still got the C4? - { - SelectWeaponByName ("weapon_c4"); - - if (IsAlive (m_enemy) || !m_inBombZone) - TaskComplete (); - else - { - m_moveToGoal = false; - m_checkTerrain = false; - m_navTimeset = GetWorldTime (); - - if (m_currentPath->flags & FLAG_CROUCH) - pev->button |= (IN_ATTACK | IN_DUCK); - else - pev->button |= IN_ATTACK; - - m_moveSpeed = 0; - m_strafeSpeed = 0; - } - } - else // done with planting - { - TaskComplete (); - - // tell teammates to move over here... - if (GetNearbyFriendsNearPosition (pev->origin, 1200) != 0) - RadioMessage (Radio_NeedBackup); - - DeleteSearchNodes (); - int index = FindDefendWaypoint (pev->origin); - - float bombTimer = mp_c4timer.GetFloat (); - - // push camp task on to stack - PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + (bombTimer * 0.5 + bombTimer * 0.25), true); - // push move command - PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, index, GetWorldTime () + (bombTimer * 0.5 + bombTimer * 0.25), true); - - if (g_waypoint->GetPath (index)->vis.crouch <= g_waypoint->GetPath (index)->vis.stand) - m_campButtons |= IN_DUCK; - else - m_campButtons &= ~IN_DUCK; - } + RunTask_PlantBomb (); break; // bomb defusing behaviour case TASK_DEFUSEBOMB: - fullDefuseTime = m_hasDefuser ? 6.0 : 11.0; - timeToBlowUp = GetBombTimeleft (); - defuseRemainingTime = fullDefuseTime; - - if (m_hasProgressBar /*&& IsOnFloor ()*/) - defuseRemainingTime = fullDefuseTime - GetWorldTime(); - - // exception: bomb has been defused - if (g_waypoint->GetBombPosition () == nullvec) - { - exceptionCaught = true; - g_bombPlanted = false; - - if (Random.Long (0, 100) < 50 && m_numFriendsLeft != 0) - { - if (timeToBlowUp <= 3.0) - { - if (yb_communication_type.GetInt () == 2) - InstantChatterMessage (Chatter_BarelyDefused); - else if (yb_communication_type. GetInt () == 1) - RadioMessage (Radio_SectorClear); - } - else - RadioMessage (Radio_SectorClear); - } - } - else if (defuseRemainingTime > timeToBlowUp) // exception: not time left for defusing - exceptionCaught = true; - else if (m_states & STATE_SEEING_ENEMY) // exception: saw/seeing enemy - { - if (GetNearbyFriendsNearPosition (pev->origin, 128) == 0) - { - if (defuseRemainingTime > 0.75f) - { - if (GetNearbyFriendsNearPosition (pev->origin, 512.0f) > 0) - RadioMessage (Radio_NeedBackup); - - exceptionCaught = true; - } - } - else if (timeToBlowUp > fullDefuseTime + 3.0 && defuseRemainingTime > 1.0) - exceptionCaught = true; - } - else if (m_states & STATE_SUSPECT_ENEMY) // exception: suspect enemy - { - if (GetNearbyFriendsNearPosition (pev->origin, 128) == 0) - { - if (timeToBlowUp > fullDefuseTime + 10.0) - { - if (GetNearbyFriendsNearPosition (pev->origin, 512.0f) > 0) - RadioMessage (Radio_NeedBackup); - - exceptionCaught = true; - } - } - } - - // one of exceptions is thrown. finish task. - if (exceptionCaught) - { - m_checkTerrain = true; - m_moveToGoal = true; - - m_destOrigin = nullvec; - m_entity = nullvec; - - m_pickupItem = NULL; - m_pickupType = PICKUP_NONE; - - TaskComplete (); - break; - } - - // to revert from pause after reload waiting && just to be sure - m_moveToGoal = false; - m_checkTerrain = true; - - m_moveSpeed = pev->maxspeed; - m_strafeSpeed = 0.0; - - // bot is reloading and we close enough to start defusing - if (m_isReloading && (g_waypoint->GetBombPosition () - pev->origin).GetLength2D () < 80.0) - { - if (m_numEnemiesLeft == 0 || timeToBlowUp < fullDefuseTime + 7.0 || ((GetAmmoInClip () > 8 && m_reloadState == RELOAD_PRIMARY) || (GetAmmoInClip () > 5 && m_reloadState == RELOAD_SECONDARY))) - { - int weaponIndex = GetHighestWeapon (); - - // just select knife and then select weapon - SelectWeaponByName ("weapon_knife"); - - if (weaponIndex > 0 && weaponIndex < NUM_WEAPONS) - SelectWeaponbyNumber (weaponIndex); - - m_isReloading = false; - } - else // just wait here - { - m_moveToGoal = false; - m_checkTerrain = false; - - m_moveSpeed = 0.0; - m_strafeSpeed = 0.0; - } - } - - // head to bomb and press use button - m_aimFlags |= AIM_ENTITY; - - m_destOrigin = g_waypoint->GetBombPosition (); - m_entity = g_waypoint->GetBombPosition (); - - pev->button |= IN_USE; - - // if defusing is not already started, maybe crouch before - if (!m_hasProgressBar && m_duckDefuseCheckTime < GetWorldTime ()) - { - if (m_difficulty >= 2 && m_numEnemiesLeft != 0) - m_duckDefuse = true; - - Vector botDuckOrigin, botStandOrigin; - - if (pev->button & IN_DUCK) - { - botDuckOrigin = pev->origin; - botStandOrigin = pev->origin + Vector(0, 0, 18); - } - else - { - botDuckOrigin = pev->origin - Vector(0, 0, 18); - botStandOrigin = pev->origin; - } - - float duckLength = (m_entity - botDuckOrigin).GetLengthSquared (); - float standLength = (m_entity - botStandOrigin).GetLengthSquared (); - - if (duckLength > 5625 || standLength > 5625) - { - if (standLength < duckLength) - m_duckDefuse = false; // stand - else - m_duckDefuse = true; // duck - } - m_duckDefuseCheckTime = GetWorldTime () + 1.5; - } - - // press duck button - if (m_duckDefuse || (pev->oldbuttons & IN_DUCK)) - pev->button |= IN_DUCK; - else - pev->button &= ~IN_DUCK; - - // we are defusing bomb - if (m_hasProgressBar) - { - pev->button |= IN_USE; - - m_reloadState = RELOAD_NONE; - m_navTimeset = GetWorldTime (); - - // don't move when defusing - m_moveToGoal = false; - m_checkTerrain = false; - - m_moveSpeed = 0.0; - m_strafeSpeed = 0.0; - - // notify team - if (m_numFriendsLeft != 0) - { - ChatterMessage (Chatter_DefusingC4); - - if (GetNearbyFriendsNearPosition (pev->origin, 512.0f) < 2) - RadioMessage (Radio_NeedBackup); - } - } + RunTask_DefuseBomb (); break; // follow user behaviour case TASK_FOLLOWUSER: - if (IsEntityNull (m_targetEntity) || !IsAlive (m_targetEntity)) - { - m_targetEntity = NULL; - TaskComplete (); - break; - } - - if (m_targetEntity->v.button & IN_ATTACK) - { - MakeVectors (m_targetEntity->v.v_angle); - TraceLine (m_targetEntity->v.origin + m_targetEntity->v.view_ofs, g_pGlobals->v_forward * 500, true, true, GetEntity (), &tr); - - if (!IsEntityNull (tr.pHit) && IsValidPlayer (tr.pHit) && GetTeam (tr.pHit) != m_team) - { - m_targetEntity = NULL; - m_lastEnemy = tr.pHit; - m_lastEnemyOrigin = tr.pHit->v.origin; - - TaskComplete (); - break; - } - } - - if (m_targetEntity->v.maxspeed != 0 && m_targetEntity->v.maxspeed < pev->maxspeed) - m_moveSpeed = m_targetEntity->v.maxspeed; - - if (m_reloadState == RELOAD_NONE && GetAmmo () != 0) - m_reloadState = RELOAD_PRIMARY; - - if ((m_targetEntity->v.origin - pev->origin).GetLength () > 130) - m_followWaitTime = 0.0; - else - { - m_moveSpeed = 0.0; - - if (m_followWaitTime == 0.0) - m_followWaitTime = GetWorldTime (); - else - { - if (m_followWaitTime + 3.0 < GetWorldTime ()) - { - // stop following if we have been waiting too long - m_targetEntity = NULL; - - RadioMessage (Radio_YouTakePoint); - TaskComplete (); - - break; - } - } - } - m_aimFlags |= AIM_NAVPOINT; - - if (yb_walking_allowed.GetBool () && m_targetEntity->v.maxspeed < m_moveSpeed && !yb_jasonmode.GetBool ()) - m_moveSpeed = GetWalkSpeed (); - - if (IsShieldDrawn ()) - pev->button |= IN_ATTACK2; - - if (DoWaypointNav ()) // reached destination? - GetTask ()->data = -1; - - if (!GoalIsValid ()) // didn't choose goal waypoint yet? - { - DeleteSearchNodes (); - - destIndex = g_waypoint->FindNearest (m_targetEntity->v.origin); - - Array points; - g_waypoint->FindInRadius (points, 200, m_targetEntity->v.origin); - - while (!points.IsEmpty ()) - { - int newIndex = points.Pop (); - - // if waypoint not yet used, assign it as dest - if (!IsPointOccupied (newIndex) && (newIndex != m_currentWaypointIndex)) - destIndex = newIndex; - } - - if (destIndex >= 0 && destIndex < g_numWaypoints && destIndex != m_currentWaypointIndex && m_currentWaypointIndex >= 0 && m_currentWaypointIndex < g_numWaypoints) - { - m_prevGoalIndex = destIndex; - GetTask ()->data = destIndex; - - // always take the shortest path - FindShortestPath (m_currentWaypointIndex, destIndex); - } - else - { - m_targetEntity = NULL; - TaskComplete (); - } - } + RunTask_FollowUser (); break; // HE grenade throw behaviour case TASK_THROWHEGRENADE: - m_aimFlags |= AIM_GRENADE; - destination = m_throw; - - if (!(m_states & STATE_SEEING_ENEMY)) - { - m_strafeSpeed = 0.0f; - m_moveSpeed = 0.0f; - m_moveToGoal = false; - } - else if (!(m_states & STATE_SUSPECT_ENEMY) && !IsEntityNull (m_enemy)) - destination = m_enemy->v.origin + (m_enemy->v.velocity.Get2D () * 0.5); - - m_isUsingGrenade = true; - m_checkTerrain = false; - - if ((pev->origin - destination).GetLengthSquared () < 400 * 400) - { - // heck, I don't wanna blow up myself - m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; - - SelectBestWeapon (); - TaskComplete (); - - break; - } - - m_grenade = CheckThrow (EyePosition (), destination); - - if (m_grenade.GetLengthSquared () < 100) - m_grenade = CheckToss (EyePosition (), destination); - - if (m_grenade.GetLengthSquared () <= 100) - { - m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; - m_grenade = m_lookAt; - - SelectBestWeapon (); - TaskComplete (); - } - else - { - edict_t *ent = NULL; - - while (!IsEntityNull (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) - { - if (ent->v.owner == GetEntity () && strcmp (STRING (ent->v.model) + 9, "hegrenade.mdl") == 0) - { - // set the correct velocity for the grenade - if (m_grenade.GetLengthSquared () > 100) - ent->v.velocity = m_grenade; - - m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; - - SelectBestWeapon (); - TaskComplete (); - - break; - } - } - - if (IsEntityNull (ent)) - { - if (m_currentWeapon != WEAPON_EXPLOSIVE) - { - if (pev->weapons & (1 << WEAPON_EXPLOSIVE)) - SelectWeaponByName ("weapon_hegrenade"); - } - else if (!(pev->oldbuttons & IN_ATTACK)) - pev->button |= IN_ATTACK; - } - } - pev->button |= m_campButtons; + RunTask_Throw_HE (); break; // flashbang throw behavior (basically the same code like for HE's) case TASK_THROWFLASHBANG: - m_aimFlags |= AIM_GRENADE; - destination = m_throw; - - if (!(m_states & STATE_SEEING_ENEMY)) - { - m_strafeSpeed = 0.0f; - m_moveSpeed = 0.0f; - } - else if (!(m_states & STATE_SUSPECT_ENEMY) && !IsEntityNull (m_enemy)) - destination = m_enemy->v.origin + (m_enemy->v.velocity.Get2D () * 0.5); - - m_isUsingGrenade = true; - m_checkTerrain = false; - - m_grenade = CheckThrow (EyePosition (), destination); - - if (m_grenade.GetLengthSquared () < 100) - m_grenade = CheckToss (pev->origin, destination); - - if (m_grenade.GetLengthSquared () <= 100) - { - m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; - m_grenade = m_lookAt; - - SelectBestWeapon (); - TaskComplete (); - } - else - { - edict_t *ent = NULL; - while (!IsEntityNull (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) - { - if (ent->v.owner == GetEntity () && strcmp (STRING (ent->v.model) + 9, "flashbang.mdl") == 0) - { - // set the correct velocity for the grenade - if (m_grenade.GetLengthSquared () > 100) - ent->v.velocity = m_grenade; - - m_grenadeCheckTime = GetWorldTime () + MAX_GRENADE_TIMER; - - SelectBestWeapon (); - TaskComplete (); - break; - } - } - - if (IsEntityNull (ent)) - { - if (m_currentWeapon != WEAPON_FLASHBANG) - { - if (pev->weapons & (1 << WEAPON_FLASHBANG)) - SelectWeaponByName ("weapon_flashbang"); - } - else if (!(pev->oldbuttons & IN_ATTACK)) - pev->button |= IN_ATTACK; - } - } - pev->button |= m_campButtons; + RunTask_Throw_FL (); break; // smoke grenade throw behavior // a bit different to the others because it mostly tries to throw the sg on the ground case TASK_THROWSMOKE: - m_aimFlags |= AIM_GRENADE; - - if (!(m_states & STATE_SEEING_ENEMY)) - { - m_strafeSpeed = 0.0f; - m_moveSpeed = 0.0f; - } - - m_checkTerrain = false; - m_isUsingGrenade = true; - - src = m_lastEnemyOrigin - pev->velocity; - - // predict where the enemy is in 0.5 secs - if (!IsEntityNull (m_enemy)) - src = src + m_enemy->v.velocity * 0.5; - - m_grenade = (src - EyePosition ()).Normalize (); - - if (GetTask ()->time < GetWorldTime () + 0.5) - { - m_aimFlags &= ~AIM_GRENADE; - m_states &= ~STATE_THROW_SG; - - TaskComplete (); - break; - } - - if (m_currentWeapon != WEAPON_SMOKE) - { - if (pev->weapons & (1 << WEAPON_SMOKE)) - { - SelectWeaponByName ("weapon_smokegrenade"); - GetTask ()->time = GetWorldTime () + MAX_GRENADE_TIMER; - } - else - GetTask ()->time = GetWorldTime () + 0.1; - } - else if (!(pev->oldbuttons & IN_ATTACK)) - pev->button |= IN_ATTACK; + RunTask_Throw_SG (); break; // bot helps human player (or other bot) to get somewhere case TASK_DOUBLEJUMP: - if (IsEntityNull (m_doubleJumpEntity) || !IsAlive (m_doubleJumpEntity) || (m_aimFlags & AIM_ENEMY) || (m_travelStartIndex != -1 && GetTask ()->time + (g_waypoint->GetTravelTime (pev->maxspeed, g_waypoint->GetPath (m_travelStartIndex)->origin, m_doubleJumpOrigin) + 11.0) < GetWorldTime ())) - { - ResetDoubleJumpState (); - break; - } - m_aimFlags |= AIM_NAVPOINT; - - if (m_jumpReady) - { - m_moveToGoal = false; - m_checkTerrain = false; - - m_navTimeset = GetWorldTime (); - m_moveSpeed = 0.0; - m_strafeSpeed = 0.0; - - if (m_duckForJump < GetWorldTime ()) - pev->button |= IN_DUCK; - - MakeVectors (nullvec); - - Vector dest = EyePosition () + g_pGlobals->v_forward * 500; - dest.z = 180.0; - - TraceLine (EyePosition (), dest, false, true, GetEntity (), &tr); - - if ((tr.flFraction < 1.0) && (tr.pHit == m_doubleJumpEntity)) - { - if (m_doubleJumpEntity->v.button & IN_JUMP) - { - m_duckForJump = GetWorldTime () + Random.Float (3.0, 5.0); - GetTask ()->time = GetWorldTime (); - } - } - break; - } - - if (m_currentWaypointIndex == m_prevGoalIndex) - { - m_waypointOrigin = m_doubleJumpOrigin; - m_destOrigin = m_doubleJumpOrigin; - } - - if (DoWaypointNav ()) // reached destination? - GetTask ()->data = -1; - - if (!GoalIsValid ()) // didn't choose goal waypoint yet? - { - DeleteSearchNodes (); - - destIndex = g_waypoint->FindNearest (m_doubleJumpOrigin); - - if (destIndex >= 0 && destIndex < g_numWaypoints) - { - m_prevGoalIndex = destIndex; - GetTask ()->data = destIndex; - m_travelStartIndex = m_currentWaypointIndex; - - // Always take the shortest path - FindShortestPath (m_currentWaypointIndex, destIndex); - - if (m_currentWaypointIndex == destIndex) - m_jumpReady = true; - } - else - ResetDoubleJumpState (); - } + RunTask_DoubleJump (); break; // escape from bomb behaviour case TASK_ESCAPEFROMBOMB: - m_aimFlags |= AIM_NAVPOINT; - - if (!g_bombPlanted) - TaskComplete (); - - if (IsShieldDrawn ()) - pev->button |= IN_ATTACK2; - - if (m_currentWeapon != WEAPON_KNIFE && m_numEnemiesLeft == 0) - SelectWeaponByName ("weapon_knife"); - - if (DoWaypointNav ()) // reached destination? - { - TaskComplete (); // we're done - - // press duck button if we still have some enemies - if (GetNearbyEnemiesNearPosition (pev->origin, 2048)) - m_campButtons = IN_DUCK; - - // we're reached destination point so just sit down and camp - PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + 10.0, true); - } - else if (!GoalIsValid ()) // didn't choose goal waypoint yet? - { - DeleteSearchNodes (); - - int lastSelectedGoal = -1; - float safeRadius = Random.Float (1024.0, 2048.0), minPathDistance = 4096.0; - - for (i = 0; i < g_numWaypoints; i++) - { - if ((g_waypoint->GetPath (i)->origin - g_waypoint->GetBombPosition ()).GetLength () < safeRadius) - continue; - - float pathDistance = g_waypoint->GetPathDistance (m_currentWaypointIndex, i); - - if (minPathDistance > pathDistance) - { - minPathDistance = pathDistance; - lastSelectedGoal = i; - } - } - - if (lastSelectedGoal < 0) - lastSelectedGoal = g_waypoint->FindFarest (pev->origin, safeRadius); - - m_prevGoalIndex = lastSelectedGoal; - GetTask ()->data = lastSelectedGoal; - - FindShortestPath (m_currentWaypointIndex, lastSelectedGoal); - } + RunTask_EscapeFromBomb (); break; // shooting breakables in the way action case TASK_SHOOTBREAKABLE: - m_aimFlags |= AIM_OVERRIDE; - - // Breakable destroyed? - if (IsEntityNull (FindBreakable ())) - { - TaskComplete (); - break; - } - pev->button |= m_campButtons; - - m_checkTerrain = false; - m_moveToGoal = false; - m_navTimeset = GetWorldTime (); - - src = m_breakable; - m_camp = src; - - // is bot facing the breakable? - if (GetShootingConeDeviation (GetEntity (), &src) >= 0.90) - { - m_moveSpeed = 0.0; - m_strafeSpeed = 0.0; - - if (m_currentWeapon == WEAPON_KNIFE) - SelectBestWeapon (); - - m_wantsToFire = true; - } - else - { - m_checkTerrain = true; - m_moveToGoal = true; - } + RunTask_ShootBreakable (); break; // picking up items and stuff behaviour case TASK_PICKUPITEM: - if (IsEntityNull (m_pickupItem)) - { - m_pickupItem = NULL; - TaskComplete (); - - break; - } - - if (m_pickupType == PICKUP_HOSTAGE) - destination = m_pickupItem->v.origin + pev->view_ofs; - else - destination = GetEntityOrigin (m_pickupItem); - - m_destOrigin = destination; - m_entity = destination; - - // find the distance to the item - float itemDistance = (destination - pev->origin).GetLength (); - - switch (m_pickupType) - { - case PICKUP_WEAPON: - m_aimFlags |= AIM_NAVPOINT; - - // near to weapon? - if (itemDistance < 50) - { - for (i = 0; i < 7; i++) - { - if (strcmp (g_weaponSelect[i].modelName, STRING (m_pickupItem->v.model) + 9) == 0) - break; - } - - if (i < 7) - { - // secondary weapon. i.e., pistol - int weaponID = 0; - - for (i = 0; i < 7; i++) - { - if (pev->weapons & (1 << g_weaponSelect[i].id)) - weaponID = i; - } - - if (weaponID > 0) - { - SelectWeaponbyNumber (weaponID); - FakeClientCommand (GetEntity (), "drop"); - - if (HasShield ()) // If we have the shield... - FakeClientCommand (GetEntity (), "drop"); // discard both shield and pistol - } - EquipInBuyzone (0); - } - else - { - // primary weapon - int weaponID = GetHighestWeapon (); - - if ((weaponID > 6) || HasShield ()) - { - SelectWeaponbyNumber (weaponID); - FakeClientCommand (GetEntity (), "drop"); - } - EquipInBuyzone (0); - } - CheckSilencer (); // check the silencer - } - break; - - case PICKUP_SHIELD: - m_aimFlags |= AIM_NAVPOINT; - - if (HasShield ()) - { - m_pickupItem = NULL; - break; - } - else if (itemDistance < 50) // near to shield? - { - // get current best weapon to check if it's a primary in need to be dropped - int weaponID = GetHighestWeapon (); - - if (weaponID > 6) - { - SelectWeaponbyNumber (weaponID); - FakeClientCommand (GetEntity (), "drop"); - } - } - break; - - case PICKUP_PLANTED_C4: - m_aimFlags |= AIM_ENTITY; - - if (m_team == TEAM_CF && itemDistance < 80.0f) - { - ChatterMessage (Chatter_DefusingC4); - - // notify team of defusing - if (m_numFriendsLeft < 3) - RadioMessage (Radio_NeedBackup); - - m_moveToGoal = false; - m_checkTerrain = false; - - m_moveSpeed = 0; - m_strafeSpeed = 0; - - PushTask (TASK_DEFUSEBOMB, TASKPRI_DEFUSEBOMB, -1, 0.0, false); - } - break; - - case PICKUP_HOSTAGE: - m_aimFlags |= AIM_ENTITY; - src = EyePosition (); - - if (!IsAlive (m_pickupItem)) - { - // don't pickup dead hostages - m_pickupItem = NULL; - TaskComplete (); - - break; - } - - if (itemDistance < 50) - { - float angleToEntity = InFieldOfView (destination - src); - - if (angleToEntity <= 10) // bot faces hostage? - { - // use game dll function to make sure the hostage is correctly 'used' - MDLL_Use (m_pickupItem, GetEntity ()); - - if (Random.Long (0, 100) < 80) - ChatterMessage (Chatter_UseHostage); - - for (i = 0; i < MAX_HOSTAGES; i++) - { - if (IsEntityNull (m_hostages[i])) // store pointer to hostage so other bots don't steal from this one or bot tries to reuse it - { - m_hostages[i] = m_pickupItem; - m_pickupItem = NULL; - - break; - } - } - } - m_lastCollTime = GetWorldTime () + 0.1; // also don't consider being stuck - } - break; - - case PICKUP_DEFUSEKIT: - m_aimFlags |= AIM_NAVPOINT; - - if (m_hasDefuser) - { - m_pickupItem = NULL; - m_pickupType = PICKUP_NONE; - } - break; - - case PICKUP_BUTTON: - m_aimFlags |= AIM_ENTITY; - - if (IsEntityNull (m_pickupItem) || m_buttonPushTime < GetWorldTime ()) // it's safer... - { - TaskComplete (); - m_pickupType = PICKUP_NONE; - - break; - } - - // find angles from bot origin to entity... - src = EyePosition (); - float angleToEntity = InFieldOfView (destination - src); - - if (itemDistance < 90) // near to the button? - { - m_moveSpeed = 0.0; - m_strafeSpeed = 0.0; - m_moveToGoal = false; - m_checkTerrain = false; - - if (angleToEntity <= 10) // facing it directly? - { - MDLL_Use (m_pickupItem, GetEntity ()); - - m_pickupItem = NULL; - m_pickupType = PICKUP_NONE; - m_buttonPushTime = GetWorldTime () + 3.0; - - TaskComplete (); - } - } - break; - } + RunTask_PickupItem (); break; } } @@ -5122,12 +5225,12 @@ void Bot::BotAI (void) while (node != NULL) { - const Vector &srcPath = g_waypoint->GetPath (node->index)->origin; + const Vector &srcPath = waypoint->GetPath (node->index)->origin; node = node->next; if (node != NULL) { - const Vector &dstPath = g_waypoint->GetPath (node->index)->origin; + const Vector &dstPath = waypoint->GetPath (node->index)->origin; DrawArrow (g_hostEntity, srcPath, dstPath, 15, 0, 255, 100, 55, 200, 5, 1); } } @@ -5179,7 +5282,7 @@ void Bot::TakeDamage (edict_t *inflictor, int damage, int armor, int bits) if (m_seeEnemyTime + 4.0f < GetWorldTime () && IsValidPlayer (inflictor)) { - if (GetTeam (inflictor) == m_team && yb_tkpunish.GetBool () && !g_botManager->GetBot (inflictor)) + if (GetTeam (inflictor) == m_team && yb_tkpunish.GetBool () && !botMgr->GetBot (inflictor)) { // alright, die you teamkiller!!! m_actualReactionTime = 0.0f; @@ -5229,7 +5332,7 @@ void Bot::TakeDamage (edict_t *inflictor, int damage, int armor, int bits) else // hurt by unusual damage like drowning or gas { // leave the camping/hiding position - if (!g_waypoint->Reachable (this, g_waypoint->FindNearest (m_destOrigin))) + if (!waypoint->Reachable (this, waypoint->FindNearest (m_destOrigin))) { DeleteSearchNodes (); FindWaypoint (); @@ -5339,14 +5442,14 @@ void Bot::CollectExperienceData (edict_t *attacker, int damage) // if these are bots also remember damage to rank destination of the bot m_goalValue -= static_cast (damage); - if (g_botManager->GetBot (attacker) != NULL) - g_botManager->GetBot (attacker)->m_goalValue += static_cast (damage); + if (botMgr->GetBot (attacker) != NULL) + botMgr->GetBot (attacker)->m_goalValue += static_cast (damage); if (damage < 20) return; // do not collect damage less than 20 - int attackerIndex = g_waypoint->FindNearest (attacker->v.origin); - int victimIndex = g_waypoint->FindNearest (pev->origin); + int attackerIndex = waypoint->FindNearest (attacker->v.origin); + int victimIndex = waypoint->FindNearest (pev->origin); if (pev->health > 20) { @@ -5611,9 +5714,9 @@ Vector Bot::CheckBombAudible (void) return nullvec; // reliability check if (m_difficulty >= 3) - return g_waypoint->GetBombPosition(); + return waypoint->GetBombPosition(); - const Vector &bombOrigin = g_waypoint->GetBombPosition (); + const Vector &bombOrigin = waypoint->GetBombPosition (); float timeElapsed = ((GetWorldTime () - g_timeBombPlanted) / mp_c4timer.GetFloat ()) * 100; float desiredRadius = 768.0; @@ -5640,7 +5743,7 @@ void Bot::MoveToVector (const Vector &to) if (to == nullvec) return; - FindPath (m_currentWaypointIndex, g_waypoint->FindNearest (to), 0); + FindPath (m_currentWaypointIndex, waypoint->FindNearest (to), 0); } byte Bot::ThrottledMsec (void) @@ -5753,7 +5856,7 @@ float Bot::GetEstimatedReachTime (void) // calculate 'real' time that we need to get from one waypoint to another if (m_currentWaypointIndex >= 0 && m_currentWaypointIndex < g_numWaypoints && m_prevWptIndex[0] >= 0 && m_prevWptIndex[0] < g_numWaypoints) { - float distance = (g_waypoint->GetPath (m_prevWptIndex[0])->origin - m_currentPath->origin).GetLength (); + float distance = (waypoint->GetPath (m_prevWptIndex[0])->origin - m_currentPath->origin).GetLength (); // caclulate estimated time if (pev->maxspeed <= 0.0) @@ -5788,7 +5891,7 @@ bool Bot::OutOfBombTimer (void) if (timeLeft > 16) return false; - const Vector &bombOrigin = g_waypoint->GetBombPosition (); + const Vector &bombOrigin = waypoint->GetBombPosition (); // for terrorist, if timer is lower than eleven seconds, return true if (static_cast (timeLeft) < 16 && m_team == TEAM_TF && (bombOrigin - pev->origin).GetLength () < 1000) @@ -5802,7 +5905,7 @@ bool Bot::OutOfBombTimer (void) Bot *bot = NULL; // temporaly pointer to bot // search players with defuse kit - if ((bot = g_botManager->GetBot (i)) != NULL && GetTeam (bot->GetEntity ()) == TEAM_CF && bot->m_hasDefuser && (bombOrigin - bot->pev->origin).GetLength () < 500) + if ((bot = botMgr->GetBot (i)) != NULL && GetTeam (bot->GetEntity ()) == TEAM_CF && bot->m_hasDefuser && (bombOrigin - bot->pev->origin).GetLength () < 500) { hasTeammatesWithDefuserKit = true; break; @@ -5810,7 +5913,7 @@ bool Bot::OutOfBombTimer (void) } // add reach time to left time - float reachTime = g_waypoint->GetTravelTime (pev->maxspeed, m_currentPath->origin, bombOrigin); + float reachTime = waypoint->GetTravelTime (pev->maxspeed, m_currentPath->origin, bombOrigin); // for counter-terrorist check alos is we have time to reach position plus average defuse time if ((timeLeft < reachTime + 6 && !m_hasDefuser && !hasTeammatesWithDefuserKit) || (timeLeft < reachTime + 2 && m_hasDefuser)) @@ -5985,7 +6088,7 @@ bool Bot::IsBombDefusing (const Vector &bombOrigin) for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot == NULL || bot == this) continue; // skip invalid bots diff --git a/source/combat.cpp b/source/combat.cpp index 94fd904..fa73c31 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -358,7 +358,7 @@ bool Bot::LookupEnemy (void) if (!(g_clients[j].flags & CF_USED) || !(g_clients[j].flags & CF_ALIVE) || g_clients[j].team != m_team || g_clients[j].ent == GetEntity ()) continue; - Bot *friendBot = g_botManager->GetBot (g_clients[j].ent); + Bot *friendBot = botMgr->GetBot (g_clients[j].ent); if (friendBot != NULL) { @@ -1211,7 +1211,7 @@ void Bot::CombatFight (void) if (!IsVisible (m_enemy->v.origin, GetEntity ()) && !IsVisible (m_enemy->v.origin + Vector (0, 0, -enemyHalfHeight), GetEntity ())) shouldDuck = false; - if (shouldDuck && GetTaskId () != TASK_SEEKCOVER && GetTaskId () != TASK_HUNTENEMY && (m_visibility & VISIBLE_BODY) && !(m_visibility & VISIBLE_OTHER) && g_waypoint->IsDuckVisible (m_currentWaypointIndex, g_waypoint->FindNearest (m_enemy->v.origin))) + if (shouldDuck && GetTaskId () != TASK_SEEKCOVER && GetTaskId () != TASK_HUNTENEMY && (m_visibility & VISIBLE_BODY) && !(m_visibility & VISIBLE_OTHER) && waypoint->IsDuckVisible (m_currentWaypointIndex, waypoint->FindNearest (m_enemy->v.origin))) m_duckTime = GetWorldTime () + 0.5f; m_moveSpeed = 0.0; @@ -1576,7 +1576,7 @@ void Bot::CheckReload (void) return; } - m_isReloading = false; // update reloading status + m_isReloading = false; // update reloading status m_reloadCheckTime = GetWorldTime () + 3.0; if (m_reloadState != RELOAD_NONE) diff --git a/source/interface.cpp b/source/interface.cpp index 5a08898..6dc55b3 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -22,55 +22,55 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c { // adding one bot with random parameters to random team if (stricmp (arg0, "addbot") == 0 || stricmp (arg0, "add") == 0) - g_botManager->AddBot (arg4, arg1, arg2, arg3, arg5); + botMgr->AddBot (arg4, arg1, arg2, arg3, arg5); // adding one bot with high difficulty parameters to random team else if (stricmp (arg0, "addbot_hs") == 0 || stricmp (arg0, "addhs") == 0) - g_botManager->AddBot (arg4, "4", "1", arg3, arg5); + botMgr->AddBot (arg4, "4", "1", arg3, arg5); // adding one bot with random parameters to terrorist team else if (stricmp (arg0, "addbot_t") == 0 || stricmp (arg0, "add_t") == 0) - g_botManager->AddBot (arg4, arg1, arg2, "1", arg5); + botMgr->AddBot (arg4, arg1, arg2, "1", arg5); // adding one bot with random parameters to counter-terrorist team else if (stricmp (arg0, "addbot_ct") == 0 || stricmp (arg0, "add_ct") == 0) - g_botManager->AddBot (arg4, arg1, arg2, "2", arg5); + botMgr->AddBot (arg4, arg1, arg2, "2", arg5); // kicking off one bot from the terrorist team else if (stricmp (arg0, "kickbot_t") == 0 || stricmp (arg0, "kick_t") == 0) - g_botManager->RemoveFromTeam (TEAM_TF); + botMgr->RemoveFromTeam (TEAM_TF); // kicking off one bot from the counter-terrorist team else if (stricmp (arg0, "kickbot_ct") == 0 || stricmp (arg0, "kick_ct") == 0) - g_botManager->RemoveFromTeam (TEAM_CF); + botMgr->RemoveFromTeam (TEAM_CF); // kills all bots on the terrorist team else if (stricmp (arg0, "killbots_t") == 0 || stricmp (arg0, "kill_t") == 0) - g_botManager->KillAll (TEAM_TF); + botMgr->KillAll (TEAM_TF); // kills all bots on the counter-terrorist team else if (stricmp (arg0, "killbots_ct") == 0 || stricmp (arg0, "kill_ct") == 0) - g_botManager->KillAll (TEAM_CF); + botMgr->KillAll (TEAM_CF); // list all bots playeing on the server else if (stricmp (arg0, "listbots") == 0 || stricmp (arg0, "list") == 0) - g_botManager->ListBots (); + botMgr->ListBots (); // kick off all bots from the played server else if (stricmp (arg0, "kickbots") == 0 || stricmp (arg0, "kickall") == 0) - g_botManager->RemoveAll (); + botMgr->RemoveAll (); // kill all bots on the played server else if (stricmp (arg0, "killbots") == 0 || stricmp (arg0, "killall") == 0) - g_botManager->KillAll (); + botMgr->KillAll (); // kick off one random bot from the played server else if (stricmp (arg0, "kickone") == 0 || stricmp (arg0, "kick") == 0) - g_botManager->RemoveRandom (); + botMgr->RemoveRandom (); // fill played server with bots else if (stricmp (arg0, "fillserver") == 0 || stricmp (arg0, "fill") == 0) - g_botManager->FillServer (atoi (arg1), IsNullString (arg2) ? -1 : atoi (arg2), IsNullString (arg3) ? -1 : atoi (arg3), IsNullString (arg4) ? -1 : atoi (arg4)); + botMgr->FillServer (atoi (arg1), IsNullString (arg2) ? -1 : atoi (arg2), IsNullString (arg3) ? -1 : atoi (arg3), IsNullString (arg4) ? -1 : atoi (arg4)); // select the weapon mode for bots else if (stricmp (arg0, "weaponmode") == 0 || stricmp (arg0, "wmode") == 0) @@ -79,7 +79,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c // check is selected range valid if (selection >= 1 && selection <= 7) - g_botManager->SetWeaponMode (selection); + botMgr->SetWeaponMode (selection); else ClientPrint (ent, print_withtag, "Choose weapon from 1 to 7 range"); } @@ -94,8 +94,8 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c // loop through all players for (int i = 0; i < GetMaxClients (); i++) { - if (g_botManager->GetBot (i) != NULL) - g_botManager->GetBot (i)->m_voteMap = nominatedMap; + if (botMgr->GetBot (i) != NULL) + botMgr->GetBot (i)->m_voteMap = nominatedMap; } ClientPrint (ent, print_withtag, "All dead bots will vote for map #%d", nominatedMap); } @@ -258,7 +258,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c // show direction to specified waypoint else if (stricmp (arg1, "find") == 0) - g_waypoint->SetFindIndex (atoi (arg2)); + waypoint->SetFindIndex (atoi (arg2)); // opens adding waypoint menu else if (stricmp (arg1, "add") == 0) @@ -270,7 +270,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c // creates basic waypoints on the map (ladder/spawn points/goals) else if (stricmp (arg1, "addbasic") == 0) { - g_waypoint->CreateBasic (); + waypoint->CreateBasic (); CenterPrint ("Basic waypoints was Created"); } @@ -278,41 +278,41 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c else if (stricmp (arg1, "delete") == 0) { g_waypointOn = true; // turn waypoints on - g_waypoint->Delete (); + waypoint->Delete (); } // save waypoint data into file on hard disk else if (stricmp (arg1, "save") == 0) { - char *waypointSaveMessage = g_localizer->TranslateInput ("Waypoints Saved"); + char *waypointSaveMessage = locale->TranslateInput ("Waypoints Saved"); if (FStrEq (arg2, "nocheck")) { - g_waypoint->Save (); + waypoint->Save (); ServerPrint (waypointSaveMessage); } - else if (g_waypoint->NodesValid ()) + else if (waypoint->NodesValid ()) { - g_waypoint->Save (); + waypoint->Save (); ServerPrint (waypointSaveMessage); } } // remove waypoint and all corresponding files from hard disk else if (stricmp (arg1, "erase") == 0) - g_waypoint->EraseFromHardDisk (); + waypoint->EraseFromHardDisk (); // load all waypoints again (overrides all changes, that wasn't saved) else if (stricmp (arg1, "load") == 0) { - if (g_waypoint->Load ()) + if (waypoint->Load ()) ServerPrint ("Waypoints loaded"); } // check all nodes for validation else if (stricmp (arg1, "check") == 0) { - if (g_waypoint->NodesValid ()) + if (waypoint->NodesValid ()) CenterPrint ("Nodes work Fine"); } @@ -322,11 +322,11 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c // setting waypoint radius else if (stricmp (arg1, "setradius") == 0) - g_waypoint->SetRadius (atoi (arg2)); + waypoint->SetRadius (atoi (arg2)); // remembers nearest waypoint else if (stricmp (arg1, "cache") == 0) - g_waypoint->CacheWaypoint (); + waypoint->CacheWaypoint (); // teleport player to specified waypoint else if (stricmp (arg1, "teleport") == 0) @@ -335,7 +335,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c if (teleportPoint < g_numWaypoints) { - Path *path = g_waypoint->GetPath (teleportPoint); + Path *path = waypoint->GetPath (teleportPoint); (*g_engfuncs.pfnSetOrigin) (g_hostEntity, path->origin); g_waypointOn = true; @@ -366,19 +366,19 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c // creates incoming path from the cached waypoint else if (stricmp (arg1, "create_in") == 0) - g_waypoint->CreatePath (CONNECTION_INCOMING); + waypoint->CreatePath (CONNECTION_INCOMING); // creates outgoing path from current waypoint else if (stricmp (arg1, "create_out") == 0) - g_waypoint->CreatePath (CONNECTION_OUTGOING); + waypoint->CreatePath (CONNECTION_OUTGOING); // creates bidirectional path from cahed to current waypoint else if (stricmp (arg1, "create_both") == 0) - g_waypoint->CreatePath (CONNECTION_BOTHWAYS); + waypoint->CreatePath (CONNECTION_BOTHWAYS); // delete special path else if (stricmp (arg1, "delete") == 0) - g_waypoint->DeletePath (); + waypoint->DeletePath (); // sets auto path maximum distance else if (stricmp (arg1, "autodistance") == 0) @@ -415,8 +415,8 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c // write experience table (and visibility table) to hard disk if (stricmp (arg1, "save") == 0) { - g_waypoint->SaveExperienceTab (); - g_waypoint->SaveVisibilityTab (); + waypoint->SaveExperienceTab (); + waypoint->SaveVisibilityTab (); ServerPrint ("Experience tab saved"); } @@ -840,7 +840,7 @@ void InitConfig (void) } if (!IsNullString (temp.translated) && !IsNullString (temp.original)) - g_localizer->m_langTab.Push (temp); + locale->m_langTab.Push (temp); } else if (strncmp (line, "[TRANSLATED]", 12) == 0) { @@ -936,7 +936,7 @@ void Touch (edict_t *pentTouched, edict_t *pentOther) if (!IsEntityNull (pentOther) && (pentOther->v.flags & FL_FAKECLIENT)) { - Bot *bot = g_botManager->GetBot (pentOther); + Bot *bot = botMgr->GetBot (pentOther); if (bot != NULL) bot->VerifyBreakable (pentTouched); @@ -958,7 +958,7 @@ int Spawn (edict_t *ent) { g_worldEntity = ent; // save the world entity for future use - g_convarWrapper->PushRegisteredConVarsToEngine (true); + convars->PushRegisteredConVarsToEngine (true); PRECACHE_SOUND (ENGINE_STR ("weapons/xbow_hit1.wav")); // waypoint add PRECACHE_SOUND (ENGINE_STR ("weapons/mine_activate.wav")); // waypoint delete @@ -1036,7 +1036,7 @@ void UpdateClientData (const struct edict_s *ent, int sendweapons, struct client extern ConVar yb_latency_display; if (yb_latency_display.GetInt () == 2) - g_botManager->SendPingDataOffsets (const_cast (ent)); + botMgr->SendPingDataOffsets (const_cast (ent)); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -1046,7 +1046,7 @@ void UpdateClientData (const struct edict_s *ent, int sendweapons, struct client void ClientPutInServer (edict_t *ent) { - g_botManager->CheckAutoVacate (); + botMgr->CheckAutoVacate (); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -1109,7 +1109,7 @@ void ClientDisconnect (edict_t *ent) InternalAssert (i >= 0 && i < 32); - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); // check if its a bot if (bot != NULL) @@ -1119,7 +1119,7 @@ void ClientDisconnect (edict_t *ent) bot->SwitchChatterIcon (false); bot->ReleaseUsedName (); - g_botManager->Free (i); + botMgr->Free (i); } } @@ -1220,15 +1220,15 @@ void ClientCommand (edict_t *ent) case 5: case 6: case 7: - g_waypoint->Add (selection - 1); + waypoint->Add (selection - 1); break; case 8: - g_waypoint->Add (100); + waypoint->Add (100); break; case 9: - g_waypoint->SetLearnJumpWaypoint (); + waypoint->SetLearnJumpWaypoint (); break; case 10: @@ -1247,23 +1247,23 @@ void ClientCommand (edict_t *ent) switch (selection) { case 1: - g_waypoint->ToggleFlags (FLAG_NOHOSTAGE); + waypoint->ToggleFlags (FLAG_NOHOSTAGE); break; case 2: - g_waypoint->ToggleFlags (FLAG_TF_ONLY); + waypoint->ToggleFlags (FLAG_TF_ONLY); break; case 3: - g_waypoint->ToggleFlags (FLAG_CF_ONLY); + waypoint->ToggleFlags (FLAG_CF_ONLY); break; case 4: - g_waypoint->ToggleFlags (FLAG_LIFT); + waypoint->ToggleFlags (FLAG_LIFT); break; case 5: - g_waypoint->ToggleFlags (FLAG_SNIPER); + waypoint->ToggleFlags (FLAG_SNIPER); break; } if (g_isMetamod) @@ -1286,7 +1286,7 @@ void ClientCommand (edict_t *ent) case 2: g_waypointOn = true; - g_waypoint->CacheWaypoint (); + waypoint->CacheWaypoint (); break; case 3: @@ -1296,7 +1296,7 @@ void ClientCommand (edict_t *ent) case 4: g_waypointOn = true; - g_waypoint->DeletePath (); + waypoint->DeletePath (); break; case 5: @@ -1306,7 +1306,7 @@ void ClientCommand (edict_t *ent) case 6: g_waypointOn = true; - g_waypoint->Delete (); + waypoint->Delete (); break; case 7: @@ -1350,7 +1350,7 @@ void ClientCommand (edict_t *ent) for (int i = 0; i < g_numWaypoints; i++) { - Path *path = g_waypoint->GetPath (i); + Path *path = waypoint->GetPath (i); if (path->flags & FLAG_TF_ONLY) terrPoints++; @@ -1394,22 +1394,22 @@ void ClientCommand (edict_t *ent) break; case 4: - if (g_waypoint->NodesValid ()) - g_waypoint->Save (); + if (waypoint->NodesValid ()) + waypoint->Save (); else CenterPrint ("Waypoint not saved\nThere are errors, see console"); break; case 5: - g_waypoint->Save (); + waypoint->Save (); break; case 6: - g_waypoint->Load (); + waypoint->Load (); break; case 7: - if (g_waypoint->NodesValid ()) + if (waypoint->NodesValid ()) CenterPrint ("Nodes work Find"); else CenterPrint ("There are errors, see console"); @@ -1437,7 +1437,7 @@ void ClientCommand (edict_t *ent) const int radiusValue[] = {0, 8, 16, 32, 48, 64, 80, 96, 128}; if ((selection >= 1) && (selection <= 9)) - g_waypoint->SetRadius (radiusValue[selection - 1]); + waypoint->SetRadius (radiusValue[selection - 1]); if (g_isMetamod) RETURN_META (MRES_SUPERCEDE); @@ -1465,7 +1465,7 @@ void ClientCommand (edict_t *ent) break; case 4: - g_botManager->KillAll (); + botMgr->KillAll (); break; case 10: @@ -1485,7 +1485,7 @@ void ClientCommand (edict_t *ent) switch (selection) { case 1: - g_botManager->AddRandom (); + botMgr->AddRandom (); break; case 2: @@ -1493,15 +1493,15 @@ void ClientCommand (edict_t *ent) break; case 3: - g_botManager->RemoveRandom (); + botMgr->RemoveRandom (); break; case 4: - g_botManager->RemoveAll (); + botMgr->RemoveAll (); break; case 5: - g_botManager->RemoveMenu (ent, 1); + botMgr->RemoveMenu (ent, 1); break; case 10: @@ -1628,15 +1628,15 @@ void ClientCommand (edict_t *ent) switch (selection) { case 1: - g_waypoint->CreatePath (CONNECTION_OUTGOING); + waypoint->CreatePath (CONNECTION_OUTGOING); break; case 2: - g_waypoint->CreatePath (CONNECTION_INCOMING); + waypoint->CreatePath (CONNECTION_INCOMING); break; case 3: - g_waypoint->CreatePath (CONNECTION_BOTHWAYS); + waypoint->CreatePath (CONNECTION_BOTHWAYS); break; case 10: @@ -1726,7 +1726,7 @@ void ClientCommand (edict_t *ent) case 2: case 3: case 4: - g_botManager->FillServer (fillServerTeam, selection - 2, g_storeAddbotVars[0]); + botMgr->FillServer (fillServerTeam, selection - 2, g_storeAddbotVars[0]); case 10: DisplayMenuToClient (ent, NULL); @@ -1750,7 +1750,7 @@ void ClientCommand (edict_t *ent) if (selection == 5) { g_storeAddbotVars[2] = 5; - g_botManager->AddBot ("", g_storeAddbotVars[0], g_storeAddbotVars[3], g_storeAddbotVars[1], g_storeAddbotVars[2]); + botMgr->AddBot ("", g_storeAddbotVars[0], g_storeAddbotVars[3], g_storeAddbotVars[1], g_storeAddbotVars[2]); } else { @@ -1805,7 +1805,7 @@ void ClientCommand (edict_t *ent) case 4: case 5: g_storeAddbotVars[2] = selection; - g_botManager->AddBot ("", g_storeAddbotVars[0], g_storeAddbotVars[3], g_storeAddbotVars[1], g_storeAddbotVars[2]); + botMgr->AddBot ("", g_storeAddbotVars[0], g_storeAddbotVars[3], g_storeAddbotVars[1], g_storeAddbotVars[2]); break; case 10: @@ -1830,7 +1830,7 @@ void ClientCommand (edict_t *ent) case 5: case 6: case 7: - g_botManager->SetWeaponMode (selection); + botMgr->SetWeaponMode (selection); break; case 10: @@ -1856,11 +1856,11 @@ void ClientCommand (edict_t *ent) case 6: case 7: case 8: - g_botManager->GetBot (selection - 1)->Kick (); + botMgr->GetBot (selection - 1)->Kick (); break; case 9: - g_botManager->RemoveMenu (ent, 2); + botMgr->RemoveMenu (ent, 2); break; case 10: @@ -1886,15 +1886,15 @@ void ClientCommand (edict_t *ent) case 6: case 7: case 8: - g_botManager->GetBot (selection + 8 - 1)->Kick (); + botMgr->GetBot (selection + 8 - 1)->Kick (); break; case 9: - g_botManager->RemoveMenu (ent, 3); + botMgr->RemoveMenu (ent, 3); break; case 10: - g_botManager->RemoveMenu (ent, 1); + botMgr->RemoveMenu (ent, 1); break; } if (g_isMetamod) @@ -1916,15 +1916,15 @@ void ClientCommand (edict_t *ent) case 6: case 7: case 8: - g_botManager->GetBot (selection + 16 - 1)->Kick (); + botMgr->GetBot (selection + 16 - 1)->Kick (); break; case 9: - g_botManager->RemoveMenu (ent, 4); + botMgr->RemoveMenu (ent, 4); break; case 10: - g_botManager->RemoveMenu (ent, 2); + botMgr->RemoveMenu (ent, 2); break; } if (g_isMetamod) @@ -1946,11 +1946,11 @@ void ClientCommand (edict_t *ent) case 6: case 7: case 8: - g_botManager->GetBot (selection + 24 - 1)->Kick (); + botMgr->GetBot (selection + 24 - 1)->Kick (); break; case 10: - g_botManager->RemoveMenu (ent, 3); + botMgr->RemoveMenu (ent, 3); break; } if (g_isMetamod) @@ -1984,7 +1984,7 @@ void ClientCommand (edict_t *ent) if (!(g_clients[i].flags & CF_USED) || (team != -1 && team != g_clients[i].team) || isAlive != IsAlive (g_clients[i].ent)) continue; - Bot *target = g_botManager->GetBot (i); + Bot *target = botMgr->GetBot (i); if (target != NULL) { @@ -2013,7 +2013,7 @@ void ClientCommand (edict_t *ent) { for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); // validate bot if (bot != NULL && GetTeam (bot->GetEntity ()) == g_clients[clientIndex].team && VARS (ent) != bot->pev && bot->m_radioOrder == 0) @@ -2049,8 +2049,8 @@ void ServerActivate (edict_t *pentEdictList, int edictCount, int clientMax) InitConfig (); // initialize all config files // do level initialization stuff here... - g_waypoint->Init (); - g_waypoint->Load (); + waypoint->Init (); + waypoint->Load (); // execute main config ServerCommand ("exec addons/yapb/conf/yapb.cfg"); @@ -2060,14 +2060,14 @@ void ServerActivate (edict_t *pentEdictList, int edictCount, int clientMax) ServerCommand ("exec maps/%s_yapb.cfg", GetMapName ()); ServerPrint ("Executing Map-Specific config file"); } - g_botManager->InitQuota (); + botMgr->InitQuota (); if (g_isMetamod) RETURN_META (MRES_IGNORED); (*g_functionTable.pfnServerActivate) (pentEdictList, edictCount, clientMax); - g_waypoint->InitializeVisibility (); + waypoint->InitializeVisibility (); } void ServerDeactivate (void) @@ -2083,8 +2083,8 @@ void ServerDeactivate (void) // the loading of new bots and the new BSP data parsing there. // save collected experience on shutdown - g_waypoint->SaveExperienceTab (); - g_waypoint->SaveVisibilityTab (); + waypoint->SaveExperienceTab (); + waypoint->SaveVisibilityTab (); FreeLibraryMemory (); @@ -2105,7 +2105,7 @@ void StartFrame (void) // player population decreases, we should fill the server with other bots. // run periodic update of bot states - g_botManager->PeriodicThink (); + botMgr->PeriodicThink (); // record some stats of all players on the server for (int i = 0; i < GetMaxClients (); i++) @@ -2142,15 +2142,15 @@ void StartFrame (void) if (!IsDedicatedServer () && !IsEntityNull (g_hostEntity)) { if (g_waypointOn) - g_waypoint->Think (); + waypoint->Think (); CheckWelcomeMessage (); } - g_botManager->SetDeathMsgState (false); + botMgr->SetDeathMsgState (false); if (g_timePerSecondUpdate < GetWorldTime ()) { - g_botManager->CalculatePingOffsets (); + botMgr->CalculatePingOffsets (); for (int i = 0; i < GetMaxClients (); i++) { @@ -2180,7 +2180,7 @@ void StartFrame (void) } } if (g_bombPlanted) - g_waypoint->SetBombPosition (); + waypoint->SetBombPosition (); if (g_isMetamod) { @@ -2199,10 +2199,10 @@ void StartFrame (void) g_timePerSecondUpdate = GetWorldTime () + 1.0f; } else if (g_timePerSecondUpdate * 0.5f < GetWorldTime ()) - g_botManager->UpdateActiveGrenades (); + botMgr->UpdateActiveGrenades (); // keep bot number up to date - g_botManager->MaintainBotQuota (); + botMgr->MaintainBotQuota (); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2210,7 +2210,7 @@ void StartFrame (void) (*g_functionTable.pfnStartFrame) (); // **** AI EXECUTION STARTS **** - g_botManager->Think (); + botMgr->Think (); // **** AI EXECUTION FINISH **** } @@ -2223,7 +2223,7 @@ void StartFrame_Post (void) // for the bots by the MOD side, remember). Post version called only by metamod. // **** AI EXECUTION STARTS **** - g_botManager->Think (); + botMgr->Think (); // **** AI EXECUTION FINISH **** RETURN_META (MRES_IGNORED); @@ -2254,7 +2254,7 @@ void ServerActivate_Post (edict_t *, int, int) // Once this function has been called, the server can be considered as "running". Post version // called only by metamod. - g_waypoint->InitializeVisibility (); + waypoint->InitializeVisibility (); RETURN_META (MRES_IGNORED); } @@ -2271,8 +2271,8 @@ void pfnChangeLevel (char *s1, char *s2) // spawn point named "tr_2lm". // save collected experience on map change - g_waypoint->SaveExperienceTab (); - g_waypoint->SaveVisibilityTab (); + waypoint->SaveExperienceTab (); + waypoint->SaveVisibilityTab (); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2356,75 +2356,75 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed // this function called each time a message is about to sent. // store the message type in our own variables, since the GET_USER_MSG_ID () will just do a lot of strcmp()'s... - if (g_isMetamod && g_netMsg->GetId (NETMSG_MONEY) == -1) + if (g_isMetamod && netmsg->GetId (NETMSG_MONEY) == -1) { - g_netMsg->SetId (NETMSG_VGUI, GET_USER_MSG_ID (PLID, "VGUIMenu", NULL)); - g_netMsg->SetId (NETMSG_SHOWMENU, GET_USER_MSG_ID (PLID, "ShowMenu", NULL)); - g_netMsg->SetId (NETMSG_WEAPONLIST, GET_USER_MSG_ID (PLID, "WeaponList", NULL)); - g_netMsg->SetId (NETMSG_CURWEAPON, GET_USER_MSG_ID (PLID, "CurWeapon", NULL)); - g_netMsg->SetId (NETMSG_AMMOX, GET_USER_MSG_ID (PLID, "AmmoX", NULL)); - g_netMsg->SetId (NETMSG_AMMOPICKUP, GET_USER_MSG_ID (PLID, "AmmoPickup", NULL)); - g_netMsg->SetId (NETMSG_DAMAGE, GET_USER_MSG_ID (PLID, "Damage", NULL)); - g_netMsg->SetId (NETMSG_MONEY, GET_USER_MSG_ID (PLID, "Money", NULL)); - g_netMsg->SetId (NETMSG_STATUSICON, GET_USER_MSG_ID (PLID, "StatusIcon", NULL)); - g_netMsg->SetId (NETMSG_DEATH, GET_USER_MSG_ID (PLID, "DeathMsg", NULL)); - g_netMsg->SetId (NETMSG_SCREENFADE, GET_USER_MSG_ID (PLID, "ScreenFade", NULL)); - g_netMsg->SetId (NETMSG_HLTV, GET_USER_MSG_ID (PLID, "HLTV", NULL)); - g_netMsg->SetId (NETMSG_TEXTMSG, GET_USER_MSG_ID (PLID, "TextMsg", NULL)); - g_netMsg->SetId (NETMSG_SCOREINFO, GET_USER_MSG_ID (PLID, "ScoreInfo", NULL)); - g_netMsg->SetId (NETMSG_BARTIME, GET_USER_MSG_ID (PLID, "BarTime", NULL)); - g_netMsg->SetId (NETMSG_SENDAUDIO, GET_USER_MSG_ID (PLID, "SendAudio", NULL)); - g_netMsg->SetId (NETMSG_SAYTEXT, GET_USER_MSG_ID (PLID, "SayText", NULL)); - g_netMsg->SetId (NETMSG_RESETHUD, GET_USER_MSG_ID (PLID, "ResetHUD", NULL)); + netmsg->SetId (NETMSG_VGUI, GET_USER_MSG_ID (PLID, "VGUIMenu", NULL)); + netmsg->SetId (NETMSG_SHOWMENU, GET_USER_MSG_ID (PLID, "ShowMenu", NULL)); + netmsg->SetId (NETMSG_WEAPONLIST, GET_USER_MSG_ID (PLID, "WeaponList", NULL)); + netmsg->SetId (NETMSG_CURWEAPON, GET_USER_MSG_ID (PLID, "CurWeapon", NULL)); + netmsg->SetId (NETMSG_AMMOX, GET_USER_MSG_ID (PLID, "AmmoX", NULL)); + netmsg->SetId (NETMSG_AMMOPICKUP, GET_USER_MSG_ID (PLID, "AmmoPickup", NULL)); + netmsg->SetId (NETMSG_DAMAGE, GET_USER_MSG_ID (PLID, "Damage", NULL)); + netmsg->SetId (NETMSG_MONEY, GET_USER_MSG_ID (PLID, "Money", NULL)); + netmsg->SetId (NETMSG_STATUSICON, GET_USER_MSG_ID (PLID, "StatusIcon", NULL)); + netmsg->SetId (NETMSG_DEATH, GET_USER_MSG_ID (PLID, "DeathMsg", NULL)); + netmsg->SetId (NETMSG_SCREENFADE, GET_USER_MSG_ID (PLID, "ScreenFade", NULL)); + netmsg->SetId (NETMSG_HLTV, GET_USER_MSG_ID (PLID, "HLTV", NULL)); + netmsg->SetId (NETMSG_TEXTMSG, GET_USER_MSG_ID (PLID, "TextMsg", NULL)); + netmsg->SetId (NETMSG_SCOREINFO, GET_USER_MSG_ID (PLID, "ScoreInfo", NULL)); + netmsg->SetId (NETMSG_BARTIME, GET_USER_MSG_ID (PLID, "BarTime", NULL)); + netmsg->SetId (NETMSG_SENDAUDIO, GET_USER_MSG_ID (PLID, "SendAudio", NULL)); + netmsg->SetId (NETMSG_SAYTEXT, GET_USER_MSG_ID (PLID, "SayText", NULL)); + netmsg->SetId (NETMSG_RESETHUD, GET_USER_MSG_ID (PLID, "ResetHUD", NULL)); if (g_gameVersion != CSV_OLD) - g_netMsg->SetId (NETMSG_BOTVOICE, GET_USER_MSG_ID (PLID, "BotVoice", NULL)); + netmsg->SetId (NETMSG_BOTVOICE, GET_USER_MSG_ID (PLID, "BotVoice", NULL)); } - g_netMsg->Reset (); + netmsg->Reset (); - if (msgDest == MSG_SPEC && msgType == g_netMsg->GetId (NETMSG_HLTV) && g_gameVersion != CSV_OLD) - g_netMsg->SetMessage (NETMSG_HLTV); + if (msgDest == MSG_SPEC && msgType == netmsg->GetId (NETMSG_HLTV) && g_gameVersion != CSV_OLD) + netmsg->SetMessage (NETMSG_HLTV); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_WEAPONLIST); + netmsg->HandleMessageIfRequired (msgType, NETMSG_WEAPONLIST); if (!IsEntityNull (ed)) { - int index = g_botManager->GetIndex (ed); + int index = botMgr->GetIndex (ed); // is this message for a bot? - if (index != -1 && !(ed->v.flags & FL_DORMANT) && g_botManager->GetBot (index)->GetEntity () == ed) + if (index != -1 && !(ed->v.flags & FL_DORMANT) && botMgr->GetBot (index)->GetEntity () == ed) { - g_netMsg->Reset (); - g_netMsg->SetBot (g_botManager->GetBot (index)); + netmsg->Reset (); + netmsg->SetBot (botMgr->GetBot (index)); // message handling is done in usermsg.cpp - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_VGUI); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_CURWEAPON); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_AMMOX); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_AMMOPICKUP); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_DAMAGE); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_MONEY); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_STATUSICON); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_SCREENFADE); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_BARTIME); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_TEXTMSG); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_SHOWMENU); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_RESETHUD); + netmsg->HandleMessageIfRequired (msgType, NETMSG_VGUI); + netmsg->HandleMessageIfRequired (msgType, NETMSG_CURWEAPON); + netmsg->HandleMessageIfRequired (msgType, NETMSG_AMMOX); + netmsg->HandleMessageIfRequired (msgType, NETMSG_AMMOPICKUP); + netmsg->HandleMessageIfRequired (msgType, NETMSG_DAMAGE); + netmsg->HandleMessageIfRequired (msgType, NETMSG_MONEY); + netmsg->HandleMessageIfRequired (msgType, NETMSG_STATUSICON); + netmsg->HandleMessageIfRequired (msgType, NETMSG_SCREENFADE); + netmsg->HandleMessageIfRequired (msgType, NETMSG_BARTIME); + netmsg->HandleMessageIfRequired (msgType, NETMSG_TEXTMSG); + netmsg->HandleMessageIfRequired (msgType, NETMSG_SHOWMENU); + netmsg->HandleMessageIfRequired (msgType, NETMSG_RESETHUD); } } else if (msgDest == MSG_ALL) { - g_netMsg->Reset (); + netmsg->Reset (); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_SCOREINFO); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_DEATH); - g_netMsg->HandleMessageIfRequired (msgType, NETMSG_TEXTMSG); + netmsg->HandleMessageIfRequired (msgType, NETMSG_SCOREINFO); + netmsg->HandleMessageIfRequired (msgType, NETMSG_DEATH); + netmsg->HandleMessageIfRequired (msgType, NETMSG_TEXTMSG); if (msgType == SVC_INTERMISSION) { for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot != NULL) bot->m_notKilled = false; @@ -2440,7 +2440,7 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed void pfnMessageEnd (void) { - g_netMsg->Reset (); + netmsg->Reset (); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2448,13 +2448,13 @@ void pfnMessageEnd (void) MESSAGE_END (); // send latency fix - g_botManager->SendDeathMsgFix (); + botMgr->SendDeathMsgFix (); } void pfnMessageEnd_Post (void) { // send latency fix - g_botManager->SendDeathMsgFix (); + botMgr->SendDeathMsgFix (); RETURN_META (MRES_IGNORED); } @@ -2462,7 +2462,7 @@ void pfnMessageEnd_Post (void) void pfnWriteByte (int value) { // if this message is for a bot, call the client message function... - g_netMsg->Execute ((void *) &value); + netmsg->Execute ((void *) &value); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2473,7 +2473,7 @@ void pfnWriteByte (int value) void pfnWriteChar (int value) { // if this message is for a bot, call the client message function... - g_netMsg->Execute ((void *) &value); + netmsg->Execute ((void *) &value); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2484,7 +2484,7 @@ void pfnWriteChar (int value) void pfnWriteShort (int value) { // if this message is for a bot, call the client message function... - g_netMsg->Execute ((void *) &value); + netmsg->Execute ((void *) &value); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2495,7 +2495,7 @@ void pfnWriteShort (int value) void pfnWriteLong (int value) { // if this message is for a bot, call the client message function... - g_netMsg->Execute ((void *) &value); + netmsg->Execute ((void *) &value); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2506,7 +2506,7 @@ void pfnWriteLong (int value) void pfnWriteAngle (float value) { // if this message is for a bot, call the client message function... - g_netMsg->Execute ((void *) &value); + netmsg->Execute ((void *) &value); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2517,7 +2517,7 @@ void pfnWriteAngle (float value) void pfnWriteCoord (float value) { // if this message is for a bot, call the client message function... - g_netMsg->Execute ((void *) &value); + netmsg->Execute ((void *) &value); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2528,7 +2528,7 @@ void pfnWriteCoord (float value) void pfnWriteString (const char *sz) { // if this message is for a bot, call the client message function... - g_netMsg->Execute ((void *) sz); + netmsg->Execute ((void *) sz); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2539,7 +2539,7 @@ void pfnWriteString (const char *sz) void pfnWriteEntity (int value) { // if this message is for a bot, call the client message function... - g_netMsg->Execute ((void *) &value); + netmsg->Execute ((void *) &value); if (g_isMetamod) RETURN_META (MRES_IGNORED); @@ -2658,7 +2658,7 @@ void pfnClientPrintf (edict_t *ent, PRINT_TYPE printType, const char *message) void pfnSetClientMaxspeed (const edict_t *ent, float newMaxspeed) { - Bot *bot = g_botManager->GetBot (const_cast (ent)); + Bot *bot = botMgr->GetBot (const_cast (ent)); // check wether it's not a bot if (bot != NULL) @@ -2688,43 +2688,43 @@ int pfnRegUserMsg (const char *name, int size) int message = REG_USER_MSG (name, size); if (strcmp (name, "VGUIMenu") == 0) - g_netMsg->SetId (NETMSG_VGUI, message); + netmsg->SetId (NETMSG_VGUI, message); else if (strcmp (name, "ShowMenu") == 0) - g_netMsg->SetId (NETMSG_SHOWMENU, message); + netmsg->SetId (NETMSG_SHOWMENU, message); else if (strcmp (name, "WeaponList") == 0) - g_netMsg->SetId (NETMSG_WEAPONLIST, message); + netmsg->SetId (NETMSG_WEAPONLIST, message); else if (strcmp (name, "CurWeapon") == 0) - g_netMsg->SetId (NETMSG_CURWEAPON, message); + netmsg->SetId (NETMSG_CURWEAPON, message); else if (strcmp (name, "AmmoX") == 0) - g_netMsg->SetId (NETMSG_AMMOX, message); + netmsg->SetId (NETMSG_AMMOX, message); else if (strcmp (name, "AmmoPickup") == 0) - g_netMsg->SetId (NETMSG_AMMOPICKUP, message); + netmsg->SetId (NETMSG_AMMOPICKUP, message); else if (strcmp (name, "Damage") == 0) - g_netMsg->SetId (NETMSG_DAMAGE, message); + netmsg->SetId (NETMSG_DAMAGE, message); else if (strcmp (name, "Money") == 0) - g_netMsg->SetId (NETMSG_MONEY, message); + netmsg->SetId (NETMSG_MONEY, message); else if (strcmp (name, "StatusIcon") == 0) - g_netMsg->SetId (NETMSG_STATUSICON, message); + netmsg->SetId (NETMSG_STATUSICON, message); else if (strcmp (name, "DeathMsg") == 0) - g_netMsg->SetId (NETMSG_DEATH, message); + netmsg->SetId (NETMSG_DEATH, message); else if (strcmp (name, "ScreenFade") == 0) - g_netMsg->SetId (NETMSG_SCREENFADE, message); + netmsg->SetId (NETMSG_SCREENFADE, message); else if (strcmp (name, "HLTV") == 0) - g_netMsg->SetId (NETMSG_HLTV, message); + netmsg->SetId (NETMSG_HLTV, message); else if (strcmp (name, "TextMsg") == 0) - g_netMsg->SetId (NETMSG_TEXTMSG, message); + netmsg->SetId (NETMSG_TEXTMSG, message); else if (strcmp (name, "ScoreInfo") == 0) - g_netMsg->SetId (NETMSG_SCOREINFO, message); + netmsg->SetId (NETMSG_SCOREINFO, message); else if (strcmp (name, "BarTime") == 0) - g_netMsg->SetId (NETMSG_BARTIME, message); + netmsg->SetId (NETMSG_BARTIME, message); else if (strcmp (name, "SendAudio") == 0) - g_netMsg->SetId (NETMSG_SENDAUDIO, message); + netmsg->SetId (NETMSG_SENDAUDIO, message); else if (strcmp (name, "SayText") == 0) - g_netMsg->SetId (NETMSG_SAYTEXT, message); + netmsg->SetId (NETMSG_SAYTEXT, message); else if (strcmp (name, "BotVoice") == 0) - g_netMsg->SetId (NETMSG_BOTVOICE, message); + netmsg->SetId (NETMSG_BOTVOICE, message); else if (strcmp (name, "ResetHUD") == 0) - g_netMsg->SetId (NETMSG_RESETHUD, message); + netmsg->SetId (NETMSG_RESETHUD, message); return message; } @@ -2743,12 +2743,12 @@ void pfnAlertMessage (ALERT_TYPE alertType, char *format, ...) // notify all terrorists that CT is starting bomb defusing for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot != NULL && GetTeam (bot->GetEntity ()) == TEAM_TF && IsAlive (bot->GetEntity ())) { bot->ResetTasks (); - bot->MoveToVector (g_waypoint->GetBombPosition ()); + bot->MoveToVector (waypoint->GetBombPosition ()); } } } @@ -2978,7 +2978,7 @@ export int Meta_Detach (PLUG_LOADTIME now, PL_UNLOAD_REASON reason) return FALSE; // returning false prevents metamod from unloading this plugin } - g_botManager->RemoveAll (); // kick all bots off this server + botMgr->RemoveAll (); // kick all bots off this server FreeLibraryMemory (); return TRUE; @@ -3056,7 +3056,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t FixDirectoryStructure (); // register our cvars - g_convarWrapper->PushRegisteredConVarsToEngine (); + convars->PushRegisteredConVarsToEngine (); static struct ModSupport { diff --git a/source/manager.cpp b/source/manager.cpp index 910f06a..850059b 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -650,7 +650,7 @@ Bot *BotManager::GetHighestFragsBot (int team) // search bots in this team for (int i = 0; i < GetMaxClients (); i++) { - highFragBot = g_botManager->GetBot (i); + highFragBot = botMgr->GetBot (i); if (highFragBot != NULL && IsAlive (highFragBot->GetEntity ()) && GetTeam (highFragBot->GetEntity ()) == team) { @@ -1051,7 +1051,6 @@ void Bot::NewRound (void) m_grenadeCheckTime = 0.0; m_isUsingGrenade = false; - m_breakableCheckTime = 0.0f; m_blindButton = 0; m_blindTime = 0.0; m_jumpTime = 0.0; @@ -1166,8 +1165,8 @@ void Bot::Kick (void) CenterPrint ("Bot '%s' kicked", STRING (pev->netname)); // balances quota - if (g_botManager->GetBotsNum () - 1 < yb_quota.GetInt ()) - yb_quota.SetInt (g_botManager->GetBotsNum () - 1); + if (botMgr->GetBotsNum () - 1 < yb_quota.GetInt ()) + yb_quota.SetInt (botMgr->GetBotsNum () - 1); } void Bot::StartGame (void) diff --git a/source/navigate.cpp b/source/navigate.cpp index 46fe996..e0452bf 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -44,7 +44,7 @@ int Bot::FindGoal (void) { if (strcmp (STRING (pent->v.model), "models/w_backpack.mdl") == 0) { - int index = g_waypoint->FindNearest (GetEntityOrigin (pent)); + int index = waypoint->FindNearest (GetEntityOrigin (pent)); if (index >= 0 && index < g_numWaypoints) return m_loosedBombWptIndex = index; @@ -71,13 +71,13 @@ int Bot::FindGoal (void) switch (m_team) { case TEAM_TF: - offensiveWpts = g_waypoint->m_ctPoints; - defensiveWpts = g_waypoint->m_terrorPoints; + offensiveWpts = waypoint->m_ctPoints; + defensiveWpts = waypoint->m_terrorPoints; break; case TEAM_CF: - offensiveWpts = g_waypoint->m_terrorPoints; - defensiveWpts = g_waypoint->m_ctPoints; + offensiveWpts = waypoint->m_terrorPoints; + defensiveWpts = waypoint->m_ctPoints; break; } @@ -90,7 +90,7 @@ int Bot::FindGoal (void) else if (m_team == TEAM_CF && HasHostage ()) { tactic = 2; - offensiveWpts = g_waypoint->m_rescuePoints; + offensiveWpts = waypoint->m_rescuePoints; goto TacticChoosen; } @@ -122,7 +122,7 @@ int Bot::FindGoal (void) } else if ((g_mapType & MAP_DE) && m_team == TEAM_CF) { - if (g_bombPlanted && GetTaskId () != TASK_ESCAPEFROMBOMB && g_waypoint->GetBombPosition () != nullvec) + if (g_bombPlanted && GetTaskId () != TASK_ESCAPEFROMBOMB && waypoint->GetBombPosition () != nullvec) { if (g_bombSayString) { @@ -133,12 +133,15 @@ int Bot::FindGoal (void) } defensive += 25.0f; offensive -= 25.0f; + + if (m_personality != PERSONALITY_RUSHER) + defensive += 10.0f; } else if ((g_mapType & MAP_DE) && m_team == TEAM_TF && g_timeRoundStart + 10.0f < GetWorldTime ()) { // send some terrorists to guard planter bomb if (g_bombPlanted && GetTaskId () != TASK_ESCAPEFROMBOMB && GetBombTimeleft () >= 15.0) - return m_chosenGoalIndex = FindDefendWaypoint (g_waypoint->GetBombPosition ()); + return m_chosenGoalIndex = FindDefendWaypoint (waypoint->GetBombPosition ()); } goalDesire = Random.Float (0.0f, 100.0f) + offensive; @@ -147,7 +150,7 @@ int Bot::FindGoal (void) backoffDesire = Random.Float (0.0f, 100.0f) + defensive; if (!UsesCampGun ()) - campDesire = 0; + campDesire *= 0.5f; tacticChoice = backoffDesire; tactic = 0; @@ -172,17 +175,17 @@ TacticChoosen: if (tactic == 0 && !defensiveWpts.IsEmpty ()) // careful goal FilterGoals (defensiveWpts, goalChoices); - else if (tactic == 1 && !g_waypoint->m_campPoints.IsEmpty ()) // camp waypoint goal + else if (tactic == 1 && !waypoint->m_campPoints.IsEmpty ()) // camp waypoint goal { // pickup sniper points if possible for sniping bots - if (!g_waypoint->m_sniperPoints.IsEmpty () && UsesSniper ()) - FilterGoals (g_waypoint->m_sniperPoints, goalChoices); + if (!waypoint->m_sniperPoints.IsEmpty () && UsesSniper ()) + FilterGoals (waypoint->m_sniperPoints, goalChoices); else - FilterGoals (g_waypoint->m_campPoints, goalChoices); + FilterGoals (waypoint->m_campPoints, goalChoices); } else if (tactic == 2 && !offensiveWpts.IsEmpty ()) // offensive goal FilterGoals (offensiveWpts, goalChoices); - else if (tactic == 3 && !g_waypoint->m_goalPoints.IsEmpty ()) // map goal waypoint + else if (tactic == 3 && !waypoint->m_goalPoints.IsEmpty ()) // map goal waypoint { // forcee bomber to select closest goal, if round-start goal was reset by something if (m_hasC4 && g_timeRoundStart + 20.0f < GetWorldTime ()) @@ -192,7 +195,7 @@ TacticChoosen: for (int i = 0; i < g_numWaypoints; i++) { - Path *path = g_waypoint->GetPath (i); + Path *path = waypoint->GetPath (i); if (!(path->flags & FLAG_GOAL)) continue; @@ -214,17 +217,17 @@ TacticChoosen: { if (goalChoices[i] == -1) { - goalChoices[i] = g_waypoint->m_goalPoints.GetRandomElement (); + goalChoices[i] = waypoint->m_goalPoints.GetRandomElement (); InternalAssert (goalChoices[i] >= 0 && goalChoices[i] < g_numWaypoints); } } } else - FilterGoals (g_waypoint->m_goalPoints, goalChoices); + FilterGoals (waypoint->m_goalPoints, goalChoices); } if (m_currentWaypointIndex == -1 || m_currentWaypointIndex >= g_numWaypoints) - m_currentWaypointIndex = ChangeWptIndex (g_waypoint->FindNearest (pev->origin)); + m_currentWaypointIndex = ChangeWptIndex (waypoint->FindNearest (pev->origin)); if (goalChoices[0] == -1) return m_chosenGoalIndex = Random.Long (0, g_numWaypoints - 1); @@ -779,9 +782,9 @@ bool Bot::DoWaypointNav (void) { if ((m_liftState == LIFT_NO_NEARBY || m_liftState == LIFT_WAITING_FOR) && m_navNode->next != NULL) { - if (m_navNode->next->index >= 0 && m_navNode->next->index < g_numWaypoints && (g_waypoint->GetPath (m_navNode->next->index)->flags & FLAG_LIFT)) + if (m_navNode->next->index >= 0 && m_navNode->next->index < g_numWaypoints && (waypoint->GetPath (m_navNode->next->index)->flags & FLAG_LIFT)) { - TraceLine (m_currentPath->origin, g_waypoint->GetPath (m_navNode->next->index)->origin, true, true, GetEntity (), &tr); + TraceLine (m_currentPath->origin, waypoint->GetPath (m_navNode->next->index)->origin, true, true, GetEntity (), &tr); if (!IsEntityNull (tr.pHit) && (strcmp (STRING (tr.pHit->v.classname), "func_door") == 0 || strcmp (STRING (tr.pHit->v.classname), "func_plat") == 0 || strcmp (STRING (tr.pHit->v.classname), "func_train") == 0)) m_liftEntity = tr.pHit; @@ -813,7 +816,7 @@ bool Bot::DoWaypointNav (void) // if some bot is following a bot going into lift - he should take the same lift to go for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot == NULL || bot == this) continue; @@ -852,7 +855,7 @@ bool Bot::DoWaypointNav (void) for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot == NULL) continue; // skip invalid bots @@ -910,7 +913,7 @@ bool Bot::DoWaypointNav (void) // is lift activated and bot is standing on it and lift is moving ? if (m_liftState == LIFT_LOOKING_BUTTON_INSIDE || m_liftState == LIFT_ENTERING_IN || m_liftState == LIFT_WAIT_FOR_TEAMMATES || m_liftState == LIFT_WAITING_FOR) { - if (pev->groundentity == m_liftEntity && m_liftEntity->v.velocity.z != 0 && IsOnFloor () && ((g_waypoint->GetPath (m_prevWptIndex[0])->flags & FLAG_LIFT) || !IsEntityNull (m_targetEntity))) + if (pev->groundentity == m_liftEntity && m_liftEntity->v.velocity.z != 0 && IsOnFloor () && ((waypoint->GetPath (m_prevWptIndex[0])->flags & FLAG_LIFT) || !IsEntityNull (m_targetEntity))) { m_liftState = LIFT_TRAVELING_BY; m_liftUsageTime = GetWorldTime () + 14.0; @@ -953,7 +956,7 @@ bool Bot::DoWaypointNav (void) if (m_buttonPushTime + 8.0 >= GetWorldTime ()) { if ((m_prevWptIndex[0] >= 0) && (m_prevWptIndex[0] < g_numWaypoints)) - m_destOrigin = g_waypoint->GetPath (m_prevWptIndex[0])->origin; + m_destOrigin = waypoint->GetPath (m_prevWptIndex[0])->origin; else m_destOrigin = pev->origin; @@ -995,7 +998,7 @@ bool Bot::DoWaypointNav (void) if (liftUsed) { if (m_prevWptIndex[0] >= 0 && m_prevWptIndex[0] < g_numWaypoints) - m_destOrigin = g_waypoint->GetPath (m_prevWptIndex[0])->origin; + m_destOrigin = waypoint->GetPath (m_prevWptIndex[0])->origin; else m_destOrigin = button->v.origin; @@ -1028,10 +1031,10 @@ bool Bot::DoWaypointNav (void) { if ((m_prevWptIndex[0] >= 0) && (m_prevWptIndex[0] < g_numWaypoints)) { - if (!(g_waypoint->GetPath (m_prevWptIndex[0])->flags & FLAG_LIFT)) - m_destOrigin = g_waypoint->GetPath (m_prevWptIndex[0])->origin; + if (!(waypoint->GetPath (m_prevWptIndex[0])->flags & FLAG_LIFT)) + m_destOrigin = waypoint->GetPath (m_prevWptIndex[0])->origin; else if ((m_prevWptIndex[1] >= 0) && (m_prevWptIndex[0] < g_numWaypoints)) - m_destOrigin = g_waypoint->GetPath (m_prevWptIndex[1])->origin; + m_destOrigin = waypoint->GetPath (m_prevWptIndex[1])->origin; } if ((pev->origin - m_destOrigin).GetLengthSquared () < 100) @@ -1052,7 +1055,7 @@ bool Bot::DoWaypointNav (void) // bot fall down somewhere inside the lift's groove :) if (pev->groundentity != m_liftEntity && m_prevWptIndex[0] >= 0 && m_prevWptIndex[0] < g_numWaypoints) { - if ((g_waypoint->GetPath (m_prevWptIndex[0])->flags & FLAG_LIFT) && (m_currentPath->origin.z - pev->origin.z) > 50.0 && (g_waypoint->GetPath (m_prevWptIndex[0])->origin.z - pev->origin.z) > 50.0) + if ((waypoint->GetPath (m_prevWptIndex[0])->flags & FLAG_LIFT) && (m_currentPath->origin.z - pev->origin.z) > 50.0 && (waypoint->GetPath (m_prevWptIndex[0])->origin.z - pev->origin.z) > 50.0) { m_liftState = LIFT_NO_NEARBY; m_liftEntity = NULL; @@ -1096,7 +1099,7 @@ bool Bot::DoWaypointNav (void) if (m_prevWptIndex[0] >= 0 && m_prevWptIndex[0] < g_numWaypoints) { - if (!(g_waypoint->GetPath (m_prevWptIndex[0])->flags & FLAG_LIFT)) + if (!(waypoint->GetPath (m_prevWptIndex[0])->flags & FLAG_LIFT)) ChangeWptIndex (m_prevWptIndex[0]); else FindWaypoint (); @@ -1249,13 +1252,13 @@ bool Bot::DoWaypointNav (void) // bot within 'hearable' bomb tick noises? if (bombOrigin != nullvec) { - float distance = (bombOrigin - g_waypoint->GetPath (GetTask ()->data)->origin).GetLength (); + float distance = (bombOrigin - waypoint->GetPath (GetTask ()->data)->origin).GetLength (); if (distance > 512.0) - g_waypoint->SetGoalVisited (GetTask ()->data); // doesn't hear so not a good goal + waypoint->SetGoalVisited (GetTask ()->data); // doesn't hear so not a good goal } else - g_waypoint->SetGoalVisited (GetTask ()->data); // doesn't hear so not a good goal + waypoint->SetGoalVisited (GetTask ()->data); // doesn't hear so not a good goal } HeadTowardWaypoint (); // do the actual movement checking } @@ -1282,7 +1285,7 @@ void Bot::FindShortestPath (int srcIndex, int destIndex) while (srcIndex != destIndex) { - srcIndex = *(g_waypoint->m_pathMatrix + (srcIndex * g_numWaypoints) + destIndex); + srcIndex = *(waypoint->m_pathMatrix + (srcIndex * g_numWaypoints) + destIndex); if (srcIndex < 0) { @@ -1427,7 +1430,7 @@ float gfunctionKillsDistT (int currentIndex, int parentIndex) float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team0Damage + g_highestDamageT; - Path *current = g_waypoint->GetPath (currentIndex); + Path *current = waypoint->GetPath (currentIndex); for (int i = 0; i < MAX_PATH_INDEX; i++) { @@ -1440,7 +1443,7 @@ float gfunctionKillsDistT (int currentIndex, int parentIndex) if (current->flags & FLAG_CROUCH) cost *= 1.5; - return g_waypoint->GetPathDistance (parentIndex, currentIndex) + cost; + return waypoint->GetPathDistance (parentIndex, currentIndex) + cost; } @@ -1453,7 +1456,7 @@ float gfunctionKillsDistCT (int currentIndex, int parentIndex) float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team1Damage + g_highestDamageCT; - Path *current = g_waypoint->GetPath (currentIndex); + Path *current = waypoint->GetPath (currentIndex); for (int i = 0; i < MAX_PATH_INDEX; i++) { @@ -1466,14 +1469,14 @@ float gfunctionKillsDistCT (int currentIndex, int parentIndex) if (current->flags & FLAG_CROUCH) cost *= 1.5; - return g_waypoint->GetPathDistance (parentIndex, currentIndex) + cost; + return waypoint->GetPathDistance (parentIndex, currentIndex) + cost; } float gfunctionKillsDistCTWithHostage (int currentIndex, int parentIndex) { // least kills and number of nodes to goal for a team - Path *current = g_waypoint->GetPath (currentIndex); + Path *current = waypoint->GetPath (currentIndex); if (current->flags & FLAG_NOHOSTAGE) return 65355; @@ -1490,7 +1493,7 @@ float gfunctionKillsT (int currentIndex, int) float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team0Damage; - Path *current = g_waypoint->GetPath (currentIndex); + Path *current = waypoint->GetPath (currentIndex); for (int i = 0; i < MAX_PATH_INDEX; i++) { @@ -1515,7 +1518,7 @@ float gfunctionKillsCT (int currentIndex, int parentIndex) float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team1Damage; - Path *current = g_waypoint->GetPath (currentIndex); + Path *current = waypoint->GetPath (currentIndex); for (int i = 0; i < MAX_PATH_INDEX; i++) { @@ -1538,7 +1541,7 @@ float gfunctionKillsCTWithHostage (int currentIndex, int parentIndex) if (parentIndex == -1) return 0; - Path *current = g_waypoint->GetPath (currentIndex); + Path *current = waypoint->GetPath (currentIndex); if (current->flags & FLAG_NOHOSTAGE) return 65355; @@ -1554,8 +1557,8 @@ float gfunctionPathDist (int currentIndex, int parentIndex) if (parentIndex == -1) return 0; - Path *parent = g_waypoint->GetPath (parentIndex); - Path *current = g_waypoint->GetPath (currentIndex); + Path *parent = waypoint->GetPath (parentIndex); + Path *current = waypoint->GetPath (currentIndex); for (int i = 0; i < MAX_PATH_INDEX; i++) { @@ -1573,7 +1576,7 @@ float gfunctionPathDist (int currentIndex, int parentIndex) float gfunctionPathDistWithHostage (int currentIndex, int parentIndex) { - Path *current = g_waypoint->GetPath (currentIndex); + Path *current = waypoint->GetPath (currentIndex); if (current->flags & FLAG_NOHOSTAGE) return 65355; @@ -1588,8 +1591,8 @@ float hfunctionSquareDist (int index, int, int goalIndex) { // square distance heuristic - Path *start = g_waypoint->GetPath (index); - Path *goal = g_waypoint->GetPath (goalIndex); + Path *start = waypoint->GetPath (index); + Path *goal = waypoint->GetPath (goalIndex); #if 0 float deltaX = fabsf (start->origin.x - goal->origin.x); @@ -1613,7 +1616,7 @@ float hfunctionSquareDistWithHostage (int index, int startIndex, int goalIndex) { // square distance heuristic with hostages - if (g_waypoint->GetPath (startIndex)->flags & FLAG_NOHOSTAGE) + if (waypoint->GetPath (startIndex)->flags & FLAG_NOHOSTAGE) return 65355; return hfunctionSquareDist (index, startIndex, goalIndex); @@ -1771,7 +1774,7 @@ void Bot::FindPath (int srcIndex, int destIndex, unsigned char pathType) // now expand the current node for (int i = 0; i < MAX_PATH_INDEX; i++) { - int currentChild = g_waypoint->GetPath (currentIndex)->index[i]; + int currentChild = waypoint->GetPath (currentIndex)->index[i]; if (currentChild == -1) continue; @@ -1819,20 +1822,20 @@ int Bot::GetAimingWaypoint (const Vector &to) // return the most distant waypoint which is seen from the bot to the target and is within count if (m_currentWaypointIndex == -1) - m_currentWaypointIndex = ChangeWptIndex (g_waypoint->FindNearest (pev->origin)); + m_currentWaypointIndex = ChangeWptIndex (waypoint->FindNearest (pev->origin)); int srcIndex = m_currentWaypointIndex; - int destIndex = g_waypoint->FindNearest (to); + int destIndex = waypoint->FindNearest (to); int bestIndex = srcIndex; while (destIndex != srcIndex) { - destIndex = *(g_waypoint->m_pathMatrix + (destIndex * g_numWaypoints) + srcIndex); + destIndex = *(waypoint->m_pathMatrix + (destIndex * g_numWaypoints) + srcIndex); if (destIndex < 0) break; - if (g_waypoint->IsVisible (m_currentWaypointIndex, destIndex)) + if (waypoint->IsVisible (m_currentWaypointIndex, destIndex)) { bestIndex = destIndex; break; @@ -1867,11 +1870,11 @@ bool Bot::FindWaypoint (void) #endif continue; - if ((g_mapType & MAP_CS) && HasHostage () && (g_waypoint->GetPath (i)->flags & FLAG_NOHOSTAGE)) + if ((g_mapType & MAP_CS) && HasHostage () && (waypoint->GetPath (i)->flags & FLAG_NOHOSTAGE)) continue; // ignore non-reacheable waypoints... - if (!g_waypoint->Reachable (this, i)) + if (!waypoint->Reachable (this, i)) continue; // check if waypoint is already used by another bot... @@ -1882,7 +1885,7 @@ bool Bot::FindWaypoint (void) } // now pick 1-2 random waypoints that near the bot - float distance = (g_waypoint->GetPath (i)->origin - pev->origin).GetLengthSquared (); + float distance = (waypoint->GetPath (i)->origin - pev->origin).GetLengthSquared (); // now fill the waypoint list for (int j = 0; j < 3; j++) @@ -1915,7 +1918,7 @@ bool Bot::FindWaypoint (void) i = 0; Array found; - g_waypoint->FindInRadius (found, 256.0f, pev->origin); + waypoint->FindInRadius (found, 256.0f, pev->origin); if (!found.IsEmpty ()) { @@ -1926,7 +1929,7 @@ bool Bot::FindWaypoint (void) { int index = found.Pop (); - if (!g_waypoint->Reachable (this, index)) + if (!waypoint->Reachable (this, index)) continue; waypointIndeces[i] = index; @@ -2055,7 +2058,7 @@ int Bot::ChangeWptIndex(int waypointIndex) m_currentWaypointIndex = waypointIndex; m_navTimeset = GetWorldTime (); - m_currentPath = g_waypoint->GetPath (m_currentWaypointIndex); + m_currentPath = waypoint->GetPath (m_currentWaypointIndex); m_waypointFlags = m_currentPath->flags; return m_currentWaypointIndex; // to satisfy static-code analyzers @@ -2065,7 +2068,7 @@ int Bot::ChooseBombWaypoint (void) { // this function finds the best goal (bomb) waypoint for CTs when searching for a planted bomb. - Array goals = g_waypoint->m_goalPoints; + Array goals = waypoint->m_goalPoints; if (goals.IsEmpty ()) return Random.Long (0, g_numWaypoints - 1); // reliability check @@ -2082,7 +2085,7 @@ int Bot::ChooseBombWaypoint (void) // find nearest goal waypoint either to bomb (if "heard" or player) FOR_EACH_AE (goals, i) { - float distance = (g_waypoint->GetPath (goals[i])->origin - bombOrigin).GetLengthSquared (); + float distance = (waypoint->GetPath (goals[i])->origin - bombOrigin).GetLengthSquared (); // check if we got more close distance if (distance < lastDistance) @@ -2092,7 +2095,7 @@ int Bot::ChooseBombWaypoint (void) } } - while (g_waypoint->IsGoalVisited (goal)) + while (waypoint->IsGoalVisited (goal)) { goal = goals.GetRandomElement (); @@ -2118,8 +2121,8 @@ int Bot::FindDefendWaypoint (const Vector &origin) minDistance[i] = 128; } - int posIndex = g_waypoint->FindNearest (origin); - int srcIndex = g_waypoint->FindNearest (pev->origin); + int posIndex = waypoint->FindNearest (origin); + int srcIndex = waypoint->FindNearest (pev->origin); // some of points not found, return random one if (srcIndex == -1 || posIndex == -1) @@ -2128,17 +2131,17 @@ int Bot::FindDefendWaypoint (const Vector &origin) for (int i = 0; i < g_numWaypoints; i++) // find the best waypoint now { // exclude ladder & current waypoints - if ((g_waypoint->GetPath (i)->flags & FLAG_LADDER) || i == srcIndex || !g_waypoint->IsVisible (i, posIndex) || IsPointOccupied (i)) + if ((waypoint->GetPath (i)->flags & FLAG_LADDER) || i == srcIndex || !waypoint->IsVisible (i, posIndex) || IsPointOccupied (i)) continue; // use the 'real' pathfinding distances - int distances = g_waypoint->GetPathDistance (srcIndex, i); + int distances = waypoint->GetPathDistance (srcIndex, i); // skip wayponts with distance more than 1024 units if (distances > 1248.0f) continue; - TraceLine (g_waypoint->GetPath (i)->origin, g_waypoint->GetPath (posIndex)->origin, true, true, GetEntity (), &tr); + TraceLine (waypoint->GetPath (i)->origin, waypoint->GetPath (posIndex)->origin, true, true, GetEntity (), &tr); // check if line not hit anything if (tr.flFraction != 1.0) @@ -2205,7 +2208,7 @@ int Bot::FindDefendWaypoint (const Vector &origin) for (int i = 0; i < g_numWaypoints; i++) { - if ((g_waypoint->GetPath (i)->origin - origin).GetLength () <= 1248.0f && !IsPointOccupied (i)) + if ((waypoint->GetPath (i)->origin - origin).GetLength () <= 1248.0f && !IsPointOccupied (i)) found.Push (i); } @@ -2237,7 +2240,7 @@ int Bot::FindCoverWaypoint (float maxDistance) maxDistance = 300.0; int srcIndex = m_currentWaypointIndex; - int enemyIndex = g_waypoint->FindNearest (m_lastEnemyOrigin); + int enemyIndex = waypoint->FindNearest (m_lastEnemyOrigin); Array enemyIndices; int waypointIndex[MAX_PATH_INDEX]; @@ -2255,8 +2258,8 @@ int Bot::FindCoverWaypoint (float maxDistance) // now get enemies neigbouring points for (int i = 0; i < MAX_PATH_INDEX; i++) { - if (g_waypoint->GetPath (enemyIndex)->index[i] != -1) - enemyIndices.Push (g_waypoint->GetPath (enemyIndex)->index[i]); + if (waypoint->GetPath (enemyIndex)->index[i] != -1) + enemyIndices.Push (waypoint->GetPath (enemyIndex)->index[i]); } // ensure we're on valid point @@ -2266,14 +2269,14 @@ int Bot::FindCoverWaypoint (float maxDistance) for (int i = 0; i < g_numWaypoints; i++) { // exclude ladder, current waypoints and waypoints seen by the enemy - if ((g_waypoint->GetPath (i)->flags & FLAG_LADDER) || i == srcIndex || g_waypoint->IsVisible (enemyIndex, i)) + if ((waypoint->GetPath (i)->flags & FLAG_LADDER) || i == srcIndex || waypoint->IsVisible (enemyIndex, i)) continue; bool neighbourVisible = false; // now check neighbour waypoints for visibility FOR_EACH_AE (enemyIndices, j) { - if (g_waypoint->IsVisible (enemyIndices[j], i)) + if (waypoint->IsVisible (enemyIndices[j], i)) { neighbourVisible = true; break; @@ -2285,8 +2288,8 @@ int Bot::FindCoverWaypoint (float maxDistance) continue; // use the 'real' pathfinding distances - int distances = g_waypoint->GetPathDistance (srcIndex, i); - int enemyDistance = g_waypoint->GetPathDistance (enemyIndex, i); + int distances = waypoint->GetPathDistance (srcIndex, i); + int enemyDistance = waypoint->GetPathDistance (enemyIndex, i); if (distances >= enemyDistance) continue; @@ -2350,7 +2353,7 @@ int Bot::FindCoverWaypoint (float maxDistance) { if (waypointIndex[i] != -1) { - TraceLine (m_lastEnemyOrigin + Vector (0, 0, 36), g_waypoint->GetPath (waypointIndex[i])->origin, true, true, GetEntity (), &tr); + TraceLine (m_lastEnemyOrigin + Vector (0, 0, 36), waypoint->GetPath (waypointIndex[i])->origin, true, true, GetEntity (), &tr); if (tr.flFraction < 1.0) return waypointIndex[i]; @@ -2379,9 +2382,9 @@ bool Bot::GetBestNextWaypoint (void) { int id = m_currentPath->index[i]; - if (id != -1 && g_waypoint->IsConnected (id, m_navNode->next->index) && g_waypoint->IsConnected (m_currentWaypointIndex, id)) + if (id != -1 && waypoint->IsConnected (id, m_navNode->next->index) && waypoint->IsConnected (m_currentWaypointIndex, id)) { - if (g_waypoint->GetPath (id)->flags & FLAG_LADDER) // don't use ladder waypoints as alternative + if (waypoint->GetPath (id)->flags & FLAG_LADDER) // don't use ladder waypoints as alternative continue; if (!IsPointOccupied (id)) @@ -2423,13 +2426,13 @@ bool Bot::HeadTowardWaypoint (void) { m_campButtons = 0; - int waypoint = m_navNode->next->index; + int nextIndex = m_navNode->next->index; float kills = 0; if (m_team == TEAM_TF) - kills = (g_experienceData + (waypoint * g_numWaypoints) + waypoint)->team0Damage / g_highestDamageT; + kills = (g_experienceData + (nextIndex * g_numWaypoints) + nextIndex)->team0Damage / g_highestDamageT; else - kills = (g_experienceData + (waypoint * g_numWaypoints) + waypoint)->team1Damage / g_highestDamageCT; + kills = (g_experienceData + (nextIndex * g_numWaypoints) + nextIndex)->team1Damage / g_highestDamageCT; // if damage done higher than one if (kills > 0.15f && g_timeRoundMid + 15.0f < GetWorldTime ()) @@ -2448,7 +2451,7 @@ bool Bot::HeadTowardWaypoint (void) if (m_baseAgressionLevel < kills && HasPrimaryWeapon ()) { PushTask (TASK_CAMP, TASKPRI_CAMP, -1, GetWorldTime () + Random.Float (m_difficulty * 0.5, m_difficulty) * 5, true); - PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, FindDefendWaypoint (g_waypoint->GetPath (waypoint)->origin), GetWorldTime () + Random.Float (3.0f, 10.0f), true); + PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, FindDefendWaypoint (waypoint->GetPath (nextIndex)->origin), GetWorldTime () + Random.Float (3.0f, 10.0f), true); } } else if (g_botsCanPause && !IsOnLadder () && !IsInWater () && !m_currentTravelFlags && IsOnFloor ()) @@ -2492,8 +2495,8 @@ bool Bot::HeadTowardWaypoint (void) { for (int i = 0; i < MAX_PATH_INDEX; i++) { - Path *path = g_waypoint->GetPath (m_navNode->index); - Path *next = g_waypoint->GetPath (m_navNode->next->index); + Path *path = waypoint->GetPath (m_navNode->index); + Path *next = waypoint->GetPath (m_navNode->next->index); if (path->index[i] == m_navNode->next->index && (path->connectionFlags[i] & PATHFLAG_JUMP)) { @@ -2513,12 +2516,12 @@ bool Bot::HeadTowardWaypoint (void) SelectWeaponByName ("weapon_knife"); // draw out the knife if we needed // bot not already on ladder but will be soon? - if ((g_waypoint->GetPath (destIndex)->flags & FLAG_LADDER) && !IsOnLadder ()) + if ((waypoint->GetPath (destIndex)->flags & FLAG_LADDER) && !IsOnLadder ()) { // get ladder waypoints used by other (first moving) bots for (int c = 0; c < GetMaxClients (); c++) { - Bot *otherBot = g_botManager->GetBot (c); + Bot *otherBot = botMgr->GetBot (c); // if another bot uses this ladder, wait 3 secs if (otherBot != NULL && otherBot != this && IsAlive (otherBot->GetEntity ()) && otherBot->m_currentWaypointIndex == m_navNode->index) @@ -3125,10 +3128,10 @@ int Bot::GetAimingWaypoint (void) for (int i = 0; i < g_numWaypoints; i++) { - if (currentWaypoint == i || !g_waypoint->IsVisible (currentWaypoint, i)) + if (currentWaypoint == i || !waypoint->IsVisible (currentWaypoint, i)) continue; - Path *path = g_waypoint->GetPath (i); + Path *path = waypoint->GetPath (i); if (count < 3) { @@ -3375,7 +3378,7 @@ int Bot::FindPlantedBomb (void) { if (strcmp (STRING (bombEntity->v.model) + 9, "c4.mdl") == 0) { - int nearestIndex = g_waypoint->FindNearest (GetEntityOrigin (bombEntity)); + int nearestIndex = waypoint->FindNearest (GetEntityOrigin (bombEntity)); if ((nearestIndex >= 0) && (nearestIndex < g_numWaypoints)) return nearestIndex; @@ -3394,7 +3397,7 @@ bool Bot::IsPointOccupied (int index) // first check if current waypoint of one of the bots is index waypoint for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot == NULL || bot == this) continue; @@ -3404,7 +3407,7 @@ bool Bot::IsPointOccupied (int index) { int occupyId = GetShootingConeDeviation (bot->GetEntity (), &pev->origin) >= 0.7f ? bot->m_prevWptIndex[0] : m_currentWaypointIndex; - if (occupyId == index || bot->GetTask ()->data == index || (g_waypoint->GetPath (occupyId)->origin - g_waypoint->GetPath (index)->origin).GetLengthSquared () < 4096.0f) + if (occupyId == index || bot->GetTask ()->data == index || (waypoint->GetPath (occupyId)->origin - waypoint->GetPath (index)->origin).GetLengthSquared () < 4096.0f) return true; } } diff --git a/source/netmsg.cpp b/source/netmsg.cpp index aec3782..f764359 100644 --- a/source/netmsg.cpp +++ b/source/netmsg.cpp @@ -255,7 +255,7 @@ void NetworkMsg::Execute (void *p) break; case 2: - g_botManager->SetDeathMsgState (true); + botMgr->SetDeathMsgState (true); if (killerIndex != 0 && killerIndex != victimIndex) { @@ -270,7 +270,7 @@ void NetworkMsg::Execute (void *p) // need to send congrats on well placed shot for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot != NULL && IsAlive (bot->GetEntity ()) && killer != bot->GetEntity () && bot->EntityIsVisible (victim->v.origin) && GetTeam (killer) == GetTeam (bot->GetEntity ()) && GetTeam (killer) != GetTeam (victim)) { @@ -287,7 +287,7 @@ void NetworkMsg::Execute (void *p) // notice nearby to victim teammates, that attacker is near for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot != NULL && IsAlive (bot->GetEntity ()) && GetTeam (bot->GetEntity ()) == GetTeam (victim) && IsVisible (killer->v.origin, bot->GetEntity ()) && IsEntityNull (bot->m_enemy) && GetTeam (killer) != GetTeam (victim)) { @@ -299,7 +299,7 @@ void NetworkMsg::Execute (void *p) } } - Bot *bot = g_botManager->GetBot (killer); + Bot *bot = botMgr->GetBot (killer); // is this message about a bot who killed somebody? if (bot != NULL) @@ -307,7 +307,7 @@ void NetworkMsg::Execute (void *p) else // did a human kill a bot on his team? { - Bot *target = g_botManager->GetBot (victim); + Bot *target = botMgr->GetBot (victim); if (target != NULL) { @@ -393,11 +393,11 @@ void NetworkMsg::Execute (void *p) if (FStrEq (PTR_TO_STR (p), "#CTs_Win")) { - g_botManager->SetLastWinner (TEAM_CF); // update last winner for economics + botMgr->SetLastWinner (TEAM_CF); // update last winner for economics if (yb_communication_type.GetInt () == 2) { - Bot *bot = g_botManager->FindOneValidAliveBot (); + Bot *bot = botMgr->FindOneValidAliveBot (); if (bot != NULL && IsAlive (bot->GetEntity ())) bot->HandleChatterMessage (PTR_TO_STR (p)); @@ -406,23 +406,23 @@ void NetworkMsg::Execute (void *p) if (FStrEq (PTR_TO_STR (p), "#Game_will_restart_in")) { - g_botManager->CheckTeamEconomics (TEAM_CF, true); - g_botManager->CheckTeamEconomics (TEAM_TF, true); + botMgr->CheckTeamEconomics (TEAM_CF, true); + botMgr->CheckTeamEconomics (TEAM_TF, true); } if (FStrEq (PTR_TO_STR (p), "#Terrorists_Win")) { - g_botManager->SetLastWinner (TEAM_TF); // update last winner for economics + botMgr->SetLastWinner (TEAM_TF); // update last winner for economics if (yb_communication_type.GetInt () == 2) { - Bot *bot = g_botManager->FindOneValidAliveBot (); + Bot *bot = botMgr->FindOneValidAliveBot (); if (bot != NULL && IsAlive (bot->GetEntity ())) bot->HandleChatterMessage (PTR_TO_STR (p)); } } - g_waypoint->SetBombPosition (true); + waypoint->SetBombPosition (true); } else if (!g_bombPlanted && FStrEq (PTR_TO_STR (p), "#Bomb_Planted")) { @@ -431,7 +431,7 @@ void NetworkMsg::Execute (void *p) for (int i = 0; i < GetMaxClients (); i++) { - Bot *bot = g_botManager->GetBot (i); + Bot *bot = botMgr->GetBot (i); if (bot != NULL && IsAlive (bot->GetEntity ())) { @@ -442,7 +442,7 @@ void NetworkMsg::Execute (void *p) bot->ChatterMessage (Chatter_WhereIsTheBomb); } } - g_waypoint->SetBombPosition (); + waypoint->SetBombPosition (); } else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_BurstFire")) m_bot->m_weaponBurstMode = BM_ON; diff --git a/source/support.cpp b/source/support.cpp index 9596230..52cc752 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -162,7 +162,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu) String tempText = String (menu->menuText); tempText.Replace ("\v", "\n"); - char *text = g_localizer->TranslateInput (tempText.GetBuffer ()); + char *text = locale->TranslateInput (tempText.GetBuffer ()); tempText = String (text); // make menu looks best @@ -173,7 +173,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu) while (strlen (text) >= 64) { - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, g_netMsg->GetId (NETMSG_SHOWMENU), NULL, ent); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, netmsg->GetId (NETMSG_SHOWMENU), NULL, ent); WRITE_SHORT (menu->validSlots); WRITE_CHAR (-1); WRITE_BYTE (1); @@ -186,7 +186,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu) text += 64; } - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, g_netMsg->GetId (NETMSG_SHOWMENU), NULL, ent); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, netmsg->GetId (NETMSG_SHOWMENU), NULL, ent); WRITE_SHORT (menu->validSlots); WRITE_CHAR (-1); WRITE_BYTE (0); @@ -197,7 +197,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu) } else { - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, g_netMsg->GetId (NETMSG_SHOWMENU), NULL, ent); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, netmsg->GetId (NETMSG_SHOWMENU), NULL, ent); WRITE_SHORT (0); WRITE_CHAR (0); WRITE_BYTE (0); @@ -287,14 +287,14 @@ void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex) void FreeLibraryMemory (void) { // this function free's all allocated memory - g_waypoint->Init (); // frees waypoint data + waypoint->Init (); // frees waypoint data - FOR_EACH_AE (g_localizer->m_langTab, it) + FOR_EACH_AE (locale->m_langTab, it) { - delete[] g_localizer->m_langTab[it].original; - delete[] g_localizer->m_langTab[it].translated; + delete[] locale->m_langTab[it].original; + delete[] locale->m_langTab[it].translated; } - g_localizer->m_langTab.RemoveAll (); + locale->m_langTab.RemoveAll (); delete [] g_experienceData; @@ -738,18 +738,18 @@ void RoundInit (void) g_roundEnded = false; // check team economics - g_botManager->CheckTeamEconomics (TEAM_TF); - g_botManager->CheckTeamEconomics (TEAM_CF); + botMgr->CheckTeamEconomics (TEAM_TF); + botMgr->CheckTeamEconomics (TEAM_CF); for (int i = 0; i < GetMaxClients (); i++) { - if (g_botManager->GetBot (i)) - g_botManager->GetBot (i)->NewRound (); + if (botMgr->GetBot (i)) + botMgr->GetBot (i)->NewRound (); g_radioSelect[i] = 0; } - g_waypoint->SetBombPosition (true); - g_waypoint->ClearGoalScore (); + waypoint->SetBombPosition (true); + waypoint->ClearGoalScore (); g_bombSayString = false; g_timeBombPlanted = 0.0; @@ -798,7 +798,7 @@ bool IsValidPlayer (edict_t *ent) if (ent->v.flags & FL_PROXY) return false; - if ((ent->v.flags & (FL_CLIENT | FL_FAKECLIENT)) || g_botManager->GetBot (ent) != NULL) + if ((ent->v.flags & (FL_CLIENT | FL_FAKECLIENT)) || botMgr->GetBot (ent) != NULL) return !IsNullString (STRING (ent->v.netname)); return false; @@ -817,7 +817,7 @@ bool IsPlayerVIP (edict_t *ent) bool IsValidBot (edict_t *ent) { - if (g_botManager->GetBot (ent) != NULL || (!IsEntityNull (ent) && (ent->v.flags & FL_FAKECLIENT))) + if (botMgr->GetBot (ent) != NULL || (!IsEntityNull (ent) && (ent->v.flags & FL_FAKECLIENT))) return true; return false; @@ -836,7 +836,7 @@ void ServerPrint (const char *format, ...) char string[3072]; va_start (ap, format); - vsprintf (string, g_localizer->TranslateInput (format), ap); + vsprintf (string, locale->TranslateInput (format), ap); va_end (ap); SERVER_PRINT (string); @@ -849,7 +849,7 @@ void CenterPrint (const char *format, ...) char string[2048]; va_start (ap, format); - vsprintf (string, g_localizer->TranslateInput (format), ap); + vsprintf (string, locale->TranslateInput (format), ap); va_end (ap); if (IsDedicatedServer ()) @@ -858,7 +858,7 @@ void CenterPrint (const char *format, ...) return; } - MESSAGE_BEGIN (MSG_BROADCAST, g_netMsg->GetId (NETMSG_TEXTMSG)); + MESSAGE_BEGIN (MSG_BROADCAST, netmsg->GetId (NETMSG_TEXTMSG)); WRITE_BYTE (HUD_PRINTCENTER); WRITE_STRING (FormatBuffer ("%s\n", string)); MESSAGE_END (); @@ -870,7 +870,7 @@ void ChartPrint (const char *format, ...) char string[2048]; va_start (ap, format); - vsprintf (string, g_localizer->TranslateInput (format), ap); + vsprintf (string, locale->TranslateInput (format), ap); va_end (ap); if (IsDedicatedServer ()) @@ -880,7 +880,7 @@ void ChartPrint (const char *format, ...) } strcat (string, "\n"); - MESSAGE_BEGIN (MSG_BROADCAST, g_netMsg->GetId (NETMSG_TEXTMSG)); + MESSAGE_BEGIN (MSG_BROADCAST, netmsg->GetId (NETMSG_TEXTMSG)); WRITE_BYTE (HUD_PRINTTALK); WRITE_STRING (string); MESSAGE_END (); @@ -893,7 +893,7 @@ void ClientPrint (edict_t *ent, int dest, const char *format, ...) char string[2048]; va_start (ap, format); - vsprintf (string, g_localizer->TranslateInput (format), ap); + vsprintf (string, locale->TranslateInput (format), ap); va_end (ap); if (IsEntityNull (ent) || ent == g_hostEntity) @@ -1037,7 +1037,7 @@ void CheckWelcomeMessage (void) WRITE_SHORT (FixedUnsigned16 (2, 1 << 8)); WRITE_SHORT (FixedUnsigned16 (6, 1 << 8)); WRITE_SHORT (FixedUnsigned16 (0.1, 1 << 8)); - WRITE_STRING (FormatBuffer ("\nServer is running YaPB v%s (Build: %u)\nDeveloped by %s\n\n%s", PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_AUTHOR, g_waypoint->GetInfo ())); + WRITE_STRING (FormatBuffer ("\nServer is running YaPB v%s (Build: %u)\nDeveloped by %s\n\n%s", PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_AUTHOR, waypoint->GetInfo ())); MESSAGE_END (); receiveTime = 0.0; @@ -1113,7 +1113,7 @@ void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...) char buffer[512] = {0, }, levelString[32] = {0, }, logLine[1024] = {0, }; va_start (ap, format); - vsprintf (buffer, g_localizer->TranslateInput (format), ap); + vsprintf (buffer, locale->TranslateInput (format), ap); va_end (ap); switch (logLevel) @@ -1252,7 +1252,7 @@ bool FindNearestPlayer (void **pvHolder, edict_t *to, float searchDistance, bool // fill the holder if (needBot) - *pvHolder = reinterpret_cast (g_botManager->GetBot (survive)); + *pvHolder = reinterpret_cast (botMgr->GetBot (survive)); else *pvHolder = reinterpret_cast (survive); diff --git a/source/waypoint.cpp b/source/waypoint.cpp index 2df769c..3cf5c3b 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -174,8 +174,8 @@ void Waypoint::Add (int flags, const Vector &waypointOrigin) if (waypointOrigin == nullvec) newOrigin = g_hostEntity->v.origin; - if (g_botManager->GetBotsNum () > 0) - g_botManager->RemoveAll (); + if (botMgr->GetBotsNum () > 0) + botMgr->RemoveAll (); g_waypointsChanged = true; @@ -459,8 +459,8 @@ void Waypoint::Delete (void) if (g_numWaypoints < 1) return; - if (g_botManager->GetBotsNum () > 0) - g_botManager->RemoveAll (); + if (botMgr->GetBotsNum () > 0) + botMgr->RemoveAll (); int index = FindNearest (g_hostEntity->v.origin, 50.0); @@ -1210,7 +1210,7 @@ bool Waypoint::Load (void) InitVisibilityTab (); InitExperienceTab (); - g_botManager->InitQuota (); + botMgr->InitQuota (); extern ConVar yb_debug_goal; yb_debug_goal.SetInt (-1); @@ -2658,7 +2658,7 @@ WaypointDownloadError WaypointDownloader::DoDownload (void) recvPosition++; } - File fp (g_waypoint->CheckSubfolderFile (), "wb"); + File fp (waypoint->CheckSubfolderFile (), "wb"); if (!fp.IsValid ()) {