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