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