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