code refactoring, still testing

some fixes all over the place
fixed all warnings from clang
This commit is contained in:
jeefo 2016-03-12 14:35:44 +03:00
commit bc2e57a7a8
22 changed files with 984 additions and 1051 deletions

2
.gitignore vendored
View file

@ -56,3 +56,5 @@ Icon
project/yapb.vcxproj.user
*.psess
*.opendb
*.aps
*.db

View file

@ -398,32 +398,6 @@ enum GameStartMessage
GSM_SAY_TEAM = 10001
};
// netmessage functions
enum NetworkMessage
{
NETMSG_UNDEFINED = 0,
NETMSG_VGUI = 1,
NETMSG_SHOWMENU = 2,
NETMSG_WEAPONLIST = 3,
NETMSG_CURWEAPON = 4,
NETMSG_AMMOX = 5,
NETMSG_AMMOPICKUP = 6,
NETMSG_DAMAGE = 7,
NETMSG_MONEY = 8,
NETMSG_STATUSICON = 9,
NETMSG_DEATH = 10,
NETMSG_SCREENFADE = 11,
NETMSG_HLTV = 12,
NETMSG_TEXTMSG = 13,
NETMSG_SCOREINFO = 14,
NETMSG_BARTIME = 15,
NETMSG_SENDAUDIO = 17,
NETMSG_SAYTEXT = 18,
NETMSG_BOTVOICE = 19,
NETMSG_RESETHUD = 20,
NETMSG_NUM = 21
};
// sensing states
enum SensingState
{
@ -553,6 +527,7 @@ const int MAX_WEAPONS = 32;
const int NUM_WEAPONS = 26;
const int MAX_COLLIDE_MOVES = 3;
const int MAX_ENGINE_PLAYERS = 32; // we can have 64 players with xash
const int MAX_PRINT_BUFFER = 1024;
// weapon masks
const int WEAPON_PRIMARY = ((1 << WEAPON_XM1014) | (1 <<WEAPON_M3) | (1 << WEAPON_MAC10) | (1 << WEAPON_UMP45) | (1 << WEAPON_MP5) | (1 << WEAPON_TMP) | (1 << WEAPON_P90) | (1 << WEAPON_AUG) | (1 << WEAPON_M4A1) | (1 << WEAPON_SG552) | (1 << WEAPON_AK47) | (1 << WEAPON_SCOUT) | (1 << WEAPON_SG550) | (1 << WEAPON_AWP) | (1 << WEAPON_G3SG1) | (1 << WEAPON_M249) | (1 << WEAPON_FAMAS) | (1 << WEAPON_GALIL));
@ -598,13 +573,6 @@ struct ChatterItem
float repeatTime;
};
// language config structure definition
struct LanguageItem
{
const char *original; // original string
const char *translated; // string to replace for
};
struct WeaponSelect
{
int id; // the weapon id value
@ -766,7 +734,7 @@ private:
float m_blindRecognizeTime; // time to recognize enemy
float m_itemCheckTime; // time next search for items needs to be done
PickupType m_pickupType; // type of entity which needs to be used/picked up
Vector m_breakable; // origin of breakable
Vector m_breakableOrigin; // origin of breakable
edict_t *m_pickupItem; // pointer to entity of item to use/pickup
edict_t *m_itemIgnore; // pointer to entity to ignore for pickup
@ -824,7 +792,7 @@ private:
bool m_wantsToFire; // bot needs consider firing
float m_shootAtDeadTime; // time to shoot at dying players
edict_t *m_avoidGrenade; // pointer to grenade entity to avoid
char m_needAvoidGrenade; // which direction to strafe away
int m_needAvoidGrenade; // which direction to strafe away
float m_followWaitTime; // wait to follow time
edict_t *m_targetEntity; // the entity that the bot is trying to reach
@ -1194,7 +1162,7 @@ public:
void Think (void);
/// the things that can be executed while skipping frames
void ThinkDelayed (void);
void ThinkFrame (void);
void DisplayDebugOverlay (void);
void NewRound (void);
@ -1218,7 +1186,7 @@ public:
inline TaskID GetTaskId (void) { return GetTask ()->id; };
void TakeDamage (edict_t *inflictor, int damage, int armor, int bits);
void TakeBlinded (const Vector &fade, int alpha);
void TakeBlinded (int r, int g, int b, int alpha);
void DiscardWeaponForUser (edict_t *user, bool discardC4);
@ -1254,7 +1222,7 @@ public:
};
// manager class
class BotManager
class BotManager : public Singleton <BotManager>
{
private:
Array <CreateQueue> m_creationTab; // bot creation tab
@ -1349,46 +1317,9 @@ public:
void SendDeathMsgFix (void);
};
// texts localizer
class Localizer
{
public:
Array <LanguageItem> m_langTab;
public:
Localizer (void) { m_langTab.RemoveAll (); }
~Localizer (void) { m_langTab.RemoveAll (); }
char *TranslateInput (const char *input);
void Destroy (void);
};
// netmessage handler class
class NetworkMsg
{
private:
Bot *m_bot;
int m_state;
int m_message;
int m_registerdMessages[NETMSG_NUM];
public:
NetworkMsg (void);
~NetworkMsg (void) { };
void Execute (void *p);
inline void Reset (void) { m_message = NETMSG_UNDEFINED; m_state = 0; m_bot = NULL; };
void HandleMessageIfRequired (int messageType, int requiredType);
inline void SetMessage (int message) { m_message = message; }
inline void SetBot (Bot *bot) { m_bot = bot; }
inline int GetId (int messageType) { return m_registerdMessages[messageType]; }
inline void SetId (int messageType, int messsageIdentifier) { m_registerdMessages[messageType] = messsageIdentifier; }
};
// waypoint operation class
class Waypoint
class Waypoint : public Singleton <Waypoint>
{
friend class Bot;
@ -1409,7 +1340,7 @@ private:
int m_lastJumpWaypoint;
int m_visibilityIndex;
Vector m_lastWaypoint;
byte m_visLUT[MAX_WAYPOINTS][MAX_WAYPOINTS / 4];
unsigned char m_visLUT[MAX_WAYPOINTS][MAX_WAYPOINTS / 4];
float m_pathDisplayTime;
float m_arrowDisplayTime;
@ -1440,12 +1371,12 @@ public:
void InitVisibilityTab (void);
void InitTypes (void);
void AddPath (short int addIndex, short int pathIndex, float distance);
void AddPath (int addIndex, int pathIndex, float distance);
int GetFacingIndex (void);
int FindFarest (const Vector &origin, float maxDistance = 32.0);
int FindNearest (const Vector &origin, float minDistance = 9999.0f, int flags = -1);
void FindInRadius (Array <int> &radiusHolder, float radius, const Vector &origin, int maxCount = -1);
void FindInRadius (Array <int> &holder, float radius, const Vector &origin, int maxCount = -1);
void Add (int flags, const Vector &waypointOrigin = Vector::GetZero ());
void Delete (void);
@ -1466,6 +1397,7 @@ public:
bool Load (void);
void Save (void);
void CleanupPathMemory (void);
bool Reachable (Bot *bot, int index);
bool IsNodeReachable (const Vector &src, const Vector &destination);
@ -1492,25 +1424,11 @@ public:
void SetGoalVisited (int index);
void ClearVisitedGoals (void);
inline const Vector &GetBombPosition (void)
{
return m_foundBombOrigin;
}
const char *GetDataDir (void);
void SetBombPosition (bool shouldReset = false);
String CheckSubfolderFile (void);
// quick access
inline Path *operator [] (int index)
{
extern int g_numWaypoints;
if (index < 0 || index >= g_numWaypoints)
assert (0);
return GetPath (index);
}
void SetBombPosition (bool shouldReset = false);
inline const Vector &GetBombPosition (void) { return m_foundBombOrigin; }
// free's socket handle
void CloseSocketHandle (int sock);
@ -1522,11 +1440,9 @@ public:
#include <engine.h>
// expose bot super-globals
extern NetworkMsg netmsg;
extern Localizer locale;
extern Waypoint waypoints;
extern BotManager bots;
extern Engine engine;
#define waypoints Waypoint::GetReference ()
#define engine Engine::GetReference ()
#define bots BotManager::GetReference ()
// prototypes of bot functions...
extern int GetWeaponReturn (bool isString, const char *weaponAlias, int weaponIndex = -1);

View file

@ -2303,7 +2303,7 @@ public:
char buffer[1024];
va_start (ap, fmt);
vsprintf (buffer, fmt, ap);
vsnprintf (buffer, sizeof (buffer) - 1, fmt, ap);
va_end (ap);
Append (buffer);
@ -2374,7 +2374,7 @@ public:
char buffer[1024];
va_start (ap, fmt);
vsprintf (buffer, fmt, ap);
vsnprintf (buffer, sizeof (buffer) - 1, fmt, ap);
va_end (ap);
Assign (buffer);
@ -3311,46 +3311,23 @@ public:
// Returns:
// None
//
static inline void TrimExternalBuffer (char *string)
static inline void TrimExternalBuffer (char *str)
{
char *ptr = string;
int pos = 0;
char *dest = str;
int length = 0, toggleFlag = 0, increment = 0;
int i = 0;
while (str[pos] <= ' ' && str[pos] > 0)
pos++;
while (*ptr++)
length++;
for (i = length - 1; i >= 0; i--)
while (str[pos])
{
if (!isspace (string[i]))
break;
else
{
string[i] = 0;
length--;
}
*(dest++) = str[pos];
pos++;
}
*(dest--) = '\0';
for (i = 0; i < length; i++)
{
if (isspace (string[i]) && !toggleFlag)
{
increment++;
if (increment + i < length)
string[i] = string[increment + i];
}
else
{
if (!toggleFlag)
toggleFlag = 1;
if (increment)
string[i] = string[increment + i];
}
}
string[length] = 0;
while (dest >= str && *dest <= ' ' && *dest > 0)
*(dest--) = '\0';
}
};
@ -3694,10 +3671,9 @@ public:
static MF_Unloader Unloader;
protected:
String m_fileName;
int m_fileSize;
int m_filePos;
unsigned char *m_fileBuffer;
int m_size;
int m_pos;
unsigned char *m_buffer;
//
// Group: (Con/De)structors
@ -3710,11 +3686,10 @@ public:
//
MemoryFile (void)
{
m_fileSize = 0;
m_filePos = 0;
m_size = 0;
m_pos = 0;
m_fileBuffer = NULL;
m_fileName.Empty ();
m_buffer = NULL;
}
//
@ -3723,11 +3698,10 @@ public:
//
MemoryFile (const String &fileName)
{
m_fileSize = 0;
m_filePos = 0;
m_size = 0;
m_pos = 0;
m_fileBuffer = NULL;
m_fileName.Empty ();
m_buffer = NULL;
Open (fileName);
}
@ -3751,18 +3725,17 @@ public:
// Returns:
// True if operation succeeded, false otherwise.
//
bool Open (const String &fileName)
bool Open (const char *fileName)
{
if (fileName.IsEmpty () || Loader == NULL)
if (!Loader)
return false;
m_fileSize = 0;
m_filePos = 0;
m_fileName = fileName;
m_size = 0;
m_pos = 0;
m_fileBuffer = Loader (fileName.GetBuffer (), &m_fileSize);
m_buffer = Loader (fileName, &m_size);
if (m_fileBuffer == NULL || m_fileSize < 0)
if (m_buffer == NULL || m_size < 0)
return false;
return true;
@ -3775,13 +3748,12 @@ public:
void Close (void)
{
if (Unloader != NULL)
Unloader (m_fileBuffer);
Unloader (m_buffer);
m_fileSize = 0;
m_filePos = 0;
m_size = 0;
m_pos = 0;
m_fileBuffer = NULL;
m_fileName.Empty ();
m_buffer = NULL;
}
//
@ -3793,11 +3765,11 @@ public:
//
int GetChar (void)
{
if (m_fileBuffer == NULL || m_filePos >= m_fileSize)
if (m_buffer == NULL || m_pos >= m_size)
return -1;
int readCh = m_fileBuffer[m_filePos];
m_filePos++;
int readCh = m_buffer[m_pos];
m_pos++;
return readCh;
}
@ -3815,41 +3787,41 @@ public:
//
char *GetBuffer (char *buffer, int count)
{
if (m_fileBuffer == NULL || m_filePos >= m_fileSize)
if (m_buffer == NULL || m_pos >= m_size)
return NULL;
int lineStartOffset = m_filePos;
int lineEndOffset = m_fileSize - 1;
int start = m_pos;
int end = m_size - 1;
if (m_fileSize - m_filePos > count - 1)
lineEndOffset = m_filePos + count - 1;
if (m_size - m_pos > count - 1)
end = m_pos + count - 1;
while (m_filePos < lineEndOffset)
while (m_pos < end)
{
if (m_fileBuffer[m_filePos] == 0x0a)
lineEndOffset = m_filePos;
if (m_buffer[m_pos] == 0x0a)
end = m_pos;
m_filePos++;
m_pos++;
}
if (m_filePos == lineStartOffset)
if (m_pos == start)
return NULL;
int pos = lineStartOffset;
int pos = start;
for (; pos <= lineEndOffset; pos++)
buffer[pos - lineStartOffset] = m_fileBuffer[pos];
for (; pos <= end; pos++)
buffer[pos - start] = m_buffer[pos];
if (buffer[pos - lineStartOffset - 2] == 0x0d)
if (buffer[pos - start - 2] == 0x0d)
{
buffer[pos - lineStartOffset - 2] = '\n';
buffer[pos - start - 2] = '\n';
pos--;
}
if (buffer[pos - lineStartOffset - 1] == 0x0d || buffer[pos - lineStartOffset - 1] == 0x0a)
buffer[pos - lineStartOffset - 1] = '\n';
if (buffer[pos - start - 1] == 0x0d || buffer[pos - start - 1] == 0x0a)
buffer[pos - start - 1] = '\n';
buffer[pos - lineStartOffset] = 0;
buffer[pos - start] = 0;
return buffer;
}
@ -3868,16 +3840,13 @@ public:
//
int Read (void *buffer, int size, int count = 1)
{
if (m_fileBuffer == NULL || m_filePos >= m_fileSize)
if (!m_buffer|| m_pos >= m_size || buffer == NULL || !size || !count)
return 0;
if (buffer == NULL || size == 0 || count == 0 || m_fileBuffer == NULL)
return 0;
int blocksRead = min ((m_size - m_pos) / size, count) * size;
int blocksRead = min ((m_fileSize - m_filePos) / size, count);
memcpy (buffer, &m_fileBuffer[m_filePos], blocksRead * size);
m_filePos += blocksRead * size;
memcpy (buffer, &m_buffer[m_pos], blocksRead);
m_pos += blocksRead;
return blocksRead;
}
@ -3895,29 +3864,29 @@ public:
//
bool Seek (long offset, int origin)
{
if (m_fileBuffer == NULL || m_filePos >= m_fileSize)
if (m_buffer == NULL || m_pos >= m_size)
return false;
if (origin == SEEK_SET)
{
if (offset >= m_fileSize)
if (offset >= m_size)
return false;
m_filePos = offset;
m_pos = offset;
}
else if (origin == SEEK_END)
{
if (offset >= m_fileSize)
if (offset >= m_size)
return false;
m_filePos = m_fileSize - offset;
m_pos = m_size - offset;
}
else
{
if (m_filePos + offset >= m_fileSize)
if (m_pos + offset >= m_size)
return false;
m_filePos += offset;
m_pos += offset;
}
return true;
}
@ -3931,7 +3900,7 @@ public:
//
int GetSize (void)
{
return m_fileSize;
return m_size;
}
//
@ -3943,7 +3912,7 @@ public:
//
bool IsValid (void)
{
return m_fileBuffer != NULL && m_fileSize > 0;
return m_buffer != NULL && m_size > 0;
}
};
@ -3953,63 +3922,9 @@ public:
//
typedef Array <const String &> StrVec;
//
// Class: Exception
// Simple exception raiser.
//
class Exception
{
private:
String m_exceptionText;
String m_fileName;
int m_line;
//
// Group: (Con/De)structors
//
public:
//
// Function: Exception
// Default exception constructor.
//
// Parameters:
// exceptionText - Text to throw.
// fileName - Debug file name.
// line - Debug line number.
//
Exception (String exceptionText, String fileName = "(no)", int line = -1) : m_exceptionText (exceptionText), m_fileName (fileName), m_line (line) { }
//
// Function: ~Exception
// Default exception destructor.
//
virtual ~Exception (void) { };
//
// Group: Functions
//
public:
//
// Function: GetDescription
// Gets the description from throw object.
//
// Returns:
// Exception text.
//
inline const String &GetDescription (void)
{
static String result;
if (m_fileName != "(no)" && m_line != -1)
result.AssignFormat ("Exception: %s at %s:%i", m_exceptionText.GetBuffer (), m_fileName.GetBuffer (), m_line);
else
result = m_exceptionText;
return result;
}
};
#ifndef FORCEINLINE
#define FORCEINLINE inline
#endif
//
// Class: Singleton
@ -4034,6 +3949,10 @@ protected:
//
virtual ~Singleton (void) { }
private:
Singleton (Singleton const &);
void operator = (Singleton const &);
public:
//
@ -4044,7 +3963,7 @@ public:
// Object pointer.
//
//
static inline T *GetObject (void)
static FORCEINLINE T *GetObject (void)
{
static T reference;
return &reference;
@ -4058,7 +3977,7 @@ public:
// Object reference.
//
//
static inline T &GetReference (void)
static FORCEINLINE T &GetReference (void)
{
static T reference;
return reference;

View file

@ -38,10 +38,36 @@ enum VarType
VT_NOREGISTER
};
// need since we don't want to use Singleton on engine class
class ConVarWrapper : public Singleton <ConVarWrapper>
// netmessage functions
enum NetMsgId
{
private:
NETMSG_UNDEFINED = -1,
NETMSG_VGUI = 1,
NETMSG_SHOWMENU = 2,
NETMSG_WEAPONLIST = 3,
NETMSG_CURWEAPON = 4,
NETMSG_AMMOX = 5,
NETMSG_AMMOPICKUP = 6,
NETMSG_DAMAGE = 7,
NETMSG_MONEY = 8,
NETMSG_STATUSICON = 9,
NETMSG_DEATH = 10,
NETMSG_SCREENFADE = 11,
NETMSG_HLTV = 12,
NETMSG_TEXTMSG = 13,
NETMSG_SCOREINFO = 14,
NETMSG_BARTIME = 15,
NETMSG_SENDAUDIO = 17,
NETMSG_SAYTEXT = 18,
NETMSG_BOTVOICE = 19,
NETMSG_NUM = 21
};
// provides utility functions to not call original engine (less call-cost)
class Engine : public Singleton <Engine>
{
public:
// variable reg pair
struct VarPair
{
VarType type;
@ -49,16 +75,23 @@ private:
bool regMissing;
class ConVar *self;
};
Array <VarPair> m_regs;
public:
void RegisterVariable (const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self);
void PushRegisteredConVarsToEngine (bool gameVars = false);
};
// translation pair
struct TranslatorPair
{
const char *original;
const char *translated;
};
// network message block
struct MessageBlock
{
int bot;
int state;
int msg;
int regMsgs[NETMSG_NUM];
};
// provides utility functions to not call original engine (less call-cost)
class Engine
{
private:
short m_drawModels[DRAW_NUM];
@ -70,6 +103,16 @@ private:
edict_t *m_startEntity;
edict_t *m_localEntity;
Array <VarPair> m_cvars;
Array <TranslatorPair> m_language;
MessageBlock m_msgBlock;
public:
Engine (void);
~Engine (void);
// public functions
public:
@ -124,6 +167,21 @@ public:
// sends bot command
void IssueBotCommand (edict_t *ent, const char *fmt, ...);
// adds cvar to registration stack
void PushVariableToStack (const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self);
// sends local registration stack for engine registration
void PushRegisteredConVarsToEngine (bool gameVars = false);
// translates bot message into needed language
char *TraslateMessage (const char *input);
// cleanup translator resources
void TerminateTranslator (void);
// do actual network message processing
void ProcessMesageCapture (void *ptr);
// public inlines
public:
@ -168,21 +226,25 @@ public:
return m_argumentCount;
}
// gets edict pointer out of entity index
inline edict_t *EntityOfIndex (const int index)
{
return static_cast <edict_t *> (m_startEntity + index);
};
// gets edict index out of it's pointer
inline int IndexOfEntity (const edict_t *ent)
{
return static_cast <int> (ent - m_startEntity);
};
// verify entity isn't null
inline bool IsNullEntity (const edict_t *ent)
{
return !ent || !IndexOfEntity (ent);
}
// gets the player team
inline int GetTeam (edict_t *ent)
{
extern Client g_clients[MAX_ENGINE_PLAYERS];
@ -194,6 +256,51 @@ public:
#endif
}
// adds translation pair from config
inline void PushTranslationPair (const TranslatorPair &lang)
{
m_language.Push (lang);
}
// resets the message capture mechanism
inline void ResetMessageCapture (void)
{
m_msgBlock.msg = NETMSG_UNDEFINED;
m_msgBlock.state = 0;
m_msgBlock.bot = 0;
};
// sets the currently executed message
inline void SetOngoingMessageId (int message)
{
m_msgBlock.msg = message;
}
// set the bot entity that receive this message
inline void SetOngoingMessageReceiver (int id)
{
m_msgBlock.bot = id;
}
// find registered message id
inline int FindMessageId (int type)
{
return m_msgBlock.regMsgs[type];
}
// assigns message id for message type
inline void AssignMessageId (int type, int id)
{
m_msgBlock.regMsgs[type] = id;
}
// tries to set needed message id
void TryCaptureMessage (int type, int msgId)
{
if (type == m_msgBlock.regMsgs[msgId])
SetOngoingMessageId (msgId);
}
// static utility functions
public:
static const char *ExtractSingleField (const char *string, int id, bool terminate);

View file

@ -149,7 +149,7 @@ typedef struct enginefuncs_s
void (*pfnGetAimVector) (edict_t *ent, float speed, float *rgflReturn);
void (*pfnServerCommand) (char *str);
void (*pfnServerExecute) (void);
void (*pfnClientCommand) (edict_t *ent, char *szFmt, ...);
void (*pfnClientCommand) (edict_t *ent, char const *szFmt, ...);
void (*pfnParticleEffect) (const float *org, const float *dir, float color, float count);
void (*pfnLightStyle) (int style, char *val);
int (*pfnDecalIndex) (const char *name);
@ -203,7 +203,7 @@ typedef struct enginefuncs_s
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 *szFilename, int *pLength);
byte *(*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);
@ -215,9 +215,9 @@ typedef struct enginefuncs_s
void (*pfnRunPlayerMove) (edict_t *fakeclient, const float *viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, byte msec);
int (*pfnNumberOfEntities) (void);
char *(*pfnGetInfoKeyBuffer) (edict_t *e); // passing in NULL gets the serverinfo
char *(*pfnInfoKeyValue) (char *infobuffer, char *key);
char *(*pfnInfoKeyValue) (char *infobuffer, char const *key);
void (*pfnSetKeyValue) (char *infobuffer, char *key, char *value);
void (*pfnSetClientKeyValue) (int clientIndex, char *infobuffer, char *key, char *value);
void (*pfnSetClientKeyValue) (int clientIndex, char *infobuffer, char const *key, char const *value);
int (*pfnIsMapValid) (char *szFilename);
void (*pfnStaticDecal) (const float *origin, int decalIndex, int entityIndex, int modelIndex);
int (*pfnPrecacheGeneric) (char *s);
@ -280,7 +280,7 @@ typedef struct enginefuncs_s
typedef struct KeyValueData_s
{
char *szClassName; // in: entity classname
char *szKeyName; // in: name of key
char const *szKeyName; // in: name of key
char *szValue; // in: value of key
int32 fHandled; // out: DLL sets to true if key-value pair was understood
} KeyValueData;

