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