implemented cl_particles_quake cvar to use quake-style particle effects
[divverent/darkplaces.git] / cl_parse.c
1 /*
2 Copyright (C) 1996-1997 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 // cl_parse.c  -- parse a message received from the server
21
22 #include "quakedef.h"
23 #include "cdaudio.h"
24 #include "cl_collision.h"
25
26 char *svc_strings[128] =
27 {
28         "svc_bad",
29         "svc_nop",
30         "svc_disconnect",
31         "svc_updatestat",
32         "svc_version",          // [int] server version
33         "svc_setview",          // [short] entity number
34         "svc_sound",                    // <see code>
35         "svc_time",                     // [float] server time
36         "svc_print",                    // [string] null terminated string
37         "svc_stufftext",                // [string] stuffed into client's console buffer
38                                                 // the string should be \n terminated
39         "svc_setangle",         // [vec3] set the view angle to this absolute value
40
41         "svc_serverinfo",               // [int] version
42                                                 // [string] signon string
43                                                 // [string]..[0]model cache [string]...[0]sounds cache
44                                                 // [string]..[0]item cache
45         "svc_lightstyle",               // [byte] [string]
46         "svc_updatename",               // [byte] [string]
47         "svc_updatefrags",      // [byte] [short]
48         "svc_clientdata",               // <shortbits + data>
49         "svc_stopsound",                // <see code>
50         "svc_updatecolors",     // [byte] [byte]
51         "svc_particle",         // [vec3] <variable>
52         "svc_damage",                   // [byte] impact [byte] blood [vec3] from
53
54         "svc_spawnstatic",
55         "OBSOLETE svc_spawnbinary",
56         "svc_spawnbaseline",
57
58         "svc_temp_entity",              // <variable>
59         "svc_setpause",
60         "svc_signonnum",
61         "svc_centerprint",
62         "svc_killedmonster",
63         "svc_foundsecret",
64         "svc_spawnstaticsound",
65         "svc_intermission",
66         "svc_finale",                   // [string] music [string] text
67         "svc_cdtrack",                  // [byte] track [byte] looptrack
68         "svc_sellscreen",
69         "svc_cutscene",
70         "svc_showlmp",  // [string] iconlabel [string] lmpfile [short] x [short] y
71         "svc_hidelmp",  // [string] iconlabel
72         "svc_skybox", // [string] skyname
73         "", // 38
74         "", // 39
75         "", // 40
76         "", // 41
77         "", // 42
78         "", // 43
79         "", // 44
80         "", // 45
81         "", // 46
82         "", // 47
83         "", // 48
84         "", // 49
85         "svc_cgame", //                         50              // [short] length [bytes] data
86         "svc_updatestatubyte", //                       51              // [byte] stat [byte] value
87         "svc_effect", //                        52              // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate
88         "svc_effect2", //                       53              // [vector] org [short] modelindex [short] startframe [byte] framecount [byte] framerate
89         "svc_sound2", //                        54              // short soundindex instead of byte
90         "svc_spawnbaseline2", //        55              // short modelindex instead of byte
91         "svc_spawnstatic2", //          56              // short modelindex instead of byte
92         "svc_entities", //                      57              // [int] deltaframe [int] thisframe [float vector] eye [variable length] entitydata
93         "svc_unusedlh3", //                     58
94         "svc_spawnstaticsound2", //     59              // [coord3] [short] samp [byte] vol [byte] aten
95 };
96
97 //=============================================================================
98
99 cvar_t demo_nehahra = {0, "demo_nehahra", "0"};
100 cvar_t developer_networkentities = {0, "developer_networkentities", "0"};
101
102 /*
103 ==================
104 CL_ParseStartSoundPacket
105 ==================
106 */
107 void CL_ParseStartSoundPacket(int largesoundindex)
108 {
109         vec3_t  pos;
110         int     channel, ent;
111         int     sound_num;
112         int     volume;
113         int     field_mask;
114         float   attenuation;
115
116         field_mask = MSG_ReadByte();
117
118         if (field_mask & SND_VOLUME)
119                 volume = MSG_ReadByte ();
120         else
121                 volume = DEFAULT_SOUND_PACKET_VOLUME;
122
123         if (field_mask & SND_ATTENUATION)
124                 attenuation = MSG_ReadByte () / 64.0;
125         else
126                 attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
127
128         if (field_mask & SND_LARGEENTITY)
129         {
130                 ent = (unsigned short) MSG_ReadShort ();
131                 channel = MSG_ReadByte ();
132         }
133         else
134         {
135                 channel = (unsigned short) MSG_ReadShort ();
136                 ent = channel >> 3;
137                 channel &= 7;
138         }
139
140         if (largesoundindex || field_mask & SND_LARGESOUND)
141                 sound_num = (unsigned short) MSG_ReadShort ();
142         else
143                 sound_num = MSG_ReadByte ();
144
145         MSG_ReadVector(pos, cl.protocol);
146
147         if (sound_num >= MAX_SOUNDS)
148         {
149                 Con_Printf("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
150                 return;
151         }
152
153         if (ent >= MAX_EDICTS)
154         {
155                 Con_Printf("CL_ParseStartSoundPacket: ent = %i", ent);
156                 return;
157         }
158
159         S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation);
160 }
161
162 /*
163 ==================
164 CL_KeepaliveMessage
165
166 When the client is taking a long time to load stuff, send keepalive messages
167 so the server doesn't disconnect.
168 ==================
169 */
170
171 static unsigned char olddata[NET_MAXMESSAGE];
172 void CL_KeepaliveMessage (void)
173 {
174         float time;
175         static float lastmsg;
176         int oldreadcount;
177         qboolean oldbadread;
178         sizebuf_t old;
179
180         // no need if server is local and definitely not if this is a demo
181         if (sv.active || cls.demoplayback)
182                 return;
183
184 // read messages from server, should just be nops
185         oldreadcount = msg_readcount;
186         oldbadread = msg_badread;
187         old = net_message;
188         memcpy(olddata, net_message.data, net_message.cursize);
189
190         NetConn_ClientFrame();
191
192         msg_readcount = oldreadcount;
193         msg_badread = oldbadread;
194         net_message = old;
195         memcpy(net_message.data, olddata, net_message.cursize);
196
197         if (cls.netcon && NetConn_CanSendMessage(cls.netcon) && (time = Sys_DoubleTime()) - lastmsg >= 5)
198         {
199                 sizebuf_t       msg;
200                 unsigned char           buf[4];
201                 lastmsg = time;
202                 // write out a nop
203                 // LordHavoc: must use unreliable because reliable could kill the sigon message!
204                 Con_Print("--> client to server keepalive\n");
205                 msg.data = buf;
206                 msg.maxsize = sizeof(buf);
207                 msg.cursize = 0;
208                 MSG_WriteChar(&msg, svc_nop);
209                 NetConn_SendUnreliableMessage(cls.netcon, &msg);
210         }
211 }
212
213 void CL_ParseEntityLump(char *entdata)
214 {
215         const char *data;
216         char key[128], value[MAX_INPUTLINE];
217         FOG_clear(); // LordHavoc: no fog until set
218         // LordHavoc: default to the map's sky (q3 shader parsing sets this)
219         R_SetSkyBox(cl.worldmodel->brush.skybox);
220         data = entdata;
221         if (!data)
222                 return;
223         if (!COM_ParseToken(&data, false))
224                 return; // error
225         if (com_token[0] != '{')
226                 return; // error
227         while (1)
228         {
229                 if (!COM_ParseToken(&data, false))
230                         return; // error
231                 if (com_token[0] == '}')
232                         break; // end of worldspawn
233                 if (com_token[0] == '_')
234                         strlcpy (key, com_token + 1, sizeof (key));
235                 else
236                         strlcpy (key, com_token, sizeof (key));
237                 while (key[strlen(key)-1] == ' ') // remove trailing spaces
238                         key[strlen(key)-1] = 0;
239                 if (!COM_ParseToken(&data, false))
240                         return; // error
241                 strlcpy (value, com_token, sizeof (value));
242                 if (!strcmp("sky", key))
243                         R_SetSkyBox(value);
244                 else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
245                         R_SetSkyBox(value);
246                 else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
247                         R_SetSkyBox(value);
248                 else if (!strcmp("fog", key))
249                         sscanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue);
250                 else if (!strcmp("fog_density", key))
251                         fog_density = atof(value);
252                 else if (!strcmp("fog_red", key))
253                         fog_red = atof(value);
254                 else if (!strcmp("fog_green", key))
255                         fog_green = atof(value);
256                 else if (!strcmp("fog_blue", key))
257                         fog_blue = atof(value);
258         }
259 }
260
261 /*
262 =====================
263 CL_SignonReply
264
265 An svc_signonnum has been received, perform a client side setup
266 =====================
267 */
268 static void CL_SignonReply (void)
269 {
270         //char  str[8192];
271
272 Con_DPrintf("CL_SignonReply: %i\n", cls.signon);
273
274         switch (cls.signon)
275         {
276         case 1:
277                 MSG_WriteByte (&cls.message, clc_stringcmd);
278                 MSG_WriteString (&cls.message, "prespawn");
279                 break;
280
281         case 2:
282                 MSG_WriteByte (&cls.message, clc_stringcmd);
283                 MSG_WriteString (&cls.message, va("name \"%s\"", cl_name.string));
284
285                 MSG_WriteByte (&cls.message, clc_stringcmd);
286                 MSG_WriteString (&cls.message, va("color %i %i", cl_color.integer >> 4, cl_color.integer & 15));
287
288                 if (cl_pmodel.integer)
289                 {
290                         MSG_WriteByte (&cls.message, clc_stringcmd);
291                         MSG_WriteString (&cls.message, va("pmodel %i", cl_pmodel.integer));
292                 }
293                 if (*cl_playermodel.string)
294                 {
295                         MSG_WriteByte (&cls.message, clc_stringcmd);
296                         MSG_WriteString (&cls.message, va("playermodel %s", cl_playermodel.string));
297                 }
298                 if (*cl_playerskin.string)
299                 {
300                         MSG_WriteByte (&cls.message, clc_stringcmd);
301                         MSG_WriteString (&cls.message, va("playerskin %s", cl_playerskin.string));
302                 }
303
304                 MSG_WriteByte (&cls.message, clc_stringcmd);
305                 MSG_WriteString (&cls.message, va("rate %i", cl_rate.integer));
306
307                 MSG_WriteByte (&cls.message, clc_stringcmd);
308                 MSG_WriteString (&cls.message, "spawn");
309                 break;
310
311         case 3:
312                 MSG_WriteByte (&cls.message, clc_stringcmd);
313                 MSG_WriteString (&cls.message, "begin");
314                 break;
315
316         case 4:
317                 Con_ClearNotify();
318                 break;
319         }
320 }
321
322 /*
323 ==================
324 CL_ParseServerInfo
325 ==================
326 */
327 // FIXME: this is a lot of memory to be keeping around, this needs to be dynamically allocated and freed
328 static char parse_model_precache[MAX_MODELS][MAX_QPATH];
329 static char parse_sound_precache[MAX_SOUNDS][MAX_QPATH];
330 void CL_ParseServerInfo (void)
331 {
332         char *str;
333         int i;
334         protocolversion_t protocol;
335         int nummodels, numsounds;
336         entity_t *ent;
337
338         Con_DPrint("Serverinfo packet received.\n");
339
340         // check memory integrity
341         Mem_CheckSentinelsGlobal();
342
343 //
344 // wipe the client_state_t struct
345 //
346         CL_ClearState ();
347
348 // parse protocol version number
349         i = MSG_ReadLong ();
350         protocol = Protocol_EnumForNumber(i);
351         if (protocol == PROTOCOL_UNKNOWN)
352         {
353                 Host_Error("CL_ParseServerInfo: Server is unrecognized protocol number (%i)", i);
354                 return;
355         }
356         // hack for unmarked Nehahra movie demos which had a custom protocol
357         if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
358                 protocol = PROTOCOL_NEHAHRAMOVIE;
359         cl.protocol = protocol;
360         Con_DPrintf("Server protocol is %s\n", Protocol_NameForEnum(cl.protocol));
361
362 // parse maxclients
363         cl.maxclients = MSG_ReadByte ();
364         if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
365         {
366                 Host_Error("Bad maxclients (%u) from server", cl.maxclients);
367                 return;
368         }
369         cl.scores = (scoreboard_t *)Mem_Alloc(cl_mempool, cl.maxclients*sizeof(*cl.scores));
370
371 // parse gametype
372         cl.gametype = MSG_ReadByte ();
373
374 // parse signon message
375         str = MSG_ReadString ();
376         strlcpy (cl.levelname, str, sizeof(cl.levelname));
377
378 // seperate the printfs so the server message can have a color
379         if (cl.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
380                 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);
381
382         // check memory integrity
383         Mem_CheckSentinelsGlobal();
384
385         S_StopAllSounds();
386         // if server is active, we already began a loading plaque
387         if (!sv.active)
388                 SCR_BeginLoadingPlaque();
389
390         // disable until we get textures for it
391         R_ResetSkyBox();
392
393         memset(cl.model_precache, 0, sizeof(cl.model_precache));
394         memset(cl.sound_precache, 0, sizeof(cl.sound_precache));
395
396         // parse model precache list
397         for (nummodels=1 ; ; nummodels++)
398         {
399                 str = MSG_ReadString();
400                 if (!str[0])
401                         break;
402                 if (nummodels==MAX_MODELS)
403                         Host_Error ("Server sent too many model precaches");
404                 if (strlen(str) >= MAX_QPATH)
405                         Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
406                 strlcpy (parse_model_precache[nummodels], str, sizeof (parse_model_precache[nummodels]));
407         }
408         // parse sound precache list
409         for (numsounds=1 ; ; numsounds++)
410         {
411                 str = MSG_ReadString();
412                 if (!str[0])
413                         break;
414                 if (numsounds==MAX_SOUNDS)
415                         Host_Error("Server sent too many sound precaches");
416                 if (strlen(str) >= MAX_QPATH)
417                         Host_Error("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
418                 strlcpy (parse_sound_precache[numsounds], str, sizeof (parse_sound_precache[numsounds]));
419         }
420
421         // touch all of the precached models that are still loaded so we can free
422         // anything that isn't needed
423         Mod_ClearUsed();
424         for (i = 1;i < nummodels;i++)
425                 Mod_FindName(parse_model_precache[i]);
426         // precache any models used by the client (this also marks them used)
427         cl.model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
428         cl.model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
429         cl.model_bolt3 = Mod_ForName("progs/bolt3.mdl", false, false, false);
430         cl.model_beam = Mod_ForName("progs/beam.mdl", false, false, false);
431         Mod_PurgeUnused();
432
433         // do the same for sounds
434         // FIXME: S_ServerSounds does not know about cl.sfx_ sounds
435         S_ServerSounds (parse_sound_precache, numsounds);
436
437         // precache any sounds used by the client
438         cl.sfx_wizhit = S_PrecacheSound("sound/wizard/hit.wav", false, true);
439         cl.sfx_knighthit = S_PrecacheSound("sound/hknight/hit.wav", false, true);
440         cl.sfx_tink1 = S_PrecacheSound("sound/weapons/tink1.wav", false, true);
441         cl.sfx_ric1 = S_PrecacheSound("sound/weapons/ric1.wav", false, true);
442         cl.sfx_ric2 = S_PrecacheSound("sound/weapons/ric2.wav", false, true);
443         cl.sfx_ric3 = S_PrecacheSound("sound/weapons/ric3.wav", false, true);
444         cl.sfx_r_exp3 = S_PrecacheSound("sound/weapons/r_exp3.wav", false, true);
445
446         // now we try to load everything that is new
447
448         // world model
449         CL_KeepaliveMessage ();
450         cl.model_precache[1] = Mod_ForName(parse_model_precache[1], false, false, true);
451         if (cl.model_precache[1]->Draw == NULL)
452                 Con_Printf("Map %s not found\n", parse_model_precache[1]);
453
454         // normal models
455         for (i=2 ; i<nummodels ; i++)
456         {
457                 CL_KeepaliveMessage();
458                 if ((cl.model_precache[i] = Mod_ForName(parse_model_precache[i], false, false, false))->Draw == NULL)
459                         Con_Printf("Model %s not found\n", parse_model_precache[i]);
460         }
461
462         // sounds
463         for (i=1 ; i<numsounds ; i++)
464         {
465                 CL_KeepaliveMessage();
466
467                 // Don't lock the sfx here, S_ServerSounds already did that
468                 cl.sound_precache[i] = S_PrecacheSound (parse_sound_precache[i], true, false);
469         }
470
471         // local state
472         ent = &cl_entities[0];
473         // entire entity array was cleared, so just fill in a few fields
474         ent->state_current.active = true;
475         ent->render.model = cl.worldmodel = cl.model_precache[1];
476         ent->render.scale = 1; // some of the renderer still relies on scale
477         ent->render.alpha = 1;
478         ent->render.colormap = -1; // no special coloring
479         ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
480         Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
481         Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
482         CL_BoundingBoxForEntity(&ent->render);
483
484         cl_num_entities = 1;
485
486         R_Modules_NewMap();
487         CL_CGVM_Start();
488
489         // noclip is turned off at start
490         noclip_anglehack = false;
491
492         // check memory integrity
493         Mem_CheckSentinelsGlobal();
494 }
495
496 void CL_ValidateState(entity_state_t *s)
497 {
498         model_t *model;
499
500         if (!s->active)
501                 return;
502
503         if (s->modelindex >= MAX_MODELS)
504                 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)", s->modelindex, MAX_MODELS);
505
506         // colormap is client index + 1
507         if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
508         {
509                 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
510                 s->colormap = 0;
511         }
512
513         model = cl.model_precache[s->modelindex];
514         if (model && model->type && s->frame >= model->numframes)
515         {
516                 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
517                 s->frame = 0;
518         }
519         if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
520         {
521                 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
522                 s->skin = 0;
523         }
524 }
525
526 void CL_MoveLerpEntityStates(entity_t *ent)
527 {
528         float odelta[3], adelta[3];
529         CL_ValidateState(&ent->state_current);
530         VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
531         VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
532         if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
533         {
534                 // reset all persistent stuff if this is a new entity
535                 ent->persistent.lerpdeltatime = 0;
536                 ent->persistent.lerpstarttime = cl.mtime[1];
537                 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
538                 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
539                 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
540                 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
541                 // reset animation interpolation as well
542                 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
543                 ent->render.frame1time = ent->render.frame2time = cl.time;
544                 ent->render.framelerp = 1;
545                 // reset various persistent stuff
546                 ent->persistent.muzzleflash = 0;
547                 VectorCopy(ent->state_current.origin, ent->persistent.trail_origin);
548         }
549         else if (cls.timedemo || cl_nolerp.integer || DotProduct(odelta, odelta) > 1000*1000)
550         {
551                 // don't interpolate the move
552                 ent->persistent.lerpdeltatime = 0;
553                 ent->persistent.lerpstarttime = cl.mtime[1];
554                 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
555                 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
556                 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
557                 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
558         }
559         else if (ent->state_current.flags & RENDER_STEP)
560         {
561                 // monster interpolation
562                 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
563                 {
564                         ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
565                         ent->persistent.lerpstarttime = cl.mtime[1];
566                         VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
567                         VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
568                         VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
569                         VectorCopy(ent->state_current.angles, ent->persistent.newangles);
570                 }
571         }
572         else
573         {
574                 // not a monster
575                 ent->persistent.lerpstarttime = ent->state_previous.time;
576                 // no lerp if it's singleplayer
577                 if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
578                         ent->persistent.lerpdeltatime = 0;
579                 else
580                         ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
581                 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
582                 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
583                 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
584                 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
585         }
586 }
587
588 /*
589 ==================
590 CL_ParseBaseline
591 ==================
592 */
593 void CL_ParseBaseline (entity_t *ent, int large)
594 {
595         int i;
596
597         ent->state_baseline = defaultstate;
598         // FIXME: set ent->state_baseline.number?
599         ent->state_baseline.active = true;
600         if (large)
601         {
602                 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
603                 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
604         }
605         else
606         {
607                 ent->state_baseline.modelindex = MSG_ReadByte ();
608                 ent->state_baseline.frame = MSG_ReadByte ();
609         }
610         ent->state_baseline.colormap = MSG_ReadByte();
611         ent->state_baseline.skin = MSG_ReadByte();
612         for (i = 0;i < 3;i++)
613         {
614                 ent->state_baseline.origin[i] = MSG_ReadCoord(cl.protocol);
615                 ent->state_baseline.angles[i] = MSG_ReadAngle(cl.protocol);
616         }
617         CL_ValidateState(&ent->state_baseline);
618         ent->state_previous = ent->state_current = ent->state_baseline;
619 }
620
621
622 /*
623 ==================
624 CL_ParseClientdata
625
626 Server information pertaining to this client only
627 ==================
628 */
629 void CL_ParseClientdata (void)
630 {
631         int i, j, bits;
632
633         VectorCopy (cl.mpunchangle[0], cl.mpunchangle[1]);
634         VectorCopy (cl.mpunchvector[0], cl.mpunchvector[1]);
635         VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
636         cl.mviewzoom[1] = cl.mviewzoom[0];
637
638         if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
639         {
640                 cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
641                 cl.stats[STAT_ITEMS] = 0;
642                 cl.stats[STAT_VIEWZOOM] = 255;
643         }
644         cl.idealpitch = 0;
645         cl.mpunchangle[0][0] = 0;
646         cl.mpunchangle[0][1] = 0;
647         cl.mpunchangle[0][2] = 0;
648         cl.mpunchvector[0][0] = 0;
649         cl.mpunchvector[0][1] = 0;
650         cl.mpunchvector[0][2] = 0;
651         cl.mvelocity[0][0] = 0;
652         cl.mvelocity[0][1] = 0;
653         cl.mvelocity[0][2] = 0;
654         cl.mviewzoom[0] = 1;
655
656         bits = (unsigned short) MSG_ReadShort ();
657         if (bits & SU_EXTEND1)
658                 bits |= (MSG_ReadByte() << 16);
659         if (bits & SU_EXTEND2)
660                 bits |= (MSG_ReadByte() << 24);
661
662         if (bits & SU_VIEWHEIGHT)
663                 cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
664
665         if (bits & SU_IDEALPITCH)
666                 cl.idealpitch = MSG_ReadChar ();
667
668         for (i = 0;i < 3;i++)
669         {
670                 if (bits & (SU_PUNCH1<<i) )
671                 {
672                         if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE)
673                                 cl.mpunchangle[0][i] = MSG_ReadChar();
674                         else
675                                 cl.mpunchangle[0][i] = MSG_ReadAngle16i();
676                 }
677                 if (bits & (SU_PUNCHVEC1<<i))
678                 {
679                         if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
680                                 cl.mpunchvector[0][i] = MSG_ReadCoord16i();
681                         else
682                                 cl.mpunchvector[0][i] = MSG_ReadCoord32f();
683                 }
684                 if (bits & (SU_VELOCITY1<<i) )
685                 {
686                         if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
687                                 cl.mvelocity[0][i] = MSG_ReadChar()*16;
688                         else
689                                 cl.mvelocity[0][i] = MSG_ReadCoord32f();
690                 }
691         }
692
693         // LordHavoc: hipnotic demos don't have this bit set but should
694         if (bits & SU_ITEMS || cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
695                 cl.stats[STAT_ITEMS] = MSG_ReadLong ();
696
697         cl.onground = (bits & SU_ONGROUND) != 0;
698         cl.inwater = (bits & SU_INWATER) != 0;
699
700         if (cl.protocol == PROTOCOL_DARKPLACES5)
701         {
702                 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
703                 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
704                 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
705                 cl.stats[STAT_HEALTH] = MSG_ReadShort();
706                 cl.stats[STAT_AMMO] = MSG_ReadShort();
707                 cl.stats[STAT_SHELLS] = MSG_ReadShort();
708                 cl.stats[STAT_NAILS] = MSG_ReadShort();
709                 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
710                 cl.stats[STAT_CELLS] = MSG_ReadShort();
711                 cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
712         }
713         else if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
714         {
715                 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
716                 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
717                 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
718                 cl.stats[STAT_HEALTH] = MSG_ReadShort();
719                 cl.stats[STAT_AMMO] = MSG_ReadByte();
720                 cl.stats[STAT_SHELLS] = MSG_ReadByte();
721                 cl.stats[STAT_NAILS] = MSG_ReadByte();
722                 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
723                 cl.stats[STAT_CELLS] = MSG_ReadByte();
724                 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
725                         cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
726                 else
727                         cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
728         }
729
730         if (bits & SU_VIEWZOOM)
731         {
732                 if (cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
733                         cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
734                 else
735                         cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
736         }
737
738         // check for important changes
739
740         // set flash times
741         if (cl.olditems != cl.stats[STAT_ITEMS])
742                 for (j = 0;j < 32;j++)
743                         if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
744                                 cl.item_gettime[j] = cl.time;
745         cl.olditems = cl.stats[STAT_ITEMS];
746
747         // GAME_NEXUIZ hud needs weapon change time
748         if (cl.activeweapon != cl.stats[STAT_ACTIVEWEAPON])
749                 cl.weapontime = cl.time;
750         cl.activeweapon = cl.stats[STAT_ACTIVEWEAPON];
751
752         // viewzoom interpolation
753         cl.mviewzoom[0] = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
754 }
755
756 /*
757 =====================
758 CL_ParseStatic
759 =====================
760 */
761 void CL_ParseStatic (int large)
762 {
763         entity_t *ent;
764
765         if (cl_num_static_entities >= cl_max_static_entities)
766                 Host_Error ("Too many static entities");
767         ent = &cl_static_entities[cl_num_static_entities++];
768         CL_ParseBaseline (ent, large);
769
770 // copy it to the current state
771         ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
772         ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
773         ent->render.framelerp = 0;
774         // make torchs play out of sync
775         ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
776         ent->render.colormap = -1; // no special coloring
777         ent->render.skinnum = ent->state_baseline.skin;
778         ent->render.effects = ent->state_baseline.effects;
779         ent->render.alpha = 1;
780         //ent->render.scale = 1;
781
782         //VectorCopy (ent->state_baseline.origin, ent->render.origin);
783         //VectorCopy (ent->state_baseline.angles, ent->render.angles);
784
785         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);
786         Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
787         CL_BoundingBoxForEntity(&ent->render);
788
789         // This is definitely cheating...
790         if (ent->render.model == NULL)
791                 cl_num_static_entities--;
792 }
793
794 /*
795 ===================
796 CL_ParseStaticSound
797 ===================
798 */
799 void CL_ParseStaticSound (int large)
800 {
801         vec3_t          org;
802         int                     sound_num, vol, atten;
803
804         MSG_ReadVector(org, cl.protocol);
805         if (large)
806                 sound_num = (unsigned short) MSG_ReadShort ();
807         else
808                 sound_num = MSG_ReadByte ();
809         vol = MSG_ReadByte ();
810         atten = MSG_ReadByte ();
811
812         S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
813 }
814
815 void CL_ParseEffect (void)
816 {
817         vec3_t          org;
818         int                     modelindex, startframe, framecount, framerate;
819
820         MSG_ReadVector(org, cl.protocol);
821         modelindex = MSG_ReadByte ();
822         startframe = MSG_ReadByte ();
823         framecount = MSG_ReadByte ();
824         framerate = MSG_ReadByte ();
825
826         CL_Effect(org, modelindex, startframe, framecount, framerate);
827 }
828
829 void CL_ParseEffect2 (void)
830 {
831         vec3_t          org;
832         int                     modelindex, startframe, framecount, framerate;
833
834         MSG_ReadVector(org, cl.protocol);
835         modelindex = (unsigned short) MSG_ReadShort ();
836         startframe = (unsigned short) MSG_ReadShort ();
837         framecount = MSG_ReadByte ();
838         framerate = MSG_ReadByte ();
839
840         CL_Effect(org, modelindex, startframe, framecount, framerate);
841 }
842
843 void CL_ParseBeam (model_t *m, int lightning)
844 {
845         int i, ent;
846         vec3_t start, end;
847         beam_t *b = NULL;
848
849         ent = (unsigned short) MSG_ReadShort ();
850         MSG_ReadVector(start, cl.protocol);
851         MSG_ReadVector(end, cl.protocol);
852
853         if (ent >= MAX_EDICTS)
854         {
855                 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
856                 ent = 0;
857         }
858
859         if (ent >= cl_max_entities)
860                 CL_ExpandEntities(ent);
861
862         // override any beam with the same entity
863         i = cl_max_beams;
864         if (ent)
865                 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
866                         if (b->entity == ent)
867                                 break;
868         // if the entity was not found then just replace an unused beam
869         if (i == cl_max_beams)
870                 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
871                         if (!b->model || b->endtime < cl.time)
872                                 break;
873         if (i < cl_max_beams)
874         {
875                 b->entity = ent;
876                 b->lightning = lightning;
877                 b->model = m;
878                 b->endtime = cl.time + 0.2;
879                 VectorCopy (start, b->start);
880                 VectorCopy (end, b->end);
881                 b->relativestartvalid = 0;
882                 if (ent && cl_entities[ent].state_current.active)
883                 {
884                         entity_state_t *p;
885                         matrix4x4_t matrix, imatrix;
886                         if (ent == cl.viewentity && cl.movement)
887                                 p = &cl_entities[b->entity].state_previous;
888                         else
889                                 p = &cl_entities[b->entity].state_current;
890                         // not really valid yet, we need to get the orientation now
891                         // (ParseBeam flagged this because it is received before
892                         //  entities are received, by now they have been received)
893                         // note: because players create lightning in their think
894                         // function (which occurs before movement), they actually
895                         // have some lag in it's location, so compare to the
896                         // previous player state, not the latest
897                         Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2], -p->angles[0], p->angles[1], p->angles[2], 1);
898                         Matrix4x4_Invert_Simple(&imatrix, &matrix);
899                         Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
900                         Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
901                         b->relativestartvalid = 1;
902                 }
903         }
904         else
905                 Con_Print("beam list overflow!\n");
906 }
907
908 void CL_ParseTempEntity(void)
909 {
910         int type;
911         vec3_t pos;
912         vec3_t dir;
913         vec3_t pos2;
914         vec3_t color;
915         int rnd;
916         int colorStart, colorLength, count;
917         float velspeed, radius;
918         unsigned char *tempcolor;
919         matrix4x4_t tempmatrix;
920
921         type = MSG_ReadByte();
922         switch (type)
923         {
924         case TE_WIZSPIKE:
925                 // spike hitting wall
926                 MSG_ReadVector(pos, cl.protocol);
927                 CL_FindNonSolidLocation(pos, pos, 4);
928                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
929                 //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);
930                 CL_RunParticleEffect(pos, vec3_origin, 20, 30);
931                 S_StartSound(-1, 0, cl.sfx_wizhit, pos, 1, 1);
932                 break;
933
934         case TE_KNIGHTSPIKE:
935                 // spike hitting wall
936                 MSG_ReadVector(pos, cl.protocol);
937                 CL_FindNonSolidLocation(pos, pos, 4);
938                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
939                 //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);
940                 CL_RunParticleEffect(pos, vec3_origin, 226, 20);
941                 S_StartSound(-1, 0, cl.sfx_knighthit, pos, 1, 1);
942                 break;
943
944         case TE_SPIKE:
945                 // spike hitting wall
946                 MSG_ReadVector(pos, cl.protocol);
947                 CL_FindNonSolidLocation(pos, pos, 4);
948                 if (cl_particles_quake.integer)
949                         CL_RunParticleEffect(pos, vec3_origin, 0, 10);
950                 else if (cl_particles_bulletimpacts.integer)
951                 {
952                         CL_SparkShower(pos, vec3_origin, 15, 1);
953                         CL_Smoke(pos, vec3_origin, 15);
954                 }
955                 CL_BulletMark(pos);
956                 if (rand() % 5)
957                         S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
958                 else
959                 {
960                         rnd = rand() & 3;
961                         if (rnd == 1)
962                                 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
963                         else if (rnd == 2)
964                                 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
965                         else
966                                 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
967                 }
968                 break;
969         case TE_SPIKEQUAD:
970                 // quad spike hitting wall
971                 MSG_ReadVector(pos, cl.protocol);
972                 CL_FindNonSolidLocation(pos, pos, 4);
973                 if (cl_particles_quake.integer)
974                         CL_RunParticleEffect(pos, vec3_origin, 0, 10);
975                 else if (cl_particles_bulletimpacts.integer)
976                 {
977                         CL_SparkShower(pos, vec3_origin, 15, 1);
978                         CL_Smoke(pos, vec3_origin, 15);
979                 }
980                 CL_BulletMark(pos);
981                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
982                 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);
983                 if (rand() % 5)
984                         S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
985                 else
986                 {
987                         rnd = rand() & 3;
988                         if (rnd == 1)
989                                 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
990                         else if (rnd == 2)
991                                 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
992                         else
993                                 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
994                 }
995                 break;
996         case TE_SUPERSPIKE:
997                 // super spike hitting wall
998                 MSG_ReadVector(pos, cl.protocol);
999                 CL_FindNonSolidLocation(pos, pos, 4);
1000                 if (cl_particles_quake.integer)
1001                         CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1002                 else if (cl_particles_bulletimpacts.integer)
1003                 {
1004                         CL_SparkShower(pos, vec3_origin, 30, 1);
1005                         CL_Smoke(pos, vec3_origin, 30);
1006                 }
1007                 CL_BulletMark(pos);
1008                 if (rand() % 5)
1009                         S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1010                 else
1011                 {
1012                         rnd = rand() & 3;
1013                         if (rnd == 1)
1014                                 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1015                         else if (rnd == 2)
1016                                 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1017                         else
1018                                 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1019                 }
1020                 break;
1021         case TE_SUPERSPIKEQUAD:
1022                 // quad super spike hitting wall
1023                 MSG_ReadVector(pos, cl.protocol);
1024                 CL_FindNonSolidLocation(pos, pos, 4);
1025                 if (cl_particles_quake.integer)
1026                         CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1027                 else if (cl_particles_bulletimpacts.integer)
1028                 {
1029                         CL_SparkShower(pos, vec3_origin, 30, 1);
1030                         CL_Smoke(pos, vec3_origin, 30);
1031                 }
1032                 CL_BulletMark(pos);
1033                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1034                 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);
1035                 if (rand() % 5)
1036                         S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1037                 else
1038                 {
1039                         rnd = rand() & 3;
1040                         if (rnd == 1)
1041                                 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1042                         else if (rnd == 2)
1043                                 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1044                         else
1045                                 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1046                 }
1047                 break;
1048                 // LordHavoc: added for improved blood splatters
1049         case TE_BLOOD:
1050                 // blood puff
1051                 MSG_ReadVector(pos, cl.protocol);
1052                 CL_FindNonSolidLocation(pos, pos, 4);
1053                 dir[0] = MSG_ReadChar();
1054                 dir[1] = MSG_ReadChar();
1055                 dir[2] = MSG_ReadChar();
1056                 count = MSG_ReadByte();
1057                 CL_BloodPuff(pos, dir, count);
1058                 break;
1059         case TE_SPARK:
1060                 // spark shower
1061                 MSG_ReadVector(pos, cl.protocol);
1062                 CL_FindNonSolidLocation(pos, pos, 4);
1063                 dir[0] = MSG_ReadChar();
1064                 dir[1] = MSG_ReadChar();
1065                 dir[2] = MSG_ReadChar();
1066                 count = MSG_ReadByte();
1067                 CL_SparkShower(pos, dir, count, 1);
1068                 break;
1069         case TE_PLASMABURN:
1070                 MSG_ReadVector(pos, cl.protocol);
1071                 CL_FindNonSolidLocation(pos, pos, 4);
1072                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1073                 CL_AllocDlight(NULL, &tempmatrix, 200, 1, 1, 1, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1074                 CL_PlasmaBurn(pos);
1075                 break;
1076                 // LordHavoc: added for improved gore
1077         case TE_BLOODSHOWER:
1078                 // vaporized body
1079                 MSG_ReadVector(pos, cl.protocol); // mins
1080                 MSG_ReadVector(pos2, cl.protocol); // maxs
1081                 velspeed = MSG_ReadCoord(cl.protocol); // speed
1082                 count = (unsigned short) MSG_ReadShort(); // number of particles
1083                 CL_BloodShower(pos, pos2, velspeed, count);
1084                 break;
1085         case TE_PARTICLECUBE:
1086                 // general purpose particle effect
1087                 MSG_ReadVector(pos, cl.protocol); // mins
1088                 MSG_ReadVector(pos2, cl.protocol); // maxs
1089                 MSG_ReadVector(dir, cl.protocol); // dir
1090                 count = (unsigned short) MSG_ReadShort(); // number of particles
1091                 colorStart = MSG_ReadByte(); // color
1092                 colorLength = MSG_ReadByte(); // gravity (1 or 0)
1093                 velspeed = MSG_ReadCoord(cl.protocol); // randomvel
1094                 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
1095                 break;
1096
1097         case TE_PARTICLERAIN:
1098                 // general purpose particle effect
1099                 MSG_ReadVector(pos, cl.protocol); // mins
1100                 MSG_ReadVector(pos2, cl.protocol); // maxs
1101                 MSG_ReadVector(dir, cl.protocol); // dir
1102                 count = (unsigned short) MSG_ReadShort(); // number of particles
1103                 colorStart = MSG_ReadByte(); // color
1104                 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
1105                 break;
1106
1107         case TE_PARTICLESNOW:
1108                 // general purpose particle effect
1109                 MSG_ReadVector(pos, cl.protocol); // mins
1110                 MSG_ReadVector(pos2, cl.protocol); // maxs
1111                 MSG_ReadVector(dir, cl.protocol); // dir
1112                 count = (unsigned short) MSG_ReadShort(); // number of particles
1113                 colorStart = MSG_ReadByte(); // color
1114                 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
1115                 break;
1116
1117         case TE_GUNSHOT:
1118                 // bullet hitting wall
1119                 MSG_ReadVector(pos, cl.protocol);
1120                 CL_FindNonSolidLocation(pos, pos, 4);
1121                 if (cl_particles_quake.integer)
1122                         CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1123                 else
1124                 {
1125                         CL_SparkShower(pos, vec3_origin, 15, 1);
1126                         CL_Smoke(pos, vec3_origin, 15);
1127                 }
1128                 CL_BulletMark(pos);
1129                 break;
1130
1131         case TE_GUNSHOTQUAD:
1132                 // quad bullet hitting wall
1133                 MSG_ReadVector(pos, cl.protocol);
1134                 CL_FindNonSolidLocation(pos, pos, 4);
1135                 if (cl_particles_quake.integer)
1136                         CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1137                 else
1138                 {
1139                         CL_SparkShower(pos, vec3_origin, 15, 1);
1140                         CL_Smoke(pos, vec3_origin, 15);
1141                 }
1142                 CL_BulletMark(pos);
1143                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1144                 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);
1145                 break;
1146
1147         case TE_EXPLOSION:
1148                 // rocket explosion
1149                 MSG_ReadVector(pos, cl.protocol);
1150                 CL_FindNonSolidLocation(pos, pos, 10);
1151                 CL_ParticleExplosion(pos);
1152                 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
1153                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1154                 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);
1155                 if (gamemode != GAME_NEXUIZ)
1156                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1157                 break;
1158
1159         case TE_EXPLOSIONQUAD:
1160                 // quad rocket explosion
1161                 MSG_ReadVector(pos, cl.protocol);
1162                 CL_FindNonSolidLocation(pos, pos, 10);
1163                 CL_ParticleExplosion(pos);
1164                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1165                 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);
1166                 if (gamemode != GAME_NEXUIZ)
1167                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1168                 break;
1169
1170         case TE_EXPLOSION3:
1171                 // Nehahra movie colored lighting explosion
1172                 MSG_ReadVector(pos, cl.protocol);
1173                 CL_FindNonSolidLocation(pos, pos, 10);
1174                 CL_ParticleExplosion(pos);
1175                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1176                 color[0] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1177                 color[1] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1178                 color[2] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1179                 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);
1180                 if (gamemode != GAME_NEXUIZ)
1181                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1182                 break;
1183
1184         case TE_EXPLOSIONRGB:
1185                 // colored lighting explosion
1186                 MSG_ReadVector(pos, cl.protocol);
1187                 CL_FindNonSolidLocation(pos, pos, 10);
1188                 CL_ParticleExplosion(pos);
1189                 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1190                 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1191                 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1192                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1193                 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);
1194                 if (gamemode != GAME_NEXUIZ)
1195                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1196                 break;
1197
1198         case TE_TAREXPLOSION:
1199                 // tarbaby explosion
1200                 MSG_ReadVector(pos, cl.protocol);
1201                 CL_FindNonSolidLocation(pos, pos, 10);
1202                 CL_BlobExplosion(pos);
1203
1204                 if (gamemode != GAME_NEXUIZ)
1205                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1206                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1207                 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);
1208                 break;
1209
1210         case TE_SMALLFLASH:
1211                 MSG_ReadVector(pos, cl.protocol);
1212                 CL_FindNonSolidLocation(pos, pos, 10);
1213                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1214                 CL_AllocDlight(NULL, &tempmatrix, 200, 2, 2, 2, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1215                 break;
1216
1217         case TE_CUSTOMFLASH:
1218                 MSG_ReadVector(pos, cl.protocol);
1219                 CL_FindNonSolidLocation(pos, pos, 4);
1220                 radius = (MSG_ReadByte() + 1) * 8;
1221                 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
1222                 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1223                 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1224                 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1225                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1226                 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);
1227                 break;
1228
1229         case TE_FLAMEJET:
1230                 MSG_ReadVector(pos, cl.protocol);
1231                 MSG_ReadVector(dir, cl.protocol);
1232                 count = MSG_ReadByte();
1233                 CL_Flames(pos, dir, count);
1234                 break;
1235
1236         case TE_LIGHTNING1:
1237                 // lightning bolts
1238                 CL_ParseBeam(cl.model_bolt, true);
1239                 break;
1240
1241         case TE_LIGHTNING2:
1242                 // lightning bolts
1243                 CL_ParseBeam(cl.model_bolt2, true);
1244                 break;
1245
1246         case TE_LIGHTNING3:
1247                 // lightning bolts
1248                 CL_ParseBeam(cl.model_bolt3, false);
1249                 break;
1250
1251 // PGM 01/21/97
1252         case TE_BEAM:
1253                 // grappling hook beam
1254                 CL_ParseBeam(cl.model_beam, false);
1255                 break;
1256 // PGM 01/21/97
1257
1258 // LordHavoc: for compatibility with the Nehahra movie...
1259         case TE_LIGHTNING4NEH:
1260                 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
1261                 break;
1262
1263         case TE_LAVASPLASH:
1264                 MSG_ReadVector(pos, cl.protocol);
1265                 CL_LavaSplash(pos);
1266                 break;
1267
1268         case TE_TELEPORT:
1269                 MSG_ReadVector(pos, cl.protocol);
1270                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1271                 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);
1272                 CL_TeleportSplash(pos);
1273                 break;
1274
1275         case TE_EXPLOSION2:
1276                 // color mapped explosion
1277                 MSG_ReadVector(pos, cl.protocol);
1278                 CL_FindNonSolidLocation(pos, pos, 10);
1279                 colorStart = MSG_ReadByte();
1280                 colorLength = MSG_ReadByte();
1281                 CL_ParticleExplosion2(pos, colorStart, colorLength);
1282                 tempcolor = (unsigned char *)&palette_complete[(rand()%colorLength) + colorStart];
1283                 color[0] = tempcolor[0] * (2.0f / 255.0f);
1284                 color[1] = tempcolor[1] * (2.0f / 255.0f);
1285                 color[2] = tempcolor[2] * (2.0f / 255.0f);
1286                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1287                 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);
1288                 if (gamemode != GAME_NEXUIZ)
1289                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1290                 break;
1291
1292         case TE_TEI_G3:
1293                 MSG_ReadVector(pos, cl.protocol);
1294                 MSG_ReadVector(pos2, cl.protocol);
1295                 MSG_ReadVector(dir, cl.protocol);
1296                 CL_BeamParticle(pos, pos2, 8, 1, 1, 1, 1, 1);
1297                 break;
1298
1299         case TE_TEI_SMOKE:
1300                 MSG_ReadVector(pos, cl.protocol);
1301                 MSG_ReadVector(dir, cl.protocol);
1302                 count = MSG_ReadByte();
1303                 CL_FindNonSolidLocation(pos, pos, 4);
1304                 CL_Tei_Smoke(pos, dir, count);
1305                 break;
1306
1307         case TE_TEI_BIGEXPLOSION:
1308                 MSG_ReadVector(pos, cl.protocol);
1309                 CL_FindNonSolidLocation(pos, pos, 10);
1310                 CL_ParticleExplosion(pos);
1311                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1312                 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);
1313                 if (gamemode != GAME_NEXUIZ)
1314                         S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1315                 break;
1316
1317         case TE_TEI_PLASMAHIT:
1318                 MSG_ReadVector(pos, cl.protocol);
1319                 MSG_ReadVector(dir, cl.protocol);
1320                 count = MSG_ReadByte();
1321                 CL_FindNonSolidLocation(pos, pos, 5);
1322                 CL_Tei_PlasmaHit(pos, dir, count);
1323                 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1324                 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);
1325                 break;
1326
1327         default:
1328                 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
1329         }
1330 }
1331
1332 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
1333
1334 static unsigned char cgamenetbuffer[65536];
1335
1336 /*
1337 =====================
1338 CL_ParseServerMessage
1339 =====================
1340 */
1341 int parsingerror = false;
1342 void CL_ParseServerMessage(void)
1343 {
1344         int                     cmd;
1345         int                     i;
1346         protocolversion_t protocol;
1347         unsigned char           cmdlog[32];
1348         char            *cmdlogname[32], *temp;
1349         int                     cmdindex, cmdcount = 0;
1350         qboolean        sendmove = false;
1351
1352         if (cls.demorecording)
1353                 CL_WriteDemoMessage ();
1354
1355         cl.last_received_message = realtime;
1356
1357 //
1358 // if recording demos, copy the message out
1359 //
1360         if (cl_shownet.integer == 1)
1361                 Con_Printf("%f %i\n", realtime, net_message.cursize);
1362         else if (cl_shownet.integer == 2)
1363                 Con_Print("------------------\n");
1364
1365         cl.onground = false;    // unless the server says otherwise
1366 //
1367 // parse the message
1368 //
1369         //MSG_BeginReading ();
1370
1371         parsingerror = true;
1372
1373         while (1)
1374         {
1375                 if (msg_badread)
1376                         Host_Error ("CL_ParseServerMessage: Bad server message");
1377
1378                 cmd = MSG_ReadByte ();
1379
1380                 if (cmd == -1)
1381                 {
1382                         SHOWNET("END OF MESSAGE");
1383                         break;          // end of message
1384                 }
1385
1386                 cmdindex = cmdcount & 31;
1387                 cmdcount++;
1388                 cmdlog[cmdindex] = cmd;
1389
1390                 // if the high bit of the command byte is set, it is a fast update
1391                 if (cmd & 128)
1392                 {
1393                         // 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)
1394                         temp = "entity";
1395                         cmdlogname[cmdindex] = temp;
1396                         SHOWNET("fast update");
1397                         if (cls.signon == SIGNONS - 1)
1398                         {
1399                                 // first update is the final signon stage
1400                                 cls.signon = SIGNONS;
1401                                 CL_SignonReply ();
1402                         }
1403                         EntityFrameQuake_ReadEntity (cmd&127);
1404                         continue;
1405                 }
1406
1407                 SHOWNET(svc_strings[cmd]);
1408                 cmdlogname[cmdindex] = svc_strings[cmd];
1409                 if (!cmdlogname[cmdindex])
1410                 {
1411                         // 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)
1412                         temp = "<unknown>";
1413                         cmdlogname[cmdindex] = temp;
1414                 }
1415
1416                 // other commands
1417                 switch (cmd)
1418                 {
1419                 default:
1420                         {
1421                                 char description[32*64], temp[64];
1422                                 int count;
1423                                 strcpy (description, "packet dump: ");
1424                                 i = cmdcount - 32;
1425                                 if (i < 0)
1426                                         i = 0;
1427                                 count = cmdcount - i;
1428                                 i &= 31;
1429                                 while(count > 0)
1430                                 {
1431                                         dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
1432                                         strlcat (description, temp, sizeof (description));
1433                                         count--;
1434                                         i++;
1435                                         i &= 31;
1436                                 }
1437                                 description[strlen(description)-1] = '\n'; // replace the last space with a newline
1438                                 Con_Print(description);
1439                                 Host_Error ("CL_ParseServerMessage: Illegible server message");
1440                         }
1441                         break;
1442
1443                 case svc_nop:
1444                         if (cls.signon < SIGNONS)
1445                                 Con_Print("<-- server to client keepalive\n");
1446                         break;
1447
1448                 case svc_time:
1449                         cl.mtime[1] = cl.mtime[0];
1450                         cl.mtime[0] = MSG_ReadFloat ();
1451                         sendmove = true;
1452                         break;
1453
1454                 case svc_clientdata:
1455                         CL_ParseClientdata();
1456                         break;
1457
1458                 case svc_version:
1459                         i = MSG_ReadLong ();
1460                         protocol = Protocol_EnumForNumber(i);
1461                         if (protocol == PROTOCOL_UNKNOWN)
1462                                 Host_Error("CL_ParseServerMessage: Server is unrecognized protocol number (%i)", i);
1463                         // hack for unmarked Nehahra movie demos which had a custom protocol
1464                         if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
1465                                 protocol = PROTOCOL_NEHAHRAMOVIE;
1466                         cl.protocol = protocol;
1467                         break;
1468
1469                 case svc_disconnect:
1470                         Con_Printf ("Server disconnected\n");
1471                         if (cls.demonum != -1)
1472                                 CL_NextDemo ();
1473                         else
1474                                 CL_Disconnect ();
1475                         break;
1476
1477                 case svc_print:
1478                         Con_Print(MSG_ReadString());
1479                         break;
1480
1481                 case svc_centerprint:
1482                         SCR_CenterPrint(MSG_ReadString ());
1483                         break;
1484
1485                 case svc_stufftext:
1486                         Cbuf_AddText (MSG_ReadString ());
1487                         break;
1488
1489                 case svc_damage:
1490                         V_ParseDamage ();
1491                         break;
1492
1493                 case svc_serverinfo:
1494                         CL_ParseServerInfo ();
1495                         break;
1496
1497                 case svc_setangle:
1498                         for (i=0 ; i<3 ; i++)
1499                                 cl.viewangles[i] = MSG_ReadAngle (cl.protocol);
1500                         break;
1501
1502                 case svc_setview:
1503                         cl.viewentity = (unsigned short)MSG_ReadShort ();
1504                         if (cl.viewentity >= MAX_EDICTS)
1505                                 Host_Error("svc_setview >= MAX_EDICTS");
1506                         if (cl.viewentity >= cl_max_entities)
1507                                 CL_ExpandEntities(cl.viewentity);
1508                         // LordHavoc: assume first setview recieved is the real player entity
1509                         if (!cl.playerentity)
1510                                 cl.playerentity = cl.viewentity;
1511                         break;
1512
1513                 case svc_lightstyle:
1514                         i = MSG_ReadByte ();
1515                         if (i >= MAX_LIGHTSTYLES)
1516                                 Host_Error ("svc_lightstyle >= MAX_LIGHTSTYLES");
1517                         strlcpy (cl_lightstyle[i].map,  MSG_ReadString(), sizeof (cl_lightstyle[i].map));
1518                         cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
1519                         cl_lightstyle[i].length = (int)strlen(cl_lightstyle[i].map);
1520                         break;
1521
1522                 case svc_sound:
1523                         CL_ParseStartSoundPacket(false);
1524                         break;
1525
1526                 case svc_precache:
1527                         if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1528                         {
1529                                 // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
1530                                 CL_ParseStartSoundPacket(true);
1531                         }
1532                         else
1533                         {
1534                                 int i = (unsigned short)MSG_ReadShort();
1535                                 char *s = MSG_ReadString();
1536                                 if (i < 32768)
1537                                 {
1538                                         if (i >= 1 && i < MAX_MODELS)
1539                                         {
1540                                                 model_t *model = Mod_ForName(s, false, false, i == 1);
1541                                                 if (!model)
1542                                                         Con_Printf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
1543                                                 cl.model_precache[i] = model;
1544                                         }
1545                                         else
1546                                                 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
1547                                 }
1548                                 else
1549                                 {
1550                                         i -= 32768;
1551                                         if (i >= 1 && i < MAX_SOUNDS)
1552                                         {
1553                                                 sfx_t *sfx = S_PrecacheSound (s, true, false);
1554                                                 if (!sfx && snd_initialized.integer)
1555                                                         Con_Printf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
1556                                                 cl.sound_precache[i] = sfx;
1557                                         }
1558                                         else
1559                                                 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
1560                                 }
1561                         }
1562                         break;
1563
1564                 case svc_stopsound:
1565                         i = (unsigned short) MSG_ReadShort();
1566                         S_StopSound(i>>3, i&7);
1567                         break;
1568
1569                 case svc_updatename:
1570                         i = MSG_ReadByte ();
1571                         if (i >= cl.maxclients)
1572                                 Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
1573                         strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
1574                         break;
1575
1576                 case svc_updatefrags:
1577                         i = MSG_ReadByte ();
1578                         if (i >= cl.maxclients)
1579                                 Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
1580                         cl.scores[i].frags = (signed short) MSG_ReadShort ();
1581                         break;
1582
1583                 case svc_updatecolors:
1584                         i = MSG_ReadByte ();
1585                         if (i >= cl.maxclients)
1586                                 Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
1587                         cl.scores[i].colors = MSG_ReadByte ();
1588                         break;
1589
1590                 case svc_particle:
1591                         CL_ParseParticleEffect ();
1592                         break;
1593
1594                 case svc_effect:
1595                         CL_ParseEffect ();
1596                         break;
1597
1598                 case svc_effect2:
1599                         CL_ParseEffect2 ();
1600                         break;
1601
1602                 case svc_spawnbaseline:
1603                         i = (unsigned short) MSG_ReadShort ();
1604                         if (i < 0 || i >= MAX_EDICTS)
1605                                 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
1606                         if (i >= cl_max_entities)
1607                                 CL_ExpandEntities(i);
1608                         CL_ParseBaseline (cl_entities + i, false);
1609                         break;
1610                 case svc_spawnbaseline2:
1611                         i = (unsigned short) MSG_ReadShort ();
1612                         if (i < 0 || i >= MAX_EDICTS)
1613                                 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
1614                         if (i >= cl_max_entities)
1615                                 CL_ExpandEntities(i);
1616                         CL_ParseBaseline (cl_entities + i, true);
1617                         break;
1618                 case svc_spawnstatic:
1619                         CL_ParseStatic (false);
1620                         break;
1621                 case svc_spawnstatic2:
1622                         CL_ParseStatic (true);
1623                         break;
1624                 case svc_temp_entity:
1625                         CL_ParseTempEntity ();
1626                         break;
1627
1628                 case svc_setpause:
1629                         cl.paused = MSG_ReadByte ();
1630                         if (cl.paused)
1631                                 CDAudio_Pause ();
1632                         else
1633                                 CDAudio_Resume ();
1634                         S_PauseGameSounds (cl.paused);
1635                         break;
1636
1637                 case svc_signonnum:
1638                         i = MSG_ReadByte ();
1639                         // LordHavoc: it's rude to kick off the client if they missed the
1640                         // reconnect somehow, so allow signon 1 even if at signon 1
1641                         if (i <= cls.signon && i != 1)
1642                                 Host_Error ("Received signon %i when at %i", i, cls.signon);
1643                         cls.signon = i;
1644                         CL_SignonReply ();
1645                         break;
1646
1647                 case svc_killedmonster:
1648                         cl.stats[STAT_MONSTERS]++;
1649                         break;
1650
1651                 case svc_foundsecret:
1652                         cl.stats[STAT_SECRETS]++;
1653                         break;
1654
1655                 case svc_updatestat:
1656                         i = MSG_ReadByte ();
1657                         if (i < 0 || i >= MAX_CL_STATS)
1658                                 Host_Error ("svc_updatestat: %i is invalid", i);
1659                         cl.stats[i] = MSG_ReadLong ();
1660                         break;
1661
1662                 case svc_updatestatubyte:
1663                         i = MSG_ReadByte ();
1664                         if (i < 0 || i >= MAX_CL_STATS)
1665                                 Host_Error ("svc_updatestat: %i is invalid", i);
1666                         cl.stats[i] = MSG_ReadByte ();
1667                         break;
1668
1669                 case svc_spawnstaticsound:
1670                         CL_ParseStaticSound (false);
1671                         break;
1672
1673                 case svc_spawnstaticsound2:
1674                         CL_ParseStaticSound (true);
1675                         break;
1676
1677                 case svc_cdtrack:
1678                         cl.cdtrack = MSG_ReadByte ();
1679                         cl.looptrack = MSG_ReadByte ();
1680                         if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
1681                                 CDAudio_Play ((unsigned char)cls.forcetrack, true);
1682                         else
1683                                 CDAudio_Play ((unsigned char)cl.cdtrack, true);
1684                         break;
1685
1686                 case svc_intermission:
1687                         cl.intermission = 1;
1688                         cl.completed_time = cl.time;
1689                         break;
1690
1691                 case svc_finale:
1692                         cl.intermission = 2;
1693                         cl.completed_time = cl.time;
1694                         SCR_CenterPrint(MSG_ReadString ());
1695                         break;
1696
1697                 case svc_cutscene:
1698                         cl.intermission = 3;
1699                         cl.completed_time = cl.time;
1700                         SCR_CenterPrint(MSG_ReadString ());
1701                         break;
1702
1703                 case svc_sellscreen:
1704                         Cmd_ExecuteString ("help", src_command);
1705                         break;
1706                 case svc_hidelmp:
1707                         if (gamemode == GAME_TENEBRAE)
1708                         {
1709                                 // repeating particle effect
1710                                 MSG_ReadCoord(cl.protocol);
1711                                 MSG_ReadCoord(cl.protocol);
1712                                 MSG_ReadCoord(cl.protocol);
1713                                 MSG_ReadCoord(cl.protocol);
1714                                 MSG_ReadCoord(cl.protocol);
1715                                 MSG_ReadCoord(cl.protocol);
1716                                 MSG_ReadByte();
1717                                 MSG_ReadLong();
1718                                 MSG_ReadLong();
1719                                 MSG_ReadString();
1720                         }
1721                         else
1722                                 SHOWLMP_decodehide();
1723                         break;
1724                 case svc_showlmp:
1725                         if (gamemode == GAME_TENEBRAE)
1726                         {
1727                                 // particle effect
1728                                 MSG_ReadCoord(cl.protocol);
1729                                 MSG_ReadCoord(cl.protocol);
1730                                 MSG_ReadCoord(cl.protocol);
1731                                 MSG_ReadByte();
1732                                 MSG_ReadString();
1733                         }
1734                         else
1735                                 SHOWLMP_decodeshow();
1736                         break;
1737                 case svc_skybox:
1738                         R_SetSkyBox(MSG_ReadString());
1739                         break;
1740                 case svc_cgame:
1741                         {
1742                                 int length;
1743                                 length = (int) ((unsigned short) MSG_ReadShort());
1744                                 for (i = 0;i < length;i++)
1745                                         cgamenetbuffer[i] = MSG_ReadByte();
1746                                 if (!msg_badread)
1747                                         CL_CGVM_ParseNetwork(cgamenetbuffer, length);
1748                         }
1749                         break;
1750                 case svc_entities:
1751                         if (cls.signon == SIGNONS - 1)
1752                         {
1753                                 // first update is the final signon stage
1754                                 cls.signon = SIGNONS;
1755                                 CL_SignonReply ();
1756                         }
1757                         if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1758                                 EntityFrame_CL_ReadFrame();
1759                         else if (cl.protocol == PROTOCOL_DARKPLACES4)
1760                                 EntityFrame4_CL_ReadFrame();
1761                         else
1762                                 EntityFrame5_CL_ReadFrame();
1763                         break;
1764                 }
1765         }
1766
1767         EntityFrameQuake_ISeeDeadEntities();
1768
1769         if (sendmove)
1770         {
1771                 // send one move per server frame
1772                 CL_SendMove();
1773         }
1774
1775         parsingerror = false;
1776 }
1777
1778 void CL_Parse_DumpPacket(void)
1779 {
1780         if (!parsingerror)
1781                 return;
1782         Con_Print("Packet dump:\n");
1783         SZ_HexDumpToConsole(&net_message);
1784         parsingerror = false;
1785 }
1786
1787 void CL_Parse_Init(void)
1788 {
1789         // LordHavoc: added demo_nehahra cvar
1790         Cvar_RegisterVariable (&demo_nehahra);
1791         if (gamemode == GAME_NEHAHRA)
1792                 Cvar_SetValue("demo_nehahra", 1);
1793         Cvar_RegisterVariable(&developer_networkentities);
1794 }
1795
1796 void CL_Parse_Shutdown(void)
1797 {
1798 }