diff --git a/README.md b/README.md index 82b032e7..0ca04558 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ At the moment, the work of reverse engineering continues ## How can use it? -At the moment there is a workable CS 1.6 Regamedll_CS is fully compatible with official mod CS 1.6 by Valve. All you have to do is to download binaries and replace original mo.dll/cs.so Compiled binaries are available here: http://nexus.rehlds.org/nexus/content/repositories/regamedll-snapshots/regamedll/regamedll/0.2-SNAPSHOT/ @@ -28,7 +27,7 @@ Archive's bin directory contains 2 subdirectories, 'bugfixed' and 'pure' ## Current status ## Build instructions diff --git a/dep/bzip2/msvc/bzip2.vcxproj b/dep/bzip2/msvc/bzip2.vcxproj index 6dbe07d9..fe2829f3 100644 --- a/dep/bzip2/msvc/bzip2.vcxproj +++ b/dep/bzip2/msvc/bzip2.vcxproj @@ -13,6 +13,10 @@ Debug Win32 + + Release MP + Win32 + Release Win32 @@ -36,6 +40,12 @@ v120 Unicode + + StaticLibrary + true + v120 + Unicode + StaticLibrary true @@ -58,6 +68,9 @@ + + + @@ -96,6 +109,21 @@ true + + + Use + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(ProjectDir)..\include\ + MultiThreadedDebug + bzlib_private.h + + + Windows + true + + Use @@ -143,6 +171,7 @@ Create Create + Create Create Create diff --git a/dep/cppunitlite/msvc/cppunitlite.vcxproj b/dep/cppunitlite/msvc/cppunitlite.vcxproj index fb5ad527..2de76ed6 100644 --- a/dep/cppunitlite/msvc/cppunitlite.vcxproj +++ b/dep/cppunitlite/msvc/cppunitlite.vcxproj @@ -13,6 +13,10 @@ Debug Win32 + + Release MP + Win32 + Release Win32 @@ -52,6 +56,12 @@ v120 MultiByte + + StaticLibrary + true + v120 + MultiByte + StaticLibrary true @@ -80,6 +90,9 @@ + + + @@ -120,6 +133,22 @@ true + + + + + Level3 + Disabled + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_LIB;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions) + MultiThreadedDebug + $(ProjectDir)..\include\ + CompileAsCpp + + + Windows + true + + diff --git a/msvc/ReGameDLL.sln b/msvc/ReGameDLL.sln index 579bd225..ab7dff5a 100644 --- a/msvc/ReGameDLL.sln +++ b/msvc/ReGameDLL.sln @@ -27,6 +27,7 @@ Global Debug MP|Win32 = Debug MP|Win32 Debug Play|Win32 = Debug Play|Win32 Debug|Win32 = Debug|Win32 + Release MP|Win32 = Release MP|Win32 Release Play|Win32 = Release Play|Win32 Release|Win32 = Release|Win32 Tests|Win32 = Tests|Win32 @@ -40,6 +41,8 @@ Global {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Debug Play|Win32.Build.0 = Debug Play|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Debug|Win32.ActiveCfg = Debug|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Debug|Win32.Build.0 = Debug|Win32 + {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release MP|Win32.ActiveCfg = Release MP|Win32 + {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release MP|Win32.Build.0 = Release MP|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release Play|Win32.ActiveCfg = Release Play|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release Play|Win32.Build.0 = Release Play|Win32 {70A2B904-B7DB-4C48-8DE0-AF567360D572}.Release|Win32.ActiveCfg = Release|Win32 @@ -54,6 +57,8 @@ Global {CEB94F7C-E459-4673-AABB-36E2074396C0}.Debug Play|Win32.Build.0 = Debug|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Debug|Win32.ActiveCfg = Debug|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Debug|Win32.Build.0 = Debug|Win32 + {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release MP|Win32.ActiveCfg = Release MP|Win32 + {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release MP|Win32.Build.0 = Release MP|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release Play|Win32.ActiveCfg = Release|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release Play|Win32.Build.0 = Release|Win32 {CEB94F7C-E459-4673-AABB-36E2074396C0}.Release|Win32.ActiveCfg = Release|Win32 @@ -68,6 +73,8 @@ Global {792DF067-9904-4579-99B9-46C17277ADE3}.Debug Play|Win32.Build.0 = Debug|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Debug|Win32.ActiveCfg = Debug|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Debug|Win32.Build.0 = Debug|Win32 + {792DF067-9904-4579-99B9-46C17277ADE3}.Release MP|Win32.ActiveCfg = Release MP|Win32 + {792DF067-9904-4579-99B9-46C17277ADE3}.Release MP|Win32.Build.0 = Release MP|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Release Play|Win32.ActiveCfg = Release|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Release Play|Win32.Build.0 = Release|Win32 {792DF067-9904-4579-99B9-46C17277ADE3}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/regamedll/build.gradle b/regamedll/build.gradle index 24808366..b2369016 100644 --- a/regamedll/build.gradle +++ b/regamedll/build.gradle @@ -185,7 +185,7 @@ void setupToolchain(NativeBinarySpec b) if (!unitTestExecutable) { - cfg.singleDefines 'CSTRIKE' + //cfg.singleDefines 'CSTRIKE' if (!mpLib) { diff --git a/regamedll/dlls/animating.cpp b/regamedll/dlls/animating.cpp index 23604deb..0c6878f0 100644 --- a/regamedll/dlls/animating.cpp +++ b/regamedll/dlls/animating.cpp @@ -239,7 +239,7 @@ void CBaseAnimating::SetSequenceBox(void) Vector rmax(-9999, -9999, -9999); Vector base, transformed; - for (int i = 0; i <= 1; i++) + for (int i = 0; i <= 1; ++i) { base.x = bounds[i].x; for (int j = 0; j <= 1; j++) diff --git a/regamedll/dlls/animation.cpp b/regamedll/dlls/animation.cpp index f2a69404..432af5fc 100644 --- a/regamedll/dlls/animation.cpp +++ b/regamedll/dlls/animation.cpp @@ -72,7 +72,7 @@ int LookupActivity(void *pmodel, entvars_t *pev, int activity) pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex); - for (i = 0; i < pstudiohdr->numseq; i++) + for (i = 0; i < pstudiohdr->numseq; ++i) { if (pseqdesc[i].activity == activity) { @@ -87,7 +87,7 @@ int LookupActivity(void *pmodel, entvars_t *pev, int activity) { int which = RANDOM_LONG(0, weightTotal - 1); - for (i = 0; i < pstudiohdr->numseq; i++) + for (i = 0; i < pstudiohdr->numseq; ++i) { if (pseqdesc[i].activity == activity) { @@ -104,7 +104,7 @@ int LookupActivity(void *pmodel, entvars_t *pev, int activity) { select = RANDOM_LONG(0, activitySequenceCount - 1); - for (i = 0; i < pstudiohdr->numseq; i++) + for (i = 0; i < pstudiohdr->numseq; ++i) { if (pseqdesc[i].activity == activity) { @@ -136,7 +136,7 @@ int LookupActivityHeaviest(void *pmodel, entvars_t *pev, int activity) int weight = 0; int seq = ACT_INVALID; - for (int i = 0; i < pstudiohdr->numseq; i++) + for (int i = 0; i < pstudiohdr->numseq; ++i) { if (pseqdesc[i].activity == activity) { @@ -181,7 +181,7 @@ int LookupSequence(void *pmodel, const char *label) // Look up by sequence name. mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex); - for (int i = 0; i < pstudiohdr->numseq; i++) + for (int i = 0; i < pstudiohdr->numseq; ++i) { if (!Q_stricmp(pseqdesc[i].label, label)) return i; @@ -218,7 +218,7 @@ NOXREF void SequencePrecache(void *pmodel, const char *pSequenceName) mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + index; mstudioevent_t *pevent = (mstudioevent_t *)((byte *)pstudiohdr + pseqdesc->eventindex); - for (int i = 0; i < pseqdesc->numevents; i++) + for (int i = 0; i < pseqdesc->numevents; ++i) { // Don't send client-side events to the server AI if (pevent[i].event >= EVENT_CLIENT) @@ -486,7 +486,7 @@ int FindTransition(void *pmodel, int iEndingAnim, int iGoalAnim, int *piDir) } // look for someone going - for (int i = 0; i < pstudiohdr->numseq; i++) + for (int i = 0; i < pstudiohdr->numseq; ++i) { if (pseqdesc[i].entrynode == iEndNode && pseqdesc[i].exitnode == iInternNode) { @@ -645,7 +645,7 @@ void QuaternionSlerp(vec_t *p, vec_t *q, float t, vec_t *qt) float_precision a = 0; float_precision b = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < 4; ++i) { a += (p[i] - q[i]) * (p[i] - q[i]); b += (p[i] + q[i]) * (p[i] + q[i]); @@ -653,7 +653,7 @@ void QuaternionSlerp(vec_t *p, vec_t *q, float t, vec_t *qt) if (a > b) { - for (i = 0; i < 4; i++) + for (i = 0; i < 4; ++i) q[i] = -q[i]; } @@ -677,7 +677,7 @@ void QuaternionSlerp(vec_t *p, vec_t *q, float t, vec_t *qt) sclp = 1.0 - t; } - for (i = 0; i < 4; i++) + for (i = 0; i < 4; ++i) qt[i] = sclp * p[i] + sclq * q[i]; } else @@ -690,7 +690,7 @@ void QuaternionSlerp(vec_t *p, vec_t *q, float t, vec_t *qt) sclp = sin((1.0 - t) * 0.5 * M_PI); sclq = sin(t * 0.5 * M_PI); - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) qt[i] = sclp * p[i] + sclq * qt[i]; } } @@ -968,7 +968,7 @@ void StudioSlerpBones(vec4_t *q1, float pos1[][3], vec4_t *q2, float pos2[][3], s1 = 1.0 - s; - for (i = 0; i < g_pstudiohdr->numbones; i++) + for (i = 0; i < g_pstudiohdr->numbones; ++i) { QuaternionSlerp(q1[i], q2[i], s, q3); @@ -1060,7 +1060,7 @@ void SV_StudioSetupBones(model_t *pModel, float frame, int sequence, const vec_t { chainlength = g_pstudiohdr->numbones; - for (i = 0; i < chainlength; i++) + for (i = 0; i < chainlength; ++i) chain[(chainlength - i) - 1] = i; } else @@ -1203,7 +1203,7 @@ void SV_StudioSetupBones(model_t *pModel, float frame, int sequence, const vec_t panim = StudioGetAnim(pModel, pseqdesc); StudioCalcRotations(pbones, chain, chainlength, adj, pos2, q2, pseqdesc, panim, 0, 0); - for (i = 0; i < g_pstudiohdr->numbones; i++) + for (i = 0; i < g_pstudiohdr->numbones; ++i) { if (!Q_strcmp(pbones[i].name, "Bip01 Spine")) { diff --git a/regamedll/dlls/bot/cs_bot.cpp b/regamedll/dlls/bot/cs_bot.cpp index afc12061..1015f97f 100644 --- a/regamedll/dlls/bot/cs_bot.cpp +++ b/regamedll/dlls/bot/cs_bot.cpp @@ -675,7 +675,7 @@ CBasePlayer *CCSBot::GetImportantEnemy(bool checkVisibility) const CBasePlayer *nearEnemy = NULL; float nearDist = 999999999.9f; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBaseEntity *entity = UTIL_PlayerByIndex(i); diff --git a/regamedll/dlls/bot/cs_bot.h b/regamedll/dlls/bot/cs_bot.h index 7f7a2c95..07a4dd92 100644 --- a/regamedll/dlls/bot/cs_bot.h +++ b/regamedll/dlls/bot/cs_bot.h @@ -39,6 +39,9 @@ #define CSBOT_VERSION_MAJOR 1 #define CSBOT_VERSION_MINOR 50 +#define PRIMARY_WEAPON_BUY_COUNT 13 +#define SECONDARY_WEAPON_BUY_COUNT 3 + #define FLAG_PROGRESS_DRAW 0x0 // draw status bar progress #define FLAG_PROGRESS_START 0x1 // init status bar progress #define FLAG_PROGRESS_HIDE 0x2 // hide status bar progress @@ -55,11 +58,23 @@ #define _navAreaCount (*pnavAreaCount) #define _currentIndex (*pcurrentIndex) +#define primaryWeaponBuyInfoCT (*pprimaryWeaponBuyInfoCT) +#define secondaryWeaponBuyInfoCT (*psecondaryWeaponBuyInfoCT) + +#define primaryWeaponBuyInfoT (*pprimaryWeaponBuyInfoT) +#define secondaryWeaponBuyInfoT (*psecondaryWeaponBuyInfoT) + #endif // HOOK_GAMEDLL extern int _navAreaCount; extern int _currentIndex; +extern struct BuyInfo primaryWeaponBuyInfoCT[ PRIMARY_WEAPON_BUY_COUNT ]; +extern struct BuyInfo secondaryWeaponBuyInfoCT[ SECONDARY_WEAPON_BUY_COUNT ]; + +extern struct BuyInfo primaryWeaponBuyInfoT[ PRIMARY_WEAPON_BUY_COUNT ]; +extern struct BuyInfo secondaryWeaponBuyInfoT[ SECONDARY_WEAPON_BUY_COUNT ]; + class CCSBot; class BotChatterInterface; @@ -78,8 +93,8 @@ public: class IdleState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); virtual const char *GetName(void) const { return "Idle"; } #ifdef HOOK_GAMEDLL @@ -95,9 +110,9 @@ public: class HuntState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); - NOBODY virtual void OnExit(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); + virtual void OnExit(CCSBot *me); virtual const char *GetName(void) const { return "Hunt"; } #ifdef HOOK_GAMEDLL @@ -118,9 +133,9 @@ private: class AttackState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); - NOBODY virtual void OnExit(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); + virtual void OnExit(CCSBot *me); virtual const char *GetName(void) const { return "Attack"; } #ifdef HOOK_GAMEDLL @@ -166,9 +181,9 @@ protected: class InvestigateNoiseState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); - NOBODY virtual void OnExit(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); + virtual void OnExit(CCSBot *me); virtual const char *GetName(void) const { return "InvestigateNoise"; } #ifdef HOOK_GAMEDLL @@ -180,7 +195,7 @@ public: #endif // HOOK_GAMEDLL private: - NOBODY void AttendCurrentNoise(CCSBot *me); + void AttendCurrentNoise(CCSBot *me); Vector m_checkNoisePosition; };/* size: 16, cachelines: 1, members: 2 */ @@ -189,9 +204,9 @@ private: class BuyState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); - NOBODY virtual void OnExit(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); + virtual void OnExit(CCSBot *me); virtual const char *GetName(void) const { return "Buy"; } #ifdef HOOK_GAMEDLL @@ -219,9 +234,9 @@ private: class MoveToState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); - NOBODY virtual void OnExit(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); + virtual void OnExit(CCSBot *me); virtual const char *GetName(void) const { return "MoveTo"; } #ifdef HOOK_GAMEDLL @@ -283,9 +298,9 @@ public: class DefuseBombState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); - NOBODY virtual void OnExit(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); + virtual void OnExit(CCSBot *me); virtual const char *GetName(void) const { return "DefuseBomb"; } #ifdef HOOK_GAMEDLL @@ -302,9 +317,9 @@ public: class HideState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); - NOBODY virtual void OnExit(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); + virtual void OnExit(CCSBot *me); virtual const char *GetName(void) const { return "Hide"; } #ifdef HOOK_GAMEDLL @@ -348,9 +363,9 @@ private: class EscapeFromBombState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); - NOBODY virtual void OnExit(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); + virtual void OnExit(CCSBot *me); virtual const char *GetName(void) const { return "EscapeFromBomb"; } #ifdef HOOK_GAMEDLL @@ -367,9 +382,9 @@ public: class FollowState: public BotState { public: - NOBODY virtual void OnEnter(CCSBot *me); - NOBODY virtual void OnUpdate(CCSBot *me); - NOBODY virtual void OnExit(CCSBot *me); + virtual void OnEnter(CCSBot *me); + virtual void OnUpdate(CCSBot *me); + virtual void OnExit(CCSBot *me); virtual const char *GetName(void) const { return "Follow"; } #ifdef HOOK_GAMEDLL @@ -383,7 +398,7 @@ public: void SetLeader(CBaseEntity *leader) { m_leader = leader; } private: - NOBODY void ComputeLeaderMotionState(float leaderSpeed); + void ComputeLeaderMotionState(float leaderSpeed); EHANDLE m_leader; Vector m_lastLeaderPos; @@ -456,12 +471,12 @@ public: virtual void SpawnBot(void); // (EXTEND) spawn the bot into the game virtual void Upkeep(void); // lightweight maintenance, invoked frequently - NOBODY virtual void Update(void); // heavyweight algorithms, invoked less often + virtual void Update(void); // heavyweight algorithms, invoked less often virtual void Walk(void); virtual bool Jump(bool mustJump = false); // returns true if jump was started - NOBODY virtual void OnEvent(GameEventType event, CBaseEntity *entity = NULL, CBaseEntity *other = NULL); // invoked when event occurs in the game (some events have NULL entity) + virtual void OnEvent(GameEventType event, CBaseEntity *entity = NULL, CBaseEntity *other = NULL); // invoked when event occurs in the game (some events have NULL entity) #define CHECK_FOV true virtual bool IsVisible(const Vector *pos, bool testFOV = false) const; // return true if we can see the point @@ -642,7 +657,7 @@ public: // listening for noises bool IsNoiseHeard(void) const; // return true if we have heard a noise - bool ShouldInvestigateNoise(float *retNoiseDist); + bool ShouldInvestigateNoise(float *retNoiseDist = NULL); void InvestigateNoise(void); // investigate recent enemy noise const Vector *GetNoisePosition(void) const; // return position of last heard noise, or NULL if none heard CNavArea *GetNoiseArea(void) const; // return area where noise was heard @@ -1117,6 +1132,8 @@ private: GameEventType m_lastRadioCommand; // last radio command we recieved void RespondToRadioCommands(void); bool IsRadioCommand(GameEventType event) const; // returns true if the radio message is an order to do something + + #define NO_FORCE false void EndVoiceFeedback(bool force = true); float m_lastRadioRecievedTimestamp; // time we recieved a radio message float m_lastRadioSentTimestamp; // time when we send a radio message @@ -1275,8 +1292,7 @@ inline const CSGameState *CCSBot::GetGameState(void) const /* <5c4ce8> ../cstrike/dlls/bot/cs_bot.h:397 */ inline bool CCSBot::IsAtBombsite(void) { - UNTESTED - return GetGameState()->IsAtPlantedBombsite(); + return (m_signals.GetState() & SIGNAL_BOMB) == SIGNAL_BOMB; } /* <5a07c3> ../cstrike/dlls/bot/cs_bot.h:453 */ @@ -1344,8 +1360,7 @@ inline BotChatterInterface *CCSBot::GetChatter(void) /* <111238> ../cstrike/dlls/bot/cs_bot.h:508 */ inline bool CCSBot::IsUsingVoice(void) const { - UNTESTED - return (m_voiceFeedbackEndTimestamp != 0.0f); //return (m_voiceFeedbackEndTimestamp > gpGlobals->time); + return (m_voiceFeedbackEndTimestamp != 0.0f); } /* <519493> ../cstrike/dlls/bot/cs_bot.h:513 */ @@ -1927,32 +1942,27 @@ public: FollowTargetCollector(CBasePlayer *player) { m_player = player; - - Vector playerVel = player->pev->velocity; - - m_forward.x = playerVel.x; - m_forward.y = playerVel.y; + m_forward.x = player->pev->velocity.x; + m_forward.y = player->pev->velocity.y; float speed = m_forward.NormalizeInPlace(); - Vector playerOrigin = player->pev->origin; - const float walkSpeed = 100.0f; if (speed < walkSpeed) { - m_cutoff.x = playerOrigin.x; - m_cutoff.y = playerOrigin.y; + m_cutoff.x = player->pev->origin.x; + m_cutoff.y = player->pev->origin.y; m_forward.x = 0.0f; m_forward.y = 0.0f; } else { - const float k = 1.5f; // 2.0f; - float trimSpeed = (speed < 200.0f) ? speed : 200.0f; + const float k = 1.5f; + float_precision trimSpeed = (speed < 200.0f) ? speed : 200.0f; - m_cutoff.x = playerOrigin.x + k * trimSpeed * m_forward.x; - m_cutoff.y = playerOrigin.y + k * trimSpeed * m_forward.y; + m_cutoff.x = player->pev->origin.x + k * trimSpeed * m_forward.x; + m_cutoff.y = player->pev->origin.y + k * trimSpeed * m_forward.y; } m_targetAreaCount = 0; @@ -2008,11 +2018,20 @@ typedef void (CCSBot::*HIDE_VECTOR)(const Vector *, float, bool); typedef const CSGameState *(CCSBot::*GETGAMESTATE_CONST)(void) const; typedef CSGameState *(CCSBot::*GETGAMESTATE_NOTCONST)(void); -bool NavAreaBuildPath__PathCost__wrapper(CNavArea *startArea, CNavArea *goalArea, const Vector *goalPos, PathCost &costFunc, CNavArea **closestArea = NULL); -// refs +// NavAreaBuildPath hook +inline bool NavAreaBuildPath__PathCost__wrapper(CNavArea *startArea, CNavArea *goalArea, const Vector *goalPos, PathCost &costFunc, CNavArea **closestArea) +{ + return NavAreaBuildPath(startArea, goalArea, goalPos, costFunc, closestArea); +} +// NavAreaTravelDistance hook +inline float_precision NavAreaTravelDistance__PathCost__wrapper(CNavArea *startArea, CNavArea *endArea, PathCost &costFunc) +{ + return NavAreaTravelDistance(startArea, endArea, costFunc); +} + +// refs extern void (*pCCSBot__UpdateLookAngles)(void); -extern void (*pCCSBot__Update)(void); #endif // HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/cs_bot_chatter.cpp b/regamedll/dlls/bot/cs_bot_chatter.cpp index f0ae192b..2a56dcca 100644 --- a/regamedll/dlls/bot/cs_bot_chatter.cpp +++ b/regamedll/dlls/bot/cs_bot_chatter.cpp @@ -19,8 +19,6 @@ CBaseEntity *g_pSelectedZombieSpawn; CountdownTimer IMPL_CLASS(BotChatterInterface, m_encourageTimer); IntervalTimer IMPL_CLASS(BotChatterInterface, m_radioSilenceInterval)[ 2 ]; -void (*pBotPhrase__Randomize)(void); - #endif // HOOK_GAMEDLL /* <303469> ../cstrike/dlls/bot/cs_bot_chatter.cpp:32 */ @@ -388,20 +386,10 @@ char *BotPhrase::GetSpeakable(int bankIndex, float *duration) const // Randomly shuffle the speakable order /* <30395a> ../cstrike/dlls/bot/cs_bot_chatter.cpp:395 */ -#ifdef HOOK_GAMEDLL -void __declspec(naked) BotPhrase::Randomize(void) -{ - // you can not hook this function, because it uses the rand() function - // which does not allow us to carry out tests because different results at the output. - __asm - { - jmp pBotPhrase__Randomize - } -} -#else +#ifndef HOOK_GAMEDLL void BotPhrase::Randomize(void) { - for (uint32 i = 0; i < m_voiceBank.size(); i++) + for (uint32 i = 0; i < m_voiceBank.size(); ++i) { std::random_shuffle(m_voiceBank[i]->begin(), m_voiceBank[i]->end()); } @@ -1617,7 +1605,6 @@ void BotChatterInterface::Update(void) if (say->IsRedundant(friendSay)) { // thie statement is redundant - destroy it - //m_me->PrintIfWatched("Teammate said what I was going to say - shutting up.\n"); m_me->PrintIfWatched("Teammate said what I was going to say - shutting up.\n"); RemoveStatement(say); } @@ -2415,6 +2402,14 @@ void BotChatterInterface::FriendlyFire(void) #ifdef HOOK_GAMEDLL +void (*pBotPhrase__Randomize)(void); +void __declspec(naked) BotPhrase::Randomize(void) +{ + // you can not hook this function, because it uses the rand() function + // which does not allow us to carry out tests because different results at the output. + __asm { jmp pBotPhrase__Randomize } +} + void BotAllHostagesGoneMeme::Interpret(CCSBot *sender, CCSBot *receiver) const { Interpret_(sender, receiver); diff --git a/regamedll/dlls/bot/cs_bot_chatter.h b/regamedll/dlls/bot/cs_bot_chatter.h index 8b8f2740..9695d801 100644 --- a/regamedll/dlls/bot/cs_bot_chatter.h +++ b/regamedll/dlls/bot/cs_bot_chatter.h @@ -381,7 +381,7 @@ private: /* <2fea95> ../cstrike/dlls/bot/cs_bot_chatter.h:298 */ inline int BotPhraseManager::FindPlaceIndex(Place where) const { - for (int i = 0; i < m_placeCount; i++) + for (int i = 0; i < m_placeCount; ++i) { if (m_placeStatementHistory[i].placeID == where) return i; @@ -596,8 +596,9 @@ public: NOXREF void GuardingLooseBomb(CBaseEntity *bomb); void RequestBombLocation(void); - void GuardingHostages(Place place, bool isPlan); - void GuardingHostageEscapeZone(bool isPlan); + #define IS_PLAN true + void GuardingHostages(Place place, bool isPlan = false); + void GuardingHostageEscapeZone(bool isPlan = false); void HostagesBeingTaken(void); void HostagesTaken(void); void TalkingToHostages(void); diff --git a/regamedll/dlls/bot/cs_bot_event.cpp b/regamedll/dlls/bot/cs_bot_event.cpp index 93989686..33a0411b 100644 --- a/regamedll/dlls/bot/cs_bot_event.cpp +++ b/regamedll/dlls/bot/cs_bot_event.cpp @@ -1,110 +1,386 @@ #include "precompiled.h" /* <31d087> ../cstrike/dlls/bot/cs_bot_event.cpp:22 */ -NOBODY void CCSBot::__MAKE_VHOOK(OnEvent)(GameEventType event, CBaseEntity *entity, CBaseEntity *other) +void CCSBot::__MAKE_VHOOK(OnEvent)(GameEventType event, CBaseEntity *entity, CBaseEntity *other) { -// { -// class CCSBotManager *ctrl; // 63 -// class CBasePlayer *player; // 65 -// float range; // 363 -// enum PriorityType priority; // 364 -// bool isHostile; // 365 -// const Vector *newNoisePosition; // 419 -// float newNoiseDist; // 420 -// { -// class CBasePlayer *killer; // 81 -// { -// float const knifeAmbushChance; // 91 -// Hurry(CCSBot *const this, -// float duration); // 88 -// } -// } -// Say(BotChatterInterface *const this, -// const char *phraseName, -// float lifetime, -// float delay); // 221 -// { -// float const bombBeepHearRangeSq; // 242 -// operator-(const Vector *const this, -// const Vector &v); // 243 -// LengthSquared(const Vector *const this); // 243 -// { -// const class Zone *zone; // 248 -// } -// } -// { -// float const bombPickupHearRangeSq; // 229 -// operator-(const Vector *const this, -// const Vector &v); // 230 -// LengthSquared(const Vector *const this); // 230 -// } -// { -// class CBasePlayer *victim; // 111 -// class CBasePlayer *killer; // 113 -// GetNearbyEnemyCount(const class CCSBot *const this); // 175 -// { -// float delay; // 185 -// } -// GetTimeSinceLastSawEnemy(const class CCSBot *const this); // 155 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 164 -// GetEnemy(CCSBot *const this); // 164 -// Say(BotChatterInterface *const this, -// const char *phraseName, -// float lifetime, -// float delay); // 118 -// entindex(CBaseEntity *const this); // 124 -// } -// GetEnemy(CCSBot *const this); // 292 -// ForceRun(CCSBot *const this, -// float duration); // 294 -// { -// float const hearCallRange; // 329 -// Vector vecCenter; // 334 -// operator-(const Vector *const this, -// const Vector &v); // 330 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 330 -// { -// enum RouteType route; // 343 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 338 -// SetGoalEntity(CCSBot *const this, -// class CBaseEntity *entity); // 340 -// } -// } -// operator-(const Vector *const this, -// const Vector &v); // 376 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 376 -// { -// float const headOffChance; // 390 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 396 -// } -// operator-(const Vector *const this, -// const Vector &v); // 420 -// Length(const Vector *const this); // 420 -// { -// float const veryCloseRange; // 434 -// class CNavArea *noiseArea; // 461 -// float const maxErrorRadius; // 481 -// float const maxHearingRange; // 482 -// float errorRadius; // 483 -// { -// float const shortTermMemoryTime; // 445 -// { -// float oldNoiseDist; // 452 -// operator-(const Vector *const this, -// const Vector &v); // 452 -// Length(const Vector *const this); // 452 -// } -// } -// } -// } + GetGameState()->OnEvent(event, entity, other); + GetChatter()->OnEvent(event, entity, other); + + // Morale adjustments happen even for dead players + switch (event) + { + case EVENT_TERRORISTS_WIN: + if (m_iTeam == CT) + { + DecreaseMorale(); + } + else + { + IncreaseMorale(); + } + break; + case EVENT_CTS_WIN: + if (m_iTeam == CT) + { + IncreaseMorale(); + } + else + { + DecreaseMorale(); + } + break; + } + + if (!IsAlive()) + return; + + CBasePlayer *player = static_cast(entity); + + // If we just saw a nearby friend die, and we haven't yet acquired an enemy + // automatically acquire our dead friend's killer + if (!IsAttacking() && (GetDisposition() == ENGAGE_AND_INVESTIGATE || GetDisposition() == OPPORTUNITY_FIRE)) + { + if (event == EVENT_PLAYER_DIED) + { + if (player->m_iTeam == m_iTeam) + { + CBasePlayer *killer = static_cast(other); + + // check that attacker is an enemy (for friendly fire, etc) + if (killer && killer->IsPlayer()) + { + // check if we saw our friend die - dont check FOV - assume we're aware of our surroundings in combat + // snipers stay put + if (!IsSniper() && IsVisible(&player->pev->origin)) + { + // people are dying - we should hurry + Hurry(RANDOM_FLOAT(10.0f, 15.0f)); + + // if we're hiding with only our knife, be a little more cautious + const float knifeAmbushChance = 50.0f; + if (!IsHiding() || !IsUsingKnife() || RANDOM_FLOAT(0, 100) < knifeAmbushChance) + { + PrintIfWatched("Attacking our friend's killer!\n"); + Attack(killer); + return; + } + } + } + } + } + } + + switch (event) + { + case EVENT_PLAYER_DIED: + { + CBasePlayer *victim = player; + CBasePlayer *killer = (other && other->IsPlayer()) ? static_cast(other) : NULL; + + // if the human player died in the single player game, tell the team + if (g_pGameRules->IsCareer() && !victim->IsBot() && victim->m_iTeam == m_iTeam) + { + GetChatter()->Say("CommanderDown", 20.0f); + } + + // keep track of the last player we killed + if (killer == this) + { + m_lastVictimID = victim->entindex(); + } + + // react to teammate death + if (victim->m_iTeam == m_iTeam) + { + // chastise friendly fire from humans + if (killer != NULL && !killer->IsBot() && killer->m_iTeam == m_iTeam && killer != this) + { + GetChatter()->KilledFriend(); + } + + if (IsHunting()) + { + PrintIfWatched("Rethinking hunt due to teammate death\n"); + Idle(); + return; + } + + if (IsAttacking()) + { + if (GetTimeSinceLastSawEnemy() > 0.4f) + { + PrintIfWatched("Rethinking my attack due to teammate death\n"); + + // allow us to sneak past windows, doors, etc + IgnoreEnemies(1.0f); + + // move to last known position of enemy - this could cause us to flank if + // the danger has changed due to our teammate's recent death + SetTask(MOVE_TO_LAST_KNOWN_ENEMY_POSITION, GetEnemy()); + MoveTo(&GetLastKnownEnemyPosition()); + return; + } + } + } + // an enemy was killed + else + { + if (killer != NULL && killer->m_iTeam == m_iTeam) + { + // only chatter about enemy kills if we see them occur, and they were the last one we see + if (GetNearbyEnemyCount() <= 1) + { + // report if number of enemies left is few and we killed the last one we saw locally + GetChatter()->EnemiesRemaining(); + + if (IsVisible(&victim->pev->origin, CHECK_FOV)) + { + // congratulate teammates on their kills + if (killer != NULL && killer != this) + { + float delay = RANDOM_FLOAT(2.0f, 3.0f); + if (killer->IsBot()) + { + if (RANDOM_FLOAT(0.0f, 100.0f) < 40.0f) + GetChatter()->Say("NiceShot", 3.0f, delay); + } + else + { + // humans get the honorific + if (g_pGameRules->IsCareer()) + GetChatter()->Say("NiceShotCommander", 3.0f, delay); + else + GetChatter()->Say("NiceShotSir", 3.0f, delay); + } + } + } + } + } + } + return; + } + case EVENT_TERRORISTS_WIN: + if (m_iTeam == TERRORIST) + GetChatter()->CelebrateWin(); + return; + case EVENT_CTS_WIN: + if (m_iTeam == CT) + GetChatter()->CelebrateWin(); + return; + case EVENT_BOMB_DEFUSED: + if (m_iTeam == CT && TheCSBots()->GetBombTimeLeft() < 2.0) + GetChatter()->Say("BarelyDefused"); + return; + case EVENT_BOMB_PICKED_UP: + { + if (m_iTeam == CT && player != NULL) + { + // check if we're close enough to hear it + const float bombPickupHearRangeSq = 1000.0f * 1000.0f; + if ((pev->origin - player->pev->origin).LengthSquared() < bombPickupHearRangeSq) + { + GetChatter()->TheyPickedUpTheBomb(); + } + } + return; + } + case EVENT_BOMB_BEEP: + { + // if we don't know where the bomb is, but heard it beep, we've discovered it + if (GetGameState()->IsPlantedBombLocationKnown() == false) + { + // check if we're close enough to hear it + const float bombBeepHearRangeSq = 1000.0f * 1000.0f; + if ((pev->origin - entity->pev->origin).LengthSquared() < bombBeepHearRangeSq) + { + // radio the news to our team + if (m_iTeam == CT && GetGameState()->GetPlantedBombsite() == CSGameState::UNKNOWN) + { + const CCSBotManager::Zone *zone = TheCSBots()->GetZone(&entity->pev->origin); + if (zone != NULL) + GetChatter()->FoundPlantedBomb(zone->m_index); + } + + // remember where the bomb is + GetGameState()->UpdatePlantedBomb(&entity->pev->origin); + } + } + return; + } + case EVENT_BOMB_PLANTED: + { + // if we're a CT, forget what we're doing and go after the bomb + if (m_iTeam == CT) + { + Idle(); + } + + // if we are following someone, stop following + if (IsFollowing()) + { + StopFollowing(); + Idle(); + } + + OnEvent(EVENT_BOMB_BEEP, other); + return; + } + case EVENT_BOMB_DEFUSE_ABORTED: + PrintIfWatched("BOMB DEFUSE ABORTED\n"); + return; + case EVENT_WEAPON_FIRED: + case EVENT_WEAPON_FIRED_ON_EMPTY: + case EVENT_WEAPON_RELOADED: + { + if (m_enemy == entity && IsUsingKnife()) + ForceRun(5.0f); + break; + } + default: + break; + } + + // Process radio events from our team + if (player != NULL && player->m_iTeam == m_iTeam && event > EVENT_START_RADIO_1 && event < EVENT_END_RADIO) + { + // TODO: Distinguish between radio commands and responses + if (event != EVENT_RADIO_AFFIRMATIVE && event != EVENT_RADIO_NEGATIVE && event != EVENT_RADIO_REPORTING_IN) + { + m_lastRadioCommand = event; + m_lastRadioRecievedTimestamp = gpGlobals->time; + m_radioSubject = player; + m_radioPosition = player->pev->origin; + } + } + + // player_follows needs a player + if (player == NULL) + return; + + if (!IsRogue() && event == EVENT_HOSTAGE_CALLED_FOR_HELP && m_iTeam == CT && IsHunting()) + { + if ((entity->pev->origin - pev->origin).IsLengthGreaterThan(1000.0f)) + return; + + if (IsVisible(&entity->Center())) + { + m_task = COLLECT_HOSTAGES; + m_taskEntity = NULL; + + Run(); + m_goalEntity = entity; + + MoveTo(&entity->pev->origin, (RouteType)(m_hostageEscortCount == 0)); + PrintIfWatched("I'm fetching a hostage that called out to me\n"); + + return; + } + } + + // don't pay attention to noise that friends make + if (!IsEnemy(player)) + return; + + float range; + PriorityType priority; + bool isHostile; + + if (IsGameEventAudible(event, entity, other, &range, &priority, &isHostile) == false) + return; + + if (event == EVENT_HOSTAGE_USED) + { + if (m_iTeam == CT) + return; + + if ((entity->pev->origin - pev->origin).IsLengthGreaterThan(range)) + return; + + GetChatter()->HostagesBeingTaken(); + + if (!GetGameState()->GetNearestVisibleFreeHostage() && m_task != GUARD_HOSTAGE_RESCUE_ZONE && GuardRandomZone()) + { + m_task = GUARD_HOSTAGE_RESCUE_ZONE; + m_taskEntity = NULL; + + SetDisposition(OPPORTUNITY_FIRE); + PrintIfWatched("Trying to beat them to an escape zone!\n"); + } + } + + // check if noise is close enough for us to hear + const Vector *newNoisePosition = &player->pev->origin; + float newNoiseDist = (pev->origin - *newNoisePosition).Length(); + if (newNoiseDist < range) + { + // we heard the sound + if ((IsLocalPlayerWatchingMe() && cv_bot_debug.value == 3.0f) || cv_bot_debug.value == 4.0f) + { + PrintIfWatched("Heard noise (%s from %s, pri %s, time %3.1f)\n", + (event == EVENT_WEAPON_FIRED) ? "Weapon fire " : "", + STRING(player->pev->netname), + (priority == PRIORITY_HIGH) ? "HIGH" : ((priority == PRIORITY_MEDIUM) ? "MEDIUM" : "LOW"), + gpGlobals->time); + } + + if (event == EVENT_PLAYER_FOOTSTEP && IsUsingSniperRifle() && newNoiseDist < 300.0) + EquipPistol(); + + // should we pay attention to it + // if noise timestamp is zero, there is no prior noise + if (m_noiseTimestamp > 0.0f) + { + // only overwrite recent sound if we are louder (closer), or more important - if old noise was long ago, its faded + const float shortTermMemoryTime = 3.0f; + if (gpGlobals->time - m_noiseTimestamp < shortTermMemoryTime) + { + // prior noise is more important - ignore new one + if (priority < m_noisePriority) + return; + + float oldNoiseDist = (pev->origin - m_noisePosition).Length(); + if (newNoiseDist >= oldNoiseDist) + return; + } + } + + + // find the area in which the noise occured + // TODO: Better handle when noise occurs off the nav mesh + // TODO: Make sure noise area is not through a wall or ceiling from source of noise + // TODO: Change GetNavTravelTime to better deal with NULL destination areas + CNavArea *noiseArea = TheNavAreaGrid.GetNavArea(newNoisePosition); + if (noiseArea == NULL) + noiseArea = TheNavAreaGrid.GetNearestNavArea(newNoisePosition); + + if (noiseArea == NULL) + { + PrintIfWatched(" *** Noise occurred off the nav mesh - ignoring!\n"); + return; + } + + m_noiseArea = noiseArea; + + // remember noise priority + m_noisePriority = priority; + + // randomize noise position in the area a bit - hearing isn't very accurate + // the closer the noise is, the more accurate our placement + // TODO: Make sure not to pick a position on the opposite side of ourselves. + const float maxErrorRadius = 400.0f; + const float maxHearingRange = 2000.0f; + float errorRadius = maxErrorRadius * newNoiseDist / maxHearingRange; + + m_noisePosition.x = newNoisePosition->x + RANDOM_FLOAT(-errorRadius, errorRadius); + m_noisePosition.y = newNoisePosition->y + RANDOM_FLOAT(-errorRadius, errorRadius); + + // make sure noise position remains in the same area + m_noiseArea->GetClosestPointOnArea(&m_noisePosition, &m_noisePosition); + + m_isNoiseTravelRangeChecked = false; + // note when we heard the noise + m_noiseTimestamp = gpGlobals->time; + } } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/cs_bot_learn.cpp b/regamedll/dlls/bot/cs_bot_learn.cpp index 1055a689..35fc581e 100644 --- a/regamedll/dlls/bot/cs_bot_learn.cpp +++ b/regamedll/dlls/bot/cs_bot_learn.cpp @@ -2,8 +2,8 @@ const float updateTimesliceDuration = 0.5f; -int _navAreaCount; -int _currentIndex; +int _navAreaCount = 0; +int _currentIndex = 0; /* <343cbe> ../cstrike/dlls/bot/cs_bot_learn.cpp:95 */ inline CNavNode *LadderEndSearch(CBaseEntity *entity, const Vector *pos, NavDirType mountDir) @@ -163,7 +163,6 @@ void CCSBot::StartLearnProcess(void) { CONSOLE_ECHO("ERROR: Start position invalid\n\n"); m_processMode = PROCESS_NORMAL; - return; } @@ -180,180 +179,179 @@ void CCSBot::StartLearnProcess(void) /* <343d37> ../cstrike/dlls/bot/cs_bot_learn.cpp:217 */ bool CCSBot::LearnStep(void) -{ - UNTESTED - // take a step - while (true) - { - if (m_currentNode == NULL) - { - // search is exhausted - continue search from ends of ladders - NavLadderList::iterator iter; - for (iter = TheNavLadderList.begin(); iter != TheNavLadderList.end(); ++iter) - { - CNavLadder *ladder = (*iter); - - // check ladder bottom - if ((m_currentNode = LadderEndSearch(ladder->m_entity, &ladder->m_bottom, ladder->m_dir)) != 0) - break; - - // check ladder top - if ((m_currentNode = LadderEndSearch(ladder->m_entity, &ladder->m_top, ladder->m_dir)) != 0) - break; - } - - if (m_currentNode == NULL) - { - // all seeds exhausted, sampling complete - GenerateNavigationAreaMesh(); - return false; - } - } - - // Take a step from this node - for (int dir = NORTH; dir < NUM_DIRECTIONS; dir++) - { - if (!m_currentNode->HasVisited((NavDirType)dir)) - { - float feetOffset = pev->origin.z - GetFeetZ(); - - // start at current node position - Vector pos = *m_currentNode->GetPosition(); - - // snap to grid - int cx = SnapToGrid(pos.x); - int cy = SnapToGrid(pos.y); - - // attempt to move to adjacent node - switch (dir) - { - case NORTH: cy -= GenerationStepSize; break; - case SOUTH: cy += GenerationStepSize; break; - case EAST: cx += GenerationStepSize; break; - case WEST: cx -= GenerationStepSize; break; - } - - pos.x = cx; - pos.y = cy; - - m_generationDir = (NavDirType)dir; - - // mark direction as visited - m_currentNode->MarkAsVisited(m_generationDir); - - // test if we can move to new position - TraceResult result; - Vector from, to; - - // modify position to account for change in ground level during step - to.x = pos.x; - to.y = pos.y; - Vector toNormal; - if (GetGroundHeight(&pos, &to.z, &toNormal) == false) - { - return true; - } - - from = *m_currentNode->GetPosition(); - - Vector fromOrigin = from + Vector(0, 0, feetOffset); - Vector toOrigin = to + Vector(0, 0, feetOffset); - - UTIL_SetOrigin(pev, toOrigin); - UTIL_TraceLine(fromOrigin, toOrigin, ignore_monsters, dont_ignore_glass, ENT(pev), &result); - - bool walkable; - - if (result.flFraction == 1.0f && !result.fStartSolid) - { - // the trace didnt hit anything - clear - float toGround = to.z; - float fromGround = from.z; - - float epsilon = 0.1f; - - // check if ledge is too high to reach or will cause us to fall to our death - if (toGround - fromGround > JumpCrouchHeight + epsilon || fromGround - toGround > DeathDrop) - { - walkable = false; - } - else - { - // check surface normals along this step to see if we would cross any impassable slopes - Vector delta = to - from; - const float inc = 2.0f; - float along = inc; - bool done = false; - float ground; - Vector normal; - - walkable = true; - - while (!done) - { - Vector p; - - // need to guarantee that we test the exact edges - if (along >= GenerationStepSize) - { - p = to; - done = true; - } - else - { - p = from + delta * (along / GenerationStepSize); - } - - if (GetGroundHeight(&p, &ground, &normal) == false) - { - walkable = false; - break; - } - - // check for maximum allowed slope - if (normal.z < 0.7f) - { - walkable = false; - break; - } - - along += inc; - } - } - } - // TraceLine hit something... - else - { - if (IsEntityWalkable(VARS(result.pHit), WALK_THRU_EVERYTHING)) - { - walkable = true; - } - else - { - walkable = false; - } - } -#ifdef REGAMEDLL_FIXES - // if we're incrementally generating, don't overlap existing nav areas - CNavArea *overlap = TheNavAreaGrid.GetNavArea(&to, HumanHeight); - if (overlap != NULL) - { - walkable = false; - } -#endif // REGAMEDLL_FIXES - if (walkable) - { - // we can move here - // create a new navigation node, and update current node pointer - CNavNode *newNode = AddNode(&to, &toNormal, m_generationDir, m_currentNode); - } - - return true; - } - } - - // all directions have been searched from this node - pop back to its parent and continue - m_currentNode = m_currentNode->GetParent(); +{ + // take a step + while (true) + { + if (m_currentNode == NULL) + { + // search is exhausted - continue search from ends of ladders + NavLadderList::iterator iter; + for (iter = TheNavLadderList.begin(); iter != TheNavLadderList.end(); ++iter) + { + CNavLadder *ladder = (*iter); + + // check ladder bottom + if ((m_currentNode = LadderEndSearch(ladder->m_entity, &ladder->m_bottom, ladder->m_dir)) != 0) + break; + + // check ladder top + if ((m_currentNode = LadderEndSearch(ladder->m_entity, &ladder->m_top, ladder->m_dir)) != 0) + break; + } + + if (m_currentNode == NULL) + { + // all seeds exhausted, sampling complete + GenerateNavigationAreaMesh(); + return false; + } + } + + // Take a step from this node + for (int dir = NORTH; dir < NUM_DIRECTIONS; dir++) + { + if (!m_currentNode->HasVisited((NavDirType)dir)) + { + float feetOffset = pev->origin.z - GetFeetZ(); + + // start at current node position + Vector pos = *m_currentNode->GetPosition(); + + // snap to grid + int cx = SnapToGrid(pos.x); + int cy = SnapToGrid(pos.y); + + // attempt to move to adjacent node + switch (dir) + { + case NORTH: cy -= GenerationStepSize; break; + case SOUTH: cy += GenerationStepSize; break; + case EAST: cx += GenerationStepSize; break; + case WEST: cx -= GenerationStepSize; break; + } + + pos.x = cx; + pos.y = cy; + + m_generationDir = (NavDirType)dir; + + // mark direction as visited + m_currentNode->MarkAsVisited(m_generationDir); + + // test if we can move to new position + TraceResult result; + Vector from, to; + + // modify position to account for change in ground level during step + to.x = pos.x; + to.y = pos.y; + Vector toNormal; + if (GetGroundHeight(&pos, &to.z, &toNormal) == false) + { + return true; + } + + from = *m_currentNode->GetPosition(); + + Vector fromOrigin = from + Vector(0, 0, feetOffset); + Vector toOrigin = to + Vector(0, 0, feetOffset); + + UTIL_SetOrigin(pev, toOrigin); + UTIL_TraceLine(fromOrigin, toOrigin, ignore_monsters, dont_ignore_glass, ENT(pev), &result); + + bool walkable; + + if (result.flFraction == 1.0f && !result.fStartSolid) + { + // the trace didnt hit anything - clear + float toGround = to.z; + float fromGround = from.z; + + float epsilon = 0.1f; + + // check if ledge is too high to reach or will cause us to fall to our death + if (toGround - fromGround > JumpCrouchHeight + epsilon || fromGround - toGround > DeathDrop) + { + walkable = false; + } + else + { + // check surface normals along this step to see if we would cross any impassable slopes + Vector delta = to - from; + const float inc = 2.0f; + float along = inc; + bool done = false; + float ground; + Vector normal; + + walkable = true; + + while (!done) + { + Vector p; + + // need to guarantee that we test the exact edges + if (along >= GenerationStepSize) + { + p = to; + done = true; + } + else + { + p = from + delta * (along / GenerationStepSize); + } + + if (GetGroundHeight(&p, &ground, &normal) == false) + { + walkable = false; + break; + } + + // check for maximum allowed slope + if (normal.z < 0.7f) + { + walkable = false; + break; + } + + along += inc; + } + } + } + // TraceLine hit something... + else + { + if (IsEntityWalkable(VARS(result.pHit), WALK_THRU_EVERYTHING)) + { + walkable = true; + } + else + { + walkable = false; + } + } +#ifdef REGAMEDLL_FIXES + // if we're incrementally generating, don't overlap existing nav areas + CNavArea *overlap = TheNavAreaGrid.GetNavArea(&to, HumanHeight); + if (overlap != NULL) + { + walkable = false; + } +#endif // REGAMEDLL_FIXES + if (walkable) + { + // we can move here + // create a new navigation node, and update current node pointer + CNavNode *newNode = AddNode(&to, &toNormal, m_generationDir, m_currentNode); + } + + return true; + } + } + + // all directions have been searched from this node - pop back to its parent and continue + m_currentNode = m_currentNode->GetParent(); } } @@ -361,12 +359,12 @@ bool CCSBot::LearnStep(void) void CCSBot::UpdateLearnProcess(void) { float startTime = g_engfuncs.pfnTime(); - while (g_engfuncs.pfnTime() - startTime >= updateTimesliceDuration) + while (g_engfuncs.pfnTime() - startTime < updateTimesliceDuration) { if (LearnStep() == false) { StartAnalyzeAlphaProcess(); - break; + return; } } } @@ -390,12 +388,11 @@ void CCSBot::StartAnalyzeAlphaProcess(void) /* <34396c> ../cstrike/dlls/bot/cs_bot_learn.cpp:427 */ bool CCSBot::AnalyzeAlphaStep(void) { + ++_currentIndex; if (m_analyzeIter == TheNavAreaList.end()) return false; CNavArea *area = (*m_analyzeIter); - - ++_currentIndex; area->ComputeHidingSpots(); area->ComputeApproachAreas(); ++m_analyzeIter; @@ -407,20 +404,19 @@ bool CCSBot::AnalyzeAlphaStep(void) void CCSBot::UpdateAnalyzeAlphaProcess(void) { float startTime = g_engfuncs.pfnTime(); - float progress = _currentIndex / _navAreaCount * 50.0f; - - while (AnalyzeAlphaStep()) + while (g_engfuncs.pfnTime() - startTime < updateTimesliceDuration) { - if (g_engfuncs.pfnTime() - startTime >= updateTimesliceDuration) + if (AnalyzeAlphaStep() == false) { - drawProgressMeter(progress, "#CZero_AnalyzingHidingSpots"); + drawProgressMeter(50, "#CZero_AnalyzingHidingSpots"); + CleanupApproachAreaAnalysisPrep(); + StartAnalyzeBetaProcess(); return; } } - drawProgressMeter(50, "#CZero_AnalyzingHidingSpots"); - CleanupApproachAreaAnalysisPrep(); - StartAnalyzeBetaProcess(); + float progress = _currentIndex / _navAreaCount * 50.0f; + drawProgressMeter(progress, "#CZero_AnalyzingHidingSpots"); } /* <344aed> ../cstrike/dlls/bot/cs_bot_learn.cpp:467 */ @@ -436,12 +432,11 @@ void CCSBot::StartAnalyzeBetaProcess(void) /* <3437c8> ../cstrike/dlls/bot/cs_bot_learn.cpp:479 */ bool CCSBot::AnalyzeBetaStep(void) { + ++_currentIndex; if (m_analyzeIter == TheNavAreaList.end()) return false; CNavArea *area = (*m_analyzeIter); - - ++_currentIndex; area->ComputeSpotEncounters(); area->ComputeSniperSpots(); ++m_analyzeIter; @@ -453,19 +448,18 @@ bool CCSBot::AnalyzeBetaStep(void) void CCSBot::UpdateAnalyzeBetaProcess(void) { float startTime = g_engfuncs.pfnTime(); - float progress = (_currentIndex / _navAreaCount + 1.0f) * 50.0f; - - while (AnalyzeBetaStep()) + while (g_engfuncs.pfnTime() - startTime < updateTimesliceDuration) { - if (g_engfuncs.pfnTime() - startTime >= updateTimesliceDuration) + if (AnalyzeBetaStep() == false) { - drawProgressMeter(progress, "#CZero_AnalyzingApproachPoints"); + drawProgressMeter(100, "#CZero_AnalyzingApproachPoints"); + StartSaveProcess(); return; } } - drawProgressMeter(100, "#CZero_AnalyzingApproachPoints"); - StartSaveProcess(); + float progress = ((_currentIndex / _navAreaCount) + 1.0f) * 50.0f; + drawProgressMeter(progress, "#CZero_AnalyzingApproachPoints"); } /* <344d1f> ../cstrike/dlls/bot/cs_bot_learn.cpp:517 */ @@ -482,7 +476,8 @@ void CCSBot::UpdateSaveProcess(void) char cmd[128]; GET_GAME_DIR(filename); - filename[Q_strlen(filename)] = '\\'; + + Q_strcat(filename, "\\"); Q_strcat(filename, TheBots->GetNavMapFilename()); HintMessageToAllPlayers("Saving..."); diff --git a/regamedll/dlls/bot/cs_bot_manager.cpp b/regamedll/dlls/bot/cs_bot_manager.cpp index 320fe5ba..5297e02b 100644 --- a/regamedll/dlls/bot/cs_bot_manager.cpp +++ b/regamedll/dlls/bot/cs_bot_manager.cpp @@ -1203,17 +1203,10 @@ void CCSBotManager::ValidateMapData(void) } } -void (*pCCSBotManager__AddBot)(void); - /* <36c2b2> ../cstrike/dlls/bot/cs_bot_manager.cpp:1278 */ -NOBODY bool __declspec(naked) CCSBotManager::AddBot(const BotProfile *profile, BotProfileTeamType team) +#ifndef HOOK_GAMEDLL +bool CCSBotManager::AddBot(const BotProfile *profile, BotProfileTeamType team) { -#if 1 - __asm - { - jmp pCCSBotManager__AddBot - } -#else if (!UTIL_IsGame("czero")) return false; @@ -1287,8 +1280,8 @@ NOBODY bool __declspec(naked) CCSBotManager::AddBot(const BotProfile *profile, B CONSOLE_ECHO("Could not add bot to the game.\n"); return false; -#endif } +#endif // HOOK_GAMEDLL // Return the zone that contains the given position @@ -1583,6 +1576,13 @@ void CCSBotManager::ResetRadioMessageTimestamps(void) #ifdef HOOK_GAMEDLL +void (*pCCSBotManager__AddBot)(void); + +bool __declspec(naked) CCSBotManager::AddBot(const BotProfile *profile, BotProfileTeamType team) +{ + __asm { jmp pCCSBotManager__AddBot } +} + void CCSBotManager::ClientDisconnect(CBasePlayer *pPlayer) { ClientDisconnect_(pPlayer); diff --git a/regamedll/dlls/bot/cs_bot_manager.h b/regamedll/dlls/bot/cs_bot_manager.h index 9af572d4..1d05a6e9 100644 --- a/regamedll/dlls/bot/cs_bot_manager.h +++ b/regamedll/dlls/bot/cs_bot_manager.h @@ -36,13 +36,6 @@ #define TheBots (*pTheBots) -//#define m_flNextCVarCheck (*pm_flNextCVarCheck) -//#define m_isMapDataLoaded (*pm_isMapDataLoaded) -//#define m_editCmd (*pm_editCmd) - -//#define m_isLearningMap (*pm_isLearningMap) -//#define m_isAnalysisRequested (*pm_isAnalysisRequested) - #endif // HOOK_GAMEDLL extern CBotManager *TheBots; @@ -122,8 +115,8 @@ public: // "zones" // depending on the game mode, these are bomb zones, rescue zones, etc. - enum { MAX_ZONES = 4 }; // max # of zones in a map - enum { MAX_ZONE_NAV_AREAS = 16 }; // max # of nav areas in a zone + enum { MAX_ZONES = 4 }; // max # of zones in a map + enum { MAX_ZONE_NAV_AREAS = 16 }; // max # of nav areas in a zone struct Zone { CBaseEntity *m_entity; // the map entity @@ -133,8 +126,7 @@ public: bool m_isLegacy; // if true, use pev->origin and 256 unit radius as zone int m_index; Extent m_extent; - - };/* size: 116, cachelines: 2, members: 7 */ + }; const Zone *GetZone(int i) const { return &m_zone[i]; } const Zone *GetZone(const Vector *pos) const; // return the zone that contains the given position @@ -160,13 +152,10 @@ public: if (m_zone[i].m_areaCount == 0) continue; - if (m_zone[i].m_isBlocked) - continue; - // just use the first overlapping nav area as a reasonable approximation - float dist = NavAreaTravelDistance(startArea, m_zone[i].m_area[0], costFunc); + float_precision dist = NavAreaTravelDistance(startArea, m_zone[i].m_area[0], costFunc); - if (dist >= 0.0f && dist < closeDist) + if (/*dist >= 0.0f && */dist < closeDist) { closeZone = &m_zone[i]; closeDist = dist; diff --git a/regamedll/dlls/bot/cs_bot_radio.cpp b/regamedll/dlls/bot/cs_bot_radio.cpp index 9094013c..fd231086 100644 --- a/regamedll/dlls/bot/cs_bot_radio.cpp +++ b/regamedll/dlls/bot/cs_bot_radio.cpp @@ -74,6 +74,7 @@ void CCSBot::RespondToRadioCommands(void) return; } + CCSBotManager *ctrl = TheCSBots(); CBasePlayer *player = m_radioSubject; if (player == NULL) return; @@ -141,7 +142,7 @@ void CCSBot::RespondToRadioCommands(void) } case EVENT_RADIO_GET_OUT_OF_THERE: { - if (TheCSBots()->IsBombPlanted()) + if (ctrl->IsBombPlanted()) { EscapeFromBomb(); player->InhibitAutoFollow(inhibitAutoFollowDuration); @@ -153,11 +154,11 @@ void CCSBot::RespondToRadioCommands(void) { // if this is a defusal scenario, and the bomb is planted, // and a human player cleared a bombsite, check it off our list too - if (TheCSBots()->GetScenario() == CCSBotManager::SCENARIO_DEFUSE_BOMB) + if (ctrl->GetScenario() == CCSBotManager::SCENARIO_DEFUSE_BOMB) { - if (m_iTeam == CT && TheCSBots()->IsBombPlanted()) + if (m_iTeam == CT && ctrl->IsBombPlanted()) { - const CCSBotManager::Zone *zone = TheCSBots()->GetClosestZone(player); + const CCSBotManager::Zone *zone = ctrl->GetClosestZone(player); if (zone != NULL) { diff --git a/regamedll/dlls/bot/cs_bot_update.cpp b/regamedll/dlls/bot/cs_bot_update.cpp index f2cad623..cc9a4e02 100644 --- a/regamedll/dlls/bot/cs_bot_update.cpp +++ b/regamedll/dlls/bot/cs_bot_update.cpp @@ -150,198 +150,609 @@ void CCSBot::__MAKE_VHOOK(Upkeep)(void) UpdateLookAngles(); } -void (*pCCSBot__Update)(void); +// Heavyweight processing, invoked less often /* <3c6e1e> ../cstrike/dlls/bot/cs_bot_update.cpp:208 */ -NOBODY void __declspec(naked) CCSBot::__MAKE_VHOOK(Update)(void) +void CCSBot::__MAKE_VHOOK(Update)(void) { - __asm + CCSBotManager *ctrl = TheCSBots(); + + if (ctrl->IsAnalysisRequested() && m_processMode == PROCESS_NORMAL) { - jmp pCCSBot__Update + ctrl->AckAnalysisRequest(); + StartAnalyzeAlphaProcess(); } -// { -// class CCSBotManager *ctrl; // 210 -// float const rememberNoiseDuration; // 401 -// float const recomputeApproachPointTolerance; // 419 -// class CBasePlayer *threat; // 459 -// float const seenRecentTime; // 572 -// float const safeRearmTime; // 676 -// float const avoidTime; // 691 -// float const earliestAutoFollowTime; // 807 -// float const minAutoFollowTeamwork; // 808 -// { -// Vector vecAiming; // 342 -// Vector vecSrc; // 344 -// operator+(const Vector *const this, -// const Vector &v); // 341 -// operator+(const Vector *const this, -// const Vector &v); // 349 -// operator*(float fl, -// const Vector &v); // 349 -// operator+(const Vector *const this, -// const Vector &v); // 351 -// operator*(float fl, -// const Vector &v); // 351 -// Vector(Vector *const this, -// const Vector &v); // 351 -// Vector(Vector *const this, -// const Vector &v); // 349 -// } -// { -// Vector dir; // 366 -// float length; // 367 -// const class SpotOrder *order; // 369 -// Vector along; // 370 -// Vector(Vector *const this, -// const Vector &v); // 364 -// Vector(Vector *const this, -// const Vector &v); // 364 -// operator-(const Vector *const this, -// const Vector &v); // 366 -// NormalizeInPlace(Vector *const this); // 367 -// { -// const_iterator iter; // 371 -// end(list> *const this); // 371 -// operator*(float fl, -// const Vector &v); // 375 -// operator+(const Vector *const this, -// const Vector &v); // 375 -// Vector(Vector *const this, -// const Vector &v); // 377 -// Vector(Vector *const this, -// const Vector &v); // 377 -// operator++(_List_const_iterator *const this); // 371 -// } -// } -// { -// Vector from; // 385 -// float const size; // 387 -// Vector arrow; // 389 -// GetEyePosition(const class CCSBot *const this); // 385 -// operator+(const Vector *const this, -// const Vector &v); // 391 -// Vector(Vector *const this, -// const Vector &v); // 391 -// } -// ForgetNoise(CCSBot *const this); // 403 -// SetClearedTimestamp(CNavArea *const this, -// int teamID); // 415 -// operator-(const Vector *const this, -// const Vector &v); // 420 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 420 -// AckAnalysisRequest(CCSBotManager *const this); // 215 -// { -// float const selfDefenseRange; // 465 -// { -// float const knifeAttackRange; // 490 -// operator-(const Vector *const this, -// const Vector &v); // 491 -// IsLengthLessThan(const Vector *const this, -// float length); // 491 -// } -// GetEnemy(CCSBot *const this); // 485 -// operator-(const Vector *const this, -// const Vector &v); // 483 -// IsLengthLessThan(const Vector *const this, -// float length); // 483 -// { -// float const recentAttackDuration; // 512 -// GetTimeSinceAttacked(const class CCSBot *const this); // 513 -// } -// SetLastSeenEnemyTimestamp(CCSBotManager *const this); // 522 -// } -// IsAwareOfEnemyDeath(const class CCSBot *const this); // 530 -// GetTimeSinceLastSawEnemy(const class CCSBot *const this); // 573 -// { -// Vector target; // 591 -// } -// { -// bool doToss; // 601 -// IsElapsed(const class CountdownTimer *const this); // 605 -// } -// IsActiveWeaponReloading(const class CBot *const this); // 677 -// { -// float const duration; // 704 -// float crouchDelayTime; // 705 -// float standUpTime; // 706 -// float elapsed; // 708 -// } -// { -// unsigned char status; // 784 -// HostageWasTaken(CSGameState *const this); // 793 -// } -// { -// float gonnaBlowTime; // 755 -// } -// GetElapsedRoundTime(const class CCSBotManager *const this); // 809 -// { -// class CBasePlayer *leader; // 820 -// GetClosestVisibleHumanFriend(const class CCSBot *const this); // 820 -// IsAutoFollowAllowed(const class CBasePlayer *const this); // 821 -// { -// float const maxFollowCount; // 824 -// { -// float const autoFollowRange; // 827 -// operator-(const Vector *const this, -// const Vector &v); // 828 -// IsLengthLessThan(const Vector *const this, -// float length); // 828 -// { -// class CNavArea *leaderArea; // 830 -// { -// class PathCost pc; // 833 -// float travelRange; // 834 -// PathCost(PathCost *const this, -// class CCSBot *bot, -// enum RouteType route); // 833 -// NavAreaTravelDistance(CNavArea *startArea, -// class CNavArea *endArea, -// class PathCost &costFunc); // 834 -// } -// } -// } -// } -// } -// { -// class CBaseEntity *leader; // 865 -// float const highTeamwork; // 872 -// { -// float minFollowDuration; // 875 -// GetFollowDuration(const class CCSBot *const this); // 876 -// } -// } -// { -// float const campChance; // 890 -// } -// IsReloading(CBasePlayer *const this); // 920 -// IsElapsed(const class CountdownTimer *const this); // 927 -// { -// float const waitForHostageRange; // 929 -// Start(CountdownTimer *const this, -// float duration); // 936 -// IsElapsed(const class CountdownTimer *const this); // 941 -// Start(CountdownTimer *const this, -// float duration); // 945 -// } -// GetLooseBomb(CCSBotManager *const this); // 743 -// GetBomber(CCSBot *const this); // 740 -// GetTimeSinceLastSawEnemy(const class CCSBot *const this); // 678 -// } + + switch (m_processMode) + { + case PROCESS_LEARN: UpdateLearnProcess(); return; + case PROCESS_ANALYZE_ALPHA: UpdateAnalyzeAlphaProcess(); return; + case PROCESS_ANALYZE_BETA: UpdateAnalyzeBetaProcess(); return; + case PROCESS_SAVE: UpdateSaveProcess(); return; + } + + // update our radio chatter + // need to allow bots to finish their chatter even if they are dead + GetChatter()->Update(); + + if (m_voiceFeedbackEndTimestamp != 0.0f + && (m_voiceFeedbackEndTimestamp <= gpGlobals->time || gpGlobals->time < m_voiceFeedbackStartTimestamp)) + { + EndVoiceFeedback(NO_FORCE); + } + + // check if we are dead + if (!IsAlive()) + { + // remember that we died + m_diedLastRound = true; + BotDeathThink(); + return; + } + + // show line of fire + if ((cv_bot_traceview.value == 100.0f && IsLocalPlayerWatchingMe()) || cv_bot_traceview.value == 101.0f) + { + UTIL_MakeVectors(pev->punchangle + pev->v_angle); + + if (!IsFriendInLineOfFire()) + { + Vector vecAiming = gpGlobals->v_forward; + Vector vecSrc = GetGunPosition(); + + if (m_iTeam == TERRORIST) + UTIL_DrawBeamPoints(vecSrc, vecSrc + 2000.0f * vecAiming, 1, 255, 0, 0); + else + UTIL_DrawBeamPoints(vecSrc, vecSrc + 2000.0f * vecAiming, 1, 0, 50, 255); + } + } + + // Debug beam rendering + if (cv_bot_traceview.value == 2.0f && IsLocalPlayerWatchingMe() || cv_bot_traceview.value == 3.0f) + DrawApproachPoints(); + + if (cv_bot_traceview.value == 4.0f && IsLocalPlayerWatchingMe() || cv_bot_traceview.value == 5.0f) + { + // ... + } + + if (cv_bot_traceview.value == 1.0f && IsLocalPlayerWatchingMe()) + { + // ... + } + + if (cv_bot_stop.value != 0.0f) + return; + + // check if we are stuck + StuckCheck(); + + // if our current 'noise' was heard a long time ago, forget it + const float rememberNoiseDuration = 20.0f; + if (m_noiseTimestamp > 0.0f && gpGlobals->time - m_noiseTimestamp > rememberNoiseDuration) + { + ForgetNoise(); + } + + // where are we + if (!m_currentArea || !m_currentArea->Contains(&pev->origin)) + { + m_currentArea = TheNavAreaGrid.GetNavArea(&pev->origin); + } + + // track the last known area we were in + if (m_currentArea != NULL && m_currentArea != m_lastKnownArea) + { + m_lastKnownArea = m_currentArea; + // assume that we "clear" an area of enemies when we enter it + m_currentArea->SetClearedTimestamp(m_iTeam - 1); + } + + // update approach points + const float recomputeApproachPointTolerance = 50.0f; + if ((m_approachPointViewPosition - pev->origin).IsLengthGreaterThan(recomputeApproachPointTolerance)) + { + ComputeApproachPoints(); + m_approachPointViewPosition = pev->origin; + } + + if (cv_bot_show_nav.value > 0.0f && m_lastKnownArea != NULL) + { + m_lastKnownArea->DrawConnectedAreas(); + } + + // if we're blind, retreat! + if (IsBlind()) + { + if (!IsAtHidingSpot()) + { + switch (m_blindMoveDir) + { + case FORWARD: MoveForward(); break; + case RIGHT: StrafeRight(); break; + case BACKWARD: MoveBackward(); break; + case LEFT: StrafeLeft(); break; + default: Crouch(); break; + } + } + if (m_blindFire) + { + PrimaryAttack(); + } + + return; + } + + // Enemy acquisition and attack initiation + // take a snapshot and update our reaction time queue + UpdateReactionQueue(); + + // "threat" may be the same as our current enemy + CBasePlayer *threat = GetRecognizedEnemy(); + if (threat != NULL) + { + // adjust our personal "safe" time + AdjustSafeTime(); + + // Decide if we should attack + bool doAttack = false; + if (!IsUsingGrenade()) + { + switch (GetDisposition()) + { + case IGNORE_ENEMIES: + { + // never attack + doAttack = false; + break; + } + case SELF_DEFENSE: + { + // attack if fired on + doAttack = IsPlayerLookingAtMe(threat); + + // attack if enemy very close + if (!doAttack) + { + const float selfDefenseRange = 750.0f; + doAttack = (pev->origin - threat->pev->origin).IsLengthLessThan(selfDefenseRange); + } + break; + } + case ENGAGE_AND_INVESTIGATE: + case OPPORTUNITY_FIRE: + { + // normal combat range + doAttack = true; + break; + } + } + } + else + ThrowGrenade(&pev->origin); + + // if we aren't attacking but we are being attacked, retaliate + if (!doAttack && !IsAttacking() && GetDisposition() != IGNORE_ENEMIES) + { + const float recentAttackDuration = 1.0f; + if (GetTimeSinceAttacked() < recentAttackDuration) + { + // we may not be attacking our attacker, but at least we're not just taking it + // (since m_attacker isn't reaction-time delayed, we can't directly use it) + doAttack = true; + PrintIfWatched("Ouch! Retaliating!\n"); + } + } + + if (doAttack) + { + if (GetEnemy() == NULL || !IsAttacking() || threat != GetEnemy()) + { + if (IsUsingKnife() && IsHiding()) + { + // if hiding with a knife, wait until threat is close + const float knifeAttackRange = 250.0f; + if ((pev->origin - threat->pev->origin).IsLengthLessThan(knifeAttackRange)) + { + Attack(threat); + } + } + else + { + Attack(threat); + } + } + } + else + { + // dont attack, but keep track of nearby enemies + SetEnemy(threat); + m_isEnemyVisible = true; + } + + ctrl->SetLastSeenEnemyTimestamp(); + } + + // Validate existing enemy, if any + if (m_enemy != NULL) + { + if (IsAwareOfEnemyDeath()) + { + // we have noticed that our enemy has died + m_enemy = NULL; + m_isEnemyVisible = false; + } + else + { + // check LOS to current enemy (chest & head), in case he's dead (GetNearestEnemy() only returns live players) + // note we're not checking FOV - once we've acquired an enemy (which does check FOV), assume we know roughly where he is + if (IsVisible(m_enemy, false, &m_visibleEnemyParts)) + { + m_isEnemyVisible = true; + m_lastSawEnemyTimestamp = gpGlobals->time; + m_lastEnemyPosition = m_enemy->pev->origin; + } + else + { + m_isEnemyVisible = false; + } + + // check if enemy died + if (m_enemy->IsAlive()) + { + m_enemyDeathTimestamp = 0.0f; + m_isLastEnemyDead = false; + } + else if (m_enemyDeathTimestamp == 0.0f) + { + // note time of death (to allow bots to overshoot for a time) + m_enemyDeathTimestamp = gpGlobals->time; + m_isLastEnemyDead = true; + } + } + } + else + { + m_isEnemyVisible = false; + } + + // if we have seen an enemy recently, keep an eye on him if we can + const float seenRecentTime = 3.0f; + if (m_enemy != NULL && GetTimeSinceLastSawEnemy() < seenRecentTime) + { + AimAtEnemy(); + } + else + { + StopAiming(); + } + + // Hack to fire while retreating + // TODO: Encapsulate aiming and firing on enemies separately from current task + if (GetDisposition() == IGNORE_ENEMIES) + { + FireWeaponAtEnemy(); + } + + if (IsEndOfSafeTime() && IsUsingGrenade() && (IsWellPastSafe() || !IsUsingHEGrenade()) && !m_isWaitingToTossGrenade) + { + Vector target; + if (FindGrenadeTossPathTarget(&target)) + { + ThrowGrenade(&target); + } + } + + if (IsUsingGrenade()) + { + bool doToss = (m_isWaitingToTossGrenade && (m_tossGrenadeTimer.IsElapsed() || m_lookAtSpotState == LOOK_AT_SPOT)); + + if (doToss) + { + ClearPrimaryAttack(); + m_isWaitingToTossGrenade = false; + } + else + { + PrimaryAttack(); + } + } + else + { + m_isWaitingToTossGrenade = false; + } + + + if (IsHunting() && IsWellPastSafe() && IsUsingGrenade()) + { + EquipBestWeapon(MUST_EQUIP); + } + + // check if our weapon is totally out of ammo + // or if we no longer feel "safe", equip our weapon + if (!IsSafe() && !IsUsingGrenade() && IsActiveWeaponOutOfAmmo()) + { + EquipBestWeapon(); + } + + // TODO: This doesn't work if we are restricted to just knives and sniper rifles because we cant use the rifle at close range + if (!IsSafe() && !IsUsingGrenade() && IsUsingKnife() && !IsEscapingFromBomb()) + { + EquipBestWeapon(); + } + + // if we haven't seen an enemy in awhile, and we switched to our pistol during combat, + // switch back to our primary weapon (if it still has ammo left) + const float safeRearmTime = 5.0f; + if (!IsActiveWeaponReloading() && IsUsingPistol() && !IsPrimaryWeaponEmpty() && GetTimeSinceLastSawEnemy() > safeRearmTime) + { + EquipBestWeapon(); + } + + // reload our weapon if we must + ReloadCheck(); + + // equip silencer + SilencerCheck(); + + // listen to the radio + RespondToRadioCommands(); + + // make way + const float avoidTime = 0.33f; + if (gpGlobals->time - m_avoidTimestamp < avoidTime && m_avoid != NULL) + { + StrafeAwayFromPosition(&m_avoid->pev->origin); + } + else + { + m_avoid = NULL; + } + + if (m_isJumpCrouching) + { + const float duration = 0.75f; + const float crouchDelayTime = 0.05f; + const float standUpTime = 0.6f; + float elapsed = gpGlobals->time - m_jumpCrouchTimestamp; + + if (elapsed > crouchDelayTime && elapsed < standUpTime) + Crouch(); + + if (elapsed >= standUpTime) + StandUp(); + + if (elapsed > duration) + m_isJumpCrouching = false; + } + + // if we're using a sniper rifle and are no longer attacking, stop looking thru scope + if (!IsAtHidingSpot() && !IsAttacking() && IsUsingSniperRifle() && IsUsingScope()) + { + SecondaryAttack(); + } + + // check encounter spots + UpdatePeripheralVision(); + + // Update gamestate + if (m_bomber != NULL) + GetChatter()->SpottedBomber(GetBomber()); + + if (CanSeeLooseBomb()) + GetChatter()->SpottedLooseBomb(ctrl->GetLooseBomb()); + + // Scenario interrupts + switch (ctrl->GetScenario()) + { + case CCSBotManager::SCENARIO_DEFUSE_BOMB: + { + // flee if the bomb is ready to blow and we aren't defusing it or attacking and we know where the bomb is + // (aggressive players wait until its almost too late) + float gonnaBlowTime = 8.0f - (2.0f * GetProfile()->GetAggression()); + + // if we have a defuse kit, can wait longer + if (m_bHasDefuser) + gonnaBlowTime *= 0.66f; + + if (!IsEscapingFromBomb() // we aren't already escaping the bomb + && ctrl->IsBombPlanted() // is the bomb planted + && GetGameState()->IsPlantedBombLocationKnown() // we know where the bomb is + && ctrl->GetBombTimeLeft() < gonnaBlowTime // is the bomb about to explode + && !IsDefusingBomb() // we aren't defusing the bomb + && !IsAttacking()) // we aren't in the midst of a firefight + { + EscapeFromBomb(); + break; + } + break; + } + case CCSBotManager::SCENARIO_RESCUE_HOSTAGES: + { + if (m_iTeam == CT) + { + UpdateHostageEscortCount(); + } + else + { + // Terrorists have imperfect information on status of hostages + CSGameState::ValidateStatusType status = GetGameState()->ValidateHostagePositions(); + + if (status & CSGameState::HOSTAGES_ALL_GONE) + { + GetChatter()->HostagesTaken(); + Idle(); + } + else if (status & CSGameState::HOSTAGE_GONE) + { + GetGameState()->HostageWasTaken(); + Idle(); + } + } + break; + } + } + + // Follow nearby humans if our co-op is high and we have nothing else to do + // If we were just following someone, don't auto-follow again for a short while to + // give us a chance to do something else. + const float earliestAutoFollowTime = 5.0f; + const float minAutoFollowTeamwork = 0.4f; + if (ctrl->GetElapsedRoundTime() > earliestAutoFollowTime + && GetProfile()->GetTeamwork() > minAutoFollowTeamwork + && CanAutoFollow() + && !IsBusy() + && !IsFollowing() + && !GetGameState()->IsAtPlantedBombsite()) + { + // chance of following is proportional to teamwork attribute + if (GetProfile()->GetTeamwork() > RANDOM_FLOAT(0.0f, 1.0f)) + { + CBasePlayer *leader = GetClosestVisibleHumanFriend(); + if (leader != NULL && leader->IsAutoFollowAllowed()) + { + // count how many bots are already following this player + const float maxFollowCount = 2; + if (GetBotFollowCount(leader) < maxFollowCount) + { + const float autoFollowRange = 300.0f; + if ((leader->pev->origin - pev->origin).IsLengthLessThan(autoFollowRange)) + { + CNavArea *leaderArea = TheNavAreaGrid.GetNavArea(&leader->pev->origin); + if (leaderArea != NULL) + { + PathCost cost(this, FASTEST_ROUTE); + float travelRange = NavAreaTravelDistance(GetLastKnownArea(), leaderArea, cost); + if (/*travelRange >= 0.0f &&*/ travelRange < autoFollowRange) + { + // follow this human + Follow(leader); + PrintIfWatched("Auto-Following %s\n", STRING(leader->pev->netname)); + + if (g_pGameRules->IsCareer()) + { + GetChatter()->Say("FollowingCommander", 10.0f); + } + else + { + GetChatter()->Say("FollowingSir", 10.0f); + } + } + } + } + } + } + } + else + { + // we decided not to follow, don't re-check for a duration + m_allowAutoFollowTime = gpGlobals->time + 15.0f + (1.0f - GetProfile()->GetTeamwork()) * 30.0f; + } + } + + if (IsFollowing()) + { + // if we are following someone, make sure they are still alive + CBaseEntity *leader = m_leader; + if (leader == NULL || !leader->IsAlive()) + { + StopFollowing(); + } + + // decide whether to continue following them + const float highTeamwork = 0.85f; + if (GetProfile()->GetTeamwork() < highTeamwork) + { + float minFollowDuration = 15.0f; + if (GetFollowDuration() > minFollowDuration + 40.0f * GetProfile()->GetTeamwork()) + { + // we are bored of following our leader + StopFollowing(); + PrintIfWatched("Stopping following - bored\n"); + } + } + } + else + { + if (GetMorale() < NEUTRAL && IsSafe() && GetSafeTimeRemaining() < 2.0f && IsHunting()) + { + if (GetMorale() * -40.0 > RANDOM_FLOAT(0.0f, 100.0f)) + { + if (ctrl->IsOnOffense(this) || !ctrl->IsDefenseRushing()) + { + SetDisposition(OPPORTUNITY_FIRE); + Hide(m_lastKnownArea, RANDOM_FLOAT(3.0f, 15.0f)); + GetChatter()->Say("WaitingHere"); + } + } + } + } + + // Execute state machine + if (m_isAttacking) + { + m_attackState.OnUpdate(this); + } + else + { + m_state->OnUpdate(this); + } + + if (m_isWaitingToTossGrenade) + { + ResetStuckMonitor(); + ClearMovement(); + } + + // don't move while reloading unless we see an enemy + if (IsReloading() && !m_isEnemyVisible) + { + ResetStuckMonitor(); + ClearMovement(); + } + + // if we get too far ahead of the hostages we are escorting, wait for them + if (!IsAttacking() && m_inhibitWaitingForHostageTimer.IsElapsed()) + { + const float waitForHostageRange = 500.0f; + if (GetTask() == RESCUE_HOSTAGES && GetRangeToFarthestEscortedHostage() > waitForHostageRange) + { + if (!m_isWaitingForHostage) + { + // just started waiting + m_isWaitingForHostage = true; + m_waitForHostageTimer.Start(10.0f); + } + else + { + // we've been waiting + if (m_waitForHostageTimer.IsElapsed()) + { + // give up waiting for awhile + m_isWaitingForHostage = false; + m_inhibitWaitingForHostageTimer.Start(3.0f); + } + else + { + // keep waiting + ResetStuckMonitor(); + ClearMovement(); + } + } + } + } + + // remember our prior safe time status + m_wasSafe = IsSafe(); } #ifdef HOOK_GAMEDLL -// NavAreaBuildPath hook -bool NavAreaBuildPath__PathCost__wrapper(CNavArea *startArea, CNavArea *goalArea, const Vector *goalPos, PathCost &costFunc, CNavArea **closestArea) -{ - return NavAreaBuildPath(startArea, goalArea, goalPos, costFunc, closestArea); -} - void CCSBot::Upkeep(void) { Upkeep_(); } + void CCSBot::Update(void) { Update_(); diff --git a/regamedll/dlls/bot/cs_bot_vision.cpp b/regamedll/dlls/bot/cs_bot_vision.cpp index a779b2e7..205921b7 100644 --- a/regamedll/dlls/bot/cs_bot_vision.cpp +++ b/regamedll/dlls/bot/cs_bot_vision.cpp @@ -1036,10 +1036,7 @@ void CCSBot::__MAKE_VHOOK(Blind)(float duration, float holdTime, float fadeTime, void (*pCCSBot__UpdateLookAngles)(void); void __declspec(naked) CCSBot::UpdateLookAngles(void) { - __asm - { - jmp pCCSBot__UpdateLookAngles - } + __asm { jmp pCCSBot__UpdateLookAngles } } void CCSBot::Blind(float duration, float holdTime, float fadeTime, int alpha) diff --git a/regamedll/dlls/bot/states/cs_bot_attack.cpp b/regamedll/dlls/bot/states/cs_bot_attack.cpp index 0e7bf412..d1e031c1 100644 --- a/regamedll/dlls/bot/states/cs_bot_attack.cpp +++ b/regamedll/dlls/bot/states/cs_bot_attack.cpp @@ -1,35 +1,120 @@ #include "precompiled.h" +// Begin attacking + /* <519735> ../cstrike/dlls/bot/states/cs_bot_attack.cpp:16 */ -NOBODY void AttackState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void AttackState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// { -// class CBasePlayer *enemy; // 18 -// float skill; // 105 -// float dodgeChance; // 108 -// GetEnemy(CCSBot *const this); // 18 -// PushPostureContext(CBot *const this); // 21 -// DestroyPath(CCSBot *const this); // 23 -// Invalidate(CountdownTimer *const this); // 34 -// { -// float const crouchFarRange; // 63 -// float crouchChance; // 64 -// operator-(const Vector *const this, -// const Vector &v); // 69 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 69 -// { -// TraceResult result; // 77 -// Vector origin; // 79 -// Vector(Vector *const this, -// const Vector &v); // 79 -// } -// } -// } + CBasePlayer *enemy = me->GetEnemy(); + + // store our posture when the attack began + me->PushPostureContext(); + me->DestroyPath(); + + // if we are using a knife, try to sneak up on the enemy + if (enemy != NULL && me->IsUsingKnife() && !me->IsPlayerFacingMe(enemy)) + me->Walk(); + else + me->Run(); + + me->GetOffLadder(); + me->ResetStuckMonitor(); + + m_repathTimer.Invalidate(); + m_haveSeenEnemy = me->IsEnemyVisible(); + m_nextDodgeStateTimestamp = 0.0f; + m_firstDodge = true; + m_isEnemyHidden = false; + m_reacquireTimestamp = 0.0f; + + m_pinnedDownTimestamp = gpGlobals->time + RANDOM_FLOAT(7.0f, 10.0f); + m_shieldToggleTimestamp = gpGlobals->time + RANDOM_FLOAT(2.0f, 10.0f); + m_shieldForceOpen = false; + + // if we encountered someone while escaping, grab our weapon and fight! + if (me->IsEscapingFromBomb()) + me->EquipBestWeapon(); + + if (me->IsUsingKnife()) + { + // can't crouch and hold with a knife + m_crouchAndHold = false; + me->StandUp(); + } + else + { + // decide whether to crouch where we are, or run and gun (if we havent already - see CCSBot::Attack()) + if (!m_crouchAndHold) + { + if (enemy != NULL) + { + const float crouchFarRange = 750.0f; + float crouchChance; + + // more likely to crouch if using sniper rifle or if enemy is far away + if (me->IsUsingSniperRifle()) + crouchChance = 50.0f; + else if ((me->pev->origin - enemy->pev->origin).IsLengthGreaterThan(crouchFarRange)) + crouchChance = 50.0f; + else + crouchChance = 20.0f * (1.0f - me->GetProfile()->GetAggression()); + + if (RANDOM_FLOAT(0.0f, 100.0f) < crouchChance) + { + // make sure we can still see if we crouch + TraceResult result; + + Vector origin = me->pev->origin; + if (!me->IsCrouching()) + { + // we are standing, adjust for lower crouch origin + origin.z -= 20.0f; + } + + UTIL_TraceLine(origin, enemy->EyePosition(), ignore_monsters, ignore_glass, ENT(me->pev), &result); + + if (result.flFraction == 1.0f) + { + m_crouchAndHold = true; + } + } + } + } + + if (m_crouchAndHold) + { + me->Crouch(); + me->PrintIfWatched("Crouch and hold attack!\n"); + } + } + + m_scopeTimestamp = 0; + m_didAmbushCheck = false; + + float skill = me->GetProfile()->GetSkill(); + + // tendency to dodge is proportional to skill + float dodgeChance = 80.0f * skill; + + if (me->IsUsingKnife()) + { + dodgeChance *= 2.0f; + } + + // high skill bots always dodge if outnumbered, or they see a sniper + if (skill > 0.5f && me->IsOutnumbered()) + { + dodgeChance = 100.0f; + } + + m_dodge = (RANDOM_FLOAT(0.0f, 100.0f) < dodgeChance) != 0; + + // decide whether we might bail out of this fight + m_isCoward = (RANDOM_FLOAT(0.0f, 100.0f) > 100.0f * me->GetProfile()->GetAggression()); } /* <51a140> ../cstrike/dlls/bot/states/cs_bot_attack.cpp:135 */ -NOBODY void AttackState::StopAttacking(CCSBot *me) +void AttackState::StopAttacking(CCSBot *me) { if (me->m_task == CCSBot::SNIPING) { @@ -42,120 +127,440 @@ NOBODY void AttackState::StopAttacking(CCSBot *me) } } +// Perform attack behavior + /* <51997e> ../cstrike/dlls/bot/states/cs_bot_attack.cpp:152 */ -NOBODY void AttackState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void AttackState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// class CBasePlayerWeapon *weapon; // 161 -// class CBasePlayer *enemy; // 173 -// float notSeenEnemyTime; // 368 -// float chaseTime; // 444 -// float const hurtRecentlyTime; // 474 -// StopRapidFire(CCSBot *const this); // 158 -// GetEnemy(CCSBot *const this); // 173 -// IsElapsed(const class CountdownTimer *const this); // 189 -// { -// bool isPinnedDown; // 198 -// Start(CountdownTimer *const this, -// float duration); // 210 -// } -// { -// bool repath; // 252 -// ForceRun(CCSBot *const this, -// float duration); // 240 -// Hurry(CCSBot *const this, -// float duration); // 241 -// { -// float const repathRange; // 255 -// operator-(const Vector *const this, -// const Vector &v); // 256 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 256 -// } -// IsElapsed(const class CountdownTimer *const this); // 264 -// DestroyPath(CCSBot *const this); // 272 -// Start(CountdownTimer *const this, -// float duration); // 267 -// } -// IsReloading(CBasePlayer *const this); // 286 -// IsProtectedByShield(CBasePlayer *const this); // 289 -// { -// float const sniperMinRange; // 320 -// operator-(const Vector *const this, -// const Vector &v); // 321 -// IsLengthLessThan(const Vector *const this, -// float length); // 321 -// } -// { -// float const shotgunMaxRange; // 327 -// operator-(const Vector *const this, -// const Vector &v); // 328 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 328 -// } -// { -// Vector toAimSpot3D; // 342 -// float targetRange; // 343 -// float const waitScopeTime; // 349 -// operator-(const Vector *const this, -// const Vector &v); // 342 -// Length(const Vector *const this); // 343 -// GetZoomLevel(const class CCSBot *const this); // 346 -// } -// IsProtectedByShield(CBasePlayer *const this); // 295 -// IsProtectedByShield(CBasePlayer *const this); // 302 -// IsAwareOfEnemyDeath(const class CCSBot *const this); // 358 -// { -// float hideChance; // 397 -// { -// float ambushTime; // 401 -// const Vector *spot; // 405 -// } -// } -// StopAttacking(AttackState *const this, -// class CCSBot *me); // 424 -// StopAttacking(AttackState *const this, -// class CCSBot *me); // 377 -// GetNoisePosition(const class CCSBot *const this); // 378 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 465 -// entindex(CBaseEntity *const this); // 361 -// { -// Vector toEnemy; // 508 -// float range; // 509 -// float const hysterisRange; // 511 -// float minRange; // 513 -// float maxRange; // 514 -// float const dodgeRange; // 526 -// operator-(const Vector *const this, -// const Vector &v); // 508 -// Length2D(const Vector *const this); // 509 -// { -// int next; // 534 -// { -// float const jumpChance; // 540 -// IsNotMoving(const class CCSBot *const this); // 541 -// } -// } -// } -// GetTimeSinceAttacked(const class CCSBot *const this); // 476 -// GetEnemy(CCSBot *const this); // 478 -// StopAttacking(AttackState *const this, -// class CCSBot *me); // 459 -// GetNearbyEnemyCount(const class CCSBot *const this); // 361 -// entindex(CBaseEntity *const this); // 362 -// } + // can't be stuck while attacking + me->ResetStuckMonitor(); + me->StopRapidFire(); + + CBasePlayerWeapon *weapon = me->GetActiveWeapon(); + if (weapon != NULL) + { + if (weapon->m_iId == WEAPON_C4 || + weapon->m_iId == WEAPON_HEGRENADE || + weapon->m_iId == WEAPON_FLASHBANG || + weapon->m_iId == WEAPON_SMOKEGRENADE) + { + me->EquipBestWeapon(); + } + } + + CBasePlayer *enemy = me->GetEnemy(); + if (enemy == NULL) + { + StopAttacking(me); + return; + } + + // keep track of whether we have seen our enemy at least once yet + if (!m_haveSeenEnemy) + m_haveSeenEnemy = me->IsEnemyVisible(); + + // Retreat check + // Do not retreat if the enemy is too close + if (m_retreatTimer.IsElapsed()) + { + // If we've been fighting this battle for awhile, we're "pinned down" and + // need to do something else. + // If we are outnumbered, retreat. + bool isPinnedDown = (gpGlobals->time > m_pinnedDownTimestamp); + + if (isPinnedDown || + (me->IsOutnumbered() && m_isCoward) || + (me->OutnumberedCount() >= 2 && me->GetProfile()->GetAggression() < 1.0f)) + { + // tell our teammates our plight + if (isPinnedDown) + me->GetChatter()->PinnedDown(); + else + me->GetChatter()->Scared(); + + m_retreatTimer.Start(RANDOM_FLOAT(3.0f, 15.0f)); + + // try to retreat + if (me->TryToRetreat()) + { + // if we are a sniper, equip our pistol so we can fire while retreating + if (me->IsUsingSniperRifle()) + { + me->EquipPistol(); + } + } + else + { + me->PrintIfWatched("I want to retreat, but no safe spots nearby!\n"); + } + } + } + + // Knife fighting + // We need to pathfind right to the enemy to cut him + if (me->IsUsingKnife()) + { + // can't crouch and hold with a knife + m_crouchAndHold = false; + me->StandUp(); + + // if we are using a knife and our prey is looking towards us, run at him + if (me->IsPlayerFacingMe(enemy)) + { + me->ForceRun(5.0f); + me->Hurry(10.0f); + } + else + { + me->Walk(); + } + + // slash our victim + me->FireWeaponAtEnemy(); + + // if our victim has moved, repath + bool repath = false; + if (me->HasPath()) + { + const float repathRange = 100.0f; + if ((me->GetPathEndpoint() - enemy->pev->origin).IsLengthGreaterThan(repathRange)) + { + repath = true; + } + } + else + { + repath = true; + } + + if (repath && m_repathTimer.IsElapsed()) + { + me->ComputePath(TheNavAreaGrid.GetNearestNavArea(&enemy->pev->origin), &enemy->pev->origin, FASTEST_ROUTE); + + const float repathInterval = 0.5f; + m_repathTimer.Start(repathInterval); + } + + // move towards victim + if (me->UpdatePathMovement(NO_SPEED_CHANGE) != CCSBot::PROGRESSING) + { + me->DestroyPath(); + } + + return; + } + + // Simple shield usage + if (me->HasShield()) + { + if (me->IsEnemyVisible() && !m_shieldForceOpen) + { + if (!me->IsRecognizedEnemyReloading() && !me->IsReloading() && me->IsPlayerLookingAtMe(enemy)) + { + // close up - enemy is pointing his gun at us + if (!me->IsProtectedByShield()) + me->SecondaryAttack(); + } + else + { + // enemy looking away or reloading his weapon - open up and shoot him + if (me->IsProtectedByShield()) + me->SecondaryAttack(); + } + } + else + { + // can't see enemy, open up + if (me->IsProtectedByShield()) + me->SecondaryAttack(); + } + + if (gpGlobals->time > m_shieldToggleTimestamp) + { + m_shieldToggleTimestamp = gpGlobals->time + RANDOM_FLOAT(0.5, 2.0f); + + // toggle shield force open + m_shieldForceOpen = !m_shieldForceOpen; + } + } + + // check if our weapon range is bad and we should switch to pistol + if (me->IsUsingSniperRifle()) + { + // if we have a sniper rifle and our enemy is too close, switch to pistol + // NOTE: Must be larger than NO_ZOOM range in AdjustZoom() + const float sniperMinRange = 310.0f; + if ((enemy->pev->origin - me->pev->origin).IsLengthLessThan(sniperMinRange)) + me->EquipPistol(); + } + else if (me->IsUsingShotgun()) + { + // if we have a shotgun equipped and enemy is too far away, switch to pistol + const float shotgunMaxRange = 1000.0f; + if ((enemy->pev->origin - me->pev->origin).IsLengthGreaterThan(shotgunMaxRange)) + me->EquipPistol(); + } + + // if we're sniping, look through the scope - need to do this here in case a reload resets our scope + if (me->IsUsingSniperRifle()) + { + // for Scouts and AWPs, we need to wait for zoom to resume + if (me->m_bResumeZoom) + { + m_scopeTimestamp = gpGlobals->time; + return; + } + + Vector toAimSpot3D = me->m_aimSpot - me->pev->origin; + float targetRange = toAimSpot3D.Length(); + + // dont adjust zoom level if we're already zoomed in - just fire + if (me->GetZoomLevel() == CCSBot::NO_ZOOM && me->AdjustZoom(targetRange)) + m_scopeTimestamp = gpGlobals->time; + + const float waitScopeTime = 0.2f + me->GetProfile()->GetReactionTime(); + if (gpGlobals->time - m_scopeTimestamp < waitScopeTime) + { + // force us to wait until zoomed in before firing + return; + } + } + + // see if we "notice" that our prey is dead + if (me->IsAwareOfEnemyDeath()) + { + // let team know if we killed the last enemy + if (me->GetLastVictimID() == enemy->entindex() && me->GetNearbyEnemyCount() <= 1) + { + me->GetChatter()->KilledMyEnemy(enemy->entindex()); + } + + StopAttacking(me); + return; + } + + float notSeenEnemyTime = gpGlobals->time - me->GetLastSawEnemyTimestamp(); + + // if we haven't seen our enemy for a moment, continue on if we dont want to fight, or decide to ambush if we do + if (!me->IsEnemyVisible()) + { + // attend to nearby enemy gunfire + if (notSeenEnemyTime > 0.5f && me->CanHearNearbyEnemyGunfire()) + { + // give up the attack, since we didn't want it in the first place + StopAttacking(me); + + me->SetLookAt("Nearby enemy gunfire", me->GetNoisePosition(), PRIORITY_HIGH, 0.0f); + me->PrintIfWatched("Checking nearby threatening enemy gunfire!\n"); + return; + } + + // check if we have lost track of our enemy during combat + if (notSeenEnemyTime > 0.25f) + { + m_isEnemyHidden = true; + } + + if (notSeenEnemyTime > 0.1f) + { + if (me->GetDisposition() == CCSBot::ENGAGE_AND_INVESTIGATE) + { + // decide whether we should hide and "ambush" our enemy + if (m_haveSeenEnemy && !m_didAmbushCheck) + { + const float hideChance = 33.3f; + + if (RANDOM_FLOAT(0.0, 100.0f) < hideChance) + { + float ambushTime = RANDOM_FLOAT(3.0f, 15.0f); + + // hide in ambush nearby + // TODO: look towards where we know enemy is + const Vector *spot = FindNearbyRetreatSpot(me, 200.0f); + if (spot != NULL) + { + me->IgnoreEnemies(1.0f); + me->Run(); + me->StandUp(); + me->Hide(spot, ambushTime, true); + return; + } + } + + // don't check again + m_didAmbushCheck = true; + } + } + else + { + // give up the attack, since we didn't want it in the first place + StopAttacking(me); + return; + } + } + } + else + { + // we can see the enemy again - reset our ambush check + m_didAmbushCheck = false; + + // if the enemy is coming out of hiding, we need time to react + if (m_isEnemyHidden) + { + m_reacquireTimestamp = gpGlobals->time + me->GetProfile()->GetReactionTime(); + m_isEnemyHidden = false; + } + } + + // if we haven't seen our enemy for a long time, chase after them + float chaseTime = 2.0f + 2.0f * (1.0f - me->GetProfile()->GetAggression()); + + // if we are sniping, be very patient + if (me->IsUsingSniperRifle()) + chaseTime += 3.0f; + // if we are crouching, be a little patient + else if (me->IsCrouching()) + chaseTime += 1.0f; + + // if we can't see the enemy, and have either seen him but currently lost sight of him, + // or haven't yet seen him, chase after him (unless we are a sniper) + if (!me->IsEnemyVisible() && (notSeenEnemyTime > chaseTime || !m_haveSeenEnemy)) + { + // snipers don't chase their prey - they wait for their prey to come to them + if (me->GetTask() == CCSBot::SNIPING) + { + StopAttacking(me); + return; + } + else + { + // move to last known position of enemy + me->SetTask(CCSBot::MOVE_TO_LAST_KNOWN_ENEMY_POSITION, enemy); + me->MoveTo(&me->GetLastKnownEnemyPosition()); + return; + } + } + + // if we can't see our enemy at the moment, and were shot by + // a different visible enemy, engage them instead + const float hurtRecentlyTime = 3.0f; + if (!me->IsEnemyVisible() && + me->GetTimeSinceAttacked() < hurtRecentlyTime && + me->GetAttacker() != NULL && + me->GetAttacker() != me->GetEnemy()) + { + // if we can see them, attack, otherwise panic + if (me->IsVisible(me->GetAttacker(), CHECK_FOV)) + { + me->Attack(me->GetAttacker()); + me->PrintIfWatched("Switching targets to retaliate against new attacker!\n"); + } + return; + } + + if (gpGlobals->time > m_reacquireTimestamp) + me->FireWeaponAtEnemy(); + + + // do dodge behavior + // If sniping or crouching, stand still. + if (m_dodge && !me->IsUsingSniperRifle() && !m_crouchAndHold) + { + Vector toEnemy = enemy->pev->origin - me->pev->origin; + float range = toEnemy.Length2D(); + + const float hysterisRange = 125.0f; // (+/-) m_combatRange + + float minRange = me->GetCombatRange() - hysterisRange; + float maxRange = me->GetCombatRange() + hysterisRange; + + // move towards (or away from) enemy if we are using a knife, behind a corner, or we aren't very skilled + if (me->GetProfile()->GetSkill() < 0.66f || !me->IsEnemyVisible()) + { + if (range > maxRange) + me->MoveForward(); + else if (range < minRange) + me->MoveBackward(); + } + + // don't dodge if enemy is facing away + const float dodgeRange = 2000.0f; + if (range > dodgeRange || !me->IsPlayerFacingMe(enemy)) + { + m_dodgeState = STEADY_ON; + m_nextDodgeStateTimestamp = 0.0f; + } + else if (gpGlobals->time >= m_nextDodgeStateTimestamp) + { + int next; + + // select next dodge state that is different that our current one + do + { + // high-skill bots may jump when first engaging the enemy (if they are moving) + const float jumpChance = 33.3f; + if (m_firstDodge && me->GetProfile()->GetSkill() > 0.5f && RANDOM_FLOAT(0, 100) < jumpChance && !me->IsNotMoving()) + next = RANDOM_LONG(0, NUM_ATTACK_STATES - 1); + else + next = RANDOM_LONG(0, NUM_ATTACK_STATES - 2); + } + while (!m_firstDodge && next == m_dodgeState); + + m_dodgeState = (DodgeStateType)next; + m_nextDodgeStateTimestamp = gpGlobals->time + RANDOM_FLOAT(0.3f, 1.0f); + m_firstDodge = false; + } + + switch (m_dodgeState) + { + case STEADY_ON: + { + break; + } + case SLIDE_LEFT: + { + me->StrafeLeft(); + break; + } + case SLIDE_RIGHT: + { + me->StrafeRight(); + break; + } + case JUMP: + { + if (me->m_isEnemyVisible) + { + me->Jump(); + } + break; + } + } + } } +// Finish attack + /* <5198d4> ../cstrike/dlls/bot/states/cs_bot_attack.cpp:578 */ -NOBODY void AttackState::__MAKE_VHOOK(OnExit)(CCSBot *me) +void AttackState::__MAKE_VHOOK(OnExit)(CCSBot *me) { -// ForgetNoise(CCSBot *const this); // 585 -// PopPostureContext(CBot *const this); // 589 -// IsProtectedByShield(CBasePlayer *const this); // 592 -// StopRapidFire(CCSBot *const this); // 597 -// ClearSurpriseDelay(CCSBot *const this); // 598 + me->PrintIfWatched("AttackState:OnExit()\n"); + + m_crouchAndHold = false; + + // clear any noises we heard during battle + me->ForgetNoise(); + me->ResetStuckMonitor(); + + // resume our original posture + me->PopPostureContext(); + + // put shield away + if (me->IsProtectedByShield()) + me->SecondaryAttack(); + + me->StopRapidFire(); + me->ClearSurpriseDelay(); } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_buy.cpp b/regamedll/dlls/bot/states/cs_bot_buy.cpp index b049eaae..9dcec715 100644 --- a/regamedll/dlls/bot/states/cs_bot_buy.cpp +++ b/regamedll/dlls/bot/states/cs_bot_buy.cpp @@ -1,91 +1,525 @@ #include "precompiled.h" /* <5291fd> ../cstrike/dlls/bot/states/cs_bot_buy.cpp:18 */ -NOBODY bool HasDefaultPistol(CCSBot *me) +bool HasDefaultPistol(CCSBot *me) { + CBasePlayerWeapon *pistol = static_cast(me->m_rgpPlayerItems[ PISTOL_SLOT ]); + + if (pistol == NULL) + return false; + + if (me->m_iTeam == TERRORIST && pistol->m_iId == WEAPON_GLOCK18) + return true; + + if (me->m_iTeam == CT && pistol->m_iId == WEAPON_USP) + return true; + + return false; } +// Buy weapons, armor, etc. + /* <5299e4> ../cstrike/dlls/bot/states/cs_bot_buy.cpp:37 */ -NOBODY void BuyState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void BuyState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// { -// class CCSBotManager *ctrl; // 48 -// { -// float const buyDefuseKitChance; // 60 -// } -// HasDefaultPistol(CCSBot *me); // 93 -// AllowShotguns(const class CCSBotManager *const this); // 96 -// } + CCSBotManager *ctrl = TheCSBots(); + + m_retries = 0; + m_prefRetries = 0; + m_prefIndex = 0; + + m_doneBuying = false; + m_isInitialDelay = true; + + // this will force us to stop holding live grenade + me->EquipBestWeapon(); + + m_buyDefuseKit = false; + m_buyShield = false; + + if (me->m_iTeam == CT) + { + if (ctrl->GetScenario() == CCSBotManager::SCENARIO_DEFUSE_BOMB) + { + // CT's sometimes buy defuse kits in the bomb scenario (except in career mode, where the player should defuse) + if (g_pGameRules->IsCareer() == false) + { + const float buyDefuseKitChance = 50.0f; // 100.0f * (me->GetProfile()->GetSkill() + 0.2f); + if (RANDOM_FLOAT(0.0f, 100.0f) < buyDefuseKitChance) + { + m_buyDefuseKit = true; + } + } + } + + // determine if we want a tactical shield + if (!me->m_bHasPrimary && ctrl->AllowTacticalShield()) + { + if (me->m_iAccount > 2500) + { + if (me->m_iAccount < 4000) + m_buyShield = (RANDOM_FLOAT(0, 100.0f) < 33.3f) ? true : false; + else + m_buyShield = (RANDOM_FLOAT(0, 100.0f) < 10.0f) ? true : false; + } + } + } + + if (ctrl->AllowGrenades()) + { + m_buyGrenade = (RANDOM_FLOAT(0.0f, 100.0f) < 33.3f) ? true : false; + } + else + { + m_buyGrenade = false; + } + + m_buyPistol = false; + + if (ctrl->AllowPistols()) + { + CBasePlayerWeapon *pistol = static_cast(me->m_rgpPlayerItems[ PISTOL_SLOT ]); + + // check if we have a pistol + if (pistol != NULL) + { + // if we have our default pistol, think about buying a different one + if (HasDefaultPistol(me)) + { + // if everything other than pistols is disallowed, buy a pistol + if (ctrl->AllowShotguns() == false && + ctrl->AllowSubMachineGuns() == false && + ctrl->AllowRifles() == false && + ctrl->AllowMachineGuns() == false && + ctrl->AllowTacticalShield() == false && + ctrl->AllowSnipers() == false) + { + m_buyPistol = (RANDOM_FLOAT(0, 100) < 75.0f); + } + else if (me->m_iAccount < 1000) + { + // if we're low on cash, buy a pistol + m_buyPistol = (RANDOM_FLOAT(0, 100) < 75.0f); + } + else + { + m_buyPistol = (RANDOM_FLOAT(0, 100) < 33.3f); + } + } + } + else + { + // we dont have a pistol - buy one + m_buyPistol = true; + } + } } -/* <52972b> ../cstrike/dlls/bot/states/cs_bot_buy.cpp:212 */ -NOBODY inline WeaponType GetWeaponType(const char *alias) +enum WeaponType { -// { -// int i; // 214 -// } + PISTOL, + SHOTGUN, + SUB_MACHINE_GUN, + RIFLE, + MACHINE_GUN, + SNIPER_RIFLE, + GRENADE, + NUM_WEAPON_TYPES, +}; + +struct BuyInfo +{ + WeaponType type; + bool preferred; // more challenging bots prefer these weapons + char *buyAlias; // the buy alias for this equipment +}; + +// These tables MUST be kept in sync with the CT and T buy aliases + +#ifndef HOOK_GAMEDLL + +static BuyInfo primaryWeaponBuyInfoCT[ PRIMARY_WEAPON_BUY_COUNT ] = +{ + { SHOTGUN, false, "m3" }, // WEAPON_M3 + { SHOTGUN, false, "xm1014" }, // WEAPON_XM1014 + { SUB_MACHINE_GUN, false, "tmp" }, // WEAPON_TMP + { SUB_MACHINE_GUN, false, "mp5" }, // WEAPON_MP5N + { SUB_MACHINE_GUN, false, "ump45" }, // WEAPON_UMP45 + { SUB_MACHINE_GUN, false, "p90" }, // WEAPON_P90 + { RIFLE, true, "famas" }, // WEAPON_FAMAS + { SNIPER_RIFLE, false, "scout" }, // WEAPON_SCOUT + { RIFLE, true, "m4a1" }, // WEAPON_M4A1 + { RIFLE, false, "aug" }, // WEAPON_AUG + { SNIPER_RIFLE, true, "sg550" }, // WEAPON_SG550 + { SNIPER_RIFLE, true, "awp" }, // WEAPON_AWP + { MACHINE_GUN, false, "m249" } // WEAPON_M249 +}; + +static BuyInfo secondaryWeaponBuyInfoCT[ SECONDARY_WEAPON_BUY_COUNT ] = +{ +// { PISTOL, false, "glock" }, +// { PISTOL, false, "usp" }, + { PISTOL, true, "p228" }, + { PISTOL, true, "deagle" }, + { PISTOL, true, "fn57" } +}; + +static BuyInfo primaryWeaponBuyInfoT[ PRIMARY_WEAPON_BUY_COUNT ] = +{ + { SHOTGUN, false, "m3" }, // WEAPON_M3 + { SHOTGUN, false, "xm1014" }, // WEAPON_XM1014 + { SUB_MACHINE_GUN, false, "mac10" }, // WEAPON_MAC10 + { SUB_MACHINE_GUN, false, "mp5" }, // WEAPON_MP5N + { SUB_MACHINE_GUN, false, "ump45" }, // WEAPON_UMP45 + { SUB_MACHINE_GUN, false, "p90" }, // WEAPON_P90 + { RIFLE, true, "galil" }, // WEAPON_GALIL + { RIFLE, true, "ak47" }, // WEAPON_AK47 + { SNIPER_RIFLE, false, "scout" }, // WEAPON_SCOUT + { RIFLE, true, "sg552" }, // WEAPON_SG552 + { SNIPER_RIFLE, true, "awp" }, // WEAPON_AWP + { SNIPER_RIFLE, true, "g3sg1" }, // WEAPON_G3SG1 + { MACHINE_GUN, false, "m249" } // WEAPON_M249 +}; + +static BuyInfo secondaryWeaponBuyInfoT[ SECONDARY_WEAPON_BUY_COUNT ] = +{ +// { PISTOL, false, "glock" }, +// { PISTOL, false, "usp" }, + { PISTOL, true, "p228" }, + { PISTOL, true, "deagle" }, + { PISTOL, true, "elites" } +}; + +#else // HOOK_GAMEDLL + +BuyInfo primaryWeaponBuyInfoCT[ PRIMARY_WEAPON_BUY_COUNT ]; +BuyInfo secondaryWeaponBuyInfoCT[ SECONDARY_WEAPON_BUY_COUNT]; + +BuyInfo primaryWeaponBuyInfoT[ PRIMARY_WEAPON_BUY_COUNT ]; +BuyInfo secondaryWeaponBuyInfoT[ SECONDARY_WEAPON_BUY_COUNT ]; + +#endif // HOOK_GAMEDLL + +// Given a weapon alias, return the kind of weapon it is + +/* <52972b> ../cstrike/dlls/bot/states/cs_bot_buy.cpp:212 */ +inline WeaponType GetWeaponType(const char *alias) +{ + int i; + for (i = 0; i < PRIMARY_WEAPON_BUY_COUNT; ++i) + { + if (!Q_stricmp(alias, primaryWeaponBuyInfoCT[i].buyAlias)) + return primaryWeaponBuyInfoCT[i].type; + + if (!Q_stricmp(alias, primaryWeaponBuyInfoT[i].buyAlias)) + return primaryWeaponBuyInfoT[i].type; + } + + for (i = 0; i < SECONDARY_WEAPON_BUY_COUNT; ++i) + { + if (!Q_stricmp(alias, secondaryWeaponBuyInfoCT[i].buyAlias)) + return secondaryWeaponBuyInfoCT[i].type; + + if (!Q_stricmp(alias, secondaryWeaponBuyInfoT[i].buyAlias)) + return secondaryWeaponBuyInfoT[i].type; + } + + return NUM_WEAPON_TYPES; } /* <529753> ../cstrike/dlls/bot/states/cs_bot_buy.cpp:241 */ -NOBODY void BuyState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void BuyState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// bool inBuyZone; // 273 -// class CCSBotManager *ctrl; // 288 -// { -// float const waitToBuyTime; // 257 -// } -// { -// bool isPreferredAllDisallowed; // 295 -// { -// int const maxPrefRetries; // 301 -// int weaponPreference; // 310 -// class CBasePlayerWeapon *weapon; // 313 -// const char *buyAlias; // 328 -// { -// enum WeaponType type; // 338 -// GetWeaponType(const char *alias); // 338 -// } -// GetWeaponPreference(const class BotProfile *const this, -// int i); // 310 -// } -// { -// class BuyInfo *masterPrimary; // 400 -// class BuyInfo *stockPrimary; // 401 -// int stockPrimaryCount; // 402 -// float const sniperRifleChance; // 405 -// bool wantSniper; // 406 -// { -// int i; // 408 -// AllowShotguns(const class CCSBotManager *const this); // 410 -// AllowSubMachineGuns(const class CCSBotManager *const this); // 411 -// AllowRifles(const class CCSBotManager *const this); // 412 -// AllowSnipers(const class CCSBotManager *const this); // 413 -// } -// { -// int which; // 423 -// GetDifficultyLevel(void); // 426 -// { -// int prefCount; // 429 -// { -// int whichPref;// 436 -// } -// } -// } -// } -// { -// int which; // 479 -// } -// { -// float rnd; // 500 -// } -// } -// } + // wait for a Navigation Mesh + if (!TheNavAreaList.size()) + return; + + // apparently we cant buy things in the first few seconds, so wait a bit + if (m_isInitialDelay) + { + const float waitToBuyTime = 2.0f; // 0.25f; + if (gpGlobals->time - me->GetStateTimestamp() < waitToBuyTime) + return; + + m_isInitialDelay = false; + } + + // if we're done buying and still in the freeze period, wait + if (m_doneBuying) + { + if (g_pGameRules->IsMultiplayer() && g_pGameRules->IsFreezePeriod()) + return; + + me->Idle(); + //return; + } + + // is the bot spawned outside of a buy zone? + if (!(me->m_signals.GetState() & SIGNAL_BUY)) + { + m_doneBuying = true; + UTIL_DPrintf("%s bot spawned outside of a buy zone (%d, %d, %d)\n", (me->m_iTeam == CT) ? "CT" : "Terrorist", me->pev->origin.x, me->pev->origin.y, me->pev->origin.z); + return; + } + + CCSBotManager *ctrl = TheCSBots(); + + // try to buy some weapons + const float buyInterval = 0.2f; // 0.02f + if (gpGlobals->time - me->GetStateTimestamp() > buyInterval) + { + me->m_stateTimestamp = gpGlobals->time; + + bool isPreferredAllDisallowed = true; + + // try to buy our preferred weapons first + if (m_prefIndex < me->GetProfile()->GetWeaponPreferenceCount()) + { + // need to retry because sometimes first buy fails?? + const int maxPrefRetries = 2; + if (m_prefRetries >= maxPrefRetries) + { + // try to buy next preferred weapon + ++m_prefIndex; + m_prefRetries = 0; + return; + } + + int weaponPreference = me->GetProfile()->GetWeaponPreference(m_prefIndex); + + // don't buy it again if we still have one from last round + CBasePlayerWeapon *weapon = me->GetActiveWeapon(); + if (weapon != NULL && weapon->m_iId == weaponPreference) + { + // done with buying preferred weapon + m_prefIndex = 9999; + return; + } + + if (me->HasShield() && weaponPreference == WEAPON_SHIELDGUN) + { + // done with buying preferred weapon + m_prefIndex = 9999; + return; + } + + const char *buyAlias = NULL; + + if (weaponPreference == WEAPON_SHIELDGUN) + { + if (ctrl->AllowTacticalShield()) + buyAlias = "shield"; + } + else + { + buyAlias = WeaponIDToAlias(weaponPreference); + WeaponType type = GetWeaponType(buyAlias); + + switch (type) + { + case PISTOL: + if (!ctrl->AllowPistols()) + buyAlias = NULL; + break; + case SHOTGUN: + if (!ctrl->AllowShotguns()) + buyAlias = NULL; + break; + case SUB_MACHINE_GUN: + if (!ctrl->AllowSubMachineGuns()) + buyAlias = NULL; + break; + case RIFLE: + if (!ctrl->AllowRifles()) + buyAlias = NULL; + break; + case MACHINE_GUN: + if (!ctrl->AllowMachineGuns()) + buyAlias = NULL; + break; + case SNIPER_RIFLE: + if (!ctrl->AllowSnipers()) + buyAlias = NULL; + break; + } + } + + if (buyAlias) + { + me->ClientCommand(buyAlias); + me->PrintIfWatched("Tried to buy preferred weapon %s.\n", buyAlias); + + isPreferredAllDisallowed = false; + } + + ++m_prefRetries; + + // bail out so we dont waste money on other equipment + // unless everything we prefer has been disallowed, then buy at random + if (isPreferredAllDisallowed == false) + return; + } + + // if we have no preferred primary weapon (or everything we want is disallowed), buy at random + if (!me->m_bHasPrimary && (isPreferredAllDisallowed || !me->GetProfile()->HasPrimaryPreference())) + { + if (m_buyShield) + { + // buy a shield + me->ClientCommand("shield"); + me->PrintIfWatched("Tried to buy a shield.\n"); + } + else + { + // build list of allowable weapons to buy + BuyInfo *masterPrimary = (me->m_iTeam == TERRORIST) ? primaryWeaponBuyInfoT : primaryWeaponBuyInfoCT; + BuyInfo *stockPrimary[ PRIMARY_WEAPON_BUY_COUNT ]; + int stockPrimaryCount = 0; + + // dont choose sniper rifles as often + const float sniperRifleChance = 50.0f; + bool wantSniper = (RANDOM_FLOAT(0, 100) < sniperRifleChance) ? true : false; + + for (int i = 0; i < PRIMARY_WEAPON_BUY_COUNT; ++i) + { + if ((masterPrimary[i].type == SHOTGUN && ctrl->AllowShotguns()) || + (masterPrimary[i].type == SUB_MACHINE_GUN && ctrl->AllowSubMachineGuns()) || + (masterPrimary[i].type == RIFLE && ctrl->AllowRifles()) || + (masterPrimary[i].type == SNIPER_RIFLE && ctrl->AllowSnipers() && wantSniper) || + (masterPrimary[i].type == MACHINE_GUN && ctrl->AllowMachineGuns())) + { + stockPrimary[ stockPrimaryCount++ ] = &masterPrimary[i]; + } + } + + if (stockPrimaryCount) + { + // buy primary weapon if we don't have one + int which; + + // on hard difficulty levels, bots try to buy preferred weapons on the first pass + if (m_retries == 0 && ctrl->GetDifficultyLevel() >= BOT_HARD) + { + // count up available preferred weapons + int prefCount = 0; + for (which = 0; which < stockPrimaryCount; ++which) + { + if (stockPrimary[which]->preferred) + ++prefCount; + } + + if (prefCount) + { + int whichPref = RANDOM_LONG(0, prefCount - 1); + for (which = 0; which < stockPrimaryCount; ++which) + { + if (stockPrimary[which]->preferred && whichPref-- == 0) + break; + } + } + else + { + // no preferred weapons available, just pick randomly + which = RANDOM_LONG(0, stockPrimaryCount - 1); + } + } + else + { + which = RANDOM_LONG(0, stockPrimaryCount - 1); + } + + me->ClientCommand(stockPrimary[ which ]->buyAlias); + me->PrintIfWatched("Tried to buy %s.\n", stockPrimary[ which ]->buyAlias); + } + } + } + + // If we now have a weapon, or have tried for too long, we're done + if (me->m_bHasPrimary || m_retries++ > 5) + { + // primary ammo + if (me->m_bHasPrimary) + { + me->ClientCommand("primammo"); + } + + // buy armor last, to make sure we bought a weapon first + me->ClientCommand("vesthelm"); + me->ClientCommand("vest"); + + // pistols - if we have no preferred pistol, buy at random + if (ctrl->AllowPistols() && !me->GetProfile()->HasPistolPreference()) + { + if (m_buyPistol) + { + int which = RANDOM_LONG(0, SECONDARY_WEAPON_BUY_COUNT - 1); + + if (me->m_iTeam == TERRORIST) + me->ClientCommand(secondaryWeaponBuyInfoT[ which ].buyAlias); + else + me->ClientCommand(secondaryWeaponBuyInfoCT[ which ].buyAlias); + + // only buy one pistol + m_buyPistol = false; + } + + me->ClientCommand("secammo"); + } + + // buy a grenade if we wish, and we don't already have one + if (m_buyGrenade && !me->HasGrenade()) + { + if (UTIL_IsTeamAllBots(me->m_iTeam)) + { + // only allow Flashbangs if everyone on the team is a bot (dont want to blind our friendly humans) + float rnd = RANDOM_FLOAT(0, 100); + + if (rnd < 10.0f) + { + // smoke grenade + me->ClientCommand("sgren"); + } + else if (rnd < 35.0f) + { + // flashbang + me->ClientCommand("flash"); + } + else + { + // he grenade + me->ClientCommand("hegren"); + } + } + else + { + if (RANDOM_FLOAT(0, 100) < 10.0f) + { + // smoke grenade + me->ClientCommand("sgren"); + } + else + { + // he grenade + me->ClientCommand("hegren"); + } + } + } + + if (m_buyDefuseKit) + { + me->ClientCommand("defuser"); + } + + m_doneBuying = true; + } + } } /* <5296f1> ../cstrike/dlls/bot/states/cs_bot_buy.cpp:529 */ -NOBODY void BuyState::__MAKE_VHOOK(OnExit)(CCSBot *me) +void BuyState::__MAKE_VHOOK(OnExit)(CCSBot *me) { + me->ResetStuckMonitor(); + me->EquipBestWeapon(); } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_defuse_bomb.cpp b/regamedll/dlls/bot/states/cs_bot_defuse_bomb.cpp index 7f2a3f26..413e6cd3 100644 --- a/regamedll/dlls/bot/states/cs_bot_defuse_bomb.cpp +++ b/regamedll/dlls/bot/states/cs_bot_defuse_bomb.cpp @@ -1,30 +1,70 @@ #include "precompiled.h" +// Begin defusing the bomb + /* <539f0e> ../cstrike/dlls/bot/states/cs_bot_defuse_bomb.cpp:16 */ -NOBODY void DefuseBombState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void DefuseBombState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// Say(BotChatterInterface *const this, -// const char *phraseName, -// float lifetime, -// float delay); // 20 + me->Crouch(); + me->SetDisposition(CCSBot::SELF_DEFENSE); + me->GetChatter()->Say("DefusingBomb"); } +// Defuse the bomb + /* <539eac> ../cstrike/dlls/bot/states/cs_bot_defuse_bomb.cpp:27 */ -NOBODY void DefuseBombState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void DefuseBombState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// const Vector *bombPos; // 29 -// class CCSBotManager *ctrl; // 44 -// } + const Vector *bombPos = me->GetGameState()->GetBombPosition(); + CCSBotManager *ctrl = TheCSBots(); + + if (bombPos == NULL) + { + me->PrintIfWatched("In Defuse state, but don't know where the bomb is!\n"); + me->Idle(); + return; + } + + // look at the bomb + me->SetLookAt("Defuse bomb", bombPos, PRIORITY_HIGH); + + // defuse... + me->UseEnvironment(); + + if (gpGlobals->time - me->GetStateTimestamp() > 1.0f) + { + // if we missed starting the defuse, give up + if (ctrl->GetBombDefuser() == NULL) + { + me->PrintIfWatched("Failed to start defuse, giving up\n"); + me->Idle(); + return; + } + else if (ctrl->GetBombDefuser() != me) + { + // if someone else got the defuse, give up + me->PrintIfWatched("Someone else started defusing, giving up\n"); + me->Idle(); + return; + } + } + + // if bomb has been defused, give up + if (!ctrl->IsBombPlanted()) + { + me->Idle(); + return; + } } /* <539e36> ../cstrike/dlls/bot/states/cs_bot_defuse_bomb.cpp:73 */ -NOBODY void DefuseBombState::__MAKE_VHOOK(OnExit)(CCSBot *me) +void DefuseBombState::__MAKE_VHOOK(OnExit)(CCSBot *me) { -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 77 -// ClearLookAt(CCSBot *const this); // 79 + me->StandUp(); + me->ResetStuckMonitor(); + me->SetTask(CCSBot::SEEK_AND_DESTROY); + me->SetDisposition(CCSBot::ENGAGE_AND_INVESTIGATE); + me->ClearLookAt(); } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_escape_from_bomb.cpp b/regamedll/dlls/bot/states/cs_bot_escape_from_bomb.cpp index b55b5cbe..9e42dcf8 100644 --- a/regamedll/dlls/bot/states/cs_bot_escape_from_bomb.cpp +++ b/regamedll/dlls/bot/states/cs_bot_escape_from_bomb.cpp @@ -1,28 +1,49 @@ #include "precompiled.h" /* <5499ae> ../cstrike/dlls/bot/states/cs_bot_escape_from_bomb.cpp:16 */ -NOBODY void EscapeFromBombState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void EscapeFromBombState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// DestroyPath(CCSBot *const this); // 20 + me->StandUp(); + me->Run(); + me->DestroyPath(); + me->EquipKnife(); } +// Escape from the bomb + /* <549be9> ../cstrike/dlls/bot/states/cs_bot_escape_from_bomb.cpp:28 */ -NOBODY void EscapeFromBombState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void EscapeFromBombState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// const Vector *bombPos; // 30 -// { -// class FarAwayFromPositionFunctor func; // 48 -// class CNavArea *goalArea; // 49 -// FarAwayFromPositionFunctor(FarAwayFromPositionFunctor *const this, -// const Vector *pos); // 48 -// } -// } + const Vector *bombPos = me->GetGameState()->GetBombPosition(); + + // if we don't know where the bomb is, we shouldn't be in this state + if (bombPos == NULL) + { + me->Idle(); + return; + } + + // grab our knife to move quickly + me->EquipKnife(); + + // look around + me->UpdateLookAround(); + + if (me->UpdatePathMovement() != CCSBot::PROGRESSING) + { + // we have no path, or reached the end of one - create a new path far away from the bomb + FarAwayFromPositionFunctor func(bombPos); + CNavArea *goalArea = FindMinimumCostArea(me->GetLastKnownArea(), func); + + // if this fails, we'll try again next time + me->ComputePath(goalArea, NULL, FASTEST_ROUTE); + } } /* <549976> ../cstrike/dlls/bot/states/cs_bot_escape_from_bomb.cpp:60 */ -NOBODY void EscapeFromBombState::__MAKE_VHOOK(OnExit)(CCSBot *me) +void EscapeFromBombState::__MAKE_VHOOK(OnExit)(CCSBot *me) { + me->EquipBestWeapon(); } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_fetch_bomb.cpp b/regamedll/dlls/bot/states/cs_bot_fetch_bomb.cpp index 32324115..dea1ef03 100644 --- a/regamedll/dlls/bot/states/cs_bot_fetch_bomb.cpp +++ b/regamedll/dlls/bot/states/cs_bot_fetch_bomb.cpp @@ -1,19 +1,54 @@ #include "precompiled.h" +// Move to the bomb on the floor and pick it up + /* <5587b3> ../cstrike/dlls/bot/states/cs_bot_fetch_bomb.cpp:17 */ -NOBODY void FetchBombState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void FetchBombState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// DestroyPath(CCSBot *const this); // 19 + me->DestroyPath(); } +// Move to the bomb on the floor and pick it up + /* <5587fa> ../cstrike/dlls/bot/states/cs_bot_fetch_bomb.cpp:26 */ -NOBODY void FetchBombState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void FetchBombState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// class CCSBotManager *ctrl; // 28 -// class CBaseEntity *bomb; // 30 -// GetLooseBomb(CCSBotManager *const this); // 30 -// } + if (me->IsCarryingBomb()) + { + me->PrintIfWatched( "I picked up the bomb\n" ); + me->Idle(); + return; + } + + CBaseEntity *bomb = TheCSBots()->GetLooseBomb(); + if (bomb != NULL) + { + if (!me->HasPath()) + { + // build a path to the bomb + if (me->ComputePath(TheNavAreaGrid.GetNavArea(&bomb->pev->origin), &bomb->pev->origin, SAFEST_ROUTE) == false) + { + me->PrintIfWatched("Fetch bomb pathfind failed\n"); + + // go Hunt instead of Idle to prevent continuous re-pathing to inaccessible bomb + me->Hunt(); + //return; + } + } + } + else + { + // someone picked up the bomb + me->PrintIfWatched("Bomb not loose\n"); + me->Idle(); + return; + } + + // look around + me->UpdateLookAround(); + + if (me->UpdatePathMovement() != CCSBot::PROGRESSING) + me->Idle(); } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_follow.cpp b/regamedll/dlls/bot/states/cs_bot_follow.cpp index f337fa37..bdfb1b89 100644 --- a/regamedll/dlls/bot/states/cs_bot_follow.cpp +++ b/regamedll/dlls/bot/states/cs_bot_follow.cpp @@ -1,105 +1,269 @@ #include "precompiled.h" +// Follow our leader + /* <56918b> ../cstrike/dlls/bot/states/cs_bot_follow.cpp:16 */ -NOBODY void FollowState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void FollowState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// DestroyPath(CCSBot *const this); // 20 -// Invalidate(CountdownTimer *const this); // 33 -// Invalidate(IntervalTimer *const this); // 37 -// Start(CountdownTimer *const this, -// float duration); // 41 + me->StandUp(); + me->Run(); + me->DestroyPath(); + + m_isStopped = false; + m_stoppedTimestamp = 0.0f; + + // to force immediate repath + m_lastLeaderPos.x = -99999999.9f; + m_lastLeaderPos.y = -99999999.9f; + m_lastLeaderPos.z = -99999999.9f; + + m_lastSawLeaderTime = 0; + + // set re-pathing frequency + m_repathInterval.Invalidate(); + + m_isSneaking = false; + + m_walkTime.Invalidate(); + m_isAtWalkSpeed = false; + + m_leaderMotionState = INVALID; + m_idleTimer.Start(RANDOM_FLOAT(2.0f, 5.0f)); } +// Determine the leader's motion state by tracking his speed + /* <569268> ../cstrike/dlls/bot/states/cs_bot_follow.cpp:48 */ -NOBODY void FollowState::ComputeLeaderMotionState(float leaderSpeed) +void FollowState::ComputeLeaderMotionState(float leaderSpeed) { -// { -// float const runWalkThreshold; // 51 -// float const walkStopThreshold; // 52 -// enum LeaderMotionStateType prevState; // 53 -// { -// float const minWalkTime; // 68 -// GetElapsedTime(const class IntervalTimer *const this); // 69 -// Start(IntervalTimer *const this); // 64 -// } -// Start(IntervalTimer *const this); // 83 -// } + // walk = 130, run = 250 + const float runWalkThreshold = 140.0f; + const float walkStopThreshold = 10.0f; + LeaderMotionStateType prevState = m_leaderMotionState; + if (leaderSpeed > runWalkThreshold) + { + m_leaderMotionState = RUNNING; + m_isAtWalkSpeed = false; + } + else if (leaderSpeed > walkStopThreshold) + { + // track when began to walk + if (!m_isAtWalkSpeed) + { + m_walkTime.Start(); + m_isAtWalkSpeed = true; + } + + const float minWalkTime = 0.25f; + if (m_walkTime.GetElapsedTime() > minWalkTime) + { + m_leaderMotionState = WALKING; + } + } + else + { + m_leaderMotionState = STOPPED; + m_isAtWalkSpeed = false; + } + + // track time spent in this motion state + if (prevState != m_leaderMotionState) + { + m_leaderMotionStateTime.Start(); + m_waitTime = RANDOM_FLOAT(1.0f, 3.0f); + } } +// Follow our leader +// TODO: Clean up this nasty mess + /* <569368> ../cstrike/dlls/bot/states/cs_bot_follow.cpp:164 */ -NOBODY void FollowState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void FollowState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// float leaderSpeed; // 194 -// bool isLeaderVisible; // 200 -// float const farAwayRange; // 213 -// float const longTime; // 231 -// bool repath; // 241 -// float const nearLeaderRange; // 244 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 177 -// IsNotMoving(const class CCSBot *const this); // 190 -// Length(const class Vector2D *const this); // 194 -// operator-(const Vector *const this, -// const Vector &v); // 214 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 214 -// GetElapsedTime(const class IntervalTimer *const this); // 245 -// operator-(const Vector *const this, -// const Vector &v); // 251 -// IsLengthLessThan(const Vector *const this, -// float length); // 251 -// { -// float const hideRange; // 253 -// } -// IsElapsed(const class CountdownTimer *const this); // 263 -// DestroyPath(CCSBot *const this); // 280 -// IsElapsed(const class CountdownTimer *const this); // 284 -// { -// float const runSpeed; // 291 -// float const collectRange; // 293 -// class FollowTargetCollector collector; // 294 -// FollowTargetCollector(FollowTargetCollector *const this, -// class CBasePlayer *player); // 294 -// SearchSurroundingAreas(CNavArea *startArea, -// const Vector *startPos, -// class FollowTargetCollector &func, -// float maxRange); // 295 -// { -// int i; // 299 -// } -// { -// class CNavArea *target; // 306 -// Vector targetPos; // 307 -// IsElapsed(const class CountdownTimer *const this); // 310 -// { -// class CNavArea *area; // 321 -// float closeRangeSq; // 322 -// Vector close; // 323 -// { -// int a; // 325 -// { -// float rangeSq;// 331 -// operator-(const Vector *const this, -// const Vector &v); // 331 -// LengthSquared(const Vector *const this); // 331 -// } -// } -// } -// Start(CountdownTimer *const this, -// float duration); // 345 -// Reset(CountdownTimer *const this); // 347 -// } -// } -// Start(CountdownTimer *const this, -// float duration); // 191 -// } + // if we lost our leader, give up + if (m_leader == NULL || !m_leader->IsAlive()) + { + me->Idle(); + return; + } + + // if we are carrying the bomb and at a bombsite, plant + if (me->IsCarryingBomb() && me->IsAtBombsite()) + { + // plant it + me->SetTask(CCSBot::PLANT_BOMB); + me->PlantBomb(); + + // radio to the team + me->GetChatter()->PlantingTheBomb(me->GetPlace()); + return; + } + + // look around + me->UpdateLookAround(); + + // if we are moving, we are not idle + if (me->IsNotMoving() == false) + m_idleTimer.Start(RANDOM_FLOAT(2.0f, 5.0f)); + + // compute the leader's speed + float leaderSpeed = Vector2D(m_leader->pev->velocity.x, m_leader->pev->velocity.y).Length(); + + // determine our leader's movement state + ComputeLeaderMotionState(leaderSpeed); + + // track whether we can see the leader + bool isLeaderVisible; + if (me->IsVisible(&m_leader->pev->origin)) + { + m_lastSawLeaderTime = gpGlobals->time; + isLeaderVisible = true; + } + else + { + isLeaderVisible = false; + } + + // determine whether we should sneak or not + const float farAwayRange = 750.0f; + if ((m_leader->pev->origin - me->pev->origin).IsLengthGreaterThan(farAwayRange)) + { + // far away from leader - run to catch up + m_isSneaking = false; + } + else if (isLeaderVisible) + { + // if we see leader walking and we are nearby, walk + if (m_leaderMotionState == WALKING) + m_isSneaking = true; + + // if we are sneaking and our leader starts running, stop sneaking + if (m_isSneaking && m_leaderMotionState == RUNNING) + m_isSneaking = false; + } + + // if we haven't seen the leader for a long time, run + const float longTime = 20.0f; + if (gpGlobals->time - m_lastSawLeaderTime > longTime) + m_isSneaking = false; + + if (m_isSneaking) + me->Walk(); + else + me->Run(); + + bool repath = false; + + // if the leader has stopped, hide nearby + const float nearLeaderRange = 250.0f; + if (!me->HasPath() && m_leaderMotionState == STOPPED && m_leaderMotionStateTime.GetElapsedTime() > m_waitTime) + { + // throttle how often this check occurs + m_waitTime += RANDOM_FLOAT(1.0f, 3.0f); + + // the leader has stopped - if we are close to him, take up a hiding spot + if ((m_leader->pev->origin - me->pev->origin).IsLengthLessThan(nearLeaderRange)) + { + const float hideRange = 250.0f; + if (me->TryToHide(NULL, -1.0f, hideRange, false, USE_NEAREST)) + { + me->ResetStuckMonitor(); + return; + } + } + } + + // if we have been idle for awhile, move + if (m_idleTimer.IsElapsed()) + { + repath = true; + + // always walk when we move such a short distance + m_isSneaking = true; + } + + // if our leader has moved, repath (don't repath if leading is stopping) + if (leaderSpeed > 100.0f && m_leaderMotionState != STOPPED) + { + repath = true; + } + + // move along our path + if (me->UpdatePathMovement(NO_SPEED_CHANGE) != CCSBot::PROGRESSING) + { + me->DestroyPath(); + } + + // recompute our path if necessary + if (repath && m_repathInterval.IsElapsed()) + { + // recompute our path to keep us near our leader + m_lastLeaderPos = m_leader->pev->origin; + + me->ResetStuckMonitor(); + + const float runSpeed = 200.0f; + const float collectRange = (leaderSpeed > runSpeed) ? 600.0f : 400.0f; + FollowTargetCollector collector(m_leader); + SearchSurroundingAreas(TheNavAreaGrid.GetNearestNavArea(&m_lastLeaderPos), &m_lastLeaderPos, collector, collectRange); + + if (cv_bot_debug.value > 0.0f) + { + for (int i = 0; i < collector.m_targetAreaCount; ++i) + collector.m_targetArea[i]->Draw(255, 0, 0, 2); + } + + // move to one of the collected areas + if (collector.m_targetAreaCount) + { + CNavArea *target = NULL; + Vector targetPos; + + // if we are idle, pick a random area + if (m_idleTimer.IsElapsed()) + { + target = collector.m_targetArea[ RANDOM_LONG(0, collector.m_targetAreaCount - 1) ]; + targetPos = *target->GetCenter(); + me->PrintIfWatched("%4.1f: Bored. Repathing to a new nearby area\n", gpGlobals->time); + } + else + { + me->PrintIfWatched("%4.1f: Repathing to stay with leader.\n", gpGlobals->time); + + // find closest area to where we are + CNavArea *area; + float closeRangeSq = 9999999999.9f; + Vector close; + + for (int a = 0; a < collector.m_targetAreaCount; ++a) + { + area = collector.m_targetArea[a]; + area->GetClosestPointOnArea(&me->pev->origin, &close); + + float_precision rangeSq = (me->pev->origin - close).LengthSquared(); + if (rangeSq < closeRangeSq) + { + target = area; + targetPos = close; + closeRangeSq = rangeSq; + } + } + } + + if (me->ComputePath(target, NULL, FASTEST_ROUTE) == NULL) + me->PrintIfWatched("Pathfind to leader failed.\n"); + + // throttle how often we repath + m_repathInterval.Start(0.5f); + m_idleTimer.Reset(); + } + } } /* <569231> ../cstrike/dlls/bot/states/cs_bot_follow.cpp:353 */ -NOBODY void FollowState::__MAKE_VHOOK(OnExit)(CCSBot *me) +void FollowState::__MAKE_VHOOK(OnExit)(CCSBot *me) { + ; } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_hide.cpp b/regamedll/dlls/bot/states/cs_bot_hide.cpp index c1641ded..14a3e892 100644 --- a/regamedll/dlls/bot/states/cs_bot_hide.cpp +++ b/regamedll/dlls/bot/states/cs_bot_hide.cpp @@ -1,122 +1,439 @@ #include "precompiled.h" +// Begin moving to a nearby hidey-hole. +// NOTE: Do not forget this state may include a very long "move-to" time to get to our hidey spot! + /* <57c261> ../cstrike/dlls/bot/states/cs_bot_hide.cpp:22 */ -NOBODY void HideState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void HideState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// GetFollowLeader(CCSBot *const this); // 50 + m_isAtSpot = false; + + // if duration is "infinite", set it to a reasonably long time to prevent infinite camping + if (m_duration < 0.0f) + { + m_duration = RANDOM_FLOAT(30.0f, 60.0f); + } + + // decide whether to "ambush" or not - never set to false so as not to override external setting + if (RANDOM_FLOAT(0.0f, 100.0f) < 50.0f) + { + m_isHoldingPosition = true; + } + + // if we are holding position, decide for how long + if (m_isHoldingPosition) + { + m_holdPositionTime = RANDOM_FLOAT(3.0f, 10.0f); + } + else + { + m_holdPositionTime = 0.0f; + } + + m_heardEnemy = false; + m_firstHeardEnemyTime = 0.0f; + m_retry = 0; + + if (me->IsFollowing()) + { + m_leaderAnchorPos = me->GetFollowLeader()->pev->origin; + } } +// Move to a nearby hidey-hole. +// NOTE: Do not forget this state may include a very long "move-to" time to get to our hidey spot! + /* <57c35e> ../cstrike/dlls/bot/states/cs_bot_hide.cpp:59 */ -NOBODY void HideState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void HideState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// class CCSBotManager *ctrl; // 61 -// IsActiveWeaponReloading(const class CBot *const this); // 64 -// { -// bool isSettledInSniper; // 241 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 94 -// { -// const class Zone *zone; // 78 -// { -// class CNavArea *area; // 81 -// } -// } -// { -// class CBasePlayer *leader; // 109 -// float runThreshold; // 111 -// float const followRange; // 120 -// GetFollowLeader(CCSBot *const this); // 109 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 112 -// operator-(const Vector *const this, -// const Vector &v); // 121 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 121 -// } -// { -// Vector toDefuser; // 184 -// float const hearDefuseRange; // 186 -// operator-(const Vector *const this, -// const Vector &v); // 184 -// IsLengthLessThan(const Vector *const this, -// float length); // 187 -// } -// GetLooseBomb(CCSBotManager *const this); // 157 -// { -// class CBaseEntity *hostage; // 222 -// { -// class CNavArea *area; // 226 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 229 -// } -// } -// IsActiveWeaponReloading(const class CBot *const this); // 245 -// } -// { -// float range; // 343 -// class CBasePlayer *camper; // 344 -// float const closeRange; // 346 -// Vector toSpot; // 367 -// float dist; // 371 -// float const crouchDist; // 373 -// float const atDist; // 377 -// { -// const Vector *pos; // 422 -// GetFeetZ(const class CCSBot *const this); // 431 -// } -// { -// int const maxRetries; // 352 -// } -// GetFeetZ(const class CCSBot *const this); // 370 -// Length(const Vector *const this); // 371 -// { -// TraceResult result; // 397 -// float outAngle; // 398 -// float outAngleRange; // 399 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 394 -// { -// float angle; // 400 -// GetEyePosition(const class CCSBot *const this); // 402 -// operator*(float fl, -// const Vector &v); // 402 -// operator+(const Vector *const this, -// const Vector &v); // 402 -// GetEyePosition(const class CCSBot *const this); // 402 -// } -// SetLookAheadAngle(CCSBot *const this, -// float angle); // 411 -// } -// } -// { -// float const hurtRecentlyTime; // 294 -// GetNearbyEnemyCount(const class CCSBot *const this); // 310 -// { -// float const someTime; // 312 -// float const littleTime; // 313 -// } -// GetNearbyEnemyCount(const class CCSBot *const this); // 326 -// { -// class CHostage *hostage; // 328 -// } -// GetTimeSinceAttacked(const class CCSBot *const this); // 295 -// IsProtectedByShield(CBasePlayer *const this); // 290 -// } -// } + CCSBotManager *ctrl = TheCSBots(); + + // wait until finished reloading to leave hide state + if (!me->IsActiveWeaponReloading()) + { + if (gpGlobals->time - me->GetStateTimestamp() > m_duration) + { + if (me->GetTask() == CCSBot::GUARD_LOOSE_BOMB) + { + // if we're guarding the loose bomb, continue to guard it but pick a new spot + me->Hide(ctrl->GetLooseBombArea()); + return; + } + else if (me->GetTask() == CCSBot::GUARD_BOMB_ZONE) + { + // if we're guarding a bombsite, continue to guard it but pick a new spot + const CCSBotManager::Zone *zone = ctrl->GetClosestZone(&me->pev->origin); + if (zone != NULL) + { + CNavArea *area = ctrl->GetRandomAreaInZone(zone); + if (area != NULL) + { + me->Hide(area); + return; + } + } + } + else if (me->GetTask() == CCSBot::GUARD_HOSTAGE_RESCUE_ZONE) + { + // if we're guarding a rescue zone, continue to guard this or another rescue zone + if (me->GuardRandomZone()) + { + me->SetTask(CCSBot::GUARD_HOSTAGE_RESCUE_ZONE); + me->PrintIfWatched("Continuing to guard hostage rescue zones\n"); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + me->GetChatter()->GuardingHostageEscapeZone(IS_PLAN); + return; + } + } + + me->Idle(); + return; + } + + // if we are momentarily hiding while following someone, check to see if he has moved on + if (me->IsFollowing()) + { + CBasePlayer *leader = me->GetFollowLeader(); + + // BOTPORT: Determine walk/run velocity thresholds + float runThreshold = 200.0f; + if (leader->pev->velocity.IsLengthGreaterThan(runThreshold)) + { + // leader is running, stay with him + me->Follow(leader); + return; + } + + // if leader has moved, stay with him + const float followRange = 250.0f; + if ((m_leaderAnchorPos - leader->pev->origin).IsLengthGreaterThan(followRange)) + { + me->Follow(leader); + return; + } + } + + // if we see a nearby buddy in combat, join him + // TODO: Perhaps tie in to TakeDamage(), so it works for human players, too + + // Scenario logic + switch (ctrl->GetScenario()) + { + case CCSBotManager::SCENARIO_DEFUSE_BOMB: + { + if (me->m_iTeam == CT) + { + // if we are just holding position (due to a radio order) and the bomb has just planted, go defuse it + if (me->GetTask() == CCSBot::HOLD_POSITION && + ctrl->IsBombPlanted() && + ctrl->GetBombPlantTimestamp() > me->GetStateTimestamp()) + { + me->Idle(); + return; + } + + // if we are guarding the defuser and he dies/gives up, stop hiding (to choose another defuser) + if (me->GetTask() == CCSBot::GUARD_BOMB_DEFUSER && ctrl->GetBombDefuser() == NULL) + { + me->Idle(); + return; + } + + // if we are guarding the loose bomb and it is picked up, stop hiding + if (me->GetTask() == CCSBot::GUARD_LOOSE_BOMB && ctrl->GetLooseBomb() == NULL) + { + me->GetChatter()->TheyPickedUpTheBomb(); + me->Idle(); + return; + } + + // if we are guarding a bombsite and the bomb is dropped and we hear about it, stop guarding + if (me->GetTask() == CCSBot::GUARD_BOMB_ZONE && me->GetGameState()->IsLooseBombLocationKnown()) + { + me->Idle(); + return; + } + + // if we are guarding (bombsite, initial encounter, etc) and the bomb is planted, go defuse it + if (me->IsDoingScenario() && me->GetTask() == CCSBot::GUARD_BOMB_ZONE && ctrl->IsBombPlanted()) + { + me->Idle(); + return; + } + + } + // TERRORIST + else + { + // if we are near the ticking bomb and someone starts defusing it, attack! + if (ctrl->GetBombDefuser()) + { + Vector toDefuser = ctrl->GetBombDefuser()->pev->origin; + const float hearDefuseRange = 2000.0f; + if ((toDefuser - me->pev->origin).IsLengthLessThan(hearDefuseRange)) + { + // if we are nearby, attack, otherwise move to the bomb (which will cause us to attack when we see defuser) + if (me->CanSeePlantedBomb()) + { + me->Attack(ctrl->GetBombDefuser()); + } + else + { + me->MoveTo(&toDefuser, FASTEST_ROUTE); + me->InhibitLookAround(10.0f); + } + + return; + } + } + } + break; + } + case CCSBotManager::SCENARIO_RESCUE_HOSTAGES: + { + // if we're guarding the hostages and they all die or are taken, do something else + if (me->GetTask() == CCSBot::GUARD_HOSTAGES) + { + if (me->GetGameState()->AreAllHostagesBeingRescued() || me->GetGameState()->AreAllHostagesGone()) + { + me->Idle(); + return; + } + } + else if (me->GetTask() == CCSBot::GUARD_HOSTAGE_RESCUE_ZONE) + { + // if we stumble across a hostage, guard it + CHostage *hostage = me->GetGameState()->GetNearestVisibleFreeHostage(); + if (hostage != NULL) + { + // we see a free hostage, guard it + CNavArea *area = TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin); + if (area != NULL) + { + me->SetTask(CCSBot::GUARD_HOSTAGES); + me->Hide(area); + me->PrintIfWatched("I'm guarding hostages I found\n"); + // don't chatter here - he'll tell us when he's in his hiding spot + return; + } + } + } + } + } + + bool isSettledInSniper = (me->IsSniper() && m_isAtSpot) ? true : false; + + // only investigate noises if we are initiating attacks, and we aren't a "settled in" sniper + // dont investigate noises if we are reloading + if (!me->IsActiveWeaponReloading() && + !isSettledInSniper && + me->GetDisposition() == CCSBot::ENGAGE_AND_INVESTIGATE) + { + // if we are holding position, and have heard the enemy nearby, investigate after our hold time is up + if (m_isHoldingPosition && m_heardEnemy && (gpGlobals->time - m_firstHeardEnemyTime > m_holdPositionTime)) + { + // TODO: We might need to remember specific location of last enemy noise here + me->InvestigateNoise(); + return; + } + + // investigate nearby enemy noises + if (me->ShouldInvestigateNoise()) + { + // if we are holding position, check if enough time has elapsed since we first heard the enemy + if (m_isAtSpot && m_isHoldingPosition) + { + if (!m_heardEnemy) + { + // first time we heard the enemy + m_heardEnemy = true; + m_firstHeardEnemyTime = gpGlobals->time; + me->PrintIfWatched("Heard enemy, holding position for %f2.1 seconds...\n", m_holdPositionTime); + } + } + else + { + // not holding position - investigate enemy noise + me->InvestigateNoise(); + return; + } + } + } + } + + // look around + me->UpdateLookAround(); + + // if we are at our hiding spot, crouch and wait + if (m_isAtSpot) + { + me->Crouch(); + + // if we have a shield, hide behind it + if (me->HasShield() && !me->IsProtectedByShield()) + me->SecondaryAttack(); + + // while sitting at our hiding spot, if we are being attacked but can't see our attacker, move somewhere else + const float hurtRecentlyTime = 1.0f; + if (!me->IsEnemyVisible() && me->GetTimeSinceAttacked() < hurtRecentlyTime) + { + me->Idle(); + return; + } + + // encourage the human player + if (!me->IsDoingScenario()) + { + if (me->m_iTeam == CT) + { + if (me->GetTask() == CCSBot::GUARD_BOMB_ZONE && me->IsAtHidingSpot() && ctrl->IsBombPlanted()) + { + if (me->GetNearbyEnemyCount() == 0) + { + const float someTime = 30.0f; + const float littleTime = 11.0; + + if (ctrl->GetBombTimeLeft() > someTime) + me->GetChatter()->Encourage("BombsiteSecure", RANDOM_FLOAT(10.0f, 15.0f)); + else if (ctrl->GetBombTimeLeft() > littleTime) + me->GetChatter()->Encourage("WaitingForHumanToDefuseBomb", RANDOM_FLOAT(5.0f, 8.0f)); + else + me->GetChatter()->Encourage("WaitingForHumanToDefuseBombPanic", RANDOM_FLOAT(3.0f, 4.0f)); + } + } + + if (me->GetTask() == CCSBot::GUARD_HOSTAGES && me->IsAtHidingSpot()) + { + if (me->GetNearbyEnemyCount() == 0) + { + CHostage *hostage = me->GetGameState()->GetNearestVisibleFreeHostage(); + if (hostage != NULL) + { + me->GetChatter()->Encourage("WaitingForHumanToRescueHostages", RANDOM_FLOAT(10.0f, 15.0f)); + } + } + } + } + } + } + else + { + // if a Player is using this hiding spot, give up + float range; + CBasePlayer *camper = UTIL_GetClosestPlayer(&m_hidingSpot, &range); + + const float closeRange = 75.0f; + if (camper != NULL && camper != me && range < closeRange && me->IsVisible(camper, CHECK_FOV)) + { + // player is in our hiding spot + me->PrintIfWatched("Someone's in my hiding spot - picking another...\n"); + + const int maxRetries = 3; + if (m_retry++ >= maxRetries) + { + me->PrintIfWatched("Can't find a free hiding spot, giving up.\n"); + me->Idle(); + return; + } + + // pick another hiding spot near where we were planning on hiding + me->Hide(TheNavAreaGrid.GetNavArea(&m_hidingSpot)); + return; + } + + Vector toSpot; + toSpot.x = m_hidingSpot.x - me->pev->origin.x; + toSpot.y = m_hidingSpot.y - me->pev->origin.y; + toSpot.z = m_hidingSpot.z - me->GetFeetZ(); // use feet location + float dist = toSpot.Length(); + + const float crouchDist = 200.0f; + if (dist < crouchDist) + me->Crouch(); + + const float atDist = 20.0f; + if (dist < atDist) + { + m_isAtSpot = true; + + // make sure our approach points are valid, since we'll be watching them + me->ComputeApproachPoints(); + + // ready our weapon and prepare to attack + me->EquipBestWeapon(MUST_EQUIP); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + + // if we are a sniper, update our task + if (me->GetTask() == CCSBot::MOVE_TO_SNIPER_SPOT) + { + me->SetTask(CCSBot::SNIPING); + } + + // determine which way to look + TraceResult result; + float outAngle = 0.0f; + float outAngleRange = 0.0f; + for (float angle = 0.0f; angle < 360.0f; angle += 45.0f) + { + UTIL_TraceLine(me->GetEyePosition(), me->GetEyePosition() + 1000.0f * Vector(BotCOS(angle), BotSIN(angle), 0.0f), ignore_monsters, ignore_glass, ENT(me->pev), &result); + + if (result.flFraction > outAngleRange) + { + outAngle = angle; + outAngleRange = result.flFraction; + } + } + + me->SetLookAheadAngle(outAngle); + } + + // move to hiding spot + if (me->UpdatePathMovement() != CCSBot::PROGRESSING && !m_isAtSpot) + { + // we couldn't get to our hiding spot - pick another + me->PrintIfWatched("Can't get to my hiding spot - finding another...\n"); + + // search from hiding spot, since we know it was valid + const Vector *pos = FindNearbyHidingSpot(me, &m_hidingSpot, m_searchFromArea, m_range, me->IsSniper()); + if (pos == NULL) + { + // no available hiding spots + me->PrintIfWatched("No available hiding spots - hiding where I'm at.\n"); + + // hide where we are + m_hidingSpot.x = me->pev->origin.x; + m_hidingSpot.x = me->pev->origin.y; + m_hidingSpot.z = me->GetFeetZ(); + } + else + { + m_hidingSpot = *pos; + } + + // build a path to our new hiding spot + if (me->ComputePath(TheNavAreaGrid.GetNavArea(&m_hidingSpot), &m_hidingSpot, FASTEST_ROUTE) == false) + { + me->PrintIfWatched("Can't pathfind to hiding spot\n"); + me->Idle(); + return; + } + } + } } /* <57c2c8> ../cstrike/dlls/bot/states/cs_bot_hide.cpp:450 */ -NOBODY void HideState::__MAKE_VHOOK(OnExit)(CCSBot *me) +void HideState::__MAKE_VHOOK(OnExit)(CCSBot *me) { -// ClearLookAt(CCSBot *const this); // 456 -// ClearApproachPoints(CCSBot *const this); // 457 -// IsProtectedByShield(CBasePlayer *const this); // 460 -// OnExit(HideState *const this, -// class CCSBot *me); // 450 + m_isHoldingPosition = false; + + me->StandUp(); + me->ResetStuckMonitor(); + me->ClearLookAt(); + me->ClearApproachPoints(); + + // if we have a shield, put it away + if (me->HasShield() && me->IsProtectedByShield()) + me->SecondaryAttack(); } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_hunt.cpp b/regamedll/dlls/bot/states/cs_bot_hunt.cpp index 8d6ff436..82dba24f 100644 --- a/regamedll/dlls/bot/states/cs_bot_hunt.cpp +++ b/regamedll/dlls/bot/states/cs_bot_hunt.cpp @@ -1,65 +1,204 @@ #include "precompiled.h" +// Begin the hunt + /* <58e6e0> ../cstrike/dlls/bot/states/cs_bot_hunt.cpp:18 */ -NOBODY void HuntState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void HuntState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 29 -// DestroyPath(CCSBot *const this); // 31 + // lurking death + if (me->IsUsingKnife() && me->IsWellPastSafe() && !me->IsHurrying()) + me->Walk(); + else + me->Run(); + + me->StandUp(); + me->SetDisposition(CCSBot::ENGAGE_AND_INVESTIGATE); + me->SetTask(CCSBot::SEEK_AND_DESTROY); + me->DestroyPath(); } +// Hunt down our enemies + /* <58e452> ../cstrike/dlls/bot/states/cs_bot_hunt.cpp:38 */ -NOBODY void HuntState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void HuntState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// class CCSBotManager *ctrl; // 40 -// float const huntingTooLongTime; // 44 -// { -// class CHostage *hostage; // 129 -// { -// class CNavArea *area; // 132 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 136 -// } -// } -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 118 -// { -// float const safeTime; // 62 -// } -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 82 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 92 -// { -// float oldest; // 163 -// int areaCount; // 165 -// float const minSize; // 166 -// iterator iter; // 167 -// int which; // 189 -// { -// class CNavArea *area; // 170 -// const class Extent *extent; // 175 -// float age; // 180 -// GetClearedTimestamp(CNavArea *const this, -// int teamID); // 180 -// } -// operator++(_List_iterator *const this); // 168 -// operator++(_List_iterator *const this); // 192 -// } -// SetRogue(CCSBot *const this, -// bool rogue); // 49 -// } + // if we've been hunting for a long time, drop into Idle for a moment to + // select something else to do + const float huntingTooLongTime = 30.0f; + if (gpGlobals->time - me->GetStateTimestamp() > huntingTooLongTime) + { + // stop being a rogue and do the scenario, since there must not be many enemies left to hunt + me->PrintIfWatched("Giving up hunting, and being a rogue\n"); + me->SetRogue(false); + me->Idle(); + return; + } + + CCSBotManager *ctrl = TheCSBots(); + + // scenario logic + if (ctrl->GetScenario() == CCSBotManager::SCENARIO_DEFUSE_BOMB) + { + if (me->m_iTeam == TERRORIST) + { + // if we have the bomb and it's time to plant, or we happen to be in a bombsite and it seems safe, do it + if (me->IsCarryingBomb()) + { + const float safeTime = 3.0f; + if (ctrl->IsTimeToPlantBomb() || (me->IsAtBombsite() && gpGlobals->time - me->GetLastSawEnemyTimestamp() > safeTime)) + { + me->Idle(); + return; + } + } + + // if we notice the bomb lying on the ground, go get it + if (me->NoticeLooseBomb()) + { + me->FetchBomb(); + return; + } + + // if bomb has been planted, and we hear it, move to a hiding spot near the bomb and watch it + const Vector *bombPos = me->GetGameState()->GetBombPosition(); + if (!me->IsRogue() && me->GetGameState()->IsBombPlanted() && bombPos != NULL) + { + me->SetTask(CCSBot::GUARD_TICKING_BOMB); + me->Hide(TheNavAreaGrid.GetNavArea(bombPos)); + return; + } + } + // CT + else + { + if (!me->IsRogue() && me->CanSeeLooseBomb()) + { + // if we are near the loose bomb and can see it, hide nearby and guard it + me->SetTask(CCSBot::GUARD_LOOSE_BOMB); + me->Hide(ctrl->GetLooseBombArea()); + me->GetChatter()->AnnouncePlan("GoingToGuardLooseBomb", ctrl->GetLooseBombArea()->GetPlace()); + return; + } + else if (ctrl->IsBombPlanted()) + { + // rogues will defuse a bomb, but not guard the defuser + if (!me->IsRogue() || !ctrl->GetBombDefuser()) + { + // search for the planted bomb to defuse + me->Idle(); + return; + } + } + } + } + else if (ctrl->GetScenario() == CCSBotManager::SCENARIO_RESCUE_HOSTAGES) + { + if (me->m_iTeam == TERRORIST) + { + if (me->GetGameState()->AreAllHostagesBeingRescued()) + { + // all hostages are being rescued, head them off at the escape zones + if (me->GuardRandomZone()) + { + me->SetTask(CCSBot::GUARD_HOSTAGE_RESCUE_ZONE); + me->PrintIfWatched("Trying to beat them to an escape zone!\n"); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + me->GetChatter()->GuardingHostageEscapeZone(IS_PLAN); + return; + } + } + + // if safe time is up, and we stumble across a hostage, guard it + if (!me->IsRogue() && !me->IsSafe()) + { + CHostage *hostage = me->GetGameState()->GetNearestVisibleFreeHostage(); + if (hostage != NULL) + { + CNavArea *area = TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin); + if (area != NULL) + { + // we see a free hostage, guard it + me->SetTask(CCSBot::GUARD_HOSTAGES); + me->Hide(area); + me->PrintIfWatched("I'm guarding hostages\n"); + me->GetChatter()->GuardingHostages(area->GetPlace(), IS_PLAN); + return; + } + } + } + } + } + + // listen for enemy noises + if (me->ShouldInvestigateNoise()) + { + me->InvestigateNoise(); + return; + } + + // look around + me->UpdateLookAround(); + + // if we have reached our destination area, pick a new one + // if our path fails, pick a new one + if (me->GetLastKnownArea() == m_huntArea || me->UpdatePathMovement() != CCSBot::PROGRESSING) + { + m_huntArea = NULL; + float oldest = 0.0f; + + int areaCount = 0; + const float minSize = 150.0f; + + NavAreaList::iterator iter; + + for (iter = TheNavAreaList.begin(); iter != TheNavAreaList.end(); ++iter) + { + CNavArea *area = (*iter); + + ++areaCount; + + // skip the small areas + const Extent *extent = area->GetExtent(); + if (extent->hi.x - extent->lo.x < minSize || extent->hi.y - extent->lo.y < minSize) + continue; + + // keep track of the least recently cleared area + float_precision age = gpGlobals->time - area->GetClearedTimestamp(me->m_iTeam - 1); + if (age > oldest) + { + oldest = age; + m_huntArea = area; + } + } + + // if all the areas were too small, pick one at random + int which = RANDOM_LONG(0, areaCount - 1); + + areaCount = 0; + for (iter = TheNavAreaList.begin(); iter != TheNavAreaList.end(); ++iter) + { + m_huntArea = (*iter); + + if (which == areaCount) + break; + + --which; + } + + if (m_huntArea != NULL) + { + // create a new path to a far away area of the map + me->ComputePath(m_huntArea, NULL, SAFEST_ROUTE); + } + } } +// Done hunting + /* <58e418> ../cstrike/dlls/bot/states/cs_bot_hunt.cpp:211 */ -NOBODY void HuntState::__MAKE_VHOOK(OnExit)(CCSBot *me) +void HuntState::__MAKE_VHOOK(OnExit)(CCSBot *me) { + ; } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_idle.cpp b/regamedll/dlls/bot/states/cs_bot_idle.cpp index 09049d3f..682d286c 100644 --- a/regamedll/dlls/bot/states/cs_bot_idle.cpp +++ b/regamedll/dlls/bot/states/cs_bot_idle.cpp @@ -1,158 +1,758 @@ #include "precompiled.h" +// range for snipers to select a hiding spot +const float sniperHideRange = 2000.0f; + +// The Idle state. +// We never stay in the Idle state - it is a "home base" for the state machine that +// does various checks to determine what we should do next. + /* <5a12ee> ../cstrike/dlls/bot/states/cs_bot_idle.cpp:26 */ -NOBODY void IdleState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void IdleState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// DestroyPath(CCSBot *const this); // 28 -// SetTask(CCSBot *const this, -// enum TaskType task, -// class CBaseEntity *entity); // 38 + me->DestroyPath(); + me->SetEnemy(NULL); + + // lurking death + if (me->IsUsingKnife() && me->IsWellPastSafe() && !me->IsHurrying()) + me->Walk(); + + // Since Idle assigns tasks, we assume that coming back to Idle means our task is complete + me->SetTask(CCSBot::SEEK_AND_DESTROY); + me->SetDisposition(CCSBot::ENGAGE_AND_INVESTIGATE); } /* <5a0c66> ../cstrike/dlls/bot/states/cs_bot_idle.cpp:46 */ -NOBODY void IdleState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void IdleState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// class CCSBotManager *ctrl; // 59 -// float const defenseSniperCampChance; // 95 -// float const offenseSniperCampChance; // 96 -// { -// const class Zone *zone; // 81 -// } -// { -// const class Zone *zone; // 121 -// { -// Place place; // 126 -// { -// const Vector *spot; // 130 -// } -// } -// } -// { -// int zoneIndex; // 149 -// const Vector *pos; // 152 -// } -// { -// const class Zone *zone; // 178 -// { -// const Vector *pos; // 182 -// } -// } -// { -// const Vector *bombPos; // 228 -// { -// const class Zone *zone; // 261 -// } -// { -// const class Zone *zone; // 286 -// float travelDistance; // 287 -// { -// int z; // 289 -// { -// class ShortestPathCost pathCost; // 299 -// float dist; // 300 -// } -// } -// { -// float const farAwayRange; // 314 -// } -// { -// int zoneIndex; // 324 -// } -// { -// const Vector *pos; // 331 -// } -// } -// } -// { -// class CNavArea *snipingArea; // 368 -// { -// const class Zone *zone; // 379 -// } -// } -// { -// float guardBombsiteChance; // 410 -// { -// class CNavArea *area; // 414 -// float guardRange; // 415 -// const class Zone *zone; // 418 -// { -// class CNavArea *area; // 421 -// } -// } -// } -// { -// float guardEscapeZoneChance; // 472 -// { -// const class Zone *zone; // 450 -// { -// class CNavArea *area; // 453 -// } -// } -// { -// const class Zone *zone; // 477 -// { -// class CNavArea *area; // 480 -// { -// float escapeGuardRange; // 487 -// } -// } -// } -// } -// { -// float const earlyTime; // 501 -// const class Zone *zone; // 502 -// { -// const Vector *pos; // 518 -// { -// float const repeatTime; // 527 -// } -// } -// } -// { -// bool campHostages; // 556 -// float const huntChance; // 625 -// const Vector *hostagePos; // 639 -// { -// float const campZoneChance; // 570 -// } -// { -// const Vector *hostagePos; // 581 -// } -// { -// class CBaseEntity *hostage; // 607 -// { -// class CNavArea *area; // 611 -// } -// } -// { -// class CNavArea *area; // 642 -// { -// float hostageGuardRange; // 649 -// } -// } -// } -// { -// class CHostage *hostage; // 699 -// bool fetchHostages; // 721 -// bool rescueHostages; // 722 -// const class Zone *zone; // 723 -// { -// float const huntChance; // 689 -// } -// { -// class CNavArea *area; // 706 -// } -// { -// class PathCost pathCost; // 736 -// float toZone; // 737 -// float toHostage; // 738 -// } -// { -// enum RouteType route; // 772 -// } -// } -// } + // all other states assume GetLastKnownArea() is valid, ensure that it is + if (me->GetLastKnownArea() == NULL && me->StayOnNavMesh() == false) + return; + + // zombies never leave the Idle state + if (cv_bot_zombie.value > 0.0f) + { + me->ResetStuckMonitor(); + return; + } + + // if we are in the early "safe" time, grab a knife or grenade + if (me->IsSafe()) + { + // if we have a grenade, use it + if (!me->EquipGrenade()) + { + // high-skill bots run with the knife + if (me->GetProfile()->GetSkill() > 0.33f) + { + me->EquipKnife(); + } + } + } + + CCSBotManager *ctrl = TheCSBots(); + + // if round is over, hunt + if (me->GetGameState()->IsRoundOver()) + { + // if we are escorting hostages, try to get to the rescue zone + if (me->GetHostageEscortCount()) + { + const CCSBotManager::Zone *zone = ctrl->GetClosestZone(me->GetLastKnownArea(), PathCost(me, FASTEST_ROUTE)); + me->SetTask(CCSBot::RESCUE_HOSTAGES); + me->Run(); + me->SetDisposition(CCSBot::SELF_DEFENSE); + me->MoveTo(ctrl->GetRandomPositionInZone(zone), FASTEST_ROUTE); + me->PrintIfWatched("Trying to rescue hostages at the end of the round\n"); + return; + } + + me->Hunt(); + return; + } + + const float defenseSniperCampChance = 75.0f; + const float offenseSniperCampChance = 10.0f; + + // if we were following someone, continue following them + if (me->IsFollowing()) + { + me->ContinueFollowing(); + return; + } + + // Scenario logic + switch (ctrl->GetScenario()) + { + case CCSBotManager::SCENARIO_DEFUSE_BOMB: + { + static int inumpo = 0; + inumpo++; + + // if this is a bomb game and we have the bomb, go plant it + if (me->m_iTeam == TERRORIST) + { + if (me->GetGameState()->IsBombPlanted()) + { + if (me->GetGameState()->GetPlantedBombsite() != CSGameState::UNKNOWN) + { + // T's always know where the bomb is - go defend it + const CCSBotManager::Zone *zone = ctrl->GetZone(me->GetGameState()->GetPlantedBombsite()); + me->SetTask(CCSBot::GUARD_TICKING_BOMB); + + Place place = TheNavAreaGrid.GetPlace(&zone->m_center); + if (place != UNDEFINED_PLACE) + { + // pick a random hiding spot in this place + const Vector *spot = FindRandomHidingSpot(me, place, me->IsSniper()); + if (spot != NULL) + { + me->Hide(spot); + return; + } + } + + // hide nearby + me->Hide(TheNavAreaGrid.GetNearestNavArea(&zone->m_center)); + return; + } + else + { + // ask our teammates where the bomb is + me->GetChatter()->RequestBombLocation(); + + // we dont know where the bomb is - we must search the bombsites + int zoneIndex = me->GetGameState()->GetNextBombsiteToSearch(); + + // move to bombsite - if we reach it, we'll update its cleared status, causing us to select another + const Vector *pos = ctrl->GetRandomPositionInZone(ctrl->GetZone(zoneIndex)); + if (pos != NULL) + { + me->SetTask(CCSBot::FIND_TICKING_BOMB); + me->MoveTo(pos); + return; + } + } + } + else if (me->IsCarryingBomb()) + { + // if we're at a bomb site, plant the bomb + if (me->IsAtBombsite()) + { + // plant it + me->SetTask(CCSBot::PLANT_BOMB); + me->PlantBomb(); + + // radio to the team + me->GetChatter()->PlantingTheBomb(me->GetPlace()); + + return; + } + else if (ctrl->IsTimeToPlantBomb()) + { + // move to the closest bomb site + const CCSBotManager::Zone *zone = ctrl->GetClosestZone(me->GetLastKnownArea(), PathCost(me)); + if (zone != NULL) + { + // pick a random spot within the bomb zone + const Vector *pos = ctrl->GetRandomPositionInZone(zone); + if (pos != NULL) + { + // move to bombsite + me->SetTask(CCSBot::PLANT_BOMB); + me->Run(); + me->MoveTo(pos); + + return; + } + } + } + } + else + { + // small chance of sniper camping on offense, if we aren't carrying the bomb + if (me->GetFriendsRemaining() && me->IsSniper() && RANDOM_FLOAT(0, 100.0f) < offenseSniperCampChance) + { + me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT); + me->Hide(me->GetLastKnownArea(), RANDOM_FLOAT(10.0f, 30.0f), sniperHideRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + me->PrintIfWatched("Sniping!\n"); + return; + } + + // if the bomb is loose (on the ground), go get it + if (me->NoticeLooseBomb()) + { + me->FetchBomb(); + return; + } + + // if bomb has been planted, and we hear it, move to a hiding spot near the bomb and guard it + if (!me->IsRogue() && me->GetGameState()->IsBombPlanted() && me->GetGameState()->GetBombPosition() != NULL) + { + const Vector *bombPos = me->GetGameState()->GetBombPosition(); + if (bombPos != NULL) + { + me->SetTask(CCSBot::GUARD_TICKING_BOMB); + me->Hide(TheNavAreaGrid.GetNavArea(bombPos)); + return; + } + } + } + } + // CT + else + { + if (me->GetGameState()->IsBombPlanted()) + { + // if the bomb has been planted, attempt to defuse it + const Vector *bombPos = me->GetGameState()->GetBombPosition(); + if (bombPos != NULL) + { + // if someone is defusing the bomb, guard them + if (ctrl->GetBombDefuser()) + { + if (!me->IsRogue()) + { + me->SetTask(CCSBot::GUARD_BOMB_DEFUSER); + me->Hide(TheNavAreaGrid.GetNavArea(bombPos)); + return; + } + } + else if (me->IsDoingScenario()) + { + // move to the bomb and defuse it + me->SetTask(CCSBot::DEFUSE_BOMB); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + me->MoveTo(bombPos); + return; + } + else + { + // we're not allowed to defuse, guard the bomb zone + me->SetTask(CCSBot::GUARD_BOMB_ZONE); + me->Hide(TheNavAreaGrid.GetNavArea(bombPos)); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + return; + } + } + else if (me->GetGameState()->GetPlantedBombsite() != CSGameState::UNKNOWN) + { + // we know which bombsite, but not exactly where the bomb is, go there + const CCSBotManager::Zone *zone = ctrl->GetZone(me->GetGameState()->GetPlantedBombsite()); + if (zone != NULL) + { + if (me->IsDoingScenario()) + { + me->SetTask(CCSBot::DEFUSE_BOMB); + me->MoveTo(&zone->m_center); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + return; + } + else + { + // we're not allowed to defuse, guard the bomb zone + me->SetTask(CCSBot::GUARD_BOMB_ZONE); + me->Hide(TheNavAreaGrid.GetNavArea(&zone->m_center)); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + return; + } + } + } + else + { + // we dont know where the bomb is - we must search the bombsites + // find closest un-cleared bombsite + const CCSBotManager::Zone *zone = NULL; + float travelDistance = 9999999.9f; + + for (int z = 0; z < ctrl->GetZoneCount(); ++z) + { + if (ctrl->GetZone(z)->m_areaCount == 0) + continue; + + // don't check bombsites that have been cleared + if (me->GetGameState()->IsBombsiteClear(z)) + continue; + + // just use the first overlapping nav area as a reasonable approximation + ShortestPathCost pathCost = ShortestPathCost(); + float_precision dist = NavAreaTravelDistance(me->GetLastKnownArea(), TheNavAreaGrid.GetNearestNavArea(&ctrl->GetZone(z)->m_center), pathCost); + + if (/*dist >= 0.0f && */dist < travelDistance) + { + zone = ctrl->GetZone(z); + travelDistance = dist; + } + } + + if (zone != NULL) + { + const float farAwayRange = 2000.0f; + if (travelDistance > farAwayRange) + { + zone = NULL; + } + } + + // if closest bombsite is "far away", pick one at random + if (zone == NULL) + { + int zoneIndex = me->GetGameState()->GetNextBombsiteToSearch(); + zone = ctrl->GetZone(zoneIndex); + } + + // move to bombsite - if we reach it, we'll update its cleared status, causing us to select another + if (zone != NULL) + { + const Vector *pos = ctrl->GetRandomPositionInZone(zone); + if (pos != NULL) + { + me->SetTask(CCSBot::FIND_TICKING_BOMB); + me->MoveTo(pos); + return; + } + } + } + + assert((0, "A CT bot doesn't know what to do while the bomb is planted!\n")); + } + + // if we have a sniper rifle, we like to camp, whether rogue or not + if (me->IsSniper()) + { + if (RANDOM_FLOAT(0, 100) <= defenseSniperCampChance) + { + CNavArea *snipingArea = NULL; + + // if the bomb is loose, snipe near it + if (me->GetGameState()->IsLooseBombLocationKnown()) + { + snipingArea = TheNavAreaGrid.GetNearestNavArea(me->GetGameState()->GetBombPosition()); + me->PrintIfWatched("Sniping near loose bomb\n"); + } + else + { + // snipe bomb zone(s) + const CCSBotManager::Zone *zone = ctrl->GetRandomZone(); + if (zone != NULL) + { + snipingArea = ctrl->GetRandomAreaInZone(zone); + me->PrintIfWatched("Sniping near bombsite\n"); + } + } + + if (snipingArea != NULL) + { + me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT); + me->Hide(snipingArea, -1.0f, sniperHideRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + return; + } + } + } + + // rogues just hunt, unless they want to snipe + // if the whole team has decided to rush, hunt + // if we know the bomb is dropped, hunt for enemies and the loose bomb + if (me->IsRogue() || ctrl->IsDefenseRushing() || me->GetGameState()->IsLooseBombLocationKnown()) + { + me->Hunt(); + return; + } + + // the lower our morale gets, the more we want to camp the bomb zone(s) + // only decide to camp at the start of the round, or if we haven't seen anything for a long time + if (me->IsSafe() || me->HasNotSeenEnemyForLongTime()) + { + float guardBombsiteChance = -34.0f * me->GetMorale(); + + if (RANDOM_FLOAT(0.0f, 100.0f) < guardBombsiteChance) + { + float guardRange = 500.0f + 100.0f * (me->GetMorale() + 3); + + // guard bomb zone(s) + const CCSBotManager::Zone *zone = ctrl->GetRandomZone(); + if (zone != NULL) + { + CNavArea *area = ctrl->GetRandomAreaInZone(zone); + if (area != NULL) + { + me->PrintIfWatched("I'm guarding a bombsite\n"); + me->GetChatter()->AnnouncePlan("GoingToDefendBombsite", area->GetPlace()); + me->SetTask(CCSBot::GUARD_BOMB_ZONE); + me->Hide(area, -1.0, guardRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + return; + } + } + } + } + } + break; + } + case CCSBotManager::SCENARIO_ESCORT_VIP: + { + if (me->m_iTeam == TERRORIST) + { + // if we have a sniper rifle, we like to camp, whether rogue or not + if (me->IsSniper()) + { + if (RANDOM_FLOAT(0, 100) <= defenseSniperCampChance) + { + // snipe escape zone(s) + const CCSBotManager::Zone *zone = ctrl->GetRandomZone(); + if (zone != NULL) + { + CNavArea *area = ctrl->GetRandomAreaInZone(zone); + if (area != NULL) + { + me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT); + me->Hide(area, -1.0, sniperHideRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + me->PrintIfWatched("Sniping near escape zone\n"); + return; + } + } + } + } + + // rogues just hunt, unless they want to snipe + // if the whole team has decided to rush, hunt + if (me->IsRogue() || ctrl->IsDefenseRushing()) + break; + + // the lower our morale gets, the more we want to camp the escape zone(s) + float guardEscapeZoneChance = -34.0f * me->GetMorale(); + + if (RANDOM_FLOAT(0.0f, 100.0f) < guardEscapeZoneChance) + { + // guard escape zone(s) + const CCSBotManager::Zone *zone = ctrl->GetRandomZone(); + if (zone != NULL) + { + CNavArea *area = ctrl->GetRandomAreaInZone(zone); + if (area != NULL) + { + // guard the escape zone - stay closer if our morale is low + me->SetTask(CCSBot::GUARD_VIP_ESCAPE_ZONE); + me->PrintIfWatched("I'm guarding an escape zone\n"); + + float escapeGuardRange = 750.0f + 250.0f * (me->GetMorale() + 3); + me->Hide(area, -1.0, escapeGuardRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + return; + } + } + } + } + // CT + else + { + if (me->m_bIsVIP) + { + // if early in round, pick a random zone, otherwise pick closest zone + const float earlyTime = 20.0f; + const CCSBotManager::Zone *zone = NULL; + + if (ctrl->GetElapsedRoundTime() < earlyTime) + { + // pick random zone + zone = ctrl->GetRandomZone(); + } + else + { + // pick closest zone + zone = ctrl->GetClosestZone(me->GetLastKnownArea(), PathCost(me)); + } + + if (zone != NULL) + { + // pick a random spot within the escape zone + const Vector *pos = ctrl->GetRandomPositionInZone(zone); + if (pos != NULL) + { + // move to escape zone + me->SetTask(CCSBot::VIP_ESCAPE); + me->Run(); + me->MoveTo(pos); + + // tell team to follow + const float repeatTime = 30.0f; + if (me->GetFriendsRemaining() && ctrl->GetRadioMessageInterval(EVENT_RADIO_FOLLOW_ME, me->m_iTeam) > repeatTime) + me->SendRadioMessage(EVENT_RADIO_FOLLOW_ME); + return; + } + } + } + else + { + // small chance of sniper camping on offense, if we aren't VIP + if (me->GetFriendsRemaining() && me->IsSniper() && RANDOM_FLOAT(0, 100.0f) < offenseSniperCampChance) + { + me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT); + me->Hide(me->GetLastKnownArea(), RANDOM_FLOAT(10.0f, 30.0f), sniperHideRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + me->PrintIfWatched("Sniping!\n"); + return; + } + } + } + break; + } + case CCSBotManager::SCENARIO_RESCUE_HOSTAGES: + { + if (me->m_iTeam == TERRORIST) + { + bool campHostages; + + // if we are in early game, camp the hostages + if (me->IsSafe()) + { + campHostages = true; + } + else if (me->GetGameState()->HaveSomeHostagesBeenTaken() || me->GetGameState()->AreAllHostagesBeingRescued()) + { + campHostages = false; + } + else + { + // later in the game, camp either hostages or escape zone + const float campZoneChance = 100.0f * (ctrl->GetElapsedRoundTime() - me->GetSafeTime()) / 120.0f; + campHostages = (RANDOM_FLOAT(0, 100) > campZoneChance) ? true : false; + } + + // if we have a sniper rifle, we like to camp, whether rogue or not + if (me->IsSniper()) + { + if (RANDOM_FLOAT(0, 100) <= defenseSniperCampChance) + { + const Vector *hostagePos = me->GetGameState()->GetRandomFreeHostagePosition(); + if (hostagePos != NULL && campHostages) + { + me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT); + me->PrintIfWatched("Sniping near hostages\n"); + me->Hide(TheNavAreaGrid.GetNearestNavArea(hostagePos), -1.0, sniperHideRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + return; + } + else + { + // camp the escape zone(s) + if (me->GuardRandomZone(sniperHideRange)) + { + me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT); + me->PrintIfWatched("Sniping near a rescue zone\n"); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + return; + } + } + } + } + + // if safe time is up, and we stumble across a hostage, guard it + if (!me->IsSafe() && !me->IsRogue()) + { + CBaseEntity *hostage = me->GetGameState()->GetNearestVisibleFreeHostage(); + if (hostage != NULL) + { + // we see a free hostage, guard it + CNavArea *area = TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin); + if (area != NULL) + { + me->SetTask(CCSBot::GUARD_HOSTAGES); + me->Hide(area); + me->PrintIfWatched("I'm guarding hostages I found\n"); + // don't chatter here - he'll tell us when he's in his hiding spot + return; + } + } + } + + // decide if we want to hunt, or guard + const float huntChance = 70.0f + 25.0f * me->GetMorale(); + + // rogues just hunt, unless they want to snipe + // if the whole team has decided to rush, hunt + if (me->GetFriendsRemaining()) + { + if (me->IsRogue() || ctrl->IsDefenseRushing() || RANDOM_FLOAT(0, 100) < huntChance) + { + me->Hunt(); + return; + } + } + + // decide whether to camp the hostages or the escape zones + const Vector *hostagePos = me->GetGameState()->GetRandomFreeHostagePosition(); + if (hostagePos != NULL && campHostages) + { + CNavArea *area = TheNavAreaGrid.GetNearestNavArea(hostagePos); + if (area != NULL) + { + // guard the hostages - stay closer to hostages if our morale is low + me->SetTask(CCSBot::GUARD_HOSTAGES); + me->PrintIfWatched("I'm guarding hostages\n"); + + float hostageGuardRange = 750.0f + 250.0f * (me->GetMorale() + 3); + me->Hide(area, -1.0, hostageGuardRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + + if (RANDOM_FLOAT(0, 100) < 50) + me->GetChatter()->GuardingHostages(area->GetPlace(), IS_PLAN); + + return; + } + } + + // guard rescue zone(s) + if (me->GuardRandomZone()) + { + me->SetTask(CCSBot::GUARD_HOSTAGE_RESCUE_ZONE); + me->PrintIfWatched("I'm guarding a rescue zone\n"); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + me->GetChatter()->GuardingHostageEscapeZone(IS_PLAN); + return; + } + } + // CT + else + { + // only decide to do something else if we aren't already rescuing hostages + if (!me->GetHostageEscortCount()) + { + // small chance of sniper camping on offense + if (me->GetFriendsRemaining() && me->IsSniper() && RANDOM_FLOAT(0, 100.0f) < offenseSniperCampChance) + { + me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT); + me->Hide(me->GetLastKnownArea(), RANDOM_FLOAT(10.0f, 30.0f), sniperHideRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + me->PrintIfWatched("Sniping!\n"); + return; + } + + if (me->GetFriendsRemaining() && !me->GetHostageEscortCount()) + { + // rogues just hunt, unless all friends are dead + // if we have friends left, we might go hunting instead of hostage rescuing + const float huntChance = 33.3f; + if (me->IsRogue() || RANDOM_FLOAT(0.0f, 100.0f) < huntChance) + { + me->Hunt(); + return; + } + } + } + + // look for free hostages - CT's have radar so they know where hostages are at all times + CHostage *hostage = me->GetGameState()->GetNearestFreeHostage(); + + // if we are not allowed to do the scenario, guard the hostages to clear the area for the human(s) + if (!me->IsDoingScenario()) + { + if (hostage != NULL) + { + CNavArea *area = TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin); + if (area != NULL) + { + me->SetTask(CCSBot::GUARD_HOSTAGES); + me->Hide(area); + me->PrintIfWatched("I'm securing the hostages for a human to rescue\n"); + return; + } + } + + me->Hunt(); + return; + } + + bool fetchHostages = false; + bool rescueHostages = false; + const CCSBotManager::Zone *zone = NULL; + me->SetGoalEntity(NULL); + + // if we are escorting hostages, determine where to take them + if (me->GetHostageEscortCount()) + zone = ctrl->GetClosestZone(me->GetLastKnownArea(), PathCost(me, FASTEST_ROUTE)); + + // if we are escorting hostages and there are more hostages to rescue, + // determine whether it's faster to rescue the ones we have, or go get the remaining ones + if (hostage != NULL) + { + if (zone != NULL) + { + PathCost pathCost(me, FASTEST_ROUTE); + float toZone = NavAreaTravelDistance(me->GetLastKnownArea(), zone->m_area[0], pathCost); + float toHostage = NavAreaTravelDistance(me->GetLastKnownArea(), TheNavAreaGrid.GetNearestNavArea(&hostage->pev->origin), pathCost); + + if (toHostage < 0.0f) + { + rescueHostages = true; + } + else + { + if (toZone < toHostage) + rescueHostages = true; + else + fetchHostages = true; + } + } + else + { + fetchHostages = true; + } + } + else if (zone != NULL) + { + rescueHostages = true; + } + + if (fetchHostages) + { + // go get hostages + me->SetTask(CCSBot::COLLECT_HOSTAGES); + me->Run(); + me->SetGoalEntity(hostage); + me->ResetWaitForHostagePatience(); + + // if we already have some hostages, move to the others by the quickest route + RouteType route = (me->GetHostageEscortCount()) ? FASTEST_ROUTE : SAFEST_ROUTE; + me->MoveTo(&hostage->pev->origin, route); + me->PrintIfWatched("I'm collecting hostages\n"); + return; + } + + if (rescueHostages) + { + me->SetTask(CCSBot::RESCUE_HOSTAGES); + me->Run(); + me->SetDisposition(CCSBot::SELF_DEFENSE); + me->MoveTo(ctrl->GetRandomPositionInZone(zone), FASTEST_ROUTE); + me->PrintIfWatched("I'm rescuing hostages\n"); + me->GetChatter()->EscortingHostages(); + return; + } + } + break; + } + // deathmatch + default: + { + // sniping check + if (me->GetFriendsRemaining() && me->IsSniper() && RANDOM_FLOAT(0, 100.0f) < offenseSniperCampChance) + { + me->SetTask(CCSBot::MOVE_TO_SNIPER_SPOT); + me->Hide(me->GetLastKnownArea(), RANDOM_FLOAT(10.0f, 30.0f), sniperHideRange); + me->SetDisposition(CCSBot::OPPORTUNITY_FIRE); + me->PrintIfWatched("Sniping!\n"); + return; + } + break; + } + } + + // if we have nothing special to do, go hunting for enemies + me->Hunt(); } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_investigate_noise.cpp b/regamedll/dlls/bot/states/cs_bot_investigate_noise.cpp index acef70e6..7781c402 100644 --- a/regamedll/dlls/bot/states/cs_bot_investigate_noise.cpp +++ b/regamedll/dlls/bot/states/cs_bot_investigate_noise.cpp @@ -3,47 +3,117 @@ // Move towards currently heard noise /* <5b3114> ../cstrike/dlls/bot/states/cs_bot_investigate_noise.cpp:17 */ -NOBODY void InvestigateNoiseState::AttendCurrentNoise(CCSBot *me) +void InvestigateNoiseState::AttendCurrentNoise(CCSBot *me) { -// IsNoiseHeard(const class CCSBot *const this); // 19 + if (!me->IsNoiseHeard() && me->GetNoisePosition()) + return; + + // remember where the noise we heard was + m_checkNoisePosition = *me->GetNoisePosition(); + + // tell our teammates (unless the noise is obvious, like gunfire) + if (me->IsWellPastSafe() && me->HasNotSeenEnemyForLongTime() && me->GetNoisePriority() != PRIORITY_HIGH) + me->GetChatter()->HeardNoise(me->GetNoisePosition()); + + // figure out how to get to the noise + me->PrintIfWatched("Attending to noise...\n"); + me->ComputePath(me->GetNoiseArea(), &m_checkNoisePosition, SAFEST_ROUTE); + + // consume the noise + me->ForgetNoise(); } /* <5b2f37> ../cstrike/dlls/bot/states/cs_bot_investigate_noise.cpp:38 */ -NOBODY void InvestigateNoiseState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void InvestigateNoiseState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// AttendCurrentNoise(InvestigateNoiseState *const this, -// class CCSBot *me); // 40 + AttendCurrentNoise(me); } +// Use TravelDistance instead of distance... + /* <5b2fa2> ../cstrike/dlls/bot/states/cs_bot_investigate_noise.cpp:47 */ -NOBODY void InvestigateNoiseState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void InvestigateNoiseState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// float newNoiseDist; // 50 -// float noiseDist; // 74 -// float const nearDist; // 111 -// { -// Vector toOldNoise; // 54 -// float const muchCloserDist; // 56 -// operator-(const Vector *const this, -// const Vector &v); // 54 -// IsLengthGreaterThan(const Vector *const this, -// float length); // 57 -// AttendCurrentNoise(InvestigateNoiseState *const this, -// class CCSBot *me); // 60 -// } -// operator-(const Vector *const this, -// const Vector &v); // 74 -// Length(const Vector *const this); // 74 -// { -// float const closeToNoiseRange; // 85 -// } -// } + float newNoiseDist; + if (me->ShouldInvestigateNoise(&newNoiseDist)) + { + Vector toOldNoise = m_checkNoisePosition - me->pev->origin; + const float muchCloserDist = 100.0f; + if (toOldNoise.IsLengthGreaterThan(newNoiseDist + muchCloserDist)) + { + // new sound is closer + AttendCurrentNoise(me); + } + } + + // if the pathfind fails, give up + if (!me->HasPath()) + { + me->Idle(); + return; + } + + // look around + me->UpdateLookAround(); + + // get distance remaining on our path until we reach the source of the noise + float noiseDist = (m_checkNoisePosition - me->pev->origin).Length(); + + if (me->IsUsingKnife()) + { + if (me->IsHurrying()) + me->Run(); + else + me->Walk(); + } + else + { + const float closeToNoiseRange = 1500.0f; + if (noiseDist < closeToNoiseRange) + { + // if we dont have many friends left, or we are alone, and we are near noise source, sneak quietly + if (me->GetFriendsRemaining() <= 2 && !me->IsHurrying()) + { + me->Walk(); + } + else + { + me->Run(); + } + } + else + { + me->Run(); + } + } + + // if we can see the noise position and we're close enough to it and looking at it, + // we don't need to actually move there (it's checked enough) + const float closeRange = 200.0f; + if (noiseDist < closeRange) + { + if (me->IsLookingAtPosition(&m_checkNoisePosition) && me->IsVisible(&m_checkNoisePosition)) + { + // can see noise position + me->PrintIfWatched("Noise location is clear.\n"); + //me->ForgetNoise(); + me->Idle(); + return; + } + } + + // move towards noise + if (me->UpdatePathMovement() != CCSBot::PROGRESSING) + { + me->Idle(); + } } /* <5b2e95> ../cstrike/dlls/bot/states/cs_bot_investigate_noise.cpp:129 */ -NOBODY void InvestigateNoiseState::__MAKE_VHOOK(OnExit)(CCSBot *me) +void InvestigateNoiseState::__MAKE_VHOOK(OnExit)(CCSBot *me) { + // reset to run mode in case we were sneaking about + me->Run(); } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/bot/states/cs_bot_move_to.cpp b/regamedll/dlls/bot/states/cs_bot_move_to.cpp index f2d3a928..f840b8d3 100644 --- a/regamedll/dlls/bot/states/cs_bot_move_to.cpp +++ b/regamedll/dlls/bot/states/cs_bot_move_to.cpp @@ -1,89 +1,304 @@ #include "precompiled.h" +// Move to a potentially far away position. + /* <5c4e91> ../cstrike/dlls/bot/states/cs_bot_move_to.cpp:21 */ -NOBODY void MoveToState::__MAKE_VHOOK(OnEnter)(CCSBot *me) +void MoveToState::__MAKE_VHOOK(OnEnter)(CCSBot *me) { -// { -// enum RouteType route; // 30 -// } + if (me->IsUsingKnife() && me->IsWellPastSafe() && !me->IsHurrying()) + { + me->Walk(); + } + else + { + me->Run(); + } + + // if we need to find the bomb, get there as quick as we can + RouteType route; + switch (me->GetTask()) + { + case CCSBot::FIND_TICKING_BOMB: + case CCSBot::DEFUSE_BOMB: + case CCSBot::MOVE_TO_LAST_KNOWN_ENEMY_POSITION: + route = FASTEST_ROUTE; + break; + + default: + route = SAFEST_ROUTE; + break; + } + + // build path to, or nearly to, goal position + me->ComputePath(TheNavAreaGrid.GetNavArea(&m_goalPosition), &m_goalPosition, route); + + m_radioedPlan = false; + m_askedForCover = false; } +// Move to a potentially far away position. + /* <5c4edf> ../cstrike/dlls/bot/states/cs_bot_move_to.cpp:55 */ -NOBODY void MoveToState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) +void MoveToState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) { -// { -// class CCSBotManager *ctrl; // 76 -// { -// class CBasePlayer *victim; // 61 -// GetTaskEntity(CCSBot *const this); // 61 -// } -// { -// float const nearPlantSite; // 161 -// { -// float const radioTime; // 173 -// } -// } -// Say(BotChatterInterface *const this, -// const char *phraseName, -// float lifetime, -// float delay); // 140 -// { -// class CHostage *hostage; // 197 -// float const repathToleranceSq; // 205 -// float error; // 206 -// GetGoalEntity(CCSBot *const this); // 197 -// IsValid(CHostage *const this); // 198 -// IsFollowingSomeone(CHostage *const this); // 198 -// operator-(const Vector *const this, -// const Vector &v); // 206 -// LengthSquared(const Vector *const this); // 206 -// { -// Vector pos; // 216 -// Vector to; // 217 -// float const watchHostageRange; // 220 -// operator+(const Vector *const this, -// const Vector &v); // 216 -// operator-(const Vector *const this, -// const Vector &v); // 217 -// IsLengthLessThan(const Vector *const this, -// float length); // 221 -// { -// enum NavRelativeDirType dir; // 226 -// float const useRange; // 236 -// GetGoalEntity(CCSBot *const this); // 239 -// } -// } -// } -// { -// int z; // 100 -// Contains(const class Extent *const this, -// const Vector *pos); // 106 -// } -// { -// const Vector *bombPos; // 284 -// IsActiveWeaponReloading(const class CBot *const this); // 278 -// { -// Vector toBomb; // 287 -// float const defuseRange; // 291 -// GetFeetZ(const class CCSBot *const this); // 290 -// IsLengthLessThan(const Vector *const this, -// float length); // 292 -// } -// } -// { -// class CBasePlayer *victim; // 303 -// GetTaskEntity(CCSBot *const this); // 303 -// Say(BotChatterInterface *const this, -// const char *phraseName, -// float lifetime, -// float delay); // 307 -// } -// } + CCSBotManager *ctrl = TheCSBots(); + + // assume that we are paying attention and close enough to know our enemy died + if (me->GetTask() == CCSBot::MOVE_TO_LAST_KNOWN_ENEMY_POSITION) + { + // TODO: Account for reaction time so we take some time to realized the enemy is dead + CBasePlayer *victim = static_cast(me->GetTaskEntity()); + if (victim == NULL || !victim->IsAlive()) + { + me->PrintIfWatched("The enemy I was chasing was killed - giving up.\n"); + me->Idle(); + return; + } + } + + // look around + me->UpdateLookAround(); + + // Scenario logic + switch (ctrl->GetScenario()) + { + case CCSBotManager::SCENARIO_DEFUSE_BOMB: + { + // if the bomb has been planted, find it + // NOTE: This task is used by both CT and T's to find the bomb + if (me->GetTask() == CCSBot::FIND_TICKING_BOMB) + { + if (!me->GetGameState()->IsBombPlanted()) + { + // the bomb is not planted - give up this task + me->Idle(); + return; + } + + if (me->GetGameState()->GetPlantedBombsite() != CSGameState::UNKNOWN) + { + // we know where the bomb is planted, stop searching + me->Idle(); + return; + } + + // check off bombsites that we explore or happen to stumble into + for (int z = 0; z < ctrl->GetZoneCount(); ++z) + { + // don't re-check zones + if (me->GetGameState()->IsBombsiteClear(z)) + continue; + + if (ctrl->GetZone(z)->m_extent.Contains(&me->pev->origin)) + { + // note this bombsite is clear + me->GetGameState()->ClearBombsite(z); + + if (me->m_iTeam == CT) + { + // tell teammates this bombsite is clear + me->GetChatter()->BombsiteClear(z); + } + + // find another zone to check + me->Idle(); + return; + } + } + + // move to a bombsite + break; + } + else if (me->m_iTeam == CT) + { + if (me->GetGameState()->IsBombPlanted()) + { + switch (me->GetTask()) + { + case CCSBot::DEFUSE_BOMB: + { + // if we are trying to defuse the bomb, and someone has started defusing, guard them instead + if (me->CanSeePlantedBomb() && ctrl->GetBombDefuser()) + { + me->GetChatter()->Say("CoveringFriend"); + me->Idle(); + return; + } + + break; + } + default: + { + // we need to find the bomb + me->Idle(); + return; + } + } + } + } + // TERRORIST + else + { + if (me->GetTask() == CCSBot::PLANT_BOMB) + { + if (me->GetFriendsRemaining()) + { + // if we are about to plant, radio for cover + if (!m_askedForCover) + { + const float nearPlantSite = 50.0f; + if (me->IsAtBombsite() && me->GetPathDistanceRemaining() < nearPlantSite) + { + // radio to the team + me->GetChatter()->PlantingTheBomb(me->GetPlace()); + m_askedForCover = true; + } + + // after we have started to move to the bombsite, tell team we're going to plant, and where + // don't do this if we have already radioed that we are starting to plant + if (!m_radioedPlan) + { + const float radioTime = 2.0f; + if (gpGlobals->time - me->GetStateTimestamp() > radioTime) + { + me->GetChatter()->GoingToPlantTheBomb(TheNavAreaGrid.GetPlace(&m_goalPosition)); + m_radioedPlan = true; + } + } + } + } + } + } + break; + } + case CCSBotManager::SCENARIO_RESCUE_HOSTAGES: + { + if (me->GetTask() == CCSBot::COLLECT_HOSTAGES) + { + // Since CT's have a radar, they can directly look at the actual hostage state + // check if someone else collected our hostage, or the hostage died or was rescued + CHostage *hostage = static_cast(me->GetGoalEntity()); + if (hostage == NULL || !hostage->IsValid() || hostage->IsFollowingSomeone()) + { + me->Idle(); + return; + } + + // if our hostage has moved, repath + const float repathToleranceSq = 75.0f * 75.0f; + float error = (hostage->pev->origin - m_goalPosition).LengthSquared(); + if (error > repathToleranceSq) + { + m_goalPosition = hostage->pev->origin; + me->ComputePath(TheNavAreaGrid.GetNavArea(&m_goalPosition), &m_goalPosition, SAFEST_ROUTE); + } + + // TODO: Generalize ladder priorities over other tasks + if (!me->IsUsingLadder()) + { + Vector pos = hostage->pev->origin + Vector(0, 0, HumanHeight * 0.75f); + Vector to = pos - me->pev->origin; + + // look at the hostage as we approach + const float watchHostageRange = 100.0f; + if (to.IsLengthLessThan(watchHostageRange)) + { + me->SetLookAt("Hostage", &pos, PRIORITY_LOW, 0.5f); + + // randomly move just a bit to avoid infinite use loops from bad hostage placement + NavRelativeDirType dir = (NavRelativeDirType)RANDOM_LONG(0, 3); + switch (dir) + { + case LEFT: me->StrafeLeft(); break; + case RIGHT: me->StrafeRight(); break; + case FORWARD: me->MoveForward(); break; + case BACKWARD: me->MoveBackward(); break; + } + + // check if we are close enough to the hostage to talk to him + const float useRange = PLAYER_USE_RADIUS - 14.0f; // shave off a fudge factor to make sure we're within range + if (to.IsLengthLessThan(useRange)) + { + me->UseEntity(me->GetGoalEntity()); + return; + } + } + } + } + else if (me->GetTask() == CCSBot::RESCUE_HOSTAGES) + { + // periodically check if we lost all our hostages + if (me->GetHostageEscortCount() == 0) + { + // lost our hostages - go get 'em + me->Idle(); + return; + } + } + break; + } + } + + if (me->UpdatePathMovement() != CCSBot::PROGRESSING) + { + // reached destination + switch (me->GetTask()) + { + case CCSBot::PLANT_BOMB: + { + // if we are at bombsite with the bomb, plant it + if (me->IsAtBombsite() && me->IsCarryingBomb()) + { + me->PlantBomb(); + return; + } + break; + } + case CCSBot::DEFUSE_BOMB: + { + if (!me->IsActiveWeaponReloading()) + { + // if we are near the bomb, defuse it (if we are reloading, don't try to defuse until we finish) + const Vector *bombPos = me->GetGameState()->GetBombPosition(); + if (bombPos != NULL) + { + const float defuseRange = 100.0f; + Vector toBomb = *bombPos - me->pev->origin + Vector(0, 0, me->GetFeetZ()); + + if (toBomb.IsLengthLessThan(defuseRange)) + { + me->DefuseBomb(); + return; + } + } + } + break; + } + case CCSBot::MOVE_TO_LAST_KNOWN_ENEMY_POSITION: + { + CBasePlayer *victim = static_cast(me->GetTaskEntity()); + if (victim != NULL && victim->IsAlive()) + { + // if we got here and haven't re-acquired the enemy, we lost him + me->GetChatter()->Say("LostEnemy"); + } + break; + } + } + + // default behavior when destination is reached + me->Idle(); + return; + } } /* <5c4e54> ../cstrike/dlls/bot/states/cs_bot_move_to.cpp:320 */ -NOBODY void MoveToState::__MAKE_VHOOK(OnExit)(CCSBot *me) +void MoveToState::__MAKE_VHOOK(OnExit)(CCSBot *me) { + // reset to run in case we were walking near our goal position + me->Run(); + me->SetDisposition(CCSBot::ENGAGE_AND_INVESTIGATE); + //me->StopAiming(); } #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/career_tasks.cpp b/regamedll/dlls/career_tasks.cpp index a263f55f..08aa04ee 100644 --- a/regamedll/dlls/career_tasks.cpp +++ b/regamedll/dlls/career_tasks.cpp @@ -483,7 +483,7 @@ void CCareerTaskManager::AddTask(const char *taskName, const char *weaponName, i { ++m_nextId; - for (int i = 0; i < ARRAYSIZE(taskInfo); i++) + for (int i = 0; i < ARRAYSIZE(taskInfo); ++i) { const TaskInfo *pTaskInfo = &taskInfo[ i ]; @@ -598,9 +598,9 @@ void CCareerTaskManager::HandleDeath(int team, CBasePlayer *pAttacker) if (enemyTeam != team) return; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (pPlayer && pPlayer->m_iTeam == enemyTeam && pPlayer->IsAlive()) ++numEnemies; diff --git a/regamedll/dlls/cbase.cpp b/regamedll/dlls/cbase.cpp index 08719c8f..5518501a 100644 --- a/regamedll/dlls/cbase.cpp +++ b/regamedll/dlls/cbase.cpp @@ -117,7 +117,7 @@ void EmptyEntityHashTable(void) int i; hash_item_t *item, *temp, *free; - for (i = 0; i < stringsHashTable.Count(); i++) + for (i = 0; i < stringsHashTable.Count(); ++i) { item = &stringsHashTable[i]; temp = item->next; @@ -281,7 +281,7 @@ void RemoveEntityHashValue(entvars_t *pev, const char *value, hash_types_e field /* <31125> ../cstrike/dlls/cbase.cpp:337 */ void printEntities(void) { - for (int i = 0; i < stringsHashTable.Count(); i++) + for (int i = 0; i < stringsHashTable.Count(); ++i) { hash_item_t *item = &stringsHashTable[i]; @@ -342,7 +342,7 @@ void loopPerformance(void) start = loopCounter.GetCurTime(); - for (i = 0; i < 100; i++) + for (i = 0; i < 100; ++i) { CBaseEntity *pSpot; for (pSpot = UTIL_FindEntityByString_Old(NULL, "classname", "info_player_start"); pSpot != NULL; pSpot = UTIL_FindEntityByString_Old(pSpot, "classname", "info_player_start")) @@ -364,7 +364,7 @@ void loopPerformance(void) // check time new search loop start = loopCounter.GetCurTime(); - for (i = 0; i < 100; i++) + for (i = 0; i < 100; ++i) { CBaseEntity *pSpot; for (pSpot = UTIL_FindEntityByString(NULL, "classname", "info_player_start"); pSpot != NULL; pSpot = UTIL_FindEntityByString(pSpot, "classname", "info_player_start")) @@ -392,7 +392,7 @@ C_DLLEXPORT int GetEntityAPI(DLL_FUNCTIONS *pFunctionTable, int interfaceVersion Q_memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS)); stringsHashTable.AddMultipleToTail(2048); - for (int i = 0; i < stringsHashTable.Count(); i++) + for (int i = 0; i < stringsHashTable.Count(); ++i) { stringsHashTable[i].next = NULL; } @@ -968,7 +968,7 @@ void SetObjectCollisionBox(entvars_t *pev) int i; max = 0; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { v = fabs((float_precision)((float *)pev->mins)[i]); if (v > max) @@ -982,7 +982,7 @@ void SetObjectCollisionBox(entvars_t *pev) max = v; } } - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { ((float *)pev->absmin)[i] = ((float *)pev->origin)[i] - max; ((float *)pev->absmax)[i] = ((float *)pev->origin)[i] + max; diff --git a/regamedll/dlls/client.cpp b/regamedll/dlls/client.cpp index 6a912ddb..5ce1c1c0 100644 --- a/regamedll/dlls/client.cpp +++ b/regamedll/dlls/client.cpp @@ -88,7 +88,7 @@ int CMD_ARGC_(void) int i = 0; while (BotArgs[i]) - i++; + ++i; return i; } @@ -352,7 +352,7 @@ int CountTeamPlayers(int iTeam) continue; if (GetClassPtr((CBasePlayer *)pPlayer->pev)->m_iTeam == iTeam) - i++; + ++i; } return i; @@ -3637,7 +3637,7 @@ void EXT_FUNC ClientCommand(edict_t *pEntity) player->m_bNightVisionOn = false; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBasePlayer *pObserver = reinterpret_cast(UTIL_PlayerByIndex(i)); @@ -3663,7 +3663,7 @@ void EXT_FUNC ClientCommand(edict_t *pEntity) player->m_bNightVisionOn = true; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBasePlayer *pObserver = reinterpret_cast(UTIL_PlayerByIndex(i)); @@ -3798,7 +3798,7 @@ void EXT_FUNC ClientCommand(edict_t *pEntity) { player->ClearAutoBuyData(); - for (int i = 1; i < CMD_ARGC_(); i++) + for (int i = 1; i < CMD_ARGC_(); ++i) { player->AddAutoBuyData(CMD_ARGV_(i)); } @@ -3973,7 +3973,7 @@ void EXT_FUNC ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) EmptyEntityHashTable(); // Clients have not been initialized yet - for (i = 0; i < edictCount; i++) + for (i = 0; i < edictCount; ++i) { edict_t *pEdict = &pEdictList[i]; @@ -4222,12 +4222,12 @@ void ClientPrecache(void) else numPlayerModels = ARRAYSIZE(sPlayerModelFiles) - 2; - for (i = 0; i < numPlayerModels; i++) + for (i = 0; i < numPlayerModels; ++i) PRECACHE_MODEL(sPlayerModelFiles[i]); if (isCZero) { - for (i = FirstCustomSkin; i <= LastCustomSkin; i++) + for (i = FirstCustomSkin; i <= LastCustomSkin; ++i) { const char *fname = TheBotProfiles->GetCustomSkinFname(i); @@ -4287,12 +4287,12 @@ void ClientPrecache(void) Vector vMin = Vector(-38, -24, -41); Vector vMax = Vector(38, 24, 41); - for (i = 0; i < numPlayerModels; i++) + for (i = 0; i < numPlayerModels; ++i) ENGINE_FORCE_UNMODIFIED(force_model_specifybounds, (float *)&vMin, (float *)&vMax, sPlayerModelFiles[i]); if (isCZero) { - for (i = FirstCustomSkin; i <= LastCustomSkin; i++) + for (i = FirstCustomSkin; i <= LastCustomSkin; ++i) { const char *fname = TheBotProfiles->GetCustomSkinFname(i); @@ -4663,7 +4663,7 @@ bool CheckPlayerPVSLeafChanged(edict_t *client, int clientnum) if (pvs->headnode != client->headnode || pvs->num_leafs != client->num_leafs) return true; - for (int i = 0; i < pvs->num_leafs; i++) + for (int i = 0; i < pvs->num_leafs; ++i) { if (client->leafnums[i] != pvs->leafnums[i]) return true; @@ -4794,10 +4794,10 @@ int EXT_FUNC AddToFullPack(struct entity_state_s *state, int e, edict_t *ent, ed state->framerate = ent->v.framerate; state->body = ent->v.body; - for (i = 0; i < 4; i++) + for (i = 0; i < 4; ++i) state->controller[i] = ent->v.controller[i]; - for (i = 0; i < 2; i++) + for (i = 0; i < 2; ++i) state->blending[i] = ent->v.blending[i]; state->rendermode = ent->v.rendermode; @@ -5086,7 +5086,7 @@ int EXT_FUNC GetWeaponData(edict_s *player, struct weapon_data_s *info) return 1; } - for (int i = 0; i < MAX_ITEM_TYPES; i++) + for (int i = 0; i < MAX_ITEM_TYPES; ++i) { CBasePlayerItem *pPlayerItem = pl->m_rgpPlayerItems[i]; diff --git a/regamedll/dlls/combat.cpp b/regamedll/dlls/combat.cpp index 61ce3694..82ff0902 100644 --- a/regamedll/dlls/combat.cpp +++ b/regamedll/dlls/combat.cpp @@ -25,7 +25,7 @@ NOXREF void CGib::SpawnStickyGibs(entvars_t *pevVictim, Vector vecOrigin, int cG return; } - for (i = 0; i < cGibs; i++) + for (i = 0; i < cGibs; ++i) { CGib *pGib = GetClassPtr((CGib *)NULL); @@ -1047,7 +1047,7 @@ void RadiusFlash(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker, UTIL_ScreenFade(pPlayer, Vector(255, 255, 255), fadeTime, fadeHold, alpha, 0); - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBasePlayer *pObserver = reinterpret_cast(UTIL_PlayerByIndex(i)); @@ -1921,7 +1921,7 @@ void CBaseEntity::__MAKE_VHOOK(TraceBleed)(float flDamage, Vector vecDir, TraceR cCount = 4; } - for (i = 0; i < cCount; i++) + for (i = 0; i < cCount; ++i) { // trace in the opposite direction the shot came from (the direction the shot is going) vecTraceDir = vecDir * -1.0f; @@ -1961,7 +1961,7 @@ NOXREF void CBaseMonster::MakeDamageBloodDecal(int cCount, float flNoise, TraceR pev->max_health--; } - for (i = 0; i < cCount; i++) + for (i = 0; i < cCount; ++i) { vecTraceDir = vecDir; diff --git a/regamedll/dlls/debug.cpp b/regamedll/dlls/debug.cpp index 170a39ee..9fa44465 100644 --- a/regamedll/dlls/debug.cpp +++ b/regamedll/dlls/debug.cpp @@ -72,7 +72,7 @@ void PrintDebugFlags(void) theDebugBuffer[0] = '\0'; tmp = BufPrintf(theDebugBuffer, remainder, "mp_debug:\n"); - for (int i = 0; i < NUM_LEVELS - 1; i++) + for (int i = 0; i < NUM_LEVELS - 1; ++i) { DebugOutputLevel level = outputLevel[i]; @@ -87,7 +87,7 @@ void SetDebugFlag(const char *flagStr, bool state) if (flagStr != NULL) { DebugOutputType flag; - for (int i = 0; i < ARRAYSIZE(outputLevel); i++) + for (int i = 0; i < ARRAYSIZE(outputLevel); ++i) { DebugOutputLevel level = outputLevel[ i ]; @@ -115,7 +115,7 @@ void PrintDebugFlag(const char *flagStr) if (flagStr != NULL) { DebugOutputType flag; - for (int i = 0; i < ARRAYSIZE(outputLevel); i++) + for (int i = 0; i < ARRAYSIZE(outputLevel); ++i) { DebugOutputLevel level = outputLevel[ i ]; diff --git a/regamedll/dlls/effects.cpp b/regamedll/dlls/effects.cpp index 7be5863d..13682c59 100644 --- a/regamedll/dlls/effects.cpp +++ b/regamedll/dlls/effects.cpp @@ -1655,7 +1655,7 @@ void CTestEffect::TestThink(void) if (t < 3.0) { - for (i = 0; i < m_iBeam; i++) + for (i = 0; i < m_iBeam; ++i) { t = (gpGlobals->time - m_flBeamTime[i]) / (3 + m_flStartTime - m_flBeamTime[i]); m_pBeam[i]->SetBrightness(255 * t); @@ -1664,7 +1664,7 @@ void CTestEffect::TestThink(void) } else { - for (i = 0; i < m_iBeam; i++) + for (i = 0; i < m_iBeam; ++i) { UTIL_Remove(m_pBeam[i]); } diff --git a/regamedll/dlls/explode.cpp b/regamedll/dlls/explode.cpp index 4fd26e56..1a163157 100644 --- a/regamedll/dlls/explode.cpp +++ b/regamedll/dlls/explode.cpp @@ -189,7 +189,7 @@ void CEnvExplosion::__MAKE_VHOOK(Use)(CBaseEntity *pActivator, CBaseEntity *pCal { int sparkCount = RANDOM_LONG(0, 3); - for (int i = 0; i < sparkCount; i++) + for (int i = 0; i < sparkCount; ++i) { Create("spark_shower", pev->origin, tr.vecPlaneNormal, NULL); } diff --git a/regamedll/dlls/func_break.cpp b/regamedll/dlls/func_break.cpp index cad60550..579a1bcf 100644 --- a/regamedll/dlls/func_break.cpp +++ b/regamedll/dlls/func_break.cpp @@ -322,7 +322,7 @@ void CBreakable::MaterialSoundPrecache(Materials precacheMaterial) pSoundList = MaterialSoundList(precacheMaterial, soundCount); - for (i = 0; i < soundCount; i++) + for (i = 0; i < soundCount; ++i) { PRECACHE_SOUND((char *)pSoundList[i]); } @@ -834,7 +834,7 @@ void CBreakable::Die(void) if (count) { - for (int i = 0; i < count; i++) + for (int i = 0; i < count; ++i) { pList[i]->pev->flags &= ~FL_ONGROUND; pList[i]->pev->groundentity = NULL; @@ -917,7 +917,7 @@ void CPushable::__MAKE_VHOOK(Spawn)(void) /* <863eb> ../cstrike/dlls/func_break.cpp:920 */ void CPushable::__MAKE_VHOOK(Precache)(void) { - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; ++i) { PRECACHE_SOUND(m_soundNames[i]); } diff --git a/regamedll/dlls/func_tank.cpp b/regamedll/dlls/func_tank.cpp index 7b7e5c8c..f0642851 100644 --- a/regamedll/dlls/func_tank.cpp +++ b/regamedll/dlls/func_tank.cpp @@ -696,9 +696,9 @@ void CFuncTankGun::__MAKE_VHOOK(Fire)(const Vector &barrelEnd, const Vector &for if (bulletCount > 0) { - for (i = 0; i < bulletCount; i++) + for (i = 0; i < bulletCount; ++i) { - switch(m_bulletType) + switch (m_bulletType) { case TANK_BULLET_9MM: FireBullets(1, barrelEnd, forward, gTankSpread[m_spread], 4096, BULLET_MONSTER_9MM, 1, m_iBulletDamage, pevAttacker); @@ -807,14 +807,14 @@ void CFuncTankLaser::__MAKE_VHOOK(Fire)(const Vector &barrelEnd, const Vector &f if (bulletCount) { - for (i = 0; i < bulletCount; i++) + for (i = 0; i < bulletCount; ++i) { m_pLaser->pev->origin = barrelEnd; TankTrace(barrelEnd, forward, gTankSpread[m_spread], tr); m_laserTime = gpGlobals->time; m_pLaser->TurnOn(); - m_pLaser->pev->dmgtime = gpGlobals->time - 1.0; + m_pLaser->pev->dmgtime = gpGlobals->time - 1.0f; m_pLaser->FireAtPoint(tr); m_pLaser->pev->nextthink = 0; } @@ -849,7 +849,7 @@ void CFuncTankRocket::__MAKE_VHOOK(Fire)(const Vector &barrelEnd, const Vector & if (bulletCount > 0) { - for (i = 0; i < bulletCount; i++) + for (i = 0; i < bulletCount; ++i) { CBaseEntity *pRocket = CBaseEntity::Create("rpg_rocket", barrelEnd, pev->angles, edict()); } diff --git a/regamedll/dlls/gamerules.cpp b/regamedll/dlls/gamerules.cpp index 5d17dba6..3f9e3753 100644 --- a/regamedll/dlls/gamerules.cpp +++ b/regamedll/dlls/gamerules.cpp @@ -123,18 +123,7 @@ void CGameRules::__MAKE_VHOOK(RefreshSkillData)(void) gSkillData.healthkitCapacity = 15; } -void (*pInstallGameRules)(void); - /* ../cstrike/dlls/gamerules.cpp:157 */ -#ifdef HOOK_GAMEDLL -NOBODY __declspec(naked) CGameRules *InstallGameRules(void) -{ - __asm - { - jmp pInstallGameRules - } -} -#else CGameRules *InstallGameRules(void) { SERVER_COMMAND("exec game.cfg\n"); @@ -145,7 +134,6 @@ CGameRules *InstallGameRules(void) return new CHalfLifeMultiplay; } -#endif // HOOK_GAMEDLL #ifdef HOOK_GAMEDLL diff --git a/regamedll/dlls/gamerules.h b/regamedll/dlls/gamerules.h index e526e959..e8fd9c3f 100644 --- a/regamedll/dlls/gamerules.h +++ b/regamedll/dlls/gamerules.h @@ -812,9 +812,6 @@ int CountPlayers(void); void ExtractCommandString(char *s, char *szCommand); int GetMapCount(void); -// refs -extern void (*pInstallGameRules)(void); - #ifdef HOOK_GAMEDLL // linked objects diff --git a/regamedll/dlls/ggrenade.cpp b/regamedll/dlls/ggrenade.cpp index 058a1d0c..57460d7b 100644 --- a/regamedll/dlls/ggrenade.cpp +++ b/regamedll/dlls/ggrenade.cpp @@ -100,7 +100,7 @@ void CGrenade::Explode(TraceResult *pTrace, int bitsDamageType) { int sparkCount = RANDOM_LONG(0, 3); - for (int i = 0; i < sparkCount; i++) + for (int i = 0; i < sparkCount; ++i) Create("spark_shower", pev->origin, pTrace->vecPlaneNormal, NULL); } } @@ -234,7 +234,7 @@ void CGrenade::Explode2(TraceResult *pTrace, int bitsDamageType) { int sparkCount = RANDOM_LONG(0, 3); - for (int i = 0; i < sparkCount; i++) + for (int i = 0; i < sparkCount; ++i) Create("spark_shower", pev->origin, pTrace->vecPlaneNormal, NULL); } } @@ -313,7 +313,7 @@ void CGrenade::Explode3(TraceResult *pTrace, int bitsDamageType) pev->nextthink = gpGlobals->time + 0.55; int sparkCount = RANDOM_LONG(0, 3); - for (int i = 0; i < sparkCount; i++) + for (int i = 0; i < sparkCount; ++i) Create("spark_shower", pev->origin, pTrace->vecPlaneNormal, NULL); } @@ -362,7 +362,7 @@ NOXREF void CGrenade::SG_Explode(TraceResult *pTrace, int bitsDamageType) { int sparkCount = RANDOM_LONG(0, 3); - for (int i = 0; i < sparkCount; i++) + for (int i = 0; i < sparkCount; ++i) Create("spark_shower", pev->origin, pTrace->vecPlaneNormal, NULL); } } diff --git a/regamedll/dlls/h_ai.cpp b/regamedll/dlls/h_ai.cpp index 43952c6a..f13d03e5 100644 --- a/regamedll/dlls/h_ai.cpp +++ b/regamedll/dlls/h_ai.cpp @@ -27,7 +27,7 @@ NOXREF BOOL FBoxVisible(entvars_t *pevLooker, entvars_t *pevTarget, Vector &vecT //look through the monster's 'eyes' Vector vecLookerOrigin = pevLooker->origin + pevLooker->view_ofs; - for (int i = 0; i < 5; i++) + for (int i = 0; i < 5; ++i) { Vector vecTarget = pevTarget->origin; diff --git a/regamedll/dlls/h_cycler.cpp b/regamedll/dlls/h_cycler.cpp index 312d8050..0792fc87 100644 --- a/regamedll/dlls/h_cycler.cpp +++ b/regamedll/dlls/h_cycler.cpp @@ -216,7 +216,7 @@ void CCyclerSprite::__MAKE_VHOOK(Spawn)(void) m_rendermode = pev->rendermode; m_renderamt = pev->renderamt; - for (int i = 0; i < ARRAYSIZE(pev->rendercolor); i++) + for (int i = 0; i < ARRAYSIZE(pev->rendercolor); ++i) { pev->rendercolor[i] = m_rendercolor[i]; } @@ -239,7 +239,7 @@ void CCyclerSprite::__MAKE_VHOOK(Restart)(void) pev->rendermode = m_rendermode; pev->renderamt = m_renderamt; - for (int i = 0; i < ARRAYSIZE(pev->rendercolor); i++) + for (int i = 0; i < ARRAYSIZE(pev->rendercolor); ++i) { pev->rendercolor[i] = m_rendercolor[i]; } diff --git a/regamedll/dlls/hintmessage.cpp b/regamedll/dlls/hintmessage.cpp index 4552a000..6f69d0b7 100644 --- a/regamedll/dlls/hintmessage.cpp +++ b/regamedll/dlls/hintmessage.cpp @@ -9,7 +9,7 @@ CHintMessage::CHintMessage(const char *hintString, bool isHint, CUtlVectorCount(); i++) + for (int i = 0; i < args->Count(); ++i) m_args.AddToTail(CloneString((*args)[i])); } } diff --git a/regamedll/dlls/hostage/hostage.cpp b/regamedll/dlls/hostage/hostage.cpp index 201a3c05..526a98cc 100644 --- a/regamedll/dlls/hostage/hostage.cpp +++ b/regamedll/dlls/hostage/hostage.cpp @@ -1148,7 +1148,7 @@ void CHostage::Wiggle(void) Vector(-50, -50, 0) }; - for (int i = 0; i < ARRAYSIZE(wiggle_directions); i++) + for (int i = 0; i < ARRAYSIZE(wiggle_directions); ++i) { Vector dest = pev->origin + wiggle_directions[i]; @@ -1424,7 +1424,7 @@ void CHostageManager::ServerDeactivate(void) /* <45e3f7> ../cstrike/dlls/hostage/hostage.cpp:1631 */ void CHostageManager::RestartRound(void) { - for (int i = 0; i < m_hostageCount; i++) + for (int i = 0; i < m_hostageCount; ++i) { if (m_hostage[i]->m_improv != NULL) { @@ -1440,7 +1440,7 @@ void CHostageManager::AddHostage(CHostage *hostage) return; int i; - for (i = 0; i < m_hostageCount; i++) + for (i = 0; i < m_hostageCount; ++i) { if (m_hostage[i] == hostage) { @@ -1458,7 +1458,7 @@ void CHostageManager::AddHostage(CHostage *hostage) /* <45e47f> ../cstrike/dlls/hostage/hostage.cpp:1657 */ bool CHostageManager::IsNearbyHostageTalking(CHostageImprov *improv) { - for (int i = 0; i < m_hostageCount; i++) + for (int i = 0; i < m_hostageCount; ++i) { const float closeRange = 500.0f; const CHostageImprov *other = m_hostage[i]->m_improv; @@ -1481,7 +1481,7 @@ bool CHostageManager::IsNearbyHostageTalking(CHostageImprov *improv) /* <45e57b> ../cstrike/dlls/hostage/hostage.cpp:1689 */ bool CHostageManager::IsNearbyHostageJumping(CHostageImprov *improv) { - for (int i = 0; i < m_hostageCount; i++) + for (int i = 0; i < m_hostageCount; ++i) { const CHostageImprov *other = m_hostage[i]->m_improv; @@ -1504,7 +1504,7 @@ bool CHostageManager::IsNearbyHostageJumping(CHostageImprov *improv) /* <45e642> ../cstrike/dlls/hostage/hostage.cpp:1716 */ void CHostageManager::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEntity *other) { - for (int i = 0; i < m_hostageCount; i++) + for (int i = 0; i < m_hostageCount; ++i) { CHostageImprov *improv = m_hostage[ i ]->m_improv; @@ -1518,7 +1518,7 @@ void CHostageManager::OnEvent(GameEventType event, CBaseEntity *entity, CBaseEnt /* <45e6b8> ../cstrike/dlls/hostage/hostage.cpp:1726 */ SimpleChatter::SimpleChatter(void) { - for (int i = 0; i < ARRAYSIZE(m_chatter); i++) + for (int i = 0; i < ARRAYSIZE(m_chatter); ++i) { m_chatter[i].count = 0; m_chatter[i].index = 0; @@ -1529,7 +1529,7 @@ SimpleChatter::SimpleChatter(void) /* <45e6f0> ../cstrike/dlls/hostage/hostage.cpp:1737 */ SimpleChatter::~SimpleChatter(void) { - for (int i = 0; i < ARRAYSIZE(m_chatter); i++) + for (int i = 0; i < ARRAYSIZE(m_chatter); ++i) { for (int f = 0; f < m_chatter[i].count; f++) { @@ -1566,7 +1566,7 @@ void SimpleChatter::Shuffle(ChatterSet *chatter) if (!chatter->needsShuffle) return; - for (int i = 1; i < chatter->count; i++) + for (int i = 1; i < chatter->count; ++i) { for (int j = i; j < chatter->count; j++) { diff --git a/regamedll/dlls/hostage/hostage_improv.cpp b/regamedll/dlls/hostage/hostage_improv.cpp index 13e9a49a..bcd469f5 100644 --- a/regamedll/dlls/hostage/hostage_improv.cpp +++ b/regamedll/dlls/hostage/hostage_improv.cpp @@ -1534,7 +1534,7 @@ CBasePlayer *CHostageImprov::GetClosestVisiblePlayer(int team) CBasePlayer *close = NULL; float closeRangeSq = 1e8f; - for (int i = 0; i < m_visiblePlayerCount; i++) + for (int i = 0; i < m_visiblePlayerCount; ++i) { CBasePlayer *player = (CBasePlayer *)m_visiblePlayer[i]; @@ -1937,18 +1937,6 @@ void CHostageImprov::UpdateStationaryAnimation(void) #ifdef HOOK_GAMEDLL -// NavAreaBuildPath hook -bool NavAreaBuildPath__HostagePathCost__wrapper(CNavArea *startArea, CNavArea *goalArea, const Vector *goalPos, class HostagePathCost &costFunc, CNavArea **closestArea) -{ - return NavAreaBuildPath(startArea, goalArea, goalPos, costFunc, closestArea); -} - -// NavAreaBuildPath hook -bool NavAreaBuildPath__ShortestPathCost__wrapper(CNavArea *startArea, CNavArea *goalArea, const Vector *goalPos, class ShortestPathCost &costFunc, CNavArea **closestArea) -{ - return NavAreaBuildPath(startArea, goalArea, goalPos, costFunc, closestArea); -} - void CHostageImprov::OnMoveToFailure(const Vector &goal, MoveToFailureType reason) { OnMoveToFailure_(goal, reason); diff --git a/regamedll/dlls/hostage/hostage_improv.h b/regamedll/dlls/hostage/hostage_improv.h index e0420f4e..cae4cf28 100644 --- a/regamedll/dlls/hostage/hostage_improv.h +++ b/regamedll/dlls/hostage/hostage_improv.h @@ -513,8 +513,17 @@ private: #ifdef HOOK_GAMEDLL -bool NavAreaBuildPath__HostagePathCost__wrapper(CNavArea *startArea, CNavArea *goalArea, const Vector *goalPos, class HostagePathCost &costFunc, CNavArea **closestArea = NULL); -bool NavAreaBuildPath__ShortestPathCost__wrapper(CNavArea *startArea, CNavArea *goalArea, const Vector *goalPos, class ShortestPathCost &costFunc, CNavArea **closestArea = NULL); +// NavAreaBuildPath hook +inline bool NavAreaBuildPath__HostagePathCost__wrapper(CNavArea *startArea, CNavArea *goalArea, const Vector *goalPos, class HostagePathCost &costFunc, CNavArea **closestArea) +{ + return NavAreaBuildPath(startArea, goalArea, goalPos, costFunc, closestArea); +} + +// NavAreaBuildPath hook +inline bool NavAreaBuildPath__ShortestPathCost__wrapper(CNavArea *startArea, CNavArea *goalArea, const Vector *goalPos, class ShortestPathCost &costFunc, CNavArea **closestArea) +{ + return NavAreaBuildPath(startArea, goalArea, goalPos, costFunc, closestArea); +} typedef bool (CHostageImprov::*IS_FRIEND_IN_THE_WAY_VECTOR)(const Vector &) const; typedef bool (CHostageImprov::*IS_FRIEND_IN_THE_WAY_CBASE)(CBaseEntity *, const Vector &) const; diff --git a/regamedll/dlls/hostage/hostage_localnav.cpp b/regamedll/dlls/hostage/hostage_localnav.cpp index dfe800f9..7050745b 100644 --- a/regamedll/dlls/hostage/hostage_localnav.cpp +++ b/regamedll/dlls/hostage/hostage_localnav.cpp @@ -860,7 +860,7 @@ void CLocalNav::RequestNav(CHostage *pCaller) return; } - for (int i = 0; i < tot_inqueue; i++) + for (int i = 0; i < tot_inqueue; ++i) { CHostage *pQueueItem = GetClassPtr((CHostage *)_queue[curr]->pev); diff --git a/regamedll/dlls/maprules.cpp b/regamedll/dlls/maprules.cpp index 9cbc0062..00825682 100644 --- a/regamedll/dlls/maprules.cpp +++ b/regamedll/dlls/maprules.cpp @@ -249,7 +249,7 @@ void CGameTeamMaster::__MAKE_VHOOK(KeyValue)(KeyValueData *pkvd) { int type = Q_atoi(pkvd->szValue); - switch(type) + switch (type) { case 0: triggerType = USE_OFF; @@ -398,9 +398,9 @@ void CGamePlayerZone::__MAKE_VHOOK(Use)(CBaseEntity *pActivator, CBaseEntity *pC CBaseEntity *pPlayer = NULL; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (pPlayer) { @@ -417,7 +417,7 @@ void CGamePlayerZone::__MAKE_VHOOK(Use)(CBaseEntity *pActivator, CBaseEntity *pC if (trace.fStartSolid) { - playersInCount++; + ++playersInCount; if (!FStringNull(m_iszInTarget)) { FireTargets(STRING(m_iszInTarget), pPlayer, pActivator, useType, value); @@ -425,7 +425,7 @@ void CGamePlayerZone::__MAKE_VHOOK(Use)(CBaseEntity *pActivator, CBaseEntity *pC } else { - playersOutCount++; + ++playersOutCount; if (!FStringNull(m_iszOutTarget)) { FireTargets(STRING(m_iszOutTarget), pPlayer, pActivator, useType, value); @@ -547,7 +547,7 @@ void CGamePlayerEquip::__MAKE_VHOOK(KeyValue)(KeyValueData *pkvd) if (!pkvd->fHandled) { - for (int i = 0; i < MAX_EQUIP; i++) + for (int i = 0; i < MAX_EQUIP; ++i) { if (FStringNull(m_weaponNames[i])) { @@ -590,12 +590,12 @@ void CGamePlayerEquip::EquipPlayer(CBaseEntity *pEntity) if (!pPlayer) return; - for (int i = 0; i < MAX_EQUIP; i++) + for (int i = 0; i < MAX_EQUIP; ++i) { if (FStringNull(m_weaponNames[i])) break; - for (int j = 0; j < m_weaponCount[i]; j++) + for (int j = 0; j < m_weaponCount[i]; ++j) { pPlayer->GiveNamedItem(STRING(m_weaponNames[i])); } diff --git a/regamedll/dlls/mortar.cpp b/regamedll/dlls/mortar.cpp index 58f46fe4..92f1769d 100644 --- a/regamedll/dlls/mortar.cpp +++ b/regamedll/dlls/mortar.cpp @@ -139,7 +139,7 @@ void CFuncMortarField::FieldUse(CBaseEntity *pActivator, CBaseEntity *pCaller, U EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "weapons/mortar.wav", VOL_NORM, ATTN_NONE, 0, pitch); float t = 2.5; - for (int i = 0; i < m_iCount; i++) + for (int i = 0; i < m_iCount; ++i) { Vector vecSpot = vecStart; vecSpot.x += RANDOM_FLOAT(-m_flSpread, m_flSpread); diff --git a/regamedll/dlls/mpstubb.cpp b/regamedll/dlls/mpstubb.cpp index b4915665..c8cc9844 100644 --- a/regamedll/dlls/mpstubb.cpp +++ b/regamedll/dlls/mpstubb.cpp @@ -171,7 +171,7 @@ void CBaseMonster::__MAKE_VHOOK(Look)(int iDistance) // Find only monsters/clients in box, NOT limited to PVS int count = UTIL_EntitiesInBox(pList, ARRAYSIZE(pList), pev->origin - delta, pev->origin + delta, (FL_CLIENT | FL_MONSTER)); - for (int i = 0; i < count; i++) + for (int i = 0; i < count; ++i) { pSightEnt = pList[i]; if (pSightEnt != this && pSightEnt->pev->health > 0) diff --git a/regamedll/dlls/multiplay_gamerules.cpp b/regamedll/dlls/multiplay_gamerules.cpp index 4febf01f..ccae3b49 100644 --- a/regamedll/dlls/multiplay_gamerules.cpp +++ b/regamedll/dlls/multiplay_gamerules.cpp @@ -21,14 +21,14 @@ CHalfLifeMultiplay *g_pMPGameRules = NULL; /* <1153e2> ../cstrike/dlls/multiplay_gamerules.cpp:92 */ bool IsBotSpeaking(void) { - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (pPlayer == NULL || !pPlayer->IsBot()) continue; - CCSBot *pBot = reinterpret_cast(pPlayer); + CCSBot *pBot = static_cast(pPlayer); if (pBot->IsUsingVoice()) return true; @@ -51,9 +51,9 @@ void SV_Continue_f(void) WRITE_STRING("GOGOGO"); MESSAGE_END(); - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (pPlayer && !pPlayer->IsBot()) { @@ -99,9 +99,9 @@ void SV_Career_EndRound_f(void) { SERVER_COMMAND("kill\n"); - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *player = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *player = static_cast(UTIL_PlayerByIndex(i)); if (!player || FNullEnt(player->pev)) continue; @@ -804,9 +804,9 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(GiveC4)(void) if (giveToHumans) { - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *player = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *player = static_cast(UTIL_PlayerByIndex(i)); if (!player || FNullEnt(player->edict())) continue; @@ -1164,7 +1164,7 @@ bool CHalfLifeMultiplay::NeededPlayersCheck(bool &bNeededPlayers) { if (IsCareer()) { - CBasePlayer *player = reinterpret_cast(UTIL_PlayerByIndex(gpGlobals->maxClients)); + CBasePlayer *player = static_cast(UTIL_PlayerByIndex(gpGlobals->maxClients)); if (!player || !player->IsBot()) { @@ -1410,7 +1410,7 @@ bool CHalfLifeMultiplay::TeamExterminationCheck(int NumAliveTerrorist, int NumAl while ((temp = UTIL_FindEntityByClassname(temp, "grenade")) != NULL) { - CGrenade *C4 = reinterpret_cast(temp); + CGrenade *C4 = static_cast(temp); if (C4->m_bIsC4 && !C4->m_bJustBlew) { @@ -1632,7 +1632,7 @@ void CHalfLifeMultiplay::BalanceTeams(void) int iHighestUserID = 0; CBasePlayer *toSwap = NULL; - for (int i = 1; i <= iNumToSwap; i++) + for (int i = 1; i <= iNumToSwap; ++i) { iHighestUserID = 0; toSwap = NULL; @@ -1808,9 +1808,9 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(RestartRound)(void) UpdateTeamScores(); // Reset the player stats - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *plr = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *plr = static_cast(UTIL_PlayerByIndex(i)); if (plr && !FNullEnt(plr->pev)) plr->Reset(); @@ -1908,7 +1908,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(RestartRound)(void) if (acct_tmp >= 2000) break; - CHostage *temp = reinterpret_cast(hostage); + CHostage *temp = static_cast(hostage); if (hostage->pev->solid != SOLID_NOT) { @@ -2208,7 +2208,7 @@ void CHalfLifeMultiplay::StackVIPQueue(void) /* <114e63> ../cstrike/dlls/multiplay_gamerules.cpp:2232 */ bool CHalfLifeMultiplay::IsVIPQueueEmpty(void) { - for (int i = 0; i < MAX_VIP_QUEUES; i++) + for (int i = 0; i < MAX_VIP_QUEUES; ++i) { CBasePlayer *toCheck = VIPQueue[i]; @@ -2225,7 +2225,7 @@ bool CHalfLifeMultiplay::IsVIPQueueEmpty(void) /* <114eea> ../cstrike/dlls/multiplay_gamerules.cpp:2257 */ bool CHalfLifeMultiplay::AddToVIPQueue(CBasePlayer *toAdd) { - for (int i = 0; i < MAX_VIP_QUEUES; i++) + for (int i = 0; i < MAX_VIP_QUEUES; ++i) { CBasePlayer *toCheck = VIPQueue[i]; @@ -2317,7 +2317,7 @@ void CHalfLifeMultiplay::PickNextVIP(void) ResetCurrentVIP(); } - for (int i = 0; i < MAX_VIP_QUEUES; i++) + for (int i = 0; i < MAX_VIP_QUEUES; ++i) { if (VIPQueue[i] != NULL) { @@ -2528,9 +2528,9 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(Think)(void) m_bFreezePeriod = TRUE; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (pPlayer != NULL && !pPlayer->IsBot()) { @@ -2780,9 +2780,9 @@ void CHalfLifeMultiplay::CheckFreezePeriodExpired(void) TheCareerTasks->HandleEvent(EVENT_ROUND_START); } - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *plr = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *plr = static_cast(UTIL_PlayerByIndex(i)); if (!plr || plr->pev->flags == FL_DORMANT) { @@ -3031,7 +3031,7 @@ void CHalfLifeMultiplay::MarkLivingPlayersOnTeamAsNotReceivingMoneyNextRound(int { for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *player = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *player = static_cast(UTIL_PlayerByIndex(i)); if (!player || FNullEnt(player->pev)) continue; @@ -3068,9 +3068,9 @@ void CHalfLifeMultiplay::CareerRestart(void) m_bSkipSpawn = false; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *player = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *player = static_cast(UTIL_PlayerByIndex(i)); if (!player || FNullEnt(player->pev)) continue; @@ -3138,7 +3138,7 @@ BOOL CHalfLifeMultiplay::__MAKE_VHOOK(GetNextBestWeapon)(CBasePlayer *pPlayer, C iBestWeight = -1; // no weapon lower than -1 can be autoswitched to pBest = NULL; - for (i = 0; i < MAX_ITEM_TYPES; i++) + for (i = 0; i < MAX_ITEM_TYPES; ++i) { pCheck = pPlayer->m_rgpPlayerItems[i]; @@ -3252,10 +3252,10 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(InitHUD)(CBasePlayer *pl) SendMOTDToClient(pl->edict()); // loop through all active players and send their score info to the new client - for (i = 1; i <= gpGlobals->maxClients; i++) + for (i = 1; i <= gpGlobals->maxClients; ++i) { // FIXME: Probably don't need to cast this just to read m_iDeaths - CBasePlayer *plr = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *plr = static_cast(UTIL_PlayerByIndex(i)); if (plr != NULL) { @@ -3295,9 +3295,9 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(InitHUD)(CBasePlayer *pl) MESSAGE_END(); } - for (i = 1; i <= gpGlobals->maxClients; i++) + for (i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *plr = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *plr = static_cast(UTIL_PlayerByIndex(i)); if (plr != NULL) { @@ -3361,7 +3361,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(ClientDisconnected)(edict_t *pClient) { if (pClient != NULL) { - CBasePlayer *pPlayer = reinterpret_cast(CBaseEntity::Instance(pClient)); + CBasePlayer *pPlayer = static_cast(CBaseEntity::Instance(pClient)); if (pPlayer != NULL) { @@ -3505,7 +3505,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(PlayerThink)(CBasePlayer *pPlayer) if (pPlayer->m_pActiveItem && pPlayer->m_pActiveItem->IsWeapon()) { - CBasePlayerWeapon *pWeapon = reinterpret_cast(pPlayer->m_pActiveItem->GetWeaponPtr()); + CBasePlayerWeapon *pWeapon = static_cast(pPlayer->m_pActiveItem->GetWeaponPtr()); if (pWeapon->m_iWeaponState & WPNSTATE_SHIELD_DRAWN) { @@ -3660,16 +3660,16 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(PlayerKilled)(CBasePlayer *pVictim, entvar if (ktmp && ktmp->Classify() == CLASS_PLAYER) { - peKiller = reinterpret_cast(ktmp); + peKiller = static_cast(ktmp); } else if (ktmp && ktmp->Classify() == CLASS_VEHICLE) { - CBasePlayer *pDriver = reinterpret_cast(((CFuncVehicle *)ktmp)->m_pDriver); + CBasePlayer *pDriver = static_cast(((CFuncVehicle *)ktmp)->m_pDriver); if (pDriver != NULL) { pKiller = pDriver->pev; - peKiller = reinterpret_cast(pDriver); + peKiller = static_cast(pDriver); } } @@ -3781,7 +3781,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(PlayerKilled)(CBasePlayer *pVictim, entvar if (ep && ep->Classify() == CLASS_PLAYER) { - CBasePlayer *PK = reinterpret_cast(ep); + CBasePlayer *PK = static_cast(ep); MESSAGE_BEGIN(MSG_ALL, gmsgScoreInfo); WRITE_BYTE(ENTINDEX(PK->edict())); @@ -3820,7 +3820,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(DeathNotice)(CBasePlayer *pVictim, entvars if (pevInflictor == pKiller) { // If the inflictor is the killer, then it must be their current weapon doing the damage - CBasePlayer *pPlayer = reinterpret_cast(CBaseEntity::Instance(pKiller)); + CBasePlayer *pPlayer = static_cast(CBaseEntity::Instance(pKiller)); if (pPlayer && pPlayer->m_pActiveItem) { @@ -3887,7 +3887,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(DeathNotice)(CBasePlayer *pVictim, entvars } else if (pKiller->flags & FL_CLIENT) { - CBasePlayer *pPlayer = reinterpret_cast(CBaseEntity::Instance(pKiller)); + CBasePlayer *pPlayer = static_cast(CBaseEntity::Instance(pKiller)); char *VictimTeam = GetTeam(pVictim->m_iTeam); char *KillerTeam = GetTeam(pPlayer->m_iTeam); @@ -4470,7 +4470,7 @@ int CountPlayers(void) { int num = 0; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBaseEntity *pEnt = UTIL_PlayerByIndex(i); diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 4620b830..4cecaaf2 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -393,7 +393,7 @@ void LinkUserMessages(void) /* <1535a5> ../cstrike/dlls/player.cpp:380 */ void WriteSigonMessages(void) { - for (int i = 0; i < MAX_WEAPONS; i++) + for (int i = 0; i < MAX_WEAPONS; ++i) { ItemInfo &II = IMPL_CLASS(CBasePlayerItem, ItemInfoArray)[i]; @@ -1135,7 +1135,7 @@ int CBasePlayer::__MAKE_VHOOK(TakeDamage)(entvars_t *pevInflictor, entvars_t *pe if (friendlyfire.string[0] == '2') teamAttack = FALSE; #endif // REGAMEDLL_ADD - pAttack = reinterpret_cast(CBasePlayer::Instance(pevAttacker)); + pAttack = static_cast(CBasePlayer::Instance(pevAttacker)); } else if (pGrenade->m_iTeam == m_iTeam && (&edict()->v != pevAttacker)) { @@ -1210,9 +1210,9 @@ int CBasePlayer::__MAKE_VHOOK(TakeDamage)(entvars_t *pevInflictor, entvars_t *pe if (mp->IsCareer()) { - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (!pPlayer) continue; @@ -1232,7 +1232,7 @@ int CBasePlayer::__MAKE_VHOOK(TakeDamage)(entvars_t *pevInflictor, entvars_t *pe { // reset damage time countdown for each type of time based damage player just sustained - for (int i = 0; i < CDMG_TIMEBASED; i++) + for (int i = 0; i < CDMG_TIMEBASED; ++i) { if (bitsDamageType & (DMG_PARALYZE << i)) m_rgbTimeBasedDamage[i] = 0; @@ -1253,9 +1253,9 @@ int CBasePlayer::__MAKE_VHOOK(TakeDamage)(entvars_t *pevInflictor, entvars_t *pe WRITE_BYTE((int)Q_max(pev->health, 0.0f) | DRC_FLAG_FACEPLAYER); MESSAGE_END(); - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (!pPlayer || pPlayer->m_hObserverTarget != this) continue; @@ -1453,9 +1453,9 @@ int CBasePlayer::__MAKE_VHOOK(TakeDamage)(entvars_t *pevInflictor, entvars_t *pe if (mp->IsCareer()) { - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (!pPlayer) continue; @@ -1475,7 +1475,7 @@ int CBasePlayer::__MAKE_VHOOK(TakeDamage)(entvars_t *pevInflictor, entvars_t *pe { // reset damage time countdown for each type of time based damage player just sustained - for (int i = 0; i < CDMG_TIMEBASED; i++) + for (int i = 0; i < CDMG_TIMEBASED; ++i) { if (bitsDamageType & (DMG_PARALYZE << i)) m_rgbTimeBasedDamage[i] = 0; @@ -1496,9 +1496,9 @@ int CBasePlayer::__MAKE_VHOOK(TakeDamage)(entvars_t *pevInflictor, entvars_t *pe WRITE_BYTE((int)Q_max(pev->health, 0.0f) | DRC_FLAG_FACEPLAYER); MESSAGE_END(); - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (!pPlayer) continue; @@ -1665,7 +1665,7 @@ void CBasePlayer::RemoveAllItems(BOOL removeSuit) } m_pLastItem = NULL; - for (i = 0; i < MAX_ITEM_TYPES; i++) + for (i = 0; i < MAX_ITEM_TYPES; ++i) { m_pActiveItem = m_rgpPlayerItems[i]; @@ -1691,7 +1691,7 @@ void CBasePlayer::RemoveAllItems(BOOL removeSuit) else pev->weapons &= ~WEAPON_ALLWEAPONS; - for (i = 0; i < MAX_AMMO_SLOTS; i++) + for (i = 0; i < MAX_AMMO_SLOTS; ++i) m_rgAmmo[i] = 0; UpdateClientData(); @@ -2043,9 +2043,9 @@ void CBasePlayer::__MAKE_VHOOK(Killed)(entvars_t *pevAttacker, int iGib) wasBlind = true; } - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (!pPlayer) continue; @@ -2076,7 +2076,7 @@ void CBasePlayer::__MAKE_VHOOK(Killed)(entvars_t *pevAttacker, int iGib) for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pObserver = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pObserver = static_cast(UTIL_PlayerByIndex(i)); if (!pObserver) continue; @@ -3016,7 +3016,7 @@ BOOL CBasePlayer::IsOnLadder(void) /* <160720> ../cstrike/dlls/player.cpp:3387 */ NOXREF void CBasePlayer::ThrowWeapon(char *pszItemName) { - for (int i = 0; i < MAX_WEAPON_SLOTS; i++) + for (int i = 0; i < MAX_WEAPON_SLOTS; ++i) { CBasePlayerItem *pWeapon = m_rgpPlayerItems[i]; @@ -4006,7 +4006,7 @@ void CBasePlayer::PlayerUse(void) if (!pClosest) { - while ((pObject = UTIL_FindEntityInSphere(pObject, pev->origin, PLAYER_SEARCH_RADIUS)) != NULL) + while ((pObject = UTIL_FindEntityInSphere(pObject, pev->origin, PLAYER_USE_RADIUS)) != NULL) { if (pObject->ObjectCaps() & (FCAP_IMPULSE_USE | FCAP_CONTINUOUS_USE | FCAP_ONOFF_USE)) { @@ -4141,7 +4141,7 @@ NOXREF void FixPlayerCrouchStuck(edict_t *pPlayer) TraceResult trace; // Move up as many as 18 pixels if the player is stuck. - for (int i = 0; i < 18; i++) + for (int i = 0; i < 18; ++i) { UTIL_TraceHull(pPlayer->v.origin, pPlayer->v.origin, dont_ignore_monsters, head_hull, pPlayer, &trace); @@ -4200,9 +4200,9 @@ void CBasePlayer::__MAKE_VHOOK(AddPointsToTeam)(int score, BOOL bAllowNegativeSc { int index = entindex(); - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (pPlayer != NULL && i != index) { @@ -4571,7 +4571,7 @@ void CBasePlayer::CheckTimeBasedDamage(void) m_tbdPrev = gpGlobals->time; - for (i = 0; i < CDMG_TIMEBASED; i++) + for (i = 0; i < CDMG_TIMEBASED; ++i) { // make sure bit is set for damage type if (m_bitsDamageType & (DMG_PARALYZE << i)) @@ -4704,7 +4704,7 @@ void CBasePlayer::CheckSuitUpdate(void) if (gpGlobals->time >= m_flSuitUpdate && m_flSuitUpdate > 0) { // play a sentence off of the end of the queue - for (i = 0; i < CSUITPLAYLIST; i++) + for (i = 0; i < CSUITPLAYLIST; ++i) { if (isentence = m_rgSuitPlayList[ isearch ]) break; @@ -4978,7 +4978,7 @@ pt_end: #ifdef CLIENT_WEAPONS // Decay timers on weapons // go through all of the weapons and make a list of the ones to pack - for (int i = 0; i < MAX_ITEM_TYPES; i++) + for (int i = 0; i < MAX_ITEM_TYPES; ++i) { if (m_rgpPlayerItems[i]) { @@ -5370,7 +5370,7 @@ void CBasePlayer::__MAKE_VHOOK(Spawn)(void) m_iNumSpawns++; InitStatusBar(); - for (i = 0; i < MAX_RECENT_PATH; i++) + for (i = 0; i < MAX_RECENT_PATH; ++i) m_vRecentPath[ i ] = Vector(0, 0, 0); if (m_pActiveItem != NULL && !pev->viewmodel) @@ -5461,7 +5461,7 @@ void CBasePlayer::__MAKE_VHOOK(Spawn)(void) { m_iClientHideHUD = -1; - for (i = 0; i < MAX_AMMO_SLOTS; i++) + for (i = 0; i < MAX_AMMO_SLOTS; ++i) m_rgAmmo[i] = 0; m_bHasPrimary = false; @@ -5471,7 +5471,7 @@ void CBasePlayer::__MAKE_VHOOK(Spawn)(void) } else { - for (i = 0; i < MAX_AMMO_SLOTS; i++) + for (i = 0; i < MAX_AMMO_SLOTS; ++i) m_rgAmmoLast[i] = -1; } @@ -5481,9 +5481,9 @@ void CBasePlayer::__MAKE_VHOOK(Spawn)(void) m_bNightVisionOn = false; - for (i = 1; i <= gpGlobals->maxClients; i++) + for (i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pObserver = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pObserver = static_cast(UTIL_PlayerByIndex(i)); if (pObserver && pObserver->IsObservingPlayer(this)) { @@ -5571,7 +5571,7 @@ void CBasePlayer::__MAKE_VHOOK(Spawn)(void) sv_aim = CVAR_GET_POINTER("sv_aim"); - for (i = 0; i < ARRAYSIZE(m_flLastCommandTime); i++) + for (i = 0; i < ARRAYSIZE(m_flLastCommandTime); ++i) m_flLastCommandTime[i] = -1; } @@ -5635,9 +5635,9 @@ void CBasePlayer::SetScoreboardAttributes(CBasePlayer *destination) return; } - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *player = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *player = static_cast(UTIL_PlayerByIndex(i)); if (player != NULL && !FNullEnt(player->edict())) SetScoreboardAttributes(player); @@ -5789,7 +5789,7 @@ void CBasePlayer::SelectItem(const char *pstr) CBasePlayerItem *pItem = NULL; - for (int i = 0; i < MAX_ITEM_TYPES; i++) + for (int i = 0; i < MAX_ITEM_TYPES; ++i) { pItem = m_rgpPlayerItems[ i ]; @@ -5849,7 +5849,7 @@ void CBasePlayer::SelectLastItem(void) if (!m_pLastItem || m_pLastItem == m_pActiveItem) { - for (int i = 1; i < MAX_ITEMS; i++) + for (int i = 1; i < MAX_ITEMS; ++i) { CBasePlayerItem *pItem = m_rgpPlayerItems[i]; if (pItem != NULL && pItem != m_pActiveItem) @@ -5896,7 +5896,7 @@ void CBasePlayer::SelectLastItem(void) /* <15733a> ../cstrike/dlls/player.cpp:6967 */ BOOL CBasePlayer::HasWeapons(void) { - for (int i = 0; i < MAX_ITEM_TYPES; i++) + for (int i = 0; i < MAX_ITEM_TYPES; ++i) { if (m_rgpPlayerItems[i] != NULL) return TRUE; @@ -6319,7 +6319,7 @@ void CBasePlayer::CheatImpulseCommands(int iImpulse) { float bloodRange = r * 50.0f; - for (int i = 0; i < 50; i++) + for (int i = 0; i < 50; ++i) { dir.x = RANDOM_FLOAT(-1, 1); dir.y = RANDOM_FLOAT(-1, 1); @@ -6656,7 +6656,7 @@ int CBasePlayer::GetAmmoIndex(const char *psz) if (!psz) return -1; - for (int i = 1; i < MAX_AMMO_SLOTS; i++) + for (int i = 1; i < MAX_AMMO_SLOTS; ++i) { if (!IMPL_CLASS(CBasePlayerItem, AmmoInfoArray)[ i ].pszName) continue; @@ -6670,7 +6670,7 @@ int CBasePlayer::GetAmmoIndex(const char *psz) /* <158bf7> ../cstrike/dlls/player.cpp:7865 */ void CBasePlayer::SendAmmoUpdate(void) { - for (int i = 0; i < MAX_AMMO_SLOTS; i++) + for (int i = 0; i < MAX_AMMO_SLOTS; ++i) { if (m_rgAmmo[i] != m_rgAmmoLast[i]) { @@ -7020,7 +7020,7 @@ void CBasePlayer::__MAKE_VHOOK(UpdateClientData)(void) SendAmmoUpdate(); // Update all the items - for (int i = 0; i < MAX_ITEM_TYPES; i++) + for (int i = 0; i < MAX_ITEM_TYPES; ++i) { if (m_rgpPlayerItems[i]) { @@ -7069,7 +7069,7 @@ void CBasePlayer::__MAKE_VHOOK(UpdateClientData)(void) if ((pev->origin - m_vLastOrigin).Length() >= 64) { - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBaseEntity *pEntity = UTIL_PlayerByIndex(i); @@ -7428,7 +7428,7 @@ void CBasePlayer::UpdateStatusBar(void) } // Check values and send if they don't match - for (int i = 1; i < SBAR_END; i++) + for (int i = 1; i < SBAR_END; ++i) { if (newSBarState[ i ] != m_izSBarState[ i ] || bForceResend) { @@ -7464,7 +7464,7 @@ void CBasePlayer::DropPlayerItem(const char *pszItemName) return; } - for (int i = 0; i < MAX_ITEM_TYPES; i++) + for (int i = 0; i < MAX_ITEM_TYPES; ++i) { CBasePlayerItem *pWeapon = m_rgpPlayerItems[i]; @@ -7611,7 +7611,7 @@ BOOL CBasePlayer::HasNamedPlayerItem(const char *pszItemName) CBasePlayerItem *pItem; int i; - for (i = 0; i < MAX_ITEM_TYPES; i++) + for (i = 0; i < MAX_ITEM_TYPES; ++i) { pItem = m_rgpPlayerItems[ i ]; @@ -7765,7 +7765,7 @@ void CBasePlayer::SwitchTeam(void) SendItemStatus(this); SetProgressBarTime(0); - for (int i = 0; i < MAX_ITEM_TYPES; i++) + for (int i = 0; i < MAX_ITEM_TYPES; ++i) { m_pActiveItem = m_rgpPlayerItems[ i ]; @@ -7790,7 +7790,7 @@ void CBasePlayer::SwitchTeam(void) szNewTeam ); - CCSBot *pBot = reinterpret_cast(this); + CCSBot *pBot = static_cast(this); if (pBot->IsBot()) { @@ -8257,7 +8257,7 @@ void CBasePlayer::ResetStamina(void) float_precision GetPlayerPitch(const edict_t *pEdict) { entvars_t *pev = VARS((edict_t *)pEdict); - CBasePlayer *pPlayer = reinterpret_cast(CBasePlayer::Instance(pev)); + CBasePlayer *pPlayer = static_cast(CBasePlayer::Instance(pev)); if (!pPlayer) return 0.0f; @@ -8269,7 +8269,7 @@ float_precision GetPlayerPitch(const edict_t *pEdict) float_precision GetPlayerYaw(const edict_t *pEdict) { entvars_t *pev = VARS((edict_t *)pEdict); - CBasePlayer *pPlayer = reinterpret_cast(CBasePlayer::Instance(pev)); + CBasePlayer *pPlayer = static_cast(CBasePlayer::Instance(pev)); if (!pPlayer) return 0.0f; @@ -8281,7 +8281,7 @@ float_precision GetPlayerYaw(const edict_t *pEdict) int GetPlayerGaitsequence(const edict_t *pEdict) { entvars_t *pev = VARS((edict_t *)pEdict); - CBasePlayer *pPlayer = reinterpret_cast(CBasePlayer::Instance(pev)); + CBasePlayer *pPlayer = static_cast(CBasePlayer::Instance(pev)); if (!pPlayer) return 1; @@ -8424,7 +8424,7 @@ bool CBasePlayer::CanAffordPrimary(void) if (m_iTeam == CT) { WeaponStruct *temp; - for (int i = 0; i < MAX_WEAPONS; i++) + for (int i = 0; i < MAX_WEAPONS; ++i) { temp = &g_weaponStruct[ i ]; @@ -8435,7 +8435,7 @@ bool CBasePlayer::CanAffordPrimary(void) else if (m_iTeam == TERRORIST) { WeaponStruct *temp; - for (int i = 0; i < MAX_WEAPONS; i++) + for (int i = 0; i < MAX_WEAPONS; ++i) { temp = &g_weaponStruct[ i ]; @@ -8452,7 +8452,7 @@ bool CBasePlayer::CanAffordPrimaryAmmo(void) { CBasePlayerWeapon *primary = (CBasePlayerWeapon *)&m_rgpPlayerItems[ PRIMARY_WEAPON_SLOT ]; - for (int i = 0; i < MAX_WEAPONS; i++) + for (int i = 0; i < MAX_WEAPONS; ++i) { WeaponStruct *temp = &g_weaponStruct[ i ]; @@ -8468,7 +8468,7 @@ bool CBasePlayer::CanAffordSecondaryAmmo(void) { CBasePlayerWeapon *secondary = (CBasePlayerWeapon *)&m_rgpPlayerItems[ PISTOL_SLOT ]; - for (int i = 0; i < MAX_WEAPONS; i++) + for (int i = 0; i < MAX_WEAPONS; ++i) { WeaponStruct *temp = &g_weaponStruct[ i ]; @@ -8778,7 +8778,7 @@ const char *CBasePlayer::PickPrimaryCareerTaskWeapon(void) } buf[0] = '\0'; - primary = reinterpret_cast(m_rgpPlayerItems[PRIMARY_WEAPON_SLOT]); + primary = static_cast(m_rgpPlayerItems[PRIMARY_WEAPON_SLOT]); for (CareerTaskListIt it = TheCareerTasks->GetTasks()->begin(); it != TheCareerTasks->GetTasks()->end(); ++it) { @@ -8831,7 +8831,7 @@ const char *CBasePlayer::PickPrimaryCareerTaskWeapon(void) return NULL; } - for (int i = 0; i < taskNum; i++) + for (int i = 0; i < taskNum; ++i) { CCareerTask *pTask = taskVector[i]; @@ -8859,7 +8859,7 @@ const char *CBasePlayer::PickSecondaryCareerTaskWeapon(void) return NULL; } - secondary = reinterpret_cast(m_rgpPlayerItems[PISTOL_SLOT]); + secondary = static_cast(m_rgpPlayerItems[PISTOL_SLOT]); for (CareerTaskListIt it = TheCareerTasks->GetTasks()->begin(); it != TheCareerTasks->GetTasks()->end(); ++it) { @@ -8914,7 +8914,7 @@ const char *CBasePlayer::PickSecondaryCareerTaskWeapon(void) buf[0] = '\0'; - for (int i = 0; i < taskNum; i++) + for (int i = 0; i < taskNum; ++i) { CCareerTask *pTask = taskVector[i]; @@ -9000,7 +9000,7 @@ void CBasePlayer::PrioritizeAutoBuyString(char *autobuyString, const char *prior // get the next token from the priority string. while (*priorityChar != '\0' && *priorityChar != ' ') { - priorityToken[ i++ ] = *priorityChar; + priorityToken[i++] = *priorityChar; ++priorityChar; } @@ -9159,7 +9159,7 @@ AutoBuyInfoStruct *CBasePlayer::GetAutoBuyCommandInfo(const char *command) if (Q_stricmp(temp->m_command, command) == 0) ret = temp; - i++; + ++i; } return ret; @@ -9377,7 +9377,7 @@ void CBasePlayer::RebuyHEGrenade(void) int numToBuy = m_rebuyStruct.m_heGrenade - m_rgAmmo[ iAmmoIndex ]; - for (int i = 0; i < numToBuy; i++) + for (int i = 0; i < numToBuy; ++i) ClientCommand("hegren"); } @@ -9391,7 +9391,7 @@ void CBasePlayer::RebuyFlashbang(void) int numToBuy = m_rebuyStruct.m_flashbang - m_rgAmmo[ iAmmoIndex ]; - for (int i = 0; i < numToBuy; i++) + for (int i = 0; i < numToBuy; ++i) ClientCommand("flash"); } @@ -9405,7 +9405,7 @@ void CBasePlayer::RebuySmokeGrenade(void) int numToBuy = m_rebuyStruct.m_smokeGrenade - m_rgAmmo[ iAmmoIndex ]; - for (int i = 0; i < numToBuy; i++) + for (int i = 0; i < numToBuy; ++i) ClientCommand("sgren"); } @@ -9488,9 +9488,9 @@ void CBasePlayer::UpdateLocation(bool forceUpdate) m_flLastUpdateTime = gpGlobals->time; Q_snprintf(m_lastLocation, sizeof(m_lastLocation), "#%s", placeName); - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *player = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *player = static_cast(UTIL_PlayerByIndex(i)); if (!player) continue; diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index 08d4985a..7bcb89a2 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -50,7 +50,7 @@ #define PLAYER_FATAL_FALL_SPEED 1100.0f #define PLAYER_MAX_SAFE_FALL_SPEED 500.0f -#define PLAYER_SEARCH_RADIUS 64.0f +#define PLAYER_USE_RADIUS 64.0f #define ARMOR_RATIO 0.5 // Armor Takes 50% of the damage #define ARMOR_BONUS 0.5 // Each Point of Armor is work 1/x points of health diff --git a/regamedll/dlls/sound.cpp b/regamedll/dlls/sound.cpp index fe6df99b..804714fe 100644 --- a/regamedll/dlls/sound.cpp +++ b/regamedll/dlls/sound.cpp @@ -1058,11 +1058,11 @@ void USENTENCEG_InitLRU(unsigned char *plru, int count) if (count > CSENTENCE_LRU_MAX) count = CSENTENCE_LRU_MAX; - for (i = 0; i < count; i++) + for (i = 0; i < count; ++i) plru[i] = (unsigned char)i; // randomize array - for (i = 0; i < (count * 4); i++) + for (i = 0; i < (count * 4); ++i) { j = RANDOM_LONG(0, count - 1); k = RANDOM_LONG(0, count - 1); @@ -1148,7 +1148,7 @@ int USENTENCEG_Pick(int isentenceg, char *szfound) while (!ffound) { - for (i = 0; i < count; i++) + for (i = 0; i < count; ++i) { if (plru[i] != 0xFF) { @@ -1194,7 +1194,7 @@ int SENTENCEG_GetIndex(const char *szgroupname) if (!Q_strcmp(szgroupname, rgsentenceg[i].szgroupname)) return i; - i++; + ++i; } return -1; @@ -1339,7 +1339,7 @@ void SENTENCEG_Init(void) // skip whitespace i = 0; while (buffer[i] && buffer[i] == ' ') - i++; + ++i; if (!buffer[i]) continue; @@ -1428,7 +1428,7 @@ void SENTENCEG_Init(void) while (rgsentenceg[i].count && i < CSENTENCEG_MAX) { USENTENCEG_InitLRU(&(rgsentenceg[i].rgblru[0]), rgsentenceg[i].count); - i++; + ++i; } } @@ -1442,7 +1442,7 @@ int SENTENCEG_Lookup(const char *sample, char *sentencenum) // this is a sentence name; lookup sentence number // and give to engine as string. - for (i = 0; i < gcallsentences; i++) + for (i = 0; i < gcallsentences; ++i) { if (!Q_stricmp(gszallsentencenames[i], sample + 1)) { @@ -1552,7 +1552,7 @@ char *memfgets(byte *pMemFile, int fileSize, int &filePos, char *pBuffer, int bu { if (pMemFile[i] == '\n') stop = 1; - i++; + ++i; } // If we actually advanced the pointer, copy it over @@ -1604,7 +1604,7 @@ void TEXTURETYPE_Init(void) // skip whitespace i = 0; while (buffer[i] && isspace(buffer[i])) - i++; + ++i; if (!buffer[i]) continue; @@ -1618,7 +1618,7 @@ void TEXTURETYPE_Init(void) // skip whitespace while (buffer[i] && isspace(buffer[i])) - i++; + ++i; if (!buffer[i]) continue; @@ -1653,7 +1653,7 @@ char TEXTURETYPE_Find(char *name) { // CONSIDER: pre-sort texture names and perform faster binary search here - for (int i = 0; i < gcTextures; i++) + for (int i = 0; i < gcTextures; ++i) { if (!Q_strnicmp(name, &(grgszTextureName[ i ][0]), CBTEXTURENAMEMAX - 1)) return (grgchTextureType[ i ]); diff --git a/regamedll/dlls/soundent.cpp b/regamedll/dlls/soundent.cpp index e31a1d8c..2a4e8e81 100644 --- a/regamedll/dlls/soundent.cpp +++ b/regamedll/dlls/soundent.cpp @@ -220,7 +220,7 @@ void CSoundEnt::Initialize(void) m_iActiveSound = SOUNDLIST_EMPTY; // clear all sounds, and link them into the free sound list. - for (i = 0; i < MAX_WORLD_SOUNDS; i++) + for (i = 0; i < MAX_WORLD_SOUNDS; ++i) { m_SoundPool[ i ].Clear(); m_SoundPool[ i ].m_iNext = i + 1; @@ -230,7 +230,7 @@ void CSoundEnt::Initialize(void) m_SoundPool[ i - 1 ].m_iNext = SOUNDLIST_EMPTY; // now reserve enough sounds for each client - for (i = 0; i < gpGlobals->maxClients; i++) + for (i = 0; i < gpGlobals->maxClients; ++i) { iSound = pSoundEnt->IAllocSound(); @@ -284,8 +284,7 @@ int CSoundEnt::ISoundsInList(int iListType) while (iThisSound != SOUNDLIST_EMPTY) { - i++; - + ++i; iThisSound = m_SoundPool[ iThisSound ].m_iNext; } diff --git a/regamedll/dlls/subs.cpp b/regamedll/dlls/subs.cpp index c99ae5a6..cb8e11d6 100644 --- a/regamedll/dlls/subs.cpp +++ b/regamedll/dlls/subs.cpp @@ -113,7 +113,7 @@ void CBaseEntity::UpdateOnRemove(void) { // this entity was a LinkEnt in the world node graph, so we must remove it from // the graph since we are removing it from the world. - for (i = 0; i < WorldGraph.m_cLinks; i++) + for (i = 0; i < WorldGraph.m_cLinks; ++i) { if (WorldGraph.m_pLinkPool[i].m_pLinkEnt == pev) { diff --git a/regamedll/dlls/training_gamerules.cpp b/regamedll/dlls/training_gamerules.cpp index c3f8370e..2af97b9d 100644 --- a/regamedll/dlls/training_gamerules.cpp +++ b/regamedll/dlls/training_gamerules.cpp @@ -501,7 +501,7 @@ void CFuncWeaponCheck::__MAKE_VHOOK(Touch)(CBaseEntity *pOther) return; CBasePlayer *pPlayer = (CBasePlayer *)pOther; - for (int i = 1; i <= iItemCount; i++) + for (int i = 1; i <= iItemCount; ++i) { if (iAnyWeapon) { diff --git a/regamedll/dlls/triggers.cpp b/regamedll/dlls/triggers.cpp index b4fc68fb..9cbc4710 100644 --- a/regamedll/dlls/triggers.cpp +++ b/regamedll/dlls/triggers.cpp @@ -276,7 +276,7 @@ void CMultiManager::__MAKE_VHOOK(Spawn)(void) while (swapped) { swapped = 0; - for (int i = 1; i < m_cTargets; i++) + for (int i = 1; i < m_cTargets; ++i) { if (m_flTargetDelay[i] < m_flTargetDelay[i - 1]) { @@ -299,7 +299,7 @@ void CMultiManager::__MAKE_VHOOK(Restart)(void) { edict_t *pentTarget = NULL; - for (int i = 0; i < m_cTargets; i++) + for (int i = 0; i < m_cTargets; ++i) { const char *name = STRING(m_iTargetName[i]); @@ -334,7 +334,7 @@ void CMultiManager::__MAKE_VHOOK(Restart)(void) /* <1a1402> ../cstrike/dlls/triggers.cpp:420 */ BOOL CMultiManager::__MAKE_VHOOK(HasTarget)(string_t targetname) { - for (int i = 0; i < m_cTargets; i++) + for (int i = 0; i < m_cTargets; ++i) { if (FStrEq(STRING(targetname), STRING(m_iTargetName[i]))) { @@ -1363,7 +1363,7 @@ int CChangeLevel::AddTransitionToList(LEVELLIST *pLevelList, int listCount, cons return 0; } - for (i = 0; i < listCount; i++) + for (i = 0; i < listCount; ++i) { if (pLevelList[i].pentLandmark == pentLandmark && Q_strcmp(pLevelList[i].mapName, pMapName) == 0) { @@ -1477,7 +1477,7 @@ int CChangeLevel::ChangeList(LEVELLIST *pLevelList, int maxList) { CSave saveHelper((SAVERESTOREDATA *)gpGlobals->pSaveData); - for (i = 0; i < count; i++) + for (i = 0; i < count; ++i) { int j, entityCount = 0; CBaseEntity *pEntList[ MAX_ENTITY ]; @@ -1788,7 +1788,7 @@ void CBuyZone::BuyTouch(CBaseEntity *pOther) if (!pOther->IsPlayer()) return; - CBasePlayer *p = reinterpret_cast(pOther); + CBasePlayer *p = static_cast(pOther); if (pev->team == UNASSIGNED || pev->team == p->m_iTeam) { @@ -1814,7 +1814,7 @@ void CBombTarget::BombTargetTouch(CBaseEntity *pOther) if (!pOther->IsPlayer()) return; - CBasePlayer *p = reinterpret_cast(pOther); + CBasePlayer *p = static_cast(pOther); if (p->m_bHasC4) { @@ -1869,7 +1869,7 @@ void CEscapeZone::EscapeTouch(CBaseEntity *pOther) if (!pOther->IsPlayer()) return; - CBasePlayer *p = reinterpret_cast(pOther); + CBasePlayer *p = static_cast(pOther); switch (p->m_iTeam) { @@ -1887,9 +1887,9 @@ void CEscapeZone::EscapeTouch(CBaseEntity *pOther) GETPLAYERAUTHID(p->edict()) ); - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (pPlayer == NULL || FNullEnt(pPlayer->pev)) continue; @@ -1923,7 +1923,7 @@ void CVIP_SafetyZone::VIP_SafetyTouch(CBaseEntity *pOther) if (!pOther->IsPlayer()) return; - CBasePlayer *p = reinterpret_cast(pOther); + CBasePlayer *p = static_cast(pOther); p->m_signals.Signal(SIGNAL_VIPSAFETY); if (p->m_bIsVIP) diff --git a/regamedll/dlls/tutor.cpp b/regamedll/dlls/tutor.cpp index 4768167e..408017ee 100644 --- a/regamedll/dlls/tutor.cpp +++ b/regamedll/dlls/tutor.cpp @@ -91,9 +91,9 @@ void MonitorTutorStatus(void) else tutor_enableCvarExists = false; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(i)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(i)); if (pPlayer && !pPlayer->IsBot()) { diff --git a/regamedll/dlls/tutor_cs_tutor.cpp b/regamedll/dlls/tutor_cs_tutor.cpp index c91457c3..282002a9 100644 --- a/regamedll/dlls/tutor_cs_tutor.cpp +++ b/regamedll/dlls/tutor_cs_tutor.cpp @@ -3075,105 +3075,90 @@ void CCSTutor::CheckExamineMessages(float time) CBasePlayer *localPlayer = UTIL_GetLocalPlayer(); if (localPlayer == NULL) - { return; - } for (int i = 0; i < TUTOR_NUM_MESSAGES; ++i) { - //bool sawOne = false; - TutorMessage *message = GetTutorMessageDefinition(i); if (message == NULL || message->m_class != TUTORMESSAGECLASS_EXAMINE) - { continue; - } - - CBaseEntity *entity = GetEntityForMessageID(i); - - if (entity == NULL) - { - message->m_examineStartTime = -1.0f; - continue; - } + CBaseEntity *entity = NULL; bool isPlayerLooking = false; - if (i == YOU_SEE_FRIEND_CORPSE || i == YOU_SEE_ENEMY_CORPSE) + while ((entity = GetEntityForMessageID(i, entity)) != NULL) { - if (IsPlayerLookingAtPosition((Vector *)entity, localPlayer)) + if (i == YOU_SEE_FRIEND_CORPSE || i == YOU_SEE_ENEMY_CORPSE) + { + if (IsPlayerLookingAtPosition((Vector *)entity, localPlayer)) + { + isPlayerLooking = true; + break; + } + } + else if (i == YOU_SEE_HOSTAGE_CT_EXAMINE || i == YOU_SEE_FRIEND || i == YOU_SEE_ENEMY) + { + if (IsPlayerLookingAtEntity(entity, localPlayer)) + { + isPlayerLooking = true; + break; + } + } + else if (IsPlayerLookingAtPosition(&entity->pev->origin, localPlayer)) { isPlayerLooking = true; + break; } } - else if (i == YOU_SEE_HOSTAGE_CT_EXAMINE || i == YOU_SEE_FRIEND || i == YOU_SEE_ENEMY) + + if (isPlayerLooking) { - if (IsPlayerLookingAtEntity(entity, localPlayer)) + if (message->m_examineStartTime == -1.0f) + continue; + + if (time - message->m_examineStartTime <= cv_tutor_examine_time.value) + continue; + + bool validEntity = false; + if (i == YOU_SEE_FRIEND) { - isPlayerLooking = true; + CBasePlayer *player = static_cast(entity); + + if (player->IsPlayer() && player->IsAlive() && player->m_iTeam == localPlayer->m_iTeam) + validEntity = true; + } + else if (i == YOU_SEE_ENEMY) + { + CBasePlayer *player = static_cast(entity); + + if (player->IsPlayer() && player->IsAlive() && player->m_iTeam == localPlayer->m_iTeam) + { + if ((player->m_iTeam != CT || localPlayer->m_iTeam == TERRORIST) && (player->m_iTeam != TERRORIST || localPlayer->m_iTeam == CT)) + validEntity = true; + } + } + else if (i == YOU_SEE_HOSTAGE_CT_EXAMINE) + { + CHostage *hostage = static_cast(entity); + + if (entity->pev->takedamage == DAMAGE_YES) + { + if (!hostage->IsFollowingSomeone()) + validEntity = true; + } + + if (!hostage->IsValid() || !validEntity) + continue; + } + + if (validEntity) + { + CreateAndAddEventToList((TutorMessageID)i, entity); } - } - else if (IsPlayerLookingAtPosition(&entity->pev->origin, localPlayer)) - { - isPlayerLooking = true; } else - isPlayerLooking = false; - - entity = GetEntityForMessageID(i, entity); - - if (!isPlayerLooking) - { - if (entity == NULL) - { - message->m_examineStartTime = -1.0f; - continue; - } - } - - if (message->m_examineStartTime == -1.0f || (time - message->m_examineStartTime <= cv_tutor_examine_time.value)) - { - continue; - } - - bool validEntity = false; - - if (i == YOU_SEE_FRIEND) - { - CBasePlayer *player = static_cast(entity); - - if (player->IsPlayer() && player->IsAlive() && player->m_iTeam == localPlayer->m_iTeam) - validEntity = true; - } - else if (i == YOU_SEE_ENEMY) - { - CBasePlayer *player = static_cast(entity); - - if (player->IsPlayer() && player->IsAlive() && player->m_iTeam == localPlayer->m_iTeam) - { - if ((player->m_iTeam != CT || localPlayer->m_iTeam == TERRORIST) && (player->m_iTeam != TERRORIST || localPlayer->m_iTeam == CT)) - validEntity = true; - } - } - else if (i == YOU_SEE_HOSTAGE_CT_EXAMINE) - { - CHostage *hostage = static_cast(entity); - - if (entity->pev->takedamage == DAMAGE_YES) - { - if (!hostage->IsFollowingSomeone()) - validEntity = true; - } - - if (!hostage->IsValid() || !validEntity) - continue; - } - - if (validEntity) - { - CreateAndAddEventToList((TutorMessageID)i, entity); - } + message->m_examineStartTime = -1.0f; } } diff --git a/regamedll/dlls/util.cpp b/regamedll/dlls/util.cpp index 77369368..33022cbb 100644 --- a/regamedll/dlls/util.cpp +++ b/regamedll/dlls/util.cpp @@ -123,7 +123,7 @@ int g_groupop = 0; const int gSizes[18] = { 4, 4, 4, 4, 4, 4, 4, 12, 12, 4, 4, 4, 4, 2, 1, 4, 4, 4 }; -#else //HOOK_GAMEDLL +#else // HOOK_GAMEDLL unsigned int seed_table[256]; TYPEDESCRIPTION gEntvarsDescription[86]; @@ -133,7 +133,7 @@ int g_groupmask; const int gSizes[18]; -#endif //HOOK_GAMEDLL +#endif // HOOK_GAMEDLL float UTIL_WeaponTimeBase(void) { @@ -283,6 +283,7 @@ NOXREF float UTIL_AngleDiff(float destAngle, float srcAngle) if (delta <= -180.0f) delta += 360.0f; } + return delta; } @@ -312,7 +313,7 @@ int UTIL_EntitiesInBox(CBaseEntity **pList, int listMax, const Vector &mins, con if (!pEdict) return 0; - for (int i = 1; i < gpGlobals->maxEntities; i++, pEdict++) + for (int i = 1; i < gpGlobals->maxEntities; ++i, ++pEdict) { if (pEdict->free) continue; @@ -356,12 +357,12 @@ NOXREF int UTIL_MonstersInSphere(CBaseEntity ** pList, int listMax, const Vector if (!pEdict) return count; - for (int i = 1; i < gpGlobals->maxEntities; i++, pEdict++) + for (int i = 1; i < gpGlobals->maxEntities; ++i, ++pEdict) { if (pEdict->free) continue; - if (!(pEdict->v.flags & (FL_CLIENT|FL_MONSTER))) + if (!(pEdict->v.flags & (FL_CLIENT | FL_MONSTER))) continue; delta = center.x - pEdict->v.origin.x; @@ -404,7 +405,7 @@ NOXREF int UTIL_MonstersInSphere(CBaseEntity ** pList, int listMax, const Vector CBaseEntity *UTIL_FindEntityInSphere(CBaseEntity *pStartEntity, const Vector &vecCenter, float flRadius) { edict_t *pentEntity; - if (pStartEntity) + if (pStartEntity != NULL) pentEntity = pStartEntity->edict(); else pentEntity = NULL; @@ -422,7 +423,7 @@ CBaseEntity *UTIL_FindEntityInSphere(CBaseEntity *pStartEntity, const Vector &ve CBaseEntity *UTIL_FindEntityByString_Old(CBaseEntity *pStartEntity, const char *szKeyword, const char *szValue) { edict_t *pentEntity; - if (pStartEntity) + if (pStartEntity != NULL) pentEntity = pStartEntity->edict(); else pentEntity = NULL; @@ -535,7 +536,7 @@ CBaseEntity *UTIL_FindEntityGeneric(const char *szWhatever, const Vector &vecSrc { CBaseEntity *pSearch = NULL; CBaseEntity *pEntity = UTIL_FindEntityByTargetname(NULL, szWhatever); - if (pEntity) + if (pEntity != NULL) return pEntity; float flMaxDist2 = flRadius * flRadius; @@ -549,6 +550,7 @@ CBaseEntity *UTIL_FindEntityGeneric(const char *szWhatever, const Vector &vecSrc flMaxDist2 = flDist2; } } + return pEntity; } @@ -645,7 +647,7 @@ void UTIL_ScreenShake(const Vector ¢er, float amplitude, float frequency, fl shake.duration = FixedUnsigned16(duration, 1<<12); shake.frequency = FixedUnsigned16(frequency, 1<<8); - for (i = 1; i <= gpGlobals->maxClients; i++) + for (i = 1; i <= gpGlobals->maxClients; ++i) { CBaseEntity *pPlayer = UTIL_PlayerByIndex(i); if (!pPlayer || !(pPlayer->pev->flags & FL_ONGROUND)) @@ -717,7 +719,7 @@ void UTIL_ScreenFadeAll(const Vector &color, float fadeTime, float fadeHold, int int i; ScreenFade fade; UTIL_ScreenFadeBuild(fade, color, fadeTime, fadeHold, alpha, flags); - for (i = 1; i <= gpGlobals->maxClients; i++) + for (i = 1; i <= gpGlobals->maxClients; ++i) { CBaseEntity *pPlayer = UTIL_PlayerByIndex(i); UTIL_ScreenFadeWrite(fade, pPlayer); @@ -779,10 +781,10 @@ void UTIL_HudMessage(CBaseEntity *pEntity, const hudtextparms_t &textparms, cons /* <1ae1bf> ../cstrike/dlls/util.cpp:963 */ void UTIL_HudMessageAll(const hudtextparms_t &textparms, const char *pMessage) { - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBaseEntity *pPlayer = UTIL_PlayerByIndex(i); - if (pPlayer) + if (pPlayer != NULL) UTIL_HudMessage(pPlayer, textparms, pMessage); } } @@ -877,14 +879,14 @@ NOXREF char *UTIL_dtos4(int d) /* <1ae6c6> ../cstrike/dlls/util.cpp:1061 */ void UTIL_ShowMessageArgs(const char *pString, CBaseEntity *pPlayer, CUtlVector *args, bool isHint) { - if (pPlayer && pPlayer->IsNetClient()) + if (pPlayer != NULL && pPlayer->IsNetClient()) { MESSAGE_BEGIN(MSG_ONE, gmsgHudTextArgs, NULL, pPlayer->pev); WRITE_STRING(pString); WRITE_BYTE(isHint); WRITE_BYTE(args->Count()); - for (int i = 0; i < args->Count(); i++) + for (int i = 0; i < args->Count(); ++i) WRITE_STRING(args->Element(i)); MESSAGE_END(); @@ -913,10 +915,10 @@ void UTIL_ShowMessage(const char *pString, CBaseEntity *pEntity, bool isHint) /* <1ae8ac> ../cstrike/dlls/util.cpp:1095 */ void UTIL_ShowMessageAll(const char *pString, bool isHint) { - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBaseEntity *pPlayer = UTIL_PlayerByIndex(i); - if (pPlayer) + if (pPlayer != NULL) UTIL_ShowMessage(pString, pPlayer, isHint); } } @@ -980,7 +982,8 @@ float UTIL_VecToYaw(const Vector &vec) void UTIL_SetOrigin(entvars_t *pev, const Vector &vecOrigin) { edict_t *ent = ENT(pev); - if (ent) + + if (ent != NULL) SET_ORIGIN(ent, vecOrigin); } @@ -1000,6 +1003,7 @@ float UTIL_Approach(float target, float value, float speed) value -= speed; else value = target; + return value; } @@ -1024,6 +1028,7 @@ float_precision UTIL_ApproachAngle(float target, float value, float speed) value -= speed; else value = target; + return value; } @@ -1105,6 +1110,7 @@ BOOL UTIL_ShouldShowBlood(int color) return TRUE; } } + return FALSE; } @@ -1231,6 +1237,7 @@ void UTIL_DecalTrace(TraceResult *pTrace, int decalNumber) index -= 256; } } + MESSAGE_BEGIN(MSG_BROADCAST, SVC_TEMPENTITY); WRITE_BYTE(message); WRITE_COORD(pTrace->vecEndPos.x); @@ -1330,6 +1337,7 @@ BOOL UTIL_TeamsMatch(const char *pTeamName1, const char *pTeamName2) if (!Q_stricmp(pTeamName1, pTeamName2)) return TRUE; } + return FALSE; } @@ -1506,7 +1514,7 @@ void UTIL_BubbleTrail(Vector from, Vector to, int count) /* <1afcfe> ../cstrike/dlls/util.cpp:1731 */ void UTIL_Remove(CBaseEntity *pEntity) { - if (pEntity) + if (pEntity != NULL) { pEntity->UpdateOnRemove(); pEntity->pev->flags |= FL_KILLME; @@ -1570,9 +1578,9 @@ void UTIL_StripToken(const char *pKey, char *pDest) while (pKey[i] && pKey[i] != '#') { pDest[i] = pKey[i]; - i++; + ++i; } - pDest[i] = 0; + pDest[i] = '\0'; } /* <1b003a> ../cstrike/dlls/util.cpp:1847 */ @@ -1623,12 +1631,13 @@ int CSaveRestoreBuffer::EntityIndex(edict_t *pentLookup) if (!m_pdata || !pentLookup) return -1; - for (int i = 0; i < m_pdata->tableCount; i++) + for (int i = 0; i < m_pdata->tableCount; ++i) { ENTITYTABLE *pTable = &m_pdata->pTable[i]; if (pTable->pent == pentLookup) return i; } + return -1; } @@ -1638,12 +1647,13 @@ edict_t *CSaveRestoreBuffer::EntityFromIndex(int entityIndex) if (!m_pdata || entityIndex < 0) return NULL; - for (int i = 0; i < m_pdata->tableCount; i++) + for (int i = 0; i < m_pdata->tableCount; ++i) { ENTITYTABLE *pTable = &m_pdata->pTable[i]; if (pTable->id == entityIndex) return pTable->pent; } + return NULL; } @@ -1691,6 +1701,7 @@ extern "C" if (lobit) num |= 0x80000000; } + return num; } } @@ -1710,7 +1721,7 @@ unsigned int CSaveRestoreBuffer::HashString(const char *pszToken) unsigned short CSaveRestoreBuffer::TokenHash(const char *pszToken) { unsigned short hash = (unsigned short)(HashString(pszToken) % (unsigned)m_pdata->tokenCount); - for (int i = 0; i < m_pdata->tokenCount; i++) + for (int i = 0; i < m_pdata->tokenCount; ++i) { int index = hash + i; if (index >= m_pdata->tokenCount) @@ -1757,7 +1768,7 @@ void CSave::WriteTime(const char *pname, const float *data, int count) int i; BufferHeader(pname, sizeof(float) * count); - for (i = 0; i < count; i++) + for (i = 0; i < count; ++i) { float tmp = data[0]; @@ -1781,11 +1792,11 @@ void CSave::WriteString(const char *pname, const int *stringId, int count) int i; int size = 0; - for (i = 0; i < count; i++) + for (i = 0; i < count; ++i) size += Q_strlen(STRING(stringId[i])) + 1; BufferHeader(pname, size); - for (i = 0; i < count; i++) + for (i = 0; i < count; ++i) { const char *pString = STRING(stringId[i]); BufferData(pString, Q_strlen(pString) + 1); @@ -1820,7 +1831,7 @@ NOXREF void CSave::WritePositionVector(const char *pname, const Vector &value) void CSave::WritePositionVector(const char *pname, const float *value, int count) { BufferHeader(pname, sizeof(float) * 3 * count); - for (int i = 0; i < count; i++) + for (int i = 0; i < count; ++i) { Vector tmp(value[0], value[1], value[2]); @@ -1846,7 +1857,7 @@ void CSave::WriteFunction(const char *pname, void **data, int count) /* <1b2e7a> ../cstrike/dlls/util.cpp:2157 */ void EntvarsKeyvalue(entvars_t *pev, KeyValueData *pkvd) { - for (int i = 0; i < ARRAYSIZE(gEntvarsDescription); i++) + for (int i = 0; i < ARRAYSIZE(gEntvarsDescription); ++i) { TYPEDESCRIPTION *pField = &gEntvarsDescription[i]; @@ -1898,7 +1909,7 @@ int CSave::WriteFields(const char *pname, void *pBaseData, TYPEDESCRIPTION *pFie int i; int emptyCount = 0; - for (i = 0; i < fieldCount; i++) + for (i = 0; i < fieldCount; ++i) { void *pOutputData = ((char *)pBaseData + pFields[i].fieldOffset); if (DataEmpty((const char *)pOutputData, pFields[i].fieldSize * gSizes[pFields[i].fieldType])) @@ -1909,7 +1920,7 @@ int CSave::WriteFields(const char *pname, void *pBaseData, TYPEDESCRIPTION *pFie int actualCount = fieldCount - emptyCount; WriteInt(pname, &actualCount, 1); - for (i = 0; i < fieldCount; i++) + for (i = 0; i < fieldCount; ++i) { TYPEDESCRIPTION *pTest = &pFields[i]; void *pOutputData = ((char *)pBaseData + pTest->fieldOffset); @@ -1994,6 +2005,7 @@ int CSave::WriteFields(const char *pname, void *pBaseData, TYPEDESCRIPTION *pFie default: ALERT(at_error, "Bad field type\n"); } } + return 1; } @@ -2008,11 +2020,12 @@ NOXREF void CSave::BufferString(char *pdata, int len) /* <1b3f5d> ../cstrike/dlls/util.cpp:2333 */ int CSave::DataEmpty(const char *pdata, int size) { - for (int i = 0; i < size; i++) + for (int i = 0; i < size; ++i) { if (pdata[i]) return 0; } + return 1; } @@ -2064,7 +2077,7 @@ int CRestore::ReadField(void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCoun if (m_pdata->fUseLandmark) position = m_pdata->vecLandmarkOffset; } - for (int i = 0; i < fieldCount; i++) + for (int i = 0; i < fieldCount; ++i) { int fieldNumber = (i + startField) % fieldCount; TYPEDESCRIPTION *pTest = &pFields[fieldNumber]; @@ -2244,12 +2257,12 @@ int CRestore::ReadFields(const char *pname, void *pBaseData, TYPEDESCRIPTION *pF int fileCount = ReadInt(); int lastField = 0; - for (i = 0; i < fieldCount; i++) + for (i = 0; i < fieldCount; ++i) { if (!m_global || !(pFields[i].flags & FTYPEDESC_GLOBAL)) Q_memset(((char *)pBaseData + pFields[i].fieldOffset), 0, pFields[i].fieldSize * gSizes[pFields[i].fieldType]); } - for (i = 0; i < fileCount; i++) + for (i = 0; i < fileCount; ++i) { HEADER header; BufferReadHeader(&header); @@ -2369,6 +2382,7 @@ NOXREF int CRestore::BufferCheckZString(const char *string) if (!strncmp(string, m_pdata->pCurrentData, len)) return 1; } + return 0; } @@ -2402,18 +2416,19 @@ char UTIL_TextureHit(TraceResult *ptr, Vector vecSrc, Vector vecEnd) pTextureName++; Q_strcpy(szbuffer, pTextureName); - szbuffer[16] = 0; + szbuffer[16] = '\0'; chTextureType = TEXTURETYPE_Find(szbuffer); } else - chTextureType = 0; + chTextureType = '\0'; + return chTextureType; } /* <1b5330> ../cstrike/dlls/util.cpp:2767 */ NOXREF int GetPlayerTeam(int index) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(index)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(index)); if (pPlayer != NULL) { return pPlayer->m_iTeam; @@ -2440,7 +2455,7 @@ bool UTIL_IsGame(const char *gameName) /* <1b5470> ../cstrike/dlls/util.cpp:2802 */ float_precision UTIL_GetPlayerGaitYaw(int playerIndex) { - CBasePlayer *pPlayer = reinterpret_cast(UTIL_PlayerByIndex(playerIndex)); + CBasePlayer *pPlayer = static_cast(UTIL_PlayerByIndex(playerIndex)); if (pPlayer != NULL) { return pPlayer->m_flGaityaw; diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index 30b71b8b..56679713 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -78,7 +78,7 @@ MULTIDAMAGE gMultiDamage; /* <1d018e> ../cstrike/dlls/weapons.cpp:82 */ int MaxAmmoCarry(int iszName) { - for (int i = 0; i < MAX_WEAPONS; i++) + for (int i = 0; i < MAX_WEAPONS; ++i) { ItemInfo *info = &IMPL_CLASS(CBasePlayerItem, ItemInfoArray)[ i ]; @@ -229,7 +229,7 @@ NOXREF void EjectBrass2(const Vector &vecOrigin, const Vector &vecVelocity, floa void AddAmmoNameToAmmoRegistry(const char *szAmmoname) { // make sure it's not already in the registry - for (int i = 0; i < MAX_AMMO_SLOTS; i++) + for (int i = 0; i < MAX_AMMO_SLOTS; ++i) { if (!IMPL_CLASS(CBasePlayerItem, AmmoInfoArray)[ i ].pszName) continue; @@ -1716,7 +1716,7 @@ void CWeaponBox::Kill(void) int i; // destroy the weapons - for (i = 0; i < MAX_ITEM_TYPES; i++) + for (i = 0; i < MAX_ITEM_TYPES; ++i) { pWeapon = m_rgpPlayerItems[i]; @@ -1768,7 +1768,7 @@ void CWeaponBox::__MAKE_VHOOK(Touch)(CBaseEntity *pOther) // go through my weapons and try to give the usable ones to the player. // it's important the the player be given ammo first, so the weapons code doesn't refuse // to deploy a better weapon that the player may pick up because he has no ammo for it. - for (int i = 0; i < MAX_ITEM_TYPES; i++) + for (int i = 0; i < MAX_ITEM_TYPES; ++i) { if (!m_rgpPlayerItems[i]) { @@ -2035,7 +2035,7 @@ int CWeaponBox::GiveAmmo(int iCount, char *szName, int iMax, int *pIndex) { int i; - for (i = 1; i < MAX_AMMO_SLOTS && !FStringNull(m_rgiszAmmo[i]); i++) + for (i = 1; i < MAX_AMMO_SLOTS && !FStringNull(m_rgiszAmmo[i]); ++i) { if (!Q_stricmp(szName, STRING(m_rgiszAmmo[i]))) { @@ -2096,7 +2096,7 @@ BOOL CWeaponBox::IsEmpty(void) { int i; - for (i = 0; i < MAX_ITEM_TYPES; i++) + for (i = 0; i < MAX_ITEM_TYPES; ++i) { if (m_rgpPlayerItems[i]) { @@ -2104,7 +2104,7 @@ BOOL CWeaponBox::IsEmpty(void) } } - for (i = 0; i < MAX_AMMO_SLOTS; i++) + for (i = 0; i < MAX_AMMO_SLOTS; ++i) { if (m_rgiszAmmo[i]) { diff --git a/regamedll/dlls/weapons.h b/regamedll/dlls/weapons.h index 54c46357..3c5d26ff 100644 --- a/regamedll/dlls/weapons.h +++ b/regamedll/dlls/weapons.h @@ -95,14 +95,6 @@ enum ArmouryItemPack ARMOURY_SMOKEGRENADE, }; -struct BuyInfo -{ - WeaponType type; - bool preferred; - char *buyAlias; - -};/* size: 12, cachelines: 1, members: 3 */ - struct ItemInfo { int iSlot; diff --git a/regamedll/dlls/weapontype.cpp b/regamedll/dlls/weapontype.cpp index 54eb7caa..b1cc4e8e 100644 --- a/regamedll/dlls/weapontype.cpp +++ b/regamedll/dlls/weapontype.cpp @@ -247,7 +247,7 @@ const char *BuyAliasToWeaponID(const char *alias, WeaponIdType &id) { if (alias) { - for (int i = 0; weaponBuyAliasInfo[i].alias != NULL; i++) + for (int i = 0; weaponBuyAliasInfo[i].alias != NULL; ++i) { if (!Q_stricmp(weaponBuyAliasInfo[i].alias, alias)) { @@ -266,7 +266,7 @@ const char *BuyAliasToWeaponID(const char *alias, WeaponIdType &id) /* <22cd03> ../cstrike/dlls/weapontype.cpp:246 */ const char *WeaponIDToAlias(int id) { - for (int i = 0; weaponAliasInfo[i].alias != NULL; i++) + for (int i = 0; weaponAliasInfo[i].alias != NULL; ++i) { if (weaponAliasInfo[i].id == id) return weaponAliasInfo[i].alias; @@ -280,7 +280,7 @@ WeaponClassType AliasToWeaponClass(const char *alias) { if (alias != NULL) { - for (int i = 0; weaponClassAliasInfo[i].alias != NULL; i++) + for (int i = 0; weaponClassAliasInfo[i].alias != NULL; ++i) { if (!Q_stricmp(weaponClassAliasInfo[i].alias, alias)) return weaponClassAliasInfo[i].id; @@ -354,7 +354,7 @@ NOXREF bool IsSecondaryWeapon(int id) /* <22cf48> ../cstrike/dlls/weapontype.cpp:426 */ WeaponInfoStruct *GetWeaponInfo(int weaponID) { - for (int i = 0; weaponInfo[i].id != 0; i++) + for (int i = 0; weaponInfo[i].id != 0; ++i) { if (weaponInfo[i].id == weaponID) return &weaponInfo[i]; @@ -372,63 +372,7 @@ bool CanBuyWeaponByMaptype(int playerTeam, WeaponIdType weaponID, bool useAssasi { switch (weaponID) { - case WEAPON_P228: - case WEAPON_XM1014: - case WEAPON_AUG: - case WEAPON_FIVESEVEN: - case WEAPON_UMP45: - case WEAPON_SG550: - case WEAPON_FAMAS: - case WEAPON_USP: - case WEAPON_GLOCK18: - case WEAPON_MP5N: - case WEAPON_M249: - case WEAPON_M3: - case WEAPON_M4A1: - case WEAPON_TMP: - case WEAPON_DEAGLE: - case WEAPON_P90: - case WEAPON_SHIELDGUN: - { - return true; - } - default: - { - return false; - } - } - } - else if (playerTeam == TERRORIST) - { - switch (weaponID) - { - case WEAPON_P228: - case WEAPON_MAC10: - case WEAPON_ELITE: - case WEAPON_UMP45: - case WEAPON_GALIL: - case WEAPON_USP: - case WEAPON_GLOCK18: - case WEAPON_AWP: - case WEAPON_DEAGLE: - case WEAPON_AK47: - { - return true; - } - default: - { - return false; - } - } - } - return false; - } - if (playerTeam == CT) - { - switch (weaponID) - { case WEAPON_P228: - case WEAPON_SCOUT: case WEAPON_XM1014: case WEAPON_AUG: case WEAPON_FIVESEVEN: @@ -437,7 +381,6 @@ bool CanBuyWeaponByMaptype(int playerTeam, WeaponIdType weaponID, bool useAssasi case WEAPON_FAMAS: case WEAPON_USP: case WEAPON_GLOCK18: - case WEAPON_AWP: case WEAPON_MP5N: case WEAPON_M249: case WEAPON_M3: @@ -446,22 +389,16 @@ bool CanBuyWeaponByMaptype(int playerTeam, WeaponIdType weaponID, bool useAssasi case WEAPON_DEAGLE: case WEAPON_P90: case WEAPON_SHIELDGUN: - { return true; - } default: - { return false; } } - } - else if (playerTeam == TERRORIST) - { - switch (weaponID) + else if (playerTeam == TERRORIST) { + switch (weaponID) + { case WEAPON_P228: - case WEAPON_SCOUT: - case WEAPON_XM1014: case WEAPON_MAC10: case WEAPON_ELITE: case WEAPON_UMP45: @@ -469,22 +406,70 @@ bool CanBuyWeaponByMaptype(int playerTeam, WeaponIdType weaponID, bool useAssasi case WEAPON_USP: case WEAPON_GLOCK18: case WEAPON_AWP: - case WEAPON_MP5N: - case WEAPON_M249: - case WEAPON_M3: - case WEAPON_G3SG1: case WEAPON_DEAGLE: - case WEAPON_SG552: case WEAPON_AK47: - case WEAPON_P90: - { return true; - } default: - { return false; } } + + return false; + } + if (playerTeam == CT) + { + switch (weaponID) + { + case WEAPON_P228: + case WEAPON_SCOUT: + case WEAPON_XM1014: + case WEAPON_AUG: + case WEAPON_FIVESEVEN: + case WEAPON_UMP45: + case WEAPON_SG550: + case WEAPON_FAMAS: + case WEAPON_USP: + case WEAPON_GLOCK18: + case WEAPON_AWP: + case WEAPON_MP5N: + case WEAPON_M249: + case WEAPON_M3: + case WEAPON_M4A1: + case WEAPON_TMP: + case WEAPON_DEAGLE: + case WEAPON_P90: + case WEAPON_SHIELDGUN: + return true; + default: + return false; + } + } + else if (playerTeam == TERRORIST) + { + switch (weaponID) + { + case WEAPON_P228: + case WEAPON_SCOUT: + case WEAPON_XM1014: + case WEAPON_MAC10: + case WEAPON_ELITE: + case WEAPON_UMP45: + case WEAPON_GALIL: + case WEAPON_USP: + case WEAPON_GLOCK18: + case WEAPON_AWP: + case WEAPON_MP5N: + case WEAPON_M249: + case WEAPON_M3: + case WEAPON_G3SG1: + case WEAPON_DEAGLE: + case WEAPON_SG552: + case WEAPON_AK47: + case WEAPON_P90: + return true; + default: + return false; + } } return false; diff --git a/regamedll/dlls/weapontype.h b/regamedll/dlls/weapontype.h index 19ad8533..8deff4db 100644 --- a/regamedll/dlls/weapontype.h +++ b/regamedll/dlls/weapontype.h @@ -338,22 +338,10 @@ enum InventorySlotType GRENADE_SLOT, C4_SLOT, }; - -enum WeaponType -{ - PISTOL = 0, - SHOTGUN, - SUB_MACHINE_GUN, - RIFLE, - MACHINE_GUN, - SNIPER_RIFLE, - GRENADE, - NUM_WEAPON_TYPES, -}; enum Bullet { - BULLET_NONE = 0, + BULLET_NONE, BULLET_PLAYER_9MM, BULLET_PLAYER_MP5, BULLET_PLAYER_357, @@ -376,26 +364,26 @@ struct AutoBuyInfoStruct AutoBuyClassType m_class; char *m_command; char *m_classname; -};/* size: 12, cachelines: 1, members: 3 */ +}; struct WeaponAliasInfo { char *alias; WeaponIdType id; -};/* size: 8, cachelines: 1, members: 2 */ +}; struct WeaponBuyAliasInfo { char *alias; WeaponIdType id; char *failName; -};/* size: 12, cachelines: 1, members: 3 */ +}; struct WeaponClassAliasInfo { char *alias; WeaponClassType id; -};/* size: 8, cachelines: 1, members: 2 */ +}; struct WeaponInfoStruct { diff --git a/regamedll/dlls/world.cpp b/regamedll/dlls/world.cpp index 9008734e..ef8d6a02 100644 --- a/regamedll/dlls/world.cpp +++ b/regamedll/dlls/world.cpp @@ -330,7 +330,7 @@ int CGlobalState::Save(CSave &save) } pEntity = m_pList; - for (i = 0; i < m_listCount && pEntity != NULL; i++) + for (i = 0; i < m_listCount && pEntity != NULL; ++i) { if (!save.WriteFields("GENT", pEntity, gGlobalEntitySaveData, ARRAYSIZE(gGlobalEntitySaveData))) { @@ -362,7 +362,7 @@ int CGlobalState::Restore(CRestore &restore) // Clear loaded data m_listCount = 0; - for (i = 0; i < listCount; i++) + for (i = 0; i < listCount; ++i) { if (!restore.ReadFields("GENT", &tmpEntity, gGlobalEntitySaveData, ARRAYSIZE(gGlobalEntitySaveData))) { @@ -605,7 +605,7 @@ void CWorld::__MAKE_VHOOK(Precache)(void) // 63 testing LIGHT_STYLE(63, "a"); - for (int i = 0; i < ARRAYSIZE(gDecals); i++) + for (int i = 0; i < ARRAYSIZE(gDecals); ++i) gDecals[i].index = DECAL_INDEX(gDecals[i].name); // init the WorldGraph. diff --git a/regamedll/game_shared/bot/bot_manager.cpp b/regamedll/game_shared/bot/bot_manager.cpp index dcc470f0..6f2e8ac5 100644 --- a/regamedll/game_shared/bot/bot_manager.cpp +++ b/regamedll/game_shared/bot/bot_manager.cpp @@ -235,7 +235,7 @@ const char *CBotManager::GetNavMapFilename(void) const void CBotManager::__MAKE_VHOOK(OnEvent)(GameEventType event, CBaseEntity *entity, CBaseEntity *other) { // propogate event to all bots - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBasePlayer *player = static_cast(UTIL_PlayerByIndex(i)); diff --git a/regamedll/game_shared/bot/bot_profile.h b/regamedll/game_shared/bot/bot_profile.h index b2944486..05135d04 100644 --- a/regamedll/game_shared/bot/bot_profile.h +++ b/regamedll/game_shared/bot/bot_profile.h @@ -150,7 +150,7 @@ inline void BotProfile::Inherit(const BotProfile *parent, const BotProfile *base if (parent->m_weaponPreferenceCount != baseline->m_weaponPreferenceCount) { m_weaponPreferenceCount = parent->m_weaponPreferenceCount; - for (int i = 0; im_weaponPreferenceCount; i++) + for (int i = 0; i < parent->m_weaponPreferenceCount; ++i) m_weaponPreference[i] = parent->m_weaponPreference[i]; } diff --git a/regamedll/game_shared/bot/nav.h b/regamedll/game_shared/bot/nav.h index 5296df5a..38e42a27 100644 --- a/regamedll/game_shared/bot/nav.h +++ b/regamedll/game_shared/bot/nav.h @@ -318,10 +318,10 @@ inline void SnapToGrid(float *value) } // custom -inline float SnapToGrid(float v) +inline float SnapToGrid(float value) { - int c = v / GenerationStepSize; - return c; + int c = value / GenerationStepSize; + return c * GenerationStepSize; } /* <14ea2f> ../game_shared/bot/nav.h:251 */ diff --git a/regamedll/game_shared/bot/nav_area.cpp b/regamedll/game_shared/bot/nav_area.cpp index 672a4aad..da093037 100644 --- a/regamedll/game_shared/bot/nav_area.cpp +++ b/regamedll/game_shared/bot/nav_area.cpp @@ -1053,7 +1053,7 @@ inline CNavArea *FindFirstAreaInDirection(const Vector *start, NavDirType dir, f Vector pos = *start; int end = (int)((range / GenerationStepSize) + 0.5f); - for (int i = 1; i <= end; i++) + for (int i = 1; i <= end; ++i) { AddDirectionVector(&pos, dir, GenerationStepSize); @@ -1872,7 +1872,7 @@ void GenerateNavigationAreaMesh(void) while (uncoveredNodes > 0) { - for (CNavNode *node = CNavNode::GetFirst(); node; node = node->GetNext()) + for (CNavNode *node = CNavNode::GetFirst(); node != NULL; node = node->GetNext()) { if (node->IsCovered()) continue; @@ -2260,7 +2260,7 @@ CNavArea *CNavArea::GetRandomAdjacentArea(NavDirType dir) const if (i == which) return (*iter).area; - i++; + ++i; } return NULL; @@ -2556,7 +2556,7 @@ void CNavArea::DrawMarkedCorner(NavCornerType corner, byte red, byte green, byte se.x -= border; se.y -= border; - switch(corner) + switch (corner) { case NORTH_WEST: UTIL_DrawBeamPoints(nw + Vector(0, 0, 10), nw, duration, red, green, blue); @@ -2684,7 +2684,7 @@ const Vector *CNavArea::GetCorner(NavCornerType corner) const { static Vector pos; - switch(corner) + switch (corner) { case NORTH_WEST: return &m_extent.lo; @@ -2824,7 +2824,7 @@ void CNavArea::ComputeHidingSpots(void) } } - switch(d) + switch (d) { case NORTH: if (extent.lo - m_extent.lo.x >= cornerSize) @@ -3742,7 +3742,6 @@ void CNavArea::DrawConnectedAreas(void) NavDirType dir = (NavDirType)dirSet[i]; int count = GetAdjacentCount(dir); - for (int a = 0; a < count; ++a) { CNavArea *adj = GetAdjacentArea(dir, a); @@ -3787,7 +3786,7 @@ void CNavArea::DrawConnectedAreas(void) float size = 5.0f; ComputePortal(adj, dir, &hookPos, &halfWidth); - switch(dir) + switch (dir) { case NORTH: from = hookPos + Vector(0.0f, size, 0.0f); @@ -4086,7 +4085,7 @@ void EditNavAreas(NavEditCmdType cmd) { area->DrawConnectedAreas(); - switch(cmd) + switch (cmd) { case EDIT_TOGGLE_PLACE_MODE: EMIT_SOUND_DYN(ENT(UTIL_GetLocalPlayer()->pev), CHAN_ITEM, "buttons/blip1.wav", 1, ATTN_NORM, 0, 100); @@ -4790,25 +4789,24 @@ CNavAreaGrid::CNavAreaGrid(void) : m_cellSize(300.0f) /* <4c4a70> ../game_shared/bot/nav_area.cpp:4953 */ CNavAreaGrid::~CNavAreaGrid(void) { - delete [] m_grid; + delete[] m_grid; m_grid = NULL; } +// Clear the grid + /* <4cf837> ../game_shared/bot/nav_area.cpp:4962 */ void CNavAreaGrid::Reset(void) { if (m_grid) - { - // TODO: FIX ME - //delete[] m_grid; - } + delete[] m_grid; m_grid = NULL; m_gridSizeX = 0; m_gridSizeY = 0; // clear the hash table - for (int i = 0; i < HASH_TABLE_SIZE; i++) + for (int i = 0; i < HASH_TABLE_SIZE; ++i) m_hashTable[i] = NULL; m_areaCount = 0; @@ -4817,6 +4815,8 @@ void CNavAreaGrid::Reset(void) EditNavAreasReset(); } +// Allocate the grid and define its extents + /* <4cf984> ../game_shared/bot/nav_area.cpp:4983 */ void CNavAreaGrid::Initialize(float minX, float maxX, float minY, float maxY) { @@ -4826,8 +4826,8 @@ void CNavAreaGrid::Initialize(float minX, float maxX, float minY, float maxY) m_minX = minX; m_minY = minY; - m_gridSizeX = ((maxX - minX) / m_cellSize) + 1; - m_gridSizeY = ((maxY - minY) / m_cellSize) + 1; + m_gridSizeX = (int)((maxX - minX) / m_cellSize + 1); + m_gridSizeY = (int)((maxY - minY) / m_cellSize + 1); m_grid = new NavAreaList[ m_gridSizeX * m_gridSizeY ]; } @@ -4846,8 +4846,10 @@ void CNavAreaGrid::AddNavArea(CNavArea *area) int hiY = WorldToGridY(extent->hi.y); for (int y = loY; y <= hiY; ++y) + { for (int x = loX; x <= hiX; ++x) m_grid[ x + y*m_gridSizeX ].push_back(const_cast(area)); + } // add to hash table int key = ComputeHashKey(area->GetID()); diff --git a/regamedll/game_shared/bot/nav_file.cpp b/regamedll/game_shared/bot/nav_file.cpp index 3b30de1f..68dd2091 100644 --- a/regamedll/game_shared/bot/nav_file.cpp +++ b/regamedll/game_shared/bot/nav_file.cpp @@ -129,7 +129,7 @@ void PlaceDirectory::Load(SteamFile *file) // read each entry char placeName[256]; unsigned short len; - for (int i = 0; i < count; i++) + for (int i = 0; i < count; ++i) { file->Read(&len, sizeof(unsigned short)); file->Read(placeName, len); @@ -190,7 +190,7 @@ void CNavArea::Save(int fd, unsigned int version) // save connections to adjacent areas // in the enum order NORTH, EAST, SOUTH, WEST - for (int d = 0; d < NUM_DIRECTIONS; d++) + for (int d = 0; d < NUM_DIRECTIONS; ++d) { // save number of connections for this direction unsigned int count = m_connect[d].size(); @@ -360,13 +360,13 @@ void CNavArea::Load(SteamFile *file, unsigned int version) // load connections (IDs) to adjacent areas // in the enum order NORTH, EAST, SOUTH, WEST - for (int d = 0; d < NUM_DIRECTIONS; d++) + for (int d = 0; d < NUM_DIRECTIONS; ++d) { // load number of connections for this direction unsigned int count; file->Read(&count, sizeof(unsigned int)); - for (unsigned int i = 0; iRead(&connect.id, sizeof(unsigned int)); @@ -509,7 +509,7 @@ NavErrorType CNavArea::PostLoad(void) NavErrorType error = NAV_OK; // connect areas together - for (int d = 0; d < NUM_DIRECTIONS; d++) + for (int d = 0; d < NUM_DIRECTIONS; ++d) { NavConnectList::iterator iter; for (iter = m_connect[d].begin(); iter != m_connect[d].end(); ++iter) @@ -946,7 +946,7 @@ NavErrorType LoadNavigationMap(void) extent.hi.y = -9999999999.9f; // load the areas and compute total extent - for (unsigned int i = 0; i < count; i++) + for (unsigned int i = 0; i < count; ++i) { CNavArea *area = new CNavArea; area->Load(&navFile, version); diff --git a/regamedll/hookers/6153_hooker.cpp b/regamedll/hookers/6153_hooker.cpp index 0d39b27e..d00c9d73 100644 --- a/regamedll/hookers/6153_hooker.cpp +++ b/regamedll/hookers/6153_hooker.cpp @@ -2514,7 +2514,7 @@ FunctionHook g_FunctionHooks[] = #ifndef GameRules_Region - //{ 0x01D80C90, "_Z16InstallGameRulesv", (size_t)&InstallGameRules }, + { 0x01D80C90, "_Z16InstallGameRulesv", (size_t)&InstallGameRules }, // HOOK: FIX ME { 0x01D80C00, "_ZN10CGameRules16RefreshSkillDataEv", mfunc_ptr_cast(&CGameRules::RefreshSkillData_) }, //{ 0x01D8EBB0, "_ZN10CGameRules10IsTeamplayEv", mfunc_ptr_cast(&CGameRules::IsTeamplay_) }, // DEFAULT //{ 0x01D8EBC0, "_ZN10CGameRules18GetGameDescriptionEv", mfunc_ptr_cast(&CGameRules::GetGameDescription_) }, // DEFAULT @@ -3746,7 +3746,7 @@ FunctionHook g_FunctionHooks[] = //{ 0x01D24D10, "_ZN13CCSBotManager15MonitorBotCVarsEv", mfunc_ptr_cast(&CCSBotManager::MonitorBotCVars) }, { 0x01D24AE0, "_ZN13CCSBotManager16MaintainBotQuotaEv", mfunc_ptr_cast(&CCSBotManager::MaintainBotQuota) }, //{ 0x0, "_ZN13CCSBotManager16GetRandomBotNameENS_9SkillTypeE", mfunc_ptr_cast(&CCSBotManager::GetRandomBotName) }, - //{ 0x01D25270, "_ZN13CCSBotManager6AddBotEPK10BotProfile18BotProfileTeamType", mfunc_ptr_cast(&CCSBotManager::AddBot) }, + //{ 0x01D25270, "_ZN13CCSBotManager6AddBotEPK10BotProfile18BotProfileTeamType", mfunc_ptr_cast(&CCSBotManager::AddBot) }, // HOOK: FIX ME { 0x01D248B0, "_ZN13CCSBotManager13BotAddCommandE18BotProfileTeamTypeb", mfunc_ptr_cast(&CCSBotManager::BotAddCommand) }, //{ 0x01D238A0, "_Z16PrintAllEntitiesv", (size_t)&PrintAllEntities }, // NOXREF //{ 0x01D23020, "_Z12UTIL_DrawBoxP6Extentiiii", (size_t)&UTIL_DrawBox }, @@ -3761,7 +3761,7 @@ FunctionHook g_FunctionHooks[] = { 0x01D20A60, "_ZN6CCSBot10InitializeEPK10BotProfile", mfunc_ptr_cast(&CCSBot::Initialize_) }, { 0x01D20E40, "_ZN6CCSBot8SpawnBotEv", mfunc_ptr_cast(&CCSBot::SpawnBot_) }, { 0x01D2D370, "_ZN6CCSBot6UpkeepEv", mfunc_ptr_cast(&CCSBot::Upkeep_) }, - //{ 0x01D2D9B0, "_ZN6CCSBot6UpdateEv", mfunc_ptr_cast(&CCSBot::Update_) }, // using refs + //{ 0x01D2D9B0, "_ZN6CCSBot6UpdateEv", mfunc_ptr_cast(&CCSBot::Update_) }, // using refs HOOK: FIX ME { 0x01D17370, "_ZN6CCSBot4WalkEv", mfunc_ptr_cast(&CCSBot::Walk_) }, { 0x01D173A0, "_ZN6CCSBot4JumpEb", mfunc_ptr_cast(&CCSBot::Jump_) }, //{ 0x01D1F990, "_ZN6CCSBot7OnEventE13GameEventTypeP11CBaseEntityS2_", mfunc_ptr_cast(&CCSBot::OnEvent_) }, @@ -4046,6 +4046,9 @@ FunctionHook g_FunctionHooks[] = //{ 0x0, "_ZNK11CSGameState17GetNearestHostageEv", mfunc_ptr_cast(&CSGameState::GetNearestHostage) }, // NOXREF { 0x01D32BE0, "_ZN11CSGameState21InitializeHostageInfoEv", mfunc_ptr_cast(&CSGameState::InitializeHostageInfo) }, //{ 0x01D15EA0, "_Z16NavAreaBuildPathI8PathCostEbP8CNavAreaS2_PK6VectorRT_PS2_", (size_t)&NavAreaBuildPath__PathCost__wrapper }, +#ifdef _WIN32 + { 0x01D15A30, "", (size_t)&NavAreaTravelDistance__PathCost__wrapper }, +#endif // _WIN32 { 0x01D2B2E0, "_ZN8PathCostclEP8CNavAreaS1_PK10CNavLadder", mfunc_ptr_cast(&PathCost::operator()) }, { 0x01D172A0, "_Z17GetBotFollowCountP11CBasePlayer", (size_t)&GetBotFollowCount }, { 0x01D187B0, "_Z21FindNearbyRetreatSpotP6CCSBotf", mfunc_ptr_cast(&FindNearbyRetreatSpot) }, @@ -4065,53 +4068,53 @@ FunctionHook g_FunctionHooks[] = //{ 0x0, "_ZNK8BotState7GetNameEv", mfunc_ptr_cast(&BotState::GetName) }, // NOXREF //IdleState //virtual func - //{ 0x01D142A0, "_ZN9IdleState7OnEnterEP6CCSBot", mfunc_ptr_cast(&IdleState::OnEnter_) }, - //{ 0x01D14320, "_ZN9IdleState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&IdleState::OnUpdate_) }, + { 0x01D142A0, "_ZN9IdleState7OnEnterEP6CCSBot", mfunc_ptr_cast(&IdleState::OnEnter_) }, + { 0x01D14320, "_ZN9IdleState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&IdleState::OnUpdate_) }, //{ 0x01D212C0, "_ZNK9IdleState7GetNameEv", mfunc_ptr_cast(&IdleState::GetName_) }, //HuntState //virtual func - //{ 0x01D13E20, "_ZN9HuntState7OnEnterEP6CCSBot", mfunc_ptr_cast(&HuntState::OnEnter_) }, - //{ 0x01D13EA0, "_ZN9HuntState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&HuntState::OnUpdate_) }, - //{ 0x01D14290, "_ZN9HuntState6OnExitEP6CCSBot", mfunc_ptr_cast(&HuntState::OnExit_) }, + { 0x01D13E20, "_ZN9HuntState7OnEnterEP6CCSBot", mfunc_ptr_cast(&HuntState::OnEnter_) }, + { 0x01D13EA0, "_ZN9HuntState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&HuntState::OnUpdate_) }, + //{ 0x01D14290, "_ZN9HuntState6OnExitEP6CCSBot", mfunc_ptr_cast(&HuntState::OnExit_) }, // PURE //{ 0x01D212D0, "_ZNK9HuntState7GetNameEv", mfunc_ptr_cast(&HuntState::GetName_) }, //non-virtual func //{ 0x0, "_ZN9HuntState13ClearHuntAreaEv", mfunc_ptr_cast(&HuntState::ClearHuntArea) }, // NOXREF //AttackState //virtual func - //{ 0x01D10960, "_ZN11AttackState7OnEnterEP6CCSBot", mfunc_ptr_cast(&AttackState::OnEnter_) }, - //{ 0x01D10CF0, "_ZN11AttackState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&AttackState::OnUpdate_) }, - //{ 0x01D11860, "_ZN11AttackState6OnExitEP6CCSBot", mfunc_ptr_cast(&AttackState::OnExit_) }, + { 0x01D10960, "_ZN11AttackState7OnEnterEP6CCSBot", mfunc_ptr_cast(&AttackState::OnEnter_) }, + { 0x01D10CF0, "_ZN11AttackState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&AttackState::OnUpdate_) }, + { 0x01D11860, "_ZN11AttackState6OnExitEP6CCSBot", mfunc_ptr_cast(&AttackState::OnExit_) }, //{ 0x01D212E0, "_ZNK11AttackState7GetNameEv", mfunc_ptr_cast(&AttackState::GetName_) }, //non-virtual func //{ 0x0, "_ZN11AttackState16SetCrouchAndHoldEb", mfunc_ptr_cast(&AttackState::SetCrouchAndHold) }, // NOXREF //{ 0x01D10CC0, "_ZN11AttackState13StopAttackingEP6CCSBot", mfunc_ptr_cast(&AttackState::StopAttacking) }, // NOXREF //InvestigateNoiseState //virtual func - //{ 0x01D165C0, "_ZN21InvestigateNoiseState7OnEnterEP6CCSBot", mfunc_ptr_cast(&InvestigateNoiseState::OnEnter_) }, - //{ 0x01D166B0, "_ZN21InvestigateNoiseState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&InvestigateNoiseState::OnUpdate_) }, - //{ 0x01D16920, "_ZN21InvestigateNoiseState6OnExitEP6CCSBot", mfunc_ptr_cast(&InvestigateNoiseState::OnExit_) }, + { 0x01D165C0, "_ZN21InvestigateNoiseState7OnEnterEP6CCSBot", mfunc_ptr_cast(&InvestigateNoiseState::OnEnter_) }, + { 0x01D166B0, "_ZN21InvestigateNoiseState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&InvestigateNoiseState::OnUpdate_) }, + { 0x01D16920, "_ZN21InvestigateNoiseState6OnExitEP6CCSBot", mfunc_ptr_cast(&InvestigateNoiseState::OnExit_) }, //{ 0x01D212F0, "_ZNK21InvestigateNoiseState7GetNameEv", mfunc_ptr_cast(&InvestigateNoiseState::GetName_) }, //non-virtual func - //{ 0x0, "_ZN21InvestigateNoiseState18AttendCurrentNoiseEP6CCSBot", mfunc_ptr_cast(&InvestigateNoiseState::AttendCurrentNoise) }, // NOXREF + //{ 0x01D164D0, "_ZN21InvestigateNoiseState18AttendCurrentNoiseEP6CCSBot", mfunc_ptr_cast(&InvestigateNoiseState::AttendCurrentNoise) }, // NOXREF //BuyState //virtual func - //{ 0x01D11910, "_ZN8BuyState7OnEnterEP6CCSBot", mfunc_ptr_cast(&BuyState::OnEnter_) }, - //{ 0x01D11B60, "_ZN8BuyState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&BuyState::OnUpdate_) }, - //{ 0x01D121E0, "_ZN8BuyState6OnExitEP6CCSBot", mfunc_ptr_cast(&BuyState::OnExit_) }, + { 0x01D11910, "_ZN8BuyState7OnEnterEP6CCSBot", mfunc_ptr_cast(&BuyState::OnEnter_) }, + { 0x01D11B60, "_ZN8BuyState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&BuyState::OnUpdate_) }, + { 0x01D121E0, "_ZN8BuyState6OnExitEP6CCSBot", mfunc_ptr_cast(&BuyState::OnExit_) }, //{ 0x01D21300, "_ZNK8BuyState7GetNameEv", mfunc_ptr_cast(&BuyState::GetName_) }, // DEFAULT //MoveToState //virtual func - //{ 0x01D16930, "_ZN11MoveToState7OnEnterEP6CCSBot", mfunc_ptr_cast(&MoveToState::OnEnter_) }, - //{ 0x01D169C0, "_ZN11MoveToState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&MoveToState::OnUpdate_) }, - //{ 0x01D16FE0, "_ZN11MoveToState6OnExitEP6CCSBot", mfunc_ptr_cast(&MoveToState::OnExit_) }, + { 0x01D16930, "_ZN11MoveToState7OnEnterEP6CCSBot", mfunc_ptr_cast(&MoveToState::OnEnter_) }, + //{ 0x01D169C0, "_ZN11MoveToState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&MoveToState::OnUpdate_) }, // HOOK: FIX ME + { 0x01D16FE0, "_ZN11MoveToState6OnExitEP6CCSBot", mfunc_ptr_cast(&MoveToState::OnExit_) }, //{ 0x01D21310, "_ZNK11MoveToState7GetNameEv", mfunc_ptr_cast(&MoveToState::GetName_) }, // DEFAULT //non-virtual func //{ 0x0, "_ZN11MoveToState15SetGoalPositionEPK6Vector", mfunc_ptr_cast(&MoveToState::SetGoalPosition) }, // NOXREF //{ 0x0, "_ZN11MoveToState12SetRouteTypeE9RouteType", mfunc_ptr_cast(&MoveToState::SetRouteType) }, // NOXREF //FetchBombState //virtual func - //{ 0x01D125A0, "_ZN14FetchBombState7OnEnterEP6CCSBot", mfunc_ptr_cast(&FetchBombState::OnEnter_) }, - //{ 0x01D125C0, "_ZN14FetchBombState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&FetchBombState::OnUpdate_) }, + { 0x01D125A0, "_ZN14FetchBombState7OnEnterEP6CCSBot", mfunc_ptr_cast(&FetchBombState::OnEnter_) }, + { 0x01D125C0, "_ZN14FetchBombState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&FetchBombState::OnUpdate_) }, //{ 0x01D21320, "_ZNK14FetchBombState7GetNameEv", mfunc_ptr_cast(&FetchBombState::GetName_) }, // DEFAULT //PlantBombState //virtual func @@ -4121,15 +4124,15 @@ FunctionHook g_FunctionHooks[] = //{ 0x01D21330, "_ZNK14PlantBombState7GetNameEv", mfunc_ptr_cast(&PlantBombState::GetName_) }, // DEFAULT //DefuseBombState //virtual func - //{ 0x01D12200, "_ZN15DefuseBombState7OnEnterEP6CCSBot", mfunc_ptr_cast(&DefuseBombState::OnEnter_) }, - //{ 0x01D12270, "_ZN15DefuseBombState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&DefuseBombState::OnUpdate_) }, - //{ 0x01D12340, "_ZN15DefuseBombState6OnExitEP6CCSBot", mfunc_ptr_cast(&DefuseBombState::OnExit_) }, + { 0x01D12200, "_ZN15DefuseBombState7OnEnterEP6CCSBot", mfunc_ptr_cast(&DefuseBombState::OnEnter_) }, + { 0x01D12270, "_ZN15DefuseBombState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&DefuseBombState::OnUpdate_) }, + { 0x01D12340, "_ZN15DefuseBombState6OnExitEP6CCSBot", mfunc_ptr_cast(&DefuseBombState::OnExit_) }, //{ 0x01D21340, "_ZNK15DefuseBombState7GetNameEv", mfunc_ptr_cast(&DefuseBombState::GetName_) }, // DEFAULT //HideState //virtual func - //{ 0x01D13250, "_ZN9HideState7OnEnterEP6CCSBot", mfunc_ptr_cast(&HideState::OnEnter_) }, - //{ 0x01D13300, "_ZN9HideState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&HideState::OnUpdate_) }, - //{ 0x01D13D90, "_ZN9HideState6OnExitEP6CCSBot", mfunc_ptr_cast(&HideState::OnExit_) }, + { 0x01D13250, "_ZN9HideState7OnEnterEP6CCSBot", mfunc_ptr_cast(&HideState::OnEnter_) }, + { 0x01D13300, "_ZN9HideState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&HideState::OnUpdate_) }, + { 0x01D13D90, "_ZN9HideState6OnExitEP6CCSBot", mfunc_ptr_cast(&HideState::OnExit_) }, //{ 0x01D21350, "_ZNK9HideState7GetNameEv", mfunc_ptr_cast(&HideState::GetName_) }, // DEFAULT //non-virtual func //{ 0x0, "_ZN9HideState13SetHidingSpotEPK6Vector", mfunc_ptr_cast(&HideState::SetHidingSpot) }, // NOXREF @@ -4141,19 +4144,19 @@ FunctionHook g_FunctionHooks[] = //{ 0x0, "_ZNK9HideState8IsAtSpotEv", mfunc_ptr_cast(&HideState::IsAtSpot) }, // NOXREF //EscapeFromBombState //virtual func - //{ 0x01D12390, "_ZN19EscapeFromBombState7OnEnterEP6CCSBot", mfunc_ptr_cast(&EscapeFromBombState::OnEnter_) }, - //{ 0x01D123D0, "_ZN19EscapeFromBombState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&EscapeFromBombState::OnUpdate_) }, - //{ 0x01D12560, "_ZN19EscapeFromBombState6OnExitEP6CCSBot", mfunc_ptr_cast(&EscapeFromBombState::OnExit_) }, + { 0x01D12390, "_ZN19EscapeFromBombState7OnEnterEP6CCSBot", mfunc_ptr_cast(&EscapeFromBombState::OnEnter_) }, + { 0x01D123D0, "_ZN19EscapeFromBombState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&EscapeFromBombState::OnUpdate_) }, + { 0x01D12560, "_ZN19EscapeFromBombState6OnExitEP6CCSBot", mfunc_ptr_cast(&EscapeFromBombState::OnExit_) }, //{ 0x01D21360, "_ZNK19EscapeFromBombState7GetNameEv", mfunc_ptr_cast(&EscapeFromBombState::GetName_) }, // DEFAULT //FollowState //virtual func - //{ 0x01D12660, "_ZN11FollowState7OnEnterEP6CCSBot", mfunc_ptr_cast(&FollowState::OnEnter_) }, - //{ 0x01D127A0, "_ZN11FollowState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&FollowState::OnUpdate_) }, - //{ 0x01D130C0, "_ZN11FollowState6OnExitEP6CCSBot", mfunc_ptr_cast(&FollowState::OnExit_) }, // PURE + { 0x01D12660, "_ZN11FollowState7OnEnterEP6CCSBot", mfunc_ptr_cast(&FollowState::OnEnter_) }, + { 0x01D127A0, "_ZN11FollowState8OnUpdateEP6CCSBot", mfunc_ptr_cast(&FollowState::OnUpdate_) }, + //{ 0x01D130C0, "_ZN11FollowState6OnExitEP6CCSBot", mfunc_ptr_cast(&FollowState::OnExit_) }, // PURE //{ 0x01D21370, "_ZNK11FollowState7GetNameEv", mfunc_ptr_cast(&FollowState::GetName_) }, // DEFAULT //non-virtual func //{ 0x0, "_ZN11FollowState9SetLeaderEP11CBasePlayer", mfunc_ptr_cast(&FollowState::SetLeader) }, // NOXREF - //{ 0x0, "_ZN11FollowState24ComputeLeaderMotionStateEf", mfunc_ptr_cast(&FollowState::ComputeLeaderMotionState) }, + //{ 0x01D126E0, "_ZN11FollowState24ComputeLeaderMotionStateEf", mfunc_ptr_cast(&FollowState::ComputeLeaderMotionState) }, //UseEntityState //virtual func { 0x01D171A0, "_ZN14UseEntityState7OnEnterEP6CCSBot", mfunc_ptr_cast(&UseEntityState::OnEnter_) }, @@ -4164,7 +4167,7 @@ FunctionHook g_FunctionHooks[] = //{ 0x0, "_ZN14UseEntityState9SetEntityEP11CBaseEntity", mfunc_ptr_cast(&UseEntityState::SetEntity) }, // NOXREF #ifdef _WIN32 - //{ 0x01D12F90, "_ZN21FollowTargetCollectorclEP8CNavArea", mfunc_ptr_cast(&FollowTargetCollector::operator()) }, + { 0x01D12F90, "_ZN21FollowTargetCollectorclEP8CNavArea", mfunc_ptr_cast(&FollowTargetCollector::operator()) }, #endif // _WIN32 #endif // CS_BotState_Region @@ -5000,7 +5003,7 @@ FunctionHook g_FunctionHooks[] = //{ 0x01D43000, "", mfunc_ptr_cast(&CNavAreaGrid::CNavAreaGrid) }, // NOXREF //{ 0x01D43090, "", mfunc_ptr_cast(&CNavAreaGrid::~CNavAreaGrid) }, // NOXREF //{ 0x01D43180, "_ZN12CNavAreaGrid5ResetEv", mfunc_ptr_cast(&CNavAreaGrid::Reset) }, // NOXREF - { 0x01D43360, "_ZN12CNavAreaGrid10InitializeEffff", mfunc_ptr_cast(&CNavAreaGrid::Initialize) }, + { 0x01D43230, "_ZN12CNavAreaGrid10InitializeEffff", mfunc_ptr_cast(&CNavAreaGrid::Initialize) }, { 0x01D43390, "_ZN12CNavAreaGrid10AddNavAreaEP8CNavArea", mfunc_ptr_cast(&CNavAreaGrid::AddNavArea) }, { 0x01D43560, "_ZN12CNavAreaGrid13RemoveNavAreaEP8CNavArea", mfunc_ptr_cast(&CNavAreaGrid::RemoveNavArea) }, { 0x01D43710, "_ZNK12CNavAreaGrid10GetNavAreaEPK6Vectorf", mfunc_ptr_cast(&CNavAreaGrid::GetNavArea) }, @@ -5639,10 +5642,8 @@ AddressRef g_FunctionRefs[] = #ifndef Function_References_Region { 0x01D2EDD0, "_ZN6CCSBot16UpdateLookAnglesEv", (size_t)&pCCSBot__UpdateLookAngles }, - { 0x01D2D9B0, "_ZN6CCSBot6UpdateEv", (size_t)&pCCSBot__Update }, { 0x01D19C70, "_ZN9BotPhrase9RandomizeEv", (size_t)&pBotPhrase__Randomize }, { 0x01D25270, "_ZN13CCSBotManager6AddBotEPK10BotProfile18BotProfileTeamType", (size_t)&pCCSBotManager__AddBot }, - { 0x01D80C90, "_Z16InstallGameRulesv", (size_t)&pInstallGameRules }, { 0x01D4C450, "_ZN8CHostage9IdleThinkEv", (size_t)&pCHostage__IdleThink }, #endif // Function_References_Region @@ -6165,6 +6166,12 @@ AddressRef g_DataRefs[] = { 0x01E2F8B4, "sclp", (size_t)&psclp }, { 0x01E2F8B8, "sclq", (size_t)&psclq }, + { 0x01E0DF70, "primaryWeaponBuyInfoCT", (size_t)&pprimaryWeaponBuyInfoCT }, + { 0x01E0E00C, "secondaryWeaponBuyInfoCT", (size_t)&psecondaryWeaponBuyInfoCT }, + + { 0x01E0E030, "primaryWeaponBuyInfoT", (size_t)&pprimaryWeaponBuyInfoT }, + { 0x01E0E0CC, "secondaryWeaponBuyInfoT", (size_t)&psecondaryWeaponBuyInfoT }, + { 0x01E287E8, "_ZN19BotChatterInterface16m_encourageTimerE", mfunc_ptr_cast(&BotChatterInterface::pm_encourageTimer) }, { 0x01E287E0, "_ZN19BotChatterInterface22m_radioSilenceIntervalE", mfunc_ptr_cast(&BotChatterInterface::pm_radioSilenceInterval) }, diff --git a/regamedll/msvc/ReGameDLL.vcxproj b/regamedll/msvc/ReGameDLL.vcxproj index 25b45141..97bd02a7 100644 --- a/regamedll/msvc/ReGameDLL.vcxproj +++ b/regamedll/msvc/ReGameDLL.vcxproj @@ -17,6 +17,10 @@ Debug Win32 + + Release MP + Win32 + Release Play Win32 @@ -40,6 +44,7 @@ false false false + false false false false @@ -49,6 +54,8 @@ + + @@ -56,6 +63,7 @@ false false false + false false false false @@ -65,6 +73,8 @@ + + @@ -74,6 +84,8 @@ + + false @@ -83,6 +95,7 @@ false false false + false false false false @@ -92,6 +105,8 @@ + + @@ -99,6 +114,7 @@ false false false + false false false false @@ -107,6 +123,7 @@ false false false + false false false false @@ -117,6 +134,8 @@ + + false @@ -128,6 +147,8 @@ + + false @@ -138,18 +159,22 @@ + + false false + false false false false false + false false false false @@ -157,12 +182,14 @@ false false + false false false false false + false false false false @@ -171,6 +198,7 @@ false false false + false false false false @@ -179,6 +207,7 @@ false false false + false false false false @@ -187,6 +216,7 @@ false false false + false false false false @@ -195,6 +225,7 @@ false false false + false false false false @@ -203,6 +234,7 @@ false false false + false false false false @@ -211,6 +243,7 @@ false false false + false false false false @@ -219,6 +252,7 @@ false false false + false false false false @@ -227,6 +261,7 @@ false false false + false false false false @@ -235,6 +270,7 @@ false false false + false false false false @@ -243,6 +279,7 @@ false false false + false false false false @@ -251,6 +288,7 @@ false false false + false false false false @@ -259,6 +297,7 @@ false false false + false false false false @@ -284,48 +323,56 @@ false false false + false false false false false + false false false false false + false false false false false + false false false false false + false false false false false + false false false false false + false false false false false + false false @@ -369,6 +416,7 @@ false false false + false false false false @@ -377,6 +425,7 @@ false false false + false false false false @@ -385,6 +434,7 @@ false false false + false false false false @@ -393,6 +443,7 @@ false false false + false false false false @@ -401,6 +452,7 @@ false false false + false false false false @@ -409,6 +461,7 @@ false false false + false false false false @@ -417,6 +470,7 @@ false false false + false false false false @@ -425,6 +479,7 @@ false false false + false false false false @@ -433,6 +488,7 @@ false false false + false false false false @@ -441,6 +497,7 @@ false false false + false false false false @@ -449,6 +506,7 @@ false false false + false false false false @@ -457,6 +515,7 @@ false false false + false false false false @@ -465,6 +524,7 @@ false false false + false false false false @@ -473,6 +533,7 @@ false false false + false false false false @@ -481,6 +542,7 @@ false false false + false false false false @@ -489,6 +551,7 @@ false false false + false false false false @@ -497,6 +560,7 @@ false false false + false false false false @@ -505,6 +569,7 @@ false false false + false false false false @@ -513,6 +578,7 @@ false false false + false false false false @@ -521,6 +587,7 @@ false false false + false false false false @@ -529,6 +596,7 @@ false false false + false false false false @@ -537,6 +605,7 @@ false false false + false false false false @@ -545,6 +614,7 @@ false false false + false false false false @@ -553,6 +623,7 @@ false false false + false false false false @@ -561,6 +632,7 @@ false false false + false false false false @@ -569,6 +641,7 @@ false false false + false false false false @@ -577,6 +650,7 @@ false false false + false false false false @@ -584,6 +658,7 @@ false false + false false false false @@ -593,6 +668,7 @@ false false false + false false false false @@ -610,15 +686,18 @@ true + true true true true + true true true + true true @@ -626,6 +705,7 @@ true true true + true true @@ -633,6 +713,7 @@ true + true @@ -656,9 +737,11 @@ precompiled.h Create Create + Create Create precompiled.h precompiled.h + precompiled.h precompiled.h Create precompiled.h @@ -669,38 +752,46 @@ true + true true + true true + true true + true true + true true true + true true true + true true true + true true @@ -736,6 +827,8 @@ + + @@ -744,6 +837,8 @@ + + @@ -752,12 +847,15 @@ + + false false + false false @@ -935,6 +1033,7 @@ true true true + true true true @@ -942,6 +1041,7 @@ true true true + true true true @@ -982,6 +1082,13 @@ MultiByte v120 + + DynamicLibrary + true + MultiByte + v120 + true + DynamicLibrary true @@ -1020,6 +1127,9 @@ + + + @@ -1052,6 +1162,13 @@ + + mp + AllRules.ruleset + + + + mp AllRules.ruleset @@ -1169,7 +1286,7 @@ Level3 Disabled true - CSTRIKE;REGAMEDLL_ADD;REGAMEDLL_FIXES;REGAMEDLL_SELF;REGAMEDLL_CHECKS;CLIENT_WEAPONS;USE_BREAKPAD_HANDLER;DEDICATED;_CRT_SECURE_NO_WARNINGS;_DEBUG;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions) + REGAMEDLL_ADD;REGAMEDLL_FIXES;REGAMEDLL_SELF;REGAMEDLL_CHECKS;CLIENT_WEAPONS;USE_BREAKPAD_HANDLER;DEDICATED;_CRT_SECURE_NO_WARNINGS;_DEBUG;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions) Precise /arch:IA32 %(AdditionalOptions) MultiThreadedDebug @@ -1195,6 +1312,50 @@ subversion.always.run + + + IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\version\" "$(ProjectDir)..\") + Setup version from Git revision + + + $(ProjectDir)\..\;$(ProjectDir)\..\hookers\;$(ProjectDir)\..\common;$(ProjectDir)\..\dlls;$(ProjectDir)\..\engine;$(ProjectDir)\..\public;$(ProjectDir)\..\public\regamedll;$(ProjectDir)\..\pm_shared;$(ProjectDir)\..\regamedll\;$(ProjectDir)\..\testsuite\;$(VCInstallDir)UnitTest\include;$(SolutionDir)..\dep\bzip2\include\;$(SolutionDir)..\dep\cppunitlite\include\;%(AdditionalIncludeDirectories) + Level3 + MaxSpeed + true + REGAMEDLL_SELF;REGAMEDLL_CHECKS;CLIENT_WEAPONS;USE_BREAKPAD_HANDLER;DEDICATED;_CRT_SECURE_NO_WARNINGS;NDEBUG;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions) + Precise + /arch:IA32 %(AdditionalOptions) + MultiThreaded + Use + precompiled.h + ProgramDatabase + true + false + Default + true + + + true + psapi.lib;ws2_32.lib;$(ProjectDir)../lib/steam_api.lib;%(AdditionalDependencies) + + + mp.def + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + true + true + true + + + IF EXIST "$(ProjectDir)PostBuild_mp.bat" (CALL "$(ProjectDir)PostBuild_mp.bat" "$(TargetDir)" "$(TargetName)" "$(TargetExt)" "$(ProjectDir)") + Automatic deployment script + + + echo Empty Action + Force build to run Pre-Build event + subversion.always.run + subversion.always.run + + IF EXIST "$(ProjectDir)PreBuild.bat" (CALL "$(ProjectDir)PreBuild.bat" "$(ProjectDir)..\version\" "$(ProjectDir)..\") @@ -1205,7 +1366,7 @@ Level3 Disabled true - CSTRIKE;REGAMEDLL_SELF;PLAY_GAMEDLL;REGAMEDLL_CHECKS;CLIENT_WEAPONS;USE_BREAKPAD_HANDLER;DEDICATED;_CRT_SECURE_NO_WARNINGS;_DEBUG;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions) + REGAMEDLL_SELF;PLAY_GAMEDLL;REGAMEDLL_CHECKS;CLIENT_WEAPONS;USE_BREAKPAD_HANDLER;DEDICATED;_CRT_SECURE_NO_WARNINGS;_DEBUG;_ITERATOR_DEBUG_LEVEL=0;%(PreprocessorDefinitions) Precise /arch:IA32 %(AdditionalOptions) MultiThreadedDebug diff --git a/regamedll/pm_shared/pm_math.cpp b/regamedll/pm_shared/pm_math.cpp index bc4231a2..ca64da19 100644 --- a/regamedll/pm_shared/pm_math.cpp +++ b/regamedll/pm_shared/pm_math.cpp @@ -158,7 +158,7 @@ NOBODY void VectorTransform(const vec_t *in1, float *in2, vec_t *out) int VectorCompare(const vec_t *v1, const vec_t *v2) { int i; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { if (v1[i] != v2[i]) return 0; @@ -218,7 +218,7 @@ float_precision Length(const vec_t *v) int i; float_precision length = 0.0f; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) length += v[i] * v[i]; return sqrt(length); diff --git a/regamedll/pm_shared/pm_shared.cpp b/regamedll/pm_shared/pm_shared.cpp index e110c29d..4c126f58 100644 --- a/regamedll/pm_shared/pm_shared.cpp +++ b/regamedll/pm_shared/pm_shared.cpp @@ -54,7 +54,7 @@ NOXREF int PM_IsThereGrassTexture(void) { int i; - for (i = 0; i < pm_gcTextures; i++) + for (i = 0; i < pm_gcTextures; ++i) { if (pm_grgchTextureType[i] == CHAR_TEX_GRASS) return 1; @@ -69,7 +69,7 @@ void PM_SortTextures(void) // Bubble sort, yuck, but this only occurs at startup and it's only 512 elements... int i, j; - for (i = 0; i < pm_gcTextures; i++) + for (i = 0; i < pm_gcTextures; ++i) { for (j = i + 1; j < pm_gcTextures; j++) { @@ -113,7 +113,7 @@ void PM_InitTextureTypes(void) // skip whitespace i = 0; while (buffer[i] && isspace(buffer[i])) - i++; + ++i; if (!buffer[i]) continue; @@ -127,7 +127,7 @@ void PM_InitTextureTypes(void) // skip whitespace while (buffer[i] && isspace(buffer[i])) - i++; + ++i; if (!buffer[i]) continue; @@ -528,7 +528,7 @@ void PM_UpdateStepSound(void) qboolean PM_AddToTouched(pmtrace_t tr, vec_t *impactvelocity) { int i; - for (i = 0; i < pmove->numtouch; i++) + for (i = 0; i < pmove->numtouch; ++i) { if (pmove->touchindex[i].ent == tr.ent) break; @@ -557,7 +557,7 @@ void PM_CheckVelocity(void) int i; // bound velocity - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { // See if it's bogus. if (IS_NAN(pmove->velocity[i])) @@ -620,7 +620,7 @@ int PM_ClipVelocity(vec_t *in, vec_t *normal, vec_t *out, float overbounce) // Scale by overbounce factor. backoff = DotProduct(in, normal) * overbounce; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { change = in[i] - normal[i] * backoff; out[i] = change; @@ -710,7 +710,7 @@ int PM_FlyMove(void) // Assume we can move all the way from the current origin to the // end point. - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { float_precision flScale = time_left * pmove->velocity[i]; @@ -794,7 +794,7 @@ int PM_FlyMove(void) // relfect player velocity if (numplanes == 1 && pmove->movetype == MOVETYPE_WALK && (pmove->onground == -1 || pmove->friction != 1)) { - for (i = 0; i < numplanes; i++) + for (i = 0; i < numplanes; ++i) { if (planes[i][2] > 0.7f) { @@ -811,7 +811,7 @@ int PM_FlyMove(void) } else { - for (i = 0; i < numplanes; i++) + for (i = 0; i < numplanes; ++i) { PM_ClipVelocity(original_velocity, planes[i], pmove->velocity, 1); @@ -891,7 +891,7 @@ void PM_Accelerate(vec_t *wishdir, float_precision wishspeed, float accel) accelspeed = addspeed; // Adjust velocity. - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { pmove->velocity[i] += accelspeed * wishdir[i]; } @@ -941,7 +941,7 @@ void PM_WalkMove(void) VectorNormalize(pmove->right); // Determine x and y parts of velocity - for (i = 0; i < 2; i++) + for (i = 0; i < 2; ++i) { wishvel[i] = pmove->forward[i] * fmove + pmove->right[i] * smove; } @@ -1208,7 +1208,7 @@ void PM_AirAccelerate(vec_t *wishdir, float wishspeed, float accel) accelspeed = addspeed; // Adjust pmove vel. - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { pmove->velocity[i] += accelspeed * wishdir[i]; } @@ -1228,7 +1228,7 @@ void PM_WaterMove(void) float newspeed, addspeed; // user intentions - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { wishvel[i] = (pmove->forward[i] * pmove->cmd.forwardmove) + (pmove->cmd.sidemove * pmove->right[i]); } @@ -1296,7 +1296,7 @@ void PM_WaterMove(void) accelspeed = addspeed; } - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { pmove->velocity[i] += accelspeed * wishvel[i]; } @@ -1344,7 +1344,7 @@ void PM_AirMove(void) VectorNormalize(pmove->right); // Determine x and y parts of velocity - for (i = 0; i < 2; i++) + for (i = 0; i < 2; ++i) { wishvel[i] = pmove->forward[i] * fmove + pmove->right[i] * smove; } @@ -1715,7 +1715,7 @@ void PM_SpectatorMove(void) VectorNormalize(pmove->forward); VectorNormalize(pmove->right); - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { wishvel[i] = pmove->forward[i] * fmove + pmove->right[i] * smove; } @@ -1746,7 +1746,7 @@ void PM_SpectatorMove(void) accelspeed = addspeed; } - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { pmove->velocity[i] += accelspeed * wishdir[i]; } @@ -1823,7 +1823,7 @@ void PM_FixPlayerCrouchStuck(int direction) VectorCopy(pmove->origin, test); - for (i = 0; i < 36; i++) + for (i = 0; i < 36; ++i) { pmove->origin[2] += direction; hitent = pmove->PM_TestPlayerPosition(pmove->origin, NULL); @@ -2087,7 +2087,7 @@ physent_t *PM_Ladder(void) int num; vec3_t test; - for (i = 0; i < pmove->nummoveent; i++) + for (i = 0; i < pmove->nummoveent; ++i) { pe = &pmove->moveents[i]; @@ -2298,7 +2298,7 @@ void PM_NoClip(void) VectorNormalize(pmove->right); // Determine x and y parts of velocity - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { wishvel[i] = pmove->forward[i] * fmove + pmove->right[i] * smove; } @@ -3096,7 +3096,7 @@ void PM_CreateStuckTable(void) zi[1] = 1.0f; zi[2] = 6.0f; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { // Z moves z = zi[i]; @@ -3135,7 +3135,7 @@ void PM_CreateStuckTable(void) } // Remaining multi axis nudges. - for (i = 0; i < 3; i++) + for (i = 0; i < 3; ++i) { z = zi[i];