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