1 /* 2 * client.h -- client main header 3 * $Id: client.h 5427 2015-08-12 18:56:56Z sezero $ 4 * 5 * Copyright (C) 1996-1997 Id Software, Inc. 6 * Copyright (C) 1997-1998 Raven Software Corp. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or (at 11 * your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * See the GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write to the Free Software Foundation, Inc., 21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 */ 23 24 #ifndef __H2W_CLIENT_H 25 #define __H2W_CLIENT_H 26 27 typedef struct 28 { 29 char name[16]; 30 qboolean failedload; // the name isn't a valid skin 31 cache_user_t cache; 32 } skin_t; 33 34 // player_state_t is the information needed by a player entity 35 // to do move prediction and to generate a drawable entity 36 typedef struct 37 { 38 int messagenum; // all player's won't be updated each frame 39 40 double state_time; // not the same as the packet time, 41 // because player commands come asyncronously 42 usercmd_t command; // last command for prediction 43 44 vec3_t origin; 45 vec3_t viewangles; // only for demos, not from server 46 vec3_t velocity; 47 int weaponframe; 48 49 int modelindex; 50 int frame; 51 int skinnum; 52 int effects; 53 int drawflags; 54 int scale; 55 int abslight; 56 57 int flags; // dead, gib, etc 58 59 float waterjumptime; 60 int onground; // -1 = in air, else pmove entity number 61 int oldbuttons; 62 } player_state_t; 63 64 65 #define MAX_SCOREBOARDNAME 16 66 typedef struct player_info_s 67 { 68 int userid; 69 char userinfo[MAX_INFO_STRING]; 70 71 // scoreboard information 72 char name[MAX_SCOREBOARDNAME]; 73 float entertime; 74 int frags; 75 int ping; 76 77 // skin information 78 int topcolor; 79 int bottomcolor; 80 int playerclass; 81 int level; 82 int spectator; 83 byte translations[VID_GRADES*256]; 84 skin_t *skin; 85 int modelindex; 86 qboolean Translated; 87 int siege_team; 88 qboolean shownames_off; 89 } player_info_t; 90 91 92 typedef struct 93 { 94 // generated on client side 95 usercmd_t cmd; // cmd that generated the frame 96 double senttime; // time cmd was sent off 97 int delta_sequence; // sequence number to delta from, -1 = full update 98 99 // received from server 100 double receivedtime; // time message was received, or -1 101 player_state_t playerstate[MAX_CLIENTS]; // message received that reflects performing 102 // the usercmd 103 packet_entities_t packet_entities; 104 qboolean invalid; // true if the packet_entities delta was invalid 105 } frame_t; 106 107 108 typedef struct 109 { 110 int destcolor[3]; 111 int percent; // 0-256 112 } cshift_t; 113 114 #define CSHIFT_CONTENTS 0 115 #define CSHIFT_DAMAGE 1 116 #define CSHIFT_BONUS 2 117 #define CSHIFT_POWERUP 3 118 #define CSHIFT_INTERVENTION 4 119 #define NUM_CSHIFTS 5 120 121 // 122 // client_state_t should hold all pieces of the client state 123 // 124 125 #define MAX_DLIGHTS 32 126 typedef struct 127 { 128 int key; // so entities can reuse same entry 129 vec3_t origin; 130 float radius; 131 float die; // stop lighting after this time 132 float decay; // drop this each second 133 float minlight; // don't add when contributing less 134 float color[4]; 135 qboolean dark; // subtracts light instead of adding 136 } dlight_t; 137 138 typedef struct 139 { 140 int length; 141 char map[MAX_STYLESTRING]; 142 } lightstyle_t; 143 144 #define MAX_EFRAGS 512 145 146 #define MAX_DEMOS 8 147 #define MAX_DEMONAME 16 148 149 typedef enum 150 { 151 ca_disconnected, // full screen console with no connection 152 ca_demostart, // starting up a demo 153 ca_connected, // netchan_t established, waiting for svc_serverdata 154 ca_onserver, // processing data lists, donwloading, etc 155 ca_active // everything is in, so frames can be rendered 156 } cactive_t; 157 158 typedef enum 159 { 160 dl_none, 161 dl_model, 162 dl_sound, 163 dl_skin, 164 dl_single 165 } dltype_t; // download type 166 167 // 168 // the client_static_t structure is persistant through an arbitrary number 169 // of server connections 170 // 171 typedef struct 172 { 173 // connection information 174 cactive_t state; 175 176 // network stuff 177 netchan_t netchan; 178 179 // private userinfo for sending to masterless servers 180 char userinfo[MAX_INFO_STRING]; 181 182 char servername[MAX_OSPATH]; // name of server from original connect 183 184 FILE *download; // file transfer from server 185 char downloadtempname[MAX_OSPATH]; 186 char downloadname[MAX_OSPATH]; 187 int downloadnumber; 188 dltype_t downloadtype; 189 int downloadpercent; 190 191 // demo loop control 192 int demonum; // -1 = don't play demos 193 char demos[MAX_DEMOS][MAX_DEMONAME]; // when not playing 194 195 // demo recording info must be here, because record is started before 196 // entering a map (and clearing client_state_t) 197 qboolean demorecording; 198 qboolean demoplayback; 199 qboolean timedemo; 200 FILE *demofile; 201 float td_lastframe; // to meter out one message a frame 202 int td_startframe; // host_framecount at start 203 float td_starttime; // realtime at second frame of timedemo 204 205 float latency; // rolling average 206 } client_static_t; 207 208 extern client_static_t cls; 209 210 // 211 // the client_state_t structure is wiped completely at every 212 // server signon 213 // 214 typedef struct 215 { 216 int servercount; // server identification for prespawns 217 218 char serverinfo[MAX_SERVERINFO_STRING]; 219 220 int parsecount; // server message counter 221 int validsequence; // this is the sequence number of the last good 222 // packetentity_t we got. If this is 0, we can't 223 // render a frame yet 224 int movemessages; // since connecting to this server 225 // throw out the first couple, so the player 226 // doesn't accidentally do something the 227 // first frame 228 229 int protocol; 230 int spectator; 231 232 double last_ping_request; // while showing scoreboard 233 double last_servermessage; 234 235 // sentcmds[cl.netchan.outgoing_sequence & UPDATE_MASK] = cmd 236 frame_t frames[UPDATE_BACKUP]; 237 238 // information for local display 239 int stats[MAX_CL_STATS]; // health, etc 240 int inv_order[MAX_INVENTORY]; 241 int inv_count, inv_startpos, inv_selected; 242 float item_gettime[32]; // cl.time of aquiring item, for blinking 243 float faceanimtime; // use anim frame if cl.time < this 244 245 entvars_t v; // NOTE: not every field will be update 246 // you must specifically add them in 247 // functions SV_WriteClientdatatToMessage() 248 // and CL_ParseClientdata() 249 250 cshift_t cshifts[NUM_CSHIFTS]; // color shifts for damage, powerups 251 cshift_t prev_cshifts[NUM_CSHIFTS]; // and content types 252 253 char puzzle_pieces[8][10]; // puzzle piece names 254 255 // the client maintains its own idea of view angles, which are 256 // sent to the server each frame. And only reset at level change 257 // and teleport times 258 vec3_t viewangles; 259 260 // the client simulates or interpolates movement to get these values 261 double time; // this is the time value that the client 262 // is rendering at. always <= realtime 263 vec3_t simorg; 264 vec3_t simvel; 265 vec3_t simangles; 266 267 float idealroll; 268 float rollvel; 269 270 // pitch drifting vars 271 float idealpitch; 272 float pitchvel; 273 qboolean nodrift; 274 float driftmove; 275 double laststop; 276 277 byte light_level; 278 279 float crouch; // local amount for smoothing stepups 280 281 qboolean paused; // send over by server 282 283 float punchangle; // temporary view kick from weapon firing 284 285 // intermissions: setup by CL_SetupIntermission() and run by SB_IntermissionOverlay() 286 int intermission; // don't change view angle, full screen, etc 287 int completed_time; // latched at intermission start 288 int message_index; 289 int intermission_flags; 290 const char *intermission_pic; 291 int lasting_time; 292 int intermission_next; 293 294 // 295 // information that is static for the entire time connected to a server 296 // 297 char model_name[MAX_MODELS][MAX_QPATH]; 298 char sound_name[MAX_SOUNDS][MAX_QPATH]; 299 300 struct qmodel_s *model_precache[MAX_MODELS]; 301 struct sfx_s *sound_precache[MAX_SOUNDS]; 302 303 char mapname[40]; 304 char levelname[40]; // for display on solo scoreboard 305 int playernum; 306 307 // refresh related state 308 struct qmodel_s *worldmodel; // cl_entitites[0].model 309 struct efrag_s *free_efrags; 310 int num_entities; // stored bottom up in cl_entities array 311 int num_statics; // stored top down in cl_entitiers 312 313 int cdtrack; // cd audio 314 char midi_name[128]; // midi file name 315 316 entity_t viewent; // weapon model 317 318 struct EffectT Effects[MAX_EFFECTS]; 319 320 unsigned int PIV; // players in view 321 322 // all player information 323 player_info_t players[MAX_CLIENTS]; 324 } client_state_t; 325 326 327 // 328 // edict->flags 329 // 330 #define FL_FLY 1 331 #define FL_SWIM 2 332 #define FL_CONVEYOR 4 333 #define FL_CLIENT 8 334 #define FL_INWATER 16 335 #define FL_MONSTER 32 336 #define FL_GODMODE 64 337 #define FL_NOTARGET 128 338 #define FL_ITEM 256 339 #define FL_ONGROUND 512 340 #define FL_PARTIALGROUND 1024 // not all corners are valid 341 #define FL_WATERJUMP 2048 // player jumping out of water 342 #define FL_JUMPRELEASED 4096 // for jump debouncing 343 #define FL_FLASHLIGHT 8192 344 #define FL_ARCHIVE_OVERRIDE 1048576 345 #define FL_ARTIFACTUSED 16384 346 #define FL_MOVECHAIN_ANGLE 32768 // when in a move chain, will update the angle 347 #define FL_CLASS_DEPENDENT 2097152 // model will appear different to each player 348 #define FL_SPECIAL_ABILITY1 4194304 // has 1st special ability 349 #define FL_SPECIAL_ABILITY2 8388608 // has 2nd special ability 350 351 #define FL2_CROUCHED 4096 352 353 // 354 // edict->movetype values 355 // 356 #define MOVETYPE_NONE 0 // never moves 357 #define MOVETYPE_ANGLENOCLIP 1 358 #define MOVETYPE_ANGLECLIP 2 359 #define MOVETYPE_WALK 3 // gravity 360 #define MOVETYPE_STEP 4 // gravity, special edge handling 361 #define MOVETYPE_FLY 5 362 #define MOVETYPE_TOSS 6 // gravity 363 #define MOVETYPE_PUSH 7 // no clip to world, push and crush 364 #define MOVETYPE_NOCLIP 8 365 #define MOVETYPE_FLYMISSILE 9 // extra size to monsters 366 #define MOVETYPE_BOUNCE 10 367 //#ifdef QUAKE2 368 #define MOVETYPE_BOUNCEMISSILE 11 // bounce w/o gravity 369 #define MOVETYPE_FOLLOW 12 // track movement of aiment 370 //#endif 371 #define MOVETYPE_PUSHPULL 13 // pushable/pullable object 372 #define MOVETYPE_SWIM 14 // should keep the object in water 373 374 // 375 // cvars 376 // 377 extern cvar_t cl_upspeed; 378 extern cvar_t cl_forwardspeed; 379 extern cvar_t cl_backspeed; 380 extern cvar_t cl_sidespeed; 381 382 extern cvar_t cl_movespeedkey; 383 384 extern cvar_t cl_yawspeed; 385 extern cvar_t cl_pitchspeed; 386 387 extern cvar_t cl_anglespeedkey; 388 389 extern cvar_t cl_shownet; 390 391 extern cvar_t cfg_unbindall; 392 393 extern cvar_t cl_pitchdriftspeed; 394 extern cvar_t lookspring; 395 extern cvar_t lookstrafe; 396 extern cvar_t sensitivity; 397 398 extern cvar_t m_pitch; 399 extern cvar_t m_yaw; 400 extern cvar_t m_forward; 401 extern cvar_t m_side; 402 403 extern cvar_t playerclass; 404 extern cvar_t spectator; 405 406 407 #define MAX_STATIC_ENTITIES 256 // torches, etc 408 409 extern client_state_t cl; 410 411 // FIXME, allocate dynamically 412 extern entity_state_t cl_baselines[MAX_EDICTS]; 413 extern efrag_t cl_efrags[MAX_EFRAGS]; 414 extern entity_t cl_static_entities[MAX_STATIC_ENTITIES]; 415 extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; 416 extern dlight_t cl_dlights[MAX_DLIGHTS]; 417 418 extern const int color_offsets[MAX_PLAYER_CLASS]; 419 420 //============================================================================= 421 422 extern float server_version; // version of server we connected to 423 424 // 425 // cl_main 426 // 427 dlight_t *CL_AllocDlight (int key); 428 void CL_DecayLights (void); 429 430 void CL_Init (void); 431 432 void CL_ClearState (void); 433 434 void CL_SendConnectPacket (void); 435 436 void CL_Disconnect (void); 437 void CL_NextDemo (void); 438 qboolean CL_DemoBehind(void); 439 440 #define MAX_VISEDICTS 512 441 extern int cl_numvisedicts, cl_oldnumvisedicts; 442 extern entity_t *cl_visedicts, *cl_oldvisedicts; 443 extern entity_t cl_visedicts_list[2][MAX_VISEDICTS]; 444 445 // 446 // cl_cmd 447 // 448 void Cmd_ForwardToServer (void); 449 void CL_Cmd_Init (void); 450 451 // 452 // cl_input 453 // 454 typedef struct 455 { 456 int down[2]; // key nums holding it down 457 int state; // low bit is down state 458 } kbutton_t; 459 460 extern kbutton_t in_mlook, in_klook; 461 extern kbutton_t in_strafe; 462 extern kbutton_t in_speed; 463 464 extern int in_impulse; 465 466 void CL_InitInput (void); 467 void CL_SendCmd (void); 468 void CL_BaseMove (usercmd_t *cmd); 469 470 // 471 // cl_demo.c 472 // 473 void CL_StopPlayback (void); 474 qboolean CL_GetMessage (void); 475 476 void CL_Stop_f (void); 477 void CL_Record_f (void); 478 void CL_ReRecord_f (void); 479 void CL_PlayDemo_f (void); 480 void CL_TimeDemo_f (void); 481 482 void CL_WriteDemoCmd (const usercmd_t *pcmd); 483 484 // 485 // cl_interlude.c 486 // 487 #define INTERMISSION_NOT_CONNECTED (1<<0) /* can not use cl.time, use realtime */ 488 #define INTERMISSION_NO_MENUS (1<<1) /* don't allow drawing the menus */ 489 #define INTERMISSION_NO_MESSAGE (1<<2) /* doesn't need a valid message index */ 490 #define INTERMISSION_PRINT_TOP (1<<3) /* print centered in top half of screen */ 491 #define INTERMISSION_PRINT_TOPMOST (1<<4) /* print at top-most side of the screen */ 492 /* without either of the above two, prints centered on the whole screen */ 493 #define INTERMISSION_PRINT_WHITE (1<<5) /* print in white, not in red */ 494 #define INTERMISSION_PRINT_DELAY (1<<6) /* delay message print for ca. 2.5s */ 495 496 void CL_SetupIntermission (int n); 497 498 // 499 // cl_parse.c 500 // 501 void CL_ParseServerMessage (void); 502 qboolean CL_CheckOrDownloadFile (const char *filename); 503 504 // 505 // cl_cam.c 506 // 507 void CL_InitCam (void); 508 void Cam_Reset (void); 509 void Cam_Track (usercmd_t *cmd); 510 void Cam_FinishMove (usercmd_t *cmd); 511 512 // 513 // view 514 // 515 void V_StartPitchDrift (void); 516 void V_StopPitchDrift (void); 517 518 void V_RenderView (void); 519 void V_UpdatePalette (void); 520 void V_Register (void); 521 void V_ParseDamage (void); 522 void V_SetContentsColor (int contents); 523 524 void V_ParseTarget(void); 525 526 extern float v_targAngle; 527 extern float v_targPitch; 528 extern float v_targDist; 529 530 // 531 // cl_effect 532 // 533 void CL_InitEffects (void); 534 void CL_ClearEffects (void); 535 void CL_EndEffect (void); 536 void CL_ParseEffect (void); 537 void CL_ParseMultiEffect (void); 538 void CL_UpdateEffects (void); 539 void CL_TurnEffect (void); 540 void CL_ReviseEffect (void); 541 542 // 543 // cl_tent 544 // 545 void CL_InitTEnts (void); 546 void CL_ClearTEnts (void); 547 void CL_ParseTEnt (void); 548 void CL_UpdateTEnts (void); 549 550 void CL_UpdateHammer(entity_t *ent, int edict_num); 551 void CL_UpdateBug(entity_t *ent); 552 void CL_UpdateIceStorm(entity_t *ent, int edict_num); 553 void CL_UpdatePoisonGas(entity_t *ent, int edict_num); 554 void CL_UpdateAcidBlob(entity_t *ent, int edict_num); 555 void CL_UpdateOnFire(entity_t *ent, int edict_num); 556 void CL_UpdatePowerFlameBurn(entity_t *ent, int edict_num); 557 558 // 559 // cl_ents.c 560 // 561 void CL_EmitEntities (void); 562 void CL_SetUpPlayerPrediction (qboolean dopred); 563 void CL_SetSolidPlayers (int playernum); 564 void CL_SetSolidEntities (void); 565 void CL_ClearProjectiles (void); 566 void CL_ClearMissiles (void); 567 void CL_ParseProjectiles (void); 568 void CL_ParsePackMissiles (void); 569 void CL_ParsePacketEntities (qboolean delta); 570 void CL_ParsePlayerinfo (void); 571 void CL_SavePlayer (void); 572 573 // 574 // cl_pred.c 575 // 576 void CL_InitPrediction (void); 577 void CL_PredictMove (void); 578 void CL_PredictUsercmd (player_state_t *from, player_state_t *to, usercmd_t *u, qboolean spectate); 579 580 // 581 // skin.c 582 // 583 typedef struct 584 { 585 char manufacturer; 586 char version; 587 char encoding; 588 char bits_per_pixel; 589 unsigned short xmin,ymin,xmax,ymax; 590 unsigned short hres,vres; 591 unsigned char palette[48]; 592 char reserved; 593 char color_planes; 594 unsigned short bytes_per_line; 595 unsigned short palette_type; 596 char filler[58]; 597 unsigned char data; // unbounded 598 } pcx_t; 599 600 void Skin_Find (player_info_t *sc); 601 byte *Skin_Cache (skin_t *skin); 602 void Skin_Skins_f (void); 603 void Skin_AllSkins_f (void); 604 void Skin_NextDownload (void); 605 606 // 607 // globals for Siege: 608 // 609 extern qboolean cl_siege; // whether this is a Siege game 610 extern byte cl_fraglimit; 611 extern float cl_timelimit; 612 extern float cl_server_time_offset; 613 extern unsigned int defLosses; // Defender losses 614 extern unsigned int attLosses; // Attacker losses 615 extern int cl_keyholder; 616 extern int cl_doc; // Defender of Crown (Excalibur) 617 618 #endif /* __H2W_CLIENT_H */ 619 620