diff --git a/.gitignore b/.gitignore index 44da234..05499d6 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,5 @@ Icon *.opensdf *.dll *.sdf -*.suo \ No newline at end of file +*.suo +*.idb \ No newline at end of file diff --git a/include/core.h b/include/core.h index 6ec84be..80e0a40 100644 --- a/include/core.h +++ b/include/core.h @@ -972,7 +972,6 @@ private: float m_randomizeAnglesTime; // time last randomized location float m_playerTargetTime; // time last targeting - void SwitchChatterIcon (bool show); void InstantChatterMessage (int type); void BotAI (void); void CheckSpawnTimeConditions (void); @@ -1136,6 +1135,7 @@ public: bool m_buyingFinished; // done with buying bool m_buyPending; // bot buy is pending bool m_hasDefuser; // does bot has defuser + bool m_hasC4; // does bot has c4 bomb bool m_hasProgressBar; // has progress bar on a HUD bool m_jumpReady; // is double jump ready bool m_canChooseAimDirection; // can choose aiming direction @@ -1212,7 +1212,7 @@ public: inline edict_t *GetEntity (void) { return ENT (pev); }; inline EOFFSET GetOffset (void) { return OFFSET (pev); }; - inline int GetIndex (void) { return ENTINDEX (GetEntity ()); }; + int GetIndex (void); inline Vector Center (void) { return (pev->absmax + pev->absmin) * 0.5; }; inline Vector EyePosition (void) { return pev->origin + pev->view_ofs; }; @@ -1225,6 +1225,7 @@ public: bool FindWaypoint (void); bool EntityIsVisible (const Vector &dest, bool fromBody = false); + void SwitchChatterIcon (bool show); void DeleteSearchNodes (void); void RemoveCertainTask (TaskId_t id); @@ -1260,6 +1261,7 @@ public: bool UsesSubmachineGun (void); bool UsesZoomableRifle (void); bool UsesBadPrimary (void); + bool UsesCampGun (void); bool HasPrimaryWeapon (void); bool HasSecondaryWeapon(void); bool HasShield (void); @@ -1654,24 +1656,6 @@ extern void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex); extern void SoundAttachToThreat (edict_t *ent, const char *sample, float volume); extern void SoundSimulateUpdate (int playerIndex); -static inline bool IsNullString (const char *input) -{ - if (input == NULL) - return true; - - return *input == '\0'; -} - -static inline float GetWorldTime (void) -{ - return g_pGlobals->time; -} - -static inline int GetMaxClients (void) -{ - return g_pGlobals->maxClients; -} - // very global convars extern ConVar yb_jasonmode; extern ConVar yb_communication_type; @@ -1681,4 +1665,9 @@ extern ConVar yb_ignore_enemies; #include #include -#include \ No newline at end of file +#include + +inline int Bot::GetIndex (void) +{ + return IndexOfEntity (GetEntity ()); +} \ No newline at end of file diff --git a/include/engine/eiface.h b/include/engine/eiface.h index 403fee8..23c8831 100644 --- a/include/engine/eiface.h +++ b/include/engine/eiface.h @@ -230,7 +230,7 @@ typedef struct enginefuncs_s void (*pfnSetPhysicsKeyValue) (const edict_t *client, const char *key, const char *value); const char *(*pfnGetPhysicsInfoString) (const edict_t *client); unsigned short (*pfnPrecacheEvent) (int type, const char *psz); - void (*pfnPlaybackEvent) (int flags, const edict_t *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2); + void (*pfnPlaybackEvent) (int flags, const edict_t *pInvoker, unsigned short evIndexOfEntity, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2); unsigned char *(*pfnSetFatPVS) (float *org); unsigned char *(*pfnSetFatPAS) (float *org); int (*pfnCheckVisibility) (const edict_t *entity, unsigned char *pset); diff --git a/include/engine/util.h b/include/engine/util.h index d3a9a2b..e73f930 100644 --- a/include/engine/util.h +++ b/include/engine/util.h @@ -129,14 +129,7 @@ static inline entvars_t *VARS (EOFFSET eoffset) { return VARS (ENT (eoffset)); } -static inline int ENTINDEX (edict_t *ent) -{ - return (*g_engfuncs.pfnIndexOfEdict) (ent); -} -static inline edict_t *INDEXENT (int iEdictNum) -{ - return (*g_engfuncs.pfnPEntityOfEntIndex) (iEdictNum); -} + static inline void MESSAGE_BEGIN (int msg_dest, int msg_type, const float *pOrigin, entvars_t *ent) { (*g_engfuncs.pfnMessageBegin) (msg_dest, msg_type, pOrigin, ENT (ent)); diff --git a/include/globals.h b/include/globals.h index e9987d6..6bb3c81 100644 --- a/include/globals.h +++ b/include/globals.h @@ -83,4 +83,32 @@ extern gamefuncs_t g_functionTable; extern EntityAPI_t g_entityAPI; extern FuncPointers_t g_funcPointers; extern NewEntityAPI_t g_getNewEntityAPI; -extern BlendAPI_t g_serverBlendingAPI; \ No newline at end of file +extern BlendAPI_t g_serverBlendingAPI; + +static inline bool IsNullString (const char *input) +{ + if (input == NULL) + return true; + + return *input == '\0'; +} + +static inline float GetWorldTime (void) +{ + return g_pGlobals->time; +} + +static inline int GetMaxClients (void) +{ + return g_pGlobals->maxClients; +} + +static inline edict_t *EntityOfIndex (const int index) +{ + return static_cast (g_worldEdict + index); +}; + +inline int IndexOfEntity (const edict_t *ent) +{ + return static_cast (ent - g_worldEdict); +}; diff --git a/include/resource.h b/include/resource.h index 00f66ea..0f5a470 100644 --- a/include/resource.h +++ b/include/resource.h @@ -19,7 +19,7 @@ #define PRODUCT_DESCRIPTION PRODUCT_NAME " v" PRODUCT_VERSION " - The Counter-Strike 1.6 Bot" #define PRODUCT_COPYRIGHT "Copyright © 2014, by " PRODUCT_AUTHOR #define PRODUCT_LEGAL "Half-Life, Counter-Strike, Counter-Strike: Condition Zero, Steam, Valve is a trademark of Valve Corporation" -#define PRODUCT_ORIGINAL_NAME "yapb_.dll" +#define PRODUCT_ORIGINAL_NAME "yapb.dll" #define PRODUCT_INTERNAL_NAME "podbot" #define PRODUCT_VERSION_DWORD 2,6,0 // major version, minor version, WIP (or Update) version, BUILD number (generated with RES file) #define PRODUCT_SUPPORT_VERSION "1.4 - CZ" diff --git a/project/yapb.rc b/project/yapb.rc index 1b0ea2a..0ce1e90 100644 --- a/project/yapb.rc +++ b/project/yapb.rc @@ -26,7 +26,7 @@ #include <../include/resource.h> // generated by update tool -- do not edit -- -#define PRODUCT_BUILD_TOOL 3885 +#define PRODUCT_BUILD_TOOL 3892 VS_VERSION_INFO VERSIONINFO FILEVERSION PRODUCT_VERSION_DWORD, PRODUCT_BUILD_TOOL diff --git a/project/yapb.vcxproj b/project/yapb.vcxproj index 0057f6a..3670e8a 100644 --- a/project/yapb.vcxproj +++ b/project/yapb.vcxproj @@ -65,7 +65,7 @@ DynamicLibrary - Intel C++ Compiler XE 14.0 + v120_xp false diff --git a/source/basecode.cpp b/source/basecode.cpp index ce54467..2c35ed0 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -534,11 +534,6 @@ void Bot::FindItem (void) allowPickup = true; pickupType = PICKUP_DROPPED_C4; } - else if (strncmp ("weaponbox", STRING (ent->v.classname), 9) == 0 && strcmp (STRING (ent->v.model) + 9, "backpack.mdl") == 0 && !m_isUsingGrenade) - { - allowPickup = true; - pickupType = PICKUP_DROPPED_C4; - } else if ((strncmp ("weaponbox", STRING (ent->v.classname), 9) == 0 || strncmp ("armoury_entity", STRING (ent->v.classname), 14) == 0 || strncmp ("csdm", STRING (ent->v.classname), 4) == 0) && !m_isUsingGrenade) { allowPickup = true; @@ -734,7 +729,7 @@ void Bot::FindItem (void) m_itemIgnore = ent; allowPickup = false; - if (m_skill > 80 && g_randGen.Long (0, 100) < 90) + if (m_skill > 80 && g_randGen.Long (0, 100) < 95) { int index = FindDefendWaypoint (entityOrigin); @@ -868,7 +863,7 @@ void Bot::SwitchChatterIcon (bool show) for (int i = 0; i < 32; i++) { - edict_t *ent = INDEXENT (i); + edict_t *ent = EntityOfIndex (i); if (!IsValidPlayer (ent) || IsValidBot (ent) || GetTeam (ent) != m_team) continue; @@ -906,7 +901,7 @@ void Bot::InstantChatterMessage (int type) for (int i = 0; i < GetMaxClients (); i++) { - edict_t *ent = INDEXENT (i); + edict_t *ent = EntityOfIndex (i); if (!IsValidPlayer (ent) || IsValidBot (ent) || GetTeam (ent) != m_team) continue; @@ -1093,7 +1088,7 @@ void Bot::CheckMessageQueue (void) if (path->flags & FLAG_GOAL) { - if ((g_mapType & MAP_DE) && m_team == TEAM_TF && (pev->weapons & (1 << WEAPON_C4))) + if ((g_mapType & MAP_DE) && m_team == TEAM_TF && m_hasC4) InstantChatterMessage (Chatter_GoingToPlantBomb); else InstantChatterMessage (Chatter_Nothing); @@ -1994,7 +1989,7 @@ void Bot::SetConditions (void) g_taskFilters[TASK_ATTACK].desire = 0; // calculate desires to seek cover or hunt - if (IsValidPlayer (m_lastEnemy) && m_lastEnemyOrigin != nullvec && !((g_mapType & MAP_DE) && g_bombPlanted) && !(pev->weapons & (1 << WEAPON_C4)) && (m_loosedBombWptIndex == -1 && m_team == TEAM_TF)) + if (IsValidPlayer (m_lastEnemy) && m_lastEnemyOrigin != nullvec && !((g_mapType & MAP_DE) && g_bombPlanted) && !m_hasC4 && (m_loosedBombWptIndex == -1 && m_team == TEAM_TF)) { float distance = (m_lastEnemyOrigin - pev->origin).GetLength (); @@ -2299,7 +2294,7 @@ void Bot::CheckRadioCommands (void) float distance = (m_radioEntity->v.origin - pev->origin).GetLength (); // don't allow bot listen you if bot is busy - if ((GetTaskId () == TASK_DEFUSEBOMB || GetTaskId () == TASK_PLANTBOMB || HasHostage ()) && m_radioOrder != Radio_ReportTeam) + if ((GetTaskId () == TASK_DEFUSEBOMB || GetTaskId () == TASK_PLANTBOMB || HasHostage () || m_hasC4) && m_radioOrder != Radio_ReportTeam) { m_radioOrder = 0; return; @@ -2315,7 +2310,7 @@ void Bot::CheckRadioCommands (void) // check if line of sight to object is not blocked (i.e. visible) if ((EntityIsVisible (m_radioEntity->v.origin)) || (m_radioOrder == Radio_StickTogether)) { - if (FNullEnt (m_targetEntity) && FNullEnt (m_enemy) && g_randGen.Long (0, 100) < (m_personality == PERSONALITY_CAREFUL ? 80 : 50)) + if (FNullEnt (m_targetEntity) && FNullEnt (m_enemy) && g_randGen.Long (0, 100) < (m_personality == PERSONALITY_CAREFUL ? 80 : 20)) { int numFollowers = 0; @@ -2774,7 +2769,7 @@ void Bot::SelectLeaderEachTeam (int team) { if (team == TEAM_TF && !g_leaderChoosen[TEAM_TF]) { - if (pev->weapons & (1 << WEAPON_C4)) + if (m_hasC4) { // bot carrying the bomb is the leader m_isLeader = true; @@ -3008,6 +3003,9 @@ void Bot::Think (void) m_notKilled = IsAlive (GetEntity ()); m_team = GetTeam (GetEntity ()); + if (m_team == TEAM_TF) + m_hasC4 = !!(pev->weapons & (1 << WEAPON_C4)); + m_frameInterval = GetWorldTime () - m_lastThinkTime; m_lastThinkTime = GetWorldTime (); @@ -3028,10 +3026,10 @@ void Bot::Think (void) m_lastVoteKick = m_voteKickIndex; // if bot tk punishment is enabled slay the tk - if (yb_tkpunish.GetInt () != 2 || IsValidBot (INDEXENT (m_voteKickIndex))) + if (yb_tkpunish.GetInt () != 2 || IsValidBot (EntityOfIndex (m_voteKickIndex))) return; - entvars_t *killer = VARS (INDEXENT (m_lastVoteKick)); + entvars_t *killer = VARS (EntityOfIndex (m_lastVoteKick)); MESSAGE_BEGIN (MSG_PAS, SVC_TEMPENTITY, killer->origin); WRITE_BYTE (TE_TAREXPLOSION); @@ -3108,7 +3106,7 @@ void Bot::Think (void) else if (m_buyingFinished) botMovement = true; - int team = g_clients[ENTINDEX (GetEntity ()) - 1].realTeam;; + int team = g_clients[IndexOfEntity (GetEntity ()) - 1].realTeam;; // remove voice icon if (g_lastRadioTime[team] + g_randGen.Float (0.8, 2.1) < GetWorldTime ()) @@ -3257,7 +3255,7 @@ void Bot::RunTask (void) } // don't allow vip on as_ maps to camp + don't allow terrorist carrying c4 to camp - if (((g_mapType & MAP_AS) && *(INFOKEY_VALUE (GET_INFOKEYBUFFER (GetEntity ()), "model")) == 'v') || ((g_mapType & MAP_DE) && m_team == TEAM_TF && !g_bombPlanted && (pev->weapons & (1 << WEAPON_C4)))) + if (((g_mapType & MAP_AS) && *(INFOKEY_VALUE (GET_INFOKEYBUFFER (GetEntity ()), "model")) == 'v') || ((g_mapType & MAP_DE) && m_team == TEAM_TF && !g_bombPlanted && m_hasC4)) campingAllowed = false; // check if another bot is already camping here @@ -3329,10 +3327,10 @@ void Bot::RunTask (void) } } - if ((g_mapType & MAP_DE) && ((m_currentPath->flags & FLAG_GOAL) || m_inBombZone) && FNullEnt (m_enemy)) + if ((g_mapType & MAP_DE) && ((m_currentPath->flags & FLAG_GOAL) || m_inBombZone) && m_seeEnemyTime + 3.0 < GetWorldTime ()) { // is it a terrorist carrying the bomb? - if (pev->weapons & (1 << WEAPON_C4)) + if (m_hasC4) { if ((m_states & STATE_SEEING_ENEMY) && GetNearbyFriendsNearPosition (pev->origin, 768) == 0) { @@ -3347,7 +3345,7 @@ void Bot::RunTask (void) } else if (m_team == TEAM_CF) { - if (!g_bombPlanted && GetNearbyFriendsNearPosition (pev->origin, 120) <= 4 && g_randGen.Long (0, 100) < 65 && GetTaskId () == TASK_NORMAL && m_fearLevel > m_agressionLevel / 2) + if (!g_bombPlanted && GetNearbyFriendsNearPosition (pev->origin, 360) < 3 && g_randGen.Long (0, 100) < 85 && GetTaskId () == TASK_NORMAL && m_fearLevel > m_agressionLevel / 2) { int index = FindDefendWaypoint (m_currentPath->origin); @@ -3874,7 +3872,7 @@ void Bot::RunTask (void) destination = m_lastEnemyOrigin; GetCampDirection (&destination); - if (pev->weapons & (1 << WEAPON_C4)) // we're still got the C4? + if (m_hasC4) // we're still got the C4? { SelectWeaponByName ("weapon_c4"); @@ -4764,7 +4762,7 @@ void Bot::CheckSpawnTimeConditions (void) m_checkKnifeSwitch = false; - if (g_randGen.Long (0, 100) < yb_user_follow_percent.GetInt () && FNullEnt (m_targetEntity) && !m_isLeader && !(pev->weapons & (1 << WEAPON_C4))) + if (g_randGen.Long (0, 100) < yb_user_follow_percent.GetInt () && FNullEnt (m_targetEntity) && !m_isLeader && !m_hasC4) AttachToUser (); } @@ -5334,7 +5332,7 @@ void Bot::BotAI (void) { int specIndex = g_hostEntity->v.iuser2; - if (specIndex == ENTINDEX (GetEntity ())) + if (specIndex == IndexOfEntity (GetEntity ())) { static int index, goal, taskID; @@ -6204,7 +6202,7 @@ float Bot::GetBombTimeleft (void) float Bot::GetEstimatedReachTime (void) { - float estimatedTime = 4.0; // time to reach next waypoint + float estimatedTime = 2.5f; // time to reach next waypoint // 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) diff --git a/source/chatlib.cpp b/source/chatlib.cpp index cebad2a..ade6c8b 100644 --- a/source/chatlib.cpp +++ b/source/chatlib.cpp @@ -213,7 +213,7 @@ void Bot::PrepareChatMessage (char *text) // chat reply? else if (*pattern == 's') { - talkEntity = INDEXENT (m_sayTextBuffer.entityIndex); + talkEntity = EntityOfIndex (m_sayTextBuffer.entityIndex); if (!FNullEnt (talkEntity)) strcat (m_tempStrings, HumanizeName (const_cast (STRING (talkEntity->v.netname)))); diff --git a/source/combat.cpp b/source/combat.cpp index d8ad86b..ce057d2 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -160,7 +160,7 @@ bool Bot::LookupEnemy (void) } else { - if (m_seeEnemyTime + 3.0 < GetWorldTime () && (pev->weapons & (1 << WEAPON_C4) || HasHostage () || !FNullEnt (m_targetEntity))) + if (m_seeEnemyTime + 3.0 < GetWorldTime () && (m_hasC4 || HasHostage () || !FNullEnt (m_targetEntity))) RadioMessage (Radio_EnemySpotted); m_targetEntity = NULL; // stop following when we see an enemy... @@ -402,7 +402,7 @@ bool Bot::IsFriendInLineOfFire (float distance) // check if we hit something if (!FNullEnt (tr.pHit)) { - int playerIndex = ENTINDEX (tr.pHit) - 1; + int playerIndex = IndexOfEntity (tr.pHit) - 1; // check valid range if (playerIndex >= 0 && playerIndex < GetMaxClients () && g_clients[playerIndex].team == m_team && (g_clients[playerIndex].flags & CF_ALIVE)) @@ -532,7 +532,7 @@ void Bot::FireWeapon (void) goto WeaponSelectEnd; // use knife if near and good skill (l33t dude!) - if (m_skill > 80 && pev->health > 80 && pev->health >= enemy->v.health && !FNullEnt (enemy) && distance < 100.0f && !IsGroupOfEnemies (pev->origin)) + if (m_skill > 80 && pev->health > 80 && !FNullEnt (enemy) && pev->health >= enemy->v.health && distance < 100.0f && !IsGroupOfEnemies (pev->origin)) goto WeaponSelectEnd; // loop through all the weapons until terminator is found... @@ -918,7 +918,7 @@ void Bot::CombatFight (void) CheckGrenades(); CheckThrow(EyePosition(),m_throw); - if (m_states & (STATE_SEEING_ENEMY) && !(pev->weapons & (1 << WEAPON_C4))) + if (m_states & (STATE_SEEING_ENEMY) && !m_hasC4) StartTask(TASK_SEEKCOVER, TASKPRI_SEEKCOVER,-1, g_randGen.Long (10, 20), true); } // If using sniper do not jump around ! @@ -1181,6 +1181,11 @@ bool Bot::UsesPistol (void) return false; } +bool Bot::UsesCampGun (void) +{ + return UsesSubmachineGun () || UsesRifle () || UsesSniper (); +} + bool Bot::UsesSubmachineGun (void) { return m_currentWeapon == WEAPON_MP5 || m_currentWeapon == WEAPON_TMP || m_currentWeapon == WEAPON_P90 || m_currentWeapon == WEAPON_MAC10 || m_currentWeapon == WEAPON_UMP45; diff --git a/source/interface.cpp b/source/interface.cpp index cae90a0..9c208ca 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -122,7 +122,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c if (IsNullString (arg1)) return 1; - edict_t *ent = INDEXENT (atoi (arg1) - 1); + edict_t *ent = EntityOfIndex (atoi (arg1) - 1); if (IsValidBot (ent)) { @@ -1066,6 +1066,8 @@ int Spawn (edict_t *ent) if (strcmp (STRING (ent->v.classname), "worldspawn") == 0) { + g_worldEdict = ent; // save the world entity for future use + g_convarWrapper->PushRegisteredConVarsToEngine (true); PRECACHE_SOUND (ENGINE_STR ("weapons/xbow_hit1.wav")); // waypoint add @@ -1082,7 +1084,6 @@ int Spawn (edict_t *ent) RoundInit (); g_mapType = NULL; // reset map type as worldspawn is the first entity spawned - g_worldEdict = ent; // save the world entity for future use } else if (strcmp (STRING (ent->v.classname), "player_weaponstrip") == 0 && (STRING (ent->v.target))[0] == '0') ent->v.target = ent->v.targetname = ALLOC_STRING ("fake"); @@ -1214,15 +1215,22 @@ void ClientDisconnect (edict_t *ent) if (yb_autovacate.GetBool () && IsValidPlayer (ent) && !IsValidBot (ent) && yb_quota.GetInt () < GetMaxClients () - 1) yb_quota.SetInt (yb_quota.GetInt () + 1); - int i = ENTINDEX (ent) - 1; + int i = IndexOfEntity (ent) - 1; InternalAssert (i >= 0 && i < 32); + Bot *bot = g_botManager->GetBot (i); + // check if its a bot - if (g_botManager->GetBot (i) != NULL) + if (bot != NULL) { - if (g_botManager->GetBot (i)->pev == &ent->v) + if (bot->pev == &ent->v) + { + bot->SwitchChatterIcon (false); + bot->ReleaseUsedName (); + g_botManager->Free (i); + } } if (g_isMetamod) @@ -1249,7 +1257,7 @@ void ClientUserInfoChanged (edict_t *ent, char *infobuffer) (*g_functionTable.pfnClientUserInfoChanged) (ent, infobuffer); } - int clientIndex = ENTINDEX (ent) - 1; + int clientIndex = IndexOfEntity (ent) - 1; if (strcmp (password, INFOKEY_VALUE (infobuffer, const_cast (passwordField))) == 0) g_clients[clientIndex].flags |= CF_ADMIN; @@ -1283,7 +1291,7 @@ void ClientCommand (edict_t *ent) static int fillServerTeam = 5; static bool fillCommand = false; - if (!g_isFakeCommand && (ent == g_hostEntity || (g_clients[ENTINDEX (ent) - 1].flags & CF_ADMIN))) + if (!g_isFakeCommand && (ent == g_hostEntity || (g_clients[IndexOfEntity (ent) - 1].flags & CF_ADMIN))) { if (stricmp (command, "yapb") == 0 || stricmp (command, "yb") == 0) { @@ -1308,9 +1316,9 @@ void ClientCommand (edict_t *ent) return; } - else if (stricmp (command, "menuselect") == 0 && !IsNullString (arg1) && g_clients[ENTINDEX (ent) - 1].menu != NULL) + else if (stricmp (command, "menuselect") == 0 && !IsNullString (arg1) && g_clients[IndexOfEntity (ent) - 1].menu != NULL) { - Client *client = &g_clients[ENTINDEX (ent) - 1]; + Client *client = &g_clients[IndexOfEntity (ent) - 1]; int selection = atoi (arg1); if (client->menu == &g_menus[12]) @@ -1673,7 +1681,7 @@ void ClientCommand (edict_t *ent) case 2: if (FindNearestPlayer (reinterpret_cast (&bot), client->ent, 4096.0, true, true, true)) { - if (!(bot->pev->weapons & (1 << WEAPON_C4)) && !bot->HasHostage () && (bot->GetTaskId () != TASK_PLANTBOMB) && (bot->GetTaskId () != TASK_DEFUSEBOMB)) + if (!bot->m_hasC4 && !bot->HasHostage () && (bot->GetTaskId () != TASK_PLANTBOMB) && (bot->GetTaskId () != TASK_DEFUSEBOMB)) { if (selection == 1) { @@ -2098,7 +2106,7 @@ void ClientCommand (edict_t *ent) if (bot != NULL) { - bot->m_sayTextBuffer.entityIndex = ENTINDEX (ent); + bot->m_sayTextBuffer.entityIndex = IndexOfEntity (ent); if (IsNullString (CMD_ARGS ())) continue; @@ -2108,7 +2116,7 @@ void ClientCommand (edict_t *ent) } } } - int clientIndex = ENTINDEX (ent) - 1; + int clientIndex = IndexOfEntity (ent) - 1; // check if this player alive, and issue something if ((g_clients[clientIndex].flags & CF_ALIVE) && g_radioSelect[clientIndex] != 0 && strncmp (command, "menuselect", 10) == 0) @@ -2217,7 +2225,7 @@ void StartFrame (void) // record some stats of all players on the server for (int i = 0; i < GetMaxClients (); i++) { - edict_t *player = INDEXENT (i + 1); + edict_t *player = EntityOfIndex (i + 1); if (!FNullEnt (player) && (player->v.flags & FL_CLIENT)) { @@ -2264,7 +2272,7 @@ void StartFrame (void) { for (int i = 0; i < GetMaxClients (); i++) { - edict_t *player = INDEXENT (i + 1); + edict_t *player = EntityOfIndex (i + 1); // code below is executed only on dedicated server if (IsDedicatedServer () && !FNullEnt (player) && (player->v.flags & FL_CLIENT) && !(player->v.flags & FL_FAKECLIENT)) diff --git a/source/manager.cpp b/source/manager.cpp index 0bdc632..91e7d36 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -156,7 +156,7 @@ int BotManager::CreateBot (String name, int skill, int personality, int team, in return 2; } - int index = ENTINDEX (bot) - 1; + int index = IndexOfEntity (bot) - 1; InternalAssert (index >= 0 && index <= 32); // check index InternalAssert (m_bots[index] == NULL); // check bot slot @@ -177,7 +177,7 @@ int BotManager::GetIndex (edict_t *ent) if (FNullEnt (ent)) return -1; - int index = ENTINDEX (ent) - 1; + int index = IndexOfEntity (ent) - 1; if (index < 0 || index >= 32) return -1; @@ -637,7 +637,7 @@ void BotManager::ListBots (void) for (int i = 0; i < GetMaxClients (); i++) { - edict_t *player = INDEXENT (i); + edict_t *player = EntityOfIndex (i); // is this player slot valid if (IsValidBot (player)) @@ -745,9 +745,6 @@ void BotManager::Free (int index) { // this function frees one bot selected by index (used on bot disconnect) - m_bots[index]->SwitchChatterIcon (false); - m_bots[index]->ReleaseUsedName (); - delete m_bots[index]; m_bots[index] = NULL; } @@ -758,7 +755,7 @@ Bot::Bot (edict_t *bot, int skill, int personality, int team, int member) // when bot setup completed, (this is a bot class constructor) char rejectReason[128]; - int clientIndex = ENTINDEX (bot); + int clientIndex = IndexOfEntity (bot); memset (this, 0, sizeof (Bot)); @@ -792,7 +789,7 @@ Bot::Bot (edict_t *bot, int skill, int personality, int team, int member) SET_CLIENT_KEYVALUE (clientIndex, buffer, "*bot", "1"); rejectReason[0] = 0; // reset the reject reason template string - MDLL_ClientConnect (bot, "BOT", FormatBuffer ("127.0.0.%d", ENTINDEX (bot) + 100), rejectReason); + MDLL_ClientConnect (bot, "BOT", FormatBuffer ("127.0.0.%d", IndexOfEntity (bot) + 100), rejectReason); if (!IsNullString (rejectReason)) { @@ -950,7 +947,6 @@ void Bot::NewRound (void) g_canSayBombPlanted = true; int i = 0; - // delete all allocated path nodes DeleteSearchNodes (); @@ -1105,6 +1101,7 @@ void Bot::NewRound (void) m_buyPending = false; m_inBombZone = false; + m_hasC4 = false; m_shieldCheckTime = 0.0; m_zoomCheckTime = 0.0; @@ -1251,7 +1248,7 @@ void BotManager::CalculatePingOffsets (void) for (int i = 0; i < GetMaxClients (); i++) { - edict_t *ent = INDEXENT (i + 1); + edict_t *ent = EntityOfIndex (i + 1); if (!IsValidPlayer (ent)) continue; diff --git a/source/navigate.cpp b/source/navigate.cpp index 365505d..da725a9 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -79,7 +79,7 @@ int Bot::FindGoal (void) } // terrorist carrying the C4? - if (pev->weapons & (1 << WEAPON_C4) || m_isVIP) + if (m_hasC4 || m_isVIP) { tactic = 3; goto TacticChoosen; @@ -122,35 +122,21 @@ int Bot::FindGoal (void) defensive += 40.0f; offensive -= 25.0f; } - else if ((g_mapType & MAP_DE) && m_team == TEAM_TF) + 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 ()); - - float leastPathDistance = 0.0; - int goalIndex = -1; - - IterateArray (g_waypoint->m_goalPoints, i) - { - float realPathDistance = g_waypoint->GetPathDistance (m_currentWaypointIndex, g_waypoint->m_goalPoints[i]) + g_randGen.Float (0.0, 128.0); - - if (leastPathDistance > realPathDistance) - { - goalIndex = g_waypoint->m_goalPoints[i]; - leastPathDistance = realPathDistance; - } - } - - if (goalIndex != -1 && !g_bombPlanted && (pev->weapons & (1 << WEAPON_C4))) - return m_chosenGoalIndex = goalIndex; } goalDesire = g_randGen.Long (0, 100) + offensive; forwardDesire = g_randGen.Long (0, 100) + offensive; - campDesire = g_randGen.Long (0, 85) + defensive; + campDesire = g_randGen.Long (0, 100) + defensive; backoffDesire = g_randGen.Long (0, 100) + defensive; + if (!UsesCampGun ()) + campDesire = 0; + tacticChoice = backoffDesire; tactic = 0; @@ -1967,7 +1953,7 @@ bool Bot::HeadTowardWaypoint (void) m_minSpeed = pev->maxspeed; // only if we in normal task and bomb is not planted - if (taskID == TASK_NORMAL && !g_bombPlanted && m_personality != PERSONALITY_RUSHER && !(pev->weapons & (1 << WEAPON_C4)) && !m_isVIP && (m_loosedBombWptIndex == -1) && !HasHostage ()) + if (taskID == TASK_NORMAL && !g_bombPlanted && !m_inBombZone && !m_inBuyZone && m_personality != PERSONALITY_RUSHER && !m_hasC4 && !m_isVIP && (m_loosedBombWptIndex == -1) && !HasHostage () && m_fearLevel * 2 > m_agressionLevel) { m_campButtons = 0; @@ -1980,7 +1966,7 @@ bool Bot::HeadTowardWaypoint (void) kills = (g_experienceData + (waypoint * g_numWaypoints) + waypoint)->team1Damage / g_highestDamageCT; // if damage done higher than one - if (kills > 0.15f && g_timeRoundMid > GetWorldTime ()) + if (kills > 0.15f && g_timeRoundMid + 30.0f > GetWorldTime ()) { switch (m_personality) { @@ -2003,7 +1989,10 @@ bool Bot::HeadTowardWaypoint (void) pev->button |= IN_DUCK; } } - else if (g_botsCanPause && !IsOnLadder () && !IsInWater () && !m_currentTravelFlags && IsOnFloor ()) + else + + + if (g_botsCanPause && !IsOnLadder () && !IsInWater () && !m_currentTravelFlags && IsOnFloor ()) { if (static_cast (kills) == m_baseAgressionLevel) m_campButtons |= IN_DUCK; diff --git a/source/netmsg.cpp b/source/netmsg.cpp index e6a4ed1..452f317 100644 --- a/source/netmsg.cpp +++ b/source/netmsg.cpp @@ -243,6 +243,7 @@ void NetworkMsg::Execute (void *p) m_bot->m_inVIPZone = (enabled != 0); else if (strcmp (PTR_TO_STR (p), "c4") == 0) m_bot->m_inBombZone = (enabled == 2); + break; } break; @@ -263,8 +264,8 @@ void NetworkMsg::Execute (void *p) if (killerIndex != 0 && killerIndex != victimIndex) { - edict_t *killer = INDEXENT (killerIndex); - edict_t *victim = INDEXENT (victimIndex); + edict_t *killer = EntityOfIndex (killerIndex); + edict_t *victim = EntityOfIndex (victimIndex); if (FNullEnt (killer) || FNullEnt (victim)) break; diff --git a/source/support.cpp b/source/support.cpp index 734b832..eae4e66 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -155,7 +155,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu) if (!IsValidPlayer (ent)) return; - int clientIndex = ENTINDEX (ent) - 1; + int clientIndex = IndexOfEntity (ent) - 1; if (menu != NULL) { @@ -230,7 +230,7 @@ void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex) if (!FNullEnt (trace->pHit)) { if (trace->pHit->v.solid == SOLID_BSP || trace->pHit->v.movetype == MOVETYPE_PUSHSTEP) - entityIndex = ENTINDEX (trace->pHit); + entityIndex = IndexOfEntity (trace->pHit); else return; } @@ -260,11 +260,11 @@ void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex) { MESSAGE_BEGIN (MSG_BROADCAST, SVC_TEMPENTITY); WRITE_BYTE (TE_PLAYERDECAL); - WRITE_BYTE (ENTINDEX (ENT (pev))); + WRITE_BYTE (IndexOfEntity (ENT (pev))); WRITE_COORD (trace->vecEndPos.x); WRITE_COORD (trace->vecEndPos.y); WRITE_COORD (trace->vecEndPos.z); - WRITE_SHORT (static_cast (ENTINDEX (trace->pHit))); + WRITE_SHORT (static_cast (IndexOfEntity (trace->pHit))); WRITE_BYTE (decalIndex); MESSAGE_END (); } @@ -794,7 +794,7 @@ bool IsWeaponShootingThroughWall (int id) int GetTeam (edict_t *ent) { - return g_clients[ENTINDEX (ent) - 1].team; + return g_clients[IndexOfEntity (ent) - 1].team; } bool IsValidPlayer (edict_t *ent) @@ -1440,7 +1440,7 @@ void SoundAttachToThreat (edict_t *ent, const char *sample, float volume) return; // reliability check Vector origin = GetEntityOrigin (ent); - int index = ENTINDEX (ent) - 1; + int index = IndexOfEntity (ent) - 1; if (index < 0 || index >= GetMaxClients ()) { diff --git a/source/waypoint.cpp b/source/waypoint.cpp index e7e1779..f12f0ee 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -1089,7 +1089,14 @@ bool Waypoint::Load (void) if (m_paths[i] == NULL) TerminateOnMalloc (); - fp.Read (m_paths[i], sizeof (Path)); + if (fp.Read (m_paths[i], sizeof (Path)) == 0) + { + sprintf (m_infoBuffer, "%s.pwf - truncated waypoint file (count: %d, need: %d)", GetMapName (), i, g_numWaypoints); + AddLogEntry (true, LL_ERROR, m_infoBuffer); + + fp.Close (); + return false; + } } m_waypointPaths = true; } @@ -2522,11 +2529,11 @@ WaypointDownloadError WaypointDownloader::DoDownload (void) #endif timeval timeout; - timeout.tv_sec = 2; + timeout.tv_sec = 5; timeout.tv_usec = 0; - setsockopt (socketHandle, SOL_SOCKET, SO_RCVTIMEO, (char *) &timeout, sizeof(timeout)); - setsockopt (socketHandle, SOL_SOCKET, SO_SNDTIMEO, (char *) &timeout, sizeof(timeout)); + setsockopt (socketHandle, SOL_SOCKET, SO_RCVTIMEO, (char *) &timeout, sizeof (timeout)); + setsockopt (socketHandle, SOL_SOCKET, SO_SNDTIMEO, (char *) &timeout, sizeof (timeout)); memset (&dest, 0, sizeof (dest)); dest.sin_family = AF_INET; @@ -2540,9 +2547,9 @@ WaypointDownloadError WaypointDownloader::DoDownload (void) } String request; - request.AssignFormat ("GET /wpdb/%s.pwf HTTP/1.0\r\nUser-Agent: YaPB/%s\r\nHost: %s\r\n\r\n", GetMapName (), PRODUCT_VERSION, yb_waypoint_autodl_host.GetString ()); + request.AssignFormat ("GET /wpdb/%s.pwf HTTP/1.0\r\nAccept: */*\r\nUser-Agent: YaPB/%s\r\nHost: %s\r\n\r\n", GetMapName (), PRODUCT_VERSION, yb_waypoint_autodl_host.GetString ()); - if (send (socketHandle, request.GetBuffer (), request.GetLength (), 0) < 1) + if (send (socketHandle, request.GetBuffer (), request.GetLength () + 1, 0) < 1) { FreeSocket (socketHandle); return WDE_SOCKET_ERROR; @@ -2555,16 +2562,16 @@ WaypointDownloadError WaypointDownloader::DoDownload (void) FreeSocket (socketHandle); return WDE_SOCKET_ERROR; } - char buffer[4096]; + char buffer[1024]; bool finished = false; int recvPosition = 0; int symbolsInLine = 0; // scan for the end of the header - while (!finished && recvPosition < static_cast (sizeof (buffer))) + while (!finished && recvPosition < sizeof (buffer)) { - if (recv (socketHandle, &buffer[recvPosition], 1, 0) < 0) + if (recv (socketHandle, &buffer[recvPosition], 1, 0) == 0) finished = true; switch (buffer[recvPosition]) @@ -2583,9 +2590,9 @@ WaypointDownloadError WaypointDownloader::DoDownload (void) symbolsInLine++; break; } - recvPosition++; } + if (strstr (buffer, "HTTP/1.0 404") != NULL) { FreeSocket (socketHandle); @@ -2596,7 +2603,7 @@ WaypointDownloadError WaypointDownloader::DoDownload (void) int size = 0; while ((size = recv (socketHandle, buffer, sizeof (buffer) -1, 0)) > 0) - fp.Write (buffer, 1, size); + fp.Write (buffer, size); fp.Close ();