1 /* 2 Copyright (C) 1997-2001 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 21 // q_shared.h -- included first by ALL program modules 22 23 #if !defined Q_SHARED_H_ 24 #define Q_SHARED_H_ 25 26 #include <assert.h> 27 #include <math.h> 28 #include <stdio.h> 29 #include <stdarg.h> 30 #include <stddef.h> 31 #include <string.h> 32 #include <stdlib.h> 33 #include <time.h> 34 #include <ctype.h> 35 36 typedef unsigned char byte; 37 38 // TODO: check for implementation defined boolean 39 // typedef enum {false, true} qboolean; 40 #ifndef true 41 # define false 0 42 # define true 1 43 #endif 44 typedef int qboolean; 45 46 #ifndef NULL 47 #define NULL ((void *)0) 48 #endif 49 50 51 // angle indexes 52 #define PITCH 0 // up / down 53 #define YAW 1 // left / right 54 #define ROLL 2 // fall over 55 56 #define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString 57 #define MAX_STRING_TOKENS 80 // max tokens resulting from Cmd_TokenizeString 58 #define MAX_TOKEN_CHARS 1024 // max length of an individual token 59 60 // MAX_QPATH must be 64 for Alien Arena client/server protocol. 61 #define MAX_QPATH 64 // max length of a quake game pathname 62 63 #if defined UNIX_VARIANT 64 #define MAX_OSPATH 256 // max length of a filesystem pathname 65 #else 66 #define MAX_OSPATH 128 // max length of a filesystem pathname 67 #endif 68 69 #define PLAYERNAME_GLYPHS 15 // maximum visible characters in a player name 70 #define PLAYERNAME_SIZE 32 // maximum bytes in player name string including color escapes 71 72 // 73 // per-level limits 74 // 75 #define MAX_CLIENTS 256 // absolute limit 76 #define MAX_EDICTS 1024 // must change protocol to increase more 77 #define MAX_LIGHTSTYLES 256 78 #define MAX_MODELS 256 // these are sent over the net as bytes 79 #define MAX_SOUNDS 256 // so they cannot be blindly increased 80 #define MAX_IMAGES 256 81 #define MAX_ITEMS 256 82 #define MAX_GENERAL (MAX_CLIENTS*2) // general config strings 83 84 85 // game print flags 86 #define PRINT_LOW 0 // pickup messages 87 #define PRINT_MEDIUM 1 // death messages 88 #define PRINT_HIGH 2 // critical messages 89 #define PRINT_CHAT 3 // chat messages 90 91 92 93 #define ERR_FATAL 0 // exit the entire game with a popup window 94 #define ERR_DROP 1 // print to console and disconnect from game 95 #define ERR_DISCONNECT 2 // don't kill server 96 97 #define PRINT_ALL 0 98 #define PRINT_DEVELOPER 1 // only print when "developer 1" 99 #define PRINT_ALERT 2 100 101 102 // destination class for gi.multicast() 103 typedef enum 104 { 105 MULTICAST_ALL, 106 MULTICAST_PHS, 107 MULTICAST_PVS, 108 MULTICAST_ALL_R, 109 MULTICAST_PHS_R, 110 MULTICAST_PVS_R 111 } multicast_t; 112 113 114 /* 115 ============================================================== 116 117 MATHLIB 118 119 ============================================================== 120 */ 121 122 typedef float vec_t; 123 typedef vec_t vec2_t[2]; 124 typedef vec_t vec3_t[3]; 125 typedef vec_t vec4_t[4]; 126 typedef vec_t vec5_t[5]; 127 128 typedef int fixed4_t; 129 typedef int fixed8_t; 130 typedef int fixed16_t; 131 132 typedef struct matrix3x3_s 133 { 134 vec3_t a; 135 vec3_t b; 136 vec3_t c; 137 } 138 matrix3x3_t; 139 140 typedef struct matrix3x4_s 141 { 142 vec4_t a; 143 vec4_t b; 144 vec4_t c; 145 } 146 matrix3x4_t; 147 148 typedef struct matrix4x4_s 149 { 150 vec4_t a; 151 vec4_t b; 152 vec4_t c; 153 vec4_t d; 154 } 155 matrix4x4_t; 156 157 #ifndef M_PI 158 #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h 159 #endif 160 161 struct cplane_s; 162 163 extern vec3_t vec3_origin; 164 165 #define nanmask (255<<23) 166 167 #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) 168 169 #define Q_ftol( f ) ( long ) (f) 170 171 #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2]) 172 #define VectorSubtract(a,b,c) (c[0]=a[0]-b[0],c[1]=a[1]-b[1],c[2]=a[2]-b[2]) 173 #define VectorAdd(a,b,c) (c[0]=a[0]+b[0],c[1]=a[1]+b[1],c[2]=a[2]+b[2]) 174 #define VectorCopy(a,b) (b[0]=a[0],b[1]=a[1],b[2]=a[2]) 175 #define VectorClear(a) (a[0]=a[1]=a[2]=0) 176 #define VectorNegate(a,b) (b[0]=-a[0],b[1]=-a[1],b[2]=-a[2]) 177 #define VectorSet(v, x, y, z) (v[0]=(x), v[1]=(y), v[2]=(z)) 178 #define SnapVector(v) {v[0]=((int)(v[0]));v[1]=((int)(v[1]));v[2]=((int)(v[2]));} 179 180 void VectorMA (vec3_t veca, float scale, vec3_t vecb, vec3_t vecc); 181 182 #define Vector4Set(v, a, b, c, d) ((v)[0]=(a),(v)[1]=(b),(v)[2]=(c),(v)[3] = (d)) 183 #define Vector4Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3]) 184 #define Vector4Scale(in,scale,out) ((out)[0]=(in)[0]*scale,(out)[1]=(in)[1]*scale,(out)[2]=(in)[2]*scale,(out)[3]=(in)[3]*scale) 185 #define Vector4Add(a,b,c) ((c)[0]=(((a[0])+(b[0]))),(c)[1]=(((a[1])+(b[1]))),(c)[2]=(((a[2])+(b[2]))),(c)[3]=(((a[3])+(b[3])))) 186 #define Vector4Sub(a,b,c) ((c)[0]=(((a[0])-(b[0]))),(c)[1]=(((a[1])-(b[1]))),(c)[2]=(((a[2])-(b[2]))),(c)[3]=(((a[3])-(b[3])))) 187 #define Vector4Avg(a,b,c) ((c)[0]=(((a[0])+(b[0]))*0.5f),(c)[1]=(((a[1])+(b[1]))*0.5f),(c)[2]=(((a[2])+(b[2]))*0.5f),(c)[3]=(((a[3])+(b[3]))*0.5f)) 188 #define Vector4Clear(a) ((a)[0]=(a)[1]=(a)[2]=(a)[3]=0) 189 190 #define DEG2RAD( a ) (( (a) * M_PI ) / 180.0F) 191 #define RAD2DEG( a ) (( (a) * 180.0F ) / M_PI) 192 193 // just in case you do't want to use the macros 194 vec_t _DotProduct (vec3_t v1, vec3_t v2); 195 void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out); 196 void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out); 197 void _VectorCopy (vec3_t in, vec3_t out); 198 199 void ClearBounds (vec3_t mins, vec3_t maxs); 200 void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs); 201 int VectorCompare (vec3_t v1, vec3_t v2); 202 vec_t VectorLength (vec3_t v); 203 void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross); 204 vec_t VectorNormalize (vec3_t v); // returns vector length 205 vec_t VectorNormalize2 (vec3_t v, vec3_t out); 206 void VectorInverse (vec3_t v); 207 void VectorScale (vec3_t in, vec_t scale, vec3_t out); 208 int Q_log2(int val); 209 210 void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]); 211 void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]); 212 213 void NormalToLatLong( const vec3_t normal, byte latlong[2] ); 214 void LatLongToNormal( byte latlong[2], vec3_t normal ); 215 216 void fast_sincosf( float angle, float *sina, float *cosa ); 217 void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); 218 void vectoangles (vec3_t value1, vec3_t angles); 219 int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *plane); 220 float anglemod(float a); 221 float LerpAngle (float a1, float a2, float frac); 222 223 #define BOX_ON_PLANE_SIDE(emins, emaxs, p) \ 224 (((p)->type < 3)? \ 225 ( \ 226 ((p)->dist <= (emins)[(p)->type])? \ 227 1 \ 228 : \ 229 ( \ 230 ((p)->dist >= (emaxs)[(p)->type])?\ 231 2 \ 232 : \ 233 3 \ 234 ) \ 235 ) \ 236 : \ 237 BoxOnPlaneSide( (emins), (emaxs), (p))) 238 239 void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal ); 240 void PerpendicularVector( vec3_t dst, const vec3_t src ); 241 void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees ); 242 243 244 //============================================= 245 246 /* FIXME: Beware - _vsnprintf does not end with \0 - vsnprintf (*nix) does */ 247 #if defined WIN32_VARIANT 248 #define vsnprintf _vsnprintf 249 #endif 250 251 char *COM_SkipPath (char *pathname); 252 void COM_StripExtension (char *in, char *out); 253 void COM_FileBase (char *in, char *out); 254 void COM_FilePath (char *in, char *out); 255 void COM_DefaultExtension (char *path, char *extension); 256 257 char *COM_Parse (char **data_p); 258 // data is an in/out parm, returns a parsed out token 259 260 char *Com_ParseExt (char **data_p, qboolean allowNewLines); 261 char *Com_SkipWhiteSpace (char *data_p, qboolean *hasNewLines); 262 void Com_SkipRestOfLine (char **data_p); 263 264 int com_parseLine; 265 266 void Com_sprintf (char *dest, int size, char *fmt, ...); 267 268 void Com_PageInMemory (byte *buffer, int size); 269 270 //============================================= 271 272 // portable case insensitive compare 273 int Q_strcasecmp (const char *s1, const char *s2); 274 int Q_strncasecmp (const char *s1, const char *s2, int n); 275 void Q_strcat (char *dst, const char *src, int dstSize); 276 int Q_strnicmp (const char *string1, const char *string2, int n); 277 char *Q_strlwr(char *s); 278 // 279 void Q_strncpyz2 (char *dst, const char *src, int dstSize); 280 281 //============================================= 282 283 short BigShort(short l); 284 short LittleShort(short l); 285 int BigLong (int l); 286 int LittleLong (int l); 287 float BigFloat (float l); 288 float LittleFloat (float l); 289 290 void Swap_Init (void); 291 char *va(char *format, ...); 292 293 //============================================= 294 295 // 296 // key / value info strings 297 // 298 #define MAX_INFO_KEY 64 299 #define MAX_INFO_VALUE 64 300 #define MAX_INFO_STRING 512 301 302 char *Info_ValueForKey (char *s, char *key); 303 qboolean Info_KeyExists (const char *s, const char *key); 304 void Info_RemoveKey (char *s, char *key); 305 void Info_SetValueForKey (char *s, char *key, char *value); 306 qboolean Info_Validate (char *s); 307 308 size_t ValidatePlayerName( char *player_name, size_t player_name_size ); 309 310 /* 311 ============================================================== 312 313 SYSTEM SPECIFIC 314 315 ============================================================== 316 */ 317 318 extern int curtime; // time returned by last Sys_Milliseconds 319 320 int Sys_Milliseconds (void); 321 void Sys_Mkdir (char *path); 322 323 // large block stack allocation routines 324 void *Hunk_Begin (int maxsize); 325 void *Hunk_Alloc (int size); 326 void Hunk_Free (void *buf); 327 int Hunk_End (void); 328 329 // directory searching 330 #define SFF_ARCH 0x01 331 #define SFF_HIDDEN 0x02 332 #define SFF_RDONLY 0x04 333 #define SFF_SUBDIR 0x08 334 #define SFF_SYSTEM 0x10 335 336 /* 337 ** pass in an attribute mask of things you wish to REJECT 338 */ 339 char *Sys_FindFirst (char *path, unsigned musthave, unsigned canthave ); 340 char *Sys_FindNext ( unsigned musthave, unsigned canthave ); 341 void Sys_FindClose (void); 342 343 344 // this is only here so the functions in q_shared.c and q_shwin.c can link 345 void Sys_Error (char *error, ...); 346 void Com_Printf (char *msg, ...); 347 348 /* 349 ========================================================== 350 351 CVARS (console variables) 352 353 ========================================================== 354 */ 355 356 #ifndef CVAR 357 #define CVAR 358 359 // These are all the flags that actually do anything. 360 // NOTE: there is no need to maintain any kind of compatibility, we can change 361 // these if we want to. 362 #define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc 363 #define CVAR_USERINFO 2 // added to userinfo when changed 364 #define CVAR_SERVERINFO 4 // added to serverinfo when changed 365 #define CVAR_NOSET 8 // don't allow change from console at all, 366 // but can be set from the command line 367 #define CVAR_LATCH 16 // save changes until server restart 368 #define CVAR_ROM 32 // cannot be set by user at all 369 #define CVAR_GAMEINFO 64 // added to the 'mods' field of the serverinfo 370 // string when changed 371 #define CVAR_PROFILE 128 // profile information 372 373 // These flags are purely for documentation (used by the "help" command.) 374 // Usually, at most one of these will be set. They are not "enforced" by the 375 // code in any way. 376 // TODO: go through and add all these flags for cvars as appropriate. 377 // TODO: others like address, path, IP address, etc? 378 #define CVARDOC_BOOL 512 379 #define CVARDOC_STR 1024 380 #define CVARDOC_FLOAT 2048 381 #define CVARDOC_INT 4096 382 383 // nothing outside the Cvar_*() functions should modify these fields! 384 typedef struct cvar_s 385 { 386 char *name; 387 unsigned int hash_key; 388 char *string; 389 char *latched_string; // for CVAR_LATCH vars 390 int flags; 391 qboolean modified; // set each time the cvar is changed 392 float value; 393 float default_value; 394 int integer; 395 char *description; // Optional (may be NULL) 396 struct cvar_s *next; 397 } cvar_t; 398 399 #endif // CVAR 400 401 /* 402 ============================================================== 403 404 COLLISION DETECTION 405 406 ============================================================== 407 */ 408 409 // lower bits are stronger, and will eat weaker brushes completely 410 #define CONTENTS_SOLID 1 // an eye is never valid in a solid 411 #define CONTENTS_WINDOW 2 // translucent, but not watery 412 #define CONTENTS_AUX 4 413 #define CONTENTS_LAVA 8 414 #define CONTENTS_SLIME 16 415 #define CONTENTS_WATER 32 416 #define CONTENTS_MIST 64 417 #define LAST_VISIBLE_CONTENTS 64 418 419 // remaining contents are non-visible, and don't eat brushes 420 421 #define CONTENTS_AREAPORTAL 0x8000 422 423 #define CONTENTS_PLAYERCLIP 0x10000 424 #define CONTENTS_MONSTERCLIP 0x20000 425 426 // currents can be added to any other contents, and may be mixed 427 #define CONTENTS_CURRENT_0 0x40000 428 #define CONTENTS_CURRENT_90 0x80000 429 #define CONTENTS_CURRENT_180 0x100000 430 #define CONTENTS_CURRENT_270 0x200000 431 #define CONTENTS_CURRENT_UP 0x400000 432 #define CONTENTS_CURRENT_DOWN 0x800000 433 434 #define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity 435 436 #define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game 437 #define CONTENTS_DEADMONSTER 0x4000000 438 #define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs 439 #define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans 440 #define CONTENTS_LADDER 0x20000000 441 442 #define SURF_LIGHT 0x1 // value will hold the light strength 443 444 #define SURF_SLICK 0x2 // effects game physics 445 446 #define SURF_SKY 0x4 // don't draw, but add to skybox 447 #define SURF_WARP 0x8 // turbulent water warp 448 #define SURF_TRANS33 0x10 449 #define SURF_TRANS66 0x20 450 #define SURF_FLOWING 0x40 // scroll towards angle 451 #define SURF_NODRAW 0x80 // don't bother referencing the texture 452 #define SURF_BLOOD 0x400 // dripping blood surface 453 #define SURF_WATER 0x800 // dripping water surface 454 #define SURF_UNDERWATER 0x2000 // reflecting ripples; applied automatically 455 // to underwater surfs but could be applied 456 // manually as well 457 458 // content masks 459 #define MASK_ALL (-1) 460 #define MASK_SOLID (CONTENTS_SOLID|CONTENTS_WINDOW) 461 #define MASK_PLAYERSOLID (CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER) 462 #define MASK_DEADSOLID (CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_WINDOW) 463 #define MASK_MONSTERSOLID (CONTENTS_SOLID|CONTENTS_MONSTERCLIP|CONTENTS_WINDOW|CONTENTS_MONSTER) 464 #define MASK_WATER (CONTENTS_WATER|CONTENTS_LAVA|CONTENTS_SLIME) 465 #define MASK_OPAQUE (CONTENTS_SOLID|CONTENTS_SLIME|CONTENTS_LAVA) 466 #define MASK_SHOT (CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_WINDOW|CONTENTS_DEADMONSTER) 467 #define MASK_CURRENT (CONTENTS_CURRENT_0|CONTENTS_CURRENT_90|CONTENTS_CURRENT_180|CONTENTS_CURRENT_270|CONTENTS_CURRENT_UP|CONTENTS_CURRENT_DOWN) 468 #define MASK_VISIBILILITY (CONTENTS_SOLID/*|CONTENTS_WINDOW*/|CONTENTS_WATER|CONTENTS_LAVA|CONTENTS_SLIME) 469 470 // gi.BoxEdicts() can return a list of either solid or trigger entities 471 // FIXME: eliminate AREA_ distinction? 472 #define AREA_SOLID 1 473 #define AREA_TRIGGERS 2 474 475 // plane_t structure 476 // !!! if this is changed, it must be changed in asm code too !!! 477 typedef struct cplane_s 478 { 479 vec3_t normal; 480 float dist; 481 byte type; // for fast side tests 482 byte signbits; // signx + (signy<<1) + (signz<<1) 483 byte pad[2]; 484 } cplane_t; 485 486 // structure offset for asm code 487 #define CPLANE_NORMAL_X 0 488 #define CPLANE_NORMAL_Y 4 489 #define CPLANE_NORMAL_Z 8 490 #define CPLANE_DIST 12 491 #define CPLANE_TYPE 16 492 #define CPLANE_SIGNBITS 17 493 #define CPLANE_PAD0 18 494 #define CPLANE_PAD1 19 495 496 typedef struct cmodel_s 497 { 498 vec3_t mins, maxs; 499 vec3_t origin; // for sounds or lights 500 int headnode; 501 } cmodel_t; 502 503 typedef struct csurface_s 504 { 505 char name[16]; 506 int flags; 507 int value; 508 } csurface_t; 509 510 typedef struct mapsurface_s // used internally due to name len probs //ZOID 511 { 512 csurface_t c; 513 char rname[32]; 514 } mapsurface_t; 515 516 // a trace is returned when a box is swept through the world 517 typedef struct 518 { 519 qboolean allsolid; // if true, plane is not valid 520 qboolean startsolid; // if true, the initial point was in a solid area 521 float fraction; // time completed, 1.0 = didn't hit anything 522 vec3_t endpos; // final position 523 cplane_t plane; // surface normal at impact 524 csurface_t *surface; // surface hit 525 int contents; // contents on other side of surface hit 526 struct edict_s *ent; // not set by CM_*() functions 527 } trace_t; 528 529 // pmove_state_t is the information necessary for client side movement 530 // prediction 531 typedef enum 532 { 533 // can accelerate and turn 534 PM_NORMAL, 535 PM_SPECTATOR, 536 // no acceleration or turning 537 PM_DEAD, 538 PM_GIB, // different bounding box 539 PM_FREEZE 540 } pmtype_t; 541 542 // pmove->pm_flags 543 #define PMF_DUCKED 1 544 #define PMF_JUMP_HELD 2 545 #define PMF_ON_GROUND 4 546 #define PMF_TIME_WATERJUMP 8 // pm_time is waterjump 547 #define PMF_TIME_LAND 16 // pm_time is time before rejump 548 #define PMF_TIME_TELEPORT 32 // pm_time is non-moving time 549 #define PMF_NO_PREDICTION 64 // temporarily disables prediction (used for grappling hook) 550 551 // this structure needs to be communicated bit-accurate 552 // from the server to the client to guarantee that 553 // prediction stays in sync, so no floats are used. 554 // if any part of the game code modifies this struct, it 555 // will result in a prediction error of some degree. 556 typedef struct 557 { 558 pmtype_t pm_type; 559 560 int origin[3]; // 12.3 561 short velocity[3]; // 12.3 562 byte pm_flags; // ducked, jump_held, etc 563 byte pm_time; // each unit = 8 ms 564 short gravity; 565 short delta_angles[3]; // add to command angles to get view direction 566 // changed by spawns, rotating objects, and teleporters 567 } pmove_state_t; 568 569 // 570 // button bits 571 // 572 #define BUTTON_ATTACK 1 573 #define BUTTON_USE 2 574 #define BUTTON_ATTACK2 4 575 #define BUTTON_ANY 128 // any key whatsoever 576 577 // usercmd_t is sent to the server each client frame 578 typedef struct usercmd_s 579 { 580 byte msec; 581 byte buttons; 582 short angles[3]; 583 short forwardmove, sidemove, upmove; 584 byte impulse; // remove? 585 byte lightlevel; // light level the player is standing on 586 } usercmd_t; 587 588 #define MAXTOUCH 32 589 typedef struct 590 { 591 // state (in / out) 592 pmove_state_t s; 593 594 // command (in) 595 usercmd_t cmd; 596 qboolean snapinitial; // if s has been changed outside pmove 597 598 // results (out) 599 int numtouch; 600 struct edict_s *touchents[MAXTOUCH]; 601 602 vec3_t viewangles; // clamped 603 float viewheight; 604 605 vec3_t mins, maxs; // bounding box size 606 607 struct edict_s *groundentity; 608 int watertype; 609 int waterlevel; 610 int joustattempts; 611 612 // callbacks to test the world 613 trace_t (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end); 614 int (*pointcontents) (vec3_t point); 615 } pmove_t; 616 617 // entity_state_t->effects 618 // Effects are things handled on the client side (lights, particles, frame animations) 619 // that happen constantly on the given entity. 620 // An entity that has effects will be sent to the client 621 // even if it has a zero index model. 622 #define EF_ROTATE 0x00000001 // rotate (bonus items) 623 #define EF_GIB 0x00000002 // leave a trail 624 #define EF_BLASTER 0x00000008 // redlight + trail 625 #define EF_ROCKET 0x00000010 // redlight + trail 626 #define EF_GRENADE 0x00000020 627 #define EF_HYPERBLASTER 0x00000040 628 #define EF_BFG 0x00000080 629 #define EF_COLOR_SHELL 0x00000100 630 #define EF_POWERSCREEN 0x00000200 631 #define EF_ANIM01 0x00000400 // automatically cycle between frames 0 and 1 at 2 hz 632 #define EF_ANIM23 0x00000800 // automatically cycle between frames 2 and 3 at 2 hz 633 #define EF_ANIM_ALL 0x00001000 // automatically cycle through all frames at 2hz 634 #define EF_ANIM_ALLFAST 0x00002000 // automatically cycle through all frames at 10hz 635 #define EF_BUBBLES 0x00004000 636 #define EF_QUAD 0x00008000 637 #define EF_PENT 0x00010000 638 #define EF_TELEPORTER 0x00020000 // particle fountain 639 #define EF_TEAM1 0x00040000 640 #define EF_TEAM2 0x00080000 641 #define EF_GREENGIB 0x00200000 642 #define EF_PLASMA 0x01000000 643 #define EF_SHIPEXHAUST 0x02000000 644 #define EF_ROCKETEXHAUST 0x80000000 645 646 // entity_state_t->renderfx flags 647 #define RF_MINLIGHT 1 // allways have some light (viewmodel) 648 #define RF_VIEWERMODEL 2 // don't draw through eyes, only mirrors 649 #define RF_WEAPONMODEL 4 // only draw through eyes 650 #define RF_FULLBRIGHT 8 // allways draw full intensity 651 #define RF_DEPTHHACK 16 // for view weapon Z crunching 652 #define RF_TRANSLUCENT 32 653 #define RF_FRAMELERP 64 654 #define RF_BEAM 128 // unused 655 #define RF_CUSTOMSKIN 256 // skin is an index in image_precache 656 #define RF_GLOW 512 // pulse lighting for bonus items 657 #define RF_SHELL_RED 1024 658 #define RF_SHELL_GREEN 2048 659 #define RF_SHELL_BLUE 4096 660 #define RF_BOBBING 0x00008000 // 32768 661 #define RF_SHELL_DOUBLE 0x00010000 // 65536 662 #define RF_SHELL_HALF_DAM 0x00020000 663 #define RF_NOSHADOWS 0x00040000 //use this one for turning off shadows, etc. 664 #define RF_MONSTER 0x00080000 665 #define RF_NODRAW 0x00100000 //use this instead of a 0 modelindex for compatibility. 666 #define RF_MENUMODEL 0x01280000 //for player menu 667 668 669 // player_state_t->refdef flags 670 #define RDF_UNDERWATER 1 // warp the screen as apropriate 671 #define RDF_NOWORLDMODEL 2 // used for player configuration screen 672 #define RDF_IRGOGGLES 4 673 #define RDF_UVGOGGLES 8 674 675 // 676 // muzzle flashes / player effects 677 // 678 #define MZ_BLASTER 0 679 #define MZ_MACHINEGUN 1 680 #define MZ_SHOTGUN 2 681 #define MZ_CHAINGUN1 3 682 #define MZ_CHAINGUN2 4 683 #define MZ_CHAINGUN3 5 684 #define MZ_RAILGUN 6 685 #define MZ_ROCKET 7 686 #define MZ_GRENADE 8 687 #define MZ_LOGIN 9 688 #define MZ_LOGOUT 10 689 #define MZ_RESPAWN 11 690 #define MZ_BFG 12 691 #define MZ_SSHOTGUN 13 692 #define MZ_HYPERBLASTER 14 693 #define MZ_ITEMRESPAWN 15 694 #define MZ_SILENCED 128 // bit flag ORed with one of the above numbers 695 696 // temp entity events 697 // 698 // Temp entity events are for things that happen 699 // at a location seperate from any existing entity. 700 // Temporary entity messages are explicitly constructed 701 // and broadcast. 702 703 #define TE_GUNSHOT 0 704 #define TE_BLOOD 1 705 #define TE_BLASTER 2 706 #define TE_RAILTRAIL 3 707 #define TE_LASERBEAM 4 708 #define TE_EXPLOSION1 5 709 #define TE_EXPLOSION2 6 710 #define TE_ROCKET_EXPLOSION 7 711 #define TE_SPARKS 9 712 #define TE_SPLASH 10 713 #define TE_BUBBLETRAIL 11 714 #define TE_SCREEN_SPARKS 12 715 #define TE_DEATHFIELD2 13 716 #define TE_BULLET_SPARKS 14 717 #define TE_LASER_SPARKS 15 718 #define TE_DONTUSE 16 719 #define TE_ROCKET_EXPLOSION_WATER 17 720 #define TE_REDLASER 19 721 #define TE_BFG_BIGEXPLOSION 21 722 #define TE_BOSSTPORT 22 723 #define TE_DONTUSE2 23 724 #define TE_GREENBLOOD 26 725 #define TE_LIGHTNING 33 726 #define TE_VAPORBEAM 38 727 #define TE_STEAM 40 728 #define TE_SAYICON 45 729 #define TE_TELEPORT_EFFECT 48 730 #define TE_LEADERBLASTER 56 731 #define TE_CHAINGUNSMOKE 57 732 #define TE_BLUE_MUZZLEFLASH 58 733 #define TE_SMART_MUZZLEFLASH 59 734 #define TE_VOLTAGE 60 735 #define TE_DEATHFIELD 61 736 #define TE_BLASTERBEAM 62 737 #define TE_STAIN 63 738 #define TE_FIRE 64 739 #define TE_SMOKE 66 740 741 #define SPLASH_UNKNOWN 0 742 #define SPLASH_SPARKS 1 743 #define SPLASH_BLUE_WATER 2 744 #define SPLASH_BROWN_WATER 3 745 #define SPLASH_SLIME 4 746 #define SPLASH_LAVA 5 747 #define SPLASH_BLOOD 6 748 749 750 // sound channels 751 // channel 0 never willingly overrides 752 // other channels (1-7) allways override a playing sound on that channel 753 #define CHAN_AUTO 0 754 #define CHAN_WEAPON 1 755 #define CHAN_VOICE 2 756 #define CHAN_ITEM 3 757 #define CHAN_BODY 4 758 // modifier flags 759 #define CHAN_NO_PHS_ADD 8 // send to all clients, not just ones in PHS (ATTN 0 will also do this) 760 #define CHAN_RELIABLE 16 // send by reliable message, not datagram 761 762 763 // sound attenuation values 764 #define ATTN_NONE 0 // full volume the entire level 765 #define ATTN_NORM 1 766 #define ATTN_IDLE 2 767 #define ATTN_STATIC 3 // diminish very rapidly with distance 768 769 770 // player_state->stats[] indexes 771 #define STAT_HEALTH_ICON 0 772 #define STAT_HEALTH 1 773 #define STAT_AMMO_ICON 2 774 #define STAT_AMMO 3 775 #define STAT_ARMOR_ICON 4 776 #define STAT_ARMOR 5 777 #define STAT_RED_MATCHES 6 778 #define STAT_BLUE_MATCHES 7 779 #define STAT_TACTICAL_SCORE 8 780 #define STAT_TIMER_ICON 9 781 #define STAT_TIMER 10 782 #define STAT_HELPICON 11 783 #define STAT_SELECTED_ITEM 12 784 #define STAT_LAYOUTS 13 785 #define STAT_FRAGS 14 786 #define STAT_FLASHES 15 // cleared each frame, 1 = health, 2 = armor 787 #define STAT_FLAGS 15 // misc boolean values, use only bits 3-16 788 #define STAT_CHASE 16 789 #define STAT_SPECTATOR 17 790 #define STAT_SCOREBOARD 18 791 #define STAT_DEATHS 19 792 #define STAT_HIGHSCORE 20 793 #define STAT_REDSCORE 21 794 #define STAT_BLUESCORE 22 795 #define STAT_FLAG_ICON 23 796 #define STAT_ZOOMED 24 797 #define STAT_WEAPN1 25 798 #define STAT_WEAPN2 26 799 #define STAT_WEAPN3 27 800 #define STAT_WEAPN4 28 801 #define STAT_WEAPN5 29 802 #define STAT_WEAPN6 30 803 #define STAT_WEAPN7 31 804 805 #define MAX_STATS 32 806 807 // bit flags for use in STAT_FLAGS 808 #define STAT_FLAGS_CROSSHAIRPOSITION (4|8) 809 #define STAT_FLAGS_CROSSHAIRPOS1 0 //default 810 #define STAT_FLAGS_CROSSHAIRCENTER 4 811 #define STAT_FLAGS_CROSSHAIRPOS2 8 812 #define STAT_FLAGS_CROSSHAIRPOS3 12 813 814 815 // dmflags->value flags 816 #define DF_NO_HEALTH 0x00000001 // 1 817 #define DF_NO_ITEMS 0x00000002 // 2 818 #define DF_WEAPONS_STAY 0x00000004 // 4 819 #define DF_NO_FALLING 0x00000008 // 8 820 #define DF_INSTANT_ITEMS 0x00000010 // 16 821 #define DF_SAME_LEVEL 0x00000020 // 32 822 #define DF_SKINTEAMS 0x00000040 // 64 823 #define DF_NO_FRIENDLY_FIRE 0x00000100 // 256 824 #define DF_SPAWN_FARTHEST 0x00000200 // 512 825 #define DF_FORCE_RESPAWN 0x00000400 // 1024 826 #define DF_NO_ARMOR 0x00000800 // 2048 827 #define DF_ALLOW_EXIT 0x00001000 // 4096 828 #define DF_INFINITE_AMMO 0x00002000 // 8192 829 #define DF_QUAD_DROP 0x00004000 // 16384 830 831 // RAFAEL 832 #define DF_QUADFIRE_DROP 0x00010000 // 65536 833 834 //CODERED 835 836 #define DF_BOT_AUTOSAVENODES 0x00020000 //131072 837 #define DF_BOTCHAT 0x00040000 //262144 838 #define DF_BOT_FUZZYAIM 0x00080000 //524288 839 #define DF_BOTS 0x00100000 //1048576 840 #define DF_BOT_LEVELAD 0x00200000 //2097152 841 842 /* 843 ========================================================== 844 845 ELEMENTS COMMUNICATED ACROSS THE NET 846 847 ========================================================== 848 */ 849 850 #define ANGLE2SHORT(x) ((int)((x)*65536/360) & 65535) 851 #define SHORT2ANGLE(x) ((x)*(360.0/65536)) 852 853 // Number of bytes per axis of world coordinates in the net protocol. 854 // 2 is the default, backward-compatible number. 855 // TODO: make this a variable, have it set based on the map size, server kicks 856 // clients that don't support big maps. 857 #define coord_bytes 2 858 859 860 // 861 // config strings are a general means of communication from 862 // the server to all connected clients. 863 // Each config string can be at most MAX_QPATH characters. 864 // Alien Arena client/server protocol depends on MAX_QPATH being 64 865 // 866 #define CS_NAME 0 867 #define CS_SKY 2 868 #define CS_SKYAXIS 3 // %f %f %f format 869 #define CS_SKYROTATE 4 870 #define CS_STATUSBAR 5 // display program string 871 872 #define CS_AIRACCEL 29 // air acceleration control 873 #define CS_MAXCLIENTS 30 874 #define CS_MAPCHECKSUM 31 // for catching cheater maps 875 876 #define CS_MODELS 32 877 #define CS_SOUNDS (CS_MODELS+MAX_MODELS) 878 #define CS_IMAGES (CS_SOUNDS+MAX_SOUNDS) 879 #define CS_LIGHTS (CS_IMAGES+MAX_IMAGES) 880 #define CS_ITEMS (CS_LIGHTS+MAX_LIGHTSTYLES) 881 #define CS_PLAYERSKINS (CS_ITEMS+MAX_ITEMS) 882 #define CS_GENERAL (CS_PLAYERSKINS+MAX_CLIENTS) 883 #define MAX_CONFIGSTRINGS (CS_GENERAL+MAX_GENERAL) 884 885 886 //============================================== 887 888 889 // entity_state_t->event values 890 // ertity events are for effects that take place reletive 891 // to an existing entities origin. Very network efficient. 892 // All muzzle flashes really should be converted to events... 893 typedef enum 894 { 895 EV_NONE, 896 EV_ITEM_RESPAWN, 897 EV_FOOTSTEP, 898 EV_FALLSHORT, 899 EV_FALL, 900 EV_FALLFAR, 901 EV_PLAYER_TELEPORT, 902 EV_OTHER_TELEPORT, 903 EV_WADE 904 } entity_event_t; 905 906 907 // entity_state_t is the information conveyed from the server 908 // in an update message about entities that the client will 909 // need to render in some way 910 typedef struct entity_state_s 911 { 912 int number; // edict index 913 914 vec3_t origin; 915 vec3_t angles; 916 vec3_t old_origin; // for lerping 917 int modelindex; 918 int modelindex2, modelindex3, modelindex4; // weapons, CTF flags, etc 919 int frame; 920 int skinnum; 921 unsigned int effects; // PGM - we're filling it, so it needs to be unsigned 922 int renderfx; 923 int solid; // for client side prediction, 8*(bits 0-4) is x/y radius 924 // 8*(bits 5-9) is z down distance, 8(bits10-15) is z up 925 // gi.linkentity sets this properly 926 int sound; // for looping sounds, to guarantee shutoff 927 int event; // impulse events -- muzzle flashes, footsteps, etc 928 // events only go out for a single frame, they 929 // are automatically cleared each frame 930 vec3_t spawn_pos; //used for remembering the original spawn position of an entity 931 } entity_state_t; 932 933 //============================================== 934 935 //bot score info 936 //data used to track bot scores for server status strings 937 typedef struct 938 { 939 char name[MAX_INFO_STRING]; 940 int score; 941 } bot_t; 942 943 // player_state_t is the information needed in addition to pmove_state_t 944 // to rendered a view. There will only be 10 player_state_t sent each second, 945 // but the number of pmove_state_t changes will be reletive to client 946 // frame rates 947 typedef struct 948 { 949 pmove_state_t pmove; // for prediction 950 951 // these fields do not need to be communicated bit-precise 952 953 vec3_t viewangles; // for fixed views 954 vec3_t viewoffset; // add to pmovestate->origin 955 vec3_t kick_angles; // add to view direction to get render angles 956 // set by weapon kicks, pain effects, etc 957 958 vec3_t gunangles; 959 vec3_t gunoffset; 960 int gunindex; 961 int gunframe; 962 963 float blend[4]; // rgba full screen effect 964 965 float fov; // horizontal field of view 966 967 int rdflags; // refdef flags 968 969 short stats[MAX_STATS]; // fast status bar updates 970 971 //bot score info 972 int botnum; 973 bot_t bots[100]; 974 975 } player_state_t; 976 977 //colored text 978 //============================================= 979 980 #define Q_COLOR_ESCAPE '^' 981 #define Q_IsColorString(p) ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE ) 982 983 #define COLOR_BLACK '0' 984 #define COLOR_RED '1' 985 #define COLOR_GREEN '2' 986 #define COLOR_YELLOW '3' 987 #define COLOR_BLUE '4' 988 #define COLOR_CYAN '5' 989 #define COLOR_MAGENTA '6' 990 #define COLOR_WHITE '7' 991 #define ColorIndex(c) ( ( (c) - '0' ) & 7 ) 992 993 #define COLOR_R(rgba) ((rgba) & 0xFF) 994 #define COLOR_G(rgba) (((rgba) >> 8) & 0xFF) 995 #define COLOR_B(rgba) (((rgba) >> 16) & 0xFF) 996 #define COLOR_A(rgba) (((rgba) >> 24) & 0xFF) 997 #define COLOR_RGB(r,g,b) (((r) << 0)|((g) << 8)|((b) << 16)) 998 #define COLOR_RGBA(r,g,b,a) (((r) << 0)|((g) << 8)|((b) << 16)|((a) << 24)) 999 1000 #define S_COLOR_BLACK "^0" 1001 #define S_COLOR_RED "^1" 1002 #define S_COLOR_GREEN "^2" 1003 #define S_COLOR_YELLOW "^3" 1004 #define S_COLOR_BLUE "^4" 1005 #define S_COLOR_CYAN "^5" 1006 #define S_COLOR_MAGENTA "^6" 1007 #define S_COLOR_WHITE "^7" 1008 1009 //unlagged - lag simulation #2 1010 #define MAX_LATENT_CMDS 64 1011 //unlagged - lag simulation #2 1012 1013 // 1014 // types of compression 1015 // 1016 enum compressiontypes_e { 1017 compression_zlib_raw, 1018 compression_lzo, 1019 compression_zlib_header, 1020 last_compressiontype_known 1021 }; 1022 1023 #endif /* Q_SHARED_H_ */ 1024