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