diff --git a/include/core.h b/include/core.h index 981bcbb..ba18e34 100644 --- a/include/core.h +++ b/include/core.h @@ -993,7 +993,7 @@ private: bool IsInViewCone (const Vector &origin); void ReactOnSound (void); - bool CheckVisibility (entvars_t *targetOrigin, Vector *origin, byte *bodyPart); + bool CheckVisibility (edict_t *target, Vector *origin, byte *bodyPart); bool IsEnemyViewable (edict_t *player); edict_t *FindNearestButton (const char *className); @@ -1626,7 +1626,6 @@ public: // prototypes of bot functions... extern int GetWeaponReturn (bool isString, const char *weaponAlias, int weaponIndex = -1); -extern int GetTeam (edict_t *ent); extern float GetShootingConeDeviation (edict_t *ent, Vector *position); extern float GetWaveLength (const char *fileName); diff --git a/include/globals.h b/include/globals.h index c63d6ac..2d2bcb1 100644 --- a/include/globals.h +++ b/include/globals.h @@ -121,4 +121,9 @@ static inline int EntOffsetOfEntity(const edict_t *ent) static inline bool IsEntityNull (const edict_t *ent) { return !ent || !EntOffsetOfEntity (ent); -} \ No newline at end of file +} + +static inline int GetTeam (edict_t *ent) +{ + return g_clients[IndexOfEntity (ent) - 1].team; +} diff --git a/source/basecode.cpp b/source/basecode.cpp index dc5564e..fce5c4d 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -100,7 +100,7 @@ bool Bot::IsInViewCone (const Vector &origin) return ::IsInViewCone (origin, GetEntity ()); } -bool Bot::CheckVisibility (entvars_t *targetEntity, Vector *origin, byte *bodyPart) +bool Bot::CheckVisibility (edict_t *target, Vector *origin, byte *bodyPart) { // this function checks visibility of a bot target. @@ -110,69 +110,41 @@ bool Bot::CheckVisibility (entvars_t *targetEntity, Vector *origin, byte *bodyPa *bodyPart = 0; // check for the body - TraceLine (botHead, targetEntity->origin, true, true, GetEntity (), &tr); + TraceLine (botHead, target->v.origin, true, true, GetEntity (), &tr); - if (tr.flFraction >= 1.0) + if (tr.flFraction >= 1.0f) { *bodyPart |= VISIBLE_BODY; - *origin = targetEntity->origin; + *origin = target->v.origin; } // check for the head - TraceLine (botHead, targetEntity->origin + targetEntity->view_ofs, true, true, GetEntity (), &tr); + TraceLine (botHead, target->v.origin + target->v.view_ofs, true, true, GetEntity (), &tr); - if (tr.flFraction >= 1.0) + if (tr.flFraction >= 1.0f) { *bodyPart |= VISIBLE_HEAD; - *origin = targetEntity->origin + targetEntity->view_ofs; + *origin = target->v.origin + target->v.view_ofs; } if (*bodyPart != 0) return true; -#if 0 - // dimension table - const int8 dimensionTab[8][3] = - { - {1, 1, 1}, { 1, 1, -1}, - {1, -1, 1}, {-1, 1, 1}, - {1, -1, -1}, {-1, -1, 1}, - {-1, 1, -1}, {-1, -1, -1} - }; - - // check the box borders - for (int i = 7; i >= 0; i--) - { - Vector targetOrigin = petargetOrigin->origin + Vector (dimensionTab[i][0] * 24.0, dimensionTab[i][1] * 24.0, dimensionTab[i][2] * 24.0); - - // check direct line to random part of the player body - TraceLine (botHead, targetOrigin, true, true, GetEntity (), &tr); - - // check if we hit something - if (tr.flFraction >= 1.0) - { - *origin = tr.vecEndPos; - *bodyPart |= VISIBLE_OTHER; - - return true; - } - } -#else // worst case, choose random position in enemy body for (int i = 0; i < 5; i++) { - Vector targetOrigin = targetEntity->origin; // get the player origin + Vector pos = target->v.origin; // get the player origin // find the vector beetwen mins and maxs of the player body - targetOrigin.x += Random.Float (targetEntity->mins.x * 0.5, targetEntity->maxs.x * 0.5); - targetOrigin.y += Random.Float (targetEntity->mins.y * 0.5, targetEntity->maxs.y * 0.5); - targetOrigin.z += Random.Float (targetEntity->mins.z * 0.5, targetEntity->maxs.z * 0.5); + pos.x += Random.Float (target->v.mins.x * 0.5f, target->v.maxs.x * 0.5f); + pos.y += Random.Float (target->v.mins.y * 0.5f, target->v.maxs.y * 0.5f); + pos.z += Random.Float (target->v.mins.z * 0.5f, target->v.maxs.z * 0.5f); // check direct line to random part of the player body - TraceLine (botHead, targetOrigin, true, true, GetEntity (), &tr); + TraceLine (botHead, pos, true, true, GetEntity (), &tr); // check if we hit something - if (tr.flFraction >= 1.0) + if (tr.flFraction >= 1.0f) { *origin = tr.vecEndPos; *bodyPart |= VISIBLE_OTHER; @@ -180,7 +152,6 @@ bool Bot::CheckVisibility (entvars_t *targetEntity, Vector *origin, byte *bodyPa return true; } } -#endif return false; } @@ -194,7 +165,7 @@ bool Bot::IsEnemyViewable (edict_t *player) if (IsValidPlayer (pev->dmg_inflictor) && GetTeam (pev->dmg_inflictor) != m_team && ::IsInViewCone (EyePosition (), pev->dmg_inflictor)) forceTrueIfVisible = true; - if (CheckVisibility (VARS (player), &m_enemyOrigin, &m_visibility) && (IsInViewCone (player->v.origin + Vector (0, 0, 14)) || forceTrueIfVisible)) + if (CheckVisibility (player, &m_enemyOrigin, &m_visibility) && (IsInViewCone (player->v.origin + Vector (0, 0, 14)) || forceTrueIfVisible)) { m_seeEnemyTime = GetWorldTime (); m_lastEnemy = player; @@ -241,7 +212,7 @@ bool Bot::EntityIsVisible (const Vector &dest, bool fromBody) void Bot::CheckGrenadeThrow (void) { // check if throwing a grenade is a good thing to do... - if (m_lastEnemy == NULL || yb_ignore_enemies.GetBool () || yb_jasonmode.GetBool () && m_grenadeCheckTime > GetWorldTime () || m_isUsingGrenade || GetTaskId () == TASK_PLANTBOMB || GetTaskId () == TASK_DEFUSEBOMB || m_isReloading || !IsAlive (m_lastEnemy)) + if (m_lastEnemy == NULL || yb_ignore_enemies.GetBool () || yb_jasonmode.GetBool () || m_grenadeCheckTime > GetWorldTime () || m_isUsingGrenade || GetTaskId () == TASK_PLANTBOMB || GetTaskId () == TASK_DEFUSEBOMB || m_isReloading || !IsAlive (m_lastEnemy)) { m_states &= ~(STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG); return; @@ -401,6 +372,9 @@ void Bot::AvoidGrenades (void) { edict_t *ent = activeGrenades[it]; + if (ent->v.effects & EF_NODRAW) + continue; + // check if visible to the bot if (!EntityIsVisible (ent->v.origin) && InFieldOfView (ent->v.origin - EyePosition ()) > pev->fov / 2) continue; @@ -460,17 +434,20 @@ bool Bot::IsBehindSmokeClouds (edict_t *ent) // find all grenades on the map IterateArray (activeGrenades, it) { - edict_t *pentGrenade = activeGrenades[it]; + edict_t *grenade = activeGrenades[it]; + + if (grenade->v.effects & EF_NODRAW) + continue; // if grenade is invisible don't care for it - if (!(pentGrenade->v.flags & (FL_ONGROUND | FL_PARTIALGROUND)) || strcmp (STRING (pentGrenade->v.model) + 9, "smokegrenade.mdl")) + if (!(grenade->v.flags & (FL_ONGROUND | FL_PARTIALGROUND)) || strcmp (STRING (grenade->v.model) + 9, "smokegrenade.mdl")) continue; // check if visible to the bot if (!EntityIsVisible (ent->v.origin) && InFieldOfView (ent->v.origin - EyePosition ()) > pev->fov / 3) continue; - const Vector &entityOrigin = GetEntityOrigin (pentGrenade); + const Vector &entityOrigin = GetEntityOrigin (grenade); const Vector &betweenNade = (entityOrigin - pev->origin).Normalize (); const Vector &betweenResult = ((Vector (betweenNade.y, betweenNade.x, 0) * 150.0 + entityOrigin) - pev->origin).Normalize (); @@ -2469,7 +2446,7 @@ void Bot::CheckRadioCommands (void) { if (IsEntityNull (m_enemy) && m_seeEnemyTime + 4.0 < GetWorldTime ()) { - // Decrease Fear Levels to lower probability of Bot seeking Cover again + // decrease fear levels to lower probability of bot seeking cover again m_fearLevel -= 0.2; if (m_fearLevel < 0.0) @@ -2902,33 +2879,27 @@ void Bot::ChooseAimDirection (void) TraceResult tr; memset (&tr, 0, sizeof (TraceResult)); - unsigned int flags = m_aimFlags; - if (!(m_currentWaypointIndex >= 0 && m_currentWaypointIndex < g_numWaypoints)) GetValidWaypoint (); // check if last enemy vector valid - if (m_seeEnemyTime + 7.0 < GetWorldTime () && m_lastEnemyOrigin != nullvec) + if (m_seeEnemyTime + 7.0 < GetWorldTime () && m_lastEnemyOrigin != nullvec && (pev->origin - m_lastEnemyOrigin).GetLength () >= 1600.0f && IsEntityNull (m_enemy) && !UsesSniper ()) { TraceLine (EyePosition (), m_lastEnemyOrigin, false, true, GetEntity (), &tr); - if ((pev->origin - m_lastEnemyOrigin).GetLength () >= 1600 && IsEntityNull (m_enemy) && !UsesSniper () || (tr.flFraction <= 0.2 && tr.pHit == g_hostEntity)) + if (tr.flFraction <= 0.2 && tr.pHit == g_hostEntity) { if ((m_aimFlags & (AIM_LAST_ENEMY | AIM_PREDICT_PATH)) && m_wantsToFire) m_wantsToFire = false; m_lastEnemyOrigin = nullvec; m_aimFlags &= ~(AIM_LAST_ENEMY | AIM_PREDICT_PATH); - - flags &= ~(AIM_LAST_ENEMY | AIM_PREDICT_PATH); - flags = m_aimFlags; } } - else - { + else if (m_lastEnemyOrigin == nullvec) m_aimFlags &= ~(AIM_LAST_ENEMY | AIM_PREDICT_PATH); - flags = m_aimFlags; - } + + unsigned int flags = m_aimFlags; // don't allow bot to look at danger positions under certain circumstances if (!(flags & (AIM_GRENADE | AIM_ENEMY | AIM_ENTITY))) @@ -4266,13 +4237,9 @@ void Bot::RunTask (void) else { edict_t *ent = NULL; - Array activeGrenades = g_botManager->GetActiveGrenades (); - // find all grenades on the map - IterateArray (activeGrenades, it) + while (!IsEntityNull (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) { - ent = activeGrenades[it]; - if (ent->v.owner == GetEntity () && strcmp (STRING (ent->v.model) + 9, "hegrenade.mdl") == 0) { // set the correct velocity for the grenade @@ -4336,13 +4303,8 @@ void Bot::RunTask (void) else { edict_t *ent = NULL; - Array activeGrenades = g_botManager->GetActiveGrenades (); - - // find all grenades on the map - IterateArray (activeGrenades, it) + while (!IsEntityNull (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) { - ent = activeGrenades[it]; - if (ent->v.owner == GetEntity () && strcmp (STRING (ent->v.model) + 9, "flashbang.mdl") == 0) { // set the correct velocity for the grenade @@ -6081,7 +6043,7 @@ void Bot::ReactOnSound (void) extern ConVar yb_shoots_thru_walls; // check if heard enemy can be seen - if (CheckVisibility (VARS (player), &m_lastEnemyOrigin, &m_visibility)) + if (CheckVisibility (player, &m_lastEnemyOrigin, &m_visibility)) { m_enemy = player; m_lastEnemy = player; diff --git a/source/interface.cpp b/source/interface.cpp index e5d06fc..4f9f613 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -72,21 +72,6 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c 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)); - // swap counter-terrorist and terrorist teams - else if (stricmp (arg0, "swaptteams") == 0 || stricmp (arg0, "swap") == 0) - { - for (int i = 0; i < GetMaxClients (); i++) - { - if (!(g_clients[i].flags & CF_USED)) - continue; - - if (IsValidBot (g_clients[i].ent)) - FakeClientCommand (g_clients[i].ent, "chooseteam; menuselect %d; menuselect 5", GetTeam (g_clients[i].ent) == TEAM_CF ? 1 : 2); - else - (*g_engfuncs.pfnClientCommand) (g_clients[i].ent, "chooseteam; menuselect %d", GetTeam (g_clients[i].ent) == TEAM_CF ? 1 : 2); - } - } - // select the weapon mode for bots else if (stricmp (arg0, "weaponmode") == 0 || stricmp (arg0, "wmode") == 0) { @@ -116,48 +101,6 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c } } - // force bots to execute client command - else if (stricmp (arg0, "sendcmd") == 0 || stricmp (arg0, "order") == 0) - { - if (IsNullString (arg1)) - return 1; - - edict_t *target = EntityOfIndex (atoi (arg1) - 1); - - if (IsValidBot (target)) - { - FakeClientCommand (target, arg2); - ClientPrint (ent, print_withtag, "Bot %s executing command %s", STRING (target->v.netname), arg2); - } - else - ClientPrint (ent, print_withtag, "Player is not BOT!"); - } - - // display current time on the server - else if (stricmp (arg0, "test") == 0) - { - ServerPrint ("mp_bt = %.2f", mp_startmoney.GetFloat ()); - } - - // displays bot about information - else if (stricmp (arg0, "about_bot") == 0 || stricmp (arg0, "about") == 0) - { - if (g_gameVersion == CSV_OLD) - { - ServerPrint ("Cannot do this on CS 1.5"); - return 1; - } - - char aboutData[] = - "+---------------------------------------------------------------------------------+\n" - " The YaPB for Counter-Strike Version " PRODUCT_SUPPORT_VERSION "\n" - " Created by " PRODUCT_AUTHOR ", Using PODBot Code\n" - " Website: " PRODUCT_URL "\n" - "+---------------------------------------------------------------------------------+\n"; - - HudMessage (ent, true, Vector (Random.Long (33, 255), Random.Long (33, 255), Random.Long (33, 255)), aboutData); - } - // displays version information else if (stricmp (arg0, "version") == 0 || stricmp (arg0, "ver") == 0) { @@ -201,7 +144,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c if (!IsDedicatedServer ()) { - ServerPrint ("yapb autowp - toggle autowppointing."); + ServerPrint ("yapb autowp - toggle autowaypointing."); ServerPrint ("yapb wp - toggle waypoint showing."); ServerPrint ("yapb wp on noclip - enable noclip cheat"); ServerPrint ("yapb wp save nocheck - save waypoints without checking."); @@ -209,7 +152,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c ServerPrint ("yapb wp menu - open main waypoint menu."); ServerPrint ("yapb wp addbasic - creates basic waypoints on map."); ServerPrint ("yapb wp find - show direction to specified waypoint."); - ServerPrint ("yapb wp load - wload the waypoint file from hard disk."); + ServerPrint ("yapb wp load - load the waypoint file from hard disk."); ServerPrint ("yapb wp check - checks if all waypoints connections are valid."); ServerPrint ("yapb wp cache - cache nearest waypoint."); ServerPrint ("yapb wp teleport - teleport hostile to specified waypoint."); diff --git a/source/manager.cpp b/source/manager.cpp index a140d4b..35618d9 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -1358,12 +1358,7 @@ void BotManager::UpdateActiveGrenades (void) // search the map for any type of grenade while (!IsEntityNull (grenade = FIND_ENTITY_BY_CLASSNAME (grenade, "grenade"))) - { - if (grenade->v.effects & EF_NODRAW) - continue; - m_activeGrenades.Push (grenade); - } } const Array &BotManager::GetActiveGrenades (void) diff --git a/source/navigate.cpp b/source/navigate.cpp index 09bebd2..5432fe9 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -311,7 +311,7 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dir, const Vector &di TraceResult tr; edict_t *nearest = NULL; - if (FindNearestPlayer (reinterpret_cast (&nearest), GetEntity (), pev->maxspeed, true, false, true, true)) // found somebody? + if (g_timeRoundStart + 10.0f < GetWorldTime () && FindNearestPlayer (reinterpret_cast (&nearest), GetEntity (), pev->maxspeed, true, false, true, true)) // found somebody? { MakeVectors (m_moveAngles); // use our movement angles @@ -655,7 +655,7 @@ bool Bot::DoWaypointNav (void) if (IsOnFloor () || IsOnLadder ()) { if (m_desiredVelocity.x != 0.0f && m_desiredVelocity.y != 0.0f) - pev->velocity = m_desiredVelocity + m_desiredVelocity * 0.11f; + pev->velocity = m_desiredVelocity + m_desiredVelocity * 0.076f; pev->button |= IN_JUMP; @@ -1939,7 +1939,6 @@ void Bot::GetValidWaypoint (void) if (m_goalFailed > 1) { - DebugMsg ("GOAL FAILED!"); int newGoal = FindGoal (); m_prevGoalIndex = newGoal; @@ -1948,7 +1947,7 @@ void Bot::GetValidWaypoint (void) // remember index GetTask ()->data = newGoal; - // do pathfinding if it's not the current waypoint + // do path finding if it's not the current waypoint if (newGoal != m_currentWaypointIndex) FindPath (m_currentWaypointIndex, newGoal, m_pathType); @@ -2300,9 +2299,7 @@ bool Bot::GetBestNextWaypoint (void) if (!IsPointOccupied (id)) { - DebugMsg ("postprocess %d -> %d", m_navNode->index, id); m_navNode->index = id; - return true; } } diff --git a/source/netmsg.cpp b/source/netmsg.cpp index 5f5cfc8..6c76eed 100644 --- a/source/netmsg.cpp +++ b/source/netmsg.cpp @@ -270,19 +270,22 @@ void NetworkMsg::Execute (void *p) if (IsEntityNull (killer) || IsEntityNull (victim)) break; - // need to send congrats on well placed shot - for (int i = 0; i < GetMaxClients (); i++) + if (yb_communication_type.GetInt () == 2) { - Bot *bot = g_botManager->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)) + // need to send congrats on well placed shot + for (int i = 0; i < GetMaxClients (); i++) { - if (killer == g_hostEntity) - bot->HandleChatterMessage ("#Bot_NiceShotCommander"); - else - bot->HandleChatterMessage ("#Bot_NiceShotPall"); + Bot *bot = g_botManager->GetBot (i); - break; + if (bot != NULL && IsAlive (bot->GetEntity ()) && killer != bot->GetEntity () && bot->EntityIsVisible (victim->v.origin) && GetTeam (killer) == GetTeam (bot->GetEntity ()) && GetTeam (killer) != GetTeam (victim)) + { + if (killer == g_hostEntity) + bot->HandleChatterMessage ("#Bot_NiceShotCommander"); + else + bot->HandleChatterMessage ("#Bot_NiceShotPall"); + + break; + } } } @@ -394,11 +397,30 @@ void NetworkMsg::Execute (void *p) g_isCommencing = true; if (FStrEq (PTR_TO_STR (p), "#CTs_Win")) + { g_botManager->SetLastWinner (TEAM_CF); // update last winner for economics + if (yb_communication_type.GetInt () == 2) + { + Bot *bot = g_botManager->FindOneValidAliveBot (); + + if (bot != NULL && IsAlive (bot->GetEntity ())) + bot->HandleChatterMessage (PTR_TO_STR (p)); + } + } + if (FStrEq (PTR_TO_STR (p), "#Terrorists_Win")) + { g_botManager->SetLastWinner (TEAM_TF); // update last winner for economics + if (yb_communication_type.GetInt () == 2) + { + Bot *bot = g_botManager->FindOneValidAliveBot (); + + if (bot != NULL && IsAlive (bot->GetEntity ())) + bot->HandleChatterMessage (PTR_TO_STR (p)); + } + } g_waypoint->SetBombPosition (true); } else if (!g_bombPlanted && FStrEq (PTR_TO_STR (p), "#Bomb_Planted")) @@ -406,36 +428,28 @@ void NetworkMsg::Execute (void *p) g_bombPlanted = g_bombSayString = true; g_timeBombPlanted = GetWorldTime (); - if (yb_communication_type.GetInt() == 2) - { - for (int i = 0; i < GetMaxClients(); i++) - { - Bot *bot = g_botManager->GetBot(i); + if (yb_communication_type.GetInt () == 2) + { + for (int i = 0; i < GetMaxClients (); i++) + { + Bot *bot = g_botManager->GetBot (i); - if (bot != NULL && IsAlive(bot->GetEntity())) - { - bot->DeleteSearchNodes(); - bot->ResetTasks(); + if (bot != NULL && IsAlive (bot->GetEntity ())) + { + bot->DeleteSearchNodes (); + bot->ResetTasks (); - if (Random.Long(0, 100) < 75 && GetTeam(bot->GetEntity()) == TEAM_CF) - bot->ChatterMessage(Chatter_WhereIsTheBomb); - } - } - } + if (Random.Long (0, 100) < 75 && GetTeam (bot->GetEntity ()) == TEAM_CF) + bot->ChatterMessage (Chatter_WhereIsTheBomb); + } + } + } g_waypoint->SetBombPosition (); } else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_BurstFire")) m_bot->m_weaponBurstMode = BM_ON; else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_SemiAuto")) m_bot->m_weaponBurstMode = BM_OFF; - - if (yb_communication_type.GetInt() == 2) - { - Bot *bot = g_botManager->FindOneValidAliveBot(); - - if (bot != NULL && IsAlive(bot->GetEntity())) - bot->HandleChatterMessage(PTR_TO_STR(p)); - } } break; diff --git a/source/support.cpp b/source/support.cpp index abd2d64..370da13 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -789,10 +789,6 @@ int GetWeaponPenetrationPower (int id) return 0; } -int GetTeam (edict_t *ent) -{ - return g_clients[IndexOfEntity (ent) - 1].team; -} bool IsValidPlayer (edict_t *ent) {