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