2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // cl_parse.c -- parse a message received from the server
24 #include "cl_collision.h"
26 char *svc_strings[128] =
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
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
55 "OBSOLETE svc_spawnbinary",
58 "svc_temp_entity", // <variable>
64 "svc_spawnstaticsound",
66 "svc_finale", // [string] music [string] text
67 "svc_cdtrack", // [byte] track [byte] looptrack
70 "svc_showlmp", // [string] iconlabel [string] lmpfile [short] x [short] y
71 "svc_hidelmp", // [string] iconlabel
72 "svc_skybox", // [string] skyname
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
97 //=============================================================================
99 cvar_t demo_nehahra = {0, "demo_nehahra", "0"};
100 cvar_t developer_networkentities = {0, "developer_networkentities", "0"};
102 mempool_t *cl_scores_mempool;
106 CL_ParseStartSoundPacket
109 void CL_ParseStartSoundPacket(int largesoundindex)
118 field_mask = MSG_ReadByte();
120 if (field_mask & SND_VOLUME)
121 volume = MSG_ReadByte ();
123 volume = DEFAULT_SOUND_PACKET_VOLUME;
125 if (field_mask & SND_ATTENUATION)
126 attenuation = MSG_ReadByte () / 64.0;
128 attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
130 if (field_mask & SND_LARGEENTITY)
132 ent = (unsigned short) MSG_ReadShort ();
133 channel = MSG_ReadByte ();
137 channel = (unsigned short) MSG_ReadShort ();
142 if (largesoundindex || field_mask & SND_LARGESOUND)
143 sound_num = (unsigned short) MSG_ReadShort ();
145 sound_num = MSG_ReadByte ();
147 MSG_ReadVector(pos, cl.protocol);
149 if (sound_num >= MAX_SOUNDS)
151 Con_Printf("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
155 if (ent >= MAX_EDICTS)
157 Con_Printf("CL_ParseStartSoundPacket: ent = %i", ent);
161 S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation);
168 When the client is taking a long time to load stuff, send keepalive messages
169 so the server doesn't disconnect.
173 static qbyte olddata[NET_MAXMESSAGE];
174 void CL_KeepaliveMessage (void)
177 static float lastmsg;
182 // no need if server is local and definitely not if this is a demo
183 if (sv.active || cls.demoplayback)
186 // read messages from server, should just be nops
187 oldreadcount = msg_readcount;
188 oldbadread = msg_badread;
190 memcpy(olddata, net_message.data, net_message.cursize);
192 NetConn_ClientFrame();
194 msg_readcount = oldreadcount;
195 msg_badread = oldbadread;
197 memcpy(net_message.data, olddata, net_message.cursize);
199 if (cls.netcon && NetConn_CanSendMessage(cls.netcon) && (time = Sys_DoubleTime()) - lastmsg >= 5)
205 // LordHavoc: must use unreliable because reliable could kill the sigon message!
206 Con_Print("--> client to server keepalive\n");
208 msg.maxsize = sizeof(buf);
210 MSG_WriteChar(&msg, svc_nop);
211 NetConn_SendUnreliableMessage(cls.netcon, &msg);
215 void CL_ParseEntityLump(char *entdata)
218 char key[128], value[4096];
219 FOG_clear(); // LordHavoc: no fog until set
220 // LordHavoc: default to the map's sky (q3 shader parsing sets this)
221 R_SetSkyBox(cl.worldmodel->brush.skybox);
225 if (!COM_ParseToken(&data, false))
227 if (com_token[0] != '{')
231 if (!COM_ParseToken(&data, false))
233 if (com_token[0] == '}')
234 break; // end of worldspawn
235 if (com_token[0] == '_')
236 strlcpy (key, com_token + 1, sizeof (key));
238 strlcpy (key, com_token, sizeof (key));
239 while (key[strlen(key)-1] == ' ') // remove trailing spaces
240 key[strlen(key)-1] = 0;
241 if (!COM_ParseToken(&data, false))
243 strlcpy (value, com_token, sizeof (value));
244 if (!strcmp("sky", key))
246 else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
248 else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
250 else if (!strcmp("fog", key))
251 sscanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue);
252 else if (!strcmp("fog_density", key))
253 fog_density = atof(value);
254 else if (!strcmp("fog_red", key))
255 fog_red = atof(value);
256 else if (!strcmp("fog_green", key))
257 fog_green = atof(value);
258 else if (!strcmp("fog_blue", key))
259 fog_blue = atof(value);
264 =====================
267 An svc_signonnum has been received, perform a client side setup
268 =====================
270 static void CL_SignonReply (void)
274 Con_DPrintf("CL_SignonReply: %i\n", cls.signon);
279 MSG_WriteByte (&cls.message, clc_stringcmd);
280 MSG_WriteString (&cls.message, "prespawn");
284 MSG_WriteByte (&cls.message, clc_stringcmd);
285 MSG_WriteString (&cls.message, va("name \"%s\"\n", cl_name.string));
287 MSG_WriteByte (&cls.message, clc_stringcmd);
288 MSG_WriteString (&cls.message, va("color %i %i\n", cl_color.integer >> 4, cl_color.integer & 15));
290 if (cl_pmodel.integer)
292 MSG_WriteByte (&cls.message, clc_stringcmd);
293 MSG_WriteString (&cls.message, va("pmodel %i\n", cl_pmodel.integer));
295 if (*cl_playermodel.string)
297 MSG_WriteByte (&cls.message, clc_stringcmd);
298 MSG_WriteString (&cls.message, va("playermodel %s\n", cl_playermodel.string));
300 if (*cl_playerskin.string)
302 MSG_WriteByte (&cls.message, clc_stringcmd);
303 MSG_WriteString (&cls.message, va("playerskin %s\n", cl_playerskin.string));
306 MSG_WriteByte (&cls.message, clc_stringcmd);
307 MSG_WriteString (&cls.message, va("rate %i\n", cl_rate.integer));
309 MSG_WriteByte (&cls.message, clc_stringcmd);
310 MSG_WriteString (&cls.message, "spawn");
314 MSG_WriteByte (&cls.message, clc_stringcmd);
315 MSG_WriteString (&cls.message, "begin");
329 // FIXME: this is a lot of memory to be keeping around, this needs to be dynamically allocated and freed
330 static char parse_model_precache[MAX_MODELS][MAX_QPATH];
331 static char parse_sound_precache[MAX_SOUNDS][MAX_QPATH];
332 void CL_ParseServerInfo (void)
336 int nummodels, numsounds;
339 Con_DPrint("Serverinfo packet received.\n");
341 // wipe the client_state_t struct
345 // parse protocol version number
347 // hack for unmarked Nehahra movie demos which had a custom protocol
348 if (i == PROTOCOL_QUAKE && cls.demoplayback && demo_nehahra.integer)
349 i = PROTOCOL_NEHAHRAMOVIE;
350 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)
352 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);
356 Con_DPrintf("Server protocol is %i\n", cl.protocol);
359 cl.maxclients = MSG_ReadByte ();
360 if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
362 Host_Error("Bad maxclients (%u) from server\n", cl.maxclients);
365 Mem_EmptyPool(cl_scores_mempool);
366 cl.scores = Mem_Alloc(cl_scores_mempool, cl.maxclients*sizeof(*cl.scores));
369 cl.gametype = MSG_ReadByte ();
371 // parse signon message
372 str = MSG_ReadString ();
373 strlcpy (cl.levelname, str, sizeof(cl.levelname));
375 // seperate the printfs so the server message can have a color
376 if (cl.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
377 Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n\2%s\n", str);
379 // check memory integrity
380 Mem_CheckSentinelsGlobal();
383 // if server is active, we already began a loading plaque
385 SCR_BeginLoadingPlaque();
387 // disable until we get textures for it
390 memset(cl.model_precache, 0, sizeof(cl.model_precache));
391 memset(cl.sound_precache, 0, sizeof(cl.sound_precache));
393 // parse model precache list
394 for (nummodels=1 ; ; nummodels++)
396 str = MSG_ReadString();
399 if (nummodels==MAX_MODELS)
400 Host_Error ("Server sent too many model precaches\n");
401 if (strlen(str) >= MAX_QPATH)
402 Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
403 strlcpy (parse_model_precache[nummodels], str, sizeof (parse_model_precache[nummodels]));
405 // parse sound precache list
406 for (numsounds=1 ; ; numsounds++)
408 str = MSG_ReadString();
411 if (numsounds==MAX_SOUNDS)
412 Host_Error("Server sent too many sound precaches\n");
413 if (strlen(str) >= MAX_QPATH)
414 Host_Error("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
415 strlcpy (parse_sound_precache[numsounds], str, sizeof (parse_sound_precache[numsounds]));
418 // touch all of the precached models that are still loaded so we can free
419 // anything that isn't needed
421 for (i = 1;i < nummodels;i++)
422 Mod_FindName(parse_model_precache[i]);
425 // do the same for sounds
426 S_ServerSounds (parse_sound_precache, numsounds);
428 // now we try to load everything that is new
431 CL_KeepaliveMessage ();
432 cl.model_precache[1] = Mod_ForName(parse_model_precache[1], false, false, true);
433 if (cl.model_precache[1] == NULL)
434 Con_Printf("Map %s not found\n", parse_model_precache[1]);
437 for (i=2 ; i<nummodels ; i++)
439 CL_KeepaliveMessage();
440 if ((cl.model_precache[i] = Mod_ForName(parse_model_precache[i], false, false, false)) == NULL)
441 Con_Printf("Model %s not found\n", parse_model_precache[i]);
445 for (i=1 ; i<numsounds ; i++)
447 CL_KeepaliveMessage();
449 // Don't lock the sfx here, S_ServerSounds already did that
450 cl.sound_precache[i] = S_PrecacheSound (parse_sound_precache[i], true, false);
454 ent = &cl_entities[0];
455 // entire entity array was cleared, so just fill in a few fields
456 ent->state_current.active = true;
457 ent->render.model = cl.worldmodel = cl.model_precache[1];
458 ent->render.scale = 1; // some of the renderer still relies on scale
459 ent->render.alpha = 1;
460 ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
461 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
462 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
463 CL_BoundingBoxForEntity(&ent->render);
470 // noclip is turned off at start
471 noclip_anglehack = false;
473 // check memory integrity
474 Mem_CheckSentinelsGlobal();
477 void CL_ValidateState(entity_state_t *s)
484 if (s->modelindex >= MAX_MODELS)
485 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
487 // colormap is client index + 1
488 if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
490 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
494 model = cl.model_precache[s->modelindex];
495 Mod_CheckLoaded(model);
496 if (model && model->type && s->frame >= model->numframes)
498 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
501 if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
503 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
508 void CL_MoveLerpEntityStates(entity_t *ent)
510 float odelta[3], adelta[3];
511 CL_ValidateState(&ent->state_current);
512 VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
513 VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
514 if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
516 // reset all persistent stuff if this is a new entity
517 ent->persistent.lerpdeltatime = 0;
518 ent->persistent.lerpstarttime = cl.mtime[1];
519 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
520 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
521 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
522 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
523 // reset animation interpolation as well
524 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
525 ent->render.frame1time = ent->render.frame2time = cl.time;
526 ent->render.framelerp = 1;
527 // reset various persistent stuff
528 ent->persistent.muzzleflash = 0;
529 VectorCopy(ent->state_current.origin, ent->persistent.trail_origin);
531 else if (cls.timedemo || cl_nolerp.integer || DotProduct(odelta, odelta) > 1000*1000)
533 // don't interpolate the move
534 ent->persistent.lerpdeltatime = 0;
535 ent->persistent.lerpstarttime = cl.mtime[1];
536 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
537 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
538 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
539 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
541 else if (ent->state_current.flags & RENDER_STEP)
543 // monster interpolation
544 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
546 ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
547 ent->persistent.lerpstarttime = cl.mtime[1];
548 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
549 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
550 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
551 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
557 ent->persistent.lerpstarttime = ent->state_previous.time;
558 // no lerp if it's singleplayer
560 ent->persistent.lerpdeltatime = 0;
562 ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
563 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
564 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
565 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
566 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
575 void CL_ParseBaseline (entity_t *ent, int large)
579 ent->state_baseline = defaultstate;
580 // FIXME: set ent->state_baseline.number?
581 ent->state_baseline.active = true;
584 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
585 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
589 ent->state_baseline.modelindex = MSG_ReadByte ();
590 ent->state_baseline.frame = MSG_ReadByte ();
592 ent->state_baseline.colormap = MSG_ReadByte();
593 ent->state_baseline.skin = MSG_ReadByte();
594 for (i = 0;i < 3;i++)
596 ent->state_baseline.origin[i] = MSG_ReadCoord(cl.protocol);
597 ent->state_baseline.angles[i] = MSG_ReadAngle(cl.protocol);
599 CL_ValidateState(&ent->state_baseline);
600 ent->state_previous = ent->state_current = ent->state_baseline;
608 Server information pertaining to this client only
611 void CL_ParseClientdata (int bits)
615 VectorCopy (cl.mpunchangle[0], cl.mpunchangle[1]);
616 VectorCopy (cl.mpunchvector[0], cl.mpunchvector[1]);
617 VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
618 cl.mviewzoom[1] = cl.mviewzoom[0];
620 if (cl.protocol != PROTOCOL_DARKPLACES6)
622 cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
623 cl.stats[STAT_ITEMS] = 0;
624 cl.stats[STAT_VIEWZOOM] = 255;
627 cl.mpunchangle[0][0] = 0;
628 cl.mpunchangle[0][1] = 0;
629 cl.mpunchangle[0][2] = 0;
630 cl.mpunchvector[0][0] = 0;
631 cl.mpunchvector[0][1] = 0;
632 cl.mpunchvector[0][2] = 0;
633 cl.mvelocity[0][0] = 0;
634 cl.mvelocity[0][1] = 0;
635 cl.mvelocity[0][2] = 0;
639 if (bits & SU_EXTEND1)
640 bits |= (MSG_ReadByte() << 16);
641 if (bits & SU_EXTEND2)
642 bits |= (MSG_ReadByte() << 24);
644 if (bits & SU_VIEWHEIGHT)
645 cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
647 if (bits & SU_IDEALPITCH)
648 cl.idealpitch = MSG_ReadChar ();
650 for (i = 0;i < 3;i++)
652 if (bits & (SU_PUNCH1<<i) )
654 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)
655 cl.mpunchangle[0][i] = MSG_ReadAngle16i();
656 else if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_NEHAHRAMOVIE)
657 cl.mpunchangle[0][i] = MSG_ReadChar();
659 Host_Error("CL_ParseClientData: unknown cl.protocol %i\n", cl.protocol);
661 if (bits & (SU_PUNCHVEC1<<i))
663 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
664 cl.mpunchvector[0][i] = MSG_ReadCoord16i();
665 else if (cl.protocol == PROTOCOL_DARKPLACES5 || cl.protocol == PROTOCOL_DARKPLACES6)
666 cl.mpunchvector[0][i] = MSG_ReadCoord32f();
668 Host_Error("CL_ParseClientData: unknown cl.protocol %i\n", cl.protocol);
670 if (bits & (SU_VELOCITY1<<i) )
672 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)
673 cl.mvelocity[0][i] = MSG_ReadChar()*16;
674 else if (cl.protocol == PROTOCOL_DARKPLACES5 || cl.protocol == PROTOCOL_DARKPLACES6)
675 cl.mvelocity[0][i] = MSG_ReadCoord32f();
677 Host_Error("CL_ParseClientData: unknown cl.protocol %i\n", cl.protocol);
682 cl.stats[STAT_ITEMS] = MSG_ReadLong ();
684 cl.onground = (bits & SU_ONGROUND) != 0;
685 cl.inwater = (bits & SU_INWATER) != 0;
687 if (cl.protocol == PROTOCOL_DARKPLACES6)
690 else if (cl.protocol == PROTOCOL_DARKPLACES5)
692 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
693 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
694 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
695 cl.stats[STAT_HEALTH] = MSG_ReadShort();
696 cl.stats[STAT_AMMO] = MSG_ReadShort();
697 cl.stats[STAT_SHELLS] = MSG_ReadShort();
698 cl.stats[STAT_NAILS] = MSG_ReadShort();
699 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
700 cl.stats[STAT_CELLS] = MSG_ReadShort();
701 cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
705 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
706 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
707 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
708 cl.stats[STAT_HEALTH] = MSG_ReadShort();
709 cl.stats[STAT_AMMO] = MSG_ReadByte();
710 cl.stats[STAT_SHELLS] = MSG_ReadByte();
711 cl.stats[STAT_NAILS] = MSG_ReadByte();
712 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
713 cl.stats[STAT_CELLS] = MSG_ReadByte();
714 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
715 cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
717 cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
720 if (bits & SU_VIEWZOOM)
722 if (cl.protocol == PROTOCOL_DARKPLACES5 || cl.protocol == PROTOCOL_DARKPLACES6)
723 cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
725 cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
728 // check for important changes
731 if (cl.olditems != cl.stats[STAT_ITEMS])
732 for (j = 0;j < 32;j++)
733 if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
734 cl.item_gettime[j] = cl.time;
735 cl.olditems = cl.stats[STAT_ITEMS];
737 // GAME_NEXUIZ hud needs weapon change time
738 if (cl.activeweapon != cl.stats[STAT_ACTIVEWEAPON])
739 cl.weapontime = cl.time;
740 cl.activeweapon = cl.stats[STAT_ACTIVEWEAPON];
742 // viewzoom interpolation
743 cl.mviewzoom[0] = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
747 =====================
749 =====================
751 void CL_ParseStatic (int large)
755 if (cl_num_static_entities >= cl_max_static_entities)
756 Host_Error ("Too many static entities");
757 ent = &cl_static_entities[cl_num_static_entities++];
758 CL_ParseBaseline (ent, large);
760 // copy it to the current state
761 ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
762 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
763 ent->render.framelerp = 0;
764 // make torchs play out of sync
765 ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
766 ent->render.colormap = -1; // no special coloring
767 ent->render.skinnum = ent->state_baseline.skin;
768 ent->render.effects = ent->state_baseline.effects;
769 ent->render.alpha = 1;
770 //ent->render.scale = 1;
772 //VectorCopy (ent->state_baseline.origin, ent->render.origin);
773 //VectorCopy (ent->state_baseline.angles, ent->render.angles);
775 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);
776 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
777 CL_BoundingBoxForEntity(&ent->render);
779 // This is definitely cheating...
780 if (ent->render.model == NULL)
781 cl_num_static_entities--;
789 void CL_ParseStaticSound (int large)
792 int sound_num, vol, atten;
794 MSG_ReadVector(org, cl.protocol);
796 sound_num = (unsigned short) MSG_ReadShort ();
798 sound_num = MSG_ReadByte ();
799 vol = MSG_ReadByte ();
800 atten = MSG_ReadByte ();
802 S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
805 void CL_ParseEffect (void)
808 int modelindex, startframe, framecount, framerate;
810 MSG_ReadVector(org, cl.protocol);
811 modelindex = MSG_ReadByte ();
812 startframe = MSG_ReadByte ();
813 framecount = MSG_ReadByte ();
814 framerate = MSG_ReadByte ();
816 CL_Effect(org, modelindex, startframe, framecount, framerate);
819 void CL_ParseEffect2 (void)
822 int modelindex, startframe, framecount, framerate;
824 MSG_ReadVector(org, cl.protocol);
825 modelindex = (unsigned short) MSG_ReadShort ();
826 startframe = (unsigned short) MSG_ReadShort ();
827 framecount = MSG_ReadByte ();
828 framerate = MSG_ReadByte ();
830 CL_Effect(org, modelindex, startframe, framecount, framerate);
833 model_t *cl_model_bolt = NULL;
834 model_t *cl_model_bolt2 = NULL;
835 model_t *cl_model_bolt3 = NULL;
836 model_t *cl_model_beam = NULL;
838 sfx_t *cl_sfx_wizhit;
839 sfx_t *cl_sfx_knighthit;
844 sfx_t *cl_sfx_r_exp3;
851 void CL_InitTEnts (void)
853 cl_sfx_wizhit = S_PrecacheSound ("sound/wizard/hit.wav", false, true);
854 cl_sfx_knighthit = S_PrecacheSound ("sound/hknight/hit.wav", false, true);
855 cl_sfx_tink1 = S_PrecacheSound ("sound/weapons/tink1.wav", false, true);
856 cl_sfx_ric1 = S_PrecacheSound ("sound/weapons/ric1.wav", false, true);
857 cl_sfx_ric2 = S_PrecacheSound ("sound/weapons/ric2.wav", false, true);
858 cl_sfx_ric3 = S_PrecacheSound ("sound/weapons/ric3.wav", false, true);
859 cl_sfx_r_exp3 = S_PrecacheSound ("sound/weapons/r_exp3.wav", false, true);
862 void CL_ParseBeam (model_t *m, int lightning)
868 ent = (unsigned short) MSG_ReadShort ();
869 MSG_ReadVector(start, cl.protocol);
870 MSG_ReadVector(end, cl.protocol);
872 if (ent >= MAX_EDICTS)
874 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
878 if (ent >= cl_max_entities)
879 CL_ExpandEntities(ent);
881 // override any beam with the same entity
882 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
884 if (b->entity == ent)
887 b->lightning = lightning;
888 b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
890 b->endtime = cl.time + 0.2;
891 VectorCopy (start, b->start);
892 VectorCopy (end, b->end);
898 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
900 if (!b->model || b->endtime < cl.time)
903 b->lightning = lightning;
904 b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
906 b->endtime = cl.time + 0.2;
907 VectorCopy (start, b->start);
908 VectorCopy (end, b->end);
912 Con_Print("beam list overflow!\n");
915 void CL_ParseTempEntity(void)
923 int colorStart, colorLength, count;
924 float velspeed, radius;
926 matrix4x4_t tempmatrix;
928 type = MSG_ReadByte();
932 // spike hitting wall
933 MSG_ReadVector(pos, cl.protocol);
934 CL_FindNonSolidLocation(pos, pos, 4);
935 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
936 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);
937 CL_RunParticleEffect(pos, vec3_origin, 20, 30);
938 S_StartSound(-1, 0, cl_sfx_wizhit, pos, 1, 1);
942 // spike hitting wall
943 MSG_ReadVector(pos, cl.protocol);
944 CL_FindNonSolidLocation(pos, pos, 4);
945 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
946 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);
947 CL_RunParticleEffect(pos, vec3_origin, 226, 20);
948 S_StartSound(-1, 0, cl_sfx_knighthit, pos, 1, 1);
952 // spike hitting wall
953 MSG_ReadVector(pos, cl.protocol);
954 CL_FindNonSolidLocation(pos, pos, 4);
955 if (cl_particles_bulletimpacts.integer)
957 CL_SparkShower(pos, vec3_origin, 15, 1);
958 CL_Smoke(pos, vec3_origin, 15);
962 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
967 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
969 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
971 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
975 // quad spike hitting wall
976 MSG_ReadVector(pos, cl.protocol);
977 CL_FindNonSolidLocation(pos, pos, 4);
978 // LordHavoc: changed to spark shower
979 if (cl_particles_bulletimpacts.integer)
981 CL_SparkShower(pos, vec3_origin, 15, 1);
982 CL_Smoke(pos, vec3_origin, 15);
985 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
986 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);
987 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
989 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
994 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
996 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
998 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
1002 // super spike hitting wall
1003 MSG_ReadVector(pos, cl.protocol);
1004 CL_FindNonSolidLocation(pos, pos, 4);
1005 // LordHavoc: changed to dust shower
1006 if (cl_particles_bulletimpacts.integer)
1008 CL_SparkShower(pos, vec3_origin, 30, 1);
1009 CL_Smoke(pos, vec3_origin, 30);
1013 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
1018 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
1020 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
1022 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
1025 case TE_SUPERSPIKEQUAD:
1026 // quad super spike hitting wall
1027 MSG_ReadVector(pos, cl.protocol);
1028 CL_FindNonSolidLocation(pos, pos, 4);
1029 // LordHavoc: changed to dust shower
1030 if (cl_particles_bulletimpacts.integer)
1032 CL_SparkShower(pos, vec3_origin, 30, 1);
1033 CL_Smoke(pos, vec3_origin, 30);
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);
1039 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
1044 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
1046 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
1048 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
1051 // LordHavoc: added for improved blood splatters
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);
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);
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);
1079 // LordHavoc: added for improved gore
1080 case TE_BLOODSHOWER:
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);
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);
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);
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);
1121 // bullet hitting wall
1122 MSG_ReadVector(pos, cl.protocol);
1123 CL_FindNonSolidLocation(pos, pos, 4);
1124 CL_SparkShower(pos, vec3_origin, 15, 1);
1125 CL_Smoke(pos, vec3_origin, 15);
1129 case TE_GUNSHOTQUAD:
1130 // quad bullet hitting wall
1131 MSG_ReadVector(pos, cl.protocol);
1132 CL_FindNonSolidLocation(pos, pos, 4);
1133 CL_SparkShower(pos, vec3_origin, 15, 1);
1134 CL_Smoke(pos, vec3_origin, 15);
1136 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1137 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);
1142 MSG_ReadVector(pos, cl.protocol);
1143 CL_FindNonSolidLocation(pos, pos, 10);
1144 CL_ParticleExplosion(pos);
1145 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
1146 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1147 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);
1148 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1151 case TE_EXPLOSIONQUAD:
1152 // quad rocket explosion
1153 MSG_ReadVector(pos, cl.protocol);
1154 CL_FindNonSolidLocation(pos, pos, 10);
1155 CL_ParticleExplosion(pos);
1156 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1157 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);
1158 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1162 // Nehahra movie colored lighting explosion
1163 MSG_ReadVector(pos, cl.protocol);
1164 CL_FindNonSolidLocation(pos, pos, 10);
1165 CL_ParticleExplosion(pos);
1166 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1167 color[0] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1168 color[1] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1169 color[2] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1170 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);
1171 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1174 case TE_EXPLOSIONRGB:
1175 // colored lighting explosion
1176 MSG_ReadVector(pos, cl.protocol);
1177 CL_FindNonSolidLocation(pos, pos, 10);
1178 CL_ParticleExplosion(pos);
1179 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1180 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1181 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1182 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1183 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);
1184 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1187 case TE_TAREXPLOSION:
1188 // tarbaby explosion
1189 MSG_ReadVector(pos, cl.protocol);
1190 CL_FindNonSolidLocation(pos, pos, 10);
1191 CL_BlobExplosion(pos);
1193 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1194 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1195 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1196 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);
1200 MSG_ReadVector(pos, cl.protocol);
1201 CL_FindNonSolidLocation(pos, pos, 10);
1202 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1203 CL_AllocDlight(NULL, &tempmatrix, 200, 2, 2, 2, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1206 case TE_CUSTOMFLASH:
1207 MSG_ReadVector(pos, cl.protocol);
1208 CL_FindNonSolidLocation(pos, pos, 4);
1209 radius = MSG_ReadByte() * 8;
1210 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
1211 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1212 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1213 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1214 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1215 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);
1219 MSG_ReadVector(pos, cl.protocol);
1220 MSG_ReadVector(dir, cl.protocol);
1221 count = MSG_ReadByte();
1222 CL_Flames(pos, dir, count);
1228 cl_model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
1229 CL_ParseBeam(cl_model_bolt, true);
1234 if (!cl_model_bolt2)
1235 cl_model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
1236 CL_ParseBeam(cl_model_bolt2, true);
1241 if (!cl_model_bolt3)
1242 cl_model_bolt3 = Mod_ForName("progs/bolt3.mdl", true, false, false);
1243 CL_ParseBeam(cl_model_bolt3, false);
1248 // grappling hook beam
1250 cl_model_beam = Mod_ForName("progs/beam.mdl", true, false, false);
1251 CL_ParseBeam(cl_model_beam, false);
1255 // LordHavoc: for compatibility with the Nehahra movie...
1256 case TE_LIGHTNING4NEH:
1257 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
1261 MSG_ReadVector(pos, cl.protocol);
1266 MSG_ReadVector(pos, cl.protocol);
1267 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1268 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);
1269 CL_TeleportSplash(pos);
1273 // color mapped explosion
1274 MSG_ReadVector(pos, cl.protocol);
1275 CL_FindNonSolidLocation(pos, pos, 10);
1276 colorStart = MSG_ReadByte();
1277 colorLength = MSG_ReadByte();
1278 CL_ParticleExplosion2(pos, colorStart, colorLength);
1279 tempcolor = (qbyte *)&palette_complete[(rand()%colorLength) + colorStart];
1280 color[0] = tempcolor[0] * (2.0f / 255.0f);
1281 color[1] = tempcolor[1] * (2.0f / 255.0f);
1282 color[2] = tempcolor[2] * (2.0f / 255.0f);
1283 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1284 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);
1285 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1289 MSG_ReadVector(pos, cl.protocol);
1290 MSG_ReadVector(pos2, cl.protocol);
1291 MSG_ReadVector(dir, cl.protocol);
1292 CL_BeamParticle(pos, pos2, 8, 1, 1, 1, 1, 1);
1296 MSG_ReadVector(pos, cl.protocol);
1297 MSG_ReadVector(dir, cl.protocol);
1298 count = MSG_ReadByte();
1299 CL_FindNonSolidLocation(pos, pos, 4);
1300 CL_Tei_Smoke(pos, dir, count);
1303 case TE_TEI_BIGEXPLOSION:
1304 MSG_ReadVector(pos, cl.protocol);
1305 CL_FindNonSolidLocation(pos, pos, 10);
1306 CL_ParticleExplosion(pos);
1307 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1308 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);
1309 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1312 case TE_TEI_PLASMAHIT:
1313 MSG_ReadVector(pos, cl.protocol);
1314 MSG_ReadVector(dir, cl.protocol);
1315 count = MSG_ReadByte();
1316 CL_FindNonSolidLocation(pos, pos, 5);
1317 CL_Tei_PlasmaHit(pos, dir, count);
1318 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1319 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);
1323 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
1327 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
1329 static qbyte cgamenetbuffer[65536];
1332 =====================
1333 CL_ParseServerMessage
1334 =====================
1336 int parsingerror = false;
1337 void CL_ParseServerMessage(void)
1342 char *cmdlogname[32], *temp;
1343 int cmdindex, cmdcount = 0;
1345 if (cls.demorecording)
1346 CL_WriteDemoMessage ();
1348 cl.last_received_message = realtime;
1351 // if recording demos, copy the message out
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");
1358 cl.onground = false; // unless the server says otherwise
1360 // parse the message
1362 //MSG_BeginReading ();
1364 parsingerror = true;
1369 Host_Error ("CL_ParseServerMessage: Bad server message");
1371 cmd = MSG_ReadByte ();
1375 SHOWNET("END OF MESSAGE");
1376 break; // end of message
1379 cmdindex = cmdcount & 31;
1381 cmdlog[cmdindex] = cmd;
1383 // if the high bit of the command byte is set, it is a fast update
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)
1388 cmdlogname[cmdindex] = temp;
1389 SHOWNET("fast update");
1390 if (cls.signon == SIGNONS - 1)
1392 // first update is the final signon stage
1393 cls.signon = SIGNONS;
1396 EntityFrameQuake_ReadEntity (cmd&127);
1400 SHOWNET(svc_strings[cmd]);
1401 cmdlogname[cmdindex] = svc_strings[cmd];
1402 if (!cmdlogname[cmdindex])
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)
1406 cmdlogname[cmdindex] = temp;
1414 char description[32*64], temp[64];
1416 strcpy (description, "packet dump: ");
1420 count = cmdcount - i;
1424 dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
1425 strlcat (description, temp, sizeof (description));
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");
1437 if (cls.signon < SIGNONS)
1438 Con_Print("<-- server to client keepalive\n");
1442 cl.mtime[1] = cl.mtime[0];
1443 cl.mtime[0] = MSG_ReadFloat ();
1446 case svc_clientdata:
1447 i = (unsigned short) MSG_ReadShort ();
1448 CL_ParseClientdata (i);
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);
1461 case svc_disconnect:
1462 Con_Printf ("Server disconnected\n");
1463 if (cls.demonum != -1)
1470 Con_Print(MSG_ReadString());
1473 case svc_centerprint:
1474 SCR_CenterPrint(MSG_ReadString ());
1478 Cbuf_AddText (MSG_ReadString ());
1485 case svc_serverinfo:
1486 CL_ParseServerInfo ();
1490 for (i=0 ; i<3 ; i++)
1491 cl.viewangles[i] = MSG_ReadAngle (cl.protocol);
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;
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);
1515 CL_ParseStartSoundPacket(false);
1519 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1521 // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
1522 CL_ParseStartSoundPacket(true);
1526 int i = (unsigned short)MSG_ReadShort();
1527 char *s = MSG_ReadString();
1530 if (i >= 1 && i < MAX_MODELS)
1532 model_t *model = Mod_ForName(s, false, false, i == 1);
1534 Con_Printf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
1535 cl.model_precache[i] = model;
1538 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
1543 if (i >= 1 && i < MAX_SOUNDS)
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;
1551 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
1557 i = (unsigned short) MSG_ReadShort();
1558 S_StopSound(i>>3, i&7);
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));
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 ();
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 ();
1583 CL_ParseParticleEffect ();
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);
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);
1610 case svc_spawnstatic:
1611 CL_ParseStatic (false);
1613 case svc_spawnstatic2:
1614 CL_ParseStatic (true);
1616 case svc_temp_entity:
1617 CL_ParseTempEntity ();
1621 cl.paused = MSG_ReadByte ();
1626 S_PauseGameSounds (cl.paused);
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);
1639 case svc_killedmonster:
1640 cl.stats[STAT_MONSTERS]++;
1643 case svc_foundsecret:
1644 cl.stats[STAT_SECRETS]++;
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 ();
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 ();
1661 case svc_spawnstaticsound:
1662 CL_ParseStaticSound (false);
1665 case svc_spawnstaticsound2:
1666 CL_ParseStaticSound (true);
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);
1675 CDAudio_Play ((qbyte)cl.cdtrack, true);
1678 case svc_intermission:
1679 cl.intermission = 1;
1680 cl.completed_time = cl.time;
1684 cl.intermission = 2;
1685 cl.completed_time = cl.time;
1686 SCR_CenterPrint(MSG_ReadString ());
1690 cl.intermission = 3;
1691 cl.completed_time = cl.time;
1692 SCR_CenterPrint(MSG_ReadString ());
1695 case svc_sellscreen:
1696 Cmd_ExecuteString ("help", src_command);
1699 if (gamemode == GAME_TENEBRAE)
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);
1714 SHOWLMP_decodehide();
1717 if (gamemode == GAME_TENEBRAE)
1720 MSG_ReadCoord(cl.protocol);
1721 MSG_ReadCoord(cl.protocol);
1722 MSG_ReadCoord(cl.protocol);
1727 SHOWLMP_decodeshow();
1730 R_SetSkyBox(MSG_ReadString());
1735 length = (int) ((unsigned short) MSG_ReadShort());
1736 for (i = 0;i < length;i++)
1737 cgamenetbuffer[i] = MSG_ReadByte();
1739 CL_CGVM_ParseNetwork(cgamenetbuffer, length);
1743 if (cls.signon == SIGNONS - 1)
1745 // first update is the final signon stage
1746 cls.signon = SIGNONS;
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();
1756 Host_Error("CL_ParseServerMessage: svc_entities: unknown cl.protocol %i\n", cl.protocol);
1761 EntityFrameQuake_ISeeDeadEntities();
1763 parsingerror = false;
1766 void CL_Parse_DumpPacket(void)
1770 Con_Print("Packet dump:\n");
1771 SZ_HexDumpToConsole(&net_message);
1772 parsingerror = false;
1775 void CL_Parse_Init(void)
1777 // LordHavoc: added demo_nehahra cvar
1778 cl_scores_mempool = Mem_AllocPool("client player info", 0, NULL);
1779 Cvar_RegisterVariable (&demo_nehahra);
1780 if (gamemode == GAME_NEHAHRA)
1781 Cvar_SetValue("demo_nehahra", 1);
1782 Cvar_RegisterVariable(&developer_networkentities);
1785 void CL_Parse_Shutdown(void)
1787 Mem_FreePool (&cl_scores_mempool);