From 3c5d056fec308853425873f6f88c97ce554a0a82 Mon Sep 17 00:00:00 2001 From: jeefo Date: Sun, 11 Sep 2016 21:01:06 +0300 Subject: [PATCH] rewritten a little weapon selection code fixed bots do not chat when dead some code cleanup --- include/compress.h | 32 +-- include/core.h | 37 ++- include/corelib.h | 38 ++- include/engine.h | 4 +- include/engine/archtypes.h | 231 ----------------- include/engine/const.h | 44 +--- include/engine/dllapi.h | 47 ---- include/engine/eiface.h | 27 +- include/engine/enginecallback.h | 4 +- include/engine/extdll.h | 18 +- include/engine/meta_api.h | 24 +- include/engine/mutil.h | 14 -- include/engine/plinfo.h | 11 - include/engine/progdefs.h | 4 +- include/engine/sdk_util.h | 23 -- include/engine/util.h | 88 +------ include/globals.h | 4 +- include/platform.h | 18 +- include/resource.h | 2 +- project/yapb.rc | 2 +- project/yapb.vcxproj | 5 - project/yapb.vcxproj.filters | 15 -- source/basecode.cpp | 427 ++++++++++++++++++-------------- source/chatlib.cpp | 42 ++-- source/combat.cpp | 34 +-- source/engine.cpp | 58 ++--- source/globals.cpp | 37 +-- source/interface.cpp | 218 ++++++++-------- source/manager.cpp | 161 ++++++------ source/navigate.cpp | 153 ++++++------ source/support.cpp | 58 ++--- source/waypoint.cpp | 128 +++++----- 32 files changed, 794 insertions(+), 1214 deletions(-) delete mode 100644 include/engine/archtypes.h delete mode 100644 include/engine/dllapi.h delete mode 100644 include/engine/mutil.h delete mode 100644 include/engine/plinfo.h delete mode 100644 include/engine/sdk_util.h diff --git a/include/compress.h b/include/compress.h index 398bf59..896a8b2 100644 --- a/include/compress.h +++ b/include/compress.h @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #pragma once @@ -17,7 +17,7 @@ protected: unsigned long int m_textSize; unsigned long int m_codeSize; - byte m_textBuffer[N + F - 1]; + uint8 m_textBuffer[N + F - 1]; int m_matchPosition; int m_matchLength; @@ -41,7 +41,7 @@ private: int compare = 1; - byte *key = &m_textBuffer[node]; + uint8 *key = &m_textBuffer[node]; int temp = N + 1 + key[0]; m_right[node] = m_left[node] = NIL; @@ -172,16 +172,18 @@ public: memset (m_parent, 0, sizeof (m_parent)); } - int InternalEncode (const char *fileName, byte *header, int headerSize, byte *buffer, int bufferSize) + int InternalEncode (const char *fileName, uint8 *header, int headerSize, uint8 *buffer, int bufferSize) { - int i, bit, length, node, strPtr, lastMatchLength, codeBufferPtr, bufferPtr = 0; - byte codeBuffer[17], mask; + int i, length, node, strPtr, lastMatchLength, codeBufferPtr, bufferPtr = 0; + uint8 codeBuffer[17], mask; File fp (fileName, "wb"); if (!fp.IsValid ()) return -1; + uint8 bit; + fp.Write (header, headerSize, 1); InitTree (); @@ -219,8 +221,8 @@ public: } else { - codeBuffer[codeBufferPtr++] = (unsigned char) m_matchPosition; - codeBuffer[codeBufferPtr++] = (unsigned char) (((m_matchPosition >> 4) & 0xf0) | (m_matchLength - (THRESHOLD + 1))); + codeBuffer[codeBufferPtr++] = (uint8) m_matchPosition; + codeBuffer[codeBufferPtr++] = (uint8) (((m_matchPosition >> 4) & 0xf0) | (m_matchLength - (THRESHOLD + 1))); } if ((mask <<= 1) == 0) @@ -273,12 +275,14 @@ public: return m_codeSize; } - int InternalDecode (const char *fileName, int headerSize, byte *buffer, int bufferSize) + int InternalDecode (const char *fileName, int headerSize, uint8 *buffer, int bufferSize) { - int i, j, k, node, bit; + int i, j, k, node; unsigned int flags; int bufferPtr = 0; + uint8 bit; + File fp (fileName, "rb"); if (!fp.IsValid ()) @@ -296,14 +300,14 @@ public: { if (((flags >>= 1) & 256) == 0) { - if ((bit = fp.GetChar ()) == EOF) + if ((bit = static_cast (fp.GetChar ())) == EOF) break; flags = bit | 0xff00; } if (flags & 1) { - if ((bit = fp.GetChar ()) == EOF) + if ((bit = static_cast (fp.GetChar ())) == EOF) break; buffer[bufferPtr++] = bit; @@ -343,14 +347,14 @@ public: } // external decoder - static int Uncompress (const char *fileName, int headerSize, byte *buffer, int bufferSize) + static int Uncompress (const char *fileName, int headerSize, uint8 *buffer, int bufferSize) { static Compressor compressor = Compressor (); return compressor.InternalDecode (fileName, headerSize, buffer, bufferSize); } // external encoder - static int Compress(const char *fileName, byte *header, int headerSize, byte *buffer, int bufferSize) + static int Compress(const char *fileName, uint8 *header, int headerSize, uint8 *buffer, int bufferSize) { static Compressor compressor = Compressor (); return compressor.InternalEncode (fileName, header, headerSize, buffer, bufferSize); diff --git a/include/core.h b/include/core.h index bd6bc72..2e609e1 100644 --- a/include/core.h +++ b/include/core.h @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #pragma once @@ -13,7 +13,6 @@ #include #include -#include #include using namespace Math; @@ -625,21 +624,21 @@ struct Client // experience data hold in memory while playing struct Experience { - unsigned short team0Damage; - unsigned short team1Damage; - signed short team0DangerIndex; - signed short team1DangerIndex; - signed short team0Value; - signed short team1Value; + uint16 team0Damage; + uint16 team1Damage; + int16 team0DangerIndex; + int16 team1DangerIndex; + int16 team0Value; + int16 team1Value; }; // experience data when saving/loading struct ExperienceSave { - unsigned char team0Damage; - unsigned char team1Damage; - signed char team0Value; - signed char team1Value; + uint8 team0Damage; + uint8 team1Damage; + int8 team0Value; + int8 team1Value; }; // bot creation tab @@ -668,7 +667,7 @@ struct WeaponProperty // define chatting collection structure struct ChatCollection { - char chatProbability; + int chatProbability; float chatDelay; float timeNextChat; int entityIndex; @@ -775,7 +774,7 @@ private: Path *m_currentPath; // pointer to the current path waypoint SearchPathType m_pathType; // which pathfinder to use - unsigned char m_visibility; // visibility flags + uint8 m_visibility; // visibility flags int m_currentWaypointIndex; // current waypoint index int m_travelStartIndex; // travel start index to double jump action @@ -784,7 +783,7 @@ private: int m_loosedBombWptIndex; // nearest to loosed bomb waypoint int m_plantedBombWptIndex;// nearest to planted bomb waypoint - unsigned short m_currentTravelFlags; // connection flags like jumping + uint16 m_currentTravelFlags; // connection flags like jumping bool m_jumpFinished; // has bot finished jumping Vector m_desiredVelocity; // desired velocity for jump waypoints float m_navTimeset; // time waypoint chosen by Bot @@ -941,7 +940,7 @@ private: bool IsInViewCone (const Vector &origin); void ReactOnSound (void); - bool CheckVisibility (edict_t *target, Vector *origin, byte *bodyPart); + bool CheckVisibility (edict_t *target, Vector *origin, uint8 *bodyPart); bool IsEnemyViewable (edict_t *player); edict_t *FindNearestButton (const char *className); @@ -972,7 +971,7 @@ private: float GetWalkSpeed (void); - bool ItemIsVisible (const Vector &dest, char *itemName); + bool ItemIsVisible (const Vector &dest, const char *itemName); bool LastEnemyShootable (void); bool IsBehindSmokeClouds (edict_t *ent); void RunTask (void); @@ -993,7 +992,7 @@ private: int GetBestSecondaryWeaponCarried (void); void RunPlayerMovement (void); - byte ThrottledMsec (void); + uint8 ThrottledMsec (void); void GetValidWaypoint (void); int ChangeWptIndex (int waypointIndex); bool IsDeadlyDrop (const Vector &to); @@ -1357,7 +1356,7 @@ private: int m_lastJumpWaypoint; int m_visibilityIndex; Vector m_lastWaypoint; - unsigned char m_visLUT[MAX_WAYPOINTS][MAX_WAYPOINTS / 4]; + uint8 m_visLUT[MAX_WAYPOINTS][MAX_WAYPOINTS / 4]; float m_pathDisplayTime; float m_arrowDisplayTime; diff --git a/include/corelib.h b/include/corelib.h index d623331..698a45a 100644 --- a/include/corelib.h +++ b/include/corelib.h @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #pragma once @@ -27,6 +27,20 @@ #include #endif +// +// Basic Types +// +typedef signed char int8; +typedef signed short int16; +typedef signed long int32; +typedef unsigned char uint8; +typedef unsigned short uint16; +typedef unsigned long uint32; + +// Own min/max implementation +template inline T A_min (T a, T b) { return a < b ? a : b; } +template inline T A_max (T a, T b) { return a > b ? a : b; } + // // Title: Utility Classes Header // @@ -223,7 +237,7 @@ namespace Math *sine = sinf (rad); *cosine = cosf (rad); #elif defined (__linux__) || defined (GCC) || defined (__APPLE__) - register double _cos, _sin; + double _cos, _sin; __asm __volatile__ ("fsincos" : "=t" (_cos), "=u" (_sin) : "0" (rad)); *cosine = _cos; @@ -277,7 +291,7 @@ private: public: RandomSequenceOfUnique (void) { - unsigned int seedBase = time (NULL); + unsigned int seedBase = static_cast (time (NULL)); unsigned int seedOffset = seedBase + 1; m_index = PermuteQPR (PermuteQPR (seedBase) + 0x682f0161); @@ -285,7 +299,7 @@ public: m_divider = (static_cast (1)) << 32; } - inline int Long (int low, int high) + inline int Int (int low, int high) { return static_cast (Random () * (static_cast (high) - static_cast (low) + 1.0) / m_divider + static_cast (low)); } @@ -1609,7 +1623,7 @@ public: { extern class RandomSequenceOfUnique Random; - return m_elements[Random.Long (0, m_itemCount - 1)]; + return m_elements[Random.Int (0, m_itemCount - 1)]; } Array &operator = (const Array &other) @@ -2028,7 +2042,7 @@ private: int delta = 4; if (m_allocatedSize > 64) - delta = m_allocatedSize * 0.5; + delta = static_cast (m_allocatedSize * 0.5); else if (m_allocatedSize > 8) delta = 16; @@ -2667,7 +2681,7 @@ public: String result; for (int i = 0; i < GetLength (); i++) - result += toupper (m_bufferPtr[i]); + result += static_cast (toupper (static_cast (m_bufferPtr[i]))); return result; } @@ -2684,7 +2698,7 @@ public: String result; for (int i = 0; i < GetLength (); i++) - result += tolower (m_bufferPtr[i]); + result += static_cast (tolower (static_cast (m_bufferPtr[i]))); return result; } @@ -3663,8 +3677,8 @@ public: class MemoryFile { public: - typedef unsigned char *(*MF_Loader) (const char *, int *); - typedef void (*MF_Unloader) (unsigned char *); + typedef uint8 *(*MF_Loader) (const char *, int *); + typedef void (*MF_Unloader) (uint8 *); public: static MF_Loader Loader; @@ -3673,7 +3687,7 @@ public: protected: int m_size; int m_pos; - unsigned char *m_buffer; + uint8 *m_buffer; // // Group: (Con/De)structors @@ -3843,7 +3857,7 @@ public: if (!m_buffer|| m_pos >= m_size || buffer == NULL || !size || !count) return 0; - int blocksRead = min ((m_size - m_pos) / size, count) * size; + int blocksRead = A_min ((m_size - m_pos) / size, count) * size; memcpy (buffer, &m_buffer[m_pos], blocksRead); m_pos += blocksRead; diff --git a/include/engine.h b/include/engine.h index db07e47..7e7ee6f 100644 --- a/include/engine.h +++ b/include/engine.h @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // // Purpose: Engine & Game interfaces. // @@ -92,7 +92,7 @@ struct MessageBlock class Engine : public Singleton { private: - short m_drawModels[DRAW_NUM]; + int m_drawModels[DRAW_NUM]; // bot client command bool m_isBotCommand; diff --git a/include/engine/archtypes.h b/include/engine/archtypes.h deleted file mode 100644 index f5e4aea..0000000 --- a/include/engine/archtypes.h +++ /dev/null @@ -1,231 +0,0 @@ -/*** -* -* Copyright (c) 1999-2005, Valve Corporation. All rights reserved. -* -* This product contains software technology licensed from Id -* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. -* All Rights Reserved. -* -* This source code contains proprietary and confidential information of -* Valve LLC and its suppliers. Access to this code is restricted to -* persons who have executed a written SDK license with Valve. Any access, -* use or distribution of this code by or to any unlicensed person is illegal. -* -****/ -#ifndef ARCHTYPES_H -#define ARCHTYPES_H - -#ifdef _WIN32 -#pragma once -#endif - -#include - -// detects the build platform -#if defined (__linux__) || defined (__debian__) || defined (__linux) -#define __linux__ 1 - -#endif - -// for when we care about how many bits we use -typedef signed char int8; -typedef signed short int16; -typedef signed long int32; - -#ifdef _WIN32 -#ifdef _MSC_VER -typedef signed __int64 int64; -#endif -#elif defined __linux__ -typedef long long int64; -#endif - -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned long uint32; - -#ifdef _WIN32 -#ifdef _MSC_VER -typedef unsigned __int64 uint64; -#endif -#elif defined __linux__ -typedef unsigned long long uint64; -#endif - -typedef float float32; -typedef double float64; - -// for when we don't care about how many bits we use -typedef unsigned int uint; - -// This can be used to ensure the size of pointers to members when declaring -// a pointer type for a class that has only been forward declared -#ifdef _MSC_VER -#define SINGLE_INHERITANCE __single_inheritance -#define MULTIPLE_INHERITANCE __multiple_inheritance -#else -#define SINGLE_INHERITANCE -#define MULTIPLE_INHERITANCE -#endif - -// need these for the limits -#include -#include - -// Maximum and minimum representable values -// fixing compiling againt maxosx10.10 -#if 0 -#define INT8_MAX SCHAR_MAX -#define INT16_MAX SHRT_MAX -#define INT32_MAX LONG_MAX -#define INT64_MAX (((int64)~0) >> 1) - -#define INT8_MIN SCHAR_MIN -#define INT16_MIN SHRT_MIN -#define INT32_MIN LONG_MIN -#define INT64_MIN (((int64)1) << 63) - -#define UINT8_MAX ((uint8)~0) -#define UINT16_MAX ((uint16)~0) -#define UINT32_MAX ((uint32)~0) -#define UINT64_MAX ((uint64)~0) - -#define UINT8_MIN 0 -#define UINT16_MIN 0 -#define UINT32_MIN 0 -#define UINT64_MIN 0 - -#ifndef UINT_MIN -#define UINT_MIN UINT32_MIN -#endif - -#define FLOAT32_MAX FLT_MAX -#define FLOAT64_MAX DBL_MAX - -#define FLOAT32_MIN FLT_MIN -#define FLOAT64_MIN DBL_MIN -#endif - -// portability / compiler settings -#if defined(_WIN32) && !defined(WINDED) - -#if defined(_M_IX86) -#define __i386__ 1 -#endif - -#elif __linux__ -typedef unsigned int DWORD; -typedef unsigned short WORD; -typedef void *HINSTANCE; - -#define _MAX_PATH PATH_MAX -#endif // defined(_WIN32) && !defined(WINDED) - -// Defines MAX_PATH -#ifndef MAX_PATH -#define MAX_PATH 260 -#endif - -// Used to step into the debugger -#define DebuggerBreak() __asm { int 3 } - -// C functions for external declarations that call the appropriate C++ methods -#ifndef EXPORT -#ifdef _WIN32 -#define EXPORT __declspec( dllexport ) -#else -#define EXPORT /* */ -#endif -#endif - -#if defined __i386__ && !defined __linux__ -#define id386 1 -#else -#define id386 0 -#endif // __i386__ - -#ifdef _WIN32 -// Used for dll exporting and importing -#define DLL_EXPORT extern "C" __declspec( dllexport ) -#define DLL_IMPORT extern "C" __declspec( dllimport ) - -// Can't use extern "C" when DLL exporting a class -#define DLL_CLASS_EXPORT __declspec( dllexport ) -#define DLL_CLASS_IMPORT __declspec( dllimport ) - -// Can't use extern "C" when DLL exporting a global -#define DLL_GLOBAL_EXPORT extern __declspec( dllexport ) -#define DLL_GLOBAL_IMPORT extern __declspec( dllimport ) -#elif defined __linux__ || defined (__APPLE__) - -// Used for dll exporting and importing -#define DLL_EXPORT extern "C" -#define DLL_IMPORT extern "C" - -// Can't use extern "C" when DLL exporting a class -#define DLL_CLASS_EXPORT -#define DLL_CLASS_IMPORT - -// Can't use extern "C" when DLL exporting a global -#define DLL_GLOBAL_EXPORT extern -#define DLL_GLOBAL_IMPORT extern - -#else -#error "Unsupported Platform." -#endif - -#ifndef _WIN32 -#define FAKEFUNC (void *) 0 -#else -#define FAKEFUNC __noop -#endif - -// Used for standard calling conventions -#ifdef _WIN32 -#define STDCALL __stdcall -#define FASTCALL __fastcall -#ifndef FORCEINLINE -#define FORCEINLINE __forceinline -#endif -#else -#define STDCALL -#define FASTCALL -#define FORCEINLINE inline -#endif - -// Force a function call site -not- to inlined. (useful for profiling) -#define DONT_INLINE(a) (((int)(a)+1)?(a):(a)) - -// Pass hints to the compiler to prevent it from generating unnessecary / stupid code -// in certain situations. Several compilers other than MSVC also have an equivilent -// construct. -// -// Essentially the 'Hint' is that the condition specified is assumed to be true at -// that point in the compilation. If '0' is passed, then the compiler assumes that -// any subsequent code in the same 'basic block' is unreachable, and thus usually -// removed. -#ifdef _MSC_VER -#define HINT(THE_HINT) __assume((THE_HINT)) -#else -#define HINT(THE_HINT) 0 -#endif - -// Marks the codepath from here until the next branch entry point as unreachable, -// and asserts if any attempt is made to execute it. -#define UNREACHABLE() { ASSERT(0); HINT(0); } - -// In cases where no default is present or appropriate, this causes MSVC to generate -// as little code as possible, and throw an assertion in debug. -#define NO_DEFAULT default: UNREACHABLE(); - -#ifdef _WIN32 -// Alloca defined for this platform -#define stackalloc( _size ) _alloca( _size ) -#define stackfree( _p ) 0 -#elif __linux__ -// Alloca defined for this platform -#define stackalloc( _size ) alloca( _size ) -#define stackfree( _p ) 0 -#endif - -#endif diff --git a/include/engine/const.h b/include/engine/const.h index eb53672..0573cef 100644 --- a/include/engine/const.h +++ b/include/engine/const.h @@ -602,10 +602,10 @@ #define CHAN_NETWORKVOICE_END 500 // network voice data reserves slots (CHAN_NETWORKVOICE_BASE through CHAN_NETWORKVOICE_END). // attenuation values -#define ATTN_NONE 0 -#define ATTN_NORM (float)0.8 -#define ATTN_IDLE (float)2 -#define ATTN_STATIC (float)1.25 +#define ATTN_NONE 0.0f +#define ATTN_NORM 0.8f +#define ATTN_IDLE 2f +#define ATTN_STATIC 1.25f // pitch values #define PITCH_NORM 100 // non-pitch shifted @@ -710,42 +710,6 @@ enum typedef int func_t; typedef int string_t; -typedef unsigned char byte; -typedef unsigned short word; - -#define _DEF_BYTE_ - -#undef true -#undef false - -#ifndef __cplusplus -typedef enum -{ false, true } int; -#else -#endif - -typedef struct -{ - byte r, g, b; -} color24; - -typedef struct -{ - unsigned r, g, b, a; -} colorVec; - -#ifdef _WIN32 -#pragma pack(push,2) -#endif - -typedef struct -{ - unsigned short r, g, b, a; -} PackedColorVec; - -#ifdef _WIN32 -#pragma pack(pop) -#endif typedef struct link_s { struct link_s *prev, *next; diff --git a/include/engine/dllapi.h b/include/engine/dllapi.h deleted file mode 100644 index 2c4bd32..0000000 --- a/include/engine/dllapi.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2001-2006 Will Day - * - * This file is part of Metamod. - * - * Metamod is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * Metamod is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Metamod; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, the author gives permission to - * link the code of this program with the Half-Life Game Engine ("HL - * Engine") and Modified Game Libraries ("MODs") developed by Valve, - * L.L.C ("Valve"). You must obey the GNU General Public License in all - * respects for all of the code used other than the HL Engine and MODs - * from Valve. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. - * - */ - -// Simplified version by Wei Mingzhi - -#ifndef DLLAPI_H -#define DLLAPI_H - -#undef DLLEXPORT -#ifdef _WIN32 -#define DLLEXPORT __declspec(dllexport) -#elif defined(linux) || defined (__APPLE__) -#define DLLEXPORT /* */ -#define WINAPI /* */ -#endif /* linux */ - -#define C_DLLEXPORT extern "C" DLLEXPORT - -#endif /* DLLAPI_H */ diff --git a/include/engine/eiface.h b/include/engine/eiface.h index aafa72d..7d7da4a 100644 --- a/include/engine/eiface.h +++ b/include/engine/eiface.h @@ -18,7 +18,6 @@ #define INTERFACE_VERSION 140 #include -#include "archtypes.h" #define FCVAR_ARCHIVE (1 << 0) // set to cause it to be saved to vars.rc #define FCVAR_USERINFO (1 << 1) // changes the client's info string @@ -189,14 +188,14 @@ typedef struct enginefuncs_s void (*pfnGetAttachment) (const edict_t *ent, int iAttachment, float *rgflOrigin, float *rgflAngles); void (*pfnCRC32_Init) (CRC32_t *pulCRC); void (*pfnCRC32_ProcessBuffer) (CRC32_t *pulCRC, void *p, int len); - void (*pfnCRC32_ProcessByte) (CRC32_t *pulCRC, unsigned char ch); + void (*pfnCRC32_ProcessByte) (CRC32_t *pulCRC, uint8 ch); CRC32_t (*pfnCRC32_Final) (CRC32_t pulCRC); int32 (*pfnRandomLong) (int32 lLow, int32 lHigh); float (*pfnRandomFloat) (float flLow, float flHigh); void (*pfnSetView) (const edict_t *client, const edict_t *pViewent); float (*pfnTime) (void); void (*pfnCrosshairAngle) (const edict_t *client, float pitch, float yaw); - byte *(*pfnLoadFileForMe) (char const *szFilename, int *pLength); + uint8 *(*pfnLoadFileForMe) (char const *szFilename, int *pLength); void (*pfnFreeFile) (void *buffer); void (*pfnEndSection) (const char *pszSectionName); // trigger_endsection int (*pfnCompareFileTime) (char *filename1, char *filename2, int *compare); @@ -204,10 +203,10 @@ typedef struct enginefuncs_s void (*pfnCvar_RegisterVariable) (cvar_t *variable); void (*pfnFadeClientVolume) (const edict_t *ent, int fadePercent, int fadeOutSeconds, int holdTime, int fadeInSeconds); void (*pfnSetClientMaxspeed) (const edict_t *ent, float fNewMaxspeed); - edict_t *(*pfnCreateFakeClient) (const char *netname); // returns NULL if fake client can't be created - void (*pfnRunPlayerMove) (edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec); + edict_t *(*pfnCreateFakeClient) (const char *netname); // returns nullptr if fake client can't be created + void (*pfnRunPlayerMove) (edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, uint16 buttons, uint8 impulse, uint8 msec); int (*pfnNumberOfEntities) (void); - char *(*pfnGetInfoKeyBuffer) (edict_t *e); // passing in NULL gets the serverinfo + char *(*pfnGetInfoKeyBuffer) (edict_t *e); // passing in nullptr gets the serverinfo char *(*pfnInfoKeyValue) (char *infobuffer, char const *key); void (*pfnSetKeyValue) (char *infobuffer, char *key, char *value); void (*pfnSetClientKeyValue) (int clientIndex, char *infobuffer, char const *key, char const *value); @@ -224,14 +223,14 @@ typedef struct enginefuncs_s const char *(*pfnGetPhysicsKeyValue) (const edict_t *client, const char *key); void (*pfnSetPhysicsKeyValue) (const edict_t *client, const char *key, const char *value); const char *(*pfnGetPhysicsInfoString) (const edict_t *client); - unsigned short (*pfnPrecacheEvent) (int type, const char *psz); - void (*pfnPlaybackEvent) (int flags, const edict_t *pInvoker, unsigned short evIndexOfEntity, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2); - unsigned char *(*pfnSetFatPVS) (float *org); - unsigned char *(*pfnSetFatPAS) (float *org); - int (*pfnCheckVisibility) (const edict_t *entity, unsigned char *pset); + uint16 (*pfnPrecacheEvent) (int type, const char *psz); + void (*pfnPlaybackEvent) (int flags, const edict_t *pInvoker, uint16 evIndexOfEntity, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2); + uint8 *(*pfnSetFatPVS) (float *org); + uint8 *(*pfnSetFatPAS) (float *org); + int (*pfnCheckVisibility) (const edict_t *entity, uint8 *pset); void (*pfnDeltaSetField) (struct delta_s *pFields, const char *fieldname); void (*pfnDeltaUnsetField) (struct delta_s *pFields, const char *fieldname); - void (*pfnDeltaAddEncoder) (char *name, void (*conditionalencode) (struct delta_s *pFields, const unsigned char *from, const unsigned char *to)); + void (*pfnDeltaAddEncoder) (char *name, void (*conditionalencode) (struct delta_s *pFields, const uint8 *from, const uint8 *to)); int (*pfnGetCurrentPlayer) (void); int (*pfnCanSkipPlayer) (const edict_t *player); int (*pfnDeltaFindField) (struct delta_s *pFields, const char *fieldname); @@ -338,9 +337,9 @@ typedef struct void (*pfnPM_Move) (struct playermove_s *ppmove, int server); void (*pfnPM_Init) (struct playermove_s *ppmove); char (*pfnPM_FindTextureType) (char *name); - void (*pfnSetupVisibility) (struct edict_s *pViewEntity, struct edict_s *client, unsigned char **pvs, unsigned char **pas); + void (*pfnSetupVisibility) (struct edict_s *pViewEntity, struct edict_s *client, uint8 **pvs, uint8 **pas); void (*pfnUpdateClientData) (const struct edict_s *ent, int sendweapons, struct clientdata_s *cd); - int (*pfnAddToFullPack) (struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, unsigned char *pSet); + int (*pfnAddToFullPack) (struct entity_state_s *state, int e, edict_t *ent, edict_t *host, int hostflags, int player, uint8 *pSet); void (*pfnCreateBaseline) (int player, int eindex, struct entity_state_s *baseline, struct edict_s *entity, int playermodelindex, float* player_mins, float* player_maxs); void (*pfnRegisterEncoders) (void); int (*pfnGetWeaponData) (struct edict_s *player, struct weapon_data_s *info); diff --git a/include/engine/enginecallback.h b/include/engine/enginecallback.h index 44f0f84..ad35a37 100644 --- a/include/engine/enginecallback.h +++ b/include/engine/enginecallback.h @@ -72,7 +72,7 @@ extern enginefuncs_t g_engfuncs; #define RANDOM_LONG (*g_engfuncs.pfnRandomLong) #define RANDOM_FLOAT (*g_engfuncs.pfnRandomFloat) #define GETPLAYERAUTHID (*g_engfuncs.pfnGetPlayerAuthId) -static inline void MESSAGE_BEGIN (int msg_dest, int msg_type, const float *pOrigin = NULL, edict_t *ed = NULL) +static inline void MESSAGE_BEGIN (int msg_dest, int msg_type, const float *pOrigin = nullptr, edict_t *ed = nullptr) { (*g_engfuncs.pfnMessageBegin) (msg_dest, msg_type, pOrigin, ed); } @@ -95,7 +95,7 @@ static inline void MESSAGE_BEGIN (int msg_dest, int msg_type, const float *pOrig #define ALERT (*g_engfuncs.pfnAlertMessage) #define ENGINE_FPRINTF (*g_engfuncs.pfnEngineFprintf) #define ALLOC_PRIVATE (*g_engfuncs.pfnPvAllocEntPrivateData) -#define GET_PRIVATE(pent) (pent ? (pent->pvPrivateData) : NULL); +#define GET_PRIVATE(pent) (pent ? (pent->pvPrivateData) : nullptr); #define FREE_PRIVATE (*g_engfuncs.pfnFreeEntPrivateData) #define ALLOC_STRING (*g_engfuncs.pfnAllostring) #define FIND_ENTITY_BY_STRING (*g_engfuncs.pfnFindEntityByString) diff --git a/include/engine/extdll.h b/include/engine/extdll.h index 450ec1b..1e39b6b 100644 --- a/include/engine/extdll.h +++ b/include/engine/extdll.h @@ -16,21 +16,7 @@ #ifndef EXTDLL_H #define EXTDLL_H -#ifdef DLL_DEBUG -#define DEBUG 1 -#endif - #ifdef _MSC_VER - #pragma warning (disable : 4244) // int or float down-conversion - #pragma warning (disable : 4305) // int or float data truncation - #pragma warning (disable : 4201) // nameless struct/union - #pragma warning (disable : 4514) // unreferenced inline function removed - #pragma warning (disable : 4100) // unreferenced formal parameter - #pragma warning (disable : 4715) // not all control paths return a value - #pragma warning (disable : 4996) // function was declared deprecated - #pragma warning (disable : 4702) // unreachable code - #pragma warning (disable : 4706) // assignment within conditional expression - /* disable deprecation warnings concerning unsafe CRT functions */ #if !defined _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE @@ -49,7 +35,7 @@ #define FALSE 0 #define TRUE (!FALSE) typedef unsigned long ULONG; -typedef unsigned char BYTE; +typedef uint8 BYTE; typedef int BOOL; #define MAX_PATH PATH_MAX @@ -68,8 +54,6 @@ typedef int BOOL; #include "stdlib.h" #include "math.h" -#include - typedef int func_t; // typedef int string_t; // from engine's pr_comp.h; typedef float vec_t; // needed before including progdefs.h diff --git a/include/engine/meta_api.h b/include/engine/meta_api.h index f1f6788..2645c84 100644 --- a/include/engine/meta_api.h +++ b/include/engine/meta_api.h @@ -8,6 +8,7 @@ #ifndef META_API_H #define META_API_H + typedef int (*GameAPI_t) (gamefuncs_t *, int); typedef int (*GameAPI2_t) (gamefuncs_t *, int *); typedef int (*NewAPI2_t) (gamefuncs_t *, int *); @@ -18,9 +19,6 @@ typedef int (*GETENTITYAPI2_FN) (gamefuncs_t *pFunctionTable, int *interfaceVers typedef int (*GETNEWDLLFUNCTIONS_FN) (newgamefuncs_t *pFunctionTable, int *interfaceVersion); typedef int (*GET_ENGINE_FUNCTIONS_FN) (enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion); -C_DLLEXPORT int GetEntityAPI (gamefuncs_t *pFunctionTable, int interfaceVersion); -C_DLLEXPORT int GetEntityAPI2 (gamefuncs_t *pFunctionTable, int *interfaceVersion); -C_DLLEXPORT int GetNewDLLFunctions (newgamefuncs_t *pNewFunctionTable, int *interfaceVersion); #define META_INTERFACE_VERSION "5:13" @@ -159,26 +157,6 @@ extern mutil_funcs_t *gpMetaUtilFuncs; extern meta_globals_t *gpMetaGlobals; extern metamod_funcs_t gMetaFunctionTable; -C_DLLEXPORT void Meta_Init (void); -typedef void (*META_INIT_FN) (void); - -C_DLLEXPORT int Meta_Query (char *interfaceVersion, plugin_info_t **plinfo, mutil_funcs_t *pMetaUtilFuncs); -typedef int (*META_QUERY_FN) (char *interfaceVersion, plugin_info_t **plinfo, mutil_funcs_t *pMetaUtilFuncs); - -C_DLLEXPORT int Meta_Attach (PLUG_LOADTIME now, metamod_funcs_t *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs); -typedef int (*META_ATTACH_FN) (PLUG_LOADTIME now, metamod_funcs_t *pFunctionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs); - -C_DLLEXPORT int Meta_Detach (PLUG_LOADTIME now, PL_UNLOAD_REASON reason); -typedef int (*META_DETACH_FN) (PLUG_LOADTIME now, PL_UNLOAD_REASON reason); - -C_DLLEXPORT int GetEntityAPI_Post (gamefuncs_t *pFunctionTable, int interfaceVersion); -C_DLLEXPORT int GetEntityAPI2_Post (gamefuncs_t *pFunctionTable, int *interfaceVersion); - -C_DLLEXPORT int GetNewDLLFunctions_Post (newgamefuncs_t *pNewFunctionTable, int *interfaceVersion); -C_DLLEXPORT int GetEngineFunctions (enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion); -C_DLLEXPORT int GetEngineFunctions_Post (enginefuncs_t *pengfuncsFromEngine, int *interfaceVersion); - - #define MDLL_FUNC gpGamedllFuncs->dllapi_table diff --git a/include/engine/mutil.h b/include/engine/mutil.h deleted file mode 100644 index 10b252e..0000000 --- a/include/engine/mutil.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2001-2006 Will Day - * See the file "dllapi.h" in this folder for full information - */ - -// Simplified version by Wei Mingzhi - -#ifndef MUTIL_H -#define MUTIL_H - -#include "plinfo.h" -#include "sdk_util.h" - -#endif /* MUTIL_H */ \ No newline at end of file diff --git a/include/engine/plinfo.h b/include/engine/plinfo.h deleted file mode 100644 index b93a33f..0000000 --- a/include/engine/plinfo.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2001-2006 Will Day - * See the file "dllapi.h" in this folder for full information - */ - -// Simplified version by Wei Mingzhi - -#ifndef PLINFO_H -#define PLINFO_H - -#endif diff --git a/include/engine/progdefs.h b/include/engine/progdefs.h index f6b6400..71a02c0 100644 --- a/include/engine/progdefs.h +++ b/include/engine/progdefs.h @@ -116,8 +116,8 @@ typedef struct entvars_s float frame; // % playback position in animation sequences (0..255) float animtime; // world time when frame was set float framerate; // animation playback rate (-8x to 8x) - byte controller[4]; // bone controller setting (0..255) - byte blending[2]; // blending amount between sub-sequences (0..255) + uint8 controller[4]; // bone controller setting (0..255) + uint8 blending[2]; // blending amount between sub-sequences (0..255) float scale; // sprite rendering scale (0..255) diff --git a/include/engine/sdk_util.h b/include/engine/sdk_util.h deleted file mode 100644 index 41aec0b..0000000 --- a/include/engine/sdk_util.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2001-2006 Will Day - * See the file "dllapi.h" in this folder for full information - */ - -// Simplified version by Wei Mingzhi - -#ifndef SDK_UTIL_H -#define SDK_UTIL_H - -#ifdef DEBUG -#undef DEBUG -#endif - -#include - - - - -short FixedSigned16 (float value, float scale); -unsigned short FixedUnsigned16 (float value, float scale); - -#endif diff --git a/include/engine/util.h b/include/engine/util.h index 82ccd24..9f0b14a 100644 --- a/include/engine/util.h +++ b/include/engine/util.h @@ -73,94 +73,14 @@ typedef int BOOL; #define M_PI 3.1415926 #endif -// -// Conversion among the three types of "entity", including identity-conversions. -// -#if 0 -static inline edict_t *ENT (const entvars_t *pev) -{ - return pev->pContainingEntity; -} -static inline edict_t *ENT (edict_t *pent) -{ - return pent; -} -static inline edict_t *ENT (EOFFSET eoffset) -{ - return (*g_engfuncs.pfnPEntityOfEntOffset) (eoffset); -} -static inline EOFFSET OFFSET (EOFFSET eoffset) -{ - return eoffset; -} -static inline EOFFSET OFFSET (const edict_t *pent) -{ -#if _DEBUG - if (!pent) - ALERT (at_error, "Bad ent in OFFSET()\n"); -#endif - return (*g_engfuncs.pfnEntOffsetOfPEntity) (pent); -} -static inline EOFFSET OFFSET (entvars_t *pev) -{ -#if _DEBUG - if (!pev) - ALERT (at_error, "Bad pev in OFFSET()\n"); -#endif - return OFFSET (ENT (pev)); -} -static inline entvars_t *VARS (entvars_t *pev) -{ - return pev; -} - -static inline entvars_t *VARS (edict_t *pent) -{ - if (!pent) - return NULL; - - return &pent->v; -} - -static inline entvars_t *VARS (EOFFSET eoffset) -{ - return VARS (ENT (eoffset)); -} -#endif +short FixedSigned16 (float value, float scale); +uint16 FixedUnsigned16 (float value, float scale); static inline void MESSAGE_BEGIN (int msg_dest, int msg_type, const float *pOrigin, entvars_t *ent) { (*g_engfuncs.pfnMessageBegin) (msg_dest, msg_type, pOrigin, ent->pContainingEntity); } -#if 0 -// Testing the three types of "entity" for nullity -#define eoNullEntity 0 -static inline BOOL FNullEnt (EOFFSET eoffset) -{ - return eoffset == 0; -} -static inline BOOL FNullEnt (entvars_t *pev) -{ - return pev == NULL || FNullEnt (OFFSET (pev)); -} -static inline int FNullEnt (const edict_t *pent) -{ - return !pent || !(*g_engfuncs.pfnEntOffsetOfPEntity) (pent); -} - -// Testing strings for nullity -#define iStringNull 0 -static inline BOOL FStringNull (int stingPtr) -{ - return stingPtr == iStringNull; -} - -#define cchMapNameMost 32 - -#define SAFE_FUNCTION_CALL(pfn,args) try { pfn args; } catch (...) { } -#endif - // Dot products for view cone checking #define VIEW_FIELD_FULL (float)-1.0 // +-180 degrees #define VIEW_FIELD_WIDE (float)-0.7 // +-135 degrees 0.1 // +-85 degrees, used for full FOV checks @@ -195,8 +115,8 @@ typedef struct hudtextparms_s float x; float y; int effect; - byte r1, g1, b1, a1; - byte r2, g2, b2, a2; + uint8 r1, g1, b1, a1; + uint8 r2, g2, b2, a2; float fadeinTime; float fadeoutTime; float holdTime; diff --git a/include/globals.h b/include/globals.h index 38cdef3..6b53b07 100644 --- a/include/globals.h +++ b/include/globals.h @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #pragma once @@ -69,7 +69,7 @@ extern gamefuncs_t g_functionTable; static inline bool IsNullString (const char *input) { - if (input == NULL) + if (input == nullptr) return true; return *input == '\0'; diff --git a/include/platform.h b/include/platform.h index b48457b..e325090 100644 --- a/include/platform.h +++ b/include/platform.h @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #pragma once @@ -40,14 +40,14 @@ #include #include - #define DLL_ENTRYPOINT int STDCALL DllMain (HINSTANCE, DWORD dwReason, LPVOID) + #define DLL_ENTRYPOINT int __stdcall DllMain (HINSTANCE, DWORD dwReason, LPVOID) #define DLL_DETACHING (dwReason == DLL_PROCESS_DETACH) #define DLL_RETENTRY return TRUE #if defined (COMPILER_VISUALC) - #define DLL_GIVEFNPTRSTODLL extern "C" void STDCALL + #define DLL_GIVEFNPTRSTODLL extern "C" void __stdcall #elif defined (COMPILER_MINGW32) - #define DLL_GIVEFNPTRSTODLL SHARED_LIBRARAY_EXPORT void STDCALL + #define DLL_GIVEFNPTRSTODLL SHARED_LIBRARAY_EXPORT void __stdcall #endif // specify export parameter @@ -59,7 +59,7 @@ typedef int (FAR *EntityAPI_t) (gamefuncs_t *, int); typedef int (FAR *NewEntityAPI_t) (newgamefuncs_t *, int *); typedef int (FAR *BlendAPI_t) (int, void **, void *, float (*)[3][4], float (*)[128][3][4]); - typedef void (STDCALL *FuncPointers_t) (enginefuncs_t *, globalvars_t *); + typedef void (__stdcall *FuncPointers_t) (enginefuncs_t *, globalvars_t *); typedef void (FAR *EntityPtr_t) (entvars_t *); #elif defined (PLATFORM_LINUX) || defined (PLATFORM_OSX) @@ -105,9 +105,9 @@ public: Library (const char *fileName) { - m_ptr = NULL; + m_ptr = nullptr; - if (fileName == NULL) + if (fileName == nullptr) return; LoadLib (fileName); @@ -140,7 +140,7 @@ public: template R GetFuncAddr (const char *function) { if (!IsLoaded ()) - return NULL; + return nullptr; #ifdef PLATFORM_WIN32 return reinterpret_cast (GetProcAddress (static_cast (m_ptr), function)); @@ -156,6 +156,6 @@ public: inline bool IsLoaded (void) const { - return m_ptr != NULL; + return m_ptr != nullptr; } }; diff --git a/include/resource.h b/include/resource.h index 850bca5..ec0471c 100644 --- a/include/resource.h +++ b/include/resource.h @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #pragma once diff --git a/project/yapb.rc b/project/yapb.rc index 2e877ad..b590ba2 100644 --- a/project/yapb.rc +++ b/project/yapb.rc @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include diff --git a/project/yapb.vcxproj b/project/yapb.vcxproj index 3d9d590..9de0d83 100644 --- a/project/yapb.vcxproj +++ b/project/yapb.vcxproj @@ -15,17 +15,12 @@ - - - - - diff --git a/project/yapb.vcxproj.filters b/project/yapb.vcxproj.filters index 3fe3d15..9456d00 100644 --- a/project/yapb.vcxproj.filters +++ b/project/yapb.vcxproj.filters @@ -33,9 +33,6 @@ include\engine - - include\engine - include\engine @@ -45,24 +42,12 @@ include\engine - - include\engine - - - include\engine - include\engine - - include\engine - include\engine - - include\engine - include diff --git a/source/basecode.cpp b/source/basecode.cpp index bd1aa7b..db8dceb 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -27,12 +27,13 @@ ConVar yb_botbuy ("yb_botbuy", "1"); ConVar yb_chatter_path ("yb_chatter_path", "sound/radio/bot"); ConVar yb_restricted_weapons ("yb_restricted_weapons", ""); +ConVar yb_best_weapon_picker_type ("yb_best_weapon_picker_type", "2"); // game console variables -ConVar mp_c4timer ("mp_c4timer", NULL, VT_NOREGISTER); -ConVar mp_buytime ("mp_buytime", NULL, VT_NOREGISTER); -ConVar mp_footsteps ("mp_footsteps", NULL, VT_NOREGISTER); -ConVar sv_gravity ("sv_gravity", NULL, VT_NOREGISTER); +ConVar mp_c4timer ("mp_c4timer", nullptr, VT_NOREGISTER); +ConVar mp_buytime ("mp_buytime", nullptr, VT_NOREGISTER); +ConVar mp_footsteps ("mp_footsteps", nullptr, VT_NOREGISTER); +ConVar sv_gravity ("sv_gravity", nullptr, VT_NOREGISTER); int Bot::GetMessageQueue (void) { @@ -57,7 +58,7 @@ void Bot::PushMessageQueue (int message) { Bot *otherBot = bots.GetBot (i); - if (otherBot != NULL && otherBot->pev != pev) + if (otherBot != nullptr && otherBot->pev != pev) { if (m_notKilled == otherBot->m_notKilled) { @@ -97,7 +98,7 @@ bool Bot::IsInViewCone (const Vector &origin) return ::IsInViewCone (origin, GetEntity ()); } -bool Bot::ItemIsVisible (const Vector &destination, char *itemName) +bool Bot::ItemIsVisible (const Vector &destination, const char *itemName) { TraceResult tr; @@ -133,7 +134,7 @@ bool Bot::EntityIsVisible (const Vector &dest, bool fromBody) void Bot::CheckGrenadeThrow (void) { // check if throwing a grenade is a good thing to do... - if (m_lastEnemy == NULL || yb_ignore_enemies.GetBool () || yb_jasonmode.GetBool () || m_grenadeCheckTime > engine.Time () || m_isUsingGrenade || GetTaskId () == TASK_PLANTBOMB || GetTaskId () == TASK_DEFUSEBOMB || m_isReloading || !IsAlive (m_lastEnemy)) + if (m_lastEnemy == nullptr || yb_ignore_enemies.GetBool () || yb_jasonmode.GetBool () || m_grenadeCheckTime > engine.Time () || m_isUsingGrenade || GetTaskId () == TASK_PLANTBOMB || GetTaskId () == TASK_DEFUSEBOMB || m_isReloading || !IsAlive (m_lastEnemy)) { m_states &= ~(STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG); return; @@ -154,7 +155,7 @@ void Bot::CheckGrenadeThrow (void) return; } // care about different types of grenades - if ((grenadeToThrow == WEAPON_EXPLOSIVE || grenadeToThrow == WEAPON_SMOKE) && Random.Long (0, 100) < 45 && !(m_states & (STATE_SEEING_ENEMY | STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG))) + if ((grenadeToThrow == WEAPON_EXPLOSIVE || grenadeToThrow == WEAPON_SMOKE) && Random.Int (0, 100) < 45 && !(m_states & (STATE_SEEING_ENEMY | STATE_THROW_HE | STATE_THROW_FB | STATE_THROW_SG))) { float distance = (m_lastEnemy->v.origin - pev->origin).GetLength (); @@ -222,7 +223,7 @@ void Bot::CheckGrenadeThrow (void) } } } - else if (IsAlive (m_lastEnemy) && grenadeToThrow == WEAPON_FLASHBANG && (m_lastEnemy->v.origin - pev->origin).GetLength () < 800.0f && !(m_aimFlags & AIM_ENEMY) && Random.Long (0, 100) < 50) + else if (IsAlive (m_lastEnemy) && grenadeToThrow == WEAPON_FLASHBANG && (m_lastEnemy->v.origin - pev->origin).GetLength () < 800.0f && !(m_aimFlags & AIM_ENEMY) && Random.Int (0, 100) < 50) { bool allowThrowing = true; Array inRadius; @@ -283,12 +284,12 @@ void Bot::AvoidGrenades (void) // check if old pointers to grenade is invalid if (engine.IsNullEntity (m_avoidGrenade)) { - m_avoidGrenade = NULL; + m_avoidGrenade = nullptr; m_needAvoidGrenade = 0; } else if ((m_avoidGrenade->v.flags & FL_ONGROUND) || (m_avoidGrenade->v.effects & EF_NODRAW)) { - m_avoidGrenade = NULL; + m_avoidGrenade = nullptr; m_needAvoidGrenade = 0; } Array activeGrenades = bots.GetActiveGrenades (); @@ -507,10 +508,10 @@ edict_t *Bot::FindBreakable (void) return ent; } } - m_breakableEntity = NULL; + m_breakableEntity = nullptr; m_breakableOrigin.Zero (); - return NULL; + return nullptr; } void Bot::SetIdealReactionTimes (bool actual) @@ -559,14 +560,14 @@ void Bot::FindItem (void) // don't try to pickup anything while on ladder or trying to escape from bomb... if (IsOnLadder () || GetTaskId () == TASK_ESCAPEFROMBOMB || yb_jasonmode.GetBool ()) { - m_pickupItem = NULL; + m_pickupItem = nullptr; m_pickupType = PICKUP_NONE; return; } - edict_t *ent = NULL, *pickupItem = NULL; - Bot *bot = NULL; + edict_t *ent = nullptr, *pickupItem = nullptr; + Bot *bot = nullptr; float distance, minDistance = 341.0f; @@ -596,20 +597,20 @@ void Bot::FindItem (void) else { - m_pickupItem = NULL; + m_pickupItem = nullptr; m_pickupType = PICKUP_NONE; } } - ent = NULL; - pickupItem = NULL; + ent = nullptr; + pickupItem = nullptr; PickupType pickupType = PICKUP_NONE; Vector pickupOrigin; Vector entityOrigin; - m_pickupItem = NULL; + m_pickupItem = nullptr; m_pickupType = PICKUP_NONE; while (!engine.IsNullEntity (ent = FIND_ENTITY_IN_SPHERE (ent, pev->origin, searchRadius))) @@ -619,37 +620,40 @@ void Bot::FindItem (void) if ((ent->v.effects & EF_NODRAW) || ent == m_itemIgnore) continue; // someone owns this weapon or it hasn't respawned yet + auto classname = STRING (ent->v.classname); + auto model = STRING (ent->v.model) + 9; + entityOrigin = engine.GetAbsOrigin (ent); // check if line of sight to object is not blocked (i.e. visible) - if (ItemIsVisible (entityOrigin, const_cast (STRING (ent->v.classname)))) + if (ItemIsVisible (entityOrigin, classname)) { - if (strncmp ("hostage_entity", STRING (ent->v.classname), 14) == 0) + if (strncmp ("hostage_entity", classname, 14) == 0) { allowPickup = true; pickupType = PICKUP_HOSTAGE; } - else if (strncmp ("weaponbox", STRING (ent->v.classname), 9) == 0 && strcmp (STRING (ent->v.model) + 9, "backpack.mdl") == 0) + else if (strncmp ("weaponbox", classname, 9) == 0 && strcmp (model, "backpack.mdl") == 0) { allowPickup = true; pickupType = PICKUP_DROPPED_C4; } - else if ((strncmp ("weaponbox", STRING (ent->v.classname), 9) == 0 || strncmp ("armoury_entity", STRING (ent->v.classname), 14) == 0 || strncmp ("csdm", STRING (ent->v.classname), 4) == 0) && !m_isUsingGrenade) + else if ((strncmp ("weaponbox", classname, 9) == 0 || strncmp ("armoury_entity", classname, 14) == 0 || strncmp ("csdm", classname, 4) == 0) && !m_isUsingGrenade) { allowPickup = true; pickupType = PICKUP_WEAPON; } - else if (strncmp ("weapon_shield", STRING (ent->v.classname), 13) == 0 && !m_isUsingGrenade) + else if (strncmp ("weapon_shield", classname, 13) == 0 && !m_isUsingGrenade) { allowPickup = true; pickupType = PICKUP_SHIELD; } - else if (strncmp ("item_thighpack", STRING (ent->v.classname), 14) == 0 && m_team == CT && !m_hasDefuser) + else if (strncmp ("item_thighpack", classname, 14) == 0 && m_team == CT && !m_hasDefuser) { allowPickup = true; pickupType = PICKUP_DEFUSEKIT; } - else if (strncmp ("grenade", STRING (ent->v.classname), 7) == 0 && strcmp (STRING (ent->v.model) + 9, "c4.mdl") == 0) + else if (strncmp ("grenade", classname, 7) == 0 && strcmp (model, "c4.mdl") == 0) { allowPickup = true; pickupType = PICKUP_PLANTED_C4; @@ -668,32 +672,32 @@ void Bot::FindItem (void) int weaponCarried = GetBestWeaponCarried (); int secondaryWeaponCarried = GetBestSecondaryWeaponCarried (); - if (secondaryWeaponCarried < 7 && (m_ammo[g_weaponSelect[secondaryWeaponCarried].id] > 0.3 * g_weaponDefs[g_weaponSelect[secondaryWeaponCarried].id].ammo1Max) && strcmp (STRING (ent->v.model) + 9, "w_357ammobox.mdl") == 0) + if (secondaryWeaponCarried < 7 && (m_ammo[g_weaponSelect[secondaryWeaponCarried].id] > 0.3 * g_weaponDefs[g_weaponSelect[secondaryWeaponCarried].id].ammo1Max) && strcmp (model, "w_357ammobox.mdl") == 0) allowPickup = false; - else if (!m_isVIP && weaponCarried >= 7 && (m_ammo[g_weaponSelect[weaponCarried].id] > 0.3 * g_weaponDefs[g_weaponSelect[weaponCarried].id].ammo1Max) && strncmp (STRING (ent->v.model) + 9, "w_", 2) == 0) + else if (!m_isVIP && weaponCarried >= 7 && (m_ammo[g_weaponSelect[weaponCarried].id] > 0.3 * g_weaponDefs[g_weaponSelect[weaponCarried].id].ammo1Max) && strncmp (model, "w_", 2) == 0) { - if (strcmp (STRING (ent->v.model) + 9, "w_9mmarclip.mdl") == 0 && !(weaponCarried == WEAPON_FAMAS || weaponCarried == WEAPON_AK47 || weaponCarried == WEAPON_M4A1 || weaponCarried == WEAPON_GALIL || weaponCarried == WEAPON_AUG || weaponCarried == WEAPON_SG552)) + if (strcmp (model, "w_9mmarclip.mdl") == 0 && !(weaponCarried == WEAPON_FAMAS || weaponCarried == WEAPON_AK47 || weaponCarried == WEAPON_M4A1 || weaponCarried == WEAPON_GALIL || weaponCarried == WEAPON_AUG || weaponCarried == WEAPON_SG552)) allowPickup = false; - else if (strcmp (STRING (ent->v.model) + 9, "w_shotbox.mdl") == 0 && !(weaponCarried == WEAPON_M3 || weaponCarried == WEAPON_XM1014)) + else if (strcmp (model, "w_shotbox.mdl") == 0 && !(weaponCarried == WEAPON_M3 || weaponCarried == WEAPON_XM1014)) allowPickup = false; - else if (strcmp (STRING (ent->v.model) + 9, "w_9mmclip.mdl") == 0 && !(weaponCarried == WEAPON_MP5 || weaponCarried == WEAPON_TMP || weaponCarried == WEAPON_P90 || weaponCarried == WEAPON_MAC10 || weaponCarried == WEAPON_UMP45)) + else if (strcmp (model, "w_9mmclip.mdl") == 0 && !(weaponCarried == WEAPON_MP5 || weaponCarried == WEAPON_TMP || weaponCarried == WEAPON_P90 || weaponCarried == WEAPON_MAC10 || weaponCarried == WEAPON_UMP45)) allowPickup = false; - else if (strcmp (STRING (ent->v.model) + 9, "w_crossbow_clip.mdl") == 0 && !(weaponCarried == WEAPON_AWP || weaponCarried == WEAPON_G3SG1 || weaponCarried == WEAPON_SCOUT || weaponCarried == WEAPON_SG550)) + else if (strcmp (model, "w_crossbow_clip.mdl") == 0 && !(weaponCarried == WEAPON_AWP || weaponCarried == WEAPON_G3SG1 || weaponCarried == WEAPON_SCOUT || weaponCarried == WEAPON_SG550)) allowPickup = false; - else if (strcmp (STRING (ent->v.model) + 9, "w_chainammo.mdl") == 0 && weaponCarried == WEAPON_M249) + else if (strcmp (model, "w_chainammo.mdl") == 0 && weaponCarried == WEAPON_M249) allowPickup = false; } else if (m_isVIP || !RateGroundWeapon (ent)) allowPickup = false; - else if (strcmp (STRING (ent->v.model) + 9, "medkit.mdl") == 0 && pev->health >= 100.0f) + else if (strcmp (model, "medkit.mdl") == 0 && pev->health >= 100.0f) allowPickup = false; - else if ((strcmp (STRING (ent->v.model) + 9, "kevlar.mdl") == 0 || strcmp (STRING (ent->v.model) + 9, "battery.mdl") == 0) && pev->armorvalue >= 100.0f) // armor vest + else if ((strcmp (model, "kevlar.mdl") == 0 || strcmp (model, "battery.mdl") == 0) && pev->armorvalue >= 100.0f) // armor vest allowPickup = false; - else if (strcmp (STRING (ent->v.model) + 9, "flashbang.mdl") == 0 && (pev->weapons & (1 << WEAPON_FLASHBANG))) // concussion grenade + else if (strcmp (model, "flashbang.mdl") == 0 && (pev->weapons & (1 << WEAPON_FLASHBANG))) // concussion grenade allowPickup = false; - else if (strcmp (STRING (ent->v.model) + 9, "hegrenade.mdl") == 0 && (pev->weapons & (1 << WEAPON_EXPLOSIVE))) // explosive grenade + else if (strcmp (model, "hegrenade.mdl") == 0 && (pev->weapons & (1 << WEAPON_EXPLOSIVE))) // explosive grenade allowPickup = false; - else if (strcmp (STRING (ent->v.model) + 9, "smokegrenade.mdl") == 0 && (pev->weapons & (1 << WEAPON_SMOKE))) // smoke grenade + else if (strcmp (model, "smokegrenade.mdl") == 0 && (pev->weapons & (1 << WEAPON_SMOKE))) // smoke grenade allowPickup = false; } else if (pickupType == PICKUP_SHIELD) // found a shield on ground? @@ -716,7 +720,7 @@ void Bot::FindItem (void) m_itemIgnore = ent; allowPickup = false; - if (!m_defendHostage && m_difficulty >= 3 && Random.Long (0, 100) < 30 && m_timeCamping + 15.0f < engine.Time ()) + if (!m_defendHostage && m_difficulty >= 3 && Random.Int (0, 100) < 30 && m_timeCamping + 15.0f < engine.Time ()) { int index = FindDefendWaypoint (entityOrigin); @@ -760,7 +764,7 @@ void Bot::FindItem (void) else m_campButtons &= ~IN_DUCK; - if (Random.Long (0, 100) < 90) + if (Random.Int (0, 100) < 90) ChatterMessage (Chatter_DefendingBombSite); } else @@ -776,7 +780,7 @@ void Bot::FindItem (void) allowPickup = false; // never pickup dead hostage else for (int i = 0; i < engine.MaxClients (); i++) { - if ((bot = bots.GetBot (i)) != NULL && bot->m_notKilled) + if ((bot = bots.GetBot (i)) != nullptr && bot->m_notKilled) { for (int j = 0; j < MAX_HOSTAGES; j++) { @@ -797,7 +801,7 @@ void Bot::FindItem (void) return; } - if (Random.Long (0, 100) < 90) + if (Random.Int (0, 100) < 90) ChatterMessage (Chatter_FoundBombPlace); allowPickup = !IsBombDefusing (waypoints.GetBombPosition ()) || m_hasProgressBar; @@ -822,7 +826,7 @@ void Bot::FindItem (void) else m_campButtons &= ~IN_DUCK; - if (Random.Long (0, 100) < 90) + if (Random.Int (0, 100) < 90) ChatterMessage (Chatter_DefendingBombSite); } } @@ -831,7 +835,7 @@ void Bot::FindItem (void) m_itemIgnore = ent; allowPickup = false; - if (!m_defendedBomb && m_difficulty >= 2 && Random.Long (0, 100) < 80) + if (!m_defendedBomb && m_difficulty >= 2 && Random.Int (0, 100) < 80) { int index = FindDefendWaypoint (entityOrigin); @@ -870,9 +874,9 @@ void Bot::FindItem (void) { for (int i = 0; i < engine.MaxClients (); i++) { - if ((bot = bots.GetBot (i)) != NULL && bot->m_notKilled && bot->m_pickupItem == pickupItem) + if ((bot = bots.GetBot (i)) != nullptr && bot->m_notKilled && bot->m_pickupItem == pickupItem) { - m_pickupItem = NULL; + m_pickupItem = nullptr; m_pickupType = PICKUP_NONE; return; @@ -882,7 +886,7 @@ void Bot::FindItem (void) if (pickupOrigin.z > EyePosition ().z + (m_pickupType == PICKUP_HOSTAGE ? 40.0f : 15.0f) || IsDeadlyDrop (pickupOrigin)) // check if item is too high to reach, check if getting the item would hurt bot { m_itemIgnore = m_pickupItem; - m_pickupItem = NULL; + m_pickupItem = nullptr; m_pickupType = PICKUP_NONE; return; @@ -973,7 +977,7 @@ void Bot::SwitchChatterIcon (bool show) if (!(client.flags & CF_USED) || (client.ent->v.flags & FL_FAKECLIENT) || client.team != m_team) continue; - MESSAGE_BEGIN (MSG_ONE, engine.FindMessageId (NETMSG_BOTVOICE), NULL, g_clients[i].ent); // begin message + MESSAGE_BEGIN (MSG_ONE, engine.FindMessageId (NETMSG_BOTVOICE), nullptr, g_clients[i].ent); // begin message WRITE_BYTE (show); // switch on/off WRITE_BYTE (GetIndex ()); MESSAGE_END (); @@ -1009,7 +1013,7 @@ void Bot::InstantChatterMessage (int type) if (!IsValidPlayer (ent) || IsValidBot (ent) || engine.GetTeam (ent) != m_team) continue; - MESSAGE_BEGIN (MSG_ONE, engine.FindMessageId (NETMSG_SENDAUDIO), NULL, ent); // begin message + MESSAGE_BEGIN (MSG_ONE, engine.FindMessageId (NETMSG_SENDAUDIO), nullptr, ent); // begin message WRITE_BYTE (GetIndex ()); if (pev->deadflag & DEAD_DYING) @@ -1163,7 +1167,7 @@ void Bot::CheckMessageQueue (void) { Bot *bot = bots.GetBot (i); - if (bot != NULL) + if (bot != nullptr) { if (pev != bot->pev && bot->m_team == m_team) { @@ -1180,7 +1184,7 @@ void Bot::CheckMessageQueue (void) switch (GetTaskId ()) { case TASK_NORMAL: - if (GetTask ()->data != -1 && Random.Long (0, 100) < 70) + if (GetTask ()->data != -1 && Random.Int (0, 100) < 70) { Path *path = waypoints.GetPath (GetTask ()->data); @@ -1193,12 +1197,12 @@ void Bot::CheckMessageQueue (void) } else if (path->flags & FLAG_RESCUE) InstantChatterMessage (Chatter_RescuingHostages); - else if ((path->flags & FLAG_CAMP) && Random.Long (0, 100) > 15) + else if ((path->flags & FLAG_CAMP) && Random.Int (0, 100) > 15) InstantChatterMessage (Chatter_GoingToCamp); else InstantChatterMessage (Chatter_HearSomething); } - else if (Random.Long (0, 100) < 40) + else if (Random.Int (0, 100) < 40) InstantChatterMessage (Chatter_ReportingIn); break; @@ -1208,7 +1212,7 @@ void Bot::CheckMessageQueue (void) break; case TASK_CAMP: - if (Random.Long (0, 100) < 40) + if (Random.Int (0, 100) < 40) { if (g_bombPlanted && m_team == TERRORIST) @@ -1297,7 +1301,7 @@ bool Bot::IsRestricted (int weaponIndex) FOR_EACH_AE (bannedWeapons, i) { - const char *banned = STRING (GetWeaponReturn (true, NULL, weaponIndex)); + const char *banned = STRING (GetWeaponReturn (true, nullptr, weaponIndex)); // check is this weapon is banned if (strncmp (bannedWeapons[i].GetBuffer (), banned, bannedWeapons[i].GetLength ()) == 0) @@ -1382,21 +1386,53 @@ bool Bot::IsMorePowerfulWeaponCanBeBought (void) int Bot::PickBestFromRandom(int *random, int count, int moneySave) { - // this function taken from gina bot, it's picks best available weapon from random choice + // this function picks best available weapon from random choice with money save - float buyFactor = (m_moneyAmount - static_cast (moneySave)) / (16000.0f - static_cast (moneySave)) * 3.0f; + if (yb_best_weapon_picker_type.GetInt () == 1) + { + float buyFactor = (m_moneyAmount - static_cast (moneySave)) / (16000.0f - static_cast (moneySave)) * 3.0f; - if (buyFactor < 1.0f) - buyFactor = 1.0f; + if (buyFactor < 1.0f) + buyFactor = 1.0f; - return random[static_cast (static_cast (count - 1) * log10f (Random.Float (1, powf (10.0f, buyFactor))) / buyFactor + 0.5f)]; + // swap array values + for (int *begin = random, *end = random + count - 1; begin < end; ++begin, --end) + { + int swap = *end; + + *end = *begin; + *begin = swap; + } + return random[static_cast (static_cast (count - 1) * log10f (Random.Float (1, powf (10.0f, buyFactor))) / buyFactor + 0.5f)]; + } + + int chance = 95; + + // high skilled bots almost always prefer best weapon + if (m_difficulty < 4) + { + if (m_personality == PERSONALITY_NORMAL) + chance = 50; + else if (m_personality == PERSONALITY_CAREFUL) + chance = 75; + } + + for (int i = 0; i < count; i++) + { + auto weapon = &g_weaponSelect[random[i]]; + + // if wea have enough money for weapon buy it + if (weapon->price + moneySave < m_moneyAmount + Random.Int (50, 200) && Random.Int (0, 100) < chance) + return random[i]; + } + return random[Random.Int (0, count - 1)]; } void Bot::PurchaseWeapons (void) { // this function does all the work in selecting correct buy menus for most weapons/items - WeaponSelect *selectedWeapon = NULL; + WeaponSelect *selectedWeapon = nullptr; m_nextBuyTime = engine.Time () + Random.Float (0.3f, 0.5f); int count = 0, foundWeapons = 0; @@ -1531,7 +1567,7 @@ void Bot::PurchaseWeapons (void) continue; // save money for grenade for example? - moneySave = Random.Long (300, 600); + moneySave = Random.Int (500, 1000); if (bots.GetLastWinner () == m_team) moneySave = 0; @@ -1552,12 +1588,24 @@ void Bot::PurchaseWeapons (void) else chosenWeapon = choices[foundWeapons - 1]; + char select_wpns[2222] = { 0, }; + for (int j = 0; j < foundWeapons; j++) + { + strcat (select_wpns, g_weaponSelect[choices[j]].weaponName); + strcat (select_wpns, " "); + } + + char buf[3333] = { 0, }; + sprintf (buf, "got choice from %sand choosen %s", select_wpns, g_weaponSelect[chosenWeapon].weaponName); + + engine.Printf ("%s -> (primary) %s", STRING (pev->netname), buf); + selectedWeapon = &g_weaponSelect[chosenWeapon]; } else - selectedWeapon = NULL; + selectedWeapon = nullptr; - if (selectedWeapon != NULL) + if (selectedWeapon != nullptr) { engine.IssueBotCommand (GetEntity (), "buy;menuselect %d", selectedWeapon->buyGroup); @@ -1584,7 +1632,7 @@ void Bot::PurchaseWeapons (void) } case BUYSTATE_ARMOR_VESTHELM: // if armor is damaged and bot has some money, buy some armor - if (pev->armorvalue < Random.Long (50, 80) && (isPistolMode || (teamEcoValid && HasPrimaryWeapon ()))) + if (pev->armorvalue < Random.Int (50, 80) && (isPistolMode || (teamEcoValid && HasPrimaryWeapon ()))) { // if bot is rich, buy kevlar + helmet, else buy a single kevlar if (m_moneyAmount > 1500 && !IsRestricted (WEAPON_ARMORHELM)) @@ -1595,7 +1643,7 @@ void Bot::PurchaseWeapons (void) break; case BUYSTATE_SECONDARY_WEAPON: // if bot has still some money, buy a better secondary weapon - if (isPistolMode || (HasPrimaryWeapon () && (pev->weapons & ((1 << WEAPON_USP) | (1 << WEAPON_GLOCK))) && m_moneyAmount > Random.Long (7500, 9000))) + if (isPistolMode || (HasPrimaryWeapon () && (pev->weapons & ((1 << WEAPON_USP) | (1 << WEAPON_GLOCK))) && m_moneyAmount > Random.Int (7500, 9000))) { do { @@ -1624,7 +1672,7 @@ void Bot::PurchaseWeapons (void) if (selectedWeapon->teamStandard != 2 && selectedWeapon->teamStandard != m_team) continue; - if (selectedWeapon->price <= (m_moneyAmount - Random.Long (100, 200))) + if (selectedWeapon->price <= (m_moneyAmount - Random.Int (100, 200))) choices[foundWeapons++] = *ptr; } while (count < NUM_WEAPONS && foundWeapons < 4); @@ -1636,16 +1684,29 @@ void Bot::PurchaseWeapons (void) // choose randomly from the best ones... if (foundWeapons > 1) - chosenWeapon = PickBestFromRandom (choices, foundWeapons, Random.Long (100, 200)); + chosenWeapon = PickBestFromRandom (choices, foundWeapons, Random.Int (100, 200)); else chosenWeapon = choices[foundWeapons - 1]; + char select_wpns[2222] = { 0, }; + for (int j = 0; j < foundWeapons; j++) + { + strcat (select_wpns, g_weaponSelect[choices[j]].weaponName); + strcat (select_wpns, " "); + } + + char buf[3333] = { 0, }; + sprintf (buf, "got choice from %sand choosen %s", select_wpns, g_weaponSelect[chosenWeapon].weaponName); + + engine.Printf ("%s -> (sec) %s", STRING (pev->netname), buf); + + selectedWeapon = &g_weaponSelect[chosenWeapon]; } else - selectedWeapon = NULL; + selectedWeapon = nullptr; - if (selectedWeapon != NULL) + if (selectedWeapon != nullptr) { engine.IssueBotCommand (GetEntity (), "buy;menuselect %d", selectedWeapon->buyGroup); @@ -1664,21 +1725,21 @@ void Bot::PurchaseWeapons (void) break; case BUYSTATE_GRENADES: // if bot has still some money, choose if bot should buy a grenade or not - if (Random.Long (1, 100) < g_grenadeBuyPrecent[0] && m_moneyAmount >= 400 && !IsRestricted (WEAPON_EXPLOSIVE)) + if (Random.Int (1, 100) < g_grenadeBuyPrecent[0] && m_moneyAmount >= 400 && !IsRestricted (WEAPON_EXPLOSIVE)) { // buy a he grenade engine.IssueBotCommand (GetEntity (), "buyequip"); engine.IssueBotCommand (GetEntity (), "menuselect 4"); } - if (Random.Long (1, 100) < g_grenadeBuyPrecent[1] && m_moneyAmount >= 300 && teamEcoValid && !IsRestricted (WEAPON_FLASHBANG)) + if (Random.Int (1, 100) < g_grenadeBuyPrecent[1] && m_moneyAmount >= 300 && teamEcoValid && !IsRestricted (WEAPON_FLASHBANG)) { // buy a concussion grenade, i.e., 'flashbang' engine.IssueBotCommand (GetEntity (), "buyequip"); engine.IssueBotCommand (GetEntity (), "menuselect 3"); } - if (Random.Long (1, 100) < g_grenadeBuyPrecent[2] && m_moneyAmount >= 400 && teamEcoValid && !IsRestricted (WEAPON_SMOKE)) + if (Random.Int (1, 100) < g_grenadeBuyPrecent[2] && m_moneyAmount >= 400 && teamEcoValid && !IsRestricted (WEAPON_SMOKE)) { // buy a smoke grenade engine.IssueBotCommand (GetEntity (), "buyequip"); @@ -1687,7 +1748,7 @@ void Bot::PurchaseWeapons (void) break; case BUYSTATE_DEFUSER: // if bot is CT and we're on a bomb map, randomly buy the defuse kit - if ((g_mapType & MAP_DE) && m_team == CT && Random.Long (1, 100) < 80 && m_moneyAmount > 200 && !IsRestricted (WEAPON_DEFUSER)) + if ((g_mapType & MAP_DE) && m_team == CT && Random.Int (1, 100) < 80 && m_moneyAmount > 200 && !IsRestricted (WEAPON_DEFUSER)) { if (isOldGame) engine.IssueBotCommand (GetEntity (), "buyequip;menuselect 6"); @@ -1698,7 +1759,7 @@ void Bot::PurchaseWeapons (void) case BUYSTATE_AMMO: // buy enough primary & secondary ammo (do not check for money here) for (int i = 0; i <= 5; i++) - engine.IssueBotCommand (GetEntity (), "buyammo%d", Random.Long (1, 2)); // simulate human + engine.IssueBotCommand (GetEntity (), "buyammo%d", Random.Int (1, 2)); // simulate human // buy enough secondary ammo if (HasPrimaryWeapon ()) @@ -1819,7 +1880,7 @@ void Bot::SetConditionsOverride (void) PushTask (TASK_MOVETOPOSITION, TASKPRI_HIDE, nearestToEnemyPoint, engine.Time () + Random.Float (5.0f, 10.0f), true); m_isEnemyReachable = false; - m_enemy = NULL; + m_enemy = nullptr; m_enemyIgnoreTimer = engine.Time () + ((length / pev->maxspeed) * 0.5f); } @@ -1842,7 +1903,7 @@ void Bot::SetConditions (void) else { m_states &= ~STATE_SEEING_ENEMY; - m_enemy = NULL; + m_enemy = nullptr; } // did bot just kill an enemy? @@ -1856,10 +1917,10 @@ void Bot::SetConditions (void) if (m_agressionLevel > 1.0f) m_agressionLevel = 1.0f; - if (Random.Long (1, 100) < 10) + if (Random.Int (1, 100) < 10) ChatMessage (CHAT_KILLING); - if (Random.Long (1, 100) < 10) + if (Random.Int (1, 100) < 10) RadioMessage (Radio_EnemyDown); else { @@ -1870,7 +1931,7 @@ void Bot::SetConditions (void) switch (GetNearbyEnemiesNearPosition (pev->origin, 99999.0f)) { case 0: - if (Random.Long (0, 100) < 50) + if (Random.Int (0, 100) < 50) ChatterMessage (Chatter_NoEnemiesLeft); else ChatterMessage (Chatter_EnemyDown); @@ -1909,7 +1970,7 @@ void Bot::SetConditions (void) ChatMessage (CHAT_TEAMKILL, true); ChatterMessage (Chatter_TeamKill); } - m_lastVictim = NULL; + m_lastVictim = nullptr; } // check if our current enemy is still valid @@ -1918,13 +1979,13 @@ void Bot::SetConditions (void) if (!IsAlive (m_lastEnemy) && m_shootAtDeadTime < engine.Time ()) { m_lastEnemyOrigin.Zero (); - m_lastEnemy = NULL; + m_lastEnemy = nullptr; } } else { m_lastEnemyOrigin.Zero (); - m_lastEnemy = NULL; + m_lastEnemy = nullptr; } // don't listen if seeing enemy, just checked for sounds or being blinded (because its inhuman) @@ -2043,7 +2104,7 @@ void Bot::ApplyTaskFilters (void) { float desireLevel = 4096.0f - ((1.0f - tempAgression) * distance); - desireLevel = (100.0f * desireLevel) / 4096.0; + desireLevel = (100.0f * desireLevel) / 4096.0f; desireLevel -= retreatLevel; if (desireLevel > 89.0f) @@ -2143,7 +2204,7 @@ void Bot::PushTask (TaskID id, float desire, int data, float time, bool resume) SelectBestWeapon (); // this is best place to handle some voice commands report team some info - if (Random.Long (0, 100) < 95) + if (Random.Int (0, 100) < 95) { if (taskId == TASK_BLINDED) InstantChatterMessage (Chatter_GotBlinded); @@ -2151,7 +2212,7 @@ void Bot::PushTask (TaskID id, float desire, int data, float time, bool resume) InstantChatterMessage (Chatter_PlantingC4); } - if (Random.Long (0, 100) < 80 && taskId == TASK_CAMP) + if (Random.Int (0, 100) < 80 && taskId == TASK_CAMP) { if ((g_mapType & MAP_DE) && g_bombPlanted) ChatterMessage (Chatter_GuardDroppedC4); @@ -2164,7 +2225,7 @@ void Bot::PushTask (TaskID id, float desire, int data, float time, bool resume) else m_chosenGoalIndex = GetTask ()->data; - if (Random.Long (0, 100) < 80 && GetTaskId () == TASK_CAMP && m_team == TERRORIST && m_inVIPZone) + if (Random.Int (0, 100) < 80 && GetTaskId () == TASK_CAMP && m_team == TERRORIST && m_inVIPZone) ChatterMessage (Chatter_GoingToGuardVIPSafety); } @@ -2305,7 +2366,7 @@ void Bot::CheckRadioCommands (void) // check if line of sight to object is not blocked (i.e. visible) if ((EntityIsVisible (m_radioEntity->v.origin)) || (m_radioOrder == Radio_StickTogether)) { - if (engine.IsNullEntity (m_targetEntity) && engine.IsNullEntity (m_enemy) && Random.Long (0, 100) < (m_personality == PERSONALITY_CAREFUL ? 80 : 20)) + if (engine.IsNullEntity (m_targetEntity) && engine.IsNullEntity (m_enemy) && Random.Int (0, 100) < (m_personality == PERSONALITY_CAREFUL ? 80 : 20)) { int numFollowers = 0; @@ -2314,7 +2375,7 @@ void Bot::CheckRadioCommands (void) { Bot *bot = bots.GetBot (i); - if (bot != NULL) + if (bot != nullptr) { if (bot->m_notKilled) { @@ -2348,23 +2409,23 @@ void Bot::CheckRadioCommands (void) { Bot *bot = bots.GetBot (i); - if (bot != NULL) + if (bot != nullptr) { if (bot->m_notKilled) { if (bot->m_targetEntity == m_radioEntity) { - bot->m_targetEntity = NULL; + bot->m_targetEntity = nullptr; numFollowers--; } } } } } - else if (m_radioOrder != Chatter_GoingToPlantBomb && Random.Long (0, 100) < 50) + else if (m_radioOrder != Chatter_GoingToPlantBomb && Random.Int (0, 100) < 50) RadioMessage (Radio_Negative); } - else if (m_radioOrder != Chatter_GoingToPlantBomb && Random.Long (0, 100) < 50) + else if (m_radioOrder != Chatter_GoingToPlantBomb && Random.Int (0, 100) < 50) RadioMessage (Radio_Negative); } break; @@ -2374,7 +2435,7 @@ void Bot::CheckRadioCommands (void) { if (m_targetEntity == m_radioEntity) { - m_targetEntity = NULL; + m_targetEntity = nullptr; RadioMessage (Radio_Affirmative); m_campButtons = 0; @@ -2399,14 +2460,14 @@ void Bot::CheckRadioCommands (void) if (m_fearLevel < 0.0f) m_fearLevel = 0.0f; - if (Random.Long (0, 100) < 45 && yb_communication_type.GetInt () == 2) + if (Random.Int (0, 100) < 45 && yb_communication_type.GetInt () == 2) ChatterMessage (Chatter_OnMyWay); else if (m_radioOrder == Radio_NeedBackup && yb_communication_type.GetInt () != 2) RadioMessage (Radio_Affirmative); TryHeadTowardRadioEntity (); } - else if (Random.Long (0, 100) < 70) + else if (Random.Int (0, 100) < 70) RadioMessage (Radio_Negative); } break; @@ -2420,33 +2481,33 @@ void Bot::CheckRadioCommands (void) case Radio_NeedBackup: case Chatter_ScaredEmotion: case Chatter_Pinned_Down: - if (((engine.IsNullEntity (m_enemy) && EntityIsVisible (m_radioEntity->v.origin)) || distance < 2048.0f || !m_moveToC4) && Random.Long (0, 100) > 50 && m_seeEnemyTime + 4.0f < engine.Time ()) + if (((engine.IsNullEntity (m_enemy) && EntityIsVisible (m_radioEntity->v.origin)) || distance < 2048.0f || !m_moveToC4) && Random.Int (0, 100) > 50 && m_seeEnemyTime + 4.0f < engine.Time ()) { m_fearLevel -= 0.1f; if (m_fearLevel < 0.0f) m_fearLevel = 0.0f; - if (Random.Long (0, 100) < 45 && yb_communication_type.GetInt () == 2) + if (Random.Int (0, 100) < 45 && yb_communication_type.GetInt () == 2) ChatterMessage (Chatter_OnMyWay); else if (m_radioOrder == Radio_NeedBackup && yb_communication_type.GetInt () != 2) RadioMessage (Radio_Affirmative); TryHeadTowardRadioEntity (); } - else if (Random.Long (0, 100) < 60 && m_radioOrder == Radio_NeedBackup) + else if (Random.Int (0, 100) < 60 && m_radioOrder == Radio_NeedBackup) RadioMessage (Radio_Negative); break; case Radio_GoGoGo: if (m_radioEntity == m_targetEntity) { - if (Random.Long (0, 100) < 45 && yb_communication_type.GetInt () == 2) + if (Random.Int (0, 100) < 45 && yb_communication_type.GetInt () == 2) RadioMessage (Radio_Affirmative); else if (m_radioOrder == Radio_NeedBackup && yb_communication_type.GetInt () != 2) RadioMessage (Radio_Affirmative); - m_targetEntity = NULL; + m_targetEntity = nullptr; m_fearLevel -= 0.2f; if (m_fearLevel < 0.0f) @@ -2467,7 +2528,7 @@ void Bot::CheckRadioCommands (void) // don't pause/camp anymore GetTask ()->time = engine.Time (); - m_targetEntity = NULL; + m_targetEntity = nullptr; MakeVectors (m_radioEntity->v.v_angle); m_position = m_radioEntity->v.origin + g_pGlobals->v_forward * Random.Float (1024.0f, 2048.0f); @@ -2494,7 +2555,7 @@ void Bot::CheckRadioCommands (void) if (GetTaskId () == TASK_CAMP) RemoveCertainTask (TASK_CAMP); - m_targetEntity = NULL; + m_targetEntity = nullptr; PushTask (TASK_ESCAPEFROMBOMB, TASKPRI_ESCAPEFROMBOMB, -1, 0.0f, true); } else @@ -2518,7 +2579,7 @@ void Bot::CheckRadioCommands (void) break; case Radio_StormTheFront: - if (((engine.IsNullEntity (m_enemy) && EntityIsVisible (m_radioEntity->v.origin)) || distance < 1024.0f) && Random.Long (0, 100) > 50) + if (((engine.IsNullEntity (m_enemy) && EntityIsVisible (m_radioEntity->v.origin)) || distance < 1024.0f) && Random.Int (0, 100) > 50) { RadioMessage (Radio_Affirmative); @@ -2528,7 +2589,7 @@ void Bot::CheckRadioCommands (void) if (taskID == TASK_PAUSE || taskID == TASK_CAMP) GetTask ()->time = engine.Time (); - m_targetEntity = NULL; + m_targetEntity = nullptr; MakeVectors (m_radioEntity->v.v_angle); m_position = m_radioEntity->v.origin + g_pGlobals->v_forward * Random.Float (1024.0f, 2048.0f); @@ -2571,7 +2632,7 @@ void Bot::CheckRadioCommands (void) if (taskID == TASK_PAUSE) GetTask ()->time = engine.Time (); - m_targetEntity = NULL; + m_targetEntity = nullptr; m_seeEnemyTime = engine.Time (); // if bot has no enemy @@ -2605,7 +2666,7 @@ void Bot::CheckRadioCommands (void) break; case Radio_ReportTeam: - if (Random.Long (0, 100) < 30) + if (Random.Int (0, 100) < 30) RadioMessage ((GetNearbyEnemiesNearPosition (pev->origin, 400.0f) == 0 && yb_communication_type.GetInt () != 2) ? Radio_SectorClear : Radio_ReportingIn); break; @@ -2667,7 +2728,7 @@ void Bot::CheckRadioCommands (void) if (taskID == TASK_PAUSE) GetTask ()->time = engine.Time (); - m_targetEntity = NULL; + m_targetEntity = nullptr; m_seeEnemyTime = engine.Time (); // if bot has no enemy @@ -2721,7 +2782,7 @@ void Bot::TryHeadTowardRadioEntity (void) if (taskID == TASK_MOVETOPOSITION || m_headedTime + 15.0f < engine.Time () || !IsAlive (m_radioEntity) || m_hasC4) return; - if ((IsValidBot (m_radioEntity) && Random.Long (0, 100) < 25 && m_personality == PERSONALITY_NORMAL) || !(m_radioEntity->v.flags & FL_FAKECLIENT)) + if ((IsValidBot (m_radioEntity) && Random.Int (0, 100) < 25 && m_personality == PERSONALITY_NORMAL) || !(m_radioEntity->v.flags & FL_FAKECLIENT)) { if (taskID == TASK_PAUSE || taskID == TASK_CAMP) GetTask ()->time = engine.Time (); @@ -2911,10 +2972,10 @@ void Bot::PeriodicThink (void) extern ConVar yb_chat; - if (m_notKilled && yb_chat.GetBool () && m_lastChatTime + 10.0 < engine.Time () && g_lastChatTime + 5.0f < engine.Time () && !RepliesToPlayer ()) // bot chatting turned on? + if (!m_notKilled && yb_chat.GetBool () && m_lastChatTime + 10.0 < engine.Time () && g_lastChatTime + 5.0f < engine.Time () && !RepliesToPlayer ()) // bot chatting turned on? { // say a text every now and then - if (Random.Long (1, 1500) < 2) + if (Random.Int (1, 1500) < 2) { m_lastChatTime = engine.Time (); g_lastChatTime = engine.Time (); @@ -2939,7 +3000,7 @@ void Bot::PeriodicThink (void) } // clear the used line buffer every now and then - if (m_sayTextBuffer.lastUsedSentences.GetElementNumber () > Random.Long (4, 6)) + if (m_sayTextBuffer.lastUsedSentences.GetElementNumber () > Random.Int (4, 6)) m_sayTextBuffer.lastUsedSentences.RemoveAll (); } } @@ -2947,7 +3008,7 @@ void Bot::PeriodicThink (void) // clear enemy far away if (!m_lastEnemyOrigin.IsZero () && !engine.IsNullEntity (m_lastEnemy) && (pev->origin - m_lastEnemyOrigin).GetLength () >= 1600.0f) { - m_lastEnemy = NULL; + m_lastEnemy = nullptr; m_lastEnemyOrigin.Zero (); } m_timePeriodicUpdate = engine.Time () + 0.5f; @@ -2967,7 +3028,7 @@ void Bot::RunTask_Normal (void) // bots rushing with knife, when have no enemy (thanks for idea to nicebot project) if (m_currentWeapon == WEAPON_KNIFE && (engine.IsNullEntity (m_lastEnemy) || !IsAlive (m_lastEnemy)) && engine.IsNullEntity (m_enemy) && m_knifeAttackTime < engine.Time () && !HasShield () && GetNearbyFriendsNearPosition (pev->origin, 96) == 0) { - if (Random.Long (0, 100) < 40) + if (Random.Int (0, 100) < 40) pev->button |= IN_ATTACK; else pev->button |= IN_ATTACK2; @@ -2985,7 +3046,7 @@ void Bot::RunTask_Normal (void) GetTask ()->data = -1; } - if (!g_bombPlanted && m_currentWaypointIndex != -1 && (m_currentPath->flags & FLAG_GOAL) && Random.Long (0, 100) < 80 && GetNearbyEnemiesNearPosition (pev->origin, 650.0f) == 0) + if (!g_bombPlanted && m_currentWaypointIndex != -1 && (m_currentPath->flags & FLAG_GOAL) && Random.Int (0, 100) < 80 && GetNearbyEnemiesNearPosition (pev->origin, 650.0f) == 0) RadioMessage (Radio_SectorClear); // reached the destination (goal) waypoint? @@ -2995,7 +3056,7 @@ void Bot::RunTask_Normal (void) m_prevGoalIndex = -1; // spray logo sometimes if allowed to do so - if (m_timeLogoSpray < engine.Time () && yb_spraypaints.GetBool () && Random.Long (1, 100) < 60 && m_moveSpeed > GetWalkSpeed () && engine.IsNullEntity (m_pickupItem)) + if (m_timeLogoSpray < engine.Time () && yb_spraypaints.GetBool () && Random.Int (1, 100) < 60 && m_moveSpeed > GetWalkSpeed () && engine.IsNullEntity (m_pickupItem)) { if (!((g_mapType & MAP_DE) && g_bombPlanted && m_team == CT)) PushTask (TASK_SPRAY, TASKPRI_SPRAYLOGO, -1, engine.Time () + 1.0f, false); @@ -3051,7 +3112,7 @@ void Bot::RunTask_Normal (void) m_campDirection = 0; // tell the world we're camping - if (Random.Long (0, 100) < 60) + if (Random.Int (0, 100) < 60) RadioMessage (Radio_InPosition); m_moveToGoal = false; @@ -3074,10 +3135,10 @@ void Bot::RunTask_Normal (void) if (m_currentPath->flags & FLAG_RESCUE) { for (int i = 0; i < MAX_HOSTAGES; i++) - m_hostages[i] = NULL; // clear array of hostage pointers + m_hostages[i] = nullptr; // clear array of hostage pointers } } - else if (m_team == TERRORIST && Random.Long (0, 100) < 80) + else if (m_team == TERRORIST && Random.Int (0, 100) < 80) { int index = FindDefendWaypoint (m_currentPath->origin); @@ -3163,7 +3224,7 @@ void Bot::RunTask_Normal (void) m_moveSpeed = GetWalkSpeed (); // bot hasn't seen anything in a long time and is asking his teammates to report in - if (m_seeEnemyTime + Random.Float (45.0f, 80.0f) < engine.Time () && Random.Long (0, 100) < 30 && g_timeRoundStart + 20.0f < engine.Time () && m_askCheckTime < engine.Time ()) + if (m_seeEnemyTime + Random.Float (45.0f, 80.0f) < engine.Time () && Random.Int (0, 100) < 30 && g_timeRoundStart + 20.0f < engine.Time () && m_askCheckTime < engine.Time ()) { m_askCheckTime = engine.Time () + Random.Float (45.0f, 80.0f); RadioMessage (Radio_ReportTeam); @@ -3192,7 +3253,7 @@ void Bot::RunTask_Spray (void) if (GetTask ()->time - 0.5f < engine.Time ()) { // emit spraycan sound - EMIT_SOUND_DYN2 (GetEntity (), CHAN_VOICE, "player/sprayer.wav", 1.0, ATTN_NORM, 0, 100.0f); + EMIT_SOUND_DYN2 (GetEntity (), CHAN_VOICE, "player/sprayer.wav", 1.0f, ATTN_NORM, 0, 100); engine.TestLine (EyePosition (), EyePosition () + g_pGlobals->v_forward * 128.0f, TRACE_IGNORE_MONSTERS, GetEntity (), &tr); // paint the actual logo decal @@ -3225,7 +3286,7 @@ void Bot::RunTask_HuntEnemy (void) TaskComplete (); m_prevGoalIndex = -1; - m_lastEnemy = NULL; + m_lastEnemy = nullptr; m_lastEnemyOrigin.Zero (); } else if (engine.GetTeam (m_lastEnemy) == m_team) @@ -3240,7 +3301,7 @@ void Bot::RunTask_HuntEnemy (void) TaskComplete (); m_prevGoalIndex = -1; - m_lastEnemy = NULL; + m_lastEnemy = nullptr; m_lastEnemyOrigin.Zero (); } else if (!GoalIsValid ()) // do we need to calculate a new path? @@ -3548,7 +3609,7 @@ void Bot::RunTask_Camp (void) } if (--numFoundPoints >= 0) - m_camp = waypoints.GetPath (foundPoints[Random.Long (0, numFoundPoints)])->origin; + m_camp = waypoints.GetPath (foundPoints[Random.Int (0, numFoundPoints)])->origin; else m_camp = waypoints.GetPath (GetAimingWaypoint ())->origin; } @@ -3728,7 +3789,7 @@ void Bot::RunTask_DefuseBomb (void) defuseError = true; g_bombPlanted = false; - if (Random.Long (0, 100) < 50 && m_numFriendsLeft != 0) + if (Random.Int (0, 100) < 50 && m_numFriendsLeft != 0) { if (timeToBlowUp <= 3.0) { @@ -3768,7 +3829,7 @@ void Bot::RunTask_DefuseBomb (void) m_destOrigin.Zero (); m_entity.Zero (); - m_pickupItem = NULL; + m_pickupItem = nullptr; m_pickupType = PICKUP_NONE; TaskComplete (); @@ -3883,7 +3944,7 @@ void Bot::RunTask_FollowUser (void) { if (engine.IsNullEntity (m_targetEntity) || !IsAlive (m_targetEntity)) { - m_targetEntity = NULL; + m_targetEntity = nullptr; TaskComplete (); return; @@ -3898,7 +3959,7 @@ void Bot::RunTask_FollowUser (void) if (!engine.IsNullEntity (tr.pHit) && IsValidPlayer (tr.pHit) && engine.GetTeam (tr.pHit) != m_team) { - m_targetEntity = NULL; + m_targetEntity = nullptr; m_lastEnemy = tr.pHit; m_lastEnemyOrigin = tr.pHit->v.origin; @@ -3926,7 +3987,7 @@ void Bot::RunTask_FollowUser (void) if (m_followWaitTime + 3.0f < engine.Time ()) { // stop following if we have been waiting too long - m_targetEntity = NULL; + m_targetEntity = nullptr; RadioMessage (Radio_YouTakePoint); TaskComplete (); @@ -3974,7 +4035,7 @@ void Bot::RunTask_FollowUser (void) } else { - m_targetEntity = NULL; + m_targetEntity = nullptr; TaskComplete (); } } @@ -4024,7 +4085,7 @@ void Bot::RunTask_Throw_HE (void) } else { - edict_t *ent = NULL; + edict_t *ent = nullptr; while (!engine.IsNullEntity (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) { @@ -4090,7 +4151,7 @@ void Bot::RunTask_Throw_FL (void) } else { - edict_t *ent = NULL; + edict_t *ent = nullptr; while (!engine.IsNullEntity (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) { if (ent->v.owner == GetEntity () && strcmp (STRING (ent->v.model) + 9, "flashbang.mdl") == 0) @@ -4344,7 +4405,7 @@ void Bot::RunTask_PickupItem () { if (engine.IsNullEntity (m_pickupItem)) { - m_pickupItem = NULL; + m_pickupItem = nullptr; TaskComplete (); return; @@ -4419,7 +4480,7 @@ void Bot::RunTask_PickupItem () if (HasShield ()) { - m_pickupItem = NULL; + m_pickupItem = nullptr; break; } else if (itemDistance < 50.0f) // near to shield? @@ -4462,7 +4523,7 @@ void Bot::RunTask_PickupItem () if (!IsAlive (m_pickupItem)) { // don't pickup dead hostages - m_pickupItem = NULL; + m_pickupItem = nullptr; TaskComplete (); break; @@ -4470,14 +4531,14 @@ void Bot::RunTask_PickupItem () if (itemDistance < 50.0f) { - float angleToEntity = InFieldOfView (dest - EyePosition ()); + int angleToEntity = InFieldOfView (dest - EyePosition ()); - if (angleToEntity <= 10.0f) // bot faces hostage? + if (angleToEntity <= 10) // bot faces hostage? { // use game dll function to make sure the hostage is correctly 'used' MDLL_Use (m_pickupItem, GetEntity ()); - if (Random.Long (0, 100) < 80) + if (Random.Int (0, 100) < 80) ChatterMessage (Chatter_UseHostage); for (int i = 0; i < MAX_HOSTAGES; i++) @@ -4485,7 +4546,7 @@ void Bot::RunTask_PickupItem () if (engine.IsNullEntity (m_hostages[i])) // store pointer to hostage so other bots don't steal from this one or bot tries to reuse it { m_hostages[i] = m_pickupItem; - m_pickupItem = NULL; + m_pickupItem = nullptr; break; } @@ -4500,7 +4561,7 @@ void Bot::RunTask_PickupItem () if (m_hasDefuser) { - m_pickupItem = NULL; + m_pickupItem = nullptr; m_pickupType = PICKUP_NONE; } break; @@ -4517,7 +4578,7 @@ void Bot::RunTask_PickupItem () } // find angles from bot origin to entity... - float angleToEntity = InFieldOfView (dest - EyePosition ()); + int angleToEntity = InFieldOfView (dest - EyePosition ()); if (itemDistance < 90.0f) // near to the button? { @@ -4526,11 +4587,11 @@ void Bot::RunTask_PickupItem () m_moveToGoal = false; m_checkTerrain = false; - if (angleToEntity <= 10.0f) // facing it directly? + if (angleToEntity <= 10) // facing it directly? { MDLL_Use (m_pickupItem, GetEntity ()); - m_pickupItem = NULL; + m_pickupItem = nullptr; m_pickupType = PICKUP_NONE; m_buttonPushTime = engine.Time () + 3.0f; @@ -4658,10 +4719,10 @@ void Bot::CheckSpawnTimeConditions (void) // switch to knife if time to do this if (m_checkKnifeSwitch && !m_checkWeaponSwitch && m_buyingFinished && m_spawnTime + Random.Float (4.0f, 6.5f) < engine.Time ()) { - if (Random.Long (1, 100) < 2 && yb_spraypaints.GetBool ()) + if (Random.Int (1, 100) < 2 && yb_spraypaints.GetBool ()) PushTask (TASK_SPRAY, TASKPRI_SPRAYLOGO, -1, engine.Time () + 1.0f, false); - if (m_difficulty >= 2 && Random.Long (0, 100) < (m_personality == PERSONALITY_RUSHER ? 99 : 50) && !m_isReloading && (g_mapType & (MAP_CS | MAP_DE | MAP_ES | MAP_AS))) + if (m_difficulty >= 2 && Random.Int (0, 100) < (m_personality == PERSONALITY_RUSHER ? 99 : 50) && !m_isReloading && (g_mapType & (MAP_CS | MAP_DE | MAP_ES | MAP_AS))) { if (yb_jasonmode.GetBool ()) { @@ -4673,7 +4734,7 @@ void Bot::CheckSpawnTimeConditions (void) } m_checkKnifeSwitch = false; - if (Random.Long (0, 100) < yb_user_follow_percent.GetInt () && engine.IsNullEntity (m_targetEntity) && !m_isLeader && !m_hasC4) + if (Random.Int (0, 100) < yb_user_follow_percent.GetInt () && engine.IsNullEntity (m_targetEntity) && !m_isLeader && !m_hasC4) AttachToUser (); } @@ -4693,7 +4754,7 @@ void Bot::CheckSpawnTimeConditions (void) case WEAPON_FAMAS: case WEAPON_GLOCK: - if (Random.Long (0, 100) < 50) + if (Random.Int (0, 100) < 50) pev->button |= IN_ATTACK2; break; } @@ -4749,16 +4810,16 @@ void Bot::BotAI (void) { int hasFriendNearby = GetNearbyFriendsNearPosition (pev->origin, 512.0f); - if (!hasFriendNearby && Random.Long (0, 100) < 45 && (m_enemy->v.weapons & (1 << WEAPON_C4))) + if (!hasFriendNearby && Random.Int (0, 100) < 45 && (m_enemy->v.weapons & (1 << WEAPON_C4))) ChatterMessage (Chatter_SpotTheBomber); - else if (!hasFriendNearby && Random.Long (0, 100) < 45 && m_team == TERRORIST && IsPlayerVIP (m_enemy)) + else if (!hasFriendNearby && Random.Int (0, 100) < 45 && m_team == TERRORIST && IsPlayerVIP (m_enemy)) ChatterMessage (Chatter_VIPSpotted); - else if (!hasFriendNearby && Random.Long (0, 100) < 50 && engine.GetTeam (m_enemy) != m_team && IsGroupOfEnemies (m_enemy->v.origin, 2, 384.0f)) + else if (!hasFriendNearby && Random.Int (0, 100) < 50 && engine.GetTeam (m_enemy) != m_team && IsGroupOfEnemies (m_enemy->v.origin, 2, 384)) ChatterMessage (Chatter_ScaredEmotion); - else if (!hasFriendNearby && Random.Long (0, 100) < 40 && ((m_enemy->v.weapons & (1 << WEAPON_AWP)) || (m_enemy->v.weapons & (1 << WEAPON_SCOUT)) || (m_enemy->v.weapons & (1 << WEAPON_G3SG1)) || (m_enemy->v.weapons & (1 << WEAPON_SG550)))) + else if (!hasFriendNearby && Random.Int (0, 100) < 40 && ((m_enemy->v.weapons & (1 << WEAPON_AWP)) || (m_enemy->v.weapons & (1 << WEAPON_SCOUT)) || (m_enemy->v.weapons & (1 << WEAPON_G3SG1)) || (m_enemy->v.weapons & (1 << WEAPON_SG550)))) ChatterMessage (Chatter_SniperWarning); // if bot is trapped under shield yell for help ! @@ -4856,8 +4917,8 @@ void Bot::BotAI (void) if (!engine.IsNullEntity (m_pickupItem) && !m_hasProgressBar) m_itemIgnore = m_pickupItem; - m_pickupItem = NULL; - m_breakableEntity = NULL; + m_pickupItem = nullptr; + m_breakableEntity = nullptr; m_itemCheckTime = engine.Time () + 5.0f; m_pickupType = PICKUP_NONE; } @@ -4908,7 +4969,7 @@ void Bot::DisplayDebugOverlay (void) if (!displayDebugOverlay && yb_debug.GetInt () >= 2) { - Bot *nearest = NULL; + Bot *nearest = nullptr; if (FindNearestPlayer (reinterpret_cast (&nearest), g_hostEntity, 128.0f, true, true, true, true) && nearest == this) displayDebugOverlay = true; @@ -5096,7 +5157,7 @@ void Bot::DisplayDebugOverlay (void) sprintf (outputBuffer, "\n\n\n\n%s (H:%.1f/A:%.1f)- Task: %d=%s Desire:%.02f\nItem: %s Clip: %d Ammo: %d%s Money: %d AimFlags: %s\nSP=%.02f SSP=%.02f I=%d PG=%d G=%d T: %.02f MT: %d\nEnemy=%s Pickup=%s Type=%s\n", STRING (pev->netname), pev->health, pev->armorvalue, taskID, taskName, GetTask ()->desire, &weaponName[7], GetAmmoInClip (), GetAmmo (), m_isReloading ? " (R)" : "", m_moneyAmount, aimFlags, m_moveSpeed, m_strafeSpeed, index, m_prevGoalIndex, goal, m_navTimeset - engine.Time (), pev->movetype, enemyName, pickupName, botType); - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, NULL, g_hostEntity); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, nullptr, g_hostEntity); WRITE_BYTE (TE_TEXTMESSAGE); WRITE_BYTE (1); WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); @@ -5116,7 +5177,7 @@ void Bot::DisplayDebugOverlay (void) WRITE_STRING (const_cast (&outputBuffer[0])); MESSAGE_END (); - timeDebugUpdate = engine.Time () + 1.0; + timeDebugUpdate = engine.Time () + 1.0f; } // green = destination origin @@ -5134,12 +5195,12 @@ void Bot::DisplayDebugOverlay (void) // now draw line from source to destination PathNode *node = &m_navNode[0]; - while (node != NULL) + while (node != nullptr) { const Vector &srcPath = waypoints.GetPath (node->index)->origin; node = node->next; - if (node != NULL) + if (node != nullptr) { const Vector &dstPath = waypoints.GetPath (node->index)->origin; engine.DrawLine (g_hostEntity, srcPath, dstPath, 15, 0, 255, 100, 55, 200, 5, 1, DRAW_ARROW); @@ -5158,7 +5219,7 @@ bool Bot::HasHostage (void) // don't care about dead hostages if (m_hostages[i]->v.health <= 0.0f || (pev->origin - m_hostages[i]->v.origin).GetLength () > 600.0f) { - m_hostages[i] = NULL; + m_hostages[i] = nullptr; continue; } return true; @@ -5251,7 +5312,7 @@ void Bot::TakeBlinded (int r, int g, int b, int alpha) if (r != 255 || g != 255 || b != 255 || alpha <= 170) return; - m_enemy = NULL; + m_enemy = nullptr; m_maxViewDistance = Random.Float (10.0f, 20.0f); m_blindTime = engine.Time () + static_cast (alpha - 200) / 16.0f; @@ -5270,7 +5331,7 @@ void Bot::TakeBlinded (int r, int g, int b, int alpha) float walkSpeed = GetWalkSpeed (); - if (Random.Long (0, 100) > 50) + if (Random.Int (0, 100) > 50) m_blindSidemoveSpeed = walkSpeed; else m_blindSidemoveSpeed = -walkSpeed; @@ -5309,7 +5370,7 @@ void Bot::CollectGoalExperience (int damage, int team) else if (value > MAX_GOAL_VALUE) value = MAX_GOAL_VALUE; - (g_experienceData + (m_chosenGoalIndex * g_numWaypoints) + m_prevGoalIndex)->team0Value = static_cast (value); + (g_experienceData + (m_chosenGoalIndex * g_numWaypoints) + m_prevGoalIndex)->team0Value = static_cast (value); } else { @@ -5322,7 +5383,7 @@ void Bot::CollectGoalExperience (int damage, int team) else if (value > MAX_GOAL_VALUE) value = MAX_GOAL_VALUE; - (g_experienceData + (m_chosenGoalIndex * g_numWaypoints) + m_prevGoalIndex)->team1Value = static_cast (value); + (g_experienceData + (m_chosenGoalIndex * g_numWaypoints) + m_prevGoalIndex)->team1Value = static_cast (value); } } } @@ -5343,7 +5404,7 @@ void Bot::CollectExperienceData (edict_t *attacker, int damage) // if these are bots also remember damage to rank destination of the bot m_goalValue -= static_cast (damage); - if (bots.GetBot (attacker) != NULL) + if (bots.GetBot (attacker) != nullptr) bots.GetBot (attacker)->m_goalValue += static_cast (damage); if (damage < 20) @@ -5380,7 +5441,7 @@ void Bot::CollectExperienceData (edict_t *attacker, int damage) if (value > g_highestDamageT) g_highestDamageT = value; - (g_experienceData + (victimIndex * g_numWaypoints) + attackerIndex)->team0Damage = static_cast (value); + (g_experienceData + (victimIndex * g_numWaypoints) + attackerIndex)->team0Damage = static_cast (value); } else { @@ -5393,7 +5454,7 @@ void Bot::CollectExperienceData (edict_t *attacker, int damage) if (value > g_highestDamageCT) g_highestDamageCT = value; - (g_experienceData + (victimIndex * g_numWaypoints) + attackerIndex)->team1Damage = static_cast (value); + (g_experienceData + (victimIndex * g_numWaypoints) + attackerIndex)->team1Damage = static_cast (value); } } @@ -5464,7 +5525,7 @@ void Bot::DiscardWeaponForUser (edict_t *user, bool discardC4) engine.IssueBotCommand (GetEntity (), "drop"); } - m_pickupItem = NULL; + m_pickupItem = nullptr; m_pickupType = PICKUP_NONE; m_itemCheckTime = engine.Time () + 5.0f; @@ -5483,7 +5544,7 @@ void Bot::ResetDoubleJumpState (void) { TaskComplete (); - m_doubleJumpEntity = NULL; + m_doubleJumpEntity = nullptr; m_duckForJump = 0.0f; m_doubleJumpOrigin.Zero (); m_travelStartIndex = -1; @@ -5650,11 +5711,11 @@ Vector Bot::CheckBombAudible (void) return Vector::GetZero (); } -byte Bot::ThrottledMsec (void) +uint8 Bot::ThrottledMsec (void) { // estimate msec to use for this command based on time passed from the previous command - return static_cast ((engine.Time () - m_lastCommandTime) * 1000.0f); + return static_cast ((engine.Time () - m_lastCommandTime) * 1000.0f); } void Bot::RunPlayerMovement (void) @@ -5675,10 +5736,10 @@ void Bot::RunPlayerMovement (void) m_frameInterval = engine.Time () - m_lastCommandTime; - byte msecVal = ThrottledMsec (); + uint8 msecVal = ThrottledMsec (); m_lastCommandTime = engine.Time (); - (*g_engfuncs.pfnRunPlayerMove) (pev->pContainingEntity, m_moveAngles, m_moveSpeed, m_strafeSpeed, 0.0f, pev->button, pev->impulse, msecVal); + g_engfuncs.pfnRunPlayerMove (pev->pContainingEntity, m_moveAngles, m_moveSpeed, m_strafeSpeed, 0.0f, static_cast (pev->button), static_cast (pev->impulse), msecVal); } void Bot::CheckBurstMode (float distance) @@ -5708,7 +5769,7 @@ void Bot::CheckSilencer (void) int random = (m_personality == PERSONALITY_RUSHER ? 35 : 65); // aggressive bots don't like the silencer - if (Random.Long (1, 100) <= (m_currentWeapon == WEAPON_USP ? random / 3 : random)) + if (Random.Int (1, 100) <= (m_currentWeapon == WEAPON_USP ? random / 3 : random)) { if (pev->weaponanim > 6) // is the silencer not attached... pev->button |= IN_ATTACK2; // attach the silencer @@ -5791,10 +5852,10 @@ bool Bot::OutOfBombTimer (void) // check if our teammates has defusal kit for (int i = 0; i < engine.MaxClients (); i++) { - Bot *bot = NULL; // temporaly pointer to bot + Bot *bot = nullptr; // temporaly pointer to bot // search players with defuse kit - if ((bot = bots.GetBot (i)) != NULL && bot->m_team == CT && bot->m_hasDefuser && (bombOrigin - bot->pev->origin).GetLength () < 500.0f) + if ((bot = bots.GetBot (i)) != nullptr && bot->m_team == CT && bot->m_hasDefuser && (bombOrigin - bot->pev->origin).GetLength () < 500.0f) { hasTeammatesWithDefuserKit = true; break; @@ -5823,7 +5884,7 @@ void Bot::ReactOnSound (void) if (pev->flags & FL_DUCKING) pasOrg = pasOrg + (VEC_HULL_MIN - VEC_DUCK_HULL_MIN); - byte *pas = ENGINE_SET_PAS (reinterpret_cast (&pasOrg)); + uint8 *pas = ENGINE_SET_PAS (reinterpret_cast (&pasOrg)); float minDistance = 99999.0f; @@ -5849,7 +5910,7 @@ void Bot::ReactOnSound (void) minDistance = distance; } } - edict_t *player = NULL; + edict_t *player = nullptr; if (hearEnemyIndex >= 0 && g_clients[hearEnemyIndex].team != m_team && yb_csdm_mode.GetInt () != 2) player = g_clients[hearEnemyIndex].ent; @@ -5864,11 +5925,11 @@ void Bot::ReactOnSound (void) m_heardSoundTime = engine.Time (); m_states |= STATE_HEARING_ENEMY; - if ((Random.Long (0, 100) < 15) && engine.IsNullEntity (m_enemy) && engine.IsNullEntity (m_lastEnemy) && m_seeEnemyTime + 7.0f < engine.Time ()) + if ((Random.Int (0, 100) < 15) && engine.IsNullEntity (m_enemy) && engine.IsNullEntity (m_lastEnemy) && m_seeEnemyTime + 7.0f < engine.Time ()) ChatterMessage (Chatter_HeardEnemy); // didn't bot already have an enemy ? take this one... - if (m_lastEnemyOrigin.IsZero () || m_lastEnemy == NULL) + if (m_lastEnemyOrigin.IsZero () || m_lastEnemy == nullptr) { m_lastEnemy = player; m_lastEnemyOrigin = player->v.origin; @@ -5942,7 +6003,7 @@ void Bot::EquipInBuyzone (int buyState) bool checkBuyTime = false; - if (mp_buytime.m_eptr != NULL) + if (mp_buytime.m_eptr != nullptr) checkBuyTime = (g_timeRoundStart + Random.Float (10.0f, 20.0f) + mp_buytime.GetFloat () < engine.Time ()); // if bot is in buy zone, try to buy ammo for this weapon... @@ -5972,7 +6033,7 @@ bool Bot::IsBombDefusing (const Vector &bombOrigin) { Bot *bot = bots.GetBot (i); - if (bot == NULL || bot == this) + if (bot == nullptr || bot == this) continue; // skip invalid bots if (m_team != bot->m_team || bot->GetTaskId () == TASK_ESCAPEFROMBOMB) @@ -6000,7 +6061,7 @@ bool Bot::IsBombDefusing (const Vector &bombOrigin) float Bot::GetWalkSpeed (void) { - if ((GetTaskId () == TASK_SEEKCOVER) || (pev->flags & FL_DUCKING) || (pev->button & IN_DUCK) || (pev->oldbuttons & IN_DUCK) || (m_currentTravelFlags & PATHFLAG_JUMP) || (m_currentPath != NULL && m_currentPath->flags & FLAG_LADDER) || IsOnLadder () || IsInWater ()) + if ((GetTaskId () == TASK_SEEKCOVER) || (pev->flags & FL_DUCKING) || (pev->button & IN_DUCK) || (pev->oldbuttons & IN_DUCK) || (m_currentTravelFlags & PATHFLAG_JUMP) || (m_currentPath != nullptr && m_currentPath->flags & FLAG_LADDER) || IsOnLadder () || IsInWater ()) return pev->maxspeed; return static_cast ((static_cast (pev->maxspeed) * 0.5f) + (static_cast (pev->maxspeed) / 50.0f)) - 18.0f; diff --git a/source/chatlib.cpp b/source/chatlib.cpp index 0774221..f7adc2f 100644 --- a/source/chatlib.cpp +++ b/source/chatlib.cpp @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include @@ -92,17 +92,17 @@ char *HumanizeName (char *name) strncpy (outputName, name, SIZEOF_CHAR (outputName)); // copy name to new buffer // drop tag marks, 80 percent of time - if (Random.Long (1, 100) < 80) + if (Random.Int (1, 100) < 80) StripTags (outputName); else String::TrimExternalBuffer (outputName); // sometimes switch name to lower characters // note: since we're using russian names written in english, we reduce this shit to 6 percent - if (Random.Long (1, 100) <= 6) + if (Random.Int (1, 100) <= 6) { for (int i = 0; i < static_cast (strlen (outputName)); i++) - outputName[i] = tolower (outputName[i]); // to lower case + outputName[i] = static_cast (tolower (static_cast (outputName[i]))); // to lower case } return &outputName[0]; // return terminated string } @@ -116,18 +116,18 @@ void HumanizeChat (char *buffer) // sometimes switch text to lowercase // note: since we're using russian chat written in english, we reduce this shit to 4 percent - if (Random.Long (1, 100) <= 4) + if (Random.Int (1, 100) <= 4) { for (i = 0; i < length; i++) - buffer[i] = tolower (buffer[i]); // switch to lowercase + buffer[i] = static_cast (tolower (static_cast (buffer[i])));; // switch to lowercase } if (length > 15) { // "length / 2" percent of time drop a character - if (Random.Long (1, 100) < (length / 2)) + if (Random.Int (1, 100) < (length / 2)) { - int pos = Random.Long ((length / 8), length - (length / 8)); // chose random position in string + int pos = Random.Int ((length / 8), length - (length / 8)); // chose random position in string for (i = pos; i < length - 1; i++) buffer[i] = buffer[i + 1]; // overwrite the buffer with stripped string @@ -137,9 +137,9 @@ void HumanizeChat (char *buffer) } // "length" / 4 precent of time swap character - if (Random.Long (1, 100) < (length / 4)) + if (Random.Int (1, 100) < (length / 4)) { - int pos = Random.Long ((length / 8), ((3 * length) / 8)); // choose random position in string + int pos = Random.Int ((length / 8), ((3 * length) / 8)); // choose random position in string char ch = buffer[pos]; // swap characters buffer[pos] = buffer[pos + 1]; @@ -163,14 +163,14 @@ void Bot::PrepareChatMessage (char *text) char *textStart = text; char *pattern = text; - edict_t *talkEntity = NULL; + edict_t *talkEntity = nullptr; - while (pattern != NULL) + while (pattern != nullptr) { // all replacement placeholders start with a % pattern = strstr (textStart, "%"); - if (pattern != NULL) + if (pattern != nullptr) { int length = pattern - textStart; @@ -304,14 +304,14 @@ void Bot::PrepareChatMessage (char *text) { if (g_gameFlags & GAME_CZERO) { - if (Random.Long (1, 100) < 30) + if (Random.Int (1, 100) < 30) strcat (m_tempStrings, "CZ"); else strcat (m_tempStrings, "Condition Zero"); } else if ((g_gameFlags & GAME_CSTRIKE16) || (g_gameFlags & GAME_LEGACY)) { - if (Random.Long (1, 100) < 30) + if (Random.Int (1, 100) < 30) strcat (m_tempStrings, "CS"); else strcat (m_tempStrings, "Counter-Strike"); @@ -327,7 +327,7 @@ void Bot::PrepareChatMessage (char *text) } } - if (textStart != NULL) + if (textStart != nullptr) { // let the bots make some mistakes... char tempString[160]; @@ -350,7 +350,7 @@ bool CheckKeywords (char *tempMessage, char *reply) FOR_EACH_AE (g_replyFactory[i].keywords, j) { // check is keyword has occurred in message - if (strstr (tempMessage, g_replyFactory[i].keywords[j].GetBuffer ()) != NULL) + if (strstr (tempMessage, g_replyFactory[i].keywords[j].GetBuffer ()) != nullptr) { Array &replies = g_replyFactory[i].usedReplies; @@ -363,7 +363,7 @@ bool CheckKeywords (char *tempMessage, char *reply) // don't say this twice FOR_EACH_AE (replies, k) { - if (strstr (replies[k].GetBuffer (), generatedReply) != NULL) + if (strstr (replies[k].GetBuffer (), generatedReply) != nullptr) replyUsed = true; } @@ -380,7 +380,7 @@ bool CheckKeywords (char *tempMessage, char *reply) } // didn't find a keyword? 70% of the time use some universal reply - if (Random.Long (1, 100) < 70 && !g_chatFactory[CHAT_NOKW].IsEmpty ()) + if (Random.Int (1, 100) < 70 && !g_chatFactory[CHAT_NOKW].IsEmpty ()) { strcpy (reply, g_chatFactory[CHAT_NOKW].GetRandomElement ().GetBuffer ()); return true; @@ -397,7 +397,7 @@ bool Bot::ParseChat (char *reply) // text to uppercase for keyword parsing for (int i = 0; i < static_cast (strlen (tempMessage)); i++) - tempMessage[i] = toupper (tempMessage[i]); + tempMessage[i] = static_cast (tolower (static_cast (tempMessage[i]))); return CheckKeywords (tempMessage, reply); } @@ -413,7 +413,7 @@ bool Bot::RepliesToPlayer (void) // check is time to chat is good if (m_sayTextBuffer.timeNextChat < engine.Time ()) { - if (Random.Long (1, 100) < m_sayTextBuffer.chatProbability + Random.Long (2, 10) && ParseChat (reinterpret_cast (&text))) + if (Random.Int (1, 100) < m_sayTextBuffer.chatProbability + Random.Int (2, 10) && ParseChat (reinterpret_cast (&text))) { PrepareChatMessage (text); PushMessageQueue (GSM_SAY); diff --git a/source/combat.cpp b/source/combat.cpp index 2f3ccce..2b68fc8 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include @@ -14,7 +14,7 @@ ConVar yb_ignore_enemies ("yb_ignore_enemies", "0"); ConVar yb_csdm_mode ("yb_csdm_mode", "0"); ConVar yb_check_enemy_rendering ("yb_check_enemy_rendering", "0"); -ConVar mp_friendlyfire ("mp_friendlyfire", NULL, VT_NOREGISTER); +ConVar mp_friendlyfire ("mp_friendlyfire", nullptr, VT_NOREGISTER); int Bot::GetNearbyFriendsNearPosition(const Vector &origin, float radius) { @@ -93,7 +93,7 @@ bool Bot::IsEnemyHiddenByRendering (edict_t *enemy) return false; } -bool Bot::CheckVisibility (edict_t *target, Vector *origin, byte *bodyPart) +bool Bot::CheckVisibility (edict_t *target, Vector *origin, uint8 *bodyPart) { // this function checks visibility of a bot target. @@ -214,7 +214,7 @@ bool Bot::LookupEnemy (void) if (m_enemyIgnoreTimer > engine.Time () || m_blindTime > engine.Time () || yb_ignore_enemies.GetBool ()) return false; - edict_t *player, *newEnemy = NULL; + edict_t *player, *newEnemy = nullptr; float nearestDistance = m_viewDistance; @@ -237,7 +237,7 @@ bool Bot::LookupEnemy (void) m_enemyUpdateTime = engine.Time () + 0.5f; // ignore shielded enemies, while we have real one - edict_t *shieldEnemy = NULL; + edict_t *shieldEnemy = nullptr; // setup potentially visible set for this bot Vector potentialVisibility = EyePosition (); @@ -245,7 +245,7 @@ bool Bot::LookupEnemy (void) if (pev->flags & FL_DUCKING) potentialVisibility = potentialVisibility + (VEC_HULL_MIN - VEC_DUCK_HULL_MIN); - byte *pvs = ENGINE_SET_PVS (reinterpret_cast (&potentialVisibility)); + uint8 *pvs = ENGINE_SET_PVS (reinterpret_cast (&potentialVisibility)); // search the world for players... for (int i = 0; i < engine.MaxClients (); i++) @@ -266,7 +266,7 @@ bool Bot::LookupEnemy (void) { m_blindRecognizeTime = engine.Time () + Random.Float (1.0f, 2.0f); - if (Random.Long (0, 100) < 50) + if (Random.Int (0, 100) < 50) ChatterMessage (Chatter_BehindSmoke); } @@ -323,9 +323,9 @@ bool Bot::LookupEnemy (void) if (m_seeEnemyTime + 3.0 < engine.Time () && (m_hasC4 || HasHostage () || !engine.IsNullEntity (m_targetEntity))) RadioMessage (Radio_EnemySpotted); - m_targetEntity = NULL; // stop following when we see an enemy... + m_targetEntity = nullptr; // stop following when we see an enemy... - if (Random.Long (0, 100) < m_difficulty * 25) + if (Random.Int (0, 100) < m_difficulty * 25) m_enemySurpriseTime = engine.Time () + m_actualReactionTime * 0.5f; else m_enemySurpriseTime = engine.Time () + m_actualReactionTime; @@ -353,7 +353,7 @@ bool Bot::LookupEnemy (void) Bot *other = bots.GetBot (client.ent); - if (other != NULL && other->m_seeEnemyTime + 2.0f < engine.Time () && engine.IsNullEntity (other->m_lastEnemy) && IsVisible (pev->origin, other->GetEntity ()) && other->IsInViewCone (pev->origin)) + if (other != nullptr && other->m_seeEnemyTime + 2.0f < engine.Time () && engine.IsNullEntity (other->m_lastEnemy) && IsVisible (pev->origin, other->GetEntity ()) && other->IsInViewCone (pev->origin)) { other->m_lastEnemy = newEnemy; other->m_lastEnemyOrigin = m_lastEnemyOrigin; @@ -372,7 +372,7 @@ bool Bot::LookupEnemy (void) if (!IsAlive (newEnemy)) { - m_enemy = NULL; + m_enemy = nullptr; // shoot at dying players if no new enemy to give some more human-like illusion if (m_seeEnemyTime + 0.1f > engine.Time ()) @@ -459,7 +459,7 @@ const Vector &Bot::GetAimPosition (void) int headshotFreq[5] = { 20, 40, 60, 80, 100 }; // now check is our skill match to aim at head, else aim at enemy body - if ((Random.Long (1, 100) < headshotFreq[m_difficulty]) || UsesPistol ()) + if ((Random.Int (1, 100) < headshotFreq[m_difficulty]) || UsesPistol ()) targetOrigin = targetOrigin + m_enemy->v.view_ofs + Vector (0.0f, 0.0f, GetZOffset (distance)); else targetOrigin = targetOrigin + Vector (0.0f, 0.0f, GetZOffset (distance)); @@ -816,7 +816,7 @@ void Bot::FinishWeaponSelection (float distance, int index, int id, int choosen) { if (distance < 64.0f) { - if (Random.Long (1, 100) < 30 || HasShield ()) + if (Random.Int (1, 100) < 30 || HasShield ()) pev->button |= IN_ATTACK; // use primary attack else pev->button |= IN_ATTACK2; // use secondary attack @@ -1082,7 +1082,7 @@ void Bot::CombatFight (void) { if (m_lastFightStyleCheck + 3.0f < engine.Time ()) { - int rand = Random.Long (1, 100); + int rand = Random.Int (1, 100); if (distance < 450.0f) m_fightStyle = FIGHT_STRAFE; @@ -1107,7 +1107,7 @@ void Bot::CombatFight (void) { if (m_lastFightStyleCheck + 3.0f < engine.Time ()) { - if (Random.Long (0, 100) < 50) + if (Random.Int (0, 100) < 50) m_fightStyle = FIGHT_STRAFE; else m_fightStyle = FIGHT_STAY; @@ -1131,7 +1131,7 @@ void Bot::CombatFight (void) else m_combatStrafeDir = STRAFE_DIR_RIGHT; - if (Random.Long (1, 100) < 30) + if (Random.Int (1, 100) < 30) m_combatStrafeDir = (m_combatStrafeDir == STRAFE_DIR_LEFT ? STRAFE_DIR_RIGHT : STRAFE_DIR_LEFT); m_strafeSetTime = engine.Time () + Random.Float (0.5f, 3.0f); @@ -1158,7 +1158,7 @@ void Bot::CombatFight (void) } } - if (m_difficulty >= 3 && (m_jumpTime + 5.0f < engine.Time () && IsOnFloor () && Random.Long (0, 1000) < (m_isReloading ? 8 : 2) && pev->velocity.GetLength2D () > 150.0f) && !UsesSniper ()) + if (m_difficulty >= 3 && (m_jumpTime + 5.0f < engine.Time () && IsOnFloor () && Random.Int (0, 1000) < (m_isReloading ? 8 : 2) && pev->velocity.GetLength2D () > 150.0f) && !UsesSniper ()) pev->button |= IN_JUMP; if (m_moveSpeed > 0.0f && distance > 100.0f && m_currentWeapon != WEAPON_KNIFE) diff --git a/source/engine.cpp b/source/engine.cpp index 38ec4cc..8cb0a3b 100644 --- a/source/engine.cpp +++ b/source/engine.cpp @@ -4,15 +4,15 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include Engine::Engine (void) { - m_startEntity = NULL; - m_localEntity = NULL; + m_startEntity = nullptr; + m_localEntity = nullptr; m_language.RemoveAll (); ResetMessageCapture (); @@ -44,7 +44,7 @@ void Engine::Precache (edict_t *startEntity) m_drawModels[DRAW_SIMPLE] = PRECACHE_MODEL (ENGINE_STR ("sprites/laserbeam.spr")); m_drawModels[DRAW_ARROW] = PRECACHE_MODEL (ENGINE_STR ("sprites/arrow1.spr")); - m_localEntity = NULL; + m_localEntity = nullptr; m_startEntity = startEntity; } @@ -134,7 +134,7 @@ void Engine::DrawLine (edict_t * ent, const Vector &start, const Vector &end, in if (!IsValidPlayer (ent)) return; // reliability check - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, NULL, ent); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, nullptr, ent); WRITE_BYTE (TE_BEAMPOINTS); WRITE_COORD (end.x); WRITE_COORD (end.y); @@ -207,7 +207,7 @@ float Engine::GetWaveLength (const char *fileName) return 0.0f; // check if we have engine function for this - if (g_engfuncs.pfnGetApproxWavePlayLen != NULL) + if (g_engfuncs.pfnGetApproxWavePlayLen != nullptr) { fp.Close (); return g_engfuncs.pfnGetApproxWavePlayLen (filePath) / 1000.0f; @@ -221,12 +221,12 @@ float Engine::GetWaveLength (const char *fileName) char chunkID[4]; char formatChunkId[4]; unsigned long formatChunkLength; - unsigned short dummy; - unsigned short channels; + uint16 dummy; + uint16 channels; unsigned long sampleRate; unsigned long bytesPerSecond; - unsigned short bytesPerSample; - unsigned short bitsPerSample; + uint16 bytesPerSample; + uint16 bitsPerSample; char dataChunkId[4]; unsigned long dataChunkLength; } waveHdr; @@ -326,7 +326,7 @@ void Engine::RegisterCmd (const char * command, void func (void)) void Engine::EmitSound (edict_t *ent, const char *sound) { - g_engfuncs.pfnEmitSound (ent, CHAN_WEAPON, sound, 1.0f, ATTN_NORM, 0, 100.0f); + g_engfuncs.pfnEmitSound (ent, CHAN_WEAPON, sound, 1.0f, ATTN_NORM, 0, 100); } void Engine::IssueBotCommand (edict_t *ent, const char *fmt, ...) @@ -518,7 +518,7 @@ void Engine::PushRegisteredConVarsToEngine (bool gameVars) { ptr->self->m_eptr = g_engfuncs.pfnCVarGetPointer (ptr->reg.name); - if (ptr->self->m_eptr == NULL) + if (ptr->self->m_eptr == nullptr) { g_engfuncs.pfnCVarRegister (&ptr->reg); ptr->self->m_eptr = g_engfuncs.pfnCVarGetPointer (ptr->reg.name); @@ -528,12 +528,12 @@ void Engine::PushRegisteredConVarsToEngine (bool gameVars) { ptr->self->m_eptr = g_engfuncs.pfnCVarGetPointer (ptr->reg.name); - if (ptr->regMissing && ptr->self->m_eptr == NULL) + if (ptr->regMissing && ptr->self->m_eptr == nullptr) { g_engfuncs.pfnCVarRegister (&ptr->reg); ptr->self->m_eptr = g_engfuncs.pfnCVarGetPointer (ptr->reg.name); } - InternalAssert (ptr->self->m_eptr != NULL); // ensure game var exists + InternalAssert (ptr->self->m_eptr != nullptr); // ensure game var exists } } } @@ -590,8 +590,8 @@ void Engine::ProcessMessageCapture (void *ptr) return; // some needed variables - static byte r, g, b; - static byte enabled; + static uint8 r, g, b; + static uint8 enabled; static int damageArmor, damageTaken, damageBits; static int killerIndex, victimIndex, playerIndex; @@ -606,7 +606,7 @@ void Engine::ProcessMessageCapture (void *ptr) char *strVal = reinterpret_cast (ptr); int intVal = *reinterpret_cast (ptr); - unsigned char byteVal = *reinterpret_cast (ptr); + uint8 byteVal = *reinterpret_cast (ptr); // now starts of network message execution switch (m_msgBlock.msg) @@ -770,7 +770,7 @@ void Engine::ProcessMessageCapture (void *ptr) case 2: damageBits = intVal; - if (bot != NULL && (damageArmor > 0 || damageTaken > 0)) + if (bot != nullptr && (damageArmor > 0 || damageTaken > 0)) bot->TakeDamage (bot->pev->dmg_inflictor, damageTaken, damageArmor, damageBits); break; } @@ -838,7 +838,7 @@ void Engine::ProcessMessageCapture (void *ptr) { Bot *notify = bots.GetBot (i); - if (notify != NULL && notify->m_notKilled && killer != notify->GetEntity () && notify->EntityIsVisible (victim->v.origin) && GetTeam (killer) == notify->m_team && GetTeam (killer) != GetTeam (victim)) + if (notify != nullptr && notify->m_notKilled && killer != notify->GetEntity () && notify->EntityIsVisible (victim->v.origin) && GetTeam (killer) == notify->m_team && GetTeam (killer) != GetTeam (victim)) { if (killer == g_hostEntity) notify->HandleChatterMessage ("#Bot_NiceShotCommander"); @@ -855,7 +855,7 @@ void Engine::ProcessMessageCapture (void *ptr) { Bot *notify = bots.GetBot (i); - if (notify != NULL && notify->m_seeEnemyTime + 2.0f < Time () && notify->m_notKilled && notify->m_team == GetTeam (victim) && IsVisible (killer->v.origin, notify->GetEntity ()) && IsNullEntity (notify->m_enemy) && GetTeam (killer) != GetTeam (victim)) + if (notify != nullptr && notify->m_seeEnemyTime + 2.0f < Time () && notify->m_notKilled && notify->m_team == GetTeam (victim) && IsVisible (killer->v.origin, notify->GetEntity ()) && IsNullEntity (notify->m_enemy) && GetTeam (killer) != GetTeam (victim)) { notify->m_actualReactionTime = 0.0f; notify->m_seeEnemyTime = Time (); @@ -868,14 +868,14 @@ void Engine::ProcessMessageCapture (void *ptr) Bot *notify = bots.GetBot (killer); // is this message about a bot who killed somebody? - if (notify != NULL) + if (notify != nullptr) notify->m_lastVictim = victim; else // did a human kill a bot on his team? { Bot *target = bots.GetBot (victim); - if (target != NULL) + if (target != nullptr) { if (GetTeam (killer) == GetTeam (victim)) target->m_voteKickIndex = killerIndex; @@ -958,7 +958,7 @@ void Engine::ProcessMessageCapture (void *ptr) { Bot *notify = bots.FindOneValidAliveBot (); - if (notify != NULL && notify->m_notKilled) + if (notify != nullptr && notify->m_notKilled) notify->HandleChatterMessage (strVal); } } @@ -977,7 +977,7 @@ void Engine::ProcessMessageCapture (void *ptr) { Bot *notify = bots.FindOneValidAliveBot (); - if (notify != NULL && notify->m_notKilled) + if (notify != nullptr && notify->m_notKilled) notify->HandleChatterMessage (strVal); } } @@ -992,20 +992,20 @@ void Engine::ProcessMessageCapture (void *ptr) { Bot *notify = bots.GetBot (i); - if (notify != NULL && notify->m_notKilled) + if (notify != nullptr && notify->m_notKilled) { notify->DeleteSearchNodes (); notify->ResetTasks (); - if (yb_communication_type.GetInt () == 2 && Random.Long (0, 100) < 75 && notify->m_team == CT) + if (yb_communication_type.GetInt () == 2 && Random.Int (0, 100) < 75 && notify->m_team == CT) notify->ChatterMessage (Chatter_WhereIsTheBomb); } } waypoints.SetBombPosition (); } - else if (bot != NULL && FStrEq (strVal, "#Switch_To_BurstFire")) + else if (bot != nullptr && FStrEq (strVal, "#Switch_To_BurstFire")) bot->m_weaponBurstMode = BM_ON; - else if (bot != NULL && FStrEq (strVal, "#Switch_To_SemiAuto")) + else if (bot != nullptr && FStrEq (strVal, "#Switch_To_SemiAuto")) bot->m_weaponBurstMode = BM_OFF; } break; @@ -1056,7 +1056,7 @@ void Engine::ProcessMessageCapture (void *ptr) m_msgBlock.state++; // and finally update network message state } -ConVar::ConVar (const char *name, const char *initval, VarType type, bool regMissing) : m_eptr (NULL) +ConVar::ConVar (const char *name, const char *initval, VarType type, bool regMissing) : m_eptr (nullptr) { engine.PushVariableToStack (name, initval, type, regMissing, this); } diff --git a/source/globals.cpp b/source/globals.cpp index 1e0441e..8b2c5b0 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include @@ -71,11 +71,11 @@ Array > g_chatterFactory; Array g_botNames; Array g_replyFactory; RandomSequenceOfUnique Random; -Library *g_gameLib = NULL; +Library *g_gameLib = nullptr; -meta_globals_t *gpMetaGlobals = NULL; -gamedll_funcs_t *gpGamedllFuncs = NULL; -mutil_funcs_t *gpMetaUtilFuncs = NULL; +meta_globals_t *gpMetaGlobals = nullptr; +gamedll_funcs_t *gpGamedllFuncs = nullptr; +mutil_funcs_t *gpMetaUtilFuncs = nullptr; gamefuncs_t g_functionTable; @@ -83,9 +83,9 @@ enginefuncs_t g_engfuncs; Client g_clients[MAX_ENGINE_PLAYERS]; WeaponProperty g_weaponDefs[MAX_WEAPONS + 1]; -edict_t *g_hostEntity = NULL; -globalvars_t *g_pGlobals = NULL; -Experience *g_experienceData = NULL; +edict_t *g_hostEntity = nullptr; +globalvars_t *g_pGlobals = nullptr; +Experience *g_experienceData = nullptr; // default tables for personality weapon preferences, overridden by weapons.cfg int g_normalWeaponPrefs[NUM_WEAPONS] = @@ -110,19 +110,6 @@ int *g_weaponPrefs[] = g_carefulWeaponPrefs }; -// metamod engine & dllapi function tables -metamod_funcs_t gMetaFunctionTable = -{ - NULL, // pfnGetEntityAPI () - NULL, // pfnGetEntityAPI_Post () - GetEntityAPI2, // pfnGetEntityAPI2 () - GetEntityAPI2_Post, // pfnGetEntityAPI2_Post () - NULL, // pfnGetNewDLLFunctions () - NULL, // pfnGetNewDLLFunctions_Post () - GetEngineFunctions, // pfnGetEngineFunctions () - GetEngineFunctions_Post, // pfnGetEngineFunctions_Post () -}; - // metamod plugin information plugin_info_t Plugin_info = { @@ -383,25 +370,25 @@ MenuText g_menus[21] = // kickmenu #1 { 0x0, - NULL, + nullptr, }, // kickmenu #2 { 0x0, - NULL, + nullptr, }, // kickmenu #3 { 0x0, - NULL, + nullptr, }, // kickmenu #4 { 0x0, - NULL, + nullptr, }, // command menu diff --git a/source/interface.cpp b/source/interface.cpp index ce9616d..10d071c 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include @@ -16,7 +16,7 @@ ConVar yb_password_key ("yb_password_key", "_ybpw"); ConVar yb_language ("yb_language", "en"); ConVar yb_version ("yb_version", PRODUCT_VERSION, VT_READONLY); -ConVar mp_startmoney ("mp_startmoney", NULL, VT_NOREGISTER); +ConVar mp_startmoney ("mp_startmoney", nullptr, VT_NOREGISTER); int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const char *arg2, const char *arg3, const char *arg4, const char *arg5, const char *self) { @@ -96,7 +96,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c { Bot *bot = bots.GetBot (i); - if (bot != NULL) + if (bot != nullptr) bot->m_voteMap = nominatedMap; } engine.ClientPrintf (ent, "All dead bots will vote for map #%d", nominatedMap); @@ -179,7 +179,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c { Bot *bot = bots.GetBot (i); - if (bot != NULL) + if (bot != nullptr) { bot->pev->takedamage = isOn ? 0.0f : 1.0f; } @@ -197,7 +197,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c DisplayMenuToClient (ent, &g_menus[18]); else { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display engine.CenterPrintf ("You're dead, and have no access to this menu"); } } @@ -246,7 +246,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c // toggles displaying player models on spawn spots else if (stricmp (arg1, "mdl") == 0 || stricmp (arg1, "models") == 0) { - edict_t *spawnEntity = NULL; + edict_t *spawnEntity = nullptr; if (stricmp (arg2, "on") == 0) { @@ -480,8 +480,8 @@ void ParseVoiceEvent (const String &base, int type, float timeToRepeat) } // forwards for MemoryFile -MemoryFile::MF_Loader MemoryFile::Loader = NULL; -MemoryFile::MF_Unloader MemoryFile::Unloader = NULL; +MemoryFile::MF_Loader MemoryFile::Loader = nullptr; +MemoryFile::MF_Unloader MemoryFile::Unloader = nullptr; void InitConfig (void) { @@ -605,7 +605,7 @@ void InitConfig (void) break; case 3: - if (strstr (line, "@KEY") != NULL) + if (strstr (line, "@KEY") != nullptr) { if (!replyKey.keywords.IsEmpty () && !replyKey.replies.IsEmpty ()) { @@ -936,7 +936,7 @@ void GameDLLInit (void) engine.IssueCmd ("exec addons/yapb/conf/yapb.cfg"); // set correct version string - yb_version.SetString (FormatBuffer ("%d.%d.%d.%u", PRODUCT_VERSION_DWORD_INTERNAL, GenerateBuildNumber ())); + yb_version.SetString (FormatBuffer ("%d.%d.%d", PRODUCT_VERSION_DWORD_INTERNAL, GenerateBuildNumber ())); // register fake metamod command handler if we not! under mm if (!(g_gameFlags & GAME_METAMOD)) @@ -970,7 +970,7 @@ void Touch (edict_t *pentTouched, edict_t *pentOther) { Bot *bot = bots.GetBot (pentOther); - if (bot != NULL) + if (bot != nullptr) bot->VerifyBreakable (pentTouched); } if (g_gameFlags & GAME_METAMOD) @@ -1005,7 +1005,7 @@ int Spawn (edict_t *ent) g_mapType = 0; // reset map type as worldspawn is the first entity spawned // detect official csbots here, as they causing crash in linkent code when active for some reason - if (!(g_gameFlags & GAME_LEGACY) && g_engfuncs.pfnCVarGetPointer ("bot_stop") != NULL) + if (!(g_gameFlags & GAME_LEGACY) && g_engfuncs.pfnCVarGetPointer ("bot_stop") != nullptr) g_gameFlags |= GAME_OFFICIAL_CSBOT; } else if (strcmp (entityClassname, "player_weaponstrip") == 0) @@ -1147,7 +1147,7 @@ void ClientDisconnect (edict_t *ent) Bot *bot = bots.GetBot (i); // check if its a bot - if (bot != NULL) + if (bot != nullptr) { if (bot->pev == &ent->v) { @@ -1237,14 +1237,14 @@ void ClientCommand (edict_t *ent) return; } - else if (stricmp (command, "menuselect") == 0 && !IsNullString (arg1) && g_clients[issuerPlayerIndex].menu != NULL) + else if (stricmp (command, "menuselect") == 0 && !IsNullString (arg1) && g_clients[issuerPlayerIndex].menu != nullptr) { Client *client = &g_clients[issuerPlayerIndex]; int selection = atoi (arg1); if (client->menu == &g_menus[12]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1267,7 +1267,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1277,7 +1277,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[13]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1308,7 +1308,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[9]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1359,7 +1359,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1369,7 +1369,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[10]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1465,7 +1465,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[11]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display g_waypointOn = true; // turn waypoints on in case @@ -1481,7 +1481,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[0]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1504,7 +1504,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } @@ -1515,7 +1515,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[2]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1540,7 +1540,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1550,7 +1550,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[1]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1577,13 +1577,13 @@ void ClientCommand (edict_t *ent) DisplayMenuToClient (ent, &g_menus[18]); else { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display engine.CenterPrintf ("You're dead, and have no access to this menu"); } break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1593,8 +1593,8 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[18]) { - DisplayMenuToClient (ent, NULL); // reset menu display - Bot *bot = NULL; + DisplayMenuToClient (ent, nullptr); // reset menu display + Bot *bot = nullptr; switch (selection) { @@ -1628,7 +1628,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } @@ -1639,17 +1639,17 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[19]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display - const int autoDistanceValue[] = {0, 100, 130, 160, 190, 220, 250}; + const float autoDistanceValue[] = {0.0f, 100.0f, 130.0f, 160.0f, 190.0f, 220.0f, 250.0f }; if (selection >= 1 && selection <= 7) g_autoPathDistance = autoDistanceValue[selection - 1]; - if (g_autoPathDistance == 0) + if (g_autoPathDistance == 0.0f) engine.CenterPrintf ("AutoPath disabled"); else - engine.CenterPrintf ("AutoPath maximum distance set to %f", g_autoPathDistance); + engine.CenterPrintf ("AutoPath maximum distance set to %.2f", g_autoPathDistance); if (g_gameFlags & GAME_METAMOD) RETURN_META (MRES_SUPERCEDE); @@ -1658,7 +1658,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[20]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1675,7 +1675,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } @@ -1686,7 +1686,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[5]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display client->menu = &g_menus[4]; @@ -1713,7 +1713,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } @@ -1727,7 +1727,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[6] && fillCommand) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1743,7 +1743,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1753,7 +1753,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[4] && fillCommand) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1764,7 +1764,7 @@ void ClientCommand (edict_t *ent) bots.FillServer (fillServerTeam, selection - 2, g_storeAddbotVars[0]); case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1774,7 +1774,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[6]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1797,7 +1797,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1807,7 +1807,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[4]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1820,7 +1820,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1830,7 +1830,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[7] || client->menu == &g_menus[8]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1844,7 +1844,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1854,7 +1854,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[3]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1869,7 +1869,7 @@ void ClientCommand (edict_t *ent) break; case 10: - DisplayMenuToClient (ent, NULL); + DisplayMenuToClient (ent, nullptr); break; } if (g_gameFlags & GAME_METAMOD) @@ -1879,7 +1879,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[14]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1909,7 +1909,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[15]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1939,7 +1939,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[16]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1969,7 +1969,7 @@ void ClientCommand (edict_t *ent) } else if (client->menu == &g_menus[17]) { - DisplayMenuToClient (ent, NULL); // reset menu display + DisplayMenuToClient (ent, nullptr); // reset menu display switch (selection) { @@ -1998,7 +1998,7 @@ void ClientCommand (edict_t *ent) if (!engine.IsBotCommand () && (stricmp (command, "say") == 0 || stricmp (command, "say_team") == 0)) { - Bot *bot = NULL; + Bot *bot = nullptr; if (FStrEq (arg1, "dropme") || FStrEq (arg1, "dropc4")) { @@ -2023,7 +2023,7 @@ void ClientCommand (edict_t *ent) Bot *target = bots.GetBot (i); - if (target != NULL) + if (target != nullptr) { target->m_sayTextBuffer.entityIndex = engine.IndexOfEntity (ent); @@ -2056,7 +2056,7 @@ void ClientCommand (edict_t *ent) Bot *bot = bots.GetBot (i); // validate bot - if (bot != NULL && bot->m_team == radioTarget.team && ent != bot->GetEntity () && bot->m_radioOrder == 0) + if (bot != nullptr && bot->m_team == radioTarget.team && ent != bot->GetEntity () && bot->m_radioOrder == 0) { bot->m_radioOrder = radioCommand; bot->m_radioEntity = ent; @@ -2182,7 +2182,7 @@ void StartFrame (void) else { storeClient.flags &= ~(CF_USED | CF_ALIVE); - storeClient.ent = NULL; + storeClient.ent = nullptr; } } @@ -2237,14 +2237,14 @@ void StartFrame (void) static cvar_t *csdm_active; static cvar_t *mp_freeforall; - if (csdm_active == NULL) + if (csdm_active == nullptr) csdm_active = CVAR_GET_POINTER ("csdm_active"); - if (mp_freeforall == NULL) + if (mp_freeforall == nullptr) mp_freeforall = CVAR_GET_POINTER ("mp_freeforall"); - if (csdm_active != NULL && csdm_active->value > 0) - yb_csdm_mode.SetInt (mp_freeforall != NULL && mp_freeforall->value > 0 ? 2 : 1); + if (csdm_active != nullptr && csdm_active->value > 0) + yb_csdm_mode.SetInt (mp_freeforall != nullptr && mp_freeforall->value > 0 ? 2 : 1); } g_timePerSecondUpdate = engine.Time () + 1.0f; } @@ -2408,26 +2408,26 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed // store the message type in our own variables, since the GET_USER_MSG_ID () will just do a lot of strcmp()'s... if ((g_gameFlags & GAME_METAMOD) && engine.FindMessageId (NETMSG_MONEY) == -1) { - engine.AssignMessageId (NETMSG_VGUI, GET_USER_MSG_ID (PLID, "VGUIMenu", NULL)); - engine.AssignMessageId (NETMSG_SHOWMENU, GET_USER_MSG_ID (PLID, "ShowMenu", NULL)); - engine.AssignMessageId (NETMSG_WEAPONLIST, GET_USER_MSG_ID (PLID, "WeaponList", NULL)); - engine.AssignMessageId (NETMSG_CURWEAPON, GET_USER_MSG_ID (PLID, "CurWeapon", NULL)); - engine.AssignMessageId (NETMSG_AMMOX, GET_USER_MSG_ID (PLID, "AmmoX", NULL)); - engine.AssignMessageId (NETMSG_AMMOPICKUP, GET_USER_MSG_ID (PLID, "AmmoPickup", NULL)); - engine.AssignMessageId (NETMSG_DAMAGE, GET_USER_MSG_ID (PLID, "Damage", NULL)); - engine.AssignMessageId (NETMSG_MONEY, GET_USER_MSG_ID (PLID, "Money", NULL)); - engine.AssignMessageId (NETMSG_STATUSICON, GET_USER_MSG_ID (PLID, "StatusIcon", NULL)); - engine.AssignMessageId (NETMSG_DEATH, GET_USER_MSG_ID (PLID, "DeathMsg", NULL)); - engine.AssignMessageId (NETMSG_SCREENFADE, GET_USER_MSG_ID (PLID, "ScreenFade", NULL)); - engine.AssignMessageId (NETMSG_HLTV, GET_USER_MSG_ID (PLID, "HLTV", NULL)); - engine.AssignMessageId (NETMSG_TEXTMSG, GET_USER_MSG_ID (PLID, "TextMsg", NULL)); - engine.AssignMessageId (NETMSG_SCOREINFO, GET_USER_MSG_ID (PLID, "ScoreInfo", NULL)); - engine.AssignMessageId (NETMSG_BARTIME, GET_USER_MSG_ID (PLID, "BarTime", NULL)); - engine.AssignMessageId (NETMSG_SENDAUDIO, GET_USER_MSG_ID (PLID, "SendAudio", NULL)); - engine.AssignMessageId (NETMSG_SAYTEXT, GET_USER_MSG_ID (PLID, "SayText", NULL)); + engine.AssignMessageId (NETMSG_VGUI, GET_USER_MSG_ID (PLID, "VGUIMenu", nullptr)); + engine.AssignMessageId (NETMSG_SHOWMENU, GET_USER_MSG_ID (PLID, "ShowMenu", nullptr)); + engine.AssignMessageId (NETMSG_WEAPONLIST, GET_USER_MSG_ID (PLID, "WeaponList", nullptr)); + engine.AssignMessageId (NETMSG_CURWEAPON, GET_USER_MSG_ID (PLID, "CurWeapon", nullptr)); + engine.AssignMessageId (NETMSG_AMMOX, GET_USER_MSG_ID (PLID, "AmmoX", nullptr)); + engine.AssignMessageId (NETMSG_AMMOPICKUP, GET_USER_MSG_ID (PLID, "AmmoPickup", nullptr)); + engine.AssignMessageId (NETMSG_DAMAGE, GET_USER_MSG_ID (PLID, "Damage", nullptr)); + engine.AssignMessageId (NETMSG_MONEY, GET_USER_MSG_ID (PLID, "Money", nullptr)); + engine.AssignMessageId (NETMSG_STATUSICON, GET_USER_MSG_ID (PLID, "StatusIcon", nullptr)); + engine.AssignMessageId (NETMSG_DEATH, GET_USER_MSG_ID (PLID, "DeathMsg", nullptr)); + engine.AssignMessageId (NETMSG_SCREENFADE, GET_USER_MSG_ID (PLID, "ScreenFade", nullptr)); + engine.AssignMessageId (NETMSG_HLTV, GET_USER_MSG_ID (PLID, "HLTV", nullptr)); + engine.AssignMessageId (NETMSG_TEXTMSG, GET_USER_MSG_ID (PLID, "TextMsg", nullptr)); + engine.AssignMessageId (NETMSG_SCOREINFO, GET_USER_MSG_ID (PLID, "ScoreInfo", nullptr)); + engine.AssignMessageId (NETMSG_BARTIME, GET_USER_MSG_ID (PLID, "BarTime", nullptr)); + engine.AssignMessageId (NETMSG_SENDAUDIO, GET_USER_MSG_ID (PLID, "SendAudio", nullptr)); + engine.AssignMessageId (NETMSG_SAYTEXT, GET_USER_MSG_ID (PLID, "SayText", nullptr)); if (!(g_gameFlags & GAME_LEGACY)) - engine.AssignMessageId (NETMSG_BOTVOICE, GET_USER_MSG_ID (PLID, "BotVoice", NULL)); + engine.AssignMessageId (NETMSG_BOTVOICE, GET_USER_MSG_ID (PLID, "BotVoice", nullptr)); } engine.ResetMessageCapture (); @@ -2471,7 +2471,7 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed { Bot *bot = bots.GetBot (i); - if (bot != NULL) + if (bot != nullptr) bot->m_notKilled = false; } } @@ -2635,7 +2635,7 @@ const char *pfnCmd_Args (void) } if (g_gameFlags & GAME_METAMOD) - RETURN_META_VALUE (MRES_IGNORED, NULL); + RETURN_META_VALUE (MRES_IGNORED, nullptr); return CMD_ARGS (); // ask the client command string to the engine } @@ -2658,7 +2658,7 @@ const char *pfnCmd_Argv (int argc) return engine.GetOverrideArgv (argc); // if so, then return the wanted argument we know } if (g_gameFlags & GAME_METAMOD) - RETURN_META_VALUE (MRES_IGNORED, NULL); + RETURN_META_VALUE (MRES_IGNORED, nullptr); return CMD_ARGV (argc); // ask the argument number "argc" to the engine } @@ -2690,7 +2690,7 @@ void pfnSetClientMaxspeed (const edict_t *ent, float newMaxspeed) Bot *bot = bots.GetBot (const_cast (ent)); // check wether it's not a bot - if (bot != NULL) + if (bot != nullptr) bot->pev->maxspeed = newMaxspeed; if (g_gameFlags & GAME_METAMOD) @@ -2765,14 +2765,14 @@ void pfnAlertMessage (ALERT_TYPE alertType, char *format, ...) vsnprintf (buffer, SIZEOF_CHAR (buffer), format, ap); va_end (ap); - if ((g_mapType & MAP_DE) && g_bombPlanted && strstr (buffer, "_Defuse_") != NULL) + if ((g_mapType & MAP_DE) && g_bombPlanted && strstr (buffer, "_Defuse_") != nullptr) { // notify all terrorists that CT is starting bomb defusing for (int i = 0; i < engine.MaxClients (); i++) { Bot *bot = bots.GetBot (i); - if (bot != NULL && bot->m_team == TERRORIST && bot->m_notKilled) + if (bot != nullptr && bot->m_team == TERRORIST && bot->m_notKilled) { bot->DeleteSearchNodes (); @@ -2867,7 +2867,7 @@ SHARED_LIBRARAY_EXPORT int GetNewDLLFunctions (newgamefuncs_t *functionTable, in auto api_GetNewDLLFunctions = g_gameLib->GetFuncAddr ("GetNewDLLFunctions"); - if (api_GetNewDLLFunctions == NULL) + if (api_GetNewDLLFunctions == nullptr) return FALSE; if (!api_GetNewDLLFunctions (functionTable, interfaceVersion)) @@ -2927,7 +2927,7 @@ SHARED_LIBRARAY_EXPORT int Server_GetBlendingInterface (int version, void **ppin auto api_GetBlendingInterface = g_gameLib->GetFuncAddr ("Server_GetBlendingInterface"); - if (api_GetBlendingInterface == NULL) + if (api_GetBlendingInterface == nullptr) return FALSE; return api_GetBlendingInterface (version, ppinterface, pstudio, rotationmatrix, bonetransform); @@ -2951,9 +2951,23 @@ SHARED_LIBRARAY_EXPORT int Meta_Attach (PLUG_LOADTIME, metamod_funcs_t *function // where we can tell if the plugin will be allowed to run or not, we wait until here to make // our initialization stuff, like registering CVARs and dedicated server commands. + + // metamod engine & dllapi function tables + static metamod_funcs_t metamodFunctionTable = + { + nullptr, // pfnGetEntityAPI () + nullptr, // pfnGetEntityAPI_Post () + GetEntityAPI2, // pfnGetEntityAPI2 () + GetEntityAPI2_Post, // pfnGetEntityAPI2_Post () + nullptr, // pfnGetNewDLLFunctions () + nullptr, // pfnGetNewDLLFunctions_Post () + GetEngineFunctions, // pfnGetEngineFunctions () + GetEngineFunctions_Post, // pfnGetEngineFunctions_Post () + }; + // keep track of the pointers to engine function tables metamod gives us gpMetaGlobals = pMGlobals; - memcpy (functionTable, &gMetaFunctionTable, sizeof (metamod_funcs_t)); + memcpy (functionTable, &metamodFunctionTable, sizeof (metamod_funcs_t)); gpGamedllFuncs = pGamedllFuncs; return TRUE; // returning true enables metamod to attach this plugin @@ -2983,7 +2997,7 @@ Library *LoadCSBinary (void) const char *modname = engine.GetModName (); if (!modname) - return NULL; + return nullptr; #if defined (PLATFORM_WIN32) const char *libs[] = { "mp.dll", "cs.dll" }; @@ -3009,7 +3023,7 @@ Library *LoadCSBinary (void) g_gameFlags |= GAME_CZERO; if (g_gameFlags & GAME_METAMOD) - return NULL; + return nullptr; return new Library (path); } @@ -3021,18 +3035,18 @@ Library *LoadCSBinary (void) if (!game->IsLoaded ()) { AddLogEntry (true, LL_FATAL | LL_IGNORE, "Unable to load gamedll \"%s\". Exiting... (gamedir: %s)", libs[i], modname); - return NULL; + return nullptr; } // detect xash engine - if (g_engfuncs.pfnCVarGetPointer ("build") != NULL) + if (g_engfuncs.pfnCVarGetPointer ("build") != nullptr) { g_gameFlags |= (GAME_LEGACY | GAME_XASH); if (g_gameFlags & GAME_METAMOD) { delete game; - return NULL; + return nullptr; } return game; } @@ -3040,7 +3054,7 @@ Library *LoadCSBinary (void) // detect if we're running modern game EntityPtr_t entity = game->GetFuncAddr ("weapon_famas"); - if (entity != NULL) + if (entity != nullptr) g_gameFlags |= GAME_CSTRIKE16; else g_gameFlags |= GAME_LEGACY; @@ -3048,12 +3062,12 @@ Library *LoadCSBinary (void) if (g_gameFlags & GAME_METAMOD) { delete game; - return NULL; + return nullptr; } return game; } } - return NULL; + return nullptr; } DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t *pGlobals) @@ -3107,7 +3121,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t #else g_gameLib = LoadCSBinary (); { - if (g_gameLib == NULL && !(g_gameFlags & GAME_METAMOD)) + if (g_gameLib == nullptr && !(g_gameFlags & GAME_METAMOD)) { AddLogEntry (true, LL_FATAL | LL_IGNORE, "Mod that you has started, not supported by this bot (gamedir: %s)", engine.GetModName ()); return; @@ -3146,7 +3160,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t if (!api_GiveFnptrsToDll) TerminateOnMalloc (); - GetEngineFunctions (functionTable, NULL); + GetEngineFunctions (functionTable, nullptr); // give the engine functions to the other DLL... api_GiveFnptrsToDll (functionTable, pGlobals); @@ -3169,10 +3183,10 @@ DLL_ENTRYPOINT void LinkEntity_Helper (EntityPtr_t &addr, const char *name, entvars_t *pev) { - if (addr == NULL) + if (addr == nullptr) addr = g_gameLib->GetFuncAddr (name); - if (addr == NULL) + if (addr == nullptr) return; addr (pev); diff --git a/source/manager.cpp b/source/manager.cpp index c7b752f..52ae81c 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include @@ -41,7 +41,7 @@ BotManager::BotManager (void) m_grenadeUpdateTime = 0.0f; m_creationTab.RemoveAll (); - m_killerEntity = NULL; + m_killerEntity = nullptr; m_balanceCount = 0; } @@ -113,7 +113,7 @@ BotCreationResult BotManager::CreateBot (const String &name, int difficulty, int // this function completely prepares bot entity (edict) for creation, creates team, difficulty, sets name etc, and // then sends result to bot constructor - edict_t *bot = NULL; + edict_t *bot = nullptr; char outputName[33]; if (g_numWaypoints < 1) // don't allow creating bots with no waypoints loaded @@ -132,17 +132,17 @@ BotCreationResult BotManager::CreateBot (const String &name, int difficulty, int if (difficulty < 0 || difficulty > 4) { - difficulty = Random.Long (3, 4); + difficulty = Random.Int (3, 4); yb_difficulty.SetInt (difficulty); } if (personality < 0 || personality > 2) { - if (Random.Long (0, 100) < 50) + if (Random.Int (0, 100) < 50) personality = PERSONALITY_NORMAL; else { - if (Random.Long (0, 100) < 65) + if (Random.Int (0, 100) < 65) personality = PERSONALITY_RUSHER; else personality = PERSONALITY_CAREFUL; @@ -165,7 +165,7 @@ BotCreationResult BotManager::CreateBot (const String &name, int difficulty, int BotName *pickedName = &g_botNames.GetRandomElement (); - if (pickedName == NULL) + if (pickedName == nullptr) continue; if (pickedName->used) @@ -178,7 +178,7 @@ BotCreationResult BotManager::CreateBot (const String &name, int difficulty, int } } else - sprintf (outputName, "bot%i", Random.Long (0, 100)); // just pick ugly random name + sprintf (outputName, "bot%i", Random.Int (0, 100)); // just pick ugly random name } else strncpy (outputName, name, 21); @@ -204,11 +204,11 @@ BotCreationResult BotManager::CreateBot (const String &name, int difficulty, int int index = engine.IndexOfEntity (bot) - 1; InternalAssert (index >= 0 && index <= MAX_ENGINE_PLAYERS); // check index - InternalAssert (m_bots[index] == NULL); // check bot slot + InternalAssert (m_bots[index] == nullptr); // check bot slot m_bots[index] = new Bot (bot, difficulty, personality, team, member, steamId); - if (m_bots[index] == NULL) + if (m_bots[index] == nullptr) TerminateOnMalloc (); engine.Printf ("Connecting Bot..."); @@ -230,7 +230,7 @@ int BotManager::GetIndex (edict_t *ent) if (index < 0 || index >= MAX_ENGINE_PLAYERS) return -1; - if (m_bots[index] != NULL) + if (m_bots[index] != nullptr) return index; return -1; // if no edict, return -1; @@ -241,12 +241,12 @@ Bot *BotManager::GetBot (int index) // this function finds a bot specified by index, and then returns pointer to it (using own bot array) if (index < 0 || index >= MAX_ENGINE_PLAYERS) - return NULL; + return nullptr; - if (m_bots[index] != NULL) + if (m_bots[index] != nullptr) return m_bots[index]; - return NULL; // no bot + return nullptr; // no bot } Bot *BotManager::GetBot (edict_t *ent) @@ -267,14 +267,14 @@ Bot *BotManager::FindOneValidAliveBot (void) if (result.GetSize () > 4) break; - if (m_bots[i] != NULL && IsAlive (m_bots[i]->GetEntity ())) + if (m_bots[i] != nullptr && IsAlive (m_bots[i]->GetEntity ())) result.Push (i); } if (!result.IsEmpty ()) return m_bots[result.GetRandomElement ()]; - return NULL; + return nullptr; } void BotManager::Think (void) @@ -283,7 +283,7 @@ void BotManager::Think (void) for (int i = 0; i < engine.MaxClients (); i++) { - if (m_bots[i] != NULL) + if (m_bots[i] != nullptr) m_bots[i]->Think (); } } @@ -294,7 +294,7 @@ void BotManager::PeriodicThink (void) for (int i = 0; i < engine.MaxClients (); i++) { - if (m_bots[i] != NULL) + if (m_bots[i] != nullptr) m_bots[i]->PeriodicThink (); } } @@ -338,7 +338,7 @@ void BotManager::AdjustQuota (bool isPlayerConnection, edict_t *ent) { // this function increases or decreases bot quota amount depending on auto vacate variables - if (!engine.IsDedicatedServer () || !yb_autovacate.GetBool () || GetBot (ent) != NULL) + if (!engine.IsDedicatedServer () || !yb_autovacate.GetBool () || GetBot (ent) != nullptr) return; if (isPlayerConnection) @@ -454,11 +454,11 @@ void BotManager::MaintainBotQuota (void) char mode = yb_quota_mode.GetString ()[0]; if (mode == 'f') // fill - desiredCount = max (0, desiredCount - numHumans); + desiredCount = A_max (0, desiredCount - numHumans); else if (mode == 'm') // match - desiredCount = max (0, yb_quota.GetInt () * numHumans); + desiredCount = A_max (0, yb_quota.GetInt () * numHumans); - desiredCount = min (desiredCount, engine.MaxClients () - (numHumans + (yb_autovacate.GetBool () ? 1 : 0))); + desiredCount = A_min (desiredCount, engine.MaxClients () - (numHumans + (yb_autovacate.GetBool () ? 1 : 0))); if (yb_autovacate_smart_kick.GetBool () && numBots > 1 && desiredCount > 1) VerifyPlayersHasJoinedTeam (desiredCount); @@ -532,7 +532,7 @@ void BotManager::RemoveFromTeam (Team team, bool removeAll) for (int i = 0; i < engine.MaxClients (); i++) { - if (m_bots[i] != NULL && team == engine.GetTeam (m_bots[i]->GetEntity ())) + if (m_bots[i] != nullptr && team == engine.GetTeam (m_bots[i]->GetEntity ())) { m_bots[i]->Kick (); @@ -559,7 +559,7 @@ void BotManager::RemoveMenu (edict_t *ent, int selection) for (int i = ((selection - 1) * 8); i < selection * 8; i++) { - if ((m_bots[i] != NULL) && !engine.IsNullEntity (m_bots[i]->GetEntity ())) + if (m_bots[i] != nullptr && !engine.IsNullEntity (m_bots[i]->GetEntity ())) { validSlots |= 1 << (i - ((selection - 1) * 8)); sprintf (buffer, "%s %1.1d. %s%s\n", buffer, i - ((selection - 1) * 8) + 1, STRING (m_bots[i]->pev->netname), engine.GetTeam (m_bots[i]->GetEntity ()) == CT ? " \\y(CT)\\w" : " \\r(T)\\w"); @@ -608,7 +608,7 @@ void BotManager::KillAll (int team) for (int i = 0; i < engine.MaxClients (); i++) { - if (m_bots[i] != NULL) + if (m_bots[i] != nullptr) { if (team != -1 && team != m_bots[i]->m_team) continue; @@ -628,7 +628,7 @@ void BotManager::RemoveRandom (bool keepQuota) // first try to kick the bot that is currently dead for (int i = 0; i < engine.MaxClients (); i++) { - if (m_bots[i] != NULL && !m_bots[i]->m_notKilled) // is this slot used? + if (m_bots[i] != nullptr && !m_bots[i]->m_notKilled) // is this slot used? { m_bots[i]->Kick (keepQuota); deadBotFound = true; @@ -649,7 +649,7 @@ void BotManager::RemoveRandom (bool keepQuota) { Bot *bot = bots.GetBot (i); - if (bot != NULL && bot->pev->frags < score) + if (bot != nullptr && bot->pev->frags < score) { index = i; score = bot->pev->frags; @@ -666,7 +666,7 @@ void BotManager::RemoveRandom (bool keepQuota) // worst case, just kick some random bot for (int i = 0; i < engine.MaxClients (); i++) { - if (m_bots[i] != NULL) // is this slot used? + if (m_bots[i] != nullptr) // is this slot used? { m_bots[i]->Kick (keepQuota); break; @@ -737,7 +737,7 @@ void BotManager::ListBots (void) Bot *bot = GetBot (i); // is this player slot valid - if (bot != NULL) + if (bot != nullptr) engine.Printf ("[%-3.1d] %-9.13s %-17.18s %-3.4s %-3.1d %-3.1d", i, STRING (bot->pev->netname), bot->m_personality == PERSONALITY_RUSHER ? "rusher" : bot->m_personality == PERSONALITY_NORMAL ? "normal" : "careful", bot->m_team == CT ? "CT" : "T", bot->m_difficulty, static_cast (bot->pev->frags)); } } @@ -750,7 +750,7 @@ int BotManager::GetBotsNum (void) for (int i = 0; i < engine.MaxClients (); i++) { - if (m_bots[i] != NULL) + if (m_bots[i] != nullptr) count++; } return count; @@ -766,7 +766,7 @@ Bot *BotManager::GetHighestFragsBot (int team) { Bot *bot = bots.GetBot (i); - if (bot != NULL && bot->m_notKilled && bot->m_team == team) + if (bot != nullptr && bot->m_notKilled && bot->m_team == team) { if (bot->pev->frags > bestScore) { @@ -798,7 +798,7 @@ void BotManager::CheckTeamEconomics (int team, bool setTrue) // start calculating for (int i = 0; i < engine.MaxClients (); i++) { - if (m_bots[i] != NULL && engine.GetTeam (m_bots[i]->GetEntity ()) == team) + if (m_bots[i] != nullptr && engine.GetTeam (m_bots[i]->GetEntity ()) == team) { if (m_bots[i]->m_moneyAmount <= g_botBuyEconomyTable[0]) numPoorPlayers++; @@ -833,7 +833,7 @@ void BotManager::Free (int index) // this function frees one bot selected by index (used on bot disconnect) delete m_bots[index]; - m_bots[index] = NULL; + m_bots[index] = nullptr; } Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, const String &steamId) @@ -848,10 +848,10 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c pev = &bot->v; - if (bot->pvPrivateData != NULL) + if (bot->pvPrivateData != nullptr) FREE_PRIVATE (bot); - bot->pvPrivateData = NULL; + bot->pvPrivateData = nullptr; bot->v.frags = 0; // create the player entity by calling MOD's player function @@ -892,11 +892,11 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c m_startAction = GSM_IDLE; m_moneyAmount = 0; - m_logotypeIndex = Random.Long (0, 9); + m_logotypeIndex = Random.Int (0, 9); // assign how talkative this bot will be m_sayTextBuffer.chatDelay = Random.Float (3.8f, 10.0f); - m_sayTextBuffer.chatProbability = Random.Long (1, 100); + m_sayTextBuffer.chatProbability = Random.Int (1, 100); m_notKilled = false; m_weaponBurstMode = BM_OFF; @@ -904,7 +904,7 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c if (difficulty < 0 || difficulty > 4) { - difficulty = Random.Long (3, 4); + difficulty = Random.Int (3, 4); yb_difficulty.SetInt (difficulty); } @@ -937,7 +937,7 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c memset (&m_ammo, 0, sizeof (m_ammo)); m_currentWeapon = 0; // current weapon is not assigned at start - m_voicePitch = Random.Long (80, 115); // assign voice pitch + m_voicePitch = Random.Int (80, 115); // assign voice pitch // copy them over to the temp level variables m_agressionLevel = m_baseAgressionLevel; @@ -987,7 +987,7 @@ int BotManager::GetHumansNum (void) { const Client &client = g_clients[i]; - if ((client.flags & CF_USED) && m_bots[i] == NULL && !(client.ent->v.flags & FL_FAKECLIENT)) + if ((client.flags & CF_USED) && m_bots[i] == nullptr && !(client.ent->v.flags & FL_FAKECLIENT)) count++; } return count; @@ -1003,7 +1003,7 @@ int BotManager::GetHumansAliveNum (void) { const Client &client = g_clients[i]; - if ((client.flags & (CF_USED | CF_ALIVE)) && m_bots[i] == NULL && !(client.ent->v.flags & FL_FAKECLIENT)) + if ((client.flags & (CF_USED | CF_ALIVE)) && m_bots[i] == nullptr && !(client.ent->v.flags & FL_FAKECLIENT)) count++; } return count; @@ -1019,7 +1019,7 @@ int BotManager::GetHumansJoinedTeam (void) { const Client &client = g_clients[i]; - if ((client.flags & (CF_USED | CF_ALIVE)) && m_bots[i] == NULL && client.team != SPECTATOR && !(client.ent->v.flags & FL_FAKECLIENT) && client.ent->v.movetype != MOVETYPE_FLY) + if ((client.flags & (CF_USED | CF_ALIVE)) && m_bots[i] == nullptr && client.team != SPECTATOR && !(client.ent->v.flags & FL_FAKECLIENT) && client.ent->v.movetype != MOVETYPE_FLY) count++; } return count; @@ -1037,7 +1037,7 @@ void Bot::NewRound (void) m_waypointOrigin.Zero (); m_destOrigin.Zero (); m_currentWaypointIndex = -1; - m_currentPath = NULL; + m_currentPath = nullptr; m_currentTravelFlags = 0; m_goalFailed = 0; m_desiredVelocity.Zero (); @@ -1061,7 +1061,7 @@ void Bot::NewRound (void) switch (m_personality) { case PERSONALITY_NORMAL: - m_pathType = Random.Long (0, 100) > 50 ? SEARCH_PATH_SAFEST_FASTER : SEARCH_PATH_SAFEST; + m_pathType = Random.Int (0, 100) > 50 ? SEARCH_PATH_SAFEST_FASTER : SEARCH_PATH_SAFEST; break; case PERSONALITY_RUSHER: @@ -1097,23 +1097,23 @@ void Bot::NewRound (void) m_viewDistance = 4096.0f; m_maxViewDistance = 4096.0f; - m_liftEntity = NULL; - m_pickupItem = NULL; - m_itemIgnore = NULL; + m_liftEntity = nullptr; + m_pickupItem = nullptr; + m_itemIgnore = nullptr; m_itemCheckTime = 0.0f; - m_breakableEntity = NULL; + m_breakableEntity = nullptr; m_breakableOrigin.Zero (); m_timeDoorOpen = 0.0f; ResetCollideState (); ResetDoubleJumpState (); - m_enemy = NULL; - m_lastVictim = NULL; - m_lastEnemy = NULL; + m_enemy = nullptr; + m_lastVictim = nullptr; + m_lastEnemy = nullptr; m_lastEnemyOrigin.Zero (); - m_trackingEdict = NULL; + m_trackingEdict = nullptr; m_timeNextTracking = 0.0f; m_buttonPushTime = 0.0f; @@ -1124,7 +1124,7 @@ void Bot::NewRound (void) m_oldCombatDesire = 0.0f; m_liftUsageTime = 0.0f; - m_avoidGrenade = NULL; + m_avoidGrenade = nullptr; m_needAvoidGrenade = 0; m_lastDamageType = -1; @@ -1140,12 +1140,12 @@ void Bot::NewRound (void) SetIdealReactionTimes (true); - m_targetEntity = NULL; + m_targetEntity = nullptr; m_tasks.RemoveAll (); m_followWaitTime = 0.0f; for (i = 0; i < MAX_HOSTAGES; i++) - m_hostages[i] = NULL; + m_hostages[i] = nullptr; for (i = 0; i < Chatter_Total; i++) m_chatterTimes[i] = -1.0f; @@ -1202,7 +1202,7 @@ void Bot::NewRound (void) m_checkKnifeSwitch = true; m_buyingFinished = false; - m_radioEntity = NULL; + m_radioEntity = nullptr; m_radioOrder = 0; m_defendedBomb = false; m_defendHostage = false; @@ -1231,7 +1231,7 @@ void Bot::NewRound (void) PushMessageQueue (GSM_BUY_STUFF); PushTask (TASK_NORMAL, TASKPRI_NORMAL, -1, 0.0f, true); - if (Random.Long (0, 100) < 50) + if (Random.Int (0, 100) < 50) ChatterMessage (Chatter_NewRound); m_thinkInterval = (g_gameFlags & GAME_LEGACY) ? 0.0f : (1.0f / 30.0f) * Random.Float (0.95f, 1.05f); @@ -1262,13 +1262,13 @@ void Bot::StartGame (void) // this function handles the selection of teams & class #ifdef XASH_CSDM - m_wantedTeam = Random.Long (1, 2); + m_wantedTeam = Random.Int (1, 2); engine.IssueBotCommand (GetEntity (), "jointeam %d", m_wantedTeam); SET_CLIENT_KEYVALUE (GetIndex (), GET_INFOKEYBUFFER (GetEntity ()), "model", m_wantedTeam == 2 ? "Counter-Terrorists" : "Terrorists"); - if (Random.Long (0, 100) < 20) + if (Random.Int (0, 100) < 20) ChatMessage (CHAT_WELCOME); m_notStarted = false; @@ -1300,12 +1300,12 @@ void Bot::StartGame (void) if (g_gameFlags & GAME_CZERO) // czero has spetsnaz and militia skins { if (m_wantedClass < 1 || m_wantedClass > 5) - m_wantedClass = Random.Long (1, 5); // use random if invalid + m_wantedClass = Random.Int (1, 5); // use random if invalid } else { if (m_wantedClass < 1 || m_wantedClass > 4) - m_wantedClass = Random.Long (1, 4); // use random if invalid + m_wantedClass = Random.Int (1, 4); // use random if invalid } // select the class the bot wishes to use... @@ -1315,7 +1315,7 @@ void Bot::StartGame (void) m_notStarted = false; // check for greeting other players, since we connected - if (Random.Long (0, 100) < 20) + if (Random.Int (0, 100) < 20) ChatMessage (CHAT_WELCOME); } } @@ -1341,7 +1341,7 @@ void BotManager::CalculatePingOffsets (void) PLAYER_CNX_STATS (ent, &ping, &loss); if (ping < 0 || ping > 100) - ping = Random.Long (3, 15); + ping = Random.Int (3, 15); averagePing += ping; } @@ -1349,21 +1349,22 @@ void BotManager::CalculatePingOffsets (void) if (numHumans > 0) averagePing /= numHumans; else - averagePing = Random.Long (30, 40); + averagePing = Random.Int (30, 40); for (int i = 0; i < engine.MaxClients (); i++) { Bot *bot = GetBot (i); - if (bot == NULL) + if (bot == nullptr) continue; - int botPing = Random.Long (averagePing - averagePing * 0.2f, averagePing + averagePing * 0.2f) + Random.Long (bot->m_difficulty + 3, bot->m_difficulty + 6) + 10; + int part = static_cast (averagePing * 0.2f); + int botPing = Random.Int (averagePing - part, averagePing + part) + Random.Int (bot->m_difficulty + 3, bot->m_difficulty + 6) + 10; if (botPing <= 5) - botPing = Random.Long (10, 23); + botPing = Random.Int (10, 23); else if (botPing > 100) - botPing = Random.Long (30, 40); + botPing = Random.Int (30, 40); for (int j = 0; j < 2; j++) { @@ -1398,7 +1399,7 @@ void BotManager::SendPingDataOffsets (edict_t *to) { Bot *bot = m_bots[i]; - if (bot == NULL) + if (bot == nullptr) continue; switch (sending) @@ -1406,7 +1407,7 @@ void BotManager::SendPingDataOffsets (edict_t *to) case 0: { // start a new message - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, SVC_PINGS, NULL, to); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, SVC_PINGS, nullptr, to); WRITE_BYTE ((bot->m_pingOffset[sending] * 64) + (1 + 2 * i)); WRITE_SHORT (bot->m_ping[sending]); @@ -1457,7 +1458,7 @@ void BotManager::UpdateActiveGrenades (void) if (m_grenadeUpdateTime > engine.Time ()) return; - edict_t *grenade = NULL; + edict_t *grenade = nullptr; // clear previously stored grenades m_activeGrenades.RemoveAll (); @@ -1495,12 +1496,12 @@ void BotManager::SelectLeaderEachTeam (int team, bool reset) { auto bot = m_bots[i]; - if (bot != NULL && bot->m_isVIP) + if (bot != nullptr && bot->m_isVIP) { // vip bot is the leader bot->m_isLeader = true; - if (Random.Long (1, 100) < 50) + if (Random.Int (1, 100) < 50) { bot->RadioMessage (Radio_FollowMe); bot->m_campButtons = 0; @@ -1513,11 +1514,11 @@ void BotManager::SelectLeaderEachTeam (int team, bool reset) { auto bot = bots.GetHighestFragsBot (team); - if (bot != NULL && bot->m_notKilled) + if (bot != nullptr && bot->m_notKilled) { bot->m_isLeader = true; - if (Random.Long (1, 100) < 45) + if (Random.Int (1, 100) < 45) bot->RadioMessage (Radio_FollowMe); } m_leaderChoosen[TERRORIST] = true; @@ -1531,13 +1532,13 @@ void BotManager::SelectLeaderEachTeam (int team, bool reset) { auto bot = m_bots[i]; - if (bot != NULL && bot->m_hasC4) + if (bot != nullptr && bot->m_hasC4) { // bot carrying the bomb is the leader bot->m_isLeader = true; // terrorist carrying a bomb needs to have some company - if (Random.Long (1, 100) < 80) + if (Random.Int (1, 100) < 80) { if (yb_communication_type.GetInt () == 2) bot->ChatterMessage (Chatter_GoingToPlantBomb); @@ -1556,7 +1557,7 @@ void BotManager::SelectLeaderEachTeam (int team, bool reset) { bot->m_isLeader = true; - if (Random.Long (1, 100) < 30) + if (Random.Int (1, 100) < 30) bot->RadioMessage (Radio_FollowMe); } m_leaderChoosen[CT] = true; @@ -1568,7 +1569,7 @@ void BotManager::SelectLeaderEachTeam (int team, bool reset) { bot->m_isLeader = true; - if (Random.Long (1, 100) < 30) + if (Random.Int (1, 100) < 30) bot->RadioMessage (Radio_FollowMe); } } @@ -1578,7 +1579,7 @@ void BotManager::SelectLeaderEachTeam (int team, bool reset) { bot->m_isLeader = true; - if (Random.Long (1, 100) < (team == TERRORIST ? 30 : 40)) + if (Random.Int (1, 100) < (team == TERRORIST ? 30 : 40)) bot->RadioMessage (Radio_FollowMe); } } diff --git a/source/navigate.cpp b/source/navigate.cpp index 98606e8..de14f57 100644 --- a/source/navigate.cpp +++ b/source/navigate.cpp @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include @@ -16,7 +16,7 @@ int Bot::FindGoal (void) // chooses a destination (goal) waypoint for a bot if (!g_bombPlanted && m_team == TERRORIST && (g_mapType & MAP_DE)) { - edict_t *pent = NULL; + edict_t *pent = nullptr; while (!engine.IsNullEntity (pent = FIND_ENTITY_BY_STRING (pent, "classname", "weaponbox"))) { @@ -47,8 +47,8 @@ int Bot::FindGoal (void) float backoffDesire = 0.0f; float tacticChoice = 0.0f; - Array *offensiveWpts = NULL; - Array *defensiveWpts = NULL; + Array *offensiveWpts = nullptr; + Array *defensiveWpts = nullptr; switch (m_team) { @@ -217,7 +217,7 @@ int Bot::FinishFindGoal (int tactic, Array *defensive, Array *offsen m_currentWaypointIndex = ChangeWptIndex (waypoints.FindNearest (pev->origin)); if (goalChoices[0] == -1) - return m_chosenGoalIndex = Random.Long (0, g_numWaypoints - 1); + return m_chosenGoalIndex = Random.Int (0, g_numWaypoints - 1); bool isSorting = false; @@ -278,13 +278,13 @@ bool Bot::GoalIsValid (void) return false; else if (goal == m_currentWaypointIndex) // no nodes needed return true; - else if (m_navNode == NULL) // no path calculated + else if (m_navNode == nullptr) // no path calculated return false; // got path - check if still valid PathNode *node = m_navNode; - while (node->next != NULL) + while (node->next != nullptr) node = node->next; if (node->index == goal) @@ -320,7 +320,7 @@ void Bot::CheckCloseAvoidance (const Vector &dirNormal) if (m_seeEnemyTime + 1.5f < engine.Time ()) return; - edict_t *nearest = NULL; + edict_t *nearest = nullptr; float nearestDist = 99999.0f; int playerCount = 0; @@ -438,7 +438,7 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal) // collision check allowed if not flying through the air if (IsOnFloor () || IsOnLadder () || IsInWater ()) { - char state[MAX_COLLIDE_MOVES * 2 + 1]; + int state[MAX_COLLIDE_MOVES * 2 + 1]; int i = 0; // first 4 entries hold the possible collision states @@ -733,7 +733,7 @@ bool Bot::DoWaypointNav (void) if (m_liftState == LIFT_NO_NEARBY) { m_liftState = LIFT_LOOKING_BUTTON_OUTSIDE; - m_liftUsageTime = engine.Time () + 7.0; + m_liftUsageTime = engine.Time () + 7.0f; } liftClosedDoorExists = true; } @@ -742,7 +742,7 @@ bool Bot::DoWaypointNav (void) engine.TestLine (m_currentPath->origin, m_currentPath->origin + Vector (0.0f, 0.0f, -50.0f), TRACE_IGNORE_EVERYTHING, GetEntity (), &tr); // if trace result shows us that it is a lift - if (!engine.IsNullEntity (tr.pHit) && m_navNode != NULL && (strcmp (STRING (tr.pHit->v.classname), "func_door") == 0 || strcmp (STRING (tr.pHit->v.classname), "func_plat") == 0 || strcmp (STRING (tr.pHit->v.classname), "func_train") == 0) && !liftClosedDoorExists) + if (!engine.IsNullEntity (tr.pHit) && m_navNode != nullptr && (strcmp (STRING (tr.pHit->v.classname), "func_door") == 0 || strcmp (STRING (tr.pHit->v.classname), "func_plat") == 0 || strcmp (STRING (tr.pHit->v.classname), "func_train") == 0) && !liftClosedDoorExists) { if ((m_liftState == LIFT_NO_NEARBY || m_liftState == LIFT_WAITING_FOR || m_liftState == LIFT_LOOKING_BUTTON_OUTSIDE) && tr.pHit->v.velocity.z == 0.0f) { @@ -760,9 +760,9 @@ bool Bot::DoWaypointNav (void) m_liftUsageTime = engine.Time () + 7.0f; } } - else if (m_navNode != NULL) // no lift found at waypoint + else if (m_navNode != nullptr) // no lift found at waypoint { - if ((m_liftState == LIFT_NO_NEARBY || m_liftState == LIFT_WAITING_FOR) && m_navNode->next != NULL) + if ((m_liftState == LIFT_NO_NEARBY || m_liftState == LIFT_WAITING_FOR) && m_navNode->next != nullptr) { if (m_navNode->next->index >= 0 && m_navNode->next->index < g_numWaypoints && (waypoints.GetPath (m_navNode->next->index)->flags & FLAG_LIFT)) { @@ -800,7 +800,7 @@ bool Bot::DoWaypointNav (void) { Bot *bot = bots.GetBot (i); - if (bot == NULL || bot == this) + if (bot == nullptr || bot == this) continue; if (!bot->m_notKilled || bot->m_team != m_team || bot->m_targetEntity != GetEntity () || bot->GetTaskId () != TASK_FOLLOWUSER) @@ -839,7 +839,7 @@ bool Bot::DoWaypointNav (void) { Bot *bot = bots.GetBot (i); - if (bot == NULL) + if (bot == nullptr) continue; // skip invalid bots if (!bot->m_notKilled || bot->m_team != m_team || bot->m_targetEntity != GetEntity () || bot->GetTaskId () != TASK_FOLLOWUSER || bot->m_liftEntity != m_liftEntity) @@ -873,7 +873,7 @@ bool Bot::DoWaypointNav (void) if (!needWaitForTeammate || m_liftUsageTime < engine.Time ()) { m_liftState = LIFT_LOOKING_BUTTON_INSIDE; - m_liftUsageTime = engine.Time () + 10.0; + m_liftUsageTime = engine.Time () + 10.0f; } } @@ -1042,7 +1042,7 @@ bool Bot::DoWaypointNav (void) if ((waypoints.GetPath (m_prevWptIndex[0])->flags & FLAG_LIFT) && (m_currentPath->origin.z - pev->origin.z) > 50.0f && (waypoints.GetPath (m_prevWptIndex[0])->origin.z - pev->origin.z) > 50.0f) { m_liftState = LIFT_NO_NEARBY; - m_liftEntity = NULL; + m_liftEntity = nullptr; m_liftUsageTime = 0.0f; DeleteSearchNodes (); @@ -1069,13 +1069,13 @@ bool Bot::DoWaypointNav (void) m_liftState = LIFT_NO_NEARBY; m_liftUsageTime = 0.0f; - m_liftEntity = NULL; + m_liftEntity = nullptr; } } if (m_liftUsageTime < engine.Time () && m_liftUsageTime != 0.0f) { - m_liftEntity = NULL; + m_liftEntity = nullptr; m_liftState = LIFT_NO_NEARBY; m_liftUsageTime = 0.0f; @@ -1104,7 +1104,7 @@ bool Bot::DoWaypointNav (void) { IgnoreCollisionShortly (); // don't consider being stuck - if (Random.Long (1, 100) < 50) + if (Random.Int (1, 100) < 50) MDLL_Use (tr.pHit, GetEntity ()); // also 'use' the door randomly } @@ -1130,7 +1130,7 @@ bool Bot::DoWaypointNav (void) m_doorOpenAttempt++; m_timeDoorOpen = engine.Time () + 1.0f; // retry in 1 sec until door is open - edict_t *ent = NULL; + edict_t *ent = nullptr; if (m_doorOpenAttempt > 2 && !engine.IsNullEntity (ent = FIND_ENTITY_IN_SPHERE (ent, pev->origin, 512.0f))) { @@ -1193,15 +1193,16 @@ bool Bot::DoWaypointNav (void) // add goal values if (m_chosenGoalIndex != -1) { - int waypointValue; + int16 waypointValue; + int startIndex = m_chosenGoalIndex; int goalIndex = m_currentWaypointIndex; if (m_team == TERRORIST) { waypointValue = (g_experienceData + (startIndex * g_numWaypoints) + goalIndex)->team0Value; - waypointValue += static_cast (pev->health * 0.5f); - waypointValue += static_cast (m_goalValue * 0.5f); + waypointValue += static_cast (pev->health * 0.5f); + waypointValue += static_cast (m_goalValue * 0.5f); if (waypointValue < -MAX_GOAL_VALUE) waypointValue = -MAX_GOAL_VALUE; @@ -1213,8 +1214,8 @@ bool Bot::DoWaypointNav (void) else { waypointValue = (g_experienceData + (startIndex * g_numWaypoints) + goalIndex)->team1Value; - waypointValue += static_cast (pev->health * 0.5f); - waypointValue += static_cast (m_goalValue * 0.5f); + waypointValue += static_cast (pev->health * 0.5f); + waypointValue += static_cast (m_goalValue * 0.5f); if (waypointValue < -MAX_GOAL_VALUE) waypointValue = -MAX_GOAL_VALUE; @@ -1226,7 +1227,7 @@ bool Bot::DoWaypointNav (void) } return true; } - else if (m_navNode == NULL) + else if (m_navNode == nullptr) return false; int taskTarget = GetTask ()->data; @@ -1242,7 +1243,7 @@ bool Bot::DoWaypointNav (void) if (distance > 512.0) { - if (Random.Long (0, 100) < 50 && !waypoints.IsGoalVisited (taskTarget)) + if (Random.Int (0, 100) < 50 && !waypoints.IsGoalVisited (taskTarget)) RadioMessage (Radio_SectorClear); waypoints.SetGoalVisited (taskTarget); // doesn't hear so not a good goal @@ -1250,7 +1251,7 @@ bool Bot::DoWaypointNav (void) } else { - if (Random.Long (0, 100) < 50 && !waypoints.IsGoalVisited (taskTarget)) + if (Random.Int (0, 100) < 50 && !waypoints.IsGoalVisited (taskTarget)) RadioMessage (Radio_SectorClear); waypoints.SetGoalVisited (taskTarget); // doesn't hear so not a good goal @@ -1286,7 +1287,7 @@ void Bot::FindShortestPath (int srcIndex, int destIndex) PathNode *node = new PathNode; node->index = srcIndex; - node->next = NULL; + node->next = nullptr; m_navNodeStart = node; m_navNode = m_navNodeStart; @@ -1306,11 +1307,11 @@ void Bot::FindShortestPath (int srcIndex, int destIndex) node->next = new PathNode; node = node->next; - if (node == NULL) + if (node == nullptr) TerminateOnMalloc (); node->index = srcIndex; - node->next = NULL; + node->next = nullptr; } } @@ -1348,7 +1349,7 @@ public: inline ~PriorityQueue (void) { free (m_heap); - m_heap = NULL; + m_heap = nullptr; } // inserts a value into the priority queue @@ -1360,7 +1361,7 @@ public: return; } - if (m_heap == NULL) + if (m_heap == nullptr) return; if (m_size >= m_heapSize) @@ -1370,7 +1371,7 @@ public: Node *newHeap = static_cast (realloc (m_heap, sizeof (Node) * m_heapSize)); - if (newHeap != NULL) + if (newHeap != nullptr) m_heap = newHeap; } @@ -1381,7 +1382,7 @@ public: while (child) { - int parent = (child - 1) * 0.5f; + int parent = static_cast ((child - 1) * 0.5f); if (m_heap[parent].pri <= m_heap[child].pri) break; @@ -1435,7 +1436,7 @@ float gfunctionKillsDistT (int currentIndex, int parentIndex) if (parentIndex == -1) return 0.0f; - float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team0Damage + g_highestDamageT; + float cost = static_cast ((g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team0Damage + g_highestDamageT); Path *current = waypoints.GetPath (currentIndex); @@ -1461,7 +1462,7 @@ float gfunctionKillsDistCT (int currentIndex, int parentIndex) if (parentIndex == -1) return 0.0f; - float cost = (g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team1Damage + g_highestDamageCT; + float cost = static_cast ((g_experienceData + (currentIndex * g_numWaypoints) + currentIndex)->team1Damage + g_highestDamageCT); Path *current = waypoints.GetPath (currentIndex); @@ -1575,7 +1576,7 @@ float gfunctionPathDist (int currentIndex, int parentIndex) if (current->flags & (FLAG_CROUCH | FLAG_LADDER)) return parent->distances[i] * 1.5f; - return parent->distances[i]; + return static_cast (parent->distances[i]); } } return 65355.0f; @@ -1658,7 +1659,7 @@ void Bot::FindPath(int srcIndex, int destIndex, SearchPathType pathType /*= SEAR { float g; float f; - short parentIndex; + int parentIndex; AStarState state; } astar[MAX_WAYPOINTS]; @@ -1672,8 +1673,8 @@ void Bot::FindPath(int srcIndex, int destIndex, SearchPathType pathType /*= SEAR astar[i].state = NEW; } - float (*gcalc) (int, int) = NULL; - float (*hcalc) (int, int, int) = NULL; + float (*gcalc) (int, int) = nullptr; + float (*hcalc) (int, int, int) = nullptr; switch (pathType) { @@ -1750,7 +1751,7 @@ void Bot::FindPath(int srcIndex, int destIndex, SearchPathType pathType /*= SEAR if (currentIndex == destIndex) { // build the complete path - m_navNode = NULL; + m_navNode = nullptr; do { @@ -1805,18 +1806,18 @@ void Bot::FindPath(int srcIndex, int destIndex, SearchPathType pathType /*= SEAR void Bot::DeleteSearchNodes (void) { - PathNode *deletingNode = NULL; + PathNode *deletingNode = nullptr; PathNode *node = m_navNodeStart; - while (node != NULL) + while (node != nullptr) { deletingNode = node->next; delete node; node = deletingNode; } - m_navNodeStart = NULL; - m_navNode = NULL; + m_navNodeStart = nullptr; + m_navNode = nullptr; m_chosenGoalIndex = -1; } @@ -1899,13 +1900,13 @@ bool Bot::FindWaypoint (void) // now pick random one from choosen if (waypointIndeces[2] != -1) - i = Random.Long (0, 2); + i = Random.Int (0, 2); else if (waypointIndeces[1] != -1) - i = Random.Long (0, 1); + i = Random.Int (0, 1); else if (waypointIndeces[0] != -1) - i = Random.Long (0, 0); + i = Random.Int (0, 0); else if (coveredWaypoint != -1) { @@ -1941,7 +1942,7 @@ bool Bot::FindWaypoint (void) waypointIndeces[i] = random; } else - waypointIndeces[i] = Random.Long (0, g_numWaypoints - 1); + waypointIndeces[i] = Random.Int (0, g_numWaypoints - 1); } m_collideTime = engine.Time (); @@ -1974,7 +1975,7 @@ void Bot::GetValidWaypoint (void) if (value > MAX_DAMAGE_VALUE) value = MAX_DAMAGE_VALUE; - (g_experienceData + (m_currentWaypointIndex * g_numWaypoints) + m_currentWaypointIndex)->team0Damage = static_cast (value); + (g_experienceData + (m_currentWaypointIndex * g_numWaypoints) + m_currentWaypointIndex)->team0Damage = static_cast (value); // affect nearby connected with victim waypoints for (int i = 0; i < MAX_PATH_INDEX; i++) @@ -1987,7 +1988,7 @@ void Bot::GetValidWaypoint (void) if (value > MAX_DAMAGE_VALUE) value = MAX_DAMAGE_VALUE; - (g_experienceData + (m_currentPath->index[i] * g_numWaypoints) + m_currentPath->index[i])->team0Damage = static_cast (value); + (g_experienceData + (m_currentPath->index[i] * g_numWaypoints) + m_currentPath->index[i])->team0Damage = static_cast (value); } } } @@ -1999,7 +2000,7 @@ void Bot::GetValidWaypoint (void) if (value > MAX_DAMAGE_VALUE) value = MAX_DAMAGE_VALUE; - (g_experienceData + (m_currentWaypointIndex * g_numWaypoints) + m_currentWaypointIndex)->team1Damage = static_cast (value); + (g_experienceData + (m_currentWaypointIndex * g_numWaypoints) + m_currentWaypointIndex)->team1Damage = static_cast (value); // affect nearby connected with victim waypoints for (int i = 0; i < MAX_PATH_INDEX; i++) @@ -2012,7 +2013,7 @@ void Bot::GetValidWaypoint (void) if (value > MAX_DAMAGE_VALUE) value = MAX_DAMAGE_VALUE; - (g_experienceData + (m_currentPath->index[i] * g_numWaypoints) + m_currentPath->index[i])->team1Damage = static_cast (value); + (g_experienceData + (m_currentPath->index[i] * g_numWaypoints) + m_currentPath->index[i])->team1Damage = static_cast (value); } } } @@ -2070,7 +2071,7 @@ int Bot::ChooseBombWaypoint (void) Array goals = waypoints.m_goalPoints; if (goals.IsEmpty ()) - return Random.Long (0, g_numWaypoints - 1); // reliability check + return Random.Int (0, g_numWaypoints - 1); // reliability check Vector bombOrigin = CheckBombAudible (); @@ -2125,7 +2126,7 @@ int Bot::FindDefendWaypoint (const Vector &origin) // some of points not found, return random one if (srcIndex == -1 || posIndex == -1) - return Random.Long (0, g_numWaypoints - 1); + return Random.Int (0, g_numWaypoints - 1); for (int i = 0; i < g_numWaypoints; i++) // find the best waypoint now { @@ -2212,7 +2213,7 @@ int Bot::FindDefendWaypoint (const Vector &origin) } if (found.IsEmpty ()) - return Random.Long (0, g_numWaypoints - 1); // most worst case, since there a evil error in waypoints + return Random.Int (0, g_numWaypoints - 1); // most worst case, since there a evil error in waypoints return found.GetRandomElement (); } @@ -2224,7 +2225,7 @@ int Bot::FindDefendWaypoint (const Vector &origin) if (waypointIndex[index] == -1) break; } - return waypointIndex[Random.Long (0, (index - 1) * 0.5f)]; + return waypointIndex[Random.Int (0, static_cast ((index - 1) * 0.5f))]; } int Bot::FindCoverWaypoint (float maxDistance) @@ -2371,8 +2372,8 @@ bool Bot::GetBestNextWaypoint (void) // this function does a realtime post processing of waypoints return from the // pathfinder, to vary paths and find the best waypoint on our way - InternalAssert (m_navNode != NULL); - InternalAssert (m_navNode->next != NULL); + InternalAssert (m_navNode != nullptr); + InternalAssert (m_navNode->next != nullptr); if (!IsPointOccupied (m_navNode->index)) return false; @@ -2403,7 +2404,7 @@ bool Bot::HeadTowardWaypoint (void) GetValidWaypoint (); // check if old waypoints is still reliable // no waypoints from pathfinding? - if (m_navNode == NULL) + if (m_navNode == nullptr) return false; TraceResult tr; @@ -2412,10 +2413,10 @@ bool Bot::HeadTowardWaypoint (void) m_currentTravelFlags = 0; // reset travel flags (jumping etc) // we're not at the end of the list? - if (m_navNode != NULL) + if (m_navNode != nullptr) { // if in between a route, postprocess the waypoint (find better alternatives)... - if (m_navNode != m_navNodeStart && m_navNode->next != NULL) + if (m_navNode != m_navNodeStart && m_navNode->next != nullptr) { GetBestNextWaypoint (); m_minSpeed = pev->maxspeed; @@ -2449,7 +2450,7 @@ bool Bot::HeadTowardWaypoint (void) if (m_baseAgressionLevel < kills && HasPrimaryWeapon ()) { - PushTask (TASK_CAMP, TASKPRI_CAMP, -1, engine.Time () + Random.Float (m_difficulty * 0.5f, m_difficulty) * 5.0f, true); + PushTask (TASK_CAMP, TASKPRI_CAMP, -1, engine.Time () + Random.Float (m_difficulty * 0.5f, static_cast (m_difficulty)) * 5.0f, true); PushTask (TASK_MOVETOPOSITION, TASKPRI_MOVETOPOSITION, FindDefendWaypoint (waypoints.GetPath (nextIndex)->origin), engine.Time () + Random.Float (3.0f, 10.0f), true); } } @@ -2457,13 +2458,13 @@ bool Bot::HeadTowardWaypoint (void) { if (static_cast (kills) == m_baseAgressionLevel) m_campButtons |= IN_DUCK; - else if (Random.Long (1, 100) > m_difficulty * 25) + else if (Random.Int (1, 100) > m_difficulty * 25) m_minSpeed = GetWalkSpeed (); } } } - if (m_navNode != NULL) + if (m_navNode != nullptr) { int destIndex = m_navNode->index; @@ -2490,7 +2491,7 @@ bool Bot::HeadTowardWaypoint (void) Vector dst; // try to find out about future connection flags - if (m_navNode->next != NULL) + if (m_navNode->next != nullptr) { for (int i = 0; i < MAX_PATH_INDEX; i++) { @@ -2523,7 +2524,7 @@ bool Bot::HeadTowardWaypoint (void) Bot *otherBot = bots.GetBot (c); // if another bot uses this ladder, wait 3 secs - if (otherBot != NULL && otherBot != this && IsAlive (otherBot->GetEntity ()) && otherBot->m_currentWaypointIndex == m_navNode->index) + if (otherBot != nullptr && otherBot != this && IsAlive (otherBot->GetEntity ()) && otherBot->m_currentWaypointIndex == m_navNode->index) { PushTask (TASK_PAUSE, TASKPRI_PAUSE, -1, engine.Time () + 3.0f, false); return true; @@ -3099,7 +3100,7 @@ int Bot::GetAimingWaypoint (void) int currentWaypoint = m_currentWaypointIndex; if (currentWaypoint == -1) - return Random.Long (0, g_numWaypoints - 1); + return Random.Int (0, g_numWaypoints - 1); for (int i = 0; i < g_numWaypoints; i++) { @@ -3139,9 +3140,9 @@ int Bot::GetAimingWaypoint (void) count--; if (count >= 0) - return indices[Random.Long (0, count)]; + return indices[Random.Int (0, count)]; - return Random.Long (0, g_numWaypoints - 1); + return Random.Int (0, g_numWaypoints - 1); } void Bot::UpdateBodyAngles (void) @@ -3330,7 +3331,7 @@ int Bot::FindPlantedBomb (void) if (m_team != TERRORIST || !(g_mapType & MAP_DE)) return -1; // don't search for bomb if the player is CT, or it's not defusing bomb - edict_t *bombEntity = NULL; // temporaly pointer to bomb + edict_t *bombEntity = nullptr; // temporaly pointer to bomb // search the bomb on the map while (!engine.IsNullEntity (bombEntity = FIND_ENTITY_BY_CLASSNAME (bombEntity, "grenade"))) @@ -3358,7 +3359,7 @@ bool Bot::IsPointOccupied (int index) { Bot *bot = bots.GetBot (i); - if (bot == NULL || bot == this) + if (bot == nullptr || bot == this) continue; // check if this waypoint is already used @@ -3384,10 +3385,10 @@ edict_t *Bot::FindNearestButton (const char *targetName) // it's entity, also here must be specified the target, that button must open. if (IsNullString (targetName)) - return NULL; + return nullptr; float nearestDistance = 99999.0f; - edict_t *searchEntity = NULL, *foundEntity = NULL; + edict_t *searchEntity = nullptr, *foundEntity = nullptr; // find the nearest button which can open our target while (!engine.IsNullEntity(searchEntity = FIND_ENTITY_BY_TARGET (searchEntity, targetName))) diff --git a/source/support.cpp b/source/support.cpp index bc305aa..6498e63 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -4,15 +4,15 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include ConVar yb_display_menu_text ("yb_display_menu_text", "1"); -ConVar mp_roundtime ("mp_roundtime", NULL, VT_NOREGISTER); -ConVar mp_freezetime ("mp_freezetime", NULL, VT_NOREGISTER, true); +ConVar mp_roundtime ("mp_roundtime", nullptr, VT_NOREGISTER); +ConVar mp_freezetime ("mp_freezetime", nullptr, VT_NOREGISTER, true); uint16 FixedUnsigned16 (float value, float scale) { @@ -45,7 +45,7 @@ const char *FormatBuffer (const char *format, ...) static char strBuffer[2][MAX_PRINT_BUFFER]; static int rotator = 0; - if (format == NULL) + if (format == nullptr) return strBuffer[rotator]; static char *ptr = strBuffer[rotator ^= 1]; @@ -106,7 +106,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu) int clientIndex = engine.IndexOfEntity (ent) - 1; - if (menu != NULL) + if (menu != nullptr) { String tempText = String (menu->menuText); tempText.Replace ("\v", "\n"); @@ -125,7 +125,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu) while (strlen (text) >= 64) { - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), NULL, ent); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), nullptr, ent); WRITE_SHORT (menu->validSlots); WRITE_CHAR (-1); WRITE_BYTE (1); @@ -138,7 +138,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu) text += 64; } - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), NULL, ent); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), nullptr, ent); WRITE_SHORT (menu->validSlots); WRITE_CHAR (-1); WRITE_BYTE (0); @@ -149,14 +149,14 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu) } else { - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), NULL, ent); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), nullptr, ent); WRITE_SHORT (0); WRITE_CHAR (0); WRITE_BYTE (0); WRITE_STRING (""); MESSAGE_END(); - g_clients[clientIndex].menu = NULL; + g_clients[clientIndex].menu = nullptr; } CLIENT_COMMAND (ent, "speak \"player/geiger1\"\n"); // Stops others from hearing menu sounds.. } @@ -242,7 +242,7 @@ void FreeLibraryMemory (void) waypoints.Init (); // frees waypoint data delete [] g_experienceData; - g_experienceData = NULL; + g_experienceData = nullptr; } void UpdateGlobalExperienceData (void) @@ -253,8 +253,8 @@ void UpdateGlobalExperienceData (void) if (g_numWaypoints < 1 || waypoints.HasChanged ()) return; // no action - unsigned short maxDamage; // maximum damage - unsigned short actDamage; // actual damage + uint16 maxDamage; // maximum damage + uint16 actDamage; // actual damage int bestIndex; // best index to store bool recalcKills = false; @@ -327,7 +327,7 @@ void UpdateGlobalExperienceData (void) if (clip < 0) clip = 0; - (g_experienceData + (i * g_numWaypoints) + j)->team0Damage = static_cast (clip); + (g_experienceData + (i * g_numWaypoints) + j)->team0Damage = static_cast (clip); clip = (g_experienceData + (i * g_numWaypoints) + j)->team1Damage; clip -= static_cast (MAX_DAMAGE_VALUE * 0.5); @@ -335,7 +335,7 @@ void UpdateGlobalExperienceData (void) if (clip < 0) clip = 0; - (g_experienceData + (i * g_numWaypoints) + j)->team1Damage = static_cast (clip); + (g_experienceData + (i * g_numWaypoints) + j)->team1Damage = static_cast (clip); } } } @@ -359,8 +359,8 @@ void UpdateGlobalExperienceData (void) { for (int i = 0; i < g_numWaypoints; i++) { - (g_experienceData + (i * g_numWaypoints) + i)->team0Damage /= static_cast (engine.MaxClients () * 0.5); - (g_experienceData + (i * g_numWaypoints) + i)->team1Damage /= static_cast (engine.MaxClients () * 0.5); + (g_experienceData + (i * g_numWaypoints) + i)->team0Damage /= static_cast (engine.MaxClients () * 0.5); + (g_experienceData + (i * g_numWaypoints) + i)->team1Damage /= static_cast (engine.MaxClients () * 0.5); } g_highestKills = 1; } @@ -433,7 +433,7 @@ bool IsValidPlayer (edict_t *ent) if (ent->v.flags & FL_PROXY) return false; - if ((ent->v.flags & (FL_CLIENT | FL_FAKECLIENT)) || bots.GetBot (ent) != NULL) + if ((ent->v.flags & (FL_CLIENT | FL_FAKECLIENT)) || bots.GetBot (ent) != nullptr) return !IsNullString (STRING (ent->v.netname)); return false; @@ -452,7 +452,7 @@ bool IsPlayerVIP (edict_t *ent) bool IsValidBot (edict_t *ent) { - if (bots.GetBot (ent) != NULL || (!engine.IsNullEntity (ent) && (ent->v.flags & FL_FAKECLIENT))) + if (bots.GetBot (ent) != nullptr || (!engine.IsNullEntity (ent) && (ent->v.flags & FL_FAKECLIENT))) return true; return false; @@ -477,10 +477,10 @@ bool OpenConfig (const char *fileName, const char *errorIfNotExists, MemoryFile // check file existence int size = 0; - unsigned char *buffer = NULL; + uint8 *buffer = nullptr; // check is file is exists for this language - if ((buffer = MemoryFile::Loader (langConfig, &size)) != NULL) + if ((buffer = MemoryFile::Loader (langConfig, &size)) != nullptr) { MemoryFile::Unloader (buffer); @@ -544,19 +544,19 @@ void CheckWelcomeMessage (void) engine.ChatPrintf ("----- %s v%s (Build: %u), {%s}, (c) 2016, by %s (%s)-----", PRODUCT_NAME, PRODUCT_VERSION, GenerateBuildNumber (), PRODUCT_DATE, PRODUCT_AUTHOR, PRODUCT_URL); - MESSAGE_BEGIN (MSG_ONE, SVC_TEMPENTITY, NULL, g_hostEntity); + MESSAGE_BEGIN (MSG_ONE, SVC_TEMPENTITY, nullptr, g_hostEntity); WRITE_BYTE (TE_TEXTMESSAGE); WRITE_BYTE (1); WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); WRITE_SHORT (FixedSigned16 (-1, 1 << 13)); WRITE_BYTE (2); - WRITE_BYTE (Random.Long (33, 255)); - WRITE_BYTE (Random.Long (33, 255)); - WRITE_BYTE (Random.Long (33, 255)); + WRITE_BYTE (Random.Int (33, 255)); + WRITE_BYTE (Random.Int (33, 255)); + WRITE_BYTE (Random.Int (33, 255)); WRITE_BYTE (0); - WRITE_BYTE (Random.Long (230, 255)); - WRITE_BYTE (Random.Long (230, 255)); - WRITE_BYTE (Random.Long (230, 255)); + WRITE_BYTE (Random.Int (230, 255)); + WRITE_BYTE (Random.Int (230, 255)); + WRITE_BYTE (Random.Int (230, 255)); WRITE_BYTE (200); WRITE_SHORT (FixedUnsigned16 (0.0078125f, 1 << 8)); WRITE_SHORT (FixedUnsigned16 (2.0f, 1 << 8)); @@ -660,7 +660,7 @@ bool FindNearestPlayer (void **pvHolder, edict_t *to, float searchDistance, bool // team, live status, search distance etc. if needBot is true, then pvHolder, will // be filled with bot pointer, else with edict pointer(!). - edict_t *survive = NULL; // pointer to temporally & survive entity + edict_t *survive = nullptr; // pointer to temporally & survive entity float nearestPlayer = 4096.0f; // nearest player int toTeam = engine.GetTeam (to); @@ -874,7 +874,7 @@ int GenerateBuildNumber (void) const char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; // array of the month days - byte monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + uint8 monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int day = 0; // day of the year int year = 0; // year diff --git a/source/waypoint.cpp b/source/waypoint.cpp index 7166d3a..8fd6523 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -4,7 +4,7 @@ // // This software is licensed under the BSD-style license. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: -// http://yapb.jeefo.net/license +// https://yapb.jeefo.net/license // #include @@ -32,10 +32,10 @@ void Waypoint::Init (void) void Waypoint::CleanupPathMemory (void) { - for (int i = 0; i < g_numWaypoints && m_paths[i] != NULL; i++) + for (int i = 0; i < g_numWaypoints && m_paths[i] != nullptr; i++) { delete m_paths[i]; - m_paths[i] = NULL; + m_paths[i] = nullptr; } } @@ -57,11 +57,11 @@ void Waypoint::AddPath (int addIndex, int pathIndex, float distance) } // check for free space in the connection indices - for (int i = 0; i < MAX_PATH_INDEX; i++) + for (int16 i = 0; i < MAX_PATH_INDEX; i++) { if (path->index[i] == -1) { - path->index[i] = pathIndex; + path->index[i] = static_cast (pathIndex); path->distances[i] = abs (static_cast (distance)); AddLogEntry (true, LL_DEFAULT, "Path added from %d to %d", addIndex, pathIndex); @@ -86,7 +86,7 @@ void Waypoint::AddPath (int addIndex, int pathIndex, float distance) { AddLogEntry (true, LL_DEFAULT, "Path added from %d to %d", addIndex, pathIndex); - path->index[slotID] = pathIndex; + path->index[slotID] = static_cast (pathIndex); path->distances[slotID] = abs (static_cast (distance)); } } @@ -155,7 +155,7 @@ void Waypoint::Add (int flags, const Vector &waypointOrigin) float distance; Vector forward; - Path *path = NULL; + Path *path = nullptr; bool placeNew = true; Vector newOrigin = waypointOrigin; @@ -217,7 +217,7 @@ void Waypoint::Add (int flags, const Vector &waypointOrigin) case 10: index = FindNearest (g_hostEntity->v.origin, 50.0f); - if (index != -1 && m_paths[index] != NULL) + if (index != -1 && m_paths[index] != nullptr) { distance = (m_paths[index]->origin - g_hostEntity->v.origin).GetLength (); @@ -247,7 +247,7 @@ void Waypoint::Add (int flags, const Vector &waypointOrigin) m_paths[index] = new Path; - if (m_paths[index] == NULL) + if (m_paths[index] == nullptr) TerminateOnMalloc (); path = m_paths[index]; @@ -456,8 +456,8 @@ void Waypoint::Delete (void) if (index < 0) return; - Path *path = NULL; - InternalAssert (m_paths[index] != NULL); + Path *path = nullptr; + InternalAssert (m_paths[index] != nullptr); int i, j; @@ -493,7 +493,7 @@ void Waypoint::Delete (void) // free deleted node delete m_paths[index]; - m_paths[index] = NULL; + m_paths[index] = nullptr; // rotate path array down for (i = index; i < g_numWaypoints - 1; i++) @@ -742,7 +742,7 @@ void Waypoint::CalculateWayzone (int index) } } - for (int scanDistance = 16; scanDistance < 128; scanDistance += 16) + for (float scanDistance = 16.0f; scanDistance < 128.0f; scanDistance += 16.0f) { start = path->origin; MakeVectors (Vector::GetZero ()); @@ -759,11 +759,11 @@ void Waypoint::CalculateWayzone (int index) Vector radiusStart = start - g_pGlobals->v_forward * scanDistance; Vector radiusEnd = start + g_pGlobals->v_forward * scanDistance; - engine.TestHull (radiusStart, radiusEnd, TRACE_IGNORE_MONSTERS, head_hull, NULL, &tr); + engine.TestHull (radiusStart, radiusEnd, TRACE_IGNORE_MONSTERS, head_hull, nullptr, &tr); if (tr.flFraction < 1.0f) { - engine.TestLine (radiusStart, radiusEnd, TRACE_IGNORE_MONSTERS, NULL, &tr); + engine.TestLine (radiusStart, radiusEnd, TRACE_IGNORE_MONSTERS, nullptr, &tr); if (FClassnameIs (tr.pHit, "func_door") || FClassnameIs (tr.pHit, "func_door_rotating")) { @@ -782,7 +782,7 @@ void Waypoint::CalculateWayzone (int index) Vector dropStart = start + g_pGlobals->v_forward * scanDistance; Vector dropEnd = dropStart - Vector (0.0f, 0.0f, scanDistance + 60.0f); - engine.TestHull (dropStart, dropEnd, TRACE_IGNORE_MONSTERS, head_hull, NULL, &tr); + engine.TestHull (dropStart, dropEnd, TRACE_IGNORE_MONSTERS, head_hull, nullptr, &tr); if (tr.flFraction >= 1.0f) { @@ -794,7 +794,7 @@ void Waypoint::CalculateWayzone (int index) dropStart = start - g_pGlobals->v_forward * scanDistance; dropEnd = dropStart - Vector (0.0f, 0.0f, scanDistance + 60.0f); - engine.TestHull (dropStart, dropEnd, TRACE_IGNORE_MONSTERS, head_hull, NULL, &tr); + engine.TestHull (dropStart, dropEnd, TRACE_IGNORE_MONSTERS, head_hull, nullptr, &tr); if (tr.flFraction >= 1.0f) { @@ -804,7 +804,7 @@ void Waypoint::CalculateWayzone (int index) } radiusEnd.z += 34.0f; - engine.TestHull (radiusStart, radiusEnd, TRACE_IGNORE_MONSTERS, head_hull, NULL, &tr); + engine.TestHull (radiusStart, radiusEnd, TRACE_IGNORE_MONSTERS, head_hull, nullptr, &tr); if (tr.flFraction < 1.0f) { @@ -843,14 +843,14 @@ void Waypoint::SaveExperienceTab (void) { for (int j = 0; j < g_numWaypoints; j++) { - (experienceSave + (i * g_numWaypoints) + j)->team0Damage = (g_experienceData + (i * g_numWaypoints) + j)->team0Damage >> 3; - (experienceSave + (i * g_numWaypoints) + j)->team1Damage = (g_experienceData + (i * g_numWaypoints) + j)->team1Damage >> 3; - (experienceSave + (i * g_numWaypoints) + j)->team0Value = (g_experienceData + (i * g_numWaypoints) + j)->team0Value / 8; - (experienceSave + (i * g_numWaypoints) + j)->team1Value = (g_experienceData + (i * g_numWaypoints) + j)->team1Value / 8; + (experienceSave + (i * g_numWaypoints) + j)->team0Damage = static_cast ((g_experienceData + (i * g_numWaypoints) + j)->team0Damage >> 3); + (experienceSave + (i * g_numWaypoints) + j)->team1Damage = static_cast ((g_experienceData + (i * g_numWaypoints) + j)->team1Damage >> 3); + (experienceSave + (i * g_numWaypoints) + j)->team0Value = static_cast ((g_experienceData + (i * g_numWaypoints) + j)->team0Value / 8); + (experienceSave + (i * g_numWaypoints) + j)->team1Value = static_cast ((g_experienceData + (i * g_numWaypoints) + j)->team1Value / 8); } } - int result = Compressor::Compress (FormatBuffer ("%slearned/%s.exp", GetDataDir (), engine.GetMapName ()), (unsigned char *)&header, sizeof (ExtensionHeader), (unsigned char *)experienceSave, g_numWaypoints * g_numWaypoints * sizeof (ExperienceSave)); + int result = Compressor::Compress (FormatBuffer ("%slearned/%s.exp", GetDataDir (), engine.GetMapName ()), (uint8 *)&header, sizeof (ExtensionHeader), (uint8 *)experienceSave, g_numWaypoints * g_numWaypoints * sizeof (ExperienceSave)); delete [] experienceSave; @@ -866,7 +866,7 @@ void Waypoint::InitExperienceTab (void) int i, j; delete [] g_experienceData; - g_experienceData = NULL; + g_experienceData = nullptr; if (g_numWaypoints < 1) return; @@ -912,7 +912,7 @@ void Waypoint::InitExperienceTab (void) { ExperienceSave *experienceLoad = new ExperienceSave[g_numWaypoints * g_numWaypoints * sizeof (ExperienceSave)]; - Compressor::Uncompress (FormatBuffer ("%slearned/%s.exp", GetDataDir (), engine.GetMapName ()), sizeof (ExtensionHeader), (unsigned char *)experienceLoad, g_numWaypoints * g_numWaypoints * sizeof (ExperienceSave)); + Compressor::Uncompress (FormatBuffer ("%slearned/%s.exp", GetDataDir (), engine.GetMapName ()), sizeof (ExtensionHeader), (uint8 *)experienceLoad, g_numWaypoints * g_numWaypoints * sizeof (ExperienceSave)); for (i = 0; i < g_numWaypoints; i++) { @@ -920,8 +920,8 @@ void Waypoint::InitExperienceTab (void) { if (i == j) { - (g_experienceData + (i * g_numWaypoints) + j)->team0Damage = (unsigned short) ((experienceLoad + (i * g_numWaypoints) + j)->team0Damage); - (g_experienceData + (i * g_numWaypoints) + j)->team1Damage = (unsigned short) ((experienceLoad + (i * g_numWaypoints) + j)->team1Damage); + (g_experienceData + (i * g_numWaypoints) + j)->team0Damage = (uint16) ((experienceLoad + (i * g_numWaypoints) + j)->team0Damage); + (g_experienceData + (i * g_numWaypoints) + j)->team1Damage = (uint16) ((experienceLoad + (i * g_numWaypoints) + j)->team1Damage); if ((g_experienceData + (i * g_numWaypoints) + j)->team0Damage > g_highestDamageT) g_highestDamageT = (g_experienceData + (i * g_numWaypoints) + j)->team0Damage; @@ -931,12 +931,12 @@ void Waypoint::InitExperienceTab (void) } else { - (g_experienceData + (i * g_numWaypoints) + j)->team0Damage = (unsigned short) ((experienceLoad + (i * g_numWaypoints) + j)->team0Damage) << 3; - (g_experienceData + (i * g_numWaypoints) + j)->team1Damage = (unsigned short) ((experienceLoad + (i * g_numWaypoints) + j)->team1Damage) << 3; + (g_experienceData + (i * g_numWaypoints) + j)->team0Damage = (uint16) ((experienceLoad + (i * g_numWaypoints) + j)->team0Damage) << 3; + (g_experienceData + (i * g_numWaypoints) + j)->team1Damage = (uint16) ((experienceLoad + (i * g_numWaypoints) + j)->team1Damage) << 3; } - (g_experienceData + (i * g_numWaypoints) + j)->team0Value = (signed short) ((experienceLoad + i * (g_numWaypoints) + j)->team0Value) * 8; - (g_experienceData + (i * g_numWaypoints) + j)->team1Value = (signed short) ((experienceLoad + i * (g_numWaypoints) + j)->team1Value) * 8; + (g_experienceData + (i * g_numWaypoints) + j)->team0Value = (int16) ((experienceLoad + i * (g_numWaypoints) + j)->team0Value) * 8; + (g_experienceData + (i * g_numWaypoints) + j)->team1Value = (int16) ((experienceLoad + i * (g_numWaypoints) + j)->team1Value) * 8; } } delete [] experienceLoad; @@ -971,7 +971,7 @@ void Waypoint::SaveVisibilityTab (void) } fp.Close (); - Compressor::Compress (FormatBuffer ("%slearned/%s.vis", GetDataDir (), engine.GetMapName ()), (unsigned char *) &header, sizeof (ExtensionHeader), (unsigned char *) m_visLUT, MAX_WAYPOINTS * (MAX_WAYPOINTS / 4) * sizeof (unsigned char)); + Compressor::Compress (FormatBuffer ("%slearned/%s.vis", GetDataDir (), engine.GetMapName ()), (uint8 *) &header, sizeof (ExtensionHeader), (uint8 *) m_visLUT, MAX_WAYPOINTS * (MAX_WAYPOINTS / 4) * sizeof (uint8)); } void Waypoint::InitVisibilityTab (void) @@ -1012,7 +1012,7 @@ void Waypoint::InitVisibilityTab (void) return; } - int result = Compressor::Uncompress (FormatBuffer ("%slearned/%s.vis", GetDataDir (), engine.GetMapName ()), sizeof (ExtensionHeader), (unsigned char *) m_visLUT, MAX_WAYPOINTS * (MAX_WAYPOINTS / 4) * sizeof (unsigned char)); + int result = Compressor::Uncompress (FormatBuffer ("%slearned/%s.vis", GetDataDir (), engine.GetMapName ()), sizeof (ExtensionHeader), (uint8 *) m_visLUT, MAX_WAYPOINTS * (MAX_WAYPOINTS / 4) * sizeof (uint8)); if (result == -1) { @@ -1118,7 +1118,7 @@ bool Waypoint::Load (void) { m_paths[i] = new Path; - if (m_paths[i] == NULL) + if (m_paths[i] == nullptr) TerminateOnMalloc (); if (fp.Read (m_paths[i], sizeof (Path)) == 0) @@ -1285,7 +1285,7 @@ bool Waypoint::Reachable (Bot *bot, int index) { // this function return wether bot able to reach index waypoint or not, depending on several factors. - if (bot == NULL || index < 0 || index >= g_numWaypoints) + if (bot == nullptr || index < 0 || index >= g_numWaypoints) return false; Vector src = bot->pev->origin; @@ -1407,7 +1407,7 @@ void Waypoint::InitializeVisibility (void) return; TraceResult tr; - byte res, shift; + uint8 res, shift; for (m_visibilityIndex = 0; m_visibilityIndex < g_numWaypoints; m_visibilityIndex++) { @@ -1431,7 +1431,7 @@ void Waypoint::InitializeVisibility (void) // first check ducked visibility Vector dest = m_paths[i]->origin; - engine.TestLine (sourceDuck, dest, TRACE_IGNORE_MONSTERS, NULL, &tr); + engine.TestLine (sourceDuck, dest, TRACE_IGNORE_MONSTERS, nullptr, &tr); // check if line of sight to object is not blocked (i.e. visible) if (tr.flFraction != 1.0f || tr.fStartSolid) @@ -1441,7 +1441,7 @@ void Waypoint::InitializeVisibility (void) res <<= 1; - engine.TestLine (sourceStand, dest, TRACE_IGNORE_MONSTERS, NULL, &tr); + engine.TestLine (sourceStand, dest, TRACE_IGNORE_MONSTERS, nullptr, &tr); // check if line of sight to object is not blocked (i.e. visible) if (tr.flFraction != 1.0f || tr.fStartSolid) @@ -1465,7 +1465,7 @@ void Waypoint::InitializeVisibility (void) bool Waypoint::IsVisible (int srcIndex, int destIndex) { - unsigned char res = m_visLUT[srcIndex][destIndex >> 2]; + uint8 res = m_visLUT[srcIndex][destIndex >> 2]; res >>= (destIndex % 4) << 1; return !((res & 3) == 3); @@ -1473,7 +1473,7 @@ bool Waypoint::IsVisible (int srcIndex, int destIndex) bool Waypoint::IsDuckVisible (int srcIndex, int destIndex) { - unsigned char res = m_visLUT[srcIndex][destIndex >> 2]; + uint8 res = m_visLUT[srcIndex][destIndex >> 2]; res >>= (destIndex % 4) << 1; return !((res & 2) == 2); @@ -1481,7 +1481,7 @@ bool Waypoint::IsDuckVisible (int srcIndex, int destIndex) bool Waypoint::IsStandVisible (int srcIndex, int destIndex) { - unsigned char res = m_visLUT[srcIndex][destIndex >> 2]; + uint8 res = m_visLUT[srcIndex][destIndex >> 2]; res >>= (destIndex % 4) << 1; return !((res & 1) == 1); @@ -1494,7 +1494,7 @@ const char *Waypoint::GetWaypointInfo(int id) Path *path = m_paths[id]; // if this path is null, return - if (path == NULL) + if (path == nullptr) return "\0"; bool jumpPoint = false; @@ -1641,8 +1641,8 @@ void Waypoint::Think (void) engine.DrawLine (g_hostEntity, m_paths[i]->origin - Vector (0, 0, nodeHalfHeight), m_paths[i]->origin + Vector (0, 0, nodeHalfHeight), 15, 0, static_cast (nodeColor.x), static_cast (nodeColor.y), static_cast (nodeColor.z), 250, 0, 10); else // draw node with flags { - engine.DrawLine (g_hostEntity, m_paths[i]->origin - Vector (0, 0, nodeHalfHeight), m_paths[i]->origin - Vector (0, 0, nodeHalfHeight - nodeHeight * 0.75), 14, 0, static_cast (nodeColor.x), static_cast (nodeColor.y), static_cast (nodeColor.z), 250, 0, 10); // draw basic path - engine.DrawLine (g_hostEntity, m_paths[i]->origin - Vector (0, 0, nodeHalfHeight - nodeHeight * 0.75), m_paths[i]->origin + Vector (0, 0, nodeHalfHeight), 14, 0, static_cast (nodeFlagColor.x), static_cast (nodeFlagColor.y), static_cast (nodeFlagColor.z), 250, 0, 10); // draw additional path + engine.DrawLine (g_hostEntity, m_paths[i]->origin - Vector (0, 0, nodeHalfHeight), m_paths[i]->origin - Vector (0, 0, nodeHalfHeight - nodeHeight * 0.75f), 14, 0, static_cast (nodeColor.x), static_cast (nodeColor.y), static_cast (nodeColor.z), 250, 0, 10); // draw basic path + engine.DrawLine (g_hostEntity, m_paths[i]->origin - Vector (0, 0, nodeHalfHeight - nodeHeight * 0.75f), m_paths[i]->origin + Vector (0, 0, nodeHalfHeight), 14, 0, static_cast (nodeFlagColor.x), static_cast (nodeFlagColor.y), static_cast (nodeFlagColor.z), 250, 0, 10); // draw additional path } m_waypointDisplayTime[i] = engine.Time (); } @@ -1797,7 +1797,7 @@ void Waypoint::Think (void) } // draw entire message - MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, NULL, g_hostEntity); + MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, nullptr, g_hostEntity); WRITE_BYTE (TE_TEXTMESSAGE); WRITE_BYTE (4); // channel WRITE_SHORT (FixedSigned16 (0, 1 << 13)); // x @@ -1813,7 +1813,7 @@ void Waypoint::Think (void) WRITE_BYTE (255); // a2 WRITE_SHORT (0); // fadeintime WRITE_SHORT (0); // fadeouttime - WRITE_SHORT (FixedUnsigned16 (1.1, 1 << 8)); // holdtime + WRITE_SHORT (FixedUnsigned16 (1.1f, 1 << 8)); // holdtime WRITE_STRING (tempMessage); MESSAGE_END (); } @@ -1949,7 +1949,7 @@ bool Waypoint::NodesValid (void) } // perform DFS instead of floyd-warshall, this shit speedup this process in a bit - PathNode *stack = NULL; + PathNode *stack = nullptr; bool visited[MAX_WAYPOINTS]; // first check incoming connectivity, initialize the "visited" table @@ -1958,10 +1958,10 @@ bool Waypoint::NodesValid (void) // check from waypoint nr. 0 stack = new PathNode; - stack->next = NULL; + stack->next = nullptr; stack->index = 0; - while (stack != NULL) + while (stack != nullptr) { // pop a node from the stack PathNode *current = stack; @@ -2023,10 +2023,10 @@ bool Waypoint::NodesValid (void) // check from Waypoint nr. 0 stack = new PathNode; - stack->next = NULL; + stack->next = nullptr; stack->index = 0; - while (stack != NULL) + while (stack != nullptr) { // pop a node from the stack PathNode *current = stack; @@ -2075,8 +2075,8 @@ void Waypoint::InitPathMatrix (void) delete [] m_distMatrix; delete [] m_pathMatrix; - m_distMatrix = NULL; - m_pathMatrix = NULL; + m_distMatrix = nullptr; + m_pathMatrix = nullptr; m_distMatrix = new int [g_numWaypoints * g_numWaypoints]; m_pathMatrix = new int [g_numWaypoints * g_numWaypoints]; @@ -2227,7 +2227,7 @@ void Waypoint::CreateBasic (void) { // this function creates basic waypoint types on map - edict_t *ent = NULL; + edict_t *ent = nullptr; // first of all, if map contains ladder points, create it while (!engine.IsNullEntity (ent = FIND_ENTITY_BY_CLASSNAME (ent, "func_ladder"))) @@ -2248,7 +2248,7 @@ void Waypoint::CreateBasic (void) up = down = front; down.z = ent->v.absmax.z; - engine.TestHull (down, up, TRACE_IGNORE_MONSTERS, point_hull, NULL, &tr); + engine.TestHull (down, up, TRACE_IGNORE_MONSTERS, point_hull, nullptr, &tr); if (POINT_CONTENTS (up) == CONTENTS_SOLID || tr.flFraction != 1.0f) { @@ -2256,7 +2256,7 @@ void Waypoint::CreateBasic (void) down.z = ent->v.absmax.z; } - engine.TestHull (down, up - Vector (0.0f, 0.0f, 1000.0f), TRACE_IGNORE_MONSTERS, point_hull, NULL, &tr); + engine.TestHull (down, up - Vector (0.0f, 0.0f, 1000.0f), TRACE_IGNORE_MONSTERS, point_hull, nullptr, &tr); up = tr.vecEndPos; Vector pointOrigin = up + Vector (0.0f, 0.0f, 39.0f); @@ -2386,8 +2386,8 @@ Path *Waypoint::GetPath (int id) { Path *path = m_paths[id]; - if (path == NULL) - return NULL; + if (path == nullptr) + return nullptr; return path; } @@ -2442,7 +2442,7 @@ void Waypoint::SetBombPosition (bool shouldReset) return; } - edict_t *ent = NULL; + edict_t *ent = nullptr; while (!engine.IsNullEntity (ent = FIND_ENTITY_BY_CLASSNAME (ent, "grenade"))) { @@ -2499,8 +2499,8 @@ Waypoint::Waypoint (void) m_rescuePoints.RemoveAll (); m_sniperPoints.RemoveAll (); - m_distMatrix = NULL; - m_pathMatrix = NULL; + m_distMatrix = nullptr; + m_pathMatrix = nullptr; } Waypoint::~Waypoint (void) @@ -2510,8 +2510,8 @@ Waypoint::~Waypoint (void) delete [] m_distMatrix; delete [] m_pathMatrix; - m_distMatrix = NULL; - m_pathMatrix = NULL; + m_distMatrix = nullptr; + m_pathMatrix = nullptr; } void Waypoint::CloseSocketHandle (int sock) @@ -2542,7 +2542,7 @@ WaypointDownloadError Waypoint::RequestWaypoint (void) hostent *host = gethostbyname (yb_waypoint_autodl_host.GetString ()); - if (host == NULL) + if (host == nullptr) return WDE_SOCKET_ERROR; int socketHandle = socket (AF_INET, SOCK_STREAM, 0);