Merge of rewritten NS module into trunk
This commit is contained in:
@@ -1,57 +1,99 @@
|
||||
//======================================================================
|
||||
// Forward declarations for functions that deal directly with the engine
|
||||
//======================================================================
|
||||
/* AMX Mod X
|
||||
* Natural Selection Module
|
||||
*
|
||||
* by the AMX Mod X Development Team
|
||||
*
|
||||
* This file is part of AMX Mod X.
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* In addition, as a special exception, the author gives permission to
|
||||
* link the code of this program with the Half-Life Game Engine ("HL
|
||||
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||
* respects for all of the code used other than the HL Engine and MODs
|
||||
* from Valve. If you modify this file, you may extend this exception
|
||||
* to your version of the file, but you are not obligated to do so. If
|
||||
* you do not wish to do so, delete this exception statement from your
|
||||
* version.
|
||||
*/
|
||||
|
||||
#ifndef UTILFUNCTIONS_H
|
||||
#define UTILFUNCTIONS_H
|
||||
|
||||
#include "CPlayer.h"
|
||||
extern CPlayer g_player[33];
|
||||
|
||||
#define GET_PLAYER_E(x) (&g_player[ENTINDEX(x)]);
|
||||
#define GET_PLAYER_I(x) (&g_player[x]);
|
||||
|
||||
/*
|
||||
#define FLOAT_TO_CELL(x) *(cell*)&x
|
||||
#define CELL_TO_FLOAT(x) *(float*)&x
|
||||
*/
|
||||
#define FLOAT_TO_CELL amx_ftoc
|
||||
#define CELL_TO_FLOAT amx_ctof
|
||||
#include "NEW_Util.h" // include my experimental INDEXENT / ENTINDEX replacements
|
||||
|
||||
|
||||
|
||||
#define ABSOLUTE_VALUE_EASY(x) (((x) < 0) ? (-(x)) : (x)) //very useful for gpGlobals->time comparisons
|
||||
#define GetEdictModel(edict) ( (g_engfuncs.pfnInfoKeyValue((*g_engfuncs.pfnGetInfoKeyBuffer)(edict), "model")) )
|
||||
//#define INFO_KEY_VALUE(entity,keyname) (*g_engfuncs.pfnGetInfoKeyBuffer)(entity),keyname)
|
||||
#define GetKeyValue(edict,key) ( (g_engfuncs.pfnInfoKeyValue((*g_engfuncs.pfnGetInfoKeyBuffer)(edict), key)) )
|
||||
#define INFO_KEY_BUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
|
||||
#define INFO_KEY_VALUE (*g_engfuncs.pfnInfoKeyValue)
|
||||
#define GET_PLAYER_E(x) (&g_player[ENTINDEX_NEW(x)])
|
||||
#define GET_PLAYER_I(x) (&g_player[x])
|
||||
|
||||
|
||||
//just declare extra helper functions you need here
|
||||
edict_t *UTIL_FindEntityByString(edict_t *pentStart, const char *szKeyword, const char *szValue);
|
||||
edict_t *UTIL_PlayerByIndexE( int playerIndex );
|
||||
int LogToIndex(char logline[128]);
|
||||
int Find_Building_Hive(void);
|
||||
/**
|
||||
* Like GET_PLAYER_I, but this handles the invalid player index
|
||||
* as well as setting the CPlayer pointer.
|
||||
* NOTE: This declares CPlayer *player for you
|
||||
*/
|
||||
#define CreatePlayerPointer(AMX__, INDEX__) \
|
||||
if (INDEX__ < 1 || INDEX__ > gpGlobals->maxClients) \
|
||||
{ \
|
||||
return 0; \
|
||||
} \
|
||||
CPlayer *player = &g_player[INDEX__]
|
||||
|
||||
/**
|
||||
* Declares an edict (Entity) and verify it's not a player
|
||||
*/
|
||||
#define CreateNonPlayerEdict(AMX__, INDEX__) \
|
||||
if (INDEX__ <= gpGlobals->maxClients || INDEX__ > gpGlobals->maxEntities) \
|
||||
{ \
|
||||
return 0; \
|
||||
} \
|
||||
edict_t *Entity=INDEXENT_NEW(INDEX__)
|
||||
|
||||
/**
|
||||
* Declares an edict (Entity) does not care if it is a player
|
||||
*/
|
||||
#define CreateEdict(AMX__, INDEX__, INVALIDRET__) \
|
||||
if (INDEX__ < 1 || INDEX__ > gpGlobals->maxEntities) \
|
||||
{ \
|
||||
return INVALIDRET__; \
|
||||
} \
|
||||
edict_t *Entity=INDEXENT_NEW(INDEX__)
|
||||
|
||||
|
||||
/**
|
||||
* There is no need to use the AMXx provided calls as
|
||||
* they do an api call to recast, seems like overkill
|
||||
*/
|
||||
//#define amx_ftoc2(x) *((cell *)&x)
|
||||
//#define amx_ctof2(x) *((REAL *)&x)
|
||||
#define amx_ftoc3(x) *((cell *)x)
|
||||
#define amx_ctof3(x) *((REAL *)x)
|
||||
inline cell amx_ftoc2(REAL x)
|
||||
{
|
||||
return *((cell *)&x);
|
||||
};
|
||||
inline REAL amx_ctof2(cell x)
|
||||
{
|
||||
return *((REAL *)&x);
|
||||
};
|
||||
|
||||
void GiveItem(edict_t *pEntity,char *szname);
|
||||
|
||||
void HudMessage(int index, const hudtextparms_t &textparms, const char *pMessage);
|
||||
void ClearHudMessage(edict_t *pEntity, const hudtextparms_t &textparms, const char *pMessage);
|
||||
void UTIL_EmptyMenu(edict_t *pEntity, int keys, int time);
|
||||
void UTIL_FakeClientCmd(edict_t *pEntity, char *cmd);
|
||||
|
||||
inline edict_t* INDEXENT2( int iEdictNum )
|
||||
{
|
||||
if (iEdictNum >= 1 && iEdictNum <= gpGlobals->maxClients)
|
||||
{
|
||||
CPlayer *player = GET_PLAYER_I(iEdictNum);
|
||||
return player->edict;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (*g_engfuncs.pfnPEntityOfEntIndex)(iEdictNum);
|
||||
}
|
||||
}
|
||||
inline BOOL isValidEntity(int x)
|
||||
{
|
||||
if (x < 0)
|
||||
@@ -64,9 +106,151 @@ inline BOOL isValidEntity(int x)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
#define CHECK_ENTITY(x) if (x != 0 && (FNullEnt(INDEXENT2(x)) || x < 0 || x > gpGlobals->maxEntities)) return 0;
|
||||
#define CHECK_ENTITY(x) if (x != 0 && (FNullEnt(INDEXENT_NEW(x)) || x < 0 || x > gpGlobals->maxEntities)) return 0;
|
||||
#define CHECK_PARAMS(x) if (*params/sizeof(cell) < x) return 0;
|
||||
|
||||
|
||||
// Stuff in utils.cpp
|
||||
|
||||
edict_t *UTIL_FindEntityByString(edict_t *Start, const char *Keyword, const char *Value);
|
||||
|
||||
int UTIL_FindBuildingHive(void);
|
||||
|
||||
BOOL UTIL_CheckForPublic(const char *publicname);
|
||||
BOOL UTIL_CheckForNative(const char *NativeName);
|
||||
|
||||
class CPlayer;
|
||||
|
||||
CPlayer *UTIL_PlayerByCID(int CID);
|
||||
|
||||
// Converts something such as RESOURCES into OFFSET_WIN_RESOURCES or OFFSET_LIN_RESOURCES
|
||||
#ifdef __linux__
|
||||
#define MAKE_OFFSET(Offset) OFFSET_LIN_##Offset
|
||||
#define MAKE_MEMBER_OFFSET(Offs) (Offs - OFFSET_LIN_MEMBERFUNCSTART)
|
||||
#else
|
||||
#define MAKE_OFFSET(Offset) OFFSET_WIN_##Offset
|
||||
#define MAKE_MEMBER_OFFSET(Offs) (Offs - OFFSET_WIN_MEMBERFUNCSTART)
|
||||
#endif // __linux__
|
||||
|
||||
template <typename Output>
|
||||
inline Output get_private_p(edict_t *pEntity, int offset)
|
||||
{
|
||||
return (Output)(*(void**)((char*)(pEntity->pvPrivateData)+offset));
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts the private data pointer into an edict by
|
||||
* looking up the entvar pointer (first entry in cbaseentity)
|
||||
* and then getting pContainingEntity from that
|
||||
*/
|
||||
inline edict_t *private_to_edict(void *PrivateData)
|
||||
{
|
||||
if (PrivateData==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return (*((entvars_t **)((char *)PrivateData + MAKE_OFFSET(ENTVAR))))->pContainingEntity;
|
||||
};
|
||||
inline int clamp(int value, int min, int max)
|
||||
{
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
inline REAL clamp(REAL value, REAL min, REAL max)
|
||||
{
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
if (value > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
inline int clamp(int value, int min)
|
||||
{
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
inline REAL clamp(REAL value, REAL min)
|
||||
{
|
||||
if (value < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
inline int get_private(edict_t *pEntity, int offset)
|
||||
{
|
||||
return *(int*)((char*)(pEntity->pvPrivateData)+offset);
|
||||
}
|
||||
|
||||
inline REAL get_private_f(edict_t *pEntity, int offset)
|
||||
{
|
||||
return *(REAL*)((char*)(pEntity->pvPrivateData)+offset);
|
||||
}
|
||||
|
||||
inline void set_private(edict_t *pEntity, int offset, int value)
|
||||
{
|
||||
*(int*)((char*)(pEntity->pvPrivateData)+offset) = value;
|
||||
}
|
||||
inline int inc_private(edict_t *pEntity, int offset, int value)
|
||||
{
|
||||
return *(int*)((char*)(pEntity->pvPrivateData)+offset) = *(int*)((char*)(pEntity->pvPrivateData)+offset) + value;
|
||||
}
|
||||
inline int inc_private(edict_t *pEntity, int offset, int value, int min)
|
||||
{
|
||||
return *(int*)((char*)(pEntity->pvPrivateData)+offset) = clamp(*(int*)((char*)(pEntity->pvPrivateData)+offset) + value, min);
|
||||
}
|
||||
inline int inc_private(edict_t *pEntity, int offset, int value, int min, int max)
|
||||
{
|
||||
return *(int*)((char*)(pEntity->pvPrivateData)+offset) = clamp(*(int*)((char*)(pEntity->pvPrivateData)+offset) + value, min, max);
|
||||
}
|
||||
|
||||
inline void set_private_f(edict_t *pEntity, int offset, REAL value)
|
||||
{
|
||||
*(REAL*)((char*)(pEntity->pvPrivateData)+offset) = value;
|
||||
}
|
||||
inline REAL inc_private_f(edict_t *pEntity, int offset, REAL value)
|
||||
{
|
||||
return *(REAL*)((char*)(pEntity->pvPrivateData)+offset) = *(REAL*)((char*)(pEntity->pvPrivateData)+offset) + value;
|
||||
}
|
||||
inline REAL inc_private_f(edict_t *pEntity, int offset, REAL value, REAL min)
|
||||
{
|
||||
return *(REAL*)((char*)(pEntity->pvPrivateData)+offset) = clamp(*(REAL*)((char*)(pEntity->pvPrivateData)+offset) + value, min);
|
||||
}
|
||||
inline REAL inc_private_f(edict_t *pEntity, int offset, REAL value, REAL min, REAL max)
|
||||
{
|
||||
return *(REAL*)((char*)(pEntity->pvPrivateData)+offset) = clamp(*(REAL*)((char*)(pEntity->pvPrivateData)+offset) + value, min, max);
|
||||
}
|
||||
|
||||
inline unsigned char get_private_b(edict_t *pEntity, int offset)
|
||||
{
|
||||
return *(((unsigned char*)pEntity->pvPrivateData)+offset);
|
||||
};
|
||||
inline unsigned char set_private_b(edict_t *pEntity, int offset, unsigned char value)
|
||||
{
|
||||
return *(((unsigned char*)pEntity->pvPrivateData)+offset)=value;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // UTILFUNCTIONS_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user