00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _COMMON_DEFINED
00027 #define _COMMON_DEFINED
00028
00029 #include "../shared/ufotypes.h"
00030 #include "../shared/byte.h"
00031 #include "../shared/shared.h"
00032 #include "../shared/mathlib.h"
00033 #include "../shared/defines.h"
00034 #include "../shared/typedefs.h"
00035 #include "tracing.h"
00036 #include "cvar.h"
00037 #include "mem.h"
00038 #include "http.h"
00039
00040 #define UFO_VERSION "2.4-dev"
00041 #define GAME_TITLE "UFO:AI"
00042 #define GAME_TITLE_LONG "UFO:Alien Invasion"
00043
00044 #ifdef _WIN32
00045 # define BUILDSTRING_OS "Win32"
00046 # ifndef SHARED_EXT
00047 # define SHARED_EXT "dll"
00048 # endif
00049
00050 #elif defined __linux__
00051 # define BUILDSTRING_OS "Linux"
00052 # ifndef SHARED_EXT
00053 # define SHARED_EXT "so"
00054 # endif
00055
00056 #elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
00057 # define BUILDSTRING_OS "FreeBSD"
00058 # ifndef SHARED_EXT
00059 # define SHARED_EXT "so"
00060 # endif
00061
00062 #elif defined __sun
00063 # define BUILDSTRING_OS "Solaris"
00064 # ifndef SHARED_EXT
00065 # define SHARED_EXT "so"
00066 # endif
00067
00068 #elif defined (__APPLE__) || defined (MACOSX)
00069 # define BUILDSTRING_OS "MacOSX"
00070 # ifndef SHARED_EXT
00071 # define SHARED_EXT "dylib"
00072 # endif
00073
00074 #else
00075 # define BUILDSTRING_OS "Unknown"
00076 #endif
00077
00078 #if defined __alpha__ || defined __alpha || defined _M_ALPHA
00079 # define CPUSTRING "Alpha"
00080 #elif defined __amd64__ || defined __amd64 || defined __x86_64__ || defined __x86_64 || defined _M_X64
00081 # define CPUSTRING "AMD64"
00082 #elif defined __arm__ || defined __thumb__ || defined _ARM
00083 # define CPUSTRING "ARM"
00084 #elif defined i386 || defined __i386__ || defined __i386 || defined _M_IX86 || defined __X86__ || defined _X86_ || defined __THW_INTEL__ || defined __I86__ || defined __INTEL__
00085 # define CPUSTRING "IA-32"
00086 #elif defined __ia64__ || defined _IA64 || defined __IA64__ || defined __ia64 || defined _M_IA64
00087 # define CPUSTRING "IA-64"
00088 #elif defined __mips__ || defined mips || defined __mips || defined __MIPS__
00089 # define CPUSTRING "MIPS"
00090 #elif defined __powerpc || defined __powerpc__ || defined __POWERPC__ || defined __ppc__ || defined _M_PPC || defined _ARCH_PPC
00091 # define CPUSTRING "PowerPC"
00092 #elif defined __sparc__ || defined __sparc
00093 # define CPUSTRING "SPARC"
00094 #else
00095 # define CPUSTRING "Unknown"
00096 #endif
00097
00098 #ifdef DEBUG
00099 # define BUILDSTRING_VARIANT "DEBUG"
00100 #else
00101 # define BUILDSTRING_VARIANT "RELEASE"
00102 #endif
00103
00104 #ifdef UFO_REVISION
00105 # define BUILDSTRING BUILDSTRING_OS " " BUILDSTRING_VARIANT " build " UFO_REVISION
00106 #else
00107 # define BUILDSTRING BUILDSTRING_OS " " BUILDSTRING_VARIANT
00108 #endif
00109
00110 #define MASTER_SERVER "http://ufoai.ninex.info/"
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 #define PROTOCOL_VERSION 6
00121
00122 #define PORT_CLIENT 27901
00123 #define PORT_SERVER 27910
00124
00129 enum svc_ops_e {
00130 svc_bad,
00131
00133 svc_nop,
00134 svc_disconnect,
00135 svc_reconnect,
00136 svc_sound,
00137 svc_print,
00138 svc_stufftext,
00139 svc_serverdata,
00140 svc_configstring,
00141 svc_event,
00142 svc_oob = 0xff
00143 };
00144
00145 typedef int32_t svc_ops_t;
00146
00147
00148
00152 enum clc_ops_e {
00153 clc_bad,
00154 clc_nop,
00155 clc_endround,
00156 clc_teaminfo,
00157 clc_initactorstates,
00158 clc_action,
00159 clc_userinfo,
00160 clc_stringcmd,
00161 clc_oob = 0xff
00162 };
00163
00164 #define SOUND_ATTN_NONE 0.0f
00165 #define SOUND_ATTN_NORM 1.0f
00166 #define SOUND_ATTN_IDLE 1.2f
00167 #define SOUND_ATTN_STATIC 3.0f
00168 #define SOUND_ATTN_MAX SOUND_ATTN_STATIC
00169
00170 #include "../ports/system.h"
00171 #include "cmd.h"
00172 #include "cvar.h"
00173 #include "cmodel.h"
00174 #include "filesys.h"
00175 #include "scripts.h"
00176 #include "net.h"
00177 #include "dbuffer.h"
00178 #include "netpack.h"
00179
00180
00181
00182
00183
00184
00185
00186 #define ANGLE2SHORT(x) ((int)((x)*65536/360) & 65535)
00187 #define SHORT2ANGLE(x) ((x)*(360.0/65536))
00188
00189 #define ERR_FATAL 0
00190 #define ERR_DROP 1
00191 #define ERR_QUIT 2
00192
00193
00194 #define COLORED_GREEN "\1"
00195
00196 void Com_BeginRedirect(struct net_stream *stream, char *buffer, int buffersize);
00197 void Com_EndRedirect(void);
00198 void Com_MakeTimestamp(char* ts, const size_t tslen);
00199 void Com_vPrintf(const char *fmt, va_list);
00200
00201 void Com_Drop(void) __attribute__((noreturn));
00202 void Com_Quit(void);
00203 void Com_WriteConfigToFile(const char *filename);
00204 void Cvar_WriteVariables(qFILE *f);
00205
00206 int Com_ServerState(void);
00207 void Com_SetServerState(int state);
00208
00209 #include "md4.h"
00210 char *Com_MD5File(const char *fn, int length);
00211
00212 extern cvar_t *http_proxy;
00213 extern cvar_t *http_timeout;
00214 extern cvar_t *developer;
00215 extern cvar_t *sv_dedicated;
00216 extern cvar_t *sv_maxclients;
00217 extern cvar_t *sv_gametype;
00218 extern cvar_t *masterserver_url;
00219 extern cvar_t *port;
00220
00221 extern cvar_t* sys_priority;
00222 extern cvar_t* sys_affinity;
00223 extern cvar_t* sys_os;
00224
00225
00232 typedef struct date_s {
00233 int day;
00234 int sec;
00235 } date_t;
00236
00237
00238 #define DAYS_PER_YEAR 365
00239 #define DAYS_PER_YEAR_AVG 365.25
00240
00241 #define MONTHS_PER_YEAR 12
00242 #define SEASONS_PER_YEAR 4
00243 #define SECONDS_PER_DAY 86400
00244 #define SECONDS_PER_HOUR 3600
00245 #define SECONDS_PER_MINUTE 60
00246 #define MINUTES_PER_HOUR 60
00248 #define MAXCMDLINE 256
00249
00250 #define MAX_CVARLISTINGAMETYPE 16
00251 typedef struct cvarlist_s {
00252 char name[MAX_VAR];
00253 char value[MAX_VAR];
00254 } cvarlist_t;
00255
00256 typedef struct gametype_s {
00257 char id[MAX_VAR];
00258 char name[MAX_VAR];
00259 struct cvarlist_s cvars[MAX_CVARLISTINGAMETYPE];
00260 int num_cvars;
00261 } gametype_t;
00262
00264 #define MAX_GAMETYPES 16
00265 extern gametype_t gts[MAX_GAMETYPES];
00266 extern int numGTs;
00267
00268 void Qcommon_Init(int argc, const char **argv);
00269 void Qcommon_Frame(void);
00270 void Qcommon_Shutdown(void);
00271 void Com_SetGameType(void);
00272
00273 float Com_GrenadeTarget(const vec3_t from, const vec3_t at, float speed, qboolean launched, qboolean rolled, vec3_t v0);
00274
00275 void Con_Print(const char *txt);
00276
00277
00278
00279 typedef void event_func(int now, void *data);
00280 typedef qboolean event_check_func(int now, void *data);
00281 typedef qboolean event_filter(int when, event_func *func, event_check_func *check, void *data);
00282 typedef void event_clean_func(void * data);
00283 void Schedule_Event(int when, event_func *func, event_check_func *check, event_clean_func *clean, void *data);
00284 void Schedule_Timer(cvar_t *interval, event_func *func, void *data);
00285 void CL_FilterEventQueue(event_filter *filter);
00286
00287
00288
00289
00290
00291
00292
00293 void CL_Init(void);
00294 void CL_Drop(void);
00295 void CL_Shutdown(void);
00296 int CL_Milliseconds(void);
00297 void CL_Frame(int now, void *data);
00298 void CL_SlowFrame(int now, void *data);
00299 void CL_ParseClientData(const char *type, const char *name, const char **text);
00300 void SCR_BeginLoadingPlaque(void);
00301 void SCR_EndLoadingPlaque(void);
00302 void CL_InitAfter(void);
00303
00304 void SV_Init(void);
00305 void SV_Clear(void);
00306 void SV_Shutdown(const char *finalmsg, qboolean reconnect);
00307 void SV_ShutdownWhenEmpty(void);
00308 void SV_Frame(int now, void *);
00309 mapData_t* SV_GetMapData(void);
00310 mapTiles_t* SV_GetMapTiles(void);
00311
00312
00313
00314 extern memPool_t *com_aliasSysPool;
00315 extern memPool_t *com_cmdSysPool;
00316 extern memPool_t *com_cmodelSysPool;
00317 extern memPool_t *com_cvarSysPool;
00318 extern memPool_t *com_fileSysPool;
00319 extern memPool_t *com_genericPool;
00320
00321
00322
00323 int Com_Argc(void);
00324 const char *Com_Argv(int arg);
00325 void Com_ClearArgv(int arg);
00326 unsigned int Com_HashKey(const char *name, int hashsize);
00327 const char* Com_MacroExpandString(const char *text);
00328
00329 void Com_Init(void);
00330 void Com_InitArgv(int argc, const char **argv);
00331
00332 qboolean Com_ConsoleCompleteCommand(const char *s, char *target, size_t bufSize, int *pos, int offset);
00333
00334 void Key_Init(void);
00335
00336
00340 #define REMOVE_ELEM_MEMSET(array, index, n, val) \
00341 do { \
00342 size_t idx__ = (index); \
00343 size_t n__ = --(n); \
00344 assert(idx__ <= n__); \
00345 memmove((array) + idx__, (array) + idx__ + 1, (n__ - idx__) * sizeof(*(array))); \
00346 memset((array) + n__, val, sizeof(*(array))); \
00347 } while (0)
00348
00351 #define REMOVE_ELEM(array, index, n) \
00352 do { \
00353 size_t idx__ = (index); \
00354 size_t n__ = --(n); \
00355 assert(idx__ <= n__); \
00356 memmove((array) + idx__, (array) + idx__ + 1, (n__ - idx__) * sizeof(*(array))); \
00357 memset((array) + n__, 0, sizeof(*(array))); \
00358 } while (0)
00359
00362 #define REMOVE_ELEM_ADJUST_IDX(array, index, n) \
00363 do { \
00364 size_t idx__ = (index); \
00365 size_t n__; \
00366 size_t i__; \
00367 REMOVE_ELEM(array, index, n); \
00368 n__ = (n); \
00369 for (i__ = idx__; i__ < n__; ++i__) \
00370 --(array)[i__].idx; \
00371 } while (0)
00372
00373 #define HASH_Add(hash, elem, index) \
00374 do { \
00375 elem->hash_next = hash[index]; \
00376 hash[index] = elem; \
00377 } while (0)
00378
00379 #endif