View file

@ -37,13 +37,13 @@ typedef enum
typedef struct
{
char *ifvers;
char *name;
char *version;
char *date;
char *author;
char *url;
char *logtag;
char const *ifvers;
char const *name;
char const *version;
char const *date;
char const *author;
char const *url;
char const *logtag;
PLUG_LOADTIME loadable;
PLUG_LOADTIME unloadable;
} plugin_info_t;

View file

@ -53,12 +53,6 @@ static inline edict_t *FIND_ENTITY_BY_TARGET (edict_t *entStart, const char *psz
#define ClearBits(flBitVector, bits) ((flBitVector) = (int)(flBitVector) & ~(bits))
#define FBitSet(flBitVector, bit) ((int)(flBitVector) & (bit))
// Pointer operators
#define PTR_TO_BYTE(in) *(byte *) (in)
#define PTR_TO_FLT(in) *(float *) (in)
#define PTR_TO_INT(in) *(int *) (in)
#define PTR_TO_STR(in) (char *) (in)
// Makes these more explicit, and easier to find
#define FILE_GLOBAL static
@ -82,6 +76,7 @@ typedef int BOOL;
//
// Conversion among the three types of "entity", including identity-conversions.
//
#if 0
static inline edict_t *ENT (const entvars_t *pev)
{
return pev->pContainingEntity;
@ -131,12 +126,14 @@ static inline entvars_t *VARS (EOFFSET eoffset)
{
return VARS (ENT (eoffset));
}
#endif
static inline void MESSAGE_BEGIN (int msg_dest, int msg_type, const float *pOrigin, entvars_t *ent)
{
(*g_engfuncs.pfnMessageBegin) (msg_dest, msg_type, pOrigin, ENT (ent));
(*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)
@ -162,6 +159,7 @@ static inline BOOL FStringNull (int stingPtr)
#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
@ -176,7 +174,7 @@ static inline BOOL FStrEq (const char *sz1, const char *sz2)
}
static inline BOOL FClassnameIs (edict_t *pent, const char *szClassname)
{
return FStrEq (STRING (VARS (pent)->classname), szClassname);
return FStrEq (STRING (pent->v.classname), szClassname);
}
static inline BOOL FClassnameIs (entvars_t *pev, const char *szClassname)
{

View file

@ -21,15 +21,15 @@
// detects the compiler
#if defined (_MSC_VER)
#define COMPILER_VISUALC _MSC_VER
#elif defined (__MINGW32__)
#define COMPILER_MINGW32 __MINGW32__
#elif defined (__MINGW32_MAJOR_VERSION)
#define COMPILER_MINGW32 __MINGW32_MAJOR_VERSION
#endif
// configure export macros
#if defined (COMPILER_VISUALC) || defined (COMPILER_MINGW32)
#define export extern "C" __declspec (dllexport)
#define SHARED_LIBRARAY_EXPORT extern "C" __declspec (dllexport)
#elif defined (PLATFORM_LINUX) || defined (PLATFORM_OSX)
#define export extern "C" __attribute__((visibility("default")))
#define SHARED_LIBRARAY_EXPORT extern "C" __attribute__((visibility("default")))
#else
#error "Can't configure export macros. Compiler unrecognized."
#endif
@ -38,6 +38,7 @@
#ifdef PLATFORM_WIN32
#include <direct.h>
#include <string.h>
#define DLL_ENTRYPOINT int STDCALL DllMain (HINSTANCE, DWORD dwReason, LPVOID)
#define DLL_DETACHING (dwReason == DLL_PROCESS_DETACH)
@ -46,7 +47,7 @@
#if defined (COMPILER_VISUALC)
#define DLL_GIVEFNPTRSTODLL extern "C" void STDCALL
#elif defined (COMPILER_MINGW32)
#define DLL_GIVEFNPTRSTODLL export void STDCALL
#define DLL_GIVEFNPTRSTODLL SHARED_LIBRARAY_EXPORT void STDCALL
#endif
// specify export parameter
@ -138,11 +139,8 @@ public:
template <typename R> R GetFuncAddr (const char *function)
{
if (!IsLoaded ())
return NULL;
#ifdef PLATFORM_WIN32
return reinterpret_cast <R> (GetProcAddress (static_cast <HMODULE> (m_ptr), function));
return reinterpret_cast <R> (GetProcAddress (GetHandle <HMODULE> (), function));
#else
return reinterpret_cast <R> (dlsym (m_ptr, function));
#endif

View file

@ -19,7 +19,6 @@ OBJECTS = $(SRC_DIR)/basecode.cpp \
$(SRC_DIR)/engine.cpp \
$(SRC_DIR)/interface.cpp \
$(SRC_DIR)/navigate.cpp \
$(SRC_DIR)/netmsg.cpp \
$(SRC_DIR)/support.cpp \
$(SRC_DIR)/waypoint.cpp \

View file

@ -35,7 +35,6 @@
<ClCompile Include="..\source\basecode.cpp" />
<ClCompile Include="..\source\combat.cpp" />
<ClCompile Include="..\source\engine.cpp" />
<ClCompile Include="..\source\netmsg.cpp" />
<ClCompile Include="..\source\manager.cpp" />
<ClCompile Include="..\source\chatlib.cpp" />
<ClCompile Include="..\source\globals.cpp" />
@ -56,13 +55,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
<PlatformToolset>v120_xp</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@ -113,9 +112,7 @@
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\include\engine;..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<PrecompiledHeader />
<PrecompiledHeaderFile>core.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>.\debug\inf\yapb.pch</PrecompiledHeaderOutputFile>
@ -130,7 +127,10 @@
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<CompileAs>Default</CompileAs>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FloatingPointModel>Strict</FloatingPointModel>
<StringPooling>true</StringPooling>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -143,7 +143,6 @@
<OutputFile>.\debug\yapb.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AssemblyDebug>true</AssemblyDebug>
<ProgramDatabaseFile>.\debug\inf\yapb.pdb</ProgramDatabaseFile>
<GenerateMapFile>true</GenerateMapFile>
<MapFileName>.\debug\inf\yapb.map</MapFileName>
@ -151,11 +150,8 @@
<SubSystem>Windows</SubSystem>
<OptimizeReferences>false</OptimizeReferences>
<EnableCOMDATFolding>false</EnableCOMDATFolding>
<NoEntryPoint>false</NoEntryPoint>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention />
<ImportLibrary>.\debug\inf\yapb.lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>

View file

@ -39,9 +39,6 @@
<ClInclude Include="..\include\engine\eiface.h">
<Filter>include\engine</Filter>
</ClInclude>
<ClInclude Include="..\include\engine\enginecallback.h">
<Filter>include\engine</Filter>
</ClInclude>
<ClInclude Include="..\include\engine\extdll.h">
<Filter>include\engine</Filter>
</ClInclude>
@ -72,6 +69,9 @@
<ClInclude Include="..\include\engine.h">
<Filter>include</Filter>
</ClInclude>
<ClInclude Include="..\include\engine\enginecallback.h">
<Filter>include\engine</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\source\chatlib.cpp">
@ -104,9 +104,6 @@
<ClCompile Include="..\source\engine.cpp">
<Filter>source</Filter>
</ClCompile>
<ClCompile Include="..\source\netmsg.cpp">
<Filter>source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="yapb.rc">

View file

@ -25,7 +25,6 @@ LOCAL_SRC_FILES := \
engine.cpp \
interface.cpp \
navigate.cpp \
netmsg.cpp \
support.cpp \
waypoint.cpp \

View file

@ -59,7 +59,7 @@ void Bot::PushMessageQueue (int message)
if (otherBot != NULL && otherBot->pev != pev)
{
if (m_notKilled == IsAlive (otherBot->GetEntity ()))
if (m_notKilled == otherBot->m_notKilled)
{
otherBot->m_sayTextBuffer.entityIndex = entityIndex;
strcpy (otherBot->m_sayTextBuffer.sayText, m_tempStrings);
@ -482,7 +482,7 @@ edict_t *Bot::FindBreakable (void)
// this function checks if bot is blocked by a shoot able breakable in his moving direction
TraceResult tr;
engine.TestLine (pev->origin, pev->origin + (m_destOrigin - pev->origin).Normalize () * 64.0f, TRACE_IGNORE_NONE, GetEntity (), &tr);
engine.TestLine (pev->origin, pev->origin + (m_destOrigin - pev->origin).Normalize () * 72.0f, TRACE_IGNORE_NONE, GetEntity (), &tr);
if (tr.flFraction != 1.0f)
{
@ -491,11 +491,11 @@ edict_t *Bot::FindBreakable (void)
// check if this isn't a triggered (bomb) breakable and if it takes damage. if true, shoot the crap!
if (IsShootableBreakable (ent))
{
m_breakable = tr.vecEndPos;
m_breakableOrigin = engine.GetAbsOrigin (ent);
return ent;
}
}
engine.TestLine (EyePosition (), EyePosition () + (m_destOrigin - EyePosition ()).Normalize () * 64.0f, TRACE_IGNORE_NONE, GetEntity (), &tr);
engine.TestLine (EyePosition (), EyePosition () + (m_destOrigin - EyePosition ()).Normalize () * 72.0f, TRACE_IGNORE_NONE, GetEntity (), &tr);
if (tr.flFraction != 1.0f)
{
@ -503,12 +503,12 @@ edict_t *Bot::FindBreakable (void)
if (IsShootableBreakable (ent))
{
m_breakable = tr.vecEndPos;
m_breakableOrigin = engine.GetAbsOrigin (ent);
return ent;
}
}
m_breakableEntity = NULL;
m_breakable.Zero ();
m_breakableOrigin.Zero ();
return NULL;
}
@ -971,7 +971,7 @@ void Bot::SwitchChatterIcon (bool show)
if (!(g_clients[i].flags & CF_USED) || (g_clients[i].ent->v.flags & FL_FAKECLIENT) || g_clients[i].team != m_team)
continue;
MESSAGE_BEGIN (MSG_ONE, netmsg.GetId (NETMSG_BOTVOICE), NULL, g_clients[i].ent); // begin message
MESSAGE_BEGIN (MSG_ONE, engine.FindMessageId (NETMSG_BOTVOICE), NULL, g_clients[i].ent); // begin message
WRITE_BYTE (show); // switch on/off
WRITE_BYTE (GetIndex ());
MESSAGE_END ();
@ -1009,7 +1009,7 @@ void Bot::InstantChatterMessage (int type)
g_sendAudioFinished = false;
MESSAGE_BEGIN (MSG_ONE, netmsg.GetId (NETMSG_SENDAUDIO), NULL, ent); // begin message
MESSAGE_BEGIN (MSG_ONE, engine.FindMessageId (NETMSG_SENDAUDIO), NULL, ent); // begin message
WRITE_BYTE (GetIndex ());
if (pev->deadflag & DEAD_DYING)
@ -1071,13 +1071,13 @@ void Bot::CheckMessageQueue (void)
return;
// get message from stack
int currentQueueMessage = GetMessageQueue ();
int state = GetMessageQueue ();
// nothing to do?
if (currentQueueMessage == GSM_IDLE || (currentQueueMessage == GSM_RADIO && yb_csdm_mode.GetInt () == 2))
if (state == GSM_IDLE || (state == GSM_RADIO && yb_csdm_mode.GetInt () == 2))
return;
switch (currentQueueMessage)
switch (state)
{
case GSM_BUY_STUFF: // general buy message
@ -2907,7 +2907,7 @@ void Bot::Think (void)
if (m_thinkFps <= engine.Time ())
{
// execute delayed think
ThinkDelayed ();
ThinkFrame ();
// skip some frames
m_thinkFps = engine.Time () + m_thinkInterval;
@ -2916,7 +2916,7 @@ void Bot::Think (void)
UpdateLookAngles ();
}
void Bot::ThinkDelayed (void)
void Bot::ThinkFrame (void)
{
pev->button = 0;
pev->flags |= FL_FAKECLIENT; // restore fake client bit, if it were removed by some evil action =)
@ -4395,7 +4395,7 @@ void Bot::RunTask_ShootBreakable (void)
m_moveToGoal = false;
m_navTimeset = engine.Time ();
Vector src = m_breakable;
Vector src = m_breakableOrigin;
m_camp = src;
// is bot facing the breakable?
@ -5322,18 +5322,18 @@ void Bot::TakeDamage (edict_t *inflictor, int damage, int armor, int bits)
}
}
void Bot::TakeBlinded (const Vector &fade, int alpha)
void Bot::TakeBlinded (int r, int g, int b, int alpha)
{
// this function gets called by network message handler, when screenfade message get's send
// it's used to make bot blind from the grenade.
if (fade.x != 255.0f || fade.y != 255.0f || fade.z != 255.0f || alpha <= 170.0f)
if (r != 255 || g != 255 || b != 255 || alpha <= 170)
return;
m_enemy = NULL;
m_maxViewDistance = Random.Float (10.0f, 20.0f);
m_blindTime = engine.Time () + static_cast <float> (alpha - 200.0f) / 16.0f;
m_blindTime = engine.Time () + static_cast <float> (alpha - 200) / 16.0f;
if (m_difficulty <= 2)
{
@ -5577,13 +5577,13 @@ void Bot::DebugMsg (const char *format, ...)
return;
va_list ap;
char buffer[1024];
char buffer[MAX_PRINT_BUFFER];
va_start (ap, format);
vsprintf (buffer, format, ap);
vsnprintf (buffer, SIZEOF_CHAR (buffer), format, ap);
va_end (ap);
char printBuf[1024];
char printBuf[MAX_PRINT_BUFFER];
sprintf (printBuf, "%s: %s", STRING (pev->netname), buffer);
bool playMessage = false;
@ -5618,7 +5618,7 @@ Vector Bot::CheckToss(const Vector &start, const Vector &stop)
return Vector::GetZero ();
Vector midPoint = start + (end - start) * 0.5f;
engine.TestHull (midPoint, midPoint + Vector (0.0f, 0.0f, 500.0f), TRACE_IGNORE_MONSTERS, head_hull, ENT (pev), &tr);
engine.TestHull (midPoint, midPoint + Vector (0.0f, 0.0f, 500.0f), TRACE_IGNORE_MONSTERS, head_hull, GetEntity (), &tr);
if (tr.flFraction < 1.0f)
{
@ -5641,12 +5641,12 @@ Vector Bot::CheckToss(const Vector &start, const Vector &stop)
Vector apex = start + nadeVelocity * timeOne;
apex.z = midPoint.z;
engine.TestHull (start, apex, TRACE_IGNORE_NONE, head_hull, ENT (pev), &tr);
engine.TestHull (start, apex, TRACE_IGNORE_NONE, head_hull, GetEntity (), &tr);
if (tr.flFraction < 1.0f || tr.fAllSolid)
return Vector::GetZero ();
engine.TestHull (end, apex, TRACE_IGNORE_MONSTERS, head_hull, ENT (pev), &tr);
engine.TestHull (end, apex, TRACE_IGNORE_MONSTERS, head_hull, GetEntity (), &tr);
if (tr.flFraction != 1.0f)
{

View file

@ -345,7 +345,7 @@ bool Bot::LookupEnemy (void)
Bot *friendBot = bots.GetBot (g_clients[j].ent);
if (friendBot != NULL && friendBot->m_seeEnemyTime + 2.0f < engine.Time () && engine.IsNullEntity (friendBot->m_lastEnemy) && IsVisible (pev->origin, ENT (friendBot->pev)) && friendBot->IsInViewCone (pev->origin))
if (friendBot != NULL && friendBot->m_seeEnemyTime + 2.0f < engine.Time () && engine.IsNullEntity (friendBot->m_lastEnemy) && IsVisible (pev->origin, friendBot->GetEntity ()) && friendBot->IsInViewCone (pev->origin))
{
friendBot->m_lastEnemy = newEnemy;
friendBot->m_lastEnemyOrigin = m_lastEnemyOrigin;

View file

@ -9,6 +9,27 @@
#include <core.h>
Engine::Engine (void)
{
m_startEntity = NULL;
m_localEntity = NULL;
m_language.RemoveAll ();
ResetMessageCapture ();
for (int i = 0; i < NETMSG_NUM; i++)
m_msgBlock.regMsgs[i] = NETMSG_UNDEFINED;
}
Engine::~Engine (void)
{
TerminateTranslator ();
ResetMessageCapture ();
for (int i = 0; i < NETMSG_NUM; i++)
m_msgBlock.regMsgs[i] = NETMSG_UNDEFINED;
}
void Engine::Precache (edict_t *startEntity)
{
// this function precaches needed models and initialize class variables
@ -29,10 +50,10 @@ void Engine::Printf (const char *fmt, ...)
// this function outputs string into server console
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
va_start (ap, fmt);
vsnprintf (string, SIZEOF_CHAR (string), locale.TranslateInput (fmt), ap);
vsnprintf (string, SIZEOF_CHAR (string), TraslateMessage (fmt), ap);
va_end (ap);
g_engfuncs.pfnServerPrint (string);
@ -42,20 +63,20 @@ void Engine::Printf (const char *fmt, ...)
void Engine::ChatPrintf (const char *fmt, ...)
{
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
va_start (ap, fmt);
vsnprintf (string, SIZEOF_CHAR (string), locale.TranslateInput (fmt), ap);
vsnprintf (string, SIZEOF_CHAR (string), TraslateMessage (fmt), ap);
va_end (ap);
if (IsDedicatedServer ())
{
engine.Printf (string);
Printf (string);
return;
}
strcat (string, "\n");
MESSAGE_BEGIN (MSG_BROADCAST, netmsg.GetId (NETMSG_TEXTMSG));
MESSAGE_BEGIN (MSG_BROADCAST, FindMessageId (NETMSG_TEXTMSG));
WRITE_BYTE (HUD_PRINTTALK);
WRITE_STRING (string);
MESSAGE_END ();
@ -64,20 +85,20 @@ void Engine::ChatPrintf (const char *fmt, ...)
void Engine::CenterPrintf (const char *fmt, ...)
{
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
va_start (ap, fmt);
vsnprintf (string, SIZEOF_CHAR (string), locale.TranslateInput (fmt), ap);
vsnprintf (string, SIZEOF_CHAR (string), TraslateMessage (fmt), ap);
va_end (ap);
if (IsDedicatedServer ())
{
engine.Printf (string);
Printf (string);
return;
}
strcat (string, "\n");
MESSAGE_BEGIN (MSG_BROADCAST, netmsg.GetId (NETMSG_TEXTMSG));
MESSAGE_BEGIN (MSG_BROADCAST, FindMessageId (NETMSG_TEXTMSG));
WRITE_BYTE (HUD_PRINTCENTER);
WRITE_STRING (string);
MESSAGE_END ();
@ -86,15 +107,15 @@ void Engine::CenterPrintf (const char *fmt, ...)
void Engine::ClientPrintf (edict_t *ent, const char *fmt, ...)
{
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
va_start (ap, fmt);
vsnprintf (string, SIZEOF_CHAR (string), locale.TranslateInput (fmt), ap);
vsnprintf (string, SIZEOF_CHAR (string), TraslateMessage (fmt), ap);
va_end (ap);
if (engine.IsNullEntity (ent) || ent == g_hostEntity)
if (IsNullEntity (ent) || ent == g_hostEntity)
{
engine.Printf (string);
Printf (string);
return;
}
strcat (string, "\n");
@ -279,7 +300,7 @@ Vector Engine::GetAbsOrigin (edict_t *ent)
// this expanded function returns the vector origin of a bounded entity, assuming that any
// entity that has a bounding box has its center at the center of the bounding box itself.
if (engine.IsNullEntity (ent))
if (IsNullEntity (ent))
return Vector::GetZero ();
if (ent->v.origin.IsZero ())
@ -311,7 +332,7 @@ void Engine::IssueBotCommand (edict_t *ent, const char *fmt, ...)
// supply directly the whole string as if you were typing it in the bot's "console". It
// is supposed to work exactly like the pfnClientCommand (server-sided client command).
if (engine.IsNullEntity (ent))
if (IsNullEntity (ent))
return;
va_list ap;
@ -442,7 +463,7 @@ void Engine::IssueCmd (const char *fmt, ...)
// this function asks the engine to execute a server command
va_list ap;
static char string[1024];
char string[MAX_PRINT_BUFFER];
// concatenate all the arguments in one string
va_start (ap, fmt);
@ -453,7 +474,7 @@ void Engine::IssueCmd (const char *fmt, ...)
g_engfuncs.pfnServerCommand (string);
}
void ConVarWrapper::RegisterVariable(const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self)
void Engine::PushVariableToStack (const char *variable, const char *value, VarType varType, bool regMissing, ConVar *self)
{
// this function adds globally defined variable to registration stack
@ -477,16 +498,16 @@ void ConVarWrapper::RegisterVariable(const char *variable, const char *value, Va
pair.self = self;
pair.type = varType;
m_regs.Push (pair);
m_cvars.Push (pair);
}
void ConVarWrapper::PushRegisteredConVarsToEngine (bool gameVars)
void Engine::PushRegisteredConVarsToEngine (bool gameVars)
{
// this function pushes all added global variables to engine registration
FOR_EACH_AE (m_regs, i)
FOR_EACH_AE (m_cvars, i)
{
VarPair *ptr = &m_regs[i];
VarPair *ptr = &m_cvars[i];
if (ptr->type != VT_NOREGISTER)
{
@ -512,7 +533,526 @@ void ConVarWrapper::PushRegisteredConVarsToEngine (bool gameVars)
}
}
char *Engine::TraslateMessage (const char *input)
{
// this function translate input string into needed language
if (IsDedicatedServer ())
return const_cast <char *> (&input[0]);
static char string[MAX_PRINT_BUFFER];
const char *ptr = input + strlen (input) - 1;
while (ptr > input && *ptr == '\n')
ptr--;
if (ptr != input)
ptr++;
strncpy (string, input, SIZEOF_CHAR (string));
String::TrimExternalBuffer (string);
FOR_EACH_AE (m_language, i)
{
if (strcmp (string, m_language[i].original) == 0)
{
strncpy (string, m_language[i].translated, SIZEOF_CHAR (string));
if (ptr != input)
strncat (string, ptr, MAX_PRINT_BUFFER - 1 - strlen (string));
return &string[0];
}
}
return const_cast <char *> (&input[0]); // nothing found
}
void Engine::TerminateTranslator (void)
{
// this function terminates language translator and frees all memory
FOR_EACH_AE (m_language, it)
{
delete[] m_language[it].original;
delete[] m_language[it].translated;
}
m_language.RemoveAll ();
}
void Engine::ProcessMesageCapture (void *ptr)
{
if (m_msgBlock.msg == NETMSG_UNDEFINED)
return;
// some needed variables
static byte r, g, b;
static byte enabled;
static int damageArmor, damageTaken, damageBits;
static int killerIndex, victimIndex, playerIndex;
static int index, numPlayers;
static int state, id, clip;
static Vector damageOrigin;
static WeaponProperty weaponProp;
// some widely used stuff
Bot *bot = bots.GetBot (m_msgBlock.bot);
char *strVal = reinterpret_cast <char *> (ptr);
int intVal = *reinterpret_cast <int *> (ptr);
unsigned char byteVal = *reinterpret_cast <unsigned char *> (ptr);
// now starts of network message execution
switch (m_msgBlock.msg)
{
case NETMSG_VGUI:
// this message is sent when a VGUI menu is displayed.
if (m_msgBlock.state == 0)
{
switch (intVal)
{
case VMS_TEAM:
bot->m_startAction = GSM_TEAM_SELECT;
break;
case VMS_TF:
case VMS_CT:
bot->m_startAction = GSM_CLASS_SELECT;
break;
}
}
break;
case NETMSG_SHOWMENU:
// this message is sent when a text menu is displayed.
if (m_msgBlock.state < 3) // ignore first 3 fields of message
break;
if (strcmp (strVal, "#Team_Select") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#Team_Select_Spect") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#IG_Team_Select_Spect") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#IG_Team_Select") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#IG_VIP_Team_Select") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#IG_VIP_Team_Select_Spect") == 0) // team select menu?
bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (strVal, "#Terrorist_Select") == 0) // T model select?
bot->m_startAction = GSM_CLASS_SELECT;
else if (strcmp (strVal, "#CT_Select") == 0) // CT model select menu?
bot->m_startAction = GSM_CLASS_SELECT;
break;
case NETMSG_WEAPONLIST:
// this message is sent when a client joins the game. All of the weapons are sent with the weapon ID and information about what ammo is used.
switch (m_msgBlock.state)
{
case 0:
strncpy (weaponProp.className, strVal, SIZEOF_CHAR (weaponProp.className));
break;
case 1:
weaponProp.ammo1 = intVal; // ammo index 1
break;
case 2:
weaponProp.ammo1Max = intVal; // max ammo 1
break;
case 5:
weaponProp.slotID = intVal; // slot for this weapon
break;
case 6:
weaponProp.position = intVal; // position in slot
break;
case 7:
weaponProp.id = intVal; // weapon ID
break;
case 8:
weaponProp.flags = intVal; // flags for weapon (WTF???)
g_weaponDefs[weaponProp.id] = weaponProp; // store away this weapon with it's ammo information...
break;
}
break;
case NETMSG_CURWEAPON:
// this message is sent when a weapon is selected (either by the bot chosing a weapon or by the server auto assigning the bot a weapon). In CS it's also called when Ammo is increased/decreased
switch (m_msgBlock.state)
{
case 0:
state = intVal; // state of the current weapon (WTF???)
break;
case 1:
id = intVal; // weapon ID of current weapon
break;
case 2:
clip = intVal; // ammo currently in the clip for this weapon
if (id <= 31)
{
if (state != 0)
bot->m_currentWeapon = id;
// ammo amount decreased ? must have fired a bullet...
if (id == bot->m_currentWeapon && bot->m_ammoInClip[id] > clip)
bot->m_timeLastFired = Time (); // remember the last bullet time
bot->m_ammoInClip[id] = clip;
}
break;
}
break;
case NETMSG_AMMOX:
// this message is sent whenever ammo amounts are adjusted (up or down). NOTE: Logging reveals that CS uses it very unreliable!
switch (m_msgBlock.state)
{
case 0:
index = intVal; // ammo index (for type of ammo)
break;
case 1:
bot->m_ammo[index] = intVal; // store it away
break;
}
break;
case NETMSG_AMMOPICKUP:
// this message is sent when the bot picks up some ammo (AmmoX messages are also sent so this message is probably
// not really necessary except it allows the HUD to draw pictures of ammo that have been picked up. The bots
// don't really need pictures since they don't have any eyes anyway.
switch (m_msgBlock.state)
{
case 0:
index = intVal;
break;
case 1:
bot->m_ammo[index] = intVal;
break;
}
break;
case NETMSG_DAMAGE:
// this message gets sent when the bots are getting damaged.
switch (m_msgBlock.state)
{
case 0:
damageArmor = intVal;
break;
case 1:
damageTaken = intVal;
break;
case 2:
damageBits = intVal;
if (bot != NULL && (damageArmor > 0 || damageTaken > 0))
bot->TakeDamage (bot->pev->dmg_inflictor, damageTaken, damageArmor, damageBits);
break;
}
break;
case NETMSG_MONEY:
// this message gets sent when the bots money amount changes
if (m_msgBlock.state == 0)
bot->m_moneyAmount = intVal; // amount of money
break;
case NETMSG_STATUSICON:
switch (m_msgBlock.state)
{
case 0:
enabled = byteVal;
break;
case 1:
if (strcmp (strVal, "defuser") == 0)
bot->m_hasDefuser = (enabled != 0);
else if (strcmp (strVal, "buyzone") == 0)
{
bot->m_inBuyZone = (enabled != 0);
// try to equip in buyzone
bot->EquipInBuyzone (BUYSTATE_PRIMARY_WEAPON);
}
else if (strcmp (strVal, "vipsafety") == 0)
bot->m_inVIPZone = (enabled != 0);
else if (strcmp (strVal, "c4") == 0)
bot->m_inBombZone = (enabled == 2);
break;
}
break;
case NETMSG_DEATH: // this message sends on death
switch (m_msgBlock.state)
{
case 0:
killerIndex = intVal;
break;
case 1:
victimIndex = intVal;
break;
case 2:
bots.SetDeathMsgState (true);
if (killerIndex != 0 && killerIndex != victimIndex)
{
edict_t *killer = EntityOfIndex (killerIndex);
edict_t *victim = EntityOfIndex (victimIndex);
if (IsNullEntity (killer) || IsNullEntity (victim))
break;
if (yb_communication_type.GetInt () == 2)
{
// need to send congrats on well placed shot
for (int i = 0; i < MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_notKilled && killer != bot->GetEntity () && bot->EntityIsVisible (victim->v.origin) && GetTeam (killer) == bot->m_team && GetTeam (killer) != GetTeam (victim))
{
if (killer == g_hostEntity)
bot->HandleChatterMessage ("#Bot_NiceShotCommander");
else
bot->HandleChatterMessage ("#Bot_NiceShotPall");
break;
}
}
}
// notice nearby to victim teammates, that attacker is near
for (int i = 0; i < MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_seeEnemyTime + 2.0f < Time () && bot->m_notKilled && bot->m_team == GetTeam (victim) && IsVisible (killer->v.origin, bot->GetEntity ()) && IsNullEntity (bot->m_enemy) && GetTeam (killer) != GetTeam (victim))
{
bot->m_actualReactionTime = 0.0f;
bot->m_seeEnemyTime = Time ();
bot->m_enemy = killer;
bot->m_lastEnemy = killer;
bot->m_lastEnemyOrigin = killer->v.origin;
}
}
Bot *bot = bots.GetBot (killer);
// is this message about a bot who killed somebody?
if (bot != NULL)
bot->m_lastVictim = victim;
else // did a human kill a bot on his team?
{
Bot *target = bots.GetBot (victim);
if (target != NULL)
{
if (GetTeam (killer) == GetTeam (victim))
target->m_voteKickIndex = killerIndex;
target->m_notKilled = false;
}
}
}
break;
}
break;
case NETMSG_SCREENFADE: // this message gets sent when the screen fades (flashbang)
switch (m_msgBlock.state)
{
case 3:
r = byteVal;
break;
case 4:
g = byteVal;
break;
case 5:
b = byteVal;
break;
case 6:
bot->TakeBlinded (r, g, b, byteVal);
break;
}
break;
case NETMSG_HLTV: // round restart in steam cs
switch (m_msgBlock.state)
{
case 0:
numPlayers = intVal;
break;
case 1:
if (numPlayers == 0 && intVal == 0)
RoundInit ();
break;
}
break;
case NETMSG_TEXTMSG:
if (m_msgBlock.state == 1)
{
if (FStrEq (strVal, "#CTs_Win") ||
FStrEq (strVal, "#Bomb_Defused") ||
FStrEq (strVal, "#Terrorists_Win") ||
FStrEq (strVal, "#Round_Draw") ||
FStrEq (strVal, "#All_Hostages_Rescued") ||
FStrEq (strVal, "#Target_Saved") ||
FStrEq (strVal, "#Hostages_Not_Rescued") ||
FStrEq (strVal, "#Terrorists_Not_Escaped") ||
FStrEq (strVal, "#VIP_Not_Escaped") ||
FStrEq (strVal, "#Escaping_Terrorists_Neutralized") ||
FStrEq (strVal, "#VIP_Assassinated") ||
FStrEq (strVal, "#VIP_Escaped") ||
FStrEq (strVal, "#Terrorists_Escaped") ||
FStrEq (strVal, "#CTs_PreventEscape") ||
FStrEq (strVal, "#Target_Bombed") ||
FStrEq (strVal, "#Game_Commencing") ||
FStrEq (strVal, "#Game_will_restart_in"))
{
g_roundEnded = true;
if (FStrEq (strVal, "#Game_Commencing"))
g_isCommencing = true;
if (FStrEq (strVal, "#CTs_Win"))
{
bots.SetLastWinner (CT); // update last winner for economics
if (yb_communication_type.GetInt () == 2)
{
Bot *bot = bots.FindOneValidAliveBot ();
if (bot != NULL && bot->m_notKilled)
bot->HandleChatterMessage (strVal);
}
}
if (FStrEq (strVal, "#Game_will_restart_in"))
{
bots.CheckTeamEconomics (CT, true);
bots.CheckTeamEconomics (TERRORIST, true);
}
if (FStrEq (strVal, "#Terrorists_Win"))
{
bots.SetLastWinner (TERRORIST); // update last winner for economics
if (yb_communication_type.GetInt () == 2)
{
Bot *bot = bots.FindOneValidAliveBot ();
if (bot != NULL && bot->m_notKilled)
bot->HandleChatterMessage (strVal);
}
}
waypoints.SetBombPosition (true);
}
else if (!g_bombPlanted && FStrEq (strVal, "#Bomb_Planted"))
{
waypoints.SetBombPosition ();
g_bombPlanted = g_bombSayString = true;
g_timeBombPlanted = Time ();
for (int i = 0; i < MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_notKilled)
{
bot->DeleteSearchNodes ();
bot->ResetTasks ();
if (yb_communication_type.GetInt () == 2 && Random.Long (0, 100) < 75 && bot->m_team == CT)
bot->ChatterMessage (Chatter_WhereIsTheBomb);
}
}
}
else if (bot != NULL && FStrEq (strVal, "#Switch_To_BurstFire"))
bot->m_weaponBurstMode = BM_ON;
else if (bot != NULL && FStrEq (strVal, "#Switch_To_SemiAuto"))
bot->m_weaponBurstMode = BM_OFF;
}
break;
case NETMSG_SCOREINFO:
switch (m_msgBlock.state)
{
case 0:
playerIndex = intVal;
break;
case 4:
if (playerIndex >= 0 && playerIndex <= MaxClients ())
{
#ifndef XASH_CSDM
Client &cl = g_clients[playerIndex - 1];
if (intVal == 1)
cl.realTeam = TERRORIST;
else if (intVal == 2)
cl.realTeam = CT;
else
cl.realTeam = SPECTATOR;
if (yb_csdm_mode.GetInt () == 2)
cl.team = playerIndex;
else
cl.team = cl.realTeam;
#endif
}
break;
}
break;
case NETMSG_BARTIME:
if (m_msgBlock.state == 0)
{
if (intVal > 0)
bot->m_hasProgressBar = true; // the progress bar on a hud
else if (intVal == 0)
bot->m_hasProgressBar = false; // no progress bar or disappeared
}
break;
default:
AddLogEntry (true, LL_FATAL, "Network message handler error. Call to unrecognized message id (%d).\n", m_msgBlock.msg);
}
m_msgBlock.state++; // and finally update network message state
}
ConVar::ConVar (const char *name, const char *initval, VarType type, bool regMissing) : m_eptr (NULL)
{
ConVarWrapper::GetReference ().RegisterVariable (name, initval, type, regMissing, this);
engine.PushVariableToStack (name, initval, type, regMissing, this);
}

View file

@ -9,6 +9,13 @@
#include <core.h>
// forward for super-globals
//NetworkMsg netmsg;
//Localizer locale;
//Waypoint waypoints;
//BotManager bots;
//Engine engine;
bool g_canSayBombPlanted = true;
bool g_isMetamod = false;
bool g_radioInsteadVoice = false;
@ -98,10 +105,10 @@ int *g_weaponPrefs[] =
// metamod engine & dllapi function tables
metamod_funcs_t gMetaFunctionTable =
{
NULL, // pfnEntityAPI_t ()
NULL, // pfnEntityAPI_t_Post ()
GetEntityAPI2, // pfnEntityAPI_t2 ()
GetEntityAPI2_Post, // pfnEntityAPI_t2_Post ()
NULL, // pfnGetEntityAPI ()
NULL, // pfnGetEntityAPI_Post ()
GetEntityAPI2, // pfnGetEntityAPI2 ()
GetEntityAPI2_Post, // pfnGetEntityAPI2_Post ()
NULL, // pfnGetNewDLLFunctions ()
NULL, // pfnGetNewDLLFunctions_Post ()
GetEngineFunctions, // pfnGetEngineFunctions ()
@ -424,10 +431,3 @@ MenuText g_menus[21] =
"0. Exit"
}
};
// forward for super-globals
NetworkMsg netmsg;
Localizer locale;
Waypoint waypoints;
BotManager bots;
Engine engine;

View file

@ -1,4 +1,4 @@
//
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team.
//
@ -300,7 +300,7 @@ int BotCommandHandler (edict_t *ent, const char *arg0, const char *arg1, const c
// save waypoint data into file on hard disk
else if (stricmp (arg1, "save") == 0)
{
char *waypointSaveMessage = locale.TranslateInput ("Waypoints Saved");
char *waypointSaveMessage = engine.TraslateMessage ("Waypoints Saved");
if (FStrEq (arg2, "nocheck"))
{
@ -850,7 +850,7 @@ void InitConfig (void)
enum Lang { Lang_Original, Lang_Translate } langState = static_cast <Lang> (2);
char buffer[1024];
LanguageItem temp = {"", ""};
Engine::TranslatorPair temp = {"", ""};
while (fp.GetBuffer (line, 255))
{
@ -866,7 +866,7 @@ void InitConfig (void)
}
if (!IsNullString (temp.translated) && !IsNullString (temp.original))
locale.m_langTab.Push (temp);
engine.PushTranslationPair (temp);
}
else if (strncmp (line, "[TRANSLATED]", 12) == 0)
{
@ -1013,8 +1013,7 @@ int Spawn (edict_t *ent)
if (strcmp (entityClassname, "worldspawn") == 0)
{
engine.Precache (ent);
ConVarWrapper::GetReference ().PushRegisteredConVarsToEngine (true);
engine.PushRegisteredConVarsToEngine (true);
PRECACHE_SOUND (ENGINE_STR ("weapons/xbow_hit1.wav")); // waypoint add
PRECACHE_SOUND (ENGINE_STR ("weapons/mine_activate.wav")); // waypoint delete
@ -1024,7 +1023,7 @@ int Spawn (edict_t *ent)
PRECACHE_SOUND (ENGINE_STR ("common/wpn_denyselect.wav")); // path add/delete error
RoundInit ();
g_mapType = NULL; // reset map type as worldspawn is the first entity spawned
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)
@ -2071,7 +2070,7 @@ void ClientCommand (edict_t *ent)
Bot *bot = bots.GetBot (i);
// validate bot
if (bot != NULL && bot->m_team == g_clients[clientIndex].team && VARS (ent) != bot->pev && bot->m_radioOrder == 0)
if (bot != NULL && bot->m_team == g_clients[clientIndex].team && ent != bot->GetEntity () && bot->m_radioOrder == 0)
{
bot->m_radioOrder = radioCommand;
bot->m_radioEntity = ent;
@ -2370,7 +2369,7 @@ void pfnEmitSound (edict_t *entity, int channel, const char *sample, float volum
(*g_engfuncs.pfnEmitSound) (entity, channel, sample, volume, attenuation, flags, pitch);
}
void pfnClientCommand (edict_t *ent, char *format, ...)
void pfnClientCommand (edict_t *ent, char const *format, ...)
{
// this function forces the client whose player entity is ent to issue a client command.
// How it works is that clients all have a g_xgv global string in their client DLL that
@ -2413,69 +2412,67 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed
// this function called each time a message is about to sent.
// store the message type in our own variables, since the GET_USER_MSG_ID () will just do a lot of strcmp()'s...
if (g_isMetamod && netmsg.GetId (NETMSG_MONEY) == -1)
if (g_isMetamod && engine.FindMessageId (NETMSG_MONEY) == -1)
{
netmsg.SetId (NETMSG_VGUI, GET_USER_MSG_ID (PLID, "VGUIMenu", NULL));
netmsg.SetId (NETMSG_SHOWMENU, GET_USER_MSG_ID (PLID, "ShowMenu", NULL));
netmsg.SetId (NETMSG_WEAPONLIST, GET_USER_MSG_ID (PLID, "WeaponList", NULL));
netmsg.SetId (NETMSG_CURWEAPON, GET_USER_MSG_ID (PLID, "CurWeapon", NULL));
netmsg.SetId (NETMSG_AMMOX, GET_USER_MSG_ID (PLID, "AmmoX", NULL));
netmsg.SetId (NETMSG_AMMOPICKUP, GET_USER_MSG_ID (PLID, "AmmoPickup", NULL));
netmsg.SetId (NETMSG_DAMAGE, GET_USER_MSG_ID (PLID, "Damage", NULL));
netmsg.SetId (NETMSG_MONEY, GET_USER_MSG_ID (PLID, "Money", NULL));
netmsg.SetId (NETMSG_STATUSICON, GET_USER_MSG_ID (PLID, "StatusIcon", NULL));
netmsg.SetId (NETMSG_DEATH, GET_USER_MSG_ID (PLID, "DeathMsg", NULL));
netmsg.SetId (NETMSG_SCREENFADE, GET_USER_MSG_ID (PLID, "ScreenFade", NULL));
netmsg.SetId (NETMSG_HLTV, GET_USER_MSG_ID (PLID, "HLTV", NULL));
netmsg.SetId (NETMSG_TEXTMSG, GET_USER_MSG_ID (PLID, "TextMsg", NULL));
netmsg.SetId (NETMSG_SCOREINFO, GET_USER_MSG_ID (PLID, "ScoreInfo", NULL));
netmsg.SetId (NETMSG_BARTIME, GET_USER_MSG_ID (PLID, "BarTime", NULL));
netmsg.SetId (NETMSG_SENDAUDIO, GET_USER_MSG_ID (PLID, "SendAudio", NULL));
netmsg.SetId (NETMSG_SAYTEXT, GET_USER_MSG_ID (PLID, "SayText", NULL));
netmsg.SetId (NETMSG_RESETHUD, GET_USER_MSG_ID (PLID, "ResetHUD", NULL));
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));
if (!(g_gameFlags & GAME_LEGACY))
netmsg.SetId (NETMSG_BOTVOICE, GET_USER_MSG_ID (PLID, "BotVoice", NULL));
engine.AssignMessageId (NETMSG_BOTVOICE, GET_USER_MSG_ID (PLID, "BotVoice", NULL));
}
netmsg.Reset ();
engine.ResetMessageCapture ();
if (msgDest == MSG_SPEC && msgType == netmsg.GetId (NETMSG_HLTV) && !(g_gameFlags & GAME_LEGACY))
netmsg.SetMessage (NETMSG_HLTV);
if ((!(g_gameFlags & GAME_LEGACY) || (g_gameFlags & GAME_XASH)) && msgDest == MSG_SPEC && msgType == engine.FindMessageId (NETMSG_HLTV))
engine.SetOngoingMessageId (NETMSG_HLTV);
netmsg.HandleMessageIfRequired (msgType, NETMSG_WEAPONLIST);
engine.TryCaptureMessage (msgType, NETMSG_WEAPONLIST);
if (!engine.IsNullEntity (ed))
{
int index = bots.GetIndex (ed);
// is this message for a bot?
if (index != -1 && !(ed->v.flags & FL_DORMANT) && bots.GetBot (index)->GetEntity () == ed)
if (index != -1 && !(ed->v.flags & FL_DORMANT))
{
netmsg.Reset ();
netmsg.SetBot (bots.GetBot (index));
engine.ResetMessageCapture ();
engine.SetOngoingMessageReceiver (index);
// message handling is done in usermsg.cpp
netmsg.HandleMessageIfRequired (msgType, NETMSG_VGUI);
netmsg.HandleMessageIfRequired (msgType, NETMSG_CURWEAPON);
netmsg.HandleMessageIfRequired (msgType, NETMSG_AMMOX);
netmsg.HandleMessageIfRequired (msgType, NETMSG_AMMOPICKUP);
netmsg.HandleMessageIfRequired (msgType, NETMSG_DAMAGE);
netmsg.HandleMessageIfRequired (msgType, NETMSG_MONEY);
netmsg.HandleMessageIfRequired (msgType, NETMSG_STATUSICON);
netmsg.HandleMessageIfRequired (msgType, NETMSG_SCREENFADE);
netmsg.HandleMessageIfRequired (msgType, NETMSG_BARTIME);
netmsg.HandleMessageIfRequired (msgType, NETMSG_TEXTMSG);
netmsg.HandleMessageIfRequired (msgType, NETMSG_SHOWMENU);
netmsg.HandleMessageIfRequired (msgType, NETMSG_RESETHUD);
engine.TryCaptureMessage (msgType, NETMSG_VGUI);
engine.TryCaptureMessage (msgType, NETMSG_CURWEAPON);
engine.TryCaptureMessage (msgType, NETMSG_AMMOX);
engine.TryCaptureMessage (msgType, NETMSG_AMMOPICKUP);
engine.TryCaptureMessage (msgType, NETMSG_DAMAGE);
engine.TryCaptureMessage (msgType, NETMSG_MONEY);
engine.TryCaptureMessage (msgType, NETMSG_STATUSICON);
engine.TryCaptureMessage (msgType, NETMSG_SCREENFADE);
engine.TryCaptureMessage (msgType, NETMSG_BARTIME);
engine.TryCaptureMessage (msgType, NETMSG_TEXTMSG);
engine.TryCaptureMessage (msgType, NETMSG_SHOWMENU);
}
}
else if (msgDest == MSG_ALL)
{
netmsg.Reset ();
engine.ResetMessageCapture ();
netmsg.HandleMessageIfRequired (msgType, NETMSG_SCOREINFO);
netmsg.HandleMessageIfRequired (msgType, NETMSG_DEATH);
netmsg.HandleMessageIfRequired (msgType, NETMSG_TEXTMSG);
engine.TryCaptureMessage (msgType, NETMSG_SCOREINFO);
engine.TryCaptureMessage (msgType, NETMSG_DEATH);
engine.TryCaptureMessage (msgType, NETMSG_TEXTMSG);
if (msgType == SVC_INTERMISSION)
{
@ -2497,7 +2494,7 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed
void pfnMessageEnd (void)
{
netmsg.Reset ();
engine.ResetMessageCapture ();
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2519,7 +2516,7 @@ void pfnMessageEnd_Post (void)
void pfnWriteByte (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2530,7 +2527,7 @@ void pfnWriteByte (int value)
void pfnWriteChar (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2541,7 +2538,7 @@ void pfnWriteChar (int value)
void pfnWriteShort (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2552,7 +2549,7 @@ void pfnWriteShort (int value)
void pfnWriteLong (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2563,7 +2560,7 @@ void pfnWriteLong (int value)
void pfnWriteAngle (float value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2574,7 +2571,7 @@ void pfnWriteAngle (float value)
void pfnWriteCoord (float value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2585,7 +2582,7 @@ void pfnWriteCoord (float value)
void pfnWriteString (const char *sz)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) sz);
engine.ProcessMesageCapture ((void *) sz);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2596,7 +2593,7 @@ void pfnWriteString (const char *sz)
void pfnWriteEntity (int value)
{
// if this message is for a bot, call the client message function...
netmsg.Execute ((void *) &value);
engine.ProcessMesageCapture ((void *) &value);
if (g_isMetamod)
RETURN_META (MRES_IGNORED);
@ -2729,43 +2726,41 @@ int pfnRegUserMsg (const char *name, int size)
int message = REG_USER_MSG (name, size);
if (strcmp (name, "VGUIMenu") == 0)
netmsg.SetId (NETMSG_VGUI, message);
engine.AssignMessageId (NETMSG_VGUI, message);
else if (strcmp (name, "ShowMenu") == 0)
netmsg.SetId (NETMSG_SHOWMENU, message);
engine.AssignMessageId (NETMSG_SHOWMENU, message);
else if (strcmp (name, "WeaponList") == 0)
netmsg.SetId (NETMSG_WEAPONLIST, message);
engine.AssignMessageId (NETMSG_WEAPONLIST, message);
else if (strcmp (name, "CurWeapon") == 0)
netmsg.SetId (NETMSG_CURWEAPON, message);
engine.AssignMessageId (NETMSG_CURWEAPON, message);
else if (strcmp (name, "AmmoX") == 0)
netmsg.SetId (NETMSG_AMMOX, message);
engine.AssignMessageId (NETMSG_AMMOX, message);
else if (strcmp (name, "AmmoPickup") == 0)
netmsg.SetId (NETMSG_AMMOPICKUP, message);
engine.AssignMessageId (NETMSG_AMMOPICKUP, message);
else if (strcmp (name, "Damage") == 0)
netmsg.SetId (NETMSG_DAMAGE, message);
engine.AssignMessageId (NETMSG_DAMAGE, message);
else if (strcmp (name, "Money") == 0)
netmsg.SetId (NETMSG_MONEY, message);
engine.AssignMessageId (NETMSG_MONEY, message);
else if (strcmp (name, "StatusIcon") == 0)
netmsg.SetId (NETMSG_STATUSICON, message);
engine.AssignMessageId (NETMSG_STATUSICON, message);
else if (strcmp (name, "DeathMsg") == 0)
netmsg.SetId (NETMSG_DEATH, message);
engine.AssignMessageId (NETMSG_DEATH, message);
else if (strcmp (name, "ScreenFade") == 0)
netmsg.SetId (NETMSG_SCREENFADE, message);
engine.AssignMessageId (NETMSG_SCREENFADE, message);
else if (strcmp (name, "HLTV") == 0)
netmsg.SetId (NETMSG_HLTV, message);
engine.AssignMessageId (NETMSG_HLTV, message);
else if (strcmp (name, "TextMsg") == 0)
netmsg.SetId (NETMSG_TEXTMSG, message);
engine.AssignMessageId (NETMSG_TEXTMSG, message);
else if (strcmp (name, "ScoreInfo") == 0)
netmsg.SetId (NETMSG_SCOREINFO, message);
engine.AssignMessageId (NETMSG_SCOREINFO, message);
else if (strcmp (name, "BarTime") == 0)
netmsg.SetId (NETMSG_BARTIME, message);
engine.AssignMessageId (NETMSG_BARTIME, message);
else if (strcmp (name, "SendAudio") == 0)
netmsg.SetId (NETMSG_SENDAUDIO, message);
engine.AssignMessageId (NETMSG_SENDAUDIO, message);
else if (strcmp (name, "SayText") == 0)
netmsg.SetId (NETMSG_SAYTEXT, message);
engine.AssignMessageId (NETMSG_SAYTEXT, message);
else if (strcmp (name, "BotVoice") == 0)
netmsg.SetId (NETMSG_BOTVOICE, message);
else if (strcmp (name, "ResetHUD") == 0)
netmsg.SetId (NETMSG_RESETHUD, message);
engine.AssignMessageId (NETMSG_BOTVOICE, message);
return message;
}
@ -2776,7 +2771,7 @@ void pfnAlertMessage (ALERT_TYPE alertType, char *format, ...)
char buffer[1024];
va_start (ap, format);
vsprintf (buffer, format, ap);
vsnprintf (buffer, SIZEOF_CHAR (buffer), format, ap);
va_end (ap);
if ((g_mapType & MAP_DE) && g_bombPlanted && strstr (buffer, "_Defuse_") != NULL)
@ -2802,7 +2797,7 @@ void pfnAlertMessage (ALERT_TYPE alertType, char *format, ...)
gamedll_funcs_t gameDLLFunc;
export int GetEntityAPI2 (gamefuncs_t *functionTable, int *)
SHARED_LIBRARAY_EXPORT int GetEntityAPI2 (gamefuncs_t *functionTable, int *)
{
// this function is called right after FuncPointers_t() by the engine in the game DLL (or
// what it BELIEVES to be the game DLL), in order to copy the list of MOD functions that can
@ -2846,7 +2841,7 @@ export int GetEntityAPI2 (gamefuncs_t *functionTable, int *)
return TRUE;
}
export int GetEntityAPI2_Post (gamefuncs_t *functionTable, int *)
SHARED_LIBRARAY_EXPORT int GetEntityAPI2_Post (gamefuncs_t *functionTable, int *)
{
// this function is called right after FuncPointers_t() by the engine in the game DLL (or
// what it BELIEVES to be the game DLL), in order to copy the list of MOD functions that can
@ -2867,7 +2862,7 @@ export int GetEntityAPI2_Post (gamefuncs_t *functionTable, int *)
return TRUE;
}
export int GetNewDLLFunctions (newgamefuncs_t *functionTable, int *interfaceVersion)
SHARED_LIBRARAY_EXPORT int GetNewDLLFunctions (newgamefuncs_t *functionTable, int *interfaceVersion)
{
// it appears that an extra function table has been added in the engine to gamedll interface
// since the date where the first enginefuncs table standard was frozen. These ones are
@ -2888,7 +2883,7 @@ export int GetNewDLLFunctions (newgamefuncs_t *functionTable, int *interfaceVers
return TRUE;
}
export int GetEngineFunctions (enginefuncs_t *functionTable, int *)
SHARED_LIBRARAY_EXPORT int GetEngineFunctions (enginefuncs_t *functionTable, int *)
{
if (g_isMetamod)
memset (functionTable, 0, sizeof (enginefuncs_t));
@ -2918,7 +2913,7 @@ export int GetEngineFunctions (enginefuncs_t *functionTable, int *)
return TRUE;
}
export int GetEngineFunctions_Post (enginefuncs_t *functionTable, int *)
SHARED_LIBRARAY_EXPORT int GetEngineFunctions_Post (enginefuncs_t *functionTable, int *)
{
memset (functionTable, 0, sizeof (enginefuncs_t));
@ -2927,7 +2922,7 @@ export int GetEngineFunctions_Post (enginefuncs_t *functionTable, int *)
return TRUE;
}
export int Server_GetBlendingInterface (int version, void **ppinterface, void *pstudio, float (*rotationmatrix)[3][4], float (*bonetransform)[128][3][4])
SHARED_LIBRARAY_EXPORT int Server_GetBlendingInterface (int version, void **ppinterface, void *pstudio, float (*rotationmatrix)[3][4], float (*bonetransform)[128][3][4])
{
// this function synchronizes the studio model animation blending interface (i.e, what parts
// of the body move, which bones, which hitboxes and how) between the server and the game DLL.
@ -2939,7 +2934,7 @@ export int Server_GetBlendingInterface (int version, void **ppinterface, void *p
return (*g_serverBlendingAPI) (version, ppinterface, pstudio, rotationmatrix, bonetransform);
}
export int Meta_Query (char *, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
SHARED_LIBRARAY_EXPORT int Meta_Query (char *, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
{
// this function is the first function ever called by metamod in the plugin DLL. Its purpose
// is for metamod to retrieve basic information about the plugin, such as its meta-interface
@ -2951,7 +2946,7 @@ export int Meta_Query (char *, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUt
return TRUE; // tell metamod this plugin looks safe
}
export int Meta_Attach (PLUG_LOADTIME, metamod_funcs_t *functionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs)
SHARED_LIBRARAY_EXPORT int Meta_Attach (PLUG_LOADTIME, metamod_funcs_t *functionTable, meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs)
{
// this function is called when metamod attempts to load the plugin. Since it's the place
// where we can tell if the plugin will be allowed to run or not, we wait until here to make
@ -2965,7 +2960,7 @@ export int Meta_Attach (PLUG_LOADTIME, metamod_funcs_t *functionTable, meta_glob
return TRUE; // returning true enables metamod to attach this plugin
}
export int Meta_Detach (PLUG_LOADTIME, PL_UNLOAD_REASON)
SHARED_LIBRARAY_EXPORT int Meta_Detach (PLUG_LOADTIME, PL_UNLOAD_REASON)
{
// this function is called when metamod unloads the plugin. A basic check is made in order
// to prevent unloading the plugin if its processing should not be interrupted.
@ -2976,7 +2971,7 @@ export int Meta_Detach (PLUG_LOADTIME, PL_UNLOAD_REASON)
return TRUE;
}
export void Meta_Init (void)
SHARED_LIBRARAY_EXPORT void Meta_Init (void)
{
// this function is called by metamod, before any other interface functions. Purpose of this
// function to give plugin a chance to determine is plugin running under metamod or not.
@ -3002,7 +2997,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
g_pGlobals = pGlobals;
// register our cvars
ConVarWrapper::GetReference ().PushRegisteredConVarsToEngine ();
engine.PushRegisteredConVarsToEngine ();
// ensure we're have all needed directories
{
@ -3130,20 +3125,20 @@ DLL_ENTRYPOINT
DLL_RETENTRY; // the return data type is OS specific too
}
static void LinkEntity_Helper (EntityPtr_t &entAddress, const char *name, entvars_t *pev)
static void LinkEntity_Helper (EntityPtr_t &addr, const char *name, entvars_t *pev)
{
// here we're see an ugliest hack :)
if (entAddress == NULL || (g_gameFlags & GAME_OFFICIAL_CSBOT))
entAddress = g_gameLib->GetFuncAddr <EntityPtr_t > (name);
//if (addr == NULL || (g_gameFlags & GAME_OFFICIAL_CSBOT))
addr = g_gameLib->GetFuncAddr <EntityPtr_t > (name);
if (entAddress == NULL)
if (addr == NULL)
return;
entAddress (pev);
addr (pev);
}
#define LINK_ENTITY(entityName) \
export void entityName (entvars_t *pev) \
SHARED_LIBRARAY_EXPORT void entityName (entvars_t *pev) \
{ \
static EntityPtr_t addr = NULL; \
LinkEntity_Helper (addr, #entityName, pev); \

View file

@ -1114,7 +1114,7 @@ void Bot::NewRound (void)
m_itemCheckTime = 0.0f;
m_breakableEntity = NULL;
m_breakable.Zero ();
m_breakableOrigin.Zero ();
m_timeDoorOpen = 0.0f;
ResetCollideState ();

View file

@ -1,4 +1,4 @@
//
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team.
//
@ -441,7 +441,7 @@ void Bot::CheckTerrain (float movedDistance, const Vector &dirNormal)
state[i++] = COLLISION_STRAFELEFT;
state[i++] = COLLISION_STRAFERIGHT;
state[i++] = COLLISION_JUMP;
// state[i++] = COLLISION_DUCK;
state[i++] = COLLISION_DUCK;
if (bits & PROBE_STRAFE)
{
@ -1410,7 +1410,6 @@ public:
}
};
float gfunctionKillsDistT (int currentIndex, int parentIndex)
{
// least kills and number of nodes to goal for a team

View file

@ -1,499 +0,0 @@
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team.
//
// 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
//
#include <core.h>
NetworkMsg::NetworkMsg (void)
{
m_message = NETMSG_UNDEFINED;
m_state = 0;
m_bot = NULL;
for (int i = 0; i < NETMSG_NUM; i++)
m_registerdMessages[i] = -1;
}
void NetworkMsg::HandleMessageIfRequired (int messageType, int requiredType)
{
if (messageType == m_registerdMessages[requiredType])
SetMessage (requiredType);
}
void NetworkMsg::Execute (void *p)
{
if (m_message == NETMSG_UNDEFINED)
return; // no message or not for bot, return
// some needed variables
static byte r, g, b;
static byte enabled;
static int damageArmor, damageTaken, damageBits;
static int killerIndex, victimIndex, playerIndex;
static int index, numPlayers;
static int state, id, clip;
static Vector damageOrigin;
static WeaponProperty weaponProp;
// now starts of netmessage execution
switch (m_message)
{
case NETMSG_VGUI:
// this message is sent when a VGUI menu is displayed.
if (m_state == 0)
{
switch (PTR_TO_INT (p))
{
case VMS_TEAM:
m_bot->m_startAction = GSM_TEAM_SELECT;
break;
case VMS_TF:
case VMS_CT:
m_bot->m_startAction = GSM_CLASS_SELECT;
break;
}
}
break;
case NETMSG_SHOWMENU:
// this message is sent when a text menu is displayed.
if (m_state < 3) // ignore first 3 fields of message
break;
if (strcmp (PTR_TO_STR (p), "#Team_Select") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#Team_Select_Spect") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#IG_Team_Select_Spect") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#IG_Team_Select") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#IG_VIP_Team_Select") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#IG_VIP_Team_Select_Spect") == 0) // team select menu?
m_bot->m_startAction = GSM_TEAM_SELECT;
else if (strcmp (PTR_TO_STR (p), "#Terrorist_Select") == 0) // T model select?
m_bot->m_startAction = GSM_CLASS_SELECT;
else if (strcmp (PTR_TO_STR (p), "#CT_Select") == 0) // CT model select menu?
m_bot->m_startAction = GSM_CLASS_SELECT;
break;
case NETMSG_WEAPONLIST:
// this message is sent when a client joins the game. All of the weapons are sent with the weapon ID and information about what ammo is used.
switch (m_state)
{
case 0:
strncpy (weaponProp.className, PTR_TO_STR (p), SIZEOF_CHAR (weaponProp.className));
break;
case 1:
weaponProp.ammo1 = PTR_TO_INT (p); // ammo index 1
break;
case 2:
weaponProp.ammo1Max = PTR_TO_INT (p); // max ammo 1
break;
case 5:
weaponProp.slotID = PTR_TO_INT (p); // slot for this weapon
break;
case 6:
weaponProp.position = PTR_TO_INT (p); // position in slot
break;
case 7:
weaponProp.id = PTR_TO_INT (p); // weapon ID
break;
case 8:
weaponProp.flags = PTR_TO_INT (p); // flags for weapon (WTF???)
g_weaponDefs[weaponProp.id] = weaponProp; // store away this weapon with it's ammo information...
break;
}
break;
case NETMSG_CURWEAPON:
// this message is sent when a weapon is selected (either by the bot chosing a weapon or by the server auto assigning the bot a weapon). In CS it's also called when Ammo is increased/decreased
switch (m_state)
{
case 0:
state = PTR_TO_INT (p); // state of the current weapon (WTF???)
break;
case 1:
id = PTR_TO_INT (p); // weapon ID of current weapon
break;
case 2:
clip = PTR_TO_INT (p); // ammo currently in the clip for this weapon
if (id <= 31)
{
if (state != 0)
m_bot->m_currentWeapon = id;
// ammo amount decreased ? must have fired a bullet...
if (id == m_bot->m_currentWeapon && m_bot->m_ammoInClip[id] > clip)
m_bot->m_timeLastFired = engine.Time (); // remember the last bullet time
m_bot->m_ammoInClip[id] = clip;
}
break;
}
break;
case NETMSG_AMMOX:
// this message is sent whenever ammo amounts are adjusted (up or down). NOTE: Logging reveals that CS uses it very unreliable!
switch (m_state)
{
case 0:
index = PTR_TO_INT (p); // ammo index (for type of ammo)
break;
case 1:
m_bot->m_ammo[index] = PTR_TO_INT (p); // store it away
break;
}
break;
case NETMSG_AMMOPICKUP:
// this message is sent when the bot picks up some ammo (AmmoX messages are also sent so this message is probably
// not really necessary except it allows the HUD to draw pictures of ammo that have been picked up. The bots
// don't really need pictures since they don't have any eyes anyway.
switch (m_state)
{
case 0:
index = PTR_TO_INT (p);
break;
case 1:
m_bot->m_ammo[index] = PTR_TO_INT (p);
break;
}
break;
case NETMSG_DAMAGE:
// this message gets sent when the bots are getting damaged.
switch (m_state)
{
case 0:
damageArmor = PTR_TO_INT (p);
break;
case 1:
damageTaken = PTR_TO_INT (p);
break;
case 2:
damageBits = PTR_TO_INT (p);
if (m_bot != NULL && (damageArmor > 0 || damageTaken > 0))
m_bot->TakeDamage (m_bot->pev->dmg_inflictor, damageTaken, damageArmor, damageBits);
break;
}
break;
case NETMSG_MONEY:
// this message gets sent when the bots money amount changes
if (m_state == 0)
m_bot->m_moneyAmount = PTR_TO_INT (p); // amount of money
break;
case NETMSG_STATUSICON:
switch (m_state)
{
case 0:
enabled = PTR_TO_BYTE (p);
break;
case 1:
if (strcmp (PTR_TO_STR (p), "defuser") == 0)
m_bot->m_hasDefuser = (enabled != 0);
else if (strcmp (PTR_TO_STR (p), "buyzone") == 0)
{
m_bot->m_inBuyZone = (enabled != 0);
// try to equip in buyzone
m_bot->EquipInBuyzone (BUYSTATE_PRIMARY_WEAPON);
}
else if (strcmp (PTR_TO_STR (p), "vipsafety") == 0)
m_bot->m_inVIPZone = (enabled != 0);
else if (strcmp (PTR_TO_STR (p), "c4") == 0)
m_bot->m_inBombZone = (enabled == 2);
break;
}
break;
case NETMSG_DEATH: // this message sends on death
switch (m_state)
{
case 0:
killerIndex = PTR_TO_INT (p);
break;
case 1:
victimIndex = PTR_TO_INT (p);
break;
case 2:
bots.SetDeathMsgState (true);
if (killerIndex != 0 && killerIndex != victimIndex)
{
edict_t *killer = engine.EntityOfIndex (killerIndex);
edict_t *victim = engine.EntityOfIndex (victimIndex);
if (engine.IsNullEntity (killer) || engine.IsNullEntity (victim))
break;
if (yb_communication_type.GetInt () == 2)
{
// need to send congrats on well placed shot
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_notKilled && killer != bot->GetEntity () && bot->EntityIsVisible (victim->v.origin) && engine.GetTeam (killer) == bot->m_team && engine.GetTeam (killer) != engine.GetTeam (victim))
{
if (killer == g_hostEntity)
bot->HandleChatterMessage ("#Bot_NiceShotCommander");
else
bot->HandleChatterMessage ("#Bot_NiceShotPall");
break;
}
}
}
// notice nearby to victim teammates, that attacker is near
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_seeEnemyTime + 2.0f < engine.Time () && bot->m_notKilled && bot->m_team == engine.GetTeam (victim) && IsVisible (killer->v.origin, bot->GetEntity ()) && engine.IsNullEntity (bot->m_enemy) && engine.GetTeam (killer) != engine.GetTeam (victim))
{
bot->m_actualReactionTime = 0.0f;
bot->m_seeEnemyTime = engine.Time ();
bot->m_enemy = killer;
bot->m_lastEnemy = killer;
bot->m_lastEnemyOrigin = killer->v.origin;
}
}
Bot *bot = bots.GetBot (killer);
// is this message about a bot who killed somebody?
if (bot != NULL)
bot->m_lastVictim = victim;
else // did a human kill a bot on his team?
{
Bot *target = bots.GetBot (victim);
if (target != NULL)
{
if (engine.GetTeam (killer) == engine.GetTeam (victim))
target->m_voteKickIndex = killerIndex;
target->m_notKilled = false;
}
}
}
break;
}
break;
case NETMSG_SCREENFADE: // this message gets sent when the Screen fades (Flashbang)
switch (m_state)
{
case 3:
r = PTR_TO_BYTE (p);
break;
case 4:
g = PTR_TO_BYTE (p);
break;
case 5:
b = PTR_TO_BYTE (p);
break;
case 6:
m_bot->TakeBlinded (Vector (r, g, b), PTR_TO_BYTE (p));
break;
}
break;
case NETMSG_HLTV: // round restart in steam cs
switch (m_state)
{
case 0:
numPlayers = PTR_TO_INT (p);
break;
case 1:
if (numPlayers == 0 && PTR_TO_INT (p) == 0)
RoundInit ();
break;
}
break;
case NETMSG_RESETHUD:
#if 0
if (m_bot != NULL)
m_bot->NewRound ();
#endif
break;
case NETMSG_TEXTMSG:
if (m_state == 1)
{
if (FStrEq (PTR_TO_STR (p), "#CTs_Win") ||
FStrEq (PTR_TO_STR (p), "#Bomb_Defused") ||
FStrEq (PTR_TO_STR (p), "#Terrorists_Win") ||
FStrEq (PTR_TO_STR (p), "#Round_Draw") ||
FStrEq (PTR_TO_STR (p), "#All_Hostages_Rescued") ||
FStrEq (PTR_TO_STR (p), "#Target_Saved") ||
FStrEq (PTR_TO_STR (p), "#Hostages_Not_Rescued") ||
FStrEq (PTR_TO_STR (p), "#Terrorists_Not_Escaped") ||
FStrEq (PTR_TO_STR (p), "#VIP_Not_Escaped") ||
FStrEq (PTR_TO_STR (p), "#Escaping_Terrorists_Neutralized") ||
FStrEq (PTR_TO_STR (p), "#VIP_Assassinated") ||
FStrEq (PTR_TO_STR (p), "#VIP_Escaped") ||
FStrEq (PTR_TO_STR (p), "#Terrorists_Escaped") ||
FStrEq (PTR_TO_STR (p), "#CTs_PreventEscape") ||
FStrEq (PTR_TO_STR (p), "#Target_Bombed") ||
FStrEq (PTR_TO_STR (p), "#Game_Commencing") ||
FStrEq (PTR_TO_STR (p), "#Game_will_restart_in"))
{
g_roundEnded = true;
if (FStrEq (PTR_TO_STR (p), "#Game_Commencing"))
g_isCommencing = true;
if (FStrEq (PTR_TO_STR (p), "#CTs_Win"))
{
bots.SetLastWinner (CT); // update last winner for economics
if (yb_communication_type.GetInt () == 2)
{
Bot *bot = bots.FindOneValidAliveBot ();
if (bot != NULL && bot->m_notKilled)
bot->HandleChatterMessage (PTR_TO_STR (p));
}
}
if (FStrEq (PTR_TO_STR (p), "#Game_will_restart_in"))
{
bots.CheckTeamEconomics (CT, true);
bots.CheckTeamEconomics (TERRORIST, true);
}
if (FStrEq (PTR_TO_STR (p), "#Terrorists_Win"))
{
bots.SetLastWinner (TERRORIST); // update last winner for economics
if (yb_communication_type.GetInt () == 2)
{
Bot *bot = bots.FindOneValidAliveBot ();
if (bot != NULL && bot->m_notKilled)
bot->HandleChatterMessage (PTR_TO_STR (p));
}
}
waypoints.SetBombPosition (true);
}
else if (!g_bombPlanted && FStrEq (PTR_TO_STR (p), "#Bomb_Planted"))
{
waypoints.SetBombPosition ();
g_bombPlanted = g_bombSayString = true;
g_timeBombPlanted = engine.Time ();
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
if (bot != NULL && bot->m_notKilled)
{
bot->DeleteSearchNodes ();
bot->ResetTasks ();
if (yb_communication_type.GetInt () == 2 && Random.Long (0, 100) < 75 && bot->m_team == CT)
bot->ChatterMessage (Chatter_WhereIsTheBomb);
}
}
}
else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_BurstFire"))
m_bot->m_weaponBurstMode = BM_ON;
else if (m_bot != NULL && FStrEq (PTR_TO_STR (p), "#Switch_To_SemiAuto"))
m_bot->m_weaponBurstMode = BM_OFF;
}
break;
case NETMSG_SCOREINFO:
switch (m_state)
{
case 0:
playerIndex = PTR_TO_INT (p);
break;
case 4:
if (playerIndex >= 0 && playerIndex <= engine.MaxClients ())
{
#ifndef XASH_CSDM
Client &cl = g_clients[playerIndex - 1];
if (PTR_TO_INT (p) == 1)
cl.realTeam = TERRORIST;
else if (PTR_TO_INT (p) == 2)
cl.realTeam = CT;
else
cl.realTeam = SPECTATOR;
if (yb_csdm_mode.GetInt () == 2)
cl.team = playerIndex;
else
cl.team = cl.realTeam;
#endif
}
break;
}
break;
case NETMSG_BARTIME:
if (m_state == 0)
{
if (PTR_TO_INT (p) > 0)
m_bot->m_hasProgressBar = true; // the progress bar on a hud
else if (PTR_TO_INT (p) == 0)
m_bot->m_hasProgressBar = false; // no progress bar or disappeared
}
break;
default:
AddLogEntry (true, LL_FATAL, "Network message handler error. Call to unrecognized message id (%d).\n", m_message);
}
m_state++; // and finally update network message state
}

View file

@ -1,4 +1,4 @@
//
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team.
//
@ -42,14 +42,20 @@ short FixedSigned16 (float value, float scale)
const char *FormatBuffer (const char *format, ...)
{
va_list ap;
static char staticBuffer[3072];
static char strBuffer[2][MAX_PRINT_BUFFER];
static int rotator = 0;
if (format == NULL)
return strBuffer[rotator];
static char *ptr = strBuffer[rotator ^= 1];
va_list ap;
va_start (ap, format);
vsprintf (staticBuffer, format, ap);
vsnprintf (ptr, MAX_PRINT_BUFFER - 1, format, ap);
va_end (ap);
return &staticBuffer[0];
return ptr;
}
bool IsAlive (edict_t *ent)
@ -105,7 +111,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu)
String tempText = String (menu->menuText);
tempText.Replace ("\v", "\n");
char *text = locale.TranslateInput (tempText.GetBuffer ());
const char *text = engine.TraslateMessage (tempText.GetBuffer ());
tempText = String (text);
// make menu looks best
@ -115,11 +121,11 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu)
if ((g_gameFlags & (GAME_XASH | GAME_MOBILITY)) && !yb_display_menu_text.GetBool ())
text = " ";
else
text = (char *) tempText.GetBuffer ();
text = tempText.GetBuffer ();
while (strlen (text) >= 64)
{
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, netmsg.GetId (NETMSG_SHOWMENU), NULL, ent);
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), NULL, ent);
WRITE_SHORT (menu->validSlots);
WRITE_CHAR (-1);
WRITE_BYTE (1);
@ -132,7 +138,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu)
text += 64;
}
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, netmsg.GetId (NETMSG_SHOWMENU), NULL, ent);
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), NULL, ent);
WRITE_SHORT (menu->validSlots);
WRITE_CHAR (-1);
WRITE_BYTE (0);
@ -143,7 +149,7 @@ void DisplayMenuToClient (edict_t *ent, MenuText *menu)
}
else
{
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, netmsg.GetId (NETMSG_SHOWMENU), NULL, ent);
MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, engine.FindMessageId (NETMSG_SHOWMENU), NULL, ent);
WRITE_SHORT (0);
WRITE_CHAR (0);
WRITE_BYTE (0);
@ -206,7 +212,7 @@ void DecalTrace (entvars_t *pev, TraceResult *trace, int logotypeIndex)
{
MESSAGE_BEGIN (MSG_BROADCAST, SVC_TEMPENTITY);
WRITE_BYTE (TE_PLAYERDECAL);
WRITE_BYTE (engine.IndexOfEntity (ENT (pev)));
WRITE_BYTE (engine.IndexOfEntity (pev->pContainingEntity));
WRITE_COORD (trace->vecEndPos.x);
WRITE_COORD (trace->vecEndPos.y);
WRITE_COORD (trace->vecEndPos.z);
@ -234,7 +240,6 @@ void FreeLibraryMemory (void)
{
// this function free's all allocated memory
waypoints.Init (); // frees waypoint data
locale.Destroy (); // clear language
delete [] g_experienceData;
g_experienceData = NULL;
@ -566,7 +571,7 @@ void DetectCSVersion (void)
}
// counter-strike 1.6 or higher (plus detects for non-steam versions of 1.5)
byte *detection = (*g_engfuncs.pfnLoadFileForMe) ("events/galil.sc", NULL);
byte *detection = g_engfuncs.pfnLoadFileForMe ("events/galil.sc", NULL);
if (detection != NULL)
g_gameFlags |= GAME_CSTRIKE16; // just to be sure
@ -575,7 +580,7 @@ void DetectCSVersion (void)
// if we have loaded the file free it
if (detection != NULL)
(*g_engfuncs.pfnFreeFile) (detection);
g_engfuncs.pfnFreeFile (detection);
}
void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...)
@ -583,28 +588,28 @@ void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...)
// this function logs a message to the message log file root directory.
va_list ap;
char buffer[512] = {0, }, levelString[32] = {0, }, logLine[1024] = {0, };
char buffer[MAX_PRINT_BUFFER] = {0, }, levelString[32] = {0, }, logLine[MAX_PRINT_BUFFER] = {0, };
va_start (ap, format);
vsprintf (buffer, locale.TranslateInput (format), ap);
vsnprintf (buffer, SIZEOF_CHAR (buffer), format, ap);
va_end (ap);
switch (logLevel)
{
case LL_DEFAULT:
strcpy (levelString, "Log: ");
strcpy (levelString, "LOG: ");
break;
case LL_WARNING:
strcpy (levelString, "Warning: ");
strcpy (levelString, "WARN: ");
break;
case LL_ERROR:
strcpy (levelString, "Error: ");
strcpy (levelString, "ERROR: ");
break;
case LL_FATAL:
strcpy (levelString, "Critical: ");
strcpy (levelString, "FATAL: ");
break;
}
@ -661,49 +666,6 @@ void AddLogEntry (bool outputToConsole, int logLevel, const char *format, ...)
}
}
char *Localizer::TranslateInput (const char *input)
{
if (engine.IsDedicatedServer ())
return const_cast <char *> (&input[0]);
static char string[1024];
const char *ptr = input + strlen (input) - 1;
while (ptr > input && *ptr == '\n')
ptr--;
if (ptr != input)
ptr++;
strncpy (string, input, SIZEOF_CHAR (string));
String::TrimExternalBuffer (string);
FOR_EACH_AE (m_langTab, i)
{
if (strcmp (string, m_langTab[i].original) == 0)
{
strncpy (string, m_langTab[i].translated, SIZEOF_CHAR (string));
if (ptr != input)
strncat (string, ptr, 1024 - 1 - strlen (string));
return &string[0];
}
}
return const_cast <char *> (&input[0]); // nothing found
}
void Localizer::Destroy (void)
{
FOR_EACH_AE (m_langTab, it)
{
delete[] m_langTab[it].original;
delete[] m_langTab[it].translated;
}
m_langTab.RemoveAll ();
}
bool FindNearestPlayer (void **pvHolder, edict_t *to, float searchDistance, bool sameTeam, bool needBot, bool isAlive, bool needDrawn)
{
// this function finds nearest to to, player with set of parameters, like his

View file

@ -24,17 +24,21 @@ void Waypoint::Init (void)
// have any waypoint path nodes been allocated yet?
if (m_waypointPaths)
{
for (int i = 0; i < g_numWaypoints && m_paths[i] != NULL; i++)
{
delete m_paths[i];
m_paths[i] = NULL;
}
}
CleanupPathMemory ();
g_numWaypoints = 0;
}
void Waypoint::AddPath (short int addIndex, short int pathIndex, float distance)
void Waypoint::CleanupPathMemory (void)
{
for (int i = 0; i < g_numWaypoints && m_paths[i] != NULL; i++)
{
delete m_paths[i];
m_paths[i] = NULL;
}
}
void Waypoint::AddPath (int addIndex, int pathIndex, float distance)
{
if (addIndex < 0 || addIndex >= g_numWaypoints || pathIndex < 0 || pathIndex >= g_numWaypoints || addIndex == pathIndex)
return;
@ -967,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 (byte));
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));
}
void Waypoint::InitVisibilityTab (void)
@ -1008,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 (byte));
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));
if (result == -1)
{
@ -1496,7 +1500,7 @@ const char *Waypoint::GetWaypointInfo(int id)
jumpPoint = true;
}
static char messageBuffer[1024];
static char messageBuffer[MAX_PRINT_BUFFER];
sprintf (messageBuffer, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s", (path->flags == 0 && !jumpPoint) ? " (none)" : "", (path->flags & FLAG_LIFT) ? " LIFT" : "", (path->flags & FLAG_CROUCH) ? " CROUCH" : "", (path->flags & FLAG_CROSSING) ? " CROSSING" : "", (path->flags & FLAG_CAMP) ? " CAMP" : "", (path->flags & FLAG_TF_ONLY) ? " TERRORIST" : "", (path->flags & FLAG_CF_ONLY) ? " CT" : "", (path->flags & FLAG_SNIPER) ? " SNIPER" : "", (path->flags & FLAG_GOAL) ? " GOAL" : "", (path->flags & FLAG_LADDER) ? " LADDER" : "", (path->flags & FLAG_RESCUE) ? " RESCUE" : "", (path->flags & FLAG_DOUBLEJUMP) ? " JUMPHELP" : "", (path->flags & FLAG_NOHOSTAGE) ? " NOHOSTAGE" : "", jumpPoint ? " JUMP" : "");
// return the message buffer
@ -2454,6 +2458,8 @@ void Waypoint::SetFindIndex (int index)
Waypoint::Waypoint (void)
{
CleanupPathMemory ();
m_waypointPaths = false;
m_endJumpPoint = false;
m_redoneVisibility = false;
@ -2480,13 +2486,12 @@ Waypoint::Waypoint (void)
m_distMatrix = NULL;
m_pathMatrix = NULL;
for (int i = 0; i < MAX_WAYPOINTS; i++)
m_paths[i] = NULL;
}
Waypoint::~Waypoint (void)
{
CleanupPathMemory ();
delete [] m_distMatrix;
delete [] m_pathMatrix;
@ -2573,7 +2578,7 @@ WaypointDownloadError Waypoint::RequestWaypoint (void)
return WDE_SOCKET_ERROR;
}
const int ChunkSize = 1024;
const int ChunkSize = MAX_PRINT_BUFFER;
char buffer[ChunkSize] = { 0, };
bool finished = false;