2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // cl_parse.c -- parse a message received from the server
24 #include "cl_collision.h"
27 char *svc_strings[128] =
33 "svc_version", // [int] server version
34 "svc_setview", // [short] entity number
35 "svc_sound", // <see code>
36 "svc_time", // [float] server time
37 "svc_print", // [string] null terminated string
38 "svc_stufftext", // [string] stuffed into client's console buffer
39 // the string should be \n terminated
40 "svc_setangle", // [vec3] set the view angle to this absolute value
42 "svc_serverinfo", // [int] version
43 // [string] signon string
44 // [string]..[0]model cache [string]...[0]sounds cache
45 // [string]..[0]item cache
46 "svc_lightstyle", // [byte] [string]
47 "svc_updatename", // [byte] [string]
48 "svc_updatefrags", // [byte] [short]
49 "svc_clientdata", // <shortbits + data>
50 "svc_stopsound", // <see code>
51 "svc_updatecolors", // [byte] [byte]
52 "svc_particle", // [vec3] <variable>
53 "svc_damage", // [byte] impact [byte] blood [vec3] from
56 "OBSOLETE svc_spawnbinary",
59 "svc_temp_entity", // <variable>
65 "svc_spawnstaticsound",
67 "svc_finale", // [string] music [string] text
68 "svc_cdtrack", // [byte] track [byte] looptrack
71 "svc_showlmp", // [string] iconlabel [string] lmpfile [short] x [short] y
72 "svc_hidelmp", // [string] iconlabel
73 "svc_skybox", // [string] skyname
86 "svc_cgame", // 50 // [short] length [bytes] data
87 "svc_updatestatubyte", // 51 // [byte] stat [byte] value
88 "svc_effect", // 52 // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate
89 "svc_effect2", // 53 // [vector] org [short] modelindex [short] startframe [byte] framecount [byte] framerate
90 "svc_sound2", // 54 // short soundindex instead of byte
91 "svc_spawnbaseline2", // 55 // short modelindex instead of byte
92 "svc_spawnstatic2", // 56 // short modelindex instead of byte
93 "svc_entities", // 57 // [int] deltaframe [int] thisframe [float vector] eye [variable length] entitydata
94 "svc_csqcentities", // 58 // [short] entnum [variable length] entitydata ... [short] 0x0000
95 "svc_spawnstaticsound2", // 59 // [coord3] [short] samp [byte] vol [byte] aten
98 char *qw_svc_strings[128] =
102 "qw_svc_disconnect", // 2
103 "qw_svc_updatestat", // 3 // [byte] [byte]
105 "qw_svc_setview", // 5 // [short] entity number
106 "qw_svc_sound", // 6 // <see code>
108 "qw_svc_print", // 8 // [byte] id [string] null terminated string
109 "qw_svc_stufftext", // 9 // [string] stuffed into client's console buffer
110 "qw_svc_setangle", // 10 // [angle3] set the view angle to this absolute value
111 "qw_svc_serverdata", // 11 // [long] protocol ...
112 "qw_svc_lightstyle", // 12 // [byte] [string]
114 "qw_svc_updatefrags", // 14 // [byte] [short]
116 "qw_svc_stopsound", // 16 // <see code>
119 "qw_svc_damage", // 19
120 "qw_svc_spawnstatic", // 20
122 "qw_svc_spawnbaseline", // 22
123 "qw_svc_temp_entity", // 23 // variable
124 "qw_svc_setpause", // 24 // [byte] on / off
126 "qw_svc_centerprint", // 26 // [string] to put in center of the screen
127 "qw_svc_killedmonster", // 27
128 "qw_svc_foundsecret", // 28
129 "qw_svc_spawnstaticsound", // 29 // [coord3] [byte] samp [byte] vol [byte] aten
130 "qw_svc_intermission", // 30 // [vec3_t] origin [vec3_t] angle
131 "qw_svc_finale", // 31 // [string] text
132 "qw_svc_cdtrack", // 32 // [byte] track
133 "qw_svc_sellscreen", // 33
134 "qw_svc_smallkick", // 34 // set client punchangle to 2
135 "qw_svc_bigkick", // 35 // set client punchangle to 4
136 "qw_svc_updateping", // 36 // [byte] [short]
137 "qw_svc_updateentertime", // 37 // [byte] [float]
138 "qw_svc_updatestatlong", // 38 // [byte] [long]
139 "qw_svc_muzzleflash", // 39 // [short] entity
140 "qw_svc_updateuserinfo", // 40 // [byte] slot [long] uid
141 "qw_svc_download", // 41 // [short] size [size bytes]
142 "qw_svc_playerinfo", // 42 // variable
143 "qw_svc_nails", // 43 // [byte] num [48 bits] xyzpy 12 12 12 4 8
144 "qw_svc_chokecount", // 44 // [byte] packets choked
145 "qw_svc_modellist", // 45 // [strings]
146 "qw_svc_soundlist", // 46 // [strings]
147 "qw_svc_packetentities", // 47 // [...]
148 "qw_svc_deltapacketentities", // 48 // [...]
149 "qw_svc_maxspeed", // 49 // maxspeed change, for prediction
150 "qw_svc_entgravity", // 50 // gravity change, for prediction
151 "qw_svc_setinfo", // 51 // setinfo on a client
152 "qw_svc_serverinfo", // 52 // serverinfo
153 "qw_svc_updatepl", // 53 // [byte] [byte]
156 //=============================================================================
158 cvar_t demo_nehahra = {0, "demo_nehahra", "0", "reads all quake demos as nehahra movie protocol"};
159 cvar_t developer_networkentities = {0, "developer_networkentities", "0", "prints received entities, value is 0-4 (higher for more info)"};
163 CL_ParseStartSoundPacket
166 void CL_ParseStartSoundPacket(int largesoundindex)
175 field_mask = MSG_ReadByte();
177 if (field_mask & SND_VOLUME)
178 volume = MSG_ReadByte ();
180 volume = DEFAULT_SOUND_PACKET_VOLUME;
182 if (field_mask & SND_ATTENUATION)
183 attenuation = MSG_ReadByte () / 64.0;
185 attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
187 if (field_mask & SND_LARGEENTITY)
189 ent = (unsigned short) MSG_ReadShort ();
190 channel = MSG_ReadByte ();
194 channel = (unsigned short) MSG_ReadShort ();
199 if (largesoundindex || field_mask & SND_LARGESOUND)
200 sound_num = (unsigned short) MSG_ReadShort ();
202 sound_num = MSG_ReadByte ();
204 MSG_ReadVector(pos, cls.protocol);
206 if (sound_num >= MAX_SOUNDS)
208 Con_Printf("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
212 if (ent >= MAX_EDICTS)
214 Con_Printf("CL_ParseStartSoundPacket: ent = %i", ent);
218 S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation);
225 When the client is taking a long time to load stuff, send keepalive messages
226 so the server doesn't disconnect.
230 static unsigned char olddata[NET_MAXMESSAGE];
231 void CL_KeepaliveMessage (void)
234 static double nextmsg = -1;
239 // no need if server is local and definitely not if this is a demo
240 if (sv.active || !cls.netcon || cls.protocol == PROTOCOL_QUAKEWORLD)
243 // read messages from server, should just be nops
244 oldreadcount = msg_readcount;
245 oldbadread = msg_badread;
247 memcpy(olddata, net_message.data, net_message.cursize);
249 NetConn_ClientFrame();
251 msg_readcount = oldreadcount;
252 msg_badread = oldbadread;
254 memcpy(net_message.data, olddata, net_message.cursize);
256 if (cls.netcon && (time = Sys_DoubleTime()) >= nextmsg)
259 unsigned char buf[4];
262 // LordHavoc: must use unreliable because reliable could kill the sigon message!
263 Con_Print("--> client to server keepalive\n");
264 memset(&msg, 0, sizeof(msg));
266 msg.maxsize = sizeof(buf);
267 MSG_WriteChar(&msg, svc_nop);
268 NetConn_SendUnreliableMessage(cls.netcon, &msg, cls.protocol);
272 void CL_ParseEntityLump(char *entdata)
275 char key[128], value[MAX_INPUTLINE];
276 FOG_clear(); // LordHavoc: no fog until set
277 // LordHavoc: default to the map's sky (q3 shader parsing sets this)
278 R_SetSkyBox(cl.worldmodel->brush.skybox);
282 if (!COM_ParseToken(&data, false))
284 if (com_token[0] != '{')
288 if (!COM_ParseToken(&data, false))
290 if (com_token[0] == '}')
291 break; // end of worldspawn
292 if (com_token[0] == '_')
293 strlcpy (key, com_token + 1, sizeof (key));
295 strlcpy (key, com_token, sizeof (key));
296 while (key[strlen(key)-1] == ' ') // remove trailing spaces
297 key[strlen(key)-1] = 0;
298 if (!COM_ParseToken(&data, false))
300 strlcpy (value, com_token, sizeof (value));
301 if (!strcmp("sky", key))
303 else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
305 else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
307 else if (!strcmp("fog", key))
308 sscanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue);
309 else if (!strcmp("fog_density", key))
310 fog_density = atof(value);
311 else if (!strcmp("fog_red", key))
312 fog_red = atof(value);
313 else if (!strcmp("fog_green", key))
314 fog_green = atof(value);
315 else if (!strcmp("fog_blue", key))
316 fog_blue = atof(value);
321 =====================
324 An svc_signonnum has been received, perform a client side setup
325 =====================
327 static void CL_SignonReply (void)
329 Con_DPrintf("CL_SignonReply: %i\n", cls.signon);
336 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
337 MSG_WriteString (&cls.netcon->message, "prespawn");
344 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
345 MSG_WriteString (&cls.netcon->message, va("name \"%s\"", cl_name.string));
347 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
348 MSG_WriteString (&cls.netcon->message, va("color %i %i", cl_color.integer >> 4, cl_color.integer & 15));
350 if (cl_pmodel.integer)
352 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
353 MSG_WriteString (&cls.netcon->message, va("pmodel %i", cl_pmodel.integer));
355 if (*cl_playermodel.string)
357 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
358 MSG_WriteString (&cls.netcon->message, va("playermodel %s", cl_playermodel.string));
360 if (*cl_playerskin.string)
362 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
363 MSG_WriteString (&cls.netcon->message, va("playerskin %s", cl_playerskin.string));
366 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
367 MSG_WriteString (&cls.netcon->message, va("rate %i", cl_rate.integer));
369 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
370 MSG_WriteString (&cls.netcon->message, "spawn");
377 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
378 MSG_WriteString (&cls.netcon->message, "begin");
393 void CL_ParseServerInfo (void)
397 protocolversion_t protocol;
398 int nummodels, numsounds;
401 Con_DPrint("Serverinfo packet received.\n");
403 // check memory integrity
404 Mem_CheckSentinelsGlobal();
407 // wipe the client_state_t struct
411 // parse protocol version number
413 protocol = Protocol_EnumForNumber(i);
414 if (protocol == PROTOCOL_UNKNOWN)
416 Host_Error("CL_ParseServerInfo: Server is unrecognized protocol number (%i)", i);
419 // hack for unmarked Nehahra movie demos which had a custom protocol
420 if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
421 protocol = PROTOCOL_NEHAHRAMOVIE;
422 cls.protocol = protocol;
423 Con_DPrintf("Server protocol is %s\n", Protocol_NameForEnum(cls.protocol));
426 cl.maxclients = MSG_ReadByte ();
427 if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
429 Host_Error("Bad maxclients (%u) from server", cl.maxclients);
432 cl.scores = (scoreboard_t *)Mem_Alloc(cl_mempool, cl.maxclients*sizeof(*cl.scores));
435 cl.gametype = MSG_ReadByte ();
437 // parse signon message
438 str = MSG_ReadString ();
439 strlcpy (cl.levelname, str, sizeof(cl.levelname));
441 // seperate the printfs so the server message can have a color
442 if (cls.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
443 Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n\2%s\n", str);
445 // check memory integrity
446 Mem_CheckSentinelsGlobal();
449 // if server is active, we already began a loading plaque
451 SCR_BeginLoadingPlaque();
453 // disable until we get textures for it
456 memset(cl.csqc_model_precache, 0, sizeof(cl.csqc_model_precache)); //[515]: csqc
457 memset(cl.model_precache, 0, sizeof(cl.model_precache));
458 memset(cl.sound_precache, 0, sizeof(cl.sound_precache));
460 // parse model precache list
461 for (nummodels=1 ; ; nummodels++)
463 str = MSG_ReadString();
466 if (nummodels==MAX_MODELS)
467 Host_Error ("Server sent too many model precaches");
468 if (strlen(str) >= MAX_QPATH)
469 Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
470 strlcpy (cl.model_name[nummodels], str, sizeof (cl.model_name[nummodels]));
472 // parse sound precache list
473 for (numsounds=1 ; ; numsounds++)
475 str = MSG_ReadString();
478 if (numsounds==MAX_SOUNDS)
479 Host_Error("Server sent too many sound precaches");
480 if (strlen(str) >= MAX_QPATH)
481 Host_Error("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
482 strlcpy (cl.sound_name[numsounds], str, sizeof (cl.sound_name[numsounds]));
485 // touch all of the precached models that are still loaded so we can free
486 // anything that isn't needed
488 for (i = 1;i < nummodels;i++)
489 Mod_FindName(cl.model_name[i]);
490 // precache any models used by the client (this also marks them used)
491 cl.model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
492 cl.model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
493 cl.model_bolt3 = Mod_ForName("progs/bolt3.mdl", false, false, false);
494 cl.model_beam = Mod_ForName("progs/beam.mdl", false, false, false);
497 // do the same for sounds
498 // FIXME: S_ServerSounds does not know about cl.sfx_ sounds
499 S_ServerSounds (cl.sound_name, numsounds);
501 // precache any sounds used by the client
502 cl.sfx_wizhit = S_PrecacheSound("sound/wizard/hit.wav", false, true);
503 cl.sfx_knighthit = S_PrecacheSound("sound/hknight/hit.wav", false, true);
504 cl.sfx_tink1 = S_PrecacheSound("sound/weapons/tink1.wav", false, true);
505 cl.sfx_ric1 = S_PrecacheSound("sound/weapons/ric1.wav", false, true);
506 cl.sfx_ric2 = S_PrecacheSound("sound/weapons/ric2.wav", false, true);
507 cl.sfx_ric3 = S_PrecacheSound("sound/weapons/ric3.wav", false, true);
508 cl.sfx_r_exp3 = S_PrecacheSound("sound/weapons/r_exp3.wav", false, true);
510 // now we try to load everything that is new
513 CL_KeepaliveMessage ();
514 cl.model_precache[1] = Mod_ForName(cl.model_name[1], false, false, true);
515 if (cl.model_precache[1]->Draw == NULL)
516 Con_Printf("Map %s not found\n", cl.model_name[1]);
519 for (i=2 ; i<nummodels ; i++)
521 CL_KeepaliveMessage();
522 if ((cl.model_precache[i] = Mod_ForName(cl.model_name[i], false, false, false))->Draw == NULL)
523 Con_Printf("Model %s not found\n", cl.model_name[i]);
527 for (i=1 ; i<numsounds ; i++)
529 CL_KeepaliveMessage();
531 // Don't lock the sfx here, S_ServerSounds already did that
532 cl.sound_precache[i] = S_PrecacheSound (cl.sound_name[i], true, false);
536 ent = &cl_entities[0];
537 // entire entity array was cleared, so just fill in a few fields
538 ent->state_current.active = true;
539 ent->render.model = cl.worldmodel = cl.model_precache[1];
540 ent->render.scale = 1; // some of the renderer still relies on scale
541 ent->render.alpha = 1;
542 ent->render.colormap = -1; // no special coloring
543 ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
544 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
545 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
546 CL_BoundingBoxForEntity(&ent->render);
553 // noclip is turned off at start
554 noclip_anglehack = false;
556 // check memory integrity
557 Mem_CheckSentinelsGlobal();
560 void CL_ValidateState(entity_state_t *s)
567 if (s->modelindex >= MAX_MODELS && (65536-s->modelindex) >= MAX_MODELS)
568 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
570 // colormap is client index + 1
571 if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
573 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
577 model = cl.model_precache[s->modelindex];
578 if (model && model->type && s->frame >= model->numframes)
580 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
583 if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
585 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
590 void CL_MoveLerpEntityStates(entity_t *ent)
592 float odelta[3], adelta[3];
593 CL_ValidateState(&ent->state_current);
594 VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
595 VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
596 if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
598 // reset all persistent stuff if this is a new entity
599 ent->persistent.lerpdeltatime = 0;
600 ent->persistent.lerpstarttime = cl.mtime[1];
601 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
602 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
603 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
604 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
605 // reset animation interpolation as well
606 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
607 ent->render.frame1time = ent->render.frame2time = cl.time;
608 ent->render.framelerp = 1;
609 // reset various persistent stuff
610 ent->persistent.muzzleflash = 0;
611 VectorCopy(ent->state_current.origin, ent->persistent.trail_origin);
613 else if (cls.timedemo || cl_nolerp.integer || DotProduct(odelta, odelta) > 1000*1000)
615 // don't interpolate the move
616 ent->persistent.lerpdeltatime = 0;
617 ent->persistent.lerpstarttime = cl.mtime[1];
618 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
619 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
620 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
621 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
623 else if (ent->state_current.flags & RENDER_STEP)
625 // monster interpolation
626 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
628 ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
629 ent->persistent.lerpstarttime = cl.mtime[1];
630 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
631 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
632 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
633 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
639 ent->persistent.lerpstarttime = ent->state_previous.time;
640 // no lerp if it's singleplayer
641 if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
642 ent->persistent.lerpdeltatime = 0;
644 ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
645 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
646 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
647 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
648 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
657 void CL_ParseBaseline (entity_t *ent, int large)
661 ent->state_baseline = defaultstate;
662 // FIXME: set ent->state_baseline.number?
663 ent->state_baseline.active = true;
666 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
667 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
671 ent->state_baseline.modelindex = MSG_ReadByte ();
672 ent->state_baseline.frame = MSG_ReadByte ();
674 ent->state_baseline.colormap = MSG_ReadByte();
675 ent->state_baseline.skin = MSG_ReadByte();
676 for (i = 0;i < 3;i++)
678 ent->state_baseline.origin[i] = MSG_ReadCoord(cls.protocol);
679 ent->state_baseline.angles[i] = MSG_ReadAngle(cls.protocol);
681 CL_ValidateState(&ent->state_baseline);
682 ent->state_previous = ent->state_current = ent->state_baseline;
690 Server information pertaining to this client only
693 void CL_ParseClientdata (void)
697 VectorCopy (cl.mpunchangle[0], cl.mpunchangle[1]);
698 VectorCopy (cl.mpunchvector[0], cl.mpunchvector[1]);
699 VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
700 cl.mviewzoom[1] = cl.mviewzoom[0];
702 if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4 || cls.protocol == PROTOCOL_DARKPLACES5)
704 cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
705 cl.stats[STAT_ITEMS] = 0;
706 cl.stats[STAT_VIEWZOOM] = 255;
709 cl.mpunchangle[0][0] = 0;
710 cl.mpunchangle[0][1] = 0;
711 cl.mpunchangle[0][2] = 0;
712 cl.mpunchvector[0][0] = 0;
713 cl.mpunchvector[0][1] = 0;
714 cl.mpunchvector[0][2] = 0;
715 cl.mvelocity[0][0] = 0;
716 cl.mvelocity[0][1] = 0;
717 cl.mvelocity[0][2] = 0;
720 bits = (unsigned short) MSG_ReadShort ();
721 if (bits & SU_EXTEND1)
722 bits |= (MSG_ReadByte() << 16);
723 if (bits & SU_EXTEND2)
724 bits |= (MSG_ReadByte() << 24);
726 if (bits & SU_VIEWHEIGHT)
727 cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
729 if (bits & SU_IDEALPITCH)
730 cl.idealpitch = MSG_ReadChar ();
732 for (i = 0;i < 3;i++)
734 if (bits & (SU_PUNCH1<<i) )
736 if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE)
737 cl.mpunchangle[0][i] = MSG_ReadChar();
739 cl.mpunchangle[0][i] = MSG_ReadAngle16i();
741 if (bits & (SU_PUNCHVEC1<<i))
743 if (cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
744 cl.mpunchvector[0][i] = MSG_ReadCoord16i();
746 cl.mpunchvector[0][i] = MSG_ReadCoord32f();
748 if (bits & (SU_VELOCITY1<<i) )
750 if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
751 cl.mvelocity[0][i] = MSG_ReadChar()*16;
753 cl.mvelocity[0][i] = MSG_ReadCoord32f();
757 // LordHavoc: hipnotic demos don't have this bit set but should
758 if (bits & SU_ITEMS || cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4 || cls.protocol == PROTOCOL_DARKPLACES5)
759 cl.stats[STAT_ITEMS] = MSG_ReadLong ();
761 cl.onground = (bits & SU_ONGROUND) != 0;
762 csqc_onground = cl.onground; //[515]: cause without this csqc will receive not right value on svc_print =/
763 cl.inwater = (bits & SU_INWATER) != 0;
765 if (cls.protocol == PROTOCOL_DARKPLACES5)
767 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
768 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
769 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
770 cl.stats[STAT_HEALTH] = MSG_ReadShort();
771 cl.stats[STAT_AMMO] = MSG_ReadShort();
772 cl.stats[STAT_SHELLS] = MSG_ReadShort();
773 cl.stats[STAT_NAILS] = MSG_ReadShort();
774 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
775 cl.stats[STAT_CELLS] = MSG_ReadShort();
776 cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
778 else if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
780 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
781 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
782 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
783 cl.stats[STAT_HEALTH] = MSG_ReadShort();
784 cl.stats[STAT_AMMO] = MSG_ReadByte();
785 cl.stats[STAT_SHELLS] = MSG_ReadByte();
786 cl.stats[STAT_NAILS] = MSG_ReadByte();
787 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
788 cl.stats[STAT_CELLS] = MSG_ReadByte();
789 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
790 cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
792 cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
795 if (bits & SU_VIEWZOOM)
797 if (cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
798 cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
800 cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
803 // check for important changes
806 if (cl.olditems != cl.stats[STAT_ITEMS])
807 for (j = 0;j < 32;j++)
808 if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
809 cl.item_gettime[j] = cl.time;
810 cl.olditems = cl.stats[STAT_ITEMS];
812 // GAME_NEXUIZ hud needs weapon change time
813 if (cl.activeweapon != cl.stats[STAT_ACTIVEWEAPON])
814 cl.weapontime = cl.time;
815 cl.activeweapon = cl.stats[STAT_ACTIVEWEAPON];
817 // viewzoom interpolation
818 cl.mviewzoom[0] = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
822 =====================
824 =====================
826 void CL_ParseStatic (int large)
830 if (cl_num_static_entities >= cl_max_static_entities)
831 Host_Error ("Too many static entities");
832 ent = &cl_static_entities[cl_num_static_entities++];
833 CL_ParseBaseline (ent, large);
835 // copy it to the current state
836 ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
837 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
838 ent->render.framelerp = 0;
839 // make torchs play out of sync
840 ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
841 ent->render.colormap = -1; // no special coloring
842 ent->render.skinnum = ent->state_baseline.skin;
843 ent->render.effects = ent->state_baseline.effects;
844 ent->render.alpha = 1;
845 //ent->render.scale = 1;
847 //VectorCopy (ent->state_baseline.origin, ent->render.origin);
848 //VectorCopy (ent->state_baseline.angles, ent->render.angles);
850 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, ent->state_baseline.origin[0], ent->state_baseline.origin[1], ent->state_baseline.origin[2], ent->state_baseline.angles[0], ent->state_baseline.angles[1], ent->state_baseline.angles[2], 1);
851 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
852 CL_BoundingBoxForEntity(&ent->render);
854 // This is definitely cheating...
855 if (ent->render.model == NULL)
856 cl_num_static_entities--;
864 void CL_ParseStaticSound (int large)
867 int sound_num, vol, atten;
869 MSG_ReadVector(org, cls.protocol);
871 sound_num = (unsigned short) MSG_ReadShort ();
873 sound_num = MSG_ReadByte ();
874 vol = MSG_ReadByte ();
875 atten = MSG_ReadByte ();
877 S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
880 void CL_ParseEffect (void)
883 int modelindex, startframe, framecount, framerate;
885 MSG_ReadVector(org, cls.protocol);
886 modelindex = MSG_ReadByte ();
887 startframe = MSG_ReadByte ();
888 framecount = MSG_ReadByte ();
889 framerate = MSG_ReadByte ();
891 CL_Effect(org, modelindex, startframe, framecount, framerate);
894 void CL_ParseEffect2 (void)
897 int modelindex, startframe, framecount, framerate;
899 MSG_ReadVector(org, cls.protocol);
900 modelindex = (unsigned short) MSG_ReadShort ();
901 startframe = (unsigned short) MSG_ReadShort ();
902 framecount = MSG_ReadByte ();
903 framerate = MSG_ReadByte ();
905 CL_Effect(org, modelindex, startframe, framecount, framerate);
908 void CL_ParseBeam (model_t *m, int lightning)
914 ent = (unsigned short) MSG_ReadShort ();
915 MSG_ReadVector(start, cls.protocol);
916 MSG_ReadVector(end, cls.protocol);
918 if (ent >= MAX_EDICTS)
920 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
924 if (ent >= cl_max_entities)
925 CL_ExpandEntities(ent);
927 // override any beam with the same entity
930 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
931 if (b->entity == ent)
933 // if the entity was not found then just replace an unused beam
934 if (i == cl_max_beams)
935 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
936 if (!b->model || b->endtime < cl.time)
938 if (i < cl_max_beams)
941 b->lightning = lightning;
943 b->endtime = cl.time + 0.2;
944 VectorCopy (start, b->start);
945 VectorCopy (end, b->end);
946 b->relativestartvalid = 0;
947 if (ent && cl_entities[ent].state_current.active)
950 matrix4x4_t matrix, imatrix;
951 if (ent == cl.viewentity && cl.movement)
952 p = &cl_entities[b->entity].state_previous;
954 p = &cl_entities[b->entity].state_current;
955 // not really valid yet, we need to get the orientation now
956 // (ParseBeam flagged this because it is received before
957 // entities are received, by now they have been received)
958 // note: because players create lightning in their think
959 // function (which occurs before movement), they actually
960 // have some lag in it's location, so compare to the
961 // previous player state, not the latest
962 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2], -p->angles[0], p->angles[1], p->angles[2], 1);
963 Matrix4x4_Invert_Simple(&imatrix, &matrix);
964 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
965 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
966 b->relativestartvalid = 1;
970 Con_Print("beam list overflow!\n");
973 void CL_ParseTempEntity(void)
981 int colorStart, colorLength, count;
982 float velspeed, radius;
983 unsigned char *tempcolor;
984 matrix4x4_t tempmatrix;
986 type = MSG_ReadByte();
990 // spike hitting wall
991 MSG_ReadVector(pos, cls.protocol);
992 CL_FindNonSolidLocation(pos, pos, 4);
993 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
994 //CL_AllocDlight(NULL, &tempmatrix, 100, 0.12f, 0.50f, 0.12f, 500, 0.2, 0, -1, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
995 CL_RunParticleEffect(pos, vec3_origin, 20, 30);
996 S_StartSound(-1, 0, cl.sfx_wizhit, pos, 1, 1);
1000 // spike hitting wall
1001 MSG_ReadVector(pos, cls.protocol);
1002 CL_FindNonSolidLocation(pos, pos, 4);
1003 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1004 //CL_AllocDlight(NULL, &tempmatrix, 100, 0.50f, 0.30f, 0.10f, 500, 0.2, 0, -1, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1005 CL_RunParticleEffect(pos, vec3_origin, 226, 20);
1006 S_StartSound(-1, 0, cl.sfx_knighthit, pos, 1, 1);
1010 // spike hitting wall
1011 MSG_ReadVector(pos, cls.protocol);
1012 CL_FindNonSolidLocation(pos, pos, 4);
1013 if (cl_particles_quake.integer)
1014 CL_RunParticleEffect(pos, vec3_origin, 0, 10);
1015 else if (cl_particles_bulletimpacts.integer)
1017 CL_SparkShower(pos, vec3_origin, 15, 1);
1018 CL_Smoke(pos, vec3_origin, 15);
1022 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1027 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1029 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1031 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1035 // quad spike hitting wall
1036 MSG_ReadVector(pos, cls.protocol);
1037 CL_FindNonSolidLocation(pos, pos, 4);
1038 if (cl_particles_quake.integer)
1039 CL_RunParticleEffect(pos, vec3_origin, 0, 10);
1040 else if (cl_particles_bulletimpacts.integer)
1042 CL_SparkShower(pos, vec3_origin, 15, 1);
1043 CL_Smoke(pos, vec3_origin, 15);
1046 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1047 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1049 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1054 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1056 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1058 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1062 // super spike hitting wall
1063 MSG_ReadVector(pos, cls.protocol);
1064 CL_FindNonSolidLocation(pos, pos, 4);
1065 if (cl_particles_quake.integer)
1066 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1067 else if (cl_particles_bulletimpacts.integer)
1069 CL_SparkShower(pos, vec3_origin, 30, 1);
1070 CL_Smoke(pos, vec3_origin, 30);
1074 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1079 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1081 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1083 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1086 case TE_SUPERSPIKEQUAD:
1087 // quad super spike hitting wall
1088 MSG_ReadVector(pos, cls.protocol);
1089 CL_FindNonSolidLocation(pos, pos, 4);
1090 if (cl_particles_quake.integer)
1091 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1092 else if (cl_particles_bulletimpacts.integer)
1094 CL_SparkShower(pos, vec3_origin, 30, 1);
1095 CL_Smoke(pos, vec3_origin, 30);
1098 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1099 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1101 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1106 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1108 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1110 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1113 // LordHavoc: added for improved blood splatters
1116 MSG_ReadVector(pos, cls.protocol);
1117 CL_FindNonSolidLocation(pos, pos, 4);
1118 dir[0] = MSG_ReadChar();
1119 dir[1] = MSG_ReadChar();
1120 dir[2] = MSG_ReadChar();
1121 count = MSG_ReadByte();
1122 CL_BloodPuff(pos, dir, count);
1126 MSG_ReadVector(pos, cls.protocol);
1127 CL_FindNonSolidLocation(pos, pos, 4);
1128 dir[0] = MSG_ReadChar();
1129 dir[1] = MSG_ReadChar();
1130 dir[2] = MSG_ReadChar();
1131 count = MSG_ReadByte();
1132 CL_SparkShower(pos, dir, count, 1);
1135 MSG_ReadVector(pos, cls.protocol);
1136 CL_FindNonSolidLocation(pos, pos, 4);
1137 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1138 CL_AllocDlight(NULL, &tempmatrix, 200, 1, 1, 1, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1141 // LordHavoc: added for improved gore
1142 case TE_BLOODSHOWER:
1144 MSG_ReadVector(pos, cls.protocol); // mins
1145 MSG_ReadVector(pos2, cls.protocol); // maxs
1146 velspeed = MSG_ReadCoord(cls.protocol); // speed
1147 count = (unsigned short) MSG_ReadShort(); // number of particles
1148 CL_BloodShower(pos, pos2, velspeed, count);
1150 case TE_PARTICLECUBE:
1151 // general purpose particle effect
1152 MSG_ReadVector(pos, cls.protocol); // mins
1153 MSG_ReadVector(pos2, cls.protocol); // maxs
1154 MSG_ReadVector(dir, cls.protocol); // dir
1155 count = (unsigned short) MSG_ReadShort(); // number of particles
1156 colorStart = MSG_ReadByte(); // color
1157 colorLength = MSG_ReadByte(); // gravity (1 or 0)
1158 velspeed = MSG_ReadCoord(cls.protocol); // randomvel
1159 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
1162 case TE_PARTICLERAIN:
1163 // general purpose particle effect
1164 MSG_ReadVector(pos, cls.protocol); // mins
1165 MSG_ReadVector(pos2, cls.protocol); // maxs
1166 MSG_ReadVector(dir, cls.protocol); // dir
1167 count = (unsigned short) MSG_ReadShort(); // number of particles
1168 colorStart = MSG_ReadByte(); // color
1169 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
1172 case TE_PARTICLESNOW:
1173 // general purpose particle effect
1174 MSG_ReadVector(pos, cls.protocol); // mins
1175 MSG_ReadVector(pos2, cls.protocol); // maxs
1176 MSG_ReadVector(dir, cls.protocol); // dir
1177 count = (unsigned short) MSG_ReadShort(); // number of particles
1178 colorStart = MSG_ReadByte(); // color
1179 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
1183 // bullet hitting wall
1184 MSG_ReadVector(pos, cls.protocol);
1185 CL_FindNonSolidLocation(pos, pos, 4);
1186 if (cl_particles_quake.integer)
1187 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1190 CL_SparkShower(pos, vec3_origin, 15, 1);
1191 CL_Smoke(pos, vec3_origin, 15);
1196 case TE_GUNSHOTQUAD:
1197 // quad bullet hitting wall
1198 MSG_ReadVector(pos, cls.protocol);
1199 CL_FindNonSolidLocation(pos, pos, 4);
1200 if (cl_particles_quake.integer)
1201 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1204 CL_SparkShower(pos, vec3_origin, 15, 1);
1205 CL_Smoke(pos, vec3_origin, 15);
1208 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1209 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1214 MSG_ReadVector(pos, cls.protocol);
1215 CL_FindNonSolidLocation(pos, pos, 10);
1216 CL_ParticleExplosion(pos);
1217 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
1218 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1219 CL_AllocDlight(NULL, &tempmatrix, 350, 4.0f, 2.0f, 0.50f, 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1220 if (gamemode != GAME_NEXUIZ)
1221 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1224 case TE_EXPLOSIONQUAD:
1225 // quad rocket explosion
1226 MSG_ReadVector(pos, cls.protocol);
1227 CL_FindNonSolidLocation(pos, pos, 10);
1228 CL_ParticleExplosion(pos);
1229 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1230 CL_AllocDlight(NULL, &tempmatrix, 350, 2.5f, 2.0f, 4.0f, 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1231 if (gamemode != GAME_NEXUIZ)
1232 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1236 // Nehahra movie colored lighting explosion
1237 MSG_ReadVector(pos, cls.protocol);
1238 CL_FindNonSolidLocation(pos, pos, 10);
1239 CL_ParticleExplosion(pos);
1240 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1241 color[0] = MSG_ReadCoord(cls.protocol) * (2.0f / 1.0f);
1242 color[1] = MSG_ReadCoord(cls.protocol) * (2.0f / 1.0f);
1243 color[2] = MSG_ReadCoord(cls.protocol) * (2.0f / 1.0f);
1244 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1245 if (gamemode != GAME_NEXUIZ)
1246 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1249 case TE_EXPLOSIONRGB:
1250 // colored lighting explosion
1251 MSG_ReadVector(pos, cls.protocol);
1252 CL_FindNonSolidLocation(pos, pos, 10);
1253 CL_ParticleExplosion(pos);
1254 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1255 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1256 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1257 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1258 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1259 if (gamemode != GAME_NEXUIZ)
1260 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1263 case TE_TAREXPLOSION:
1264 // tarbaby explosion
1265 MSG_ReadVector(pos, cls.protocol);
1266 CL_FindNonSolidLocation(pos, pos, 10);
1267 CL_BlobExplosion(pos);
1269 if (gamemode != GAME_NEXUIZ)
1270 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1271 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1272 CL_AllocDlight(NULL, &tempmatrix, 600, 1.6f, 0.8f, 2.0f, 1200, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1276 MSG_ReadVector(pos, cls.protocol);
1277 CL_FindNonSolidLocation(pos, pos, 10);
1278 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1279 CL_AllocDlight(NULL, &tempmatrix, 200, 2, 2, 2, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1282 case TE_CUSTOMFLASH:
1283 MSG_ReadVector(pos, cls.protocol);
1284 CL_FindNonSolidLocation(pos, pos, 4);
1285 radius = (MSG_ReadByte() + 1) * 8;
1286 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
1287 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1288 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1289 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1290 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1291 CL_AllocDlight(NULL, &tempmatrix, radius, color[0], color[1], color[2], radius / velspeed, velspeed, 0, -1, true, 1, 0.25, 1, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1295 MSG_ReadVector(pos, cls.protocol);
1296 MSG_ReadVector(dir, cls.protocol);
1297 count = MSG_ReadByte();
1298 CL_Flames(pos, dir, count);
1303 CL_ParseBeam(cl.model_bolt, true);
1308 CL_ParseBeam(cl.model_bolt2, true);
1313 CL_ParseBeam(cl.model_bolt3, false);
1318 // grappling hook beam
1319 CL_ParseBeam(cl.model_beam, false);
1323 // LordHavoc: for compatibility with the Nehahra movie...
1324 case TE_LIGHTNING4NEH:
1325 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
1329 MSG_ReadVector(pos, cls.protocol);
1334 MSG_ReadVector(pos, cls.protocol);
1335 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1336 CL_AllocDlight(NULL, &tempmatrix, 200, 1.0f, 1.0f, 1.0f, 600, 99.0f, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1337 CL_TeleportSplash(pos);
1341 // color mapped explosion
1342 MSG_ReadVector(pos, cls.protocol);
1343 CL_FindNonSolidLocation(pos, pos, 10);
1344 colorStart = MSG_ReadByte();
1345 colorLength = MSG_ReadByte();
1346 CL_ParticleExplosion2(pos, colorStart, colorLength);
1347 tempcolor = (unsigned char *)&palette_complete[(rand()%colorLength) + colorStart];
1348 color[0] = tempcolor[0] * (2.0f / 255.0f);
1349 color[1] = tempcolor[1] * (2.0f / 255.0f);
1350 color[2] = tempcolor[2] * (2.0f / 255.0f);
1351 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1352 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1353 if (gamemode != GAME_NEXUIZ)
1354 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1358 MSG_ReadVector(pos, cls.protocol);
1359 MSG_ReadVector(pos2, cls.protocol);
1360 MSG_ReadVector(dir, cls.protocol);
1361 CL_BeamParticle(pos, pos2, 8, 1, 1, 1, 1, 1);
1365 MSG_ReadVector(pos, cls.protocol);
1366 MSG_ReadVector(dir, cls.protocol);
1367 count = MSG_ReadByte();
1368 CL_FindNonSolidLocation(pos, pos, 4);
1369 CL_Tei_Smoke(pos, dir, count);
1372 case TE_TEI_BIGEXPLOSION:
1373 MSG_ReadVector(pos, cls.protocol);
1374 CL_FindNonSolidLocation(pos, pos, 10);
1375 CL_ParticleExplosion(pos);
1376 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1377 CL_AllocDlight(NULL, &tempmatrix, 500, 2.5f, 2.0f, 1.0f, 500, 9999, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1378 if (gamemode != GAME_NEXUIZ)
1379 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1382 case TE_TEI_PLASMAHIT:
1383 MSG_ReadVector(pos, cls.protocol);
1384 MSG_ReadVector(dir, cls.protocol);
1385 count = MSG_ReadByte();
1386 CL_FindNonSolidLocation(pos, pos, 5);
1387 CL_Tei_PlasmaHit(pos, dir, count);
1388 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1389 CL_AllocDlight(NULL, &tempmatrix, 500, 0.6, 1.2, 2.0f, 2000, 9999, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1393 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
1397 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
1400 void CL_VM_Init (void);
1401 qboolean CL_VM_Parse_TempEntity (void);
1402 void CL_VM_Parse_StuffCmd (const char *msg);
1403 void CL_VM_Parse_CenterPrint (const char *msg);
1404 void CSQC_AddPrintText (const char *msg);
1405 void CSQC_ReadEntities (void);
1407 static unsigned char cgamenetbuffer[65536];
1410 =====================
1411 CL_ParseServerMessage
1412 =====================
1414 int parsingerror = false;
1415 void CL_ParseServerMessage(void)
1419 protocolversion_t protocol;
1420 unsigned char cmdlog[32];
1421 char *cmdlogname[32], *temp;
1422 int cmdindex, cmdcount = 0;
1424 if (cls.demorecording)
1425 CL_WriteDemoMessage ();
1427 cl.last_received_message = realtime;
1430 // if recording demos, copy the message out
1432 if (cl_shownet.integer == 1)
1433 Con_Printf("%f %i\n", realtime, net_message.cursize);
1434 else if (cl_shownet.integer == 2)
1435 Con_Print("------------------\n");
1437 cl.onground = false; // unless the server says otherwise
1439 // parse the message
1441 //MSG_BeginReading ();
1443 parsingerror = true;
1448 Host_Error ("CL_ParseServerMessage: Bad server message");
1450 cmd = MSG_ReadByte ();
1454 SHOWNET("END OF MESSAGE");
1455 break; // end of message
1458 cmdindex = cmdcount & 31;
1460 cmdlog[cmdindex] = cmd;
1462 // if the high bit of the command byte is set, it is a fast update
1465 // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
1467 cmdlogname[cmdindex] = temp;
1468 SHOWNET("fast update");
1469 if (cls.signon == SIGNONS - 1)
1471 // first update is the final signon stage
1472 cls.signon = SIGNONS;
1475 EntityFrameQuake_ReadEntity (cmd&127);
1479 SHOWNET(svc_strings[cmd]);
1480 cmdlogname[cmdindex] = svc_strings[cmd];
1481 if (!cmdlogname[cmdindex])
1483 // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
1485 cmdlogname[cmdindex] = temp;
1493 char description[32*64], temp[64];
1495 strcpy (description, "packet dump: ");
1499 count = cmdcount - i;
1503 dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
1504 strlcat (description, temp, sizeof (description));
1509 description[strlen(description)-1] = '\n'; // replace the last space with a newline
1510 Con_Print(description);
1511 Host_Error ("CL_ParseServerMessage: Illegible server message");
1516 if (cls.signon < SIGNONS)
1517 Con_Print("<-- server to client keepalive\n");
1521 cl.mtime[1] = cl.mtime[0];
1522 cl.mtime[0] = MSG_ReadFloat ();
1523 cl.movement_needupdate = true;
1526 case svc_clientdata:
1527 CL_ParseClientdata();
1531 i = MSG_ReadLong ();
1532 protocol = Protocol_EnumForNumber(i);
1533 if (protocol == PROTOCOL_UNKNOWN)
1534 Host_Error("CL_ParseServerMessage: Server is unrecognized protocol number (%i)", i);
1535 // hack for unmarked Nehahra movie demos which had a custom protocol
1536 if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
1537 protocol = PROTOCOL_NEHAHRAMOVIE;
1538 cls.protocol = protocol;
1541 case svc_disconnect:
1542 Con_Printf ("Server disconnected\n");
1543 if (cls.demonum != -1)
1550 CSQC_AddPrintText(MSG_ReadString()); //[515]: csqc
1553 case svc_centerprint:
1554 CL_VM_Parse_CenterPrint(MSG_ReadString ()); //[515]: csqc
1558 CL_VM_Parse_StuffCmd(MSG_ReadString ()); //[515]: csqc
1565 case svc_serverinfo:
1566 CL_ParseServerInfo ();
1567 CL_VM_Init(); //[515]: init csqc
1571 for (i=0 ; i<3 ; i++)
1572 cl.viewangles[i] = MSG_ReadAngle (cls.protocol);
1576 cl.viewentity = (unsigned short)MSG_ReadShort ();
1577 if (cl.viewentity >= MAX_EDICTS)
1578 Host_Error("svc_setview >= MAX_EDICTS");
1579 if (cl.viewentity >= cl_max_entities)
1580 CL_ExpandEntities(cl.viewentity);
1581 // LordHavoc: assume first setview recieved is the real player entity
1582 if (!cl.playerentity)
1583 cl.playerentity = cl.viewentity;
1586 case svc_lightstyle:
1587 i = MSG_ReadByte ();
1588 if (i >= cl_max_lightstyle)
1590 Con_Printf ("svc_lightstyle >= MAX_LIGHTSTYLES");
1593 strlcpy (cl_lightstyle[i].map, MSG_ReadString(), sizeof (cl_lightstyle[i].map));
1594 cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
1595 cl_lightstyle[i].length = (int)strlen(cl_lightstyle[i].map);
1599 CL_ParseStartSoundPacket(false);
1603 if (cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3)
1605 // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
1606 CL_ParseStartSoundPacket(true);
1610 int i = (unsigned short)MSG_ReadShort();
1611 char *s = MSG_ReadString();
1614 if (i >= 1 && i < MAX_MODELS)
1616 model_t *model = Mod_ForName(s, false, false, i == 1);
1618 Con_Printf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
1619 cl.model_precache[i] = model;
1622 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
1627 if (i >= 1 && i < MAX_SOUNDS)
1629 sfx_t *sfx = S_PrecacheSound (s, true, false);
1630 if (!sfx && snd_initialized.integer)
1631 Con_Printf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
1632 cl.sound_precache[i] = sfx;
1635 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
1641 i = (unsigned short) MSG_ReadShort();
1642 S_StopSound(i>>3, i&7);
1645 case svc_updatename:
1646 i = MSG_ReadByte ();
1647 if (i >= cl.maxclients)
1648 Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
1649 strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
1652 case svc_updatefrags:
1653 i = MSG_ReadByte ();
1654 if (i >= cl.maxclients)
1655 Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
1656 cl.scores[i].frags = (signed short) MSG_ReadShort ();
1659 case svc_updatecolors:
1660 i = MSG_ReadByte ();
1661 if (i >= cl.maxclients)
1662 Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
1663 cl.scores[i].colors = MSG_ReadByte ();
1667 CL_ParseParticleEffect ();
1678 case svc_spawnbaseline:
1679 i = (unsigned short) MSG_ReadShort ();
1680 if (i < 0 || i >= MAX_EDICTS)
1681 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
1682 if (i >= cl_max_entities)
1683 CL_ExpandEntities(i);
1684 CL_ParseBaseline (cl_entities + i, false);
1686 case svc_spawnbaseline2:
1687 i = (unsigned short) MSG_ReadShort ();
1688 if (i < 0 || i >= MAX_EDICTS)
1689 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
1690 if (i >= cl_max_entities)
1691 CL_ExpandEntities(i);
1692 CL_ParseBaseline (cl_entities + i, true);
1694 case svc_spawnstatic:
1695 CL_ParseStatic (false);
1697 case svc_spawnstatic2:
1698 CL_ParseStatic (true);
1700 case svc_temp_entity:
1701 if(!CL_VM_Parse_TempEntity())
1702 CL_ParseTempEntity ();
1706 cl.paused = MSG_ReadByte ();
1711 S_PauseGameSounds (cl.paused);
1715 i = MSG_ReadByte ();
1716 // LordHavoc: it's rude to kick off the client if they missed the
1717 // reconnect somehow, so allow signon 1 even if at signon 1
1718 if (i <= cls.signon && i != 1)
1719 Host_Error ("Received signon %i when at %i", i, cls.signon);
1724 case svc_killedmonster:
1725 cl.stats[STAT_MONSTERS]++;
1728 case svc_foundsecret:
1729 cl.stats[STAT_SECRETS]++;
1732 case svc_updatestat:
1733 i = MSG_ReadByte ();
1734 if (i < 0 || i >= MAX_CL_STATS)
1735 Host_Error ("svc_updatestat: %i is invalid", i);
1736 cl.stats[i] = MSG_ReadLong ();
1739 case svc_updatestatubyte:
1740 i = MSG_ReadByte ();
1741 if (i < 0 || i >= MAX_CL_STATS)
1742 Host_Error ("svc_updatestat: %i is invalid", i);
1743 cl.stats[i] = MSG_ReadByte ();
1746 case svc_spawnstaticsound:
1747 CL_ParseStaticSound (false);
1750 case svc_spawnstaticsound2:
1751 CL_ParseStaticSound (true);
1755 cl.cdtrack = MSG_ReadByte ();
1756 cl.looptrack = MSG_ReadByte ();
1757 if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
1758 CDAudio_Play ((unsigned char)cls.forcetrack, true);
1760 CDAudio_Play ((unsigned char)cl.cdtrack, true);
1763 case svc_intermission:
1764 cl.intermission = 1;
1765 cl.completed_time = cl.time;
1769 cl.intermission = 2;
1770 cl.completed_time = cl.time;
1771 SCR_CenterPrint(MSG_ReadString ());
1775 cl.intermission = 3;
1776 cl.completed_time = cl.time;
1777 SCR_CenterPrint(MSG_ReadString ());
1780 case svc_sellscreen:
1781 Cmd_ExecuteString ("help", src_command);
1784 if (gamemode == GAME_TENEBRAE)
1786 // repeating particle effect
1787 MSG_ReadCoord(cls.protocol);
1788 MSG_ReadCoord(cls.protocol);
1789 MSG_ReadCoord(cls.protocol);
1790 MSG_ReadCoord(cls.protocol);
1791 MSG_ReadCoord(cls.protocol);
1792 MSG_ReadCoord(cls.protocol);
1799 SHOWLMP_decodehide();
1802 if (gamemode == GAME_TENEBRAE)
1805 MSG_ReadCoord(cls.protocol);
1806 MSG_ReadCoord(cls.protocol);
1807 MSG_ReadCoord(cls.protocol);
1812 SHOWLMP_decodeshow();
1815 R_SetSkyBox(MSG_ReadString());
1820 length = (int) ((unsigned short) MSG_ReadShort());
1821 for (i = 0;i < length;i++)
1822 cgamenetbuffer[i] = MSG_ReadByte();
1824 CL_CGVM_ParseNetwork(cgamenetbuffer, length);
1828 if (cls.signon == SIGNONS - 1)
1830 // first update is the final signon stage
1831 cls.signon = SIGNONS;
1834 if (cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3)
1835 EntityFrame_CL_ReadFrame();
1836 else if (cls.protocol == PROTOCOL_DARKPLACES4)
1837 EntityFrame4_CL_ReadFrame();
1839 EntityFrame5_CL_ReadFrame();
1841 case svc_csqcentities:
1842 CSQC_ReadEntities();
1847 EntityFrameQuake_ISeeDeadEntities();
1849 parsingerror = false;
1852 void CL_Parse_DumpPacket(void)
1856 Con_Print("Packet dump:\n");
1857 SZ_HexDumpToConsole(&net_message);
1858 parsingerror = false;
1861 void CL_Parse_Init(void)
1863 // LordHavoc: added demo_nehahra cvar
1864 Cvar_RegisterVariable (&demo_nehahra);
1865 if (gamemode == GAME_NEHAHRA)
1866 Cvar_SetValue("demo_nehahra", 1);
1867 Cvar_RegisterVariable(&developer_networkentities);
1870 void CL_Parse_Shutdown(void)