This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/common/svgame_api.h

343 lines
16 KiB
C
Raw Normal View History

2008-12-15 22:00:00 +01:00
//=======================================================================
// Copyright XashXT Group 2008 <20>
// svgame_api.h - entity interface between engine and svgame
//=======================================================================
#ifndef SVGAME_API_H
#define SVGAME_API_H
2009-01-11 22:00:00 +01:00
#include "trace_def.h"
#include "event_api.h"
2008-12-15 22:00:00 +01:00
2008-12-25 22:00:00 +01:00
typedef struct globalvars_s
{
float time;
float frametime;
string_t mapname;
string_t startspot;
vec3_t spotOffset; // landmark offset
BOOL deathmatch;
BOOL coop;
BOOL teamplay;
int serverflags;
int maxClients;
int numClients; // actual clients count
int maxEntities;
int numEntities; // actual ents count
vec3_t v_forward;
vec3_t v_right;
vec3_t v_up;
BOOL trace_allsolid;
BOOL trace_startsolid;
BOOL trace_startstuck;
float trace_fraction;
vec3_t trace_endpos;
vec3_t trace_plane_normal;
float trace_plane_dist;
int trace_start_contents;
int trace_contents;
int trace_hitgroup;
const char *trace_texture; // texture name that we hitting (brushes and studiomodels)
edict_t *trace_ent;
int total_secrets;
int found_secrets; // number of secrets found
int total_monsters;
int killed_monsters; // number of monsters killed
2009-01-09 22:00:00 +01:00
void *pSaveData; // (SAVERESTOREDATA *) pointer
2008-12-25 22:00:00 +01:00
} globalvars_t;
2008-12-15 22:00:00 +01:00
// engine hands this to DLLs for functionality callbacks
typedef struct enginefuncs_s
{
// interface validator
int api_size; // must matched with sizeof( enginefuncs_t )
2008-12-20 22:00:00 +01:00
void* (*pfnMemAlloc)( size_t cb, const char *filename, const int fileline );
2009-01-11 22:00:00 +01:00
void (*pfnMemCopy)( void *dest, const void *src, size_t cb, const char *filename, const int fileline );
2008-12-20 22:00:00 +01:00
void (*pfnMemFree)( void *mem, const char *filename, const int fileline );
2008-12-15 22:00:00 +01:00
int (*pfnPrecacheModel)( const char* s );
int (*pfnPrecacheSound)( const char* s );
void (*pfnSetModel)( edict_t *e, const char *m );
int (*pfnModelIndex)( const char *m );
int (*pfnModelFrames)( int modelIndex );
void (*pfnSetSize)( edict_t *e, const float *rgflMin, const float *rgflMax );
void (*pfnChangeLevel)( const char* s1, const char* s2 );
float (*pfnVecToYaw)( const float *rgflVector );
void (*pfnVecToAngles)( const float *rgflVectorIn, float *rgflVectorOut );
void (*pfnMoveToOrigin)( edict_t *ent, const float *pflGoal, float dist, int iMoveType );
void (*pfnChangeYaw)( edict_t* ent );
void (*pfnChangePitch)( edict_t* ent );
edict_t* (*pfnFindEntityByString)( edict_t *pStartEdict, const char *pszField, const char *pszValue);
int (*pfnGetEntityIllum)( edict_t* pEnt );
edict_t* (*pfnFindEntityInSphere)( edict_t *pStartEdict, const float *org, float rad );
edict_t* (*pfnFindClientInPVS)( edict_t *pEdict );
edict_t* (*pfnFindClientInPHS)( edict_t *pEdict );
edict_t* (*pfnEntitiesInPVS)( edict_t *pplayer );
edict_t* (*pfnEntitiesInPHS)( edict_t *pplayer );
void (*pfnMakeVectors)( const float *rgflVector );
void (*pfnAngleVectors)( const float *rgflVector, float *forward, float *right, float *up );
edict_t* (*pfnCreateEntity)( void );
void (*pfnRemoveEntity)( edict_t* e );
edict_t* (*pfnCreateNamedEntity)( string_t className );
void (*pfnMakeStatic)( edict_t *ent );
2009-01-11 22:00:00 +01:00
void (*pfnLinkEdict)( edict_t *e );
2008-12-15 22:00:00 +01:00
int (*pfnDropToFloor)( edict_t* e );
int (*pfnWalkMove)( edict_t *ent, float yaw, float dist, int iMode );
void (*pfnSetOrigin)( edict_t *e, const float *rgflOrigin );
void (*pfnSetAngles)( edict_t *e, const float *rgflAngles );
void (*pfnEmitSound)( edict_t *ent, int chan, const char *sample, float vol, float attn, int flags, int pitch );
void (*pfnEmitAmbientSound)( edict_t *ent, float *pos, const char *samp, float vol, float attn, int flags, int pitch );
void (*pfnTraceLine)( const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr );
void (*pfnTraceToss)( edict_t* pent, edict_t* pentToIgnore, TraceResult *ptr );
2009-01-02 22:00:00 +01:00
void (*pfnTraceHull)( const float *v1, const float *mins, const float *maxs, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr );
2008-12-15 22:00:00 +01:00
void (*pfnTraceModel)( const float *v1, const float *v2, edict_t *pent, TraceResult *ptr );
const char *(*pfnTraceTexture)( edict_t *pTextureEntity, const float *v1, const float *v2 );
void (*pfnGetAimVector)( edict_t* ent, float speed, float *rgflReturn );
void (*pfnServerCommand)( const char* str );
void (*pfnServerExecute)( void );
void (*pfnClientCommand)( edict_t* pEdict, char* szFmt, ... );
void (*pfnParticleEffect)( const float *org, const float *dir, float color, float count );
void (*pfnLightStyle)( int style, char* val );
int (*pfnDecalIndex)( const char *name );
int (*pfnPointContents)( const float *rgflVector);
void (*pfnMessageBegin)( int msg_dest, int msg_type, const float *pOrigin, edict_t *ed );
void (*pfnMessageEnd)( void );
void (*pfnWriteByte)( int iValue );
void (*pfnWriteChar)( int iValue );
void (*pfnWriteShort)( int iValue );
void (*pfnWriteLong)( int iValue );
void (*pfnWriteAngle)( float flValue );
void (*pfnWriteCoord)( float flValue );
2008-12-25 22:00:00 +01:00
void (*pfnWriteFloat)( float flValue );
2008-12-15 22:00:00 +01:00
void (*pfnWriteString)( const char *sz );
void (*pfnWriteEntity)( int iValue );
2009-01-22 22:00:00 +01:00
cvar_t* (*pfnCVarRegister)( const char *name, const char *value, int flags, const char *desc );
2008-12-15 22:00:00 +01:00
float (*pfnCVarGetFloat)( const char *szVarName );
const char* (*pfnCVarGetString)( const char *szVarName );
void (*pfnCVarSetFloat)( const char *szVarName, float flValue );
void (*pfnCVarSetString)( const char *szVarName, const char *szValue );
void (*pfnAlertMessage)( ALERT_TYPE level, char *szFmt, ... );
void* (*pfnPvAllocEntPrivateData)( edict_t *pEdict, long cb );
void (*pfnFreeEntPrivateData)( edict_t *pEdict );
string_t (*pfnAllocString)( const char *szValue );
2008-12-17 22:00:00 +01:00
const char *(*pfnGetString)( string_t iString );
2008-12-15 22:00:00 +01:00
edict_t* (*pfnPEntityOfEntOffset)( int iEntOffset );
int (*pfnEntOffsetOfPEntity)( const edict_t *pEdict );
int (*pfnIndexOfEdict)( const edict_t *pEdict );
edict_t* (*pfnPEntityOfEntIndex)( int iEntIndex );
edict_t* (*pfnFindEntityByVars)( entvars_t* pvars );
void* (*pfnGetModelPtr)( edict_t* pEdict );
int (*pfnRegUserMsg)( const char *pszName, int iSize );
void (*pfnAnimationAutomove)( const edict_t* pEdict, float flTime );
void (*pfnGetBonePosition)( const edict_t* pEdict, int iBone, float *rgflOrigin, float *rgflAngles );
dword (*pfnFunctionFromName)( const char *pName );
const char *(*pfnNameForFunction)( dword function );
void (*pfnServerPrint)( const char *szMsg );
2008-12-17 22:00:00 +01:00
void (*pfnAreaPortal)( edict_t *pEdict, BOOL enable );
2009-01-02 22:00:00 +01:00
void (*pfnClassifyEdict)( edict_t *pEdict, int ed_type );
2008-12-15 22:00:00 +01:00
const char *(*pfnCmd_Args)( void );
const char *(*pfnCmd_Argv)( int argc );
int (*pfnCmd_Argc)( void );
void (*pfnGetAttachment)( const edict_t *pEdict, int iAttachment, float *rgflOrigin, float *rgflAngles );
void (*pfnCRC_Init)( word *pulCRC );
void (*pfnCRC_ProcessBuffer)( word *pulCRC, void *p, int len );
word (*pfnCRC_Final)( word pulCRC );
2008-12-25 22:00:00 +01:00
long (*pfnRandomLong)( long lLow, long lHigh );
2008-12-15 22:00:00 +01:00
float (*pfnRandomFloat)( float flLow, float flHigh );
2009-01-25 22:00:00 +01:00
void (*pfnFixAngle)( edict_t *pClient, const float *rgflAngles );
2008-12-15 22:00:00 +01:00
void (*pfnCrosshairAngle)( const edict_t *pClient, float pitch, float yaw );
byte* (*pfnLoadFile)( const char *filename, int *pLength );
2009-01-22 22:00:00 +01:00
void *(*pfnFOpen)( const char* path, const char* mode );
int (*pfnFClose)( void *file );
long (*pfnFWrite)( void *file, const void* data, size_t datasize);
long (*pfnFRead)( void *file, void* buffer, size_t buffersize );
int (*pfnFGets)( void *file, byte *string, size_t bufsize );
int (*pfnFSeek)( void *file, long offset, int whence );
long (*pfnFTell)( void *file );
2009-01-02 22:00:00 +01:00
int (*pfnFileExists)( const char *filename );
2008-12-15 22:00:00 +01:00
int (*pfnCompareFileTime)( const char *filename1, const char *filename2, int *iCompare );
void (*pfnGetGameDir)( char *szGetGameDir );
void (*pfnStaticDecal)( const float *origin, int decalIndex, int entityIndex, int modelIndex );
int (*pfnPrecacheGeneric)( const char* s );
int (*pfnIsDedicatedServer)( void ); // is this a dedicated server?
int (*pfnIsMapValid)( char *filename );
void (*pfnInfo_RemoveKey)( char *s, char *key );
char* (*pfnInfoKeyValue)( char *infobuffer, char *key );
void (*pfnSetKeyValue)( char *infobuffer, char *key, char *value );
char* (*pfnGetInfoKeyBuffer)( edict_t *e ); // passing in NULL gets the serverinfo
void (*pfnSetClientKeyValue)( int clientIndex, char *infobuffer, char *key, char *value );
2009-01-11 22:00:00 +01:00
word (*pfnPrecacheEvent)( int type, const char *psz );
void (*pfnPlaybackEvent)( int flags, const edict_t *pInvoker, word eventindex, float delay, event_args_t *args );
BOOL (*pfnCanSkipPlayer)( const edict_t *player );
2008-12-15 22:00:00 +01:00
void (*pfnSetSkybox)( const char *name );
void (*pfnPlayMusic)( const char *trackname, int flags ); // background track
void (*pfnDropClient)( int clientIndex ); // used for kick cheaters from server
2008-12-17 22:00:00 +01:00
void (*pfnHostError)( const char *szFmt, ... ); // invoke host error
2008-12-15 22:00:00 +01:00
} enginefuncs_t;
// passed to pfnKeyValue
typedef struct KeyValueData_s
{
char *szClassName; // in: entity classname
char *szKeyName; // in: name of key
char *szValue; // in: value of key
long fHandled; // out: DLL sets to true if key-value pair was understood
} KeyValueData;
typedef struct
{
char mapName[64];
char landmarkName[64];
edict_t *pentLandmark;
vec3_t vecLandmarkOrigin;
} LEVELLIST;
typedef struct
{
2009-01-09 22:00:00 +01:00
int id; // ENG ordinal ID of this entity (used for entity <--> pointer conversions)
edict_t *pent; // ENG pointer to the in-game entity
2008-12-15 22:00:00 +01:00
int location; // offset from the base data of this entity
int size; // byte size of this entity's data
int flags; // bit mask of transitions that this entity is in the PVS of
string_t classname; // entity class name
} ENTITYTABLE;
#define FTYPEDESC_GLOBAL 0x0001 // This field is masked for global entity save/restore
2009-01-10 22:00:00 +01:00
#define MAX_LEVEL_CONNECTIONS 16 // These are encoded in the lower 16bits of ENTITYTABLE->flags
2008-12-15 22:00:00 +01:00
#define FENTTABLE_GLOBAL 0x10000000
#define FENTTABLE_MOVEABLE 0x20000000
#define FENTTABLE_REMOVED 0x40000000
#define FENTTABLE_PLAYER 0x80000000
typedef struct saverestore_s
{
2009-01-09 22:00:00 +01:00
char *pBaseData; // ENG start of all entity save data
2008-12-15 22:00:00 +01:00
char *pCurrentData; // current buffer pointer for sequential access
int size; // current data size
2009-01-09 22:00:00 +01:00
int bufferSize; // ENG total space for data (Valve used 512 kb's)
int tokenSize; // always equal 0 (probably not used)
int tokenCount; // ENG number of elements in the pTokens table (Valve used 4096 tokens)
char **pTokens; // ENG hash table of entity strings (sparse)
int currentIndex; // ENG holds a global entity table ID
int tableCount; // ENG number of elements in the entity table (numEntities)
2008-12-15 22:00:00 +01:00
int connectionCount; // number of elements in the levelList[]
2009-01-09 22:00:00 +01:00
ENTITYTABLE *pTable; // ENG array of ENTITYTABLE elements (1 for each entity)
2008-12-15 22:00:00 +01:00
LEVELLIST levelList[MAX_LEVEL_CONNECTIONS]; // list of connections from this level
// smooth transition
2009-01-09 22:00:00 +01:00
int fUseLandmark; // ENG
char szLandmarkName[64]; // probably not used
2008-12-15 22:00:00 +01:00
vec3_t vecLandmarkOffset; // for landmark transitions
2009-01-09 22:00:00 +01:00
char szCurrentMap[64]; // ENG To check global entities
float time; // ENG
2008-12-15 22:00:00 +01:00
} SAVERESTOREDATA;
typedef enum _fieldtypes
{
FIELD_FLOAT = 0, // any floating point value
FIELD_STRING, // a string ID (return from ALLOC_STRING)
FIELD_ENTITY, // an entity offset (EOFFSET)
FIELD_CLASSPTR, // CBaseEntity *
FIELD_EHANDLE, // entity handle
FIELD_EVARS, // EVARS *
FIELD_EDICT, // edict_t *, or edict_t * (same thing)
FIELD_VECTOR, // any vector
FIELD_POSITION_VECTOR, // a world coordinate (these are fixed up across level transitions automagically)
FIELD_POINTER, // arbitrary data pointer... to be removed, use an array of FIELD_CHARACTER
FIELD_INTEGER, // any integer or enum
FIELD_FUNCTION, // a class function pointer (Think, Use, etc)
FIELD_BOOLEAN, // boolean, implemented as an int, I may use this as a hint for compression
FIELD_SHORT, // 2 byte integer
FIELD_CHARACTER, // a byte
FIELD_TIME, // a floating point time (these are fixed up automatically too!)
FIELD_MODELNAME, // engine string that is a model name (needs precache)
FIELD_SOUNDNAME, // engine string that is a sound name (needs precache)
FIELD_RANGE, // Min and Max range for generate random value
2009-01-06 22:00:00 +01:00
FIELD_INTEGER64, // long integer
FIELD_DOUBLE, // float with double precision
2008-12-15 22:00:00 +01:00
FIELD_TYPECOUNT, // MUST BE LAST
} FIELDTYPE;
typedef struct
{
FIELDTYPE fieldType;
char *fieldName;
int fieldOffset;
short fieldSize;
short flags;
} TYPEDESCRIPTION;
#define offsetof( s, m ) (size_t)&(((s *)0)->m)
#define ARRAYSIZE( p ) (sizeof( p ) / sizeof( p[0] ))
#define _FIELD( type, name, fieldtype, count, flags ) { fieldtype, #name, offsetof( type, name ), count, flags }
#define DEFINE_FIELD( type, name, fieldtype ) _FIELD( type, name, fieldtype, 1, 0 )
#define DEFINE_ARRAY( type, name, fieldtype, count ) _FIELD( type, name, fieldtype, count, 0 )
#define DEFINE_ENTITY_FIELD( name, fieldtype ) _FIELD( entvars_t, name, fieldtype, 1, 0 )
2009-01-10 22:00:00 +01:00
#define DEFINE_ENTITY_FIELD_ARRAY( name, fieldtype, count ) _FIELD( entvars_t, name, fieldtype, count, 0 )
2008-12-15 22:00:00 +01:00
#define DEFINE_ENTITY_GLOBAL_FIELD( name, fieldtype ) _FIELD( entvars_t, name, fieldtype, 1, FTYPEDESC_GLOBAL )
#define DEFINE_GLOBAL_FIELD( type, name, fieldtype ) _FIELD( type, name, fieldtype, 1, FTYPEDESC_GLOBAL )
typedef struct
{
// interface validator
size_t api_size; // must matched with sizeof(DLL_FUNCTIONS)
// initialize/shutdown the game (one-time call after loading of game .dll )
void (*pfnGameInit)( void );
2009-01-11 22:00:00 +01:00
void (*pfnGameShutdown)( void );
2008-12-15 22:00:00 +01:00
int (*pfnSpawn)( edict_t *pent );
2009-01-11 22:00:00 +01:00
int (*pfnCreate)( edict_t *pent, const char *szName ); // create custom entities
2008-12-15 22:00:00 +01:00
void (*pfnThink)( edict_t *pent );
void (*pfnUse)( edict_t *pentUsed, edict_t *pentOther );
void (*pfnTouch)( edict_t *pentTouched, edict_t *pentOther );
void (*pfnBlocked)( edict_t *pentBlocked, edict_t *pentOther );
void (*pfnKeyValue)( edict_t *pentKeyvalue, KeyValueData *pkvd );
void (*pfnSave)( edict_t *pent, SAVERESTOREDATA *pSaveData );
int (*pfnRestore)( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity );
void (*pfnSetAbsBox)( edict_t *pent );
void (*pfnSaveWriteFields)( SAVERESTOREDATA*, const char*, void*, TYPEDESCRIPTION*, int );
void (*pfnSaveReadFields)( SAVERESTOREDATA*, const char*, void*, TYPEDESCRIPTION*, int );
void (*pfnSaveGlobalState)( SAVERESTOREDATA * );
void (*pfnRestoreGlobalState)( SAVERESTOREDATA * );
void (*pfnResetGlobalState)( void );
int (*pfnClientConnect)( edict_t *pEntity, const char *userinfo );
void (*pfnClientDisconnect)( edict_t *pEntity );
void (*pfnClientKill)( edict_t *pEntity );
void (*pfnClientPutInServer)( edict_t *pEntity );
void (*pfnClientCommand)( edict_t *pEntity );
void (*pfnClientUserInfoChanged)( edict_t *pEntity, char *infobuffer );
void (*pfnServerActivate)( edict_t *pEdictList, int edictCount, int clientMax );
void (*pfnServerDeactivate)( void );
void (*pfnPlayerPreThink)( edict_t *pEntity );
void (*pfnPlayerPostThink)( edict_t *pEntity );
void (*pfnStartFrame)( void );
2009-01-11 22:00:00 +01:00
void (*pfnFrame)( edict_t *pent );
2008-12-20 22:00:00 +01:00
void (*pfnEndFrame)( void );
2009-01-09 22:00:00 +01:00
void (*pfnBuildLevelList)( void );
2008-12-15 22:00:00 +01:00
2009-01-14 22:00:00 +01:00
int (*pfnClassifyEdict)( edict_t *pentToClassify );
2009-01-11 22:00:00 +01:00
void (*pfnUpdateEntityState)( struct entity_state_s *to, edict_t *from, int baseline );
2008-12-15 22:00:00 +01:00
// returns string describing current .dll. E.g., TeamFotrress 2, Half-Life
const char *(*pfnGetGameDescription)( void );
} DLL_FUNCTIONS;
2009-01-11 22:00:00 +01:00
typedef int (*SERVERAPI)( DLL_FUNCTIONS *pFunctionTable, enginefuncs_t* engfuncs, globalvars_t *pGlobals );
2008-12-15 22:00:00 +01:00
typedef void (*LINK_ENTITY_FUNC)( entvars_t *pev );
#endif//SVGAME_API_H