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"
27 char *svc_strings[128] =
33 "svc_version", // [int] server version
34 "svc_setview", // [short] entity number
35 "svc_sound", // <see code>
36 "svc_time", // [float] server time
37 "svc_print", // [string] null terminated string
38 "svc_stufftext", // [string] stuffed into client's console buffer
39 // the string should be \n terminated
40 "svc_setangle", // [vec3] set the view angle to this absolute value
42 "svc_serverinfo", // [int] version
43 // [string] signon string
44 // [string]..[0]model cache [string]...[0]sounds cache
45 // [string]..[0]item cache
46 "svc_lightstyle", // [byte] [string]
47 "svc_updatename", // [byte] [string]
48 "svc_updatefrags", // [byte] [short]
49 "svc_clientdata", // <shortbits + data>
50 "svc_stopsound", // <see code>
51 "svc_updatecolors", // [byte] [byte]
52 "svc_particle", // [vec3] <variable>
53 "svc_damage", // [byte] impact [byte] blood [vec3] from
56 "OBSOLETE svc_spawnbinary",
59 "svc_temp_entity", // <variable>
65 "svc_spawnstaticsound",
67 "svc_finale", // [string] music [string] text
68 "svc_cdtrack", // [byte] track [byte] looptrack
71 "svc_showlmp", // [string] iconlabel [string] lmpfile [short] x [short] y
72 "svc_hidelmp", // [string] iconlabel
73 "svc_skybox", // [string] skyname
86 "svc_cgame", // 50 // [short] length [bytes] data
87 "svc_updatestatubyte", // 51 // [byte] stat [byte] value
88 "svc_effect", // 52 // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate
89 "svc_effect2", // 53 // [vector] org [short] modelindex [short] startframe [byte] framecount [byte] framerate
90 "svc_sound2", // 54 // short soundindex instead of byte
91 "svc_spawnbaseline2", // 55 // short modelindex instead of byte
92 "svc_spawnstatic2", // 56 // short modelindex instead of byte
93 "svc_entities", // 57 // [int] deltaframe [int] thisframe [float vector] eye [variable length] entitydata
94 "svc_csqcentities", // 58 // [short] entnum [variable length] entitydata ... [short] 0x0000
95 "svc_spawnstaticsound2", // 59 // [coord3] [short] samp [byte] vol [byte] aten
98 //=============================================================================
100 cvar_t demo_nehahra = {0, "demo_nehahra", "0", "reads all quake demos as nehahra movie protocol"};
101 cvar_t developer_networkentities = {0, "developer_networkentities", "0", "prints received entities, value is 0-4 (higher for more info)"};
105 CL_ParseStartSoundPacket
108 void CL_ParseStartSoundPacket(int largesoundindex)
117 field_mask = MSG_ReadByte();
119 if (field_mask & SND_VOLUME)
120 volume = MSG_ReadByte ();
122 volume = DEFAULT_SOUND_PACKET_VOLUME;
124 if (field_mask & SND_ATTENUATION)
125 attenuation = MSG_ReadByte () / 64.0;
127 attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
129 if (field_mask & SND_LARGEENTITY)
131 ent = (unsigned short) MSG_ReadShort ();
132 channel = MSG_ReadByte ();
136 channel = (unsigned short) MSG_ReadShort ();
141 if (largesoundindex || field_mask & SND_LARGESOUND)
142 sound_num = (unsigned short) MSG_ReadShort ();
144 sound_num = MSG_ReadByte ();
146 MSG_ReadVector(pos, cl.protocol);
148 if (sound_num >= MAX_SOUNDS)
150 Con_Printf("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
154 if (ent >= MAX_EDICTS)
156 Con_Printf("CL_ParseStartSoundPacket: ent = %i", ent);
160 S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation);
167 When the client is taking a long time to load stuff, send keepalive messages
168 so the server doesn't disconnect.
172 static unsigned char olddata[NET_MAXMESSAGE];
173 void CL_KeepaliveMessage (void)
176 static double nextmsg = -1;
181 // no need if server is local and definitely not if this is a demo
182 if (sv.active || !cls.netcon)
185 // read messages from server, should just be nops
186 oldreadcount = msg_readcount;
187 oldbadread = msg_badread;
189 memcpy(olddata, net_message.data, net_message.cursize);
191 NetConn_ClientFrame();
193 msg_readcount = oldreadcount;
194 msg_badread = oldbadread;
196 memcpy(net_message.data, olddata, net_message.cursize);
198 if (cls.netcon && (time = Sys_DoubleTime()) >= nextmsg)
201 unsigned char buf[4];
204 // LordHavoc: must use unreliable because reliable could kill the sigon message!
205 Con_Print("--> client to server keepalive\n");
206 memset(&msg, 0, sizeof(msg));
208 msg.maxsize = sizeof(buf);
209 MSG_WriteChar(&msg, svc_nop);
210 NetConn_SendUnreliableMessage(cls.netcon, &msg);
214 void CL_ParseEntityLump(char *entdata)
217 char key[128], value[MAX_INPUTLINE];
218 FOG_clear(); // LordHavoc: no fog until set
219 // LordHavoc: default to the map's sky (q3 shader parsing sets this)
220 R_SetSkyBox(cl.worldmodel->brush.skybox);
224 if (!COM_ParseToken(&data, false))
226 if (com_token[0] != '{')
230 if (!COM_ParseToken(&data, false))
232 if (com_token[0] == '}')
233 break; // end of worldspawn
234 if (com_token[0] == '_')
235 strlcpy (key, com_token + 1, sizeof (key));
237 strlcpy (key, com_token, sizeof (key));
238 while (key[strlen(key)-1] == ' ') // remove trailing spaces
239 key[strlen(key)-1] = 0;
240 if (!COM_ParseToken(&data, false))
242 strlcpy (value, com_token, sizeof (value));
243 if (!strcmp("sky", key))
245 else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
247 else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
249 else if (!strcmp("fog", key))
250 sscanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue);
251 else if (!strcmp("fog_density", key))
252 fog_density = atof(value);
253 else if (!strcmp("fog_red", key))
254 fog_red = atof(value);
255 else if (!strcmp("fog_green", key))
256 fog_green = atof(value);
257 else if (!strcmp("fog_blue", key))
258 fog_blue = atof(value);
263 =====================
266 An svc_signonnum has been received, perform a client side setup
267 =====================
269 static void CL_SignonReply (void)
271 Con_DPrintf("CL_SignonReply: %i\n", cls.signon);
278 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
279 MSG_WriteString (&cls.netcon->message, "prespawn");
286 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
287 MSG_WriteString (&cls.netcon->message, va("name \"%s\"", cl_name.string));
289 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
290 MSG_WriteString (&cls.netcon->message, va("color %i %i", cl_color.integer >> 4, cl_color.integer & 15));
292 if (cl_pmodel.integer)
294 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
295 MSG_WriteString (&cls.netcon->message, va("pmodel %i", cl_pmodel.integer));
297 if (*cl_playermodel.string)
299 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
300 MSG_WriteString (&cls.netcon->message, va("playermodel %s", cl_playermodel.string));
302 if (*cl_playerskin.string)
304 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
305 MSG_WriteString (&cls.netcon->message, va("playerskin %s", cl_playerskin.string));
308 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
309 MSG_WriteString (&cls.netcon->message, va("rate %i", cl_rate.integer));
311 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
312 MSG_WriteString (&cls.netcon->message, "spawn");
319 MSG_WriteByte (&cls.netcon->message, clc_stringcmd);
320 MSG_WriteString (&cls.netcon->message, "begin");
335 // FIXME: this is a lot of memory to be keeping around, this needs to be dynamically allocated and freed
336 static char parse_model_precache[MAX_MODELS][MAX_QPATH];
337 static char parse_sound_precache[MAX_SOUNDS][MAX_QPATH];
338 void CL_ParseServerInfo (void)
342 protocolversion_t protocol;
343 int nummodels, numsounds;
346 Con_DPrint("Serverinfo packet received.\n");
348 // check memory integrity
349 Mem_CheckSentinelsGlobal();
352 // wipe the client_state_t struct
356 // parse protocol version number
358 protocol = Protocol_EnumForNumber(i);
359 if (protocol == PROTOCOL_UNKNOWN)
361 Host_Error("CL_ParseServerInfo: Server is unrecognized protocol number (%i)", i);
364 // hack for unmarked Nehahra movie demos which had a custom protocol
365 if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
366 protocol = PROTOCOL_NEHAHRAMOVIE;
367 cl.protocol = protocol;
368 Con_DPrintf("Server protocol is %s\n", Protocol_NameForEnum(cl.protocol));
371 cl.maxclients = MSG_ReadByte ();
372 if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
374 Host_Error("Bad maxclients (%u) from server", cl.maxclients);
377 cl.scores = (scoreboard_t *)Mem_Alloc(cl_mempool, cl.maxclients*sizeof(*cl.scores));
380 cl.gametype = MSG_ReadByte ();
382 // parse signon message
383 str = MSG_ReadString ();
384 strlcpy (cl.levelname, str, sizeof(cl.levelname));
386 // seperate the printfs so the server message can have a color
387 if (cl.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
388 Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n\2%s\n", str);
390 // check memory integrity
391 Mem_CheckSentinelsGlobal();
394 // if server is active, we already began a loading plaque
396 SCR_BeginLoadingPlaque();
398 // disable until we get textures for it
401 memset(cl.csqc_model_precache, 0, sizeof(cl.csqc_model_precache)); //[515]: csqc
402 memset(cl.model_precache, 0, sizeof(cl.model_precache));
403 memset(cl.sound_precache, 0, sizeof(cl.sound_precache));
405 // parse model precache list
406 for (nummodels=1 ; ; nummodels++)
408 str = MSG_ReadString();
411 if (nummodels==MAX_MODELS)
412 Host_Error ("Server sent too many model precaches");
413 if (strlen(str) >= MAX_QPATH)
414 Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
415 strlcpy (parse_model_precache[nummodels], str, sizeof (parse_model_precache[nummodels]));
417 // parse sound precache list
418 for (numsounds=1 ; ; numsounds++)
420 str = MSG_ReadString();
423 if (numsounds==MAX_SOUNDS)
424 Host_Error("Server sent too many sound precaches");
425 if (strlen(str) >= MAX_QPATH)
426 Host_Error("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
427 strlcpy (parse_sound_precache[numsounds], str, sizeof (parse_sound_precache[numsounds]));
430 // touch all of the precached models that are still loaded so we can free
431 // anything that isn't needed
433 for (i = 1;i < nummodels;i++)
434 Mod_FindName(parse_model_precache[i]);
435 // precache any models used by the client (this also marks them used)
436 cl.model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
437 cl.model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
438 cl.model_bolt3 = Mod_ForName("progs/bolt3.mdl", false, false, false);
439 cl.model_beam = Mod_ForName("progs/beam.mdl", false, false, false);
442 // do the same for sounds
443 // FIXME: S_ServerSounds does not know about cl.sfx_ sounds
444 S_ServerSounds (parse_sound_precache, numsounds);
446 // precache any sounds used by the client
447 cl.sfx_wizhit = S_PrecacheSound("sound/wizard/hit.wav", false, true);
448 cl.sfx_knighthit = S_PrecacheSound("sound/hknight/hit.wav", false, true);
449 cl.sfx_tink1 = S_PrecacheSound("sound/weapons/tink1.wav", false, true);
450 cl.sfx_ric1 = S_PrecacheSound("sound/weapons/ric1.wav", false, true);
451 cl.sfx_ric2 = S_PrecacheSound("sound/weapons/ric2.wav", false, true);
452 cl.sfx_ric3 = S_PrecacheSound("sound/weapons/ric3.wav", false, true);
453 cl.sfx_r_exp3 = S_PrecacheSound("sound/weapons/r_exp3.wav", false, true);
455 // now we try to load everything that is new
458 CL_KeepaliveMessage ();
459 cl.model_precache[1] = Mod_ForName(parse_model_precache[1], false, false, true);
460 if (cl.model_precache[1]->Draw == NULL)
461 Con_Printf("Map %s not found\n", parse_model_precache[1]);
464 for (i=2 ; i<nummodels ; i++)
466 CL_KeepaliveMessage();
467 if ((cl.model_precache[i] = Mod_ForName(parse_model_precache[i], false, false, false))->Draw == NULL)
468 Con_Printf("Model %s not found\n", parse_model_precache[i]);
472 for (i=1 ; i<numsounds ; i++)
474 CL_KeepaliveMessage();
476 // Don't lock the sfx here, S_ServerSounds already did that
477 cl.sound_precache[i] = S_PrecacheSound (parse_sound_precache[i], true, false);
481 ent = &cl_entities[0];
482 // entire entity array was cleared, so just fill in a few fields
483 ent->state_current.active = true;
484 ent->render.model = cl.worldmodel = cl.model_precache[1];
485 ent->render.scale = 1; // some of the renderer still relies on scale
486 ent->render.alpha = 1;
487 ent->render.colormap = -1; // no special coloring
488 ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
489 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
490 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
491 CL_BoundingBoxForEntity(&ent->render);
498 // noclip is turned off at start
499 noclip_anglehack = false;
501 // check memory integrity
502 Mem_CheckSentinelsGlobal();
505 void CL_ValidateState(entity_state_t *s)
512 if (s->modelindex >= MAX_MODELS && (65536-s->modelindex) >= MAX_MODELS)
513 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
515 // colormap is client index + 1
516 if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
518 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
522 model = cl.model_precache[s->modelindex];
523 if (model && model->type && s->frame >= model->numframes)
525 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
528 if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
530 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
535 void CL_MoveLerpEntityStates(entity_t *ent)
537 float odelta[3], adelta[3];
538 CL_ValidateState(&ent->state_current);
539 VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
540 VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
541 if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
543 // reset all persistent stuff if this is a new entity
544 ent->persistent.lerpdeltatime = 0;
545 ent->persistent.lerpstarttime = cl.mtime[1];
546 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
547 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
548 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
549 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
550 // reset animation interpolation as well
551 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
552 ent->render.frame1time = ent->render.frame2time = cl.time;
553 ent->render.framelerp = 1;
554 // reset various persistent stuff
555 ent->persistent.muzzleflash = 0;
556 VectorCopy(ent->state_current.origin, ent->persistent.trail_origin);
558 else if (cls.timedemo || cl_nolerp.integer || DotProduct(odelta, odelta) > 1000*1000)
560 // don't interpolate the move
561 ent->persistent.lerpdeltatime = 0;
562 ent->persistent.lerpstarttime = cl.mtime[1];
563 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
564 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
565 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
566 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
568 else if (ent->state_current.flags & RENDER_STEP)
570 // monster interpolation
571 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
573 ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
574 ent->persistent.lerpstarttime = cl.mtime[1];
575 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
576 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
577 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
578 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
584 ent->persistent.lerpstarttime = ent->state_previous.time;
585 // no lerp if it's singleplayer
586 if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
587 ent->persistent.lerpdeltatime = 0;
589 ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
590 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
591 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
592 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
593 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
602 void CL_ParseBaseline (entity_t *ent, int large)
606 ent->state_baseline = defaultstate;
607 // FIXME: set ent->state_baseline.number?
608 ent->state_baseline.active = true;
611 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
612 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
616 ent->state_baseline.modelindex = MSG_ReadByte ();
617 ent->state_baseline.frame = MSG_ReadByte ();
619 ent->state_baseline.colormap = MSG_ReadByte();
620 ent->state_baseline.skin = MSG_ReadByte();
621 for (i = 0;i < 3;i++)
623 ent->state_baseline.origin[i] = MSG_ReadCoord(cl.protocol);
624 ent->state_baseline.angles[i] = MSG_ReadAngle(cl.protocol);
626 CL_ValidateState(&ent->state_baseline);
627 ent->state_previous = ent->state_current = ent->state_baseline;
635 Server information pertaining to this client only
638 void CL_ParseClientdata (void)
642 VectorCopy (cl.mpunchangle[0], cl.mpunchangle[1]);
643 VectorCopy (cl.mpunchvector[0], cl.mpunchvector[1]);
644 VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
645 cl.mviewzoom[1] = cl.mviewzoom[0];
647 if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
649 cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
650 cl.stats[STAT_ITEMS] = 0;
651 cl.stats[STAT_VIEWZOOM] = 255;
654 cl.mpunchangle[0][0] = 0;
655 cl.mpunchangle[0][1] = 0;
656 cl.mpunchangle[0][2] = 0;
657 cl.mpunchvector[0][0] = 0;
658 cl.mpunchvector[0][1] = 0;
659 cl.mpunchvector[0][2] = 0;
660 cl.mvelocity[0][0] = 0;
661 cl.mvelocity[0][1] = 0;
662 cl.mvelocity[0][2] = 0;
665 bits = (unsigned short) MSG_ReadShort ();
666 if (bits & SU_EXTEND1)
667 bits |= (MSG_ReadByte() << 16);
668 if (bits & SU_EXTEND2)
669 bits |= (MSG_ReadByte() << 24);
671 if (bits & SU_VIEWHEIGHT)
672 cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
674 if (bits & SU_IDEALPITCH)
675 cl.idealpitch = MSG_ReadChar ();
677 for (i = 0;i < 3;i++)
679 if (bits & (SU_PUNCH1<<i) )
681 if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE)
682 cl.mpunchangle[0][i] = MSG_ReadChar();
684 cl.mpunchangle[0][i] = MSG_ReadAngle16i();
686 if (bits & (SU_PUNCHVEC1<<i))
688 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
689 cl.mpunchvector[0][i] = MSG_ReadCoord16i();
691 cl.mpunchvector[0][i] = MSG_ReadCoord32f();
693 if (bits & (SU_VELOCITY1<<i) )
695 if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
696 cl.mvelocity[0][i] = MSG_ReadChar()*16;
698 cl.mvelocity[0][i] = MSG_ReadCoord32f();
702 // LordHavoc: hipnotic demos don't have this bit set but should
703 if (bits & SU_ITEMS || cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
704 cl.stats[STAT_ITEMS] = MSG_ReadLong ();
706 cl.onground = (bits & SU_ONGROUND) != 0;
707 csqc_onground = cl.onground; //[515]: cause without this csqc will receive not right value on svc_print =/
708 cl.inwater = (bits & SU_INWATER) != 0;
710 if (cl.protocol == PROTOCOL_DARKPLACES5)
712 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
713 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
714 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
715 cl.stats[STAT_HEALTH] = MSG_ReadShort();
716 cl.stats[STAT_AMMO] = MSG_ReadShort();
717 cl.stats[STAT_SHELLS] = MSG_ReadShort();
718 cl.stats[STAT_NAILS] = MSG_ReadShort();
719 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
720 cl.stats[STAT_CELLS] = MSG_ReadShort();
721 cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
723 else if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
725 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
726 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
727 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
728 cl.stats[STAT_HEALTH] = MSG_ReadShort();
729 cl.stats[STAT_AMMO] = MSG_ReadByte();
730 cl.stats[STAT_SHELLS] = MSG_ReadByte();
731 cl.stats[STAT_NAILS] = MSG_ReadByte();
732 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
733 cl.stats[STAT_CELLS] = MSG_ReadByte();
734 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
735 cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
737 cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
740 if (bits & SU_VIEWZOOM)
742 if (cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
743 cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
745 cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
748 // check for important changes
751 if (cl.olditems != cl.stats[STAT_ITEMS])
752 for (j = 0;j < 32;j++)
753 if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
754 cl.item_gettime[j] = cl.time;
755 cl.olditems = cl.stats[STAT_ITEMS];
757 // GAME_NEXUIZ hud needs weapon change time
758 if (cl.activeweapon != cl.stats[STAT_ACTIVEWEAPON])
759 cl.weapontime = cl.time;
760 cl.activeweapon = cl.stats[STAT_ACTIVEWEAPON];
762 // viewzoom interpolation
763 cl.mviewzoom[0] = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
767 =====================
769 =====================
771 void CL_ParseStatic (int large)
775 if (cl_num_static_entities >= cl_max_static_entities)
776 Host_Error ("Too many static entities");
777 ent = &cl_static_entities[cl_num_static_entities++];
778 CL_ParseBaseline (ent, large);
780 // copy it to the current state
781 ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
782 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
783 ent->render.framelerp = 0;
784 // make torchs play out of sync
785 ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
786 ent->render.colormap = -1; // no special coloring
787 ent->render.skinnum = ent->state_baseline.skin;
788 ent->render.effects = ent->state_baseline.effects;
789 ent->render.alpha = 1;
790 //ent->render.scale = 1;
792 //VectorCopy (ent->state_baseline.origin, ent->render.origin);
793 //VectorCopy (ent->state_baseline.angles, ent->render.angles);
795 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, ent->state_baseline.origin[0], ent->state_baseline.origin[1], ent->state_baseline.origin[2], ent->state_baseline.angles[0], ent->state_baseline.angles[1], ent->state_baseline.angles[2], 1);
796 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
797 CL_BoundingBoxForEntity(&ent->render);
799 // This is definitely cheating...
800 if (ent->render.model == NULL)
801 cl_num_static_entities--;
809 void CL_ParseStaticSound (int large)
812 int sound_num, vol, atten;
814 MSG_ReadVector(org, cl.protocol);
816 sound_num = (unsigned short) MSG_ReadShort ();
818 sound_num = MSG_ReadByte ();
819 vol = MSG_ReadByte ();
820 atten = MSG_ReadByte ();
822 S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
825 void CL_ParseEffect (void)
828 int modelindex, startframe, framecount, framerate;
830 MSG_ReadVector(org, cl.protocol);
831 modelindex = MSG_ReadByte ();
832 startframe = MSG_ReadByte ();
833 framecount = MSG_ReadByte ();
834 framerate = MSG_ReadByte ();
836 CL_Effect(org, modelindex, startframe, framecount, framerate);
839 void CL_ParseEffect2 (void)
842 int modelindex, startframe, framecount, framerate;
844 MSG_ReadVector(org, cl.protocol);
845 modelindex = (unsigned short) MSG_ReadShort ();
846 startframe = (unsigned short) MSG_ReadShort ();
847 framecount = MSG_ReadByte ();
848 framerate = MSG_ReadByte ();
850 CL_Effect(org, modelindex, startframe, framecount, framerate);
853 void CL_ParseBeam (model_t *m, int lightning)
859 ent = (unsigned short) MSG_ReadShort ();
860 MSG_ReadVector(start, cl.protocol);
861 MSG_ReadVector(end, cl.protocol);
863 if (ent >= MAX_EDICTS)
865 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
869 if (ent >= cl_max_entities)
870 CL_ExpandEntities(ent);
872 // override any beam with the same entity
875 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
876 if (b->entity == ent)
878 // if the entity was not found then just replace an unused beam
879 if (i == cl_max_beams)
880 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
881 if (!b->model || b->endtime < cl.time)
883 if (i < cl_max_beams)
886 b->lightning = lightning;
888 b->endtime = cl.time + 0.2;
889 VectorCopy (start, b->start);
890 VectorCopy (end, b->end);
891 b->relativestartvalid = 0;
892 if (ent && cl_entities[ent].state_current.active)
895 matrix4x4_t matrix, imatrix;
896 if (ent == cl.viewentity && cl.movement)
897 p = &cl_entities[b->entity].state_previous;
899 p = &cl_entities[b->entity].state_current;
900 // not really valid yet, we need to get the orientation now
901 // (ParseBeam flagged this because it is received before
902 // entities are received, by now they have been received)
903 // note: because players create lightning in their think
904 // function (which occurs before movement), they actually
905 // have some lag in it's location, so compare to the
906 // previous player state, not the latest
907 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2], -p->angles[0], p->angles[1], p->angles[2], 1);
908 Matrix4x4_Invert_Simple(&imatrix, &matrix);
909 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
910 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
911 b->relativestartvalid = 1;
915 Con_Print("beam list overflow!\n");
918 void CL_ParseTempEntity(void)
926 int colorStart, colorLength, count;
927 float velspeed, radius;
928 unsigned char *tempcolor;
929 matrix4x4_t tempmatrix;
931 type = MSG_ReadByte();
935 // spike hitting wall
936 MSG_ReadVector(pos, cl.protocol);
937 CL_FindNonSolidLocation(pos, pos, 4);
938 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
939 //CL_AllocDlight(NULL, &tempmatrix, 100, 0.12f, 0.50f, 0.12f, 500, 0.2, 0, -1, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
940 CL_RunParticleEffect(pos, vec3_origin, 20, 30);
941 S_StartSound(-1, 0, cl.sfx_wizhit, pos, 1, 1);
945 // spike hitting wall
946 MSG_ReadVector(pos, cl.protocol);
947 CL_FindNonSolidLocation(pos, pos, 4);
948 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
949 //CL_AllocDlight(NULL, &tempmatrix, 100, 0.50f, 0.30f, 0.10f, 500, 0.2, 0, -1, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
950 CL_RunParticleEffect(pos, vec3_origin, 226, 20);
951 S_StartSound(-1, 0, cl.sfx_knighthit, pos, 1, 1);
955 // spike hitting wall
956 MSG_ReadVector(pos, cl.protocol);
957 CL_FindNonSolidLocation(pos, pos, 4);
958 if (cl_particles_quake.integer)
959 CL_RunParticleEffect(pos, vec3_origin, 0, 10);
960 else if (cl_particles_bulletimpacts.integer)
962 CL_SparkShower(pos, vec3_origin, 15, 1);
963 CL_Smoke(pos, vec3_origin, 15);
967 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
972 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
974 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
976 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
980 // quad spike hitting wall
981 MSG_ReadVector(pos, cl.protocol);
982 CL_FindNonSolidLocation(pos, pos, 4);
983 if (cl_particles_quake.integer)
984 CL_RunParticleEffect(pos, vec3_origin, 0, 10);
985 else if (cl_particles_bulletimpacts.integer)
987 CL_SparkShower(pos, vec3_origin, 15, 1);
988 CL_Smoke(pos, vec3_origin, 15);
991 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
992 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
994 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
999 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1001 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1003 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1007 // super spike hitting wall
1008 MSG_ReadVector(pos, cl.protocol);
1009 CL_FindNonSolidLocation(pos, pos, 4);
1010 if (cl_particles_quake.integer)
1011 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1012 else if (cl_particles_bulletimpacts.integer)
1014 CL_SparkShower(pos, vec3_origin, 30, 1);
1015 CL_Smoke(pos, vec3_origin, 30);
1019 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1024 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1026 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1028 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1031 case TE_SUPERSPIKEQUAD:
1032 // quad super spike hitting wall
1033 MSG_ReadVector(pos, cl.protocol);
1034 CL_FindNonSolidLocation(pos, pos, 4);
1035 if (cl_particles_quake.integer)
1036 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1037 else if (cl_particles_bulletimpacts.integer)
1039 CL_SparkShower(pos, vec3_origin, 30, 1);
1040 CL_Smoke(pos, vec3_origin, 30);
1043 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1044 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1046 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1051 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1053 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1055 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1058 // LordHavoc: added for improved blood splatters
1061 MSG_ReadVector(pos, cl.protocol);
1062 CL_FindNonSolidLocation(pos, pos, 4);
1063 dir[0] = MSG_ReadChar();
1064 dir[1] = MSG_ReadChar();
1065 dir[2] = MSG_ReadChar();
1066 count = MSG_ReadByte();
1067 CL_BloodPuff(pos, dir, count);
1071 MSG_ReadVector(pos, cl.protocol);
1072 CL_FindNonSolidLocation(pos, pos, 4);
1073 dir[0] = MSG_ReadChar();
1074 dir[1] = MSG_ReadChar();
1075 dir[2] = MSG_ReadChar();
1076 count = MSG_ReadByte();
1077 CL_SparkShower(pos, dir, count, 1);
1080 MSG_ReadVector(pos, cl.protocol);
1081 CL_FindNonSolidLocation(pos, pos, 4);
1082 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1083 CL_AllocDlight(NULL, &tempmatrix, 200, 1, 1, 1, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1086 // LordHavoc: added for improved gore
1087 case TE_BLOODSHOWER:
1089 MSG_ReadVector(pos, cl.protocol); // mins
1090 MSG_ReadVector(pos2, cl.protocol); // maxs
1091 velspeed = MSG_ReadCoord(cl.protocol); // speed
1092 count = (unsigned short) MSG_ReadShort(); // number of particles
1093 CL_BloodShower(pos, pos2, velspeed, count);
1095 case TE_PARTICLECUBE:
1096 // general purpose particle effect
1097 MSG_ReadVector(pos, cl.protocol); // mins
1098 MSG_ReadVector(pos2, cl.protocol); // maxs
1099 MSG_ReadVector(dir, cl.protocol); // dir
1100 count = (unsigned short) MSG_ReadShort(); // number of particles
1101 colorStart = MSG_ReadByte(); // color
1102 colorLength = MSG_ReadByte(); // gravity (1 or 0)
1103 velspeed = MSG_ReadCoord(cl.protocol); // randomvel
1104 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
1107 case TE_PARTICLERAIN:
1108 // general purpose particle effect
1109 MSG_ReadVector(pos, cl.protocol); // mins
1110 MSG_ReadVector(pos2, cl.protocol); // maxs
1111 MSG_ReadVector(dir, cl.protocol); // dir
1112 count = (unsigned short) MSG_ReadShort(); // number of particles
1113 colorStart = MSG_ReadByte(); // color
1114 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
1117 case TE_PARTICLESNOW:
1118 // general purpose particle effect
1119 MSG_ReadVector(pos, cl.protocol); // mins
1120 MSG_ReadVector(pos2, cl.protocol); // maxs
1121 MSG_ReadVector(dir, cl.protocol); // dir
1122 count = (unsigned short) MSG_ReadShort(); // number of particles
1123 colorStart = MSG_ReadByte(); // color
1124 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
1128 // bullet hitting wall
1129 MSG_ReadVector(pos, cl.protocol);
1130 CL_FindNonSolidLocation(pos, pos, 4);
1131 if (cl_particles_quake.integer)
1132 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1135 CL_SparkShower(pos, vec3_origin, 15, 1);
1136 CL_Smoke(pos, vec3_origin, 15);
1141 case TE_GUNSHOTQUAD:
1142 // quad bullet hitting wall
1143 MSG_ReadVector(pos, cl.protocol);
1144 CL_FindNonSolidLocation(pos, pos, 4);
1145 if (cl_particles_quake.integer)
1146 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1149 CL_SparkShower(pos, vec3_origin, 15, 1);
1150 CL_Smoke(pos, vec3_origin, 15);
1153 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1154 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1159 MSG_ReadVector(pos, cl.protocol);
1160 CL_FindNonSolidLocation(pos, pos, 10);
1161 CL_ParticleExplosion(pos);
1162 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
1163 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1164 CL_AllocDlight(NULL, &tempmatrix, 350, 4.0f, 2.0f, 0.50f, 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1165 if (gamemode != GAME_NEXUIZ)
1166 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1169 case TE_EXPLOSIONQUAD:
1170 // quad rocket explosion
1171 MSG_ReadVector(pos, cl.protocol);
1172 CL_FindNonSolidLocation(pos, pos, 10);
1173 CL_ParticleExplosion(pos);
1174 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1175 CL_AllocDlight(NULL, &tempmatrix, 350, 2.5f, 2.0f, 4.0f, 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1176 if (gamemode != GAME_NEXUIZ)
1177 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1181 // Nehahra movie colored lighting explosion
1182 MSG_ReadVector(pos, cl.protocol);
1183 CL_FindNonSolidLocation(pos, pos, 10);
1184 CL_ParticleExplosion(pos);
1185 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1186 color[0] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1187 color[1] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1188 color[2] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1189 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1190 if (gamemode != GAME_NEXUIZ)
1191 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1194 case TE_EXPLOSIONRGB:
1195 // colored lighting explosion
1196 MSG_ReadVector(pos, cl.protocol);
1197 CL_FindNonSolidLocation(pos, pos, 10);
1198 CL_ParticleExplosion(pos);
1199 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1200 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1201 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1202 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1203 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1204 if (gamemode != GAME_NEXUIZ)
1205 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1208 case TE_TAREXPLOSION:
1209 // tarbaby explosion
1210 MSG_ReadVector(pos, cl.protocol);
1211 CL_FindNonSolidLocation(pos, pos, 10);
1212 CL_BlobExplosion(pos);
1214 if (gamemode != GAME_NEXUIZ)
1215 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1216 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1217 CL_AllocDlight(NULL, &tempmatrix, 600, 1.6f, 0.8f, 2.0f, 1200, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1221 MSG_ReadVector(pos, cl.protocol);
1222 CL_FindNonSolidLocation(pos, pos, 10);
1223 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1224 CL_AllocDlight(NULL, &tempmatrix, 200, 2, 2, 2, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1227 case TE_CUSTOMFLASH:
1228 MSG_ReadVector(pos, cl.protocol);
1229 CL_FindNonSolidLocation(pos, pos, 4);
1230 radius = (MSG_ReadByte() + 1) * 8;
1231 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
1232 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1233 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1234 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1235 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1236 CL_AllocDlight(NULL, &tempmatrix, radius, color[0], color[1], color[2], radius / velspeed, velspeed, 0, -1, true, 1, 0.25, 1, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1240 MSG_ReadVector(pos, cl.protocol);
1241 MSG_ReadVector(dir, cl.protocol);
1242 count = MSG_ReadByte();
1243 CL_Flames(pos, dir, count);
1248 CL_ParseBeam(cl.model_bolt, true);
1253 CL_ParseBeam(cl.model_bolt2, true);
1258 CL_ParseBeam(cl.model_bolt3, false);
1263 // grappling hook beam
1264 CL_ParseBeam(cl.model_beam, false);
1268 // LordHavoc: for compatibility with the Nehahra movie...
1269 case TE_LIGHTNING4NEH:
1270 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
1274 MSG_ReadVector(pos, cl.protocol);
1279 MSG_ReadVector(pos, cl.protocol);
1280 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1281 CL_AllocDlight(NULL, &tempmatrix, 200, 1.0f, 1.0f, 1.0f, 600, 99.0f, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1282 CL_TeleportSplash(pos);
1286 // color mapped explosion
1287 MSG_ReadVector(pos, cl.protocol);
1288 CL_FindNonSolidLocation(pos, pos, 10);
1289 colorStart = MSG_ReadByte();
1290 colorLength = MSG_ReadByte();
1291 CL_ParticleExplosion2(pos, colorStart, colorLength);
1292 tempcolor = (unsigned char *)&palette_complete[(rand()%colorLength) + colorStart];
1293 color[0] = tempcolor[0] * (2.0f / 255.0f);
1294 color[1] = tempcolor[1] * (2.0f / 255.0f);
1295 color[2] = tempcolor[2] * (2.0f / 255.0f);
1296 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1297 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1298 if (gamemode != GAME_NEXUIZ)
1299 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1303 MSG_ReadVector(pos, cl.protocol);
1304 MSG_ReadVector(pos2, cl.protocol);
1305 MSG_ReadVector(dir, cl.protocol);
1306 CL_BeamParticle(pos, pos2, 8, 1, 1, 1, 1, 1);
1310 MSG_ReadVector(pos, cl.protocol);
1311 MSG_ReadVector(dir, cl.protocol);
1312 count = MSG_ReadByte();
1313 CL_FindNonSolidLocation(pos, pos, 4);
1314 CL_Tei_Smoke(pos, dir, count);
1317 case TE_TEI_BIGEXPLOSION:
1318 MSG_ReadVector(pos, cl.protocol);
1319 CL_FindNonSolidLocation(pos, pos, 10);
1320 CL_ParticleExplosion(pos);
1321 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1322 CL_AllocDlight(NULL, &tempmatrix, 500, 2.5f, 2.0f, 1.0f, 500, 9999, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1323 if (gamemode != GAME_NEXUIZ)
1324 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1327 case TE_TEI_PLASMAHIT:
1328 MSG_ReadVector(pos, cl.protocol);
1329 MSG_ReadVector(dir, cl.protocol);
1330 count = MSG_ReadByte();
1331 CL_FindNonSolidLocation(pos, pos, 5);
1332 CL_Tei_PlasmaHit(pos, dir, count);
1333 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1334 CL_AllocDlight(NULL, &tempmatrix, 500, 0.6, 1.2, 2.0f, 2000, 9999, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1338 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
1342 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
1345 void CL_VM_Init (void);
1346 qboolean CL_VM_Parse_TempEntity (void);
1347 void CL_VM_Parse_StuffCmd (const char *msg);
1348 void CL_VM_Parse_CenterPrint (const char *msg);
1349 void CSQC_AddPrintText (const char *msg);
1350 void CSQC_ReadEntities (void);
1352 static unsigned char cgamenetbuffer[65536];
1355 =====================
1356 CL_ParseServerMessage
1357 =====================
1359 int parsingerror = false;
1360 void CL_ParseServerMessage(void)
1364 protocolversion_t protocol;
1365 unsigned char cmdlog[32];
1366 char *cmdlogname[32], *temp;
1367 int cmdindex, cmdcount = 0;
1369 if (cls.demorecording)
1370 CL_WriteDemoMessage ();
1372 cl.last_received_message = realtime;
1375 // if recording demos, copy the message out
1377 if (cl_shownet.integer == 1)
1378 Con_Printf("%f %i\n", realtime, net_message.cursize);
1379 else if (cl_shownet.integer == 2)
1380 Con_Print("------------------\n");
1382 cl.onground = false; // unless the server says otherwise
1384 // parse the message
1386 //MSG_BeginReading ();
1388 parsingerror = true;
1393 Host_Error ("CL_ParseServerMessage: Bad server message");
1395 cmd = MSG_ReadByte ();
1399 SHOWNET("END OF MESSAGE");
1400 break; // end of message
1403 cmdindex = cmdcount & 31;
1405 cmdlog[cmdindex] = cmd;
1407 // if the high bit of the command byte is set, it is a fast update
1410 // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
1412 cmdlogname[cmdindex] = temp;
1413 SHOWNET("fast update");
1414 if (cls.signon == SIGNONS - 1)
1416 // first update is the final signon stage
1417 cls.signon = SIGNONS;
1420 EntityFrameQuake_ReadEntity (cmd&127);
1424 SHOWNET(svc_strings[cmd]);
1425 cmdlogname[cmdindex] = svc_strings[cmd];
1426 if (!cmdlogname[cmdindex])
1428 // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
1430 cmdlogname[cmdindex] = temp;
1438 char description[32*64], temp[64];
1440 strcpy (description, "packet dump: ");
1444 count = cmdcount - i;
1448 dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
1449 strlcat (description, temp, sizeof (description));
1454 description[strlen(description)-1] = '\n'; // replace the last space with a newline
1455 Con_Print(description);
1456 Host_Error ("CL_ParseServerMessage: Illegible server message");
1461 if (cls.signon < SIGNONS)
1462 Con_Print("<-- server to client keepalive\n");
1466 cl.mtime[1] = cl.mtime[0];
1467 cl.mtime[0] = MSG_ReadFloat ();
1468 cl.movement_needupdate = true;
1471 case svc_clientdata:
1472 CL_ParseClientdata();
1476 i = MSG_ReadLong ();
1477 protocol = Protocol_EnumForNumber(i);
1478 if (protocol == PROTOCOL_UNKNOWN)
1479 Host_Error("CL_ParseServerMessage: Server is unrecognized protocol number (%i)", i);
1480 // hack for unmarked Nehahra movie demos which had a custom protocol
1481 if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
1482 protocol = PROTOCOL_NEHAHRAMOVIE;
1483 cl.protocol = protocol;
1486 case svc_disconnect:
1487 Con_Printf ("Server disconnected\n");
1488 if (cls.demonum != -1)
1495 CSQC_AddPrintText(MSG_ReadString()); //[515]: csqc
1498 case svc_centerprint:
1499 CL_VM_Parse_CenterPrint(MSG_ReadString ()); //[515]: csqc
1503 CL_VM_Parse_StuffCmd(MSG_ReadString ()); //[515]: csqc
1510 case svc_serverinfo:
1511 CL_ParseServerInfo ();
1512 CL_VM_Init(); //[515]: init csqc
1516 for (i=0 ; i<3 ; i++)
1517 cl.viewangles[i] = MSG_ReadAngle (cl.protocol);
1521 cl.viewentity = (unsigned short)MSG_ReadShort ();
1522 if (cl.viewentity >= MAX_EDICTS)
1523 Host_Error("svc_setview >= MAX_EDICTS");
1524 if (cl.viewentity >= cl_max_entities)
1525 CL_ExpandEntities(cl.viewentity);
1526 // LordHavoc: assume first setview recieved is the real player entity
1527 if (!cl.playerentity)
1528 cl.playerentity = cl.viewentity;
1531 case svc_lightstyle:
1532 i = MSG_ReadByte ();
1533 if (i >= cl_max_lightstyle)
1535 Con_Printf ("svc_lightstyle >= MAX_LIGHTSTYLES");
1538 strlcpy (cl_lightstyle[i].map, MSG_ReadString(), sizeof (cl_lightstyle[i].map));
1539 cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
1540 cl_lightstyle[i].length = (int)strlen(cl_lightstyle[i].map);
1544 CL_ParseStartSoundPacket(false);
1548 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1550 // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
1551 CL_ParseStartSoundPacket(true);
1555 int i = (unsigned short)MSG_ReadShort();
1556 char *s = MSG_ReadString();
1559 if (i >= 1 && i < MAX_MODELS)
1561 model_t *model = Mod_ForName(s, false, false, i == 1);
1563 Con_Printf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
1564 cl.model_precache[i] = model;
1567 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
1572 if (i >= 1 && i < MAX_SOUNDS)
1574 sfx_t *sfx = S_PrecacheSound (s, true, false);
1575 if (!sfx && snd_initialized.integer)
1576 Con_Printf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
1577 cl.sound_precache[i] = sfx;
1580 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
1586 i = (unsigned short) MSG_ReadShort();
1587 S_StopSound(i>>3, i&7);
1590 case svc_updatename:
1591 i = MSG_ReadByte ();
1592 if (i >= cl.maxclients)
1593 Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
1594 strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
1597 case svc_updatefrags:
1598 i = MSG_ReadByte ();
1599 if (i >= cl.maxclients)
1600 Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
1601 cl.scores[i].frags = (signed short) MSG_ReadShort ();
1604 case svc_updatecolors:
1605 i = MSG_ReadByte ();
1606 if (i >= cl.maxclients)
1607 Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
1608 cl.scores[i].colors = MSG_ReadByte ();
1612 CL_ParseParticleEffect ();
1623 case svc_spawnbaseline:
1624 i = (unsigned short) MSG_ReadShort ();
1625 if (i < 0 || i >= MAX_EDICTS)
1626 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
1627 if (i >= cl_max_entities)
1628 CL_ExpandEntities(i);
1629 CL_ParseBaseline (cl_entities + i, false);
1631 case svc_spawnbaseline2:
1632 i = (unsigned short) MSG_ReadShort ();
1633 if (i < 0 || i >= MAX_EDICTS)
1634 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
1635 if (i >= cl_max_entities)
1636 CL_ExpandEntities(i);
1637 CL_ParseBaseline (cl_entities + i, true);
1639 case svc_spawnstatic:
1640 CL_ParseStatic (false);
1642 case svc_spawnstatic2:
1643 CL_ParseStatic (true);
1645 case svc_temp_entity:
1646 if(!CL_VM_Parse_TempEntity())
1647 CL_ParseTempEntity ();
1651 cl.paused = MSG_ReadByte ();
1656 S_PauseGameSounds (cl.paused);
1660 i = MSG_ReadByte ();
1661 // LordHavoc: it's rude to kick off the client if they missed the
1662 // reconnect somehow, so allow signon 1 even if at signon 1
1663 if (i <= cls.signon && i != 1)
1664 Host_Error ("Received signon %i when at %i", i, cls.signon);
1669 case svc_killedmonster:
1670 cl.stats[STAT_MONSTERS]++;
1673 case svc_foundsecret:
1674 cl.stats[STAT_SECRETS]++;
1677 case svc_updatestat:
1678 i = MSG_ReadByte ();
1679 if (i < 0 || i >= MAX_CL_STATS)
1680 Host_Error ("svc_updatestat: %i is invalid", i);
1681 cl.stats[i] = MSG_ReadLong ();
1684 case svc_updatestatubyte:
1685 i = MSG_ReadByte ();
1686 if (i < 0 || i >= MAX_CL_STATS)
1687 Host_Error ("svc_updatestat: %i is invalid", i);
1688 cl.stats[i] = MSG_ReadByte ();
1691 case svc_spawnstaticsound:
1692 CL_ParseStaticSound (false);
1695 case svc_spawnstaticsound2:
1696 CL_ParseStaticSound (true);
1700 cl.cdtrack = MSG_ReadByte ();
1701 cl.looptrack = MSG_ReadByte ();
1702 if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
1703 CDAudio_Play ((unsigned char)cls.forcetrack, true);
1705 CDAudio_Play ((unsigned char)cl.cdtrack, true);
1708 case svc_intermission:
1709 cl.intermission = 1;
1710 cl.completed_time = cl.time;
1714 cl.intermission = 2;
1715 cl.completed_time = cl.time;
1716 SCR_CenterPrint(MSG_ReadString ());
1720 cl.intermission = 3;
1721 cl.completed_time = cl.time;
1722 SCR_CenterPrint(MSG_ReadString ());
1725 case svc_sellscreen:
1726 Cmd_ExecuteString ("help", src_command);
1729 if (gamemode == GAME_TENEBRAE)
1731 // repeating particle effect
1732 MSG_ReadCoord(cl.protocol);
1733 MSG_ReadCoord(cl.protocol);
1734 MSG_ReadCoord(cl.protocol);
1735 MSG_ReadCoord(cl.protocol);
1736 MSG_ReadCoord(cl.protocol);
1737 MSG_ReadCoord(cl.protocol);
1744 SHOWLMP_decodehide();
1747 if (gamemode == GAME_TENEBRAE)
1750 MSG_ReadCoord(cl.protocol);
1751 MSG_ReadCoord(cl.protocol);
1752 MSG_ReadCoord(cl.protocol);
1757 SHOWLMP_decodeshow();
1760 R_SetSkyBox(MSG_ReadString());
1765 length = (int) ((unsigned short) MSG_ReadShort());
1766 for (i = 0;i < length;i++)
1767 cgamenetbuffer[i] = MSG_ReadByte();
1769 CL_CGVM_ParseNetwork(cgamenetbuffer, length);
1773 if (cls.signon == SIGNONS - 1)
1775 // first update is the final signon stage
1776 cls.signon = SIGNONS;
1779 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1780 EntityFrame_CL_ReadFrame();
1781 else if (cl.protocol == PROTOCOL_DARKPLACES4)
1782 EntityFrame4_CL_ReadFrame();
1784 EntityFrame5_CL_ReadFrame();
1786 case svc_csqcentities:
1787 CSQC_ReadEntities();
1792 EntityFrameQuake_ISeeDeadEntities();
1794 parsingerror = false;
1797 void CL_Parse_DumpPacket(void)
1801 Con_Print("Packet dump:\n");
1802 SZ_HexDumpToConsole(&net_message);
1803 parsingerror = false;
1806 void CL_Parse_Init(void)
1808 // LordHavoc: added demo_nehahra cvar
1809 Cvar_RegisterVariable (&demo_nehahra);
1810 if (gamemode == GAME_NEHAHRA)
1811 Cvar_SetValue("demo_nehahra", 1);
1812 Cvar_RegisterVariable(&developer_networkentities);
1815 void CL_Parse_Shutdown(void)