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 float lastmsg;
181 // no need if server is local and definitely not if this is a demo
182 if (sv.active || cls.demoplayback)
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 && NetConn_CanSendMessage(cls.netcon) && (time = Sys_DoubleTime()) - lastmsg >= 5)
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");
207 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)
273 Con_DPrintf("CL_SignonReply: %i\n", cls.signon);
278 MSG_WriteByte (&cls.message, clc_stringcmd);
279 MSG_WriteString (&cls.message, "prespawn");
283 MSG_WriteByte (&cls.message, clc_stringcmd);
284 MSG_WriteString (&cls.message, va("name \"%s\"", cl_name.string));
286 MSG_WriteByte (&cls.message, clc_stringcmd);
287 MSG_WriteString (&cls.message, va("color %i %i", cl_color.integer >> 4, cl_color.integer & 15));
289 if (cl_pmodel.integer)
291 MSG_WriteByte (&cls.message, clc_stringcmd);
292 MSG_WriteString (&cls.message, va("pmodel %i", cl_pmodel.integer));
294 if (*cl_playermodel.string)
296 MSG_WriteByte (&cls.message, clc_stringcmd);
297 MSG_WriteString (&cls.message, va("playermodel %s", cl_playermodel.string));
299 if (*cl_playerskin.string)
301 MSG_WriteByte (&cls.message, clc_stringcmd);
302 MSG_WriteString (&cls.message, va("playerskin %s", cl_playerskin.string));
305 MSG_WriteByte (&cls.message, clc_stringcmd);
306 MSG_WriteString (&cls.message, va("rate %i", cl_rate.integer));
308 MSG_WriteByte (&cls.message, clc_stringcmd);
309 MSG_WriteString (&cls.message, "spawn");
313 MSG_WriteByte (&cls.message, clc_stringcmd);
314 MSG_WriteString (&cls.message, "begin");
328 // FIXME: this is a lot of memory to be keeping around, this needs to be dynamically allocated and freed
329 static char parse_model_precache[MAX_MODELS][MAX_QPATH];
330 static char parse_sound_precache[MAX_SOUNDS][MAX_QPATH];
331 void CL_ParseServerInfo (void)
335 protocolversion_t protocol;
336 int nummodels, numsounds;
339 Con_DPrint("Serverinfo packet received.\n");
341 // check memory integrity
342 Mem_CheckSentinelsGlobal();
345 // wipe the client_state_t struct
349 // parse protocol version number
351 protocol = Protocol_EnumForNumber(i);
352 if (protocol == PROTOCOL_UNKNOWN)
354 Host_Error("CL_ParseServerInfo: Server is unrecognized protocol number (%i)", i);
357 // hack for unmarked Nehahra movie demos which had a custom protocol
358 if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
359 protocol = PROTOCOL_NEHAHRAMOVIE;
360 cl.protocol = protocol;
361 Con_DPrintf("Server protocol is %s\n", Protocol_NameForEnum(cl.protocol));
364 cl.maxclients = MSG_ReadByte ();
365 if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
367 Host_Error("Bad maxclients (%u) from server", cl.maxclients);
370 cl.scores = (scoreboard_t *)Mem_Alloc(cl_mempool, cl.maxclients*sizeof(*cl.scores));
373 cl.gametype = MSG_ReadByte ();
375 // parse signon message
376 str = MSG_ReadString ();
377 strlcpy (cl.levelname, str, sizeof(cl.levelname));
379 // seperate the printfs so the server message can have a color
380 if (cl.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
381 Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n\2%s\n", str);
383 // check memory integrity
384 Mem_CheckSentinelsGlobal();
387 // if server is active, we already began a loading plaque
389 SCR_BeginLoadingPlaque();
391 // disable until we get textures for it
394 memset(cl.csqc_model_precache, 0, sizeof(cl.csqc_model_precache)); //[515]: csqc
395 memset(cl.model_precache, 0, sizeof(cl.model_precache));
396 memset(cl.sound_precache, 0, sizeof(cl.sound_precache));
398 // parse model precache list
399 for (nummodels=1 ; ; nummodels++)
401 str = MSG_ReadString();
404 if (nummodels==MAX_MODELS)
405 Host_Error ("Server sent too many model precaches");
406 if (strlen(str) >= MAX_QPATH)
407 Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
408 strlcpy (parse_model_precache[nummodels], str, sizeof (parse_model_precache[nummodels]));
410 // parse sound precache list
411 for (numsounds=1 ; ; numsounds++)
413 str = MSG_ReadString();
416 if (numsounds==MAX_SOUNDS)
417 Host_Error("Server sent too many sound precaches");
418 if (strlen(str) >= MAX_QPATH)
419 Host_Error("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
420 strlcpy (parse_sound_precache[numsounds], str, sizeof (parse_sound_precache[numsounds]));
423 // touch all of the precached models that are still loaded so we can free
424 // anything that isn't needed
426 for (i = 1;i < nummodels;i++)
427 Mod_FindName(parse_model_precache[i]);
428 // precache any models used by the client (this also marks them used)
429 cl.model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
430 cl.model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
431 cl.model_bolt3 = Mod_ForName("progs/bolt3.mdl", false, false, false);
432 cl.model_beam = Mod_ForName("progs/beam.mdl", false, false, false);
435 // do the same for sounds
436 // FIXME: S_ServerSounds does not know about cl.sfx_ sounds
437 S_ServerSounds (parse_sound_precache, numsounds);
439 // precache any sounds used by the client
440 cl.sfx_wizhit = S_PrecacheSound("sound/wizard/hit.wav", false, true);
441 cl.sfx_knighthit = S_PrecacheSound("sound/hknight/hit.wav", false, true);
442 cl.sfx_tink1 = S_PrecacheSound("sound/weapons/tink1.wav", false, true);
443 cl.sfx_ric1 = S_PrecacheSound("sound/weapons/ric1.wav", false, true);
444 cl.sfx_ric2 = S_PrecacheSound("sound/weapons/ric2.wav", false, true);
445 cl.sfx_ric3 = S_PrecacheSound("sound/weapons/ric3.wav", false, true);
446 cl.sfx_r_exp3 = S_PrecacheSound("sound/weapons/r_exp3.wav", false, true);
448 // now we try to load everything that is new
451 CL_KeepaliveMessage ();
452 cl.model_precache[1] = Mod_ForName(parse_model_precache[1], false, false, true);
453 if (cl.model_precache[1]->Draw == NULL)
454 Con_Printf("Map %s not found\n", parse_model_precache[1]);
457 for (i=2 ; i<nummodels ; i++)
459 CL_KeepaliveMessage();
460 if ((cl.model_precache[i] = Mod_ForName(parse_model_precache[i], false, false, false))->Draw == NULL)
461 Con_Printf("Model %s not found\n", parse_model_precache[i]);
465 for (i=1 ; i<numsounds ; i++)
467 CL_KeepaliveMessage();
469 // Don't lock the sfx here, S_ServerSounds already did that
470 cl.sound_precache[i] = S_PrecacheSound (parse_sound_precache[i], true, false);
474 ent = &cl_entities[0];
475 // entire entity array was cleared, so just fill in a few fields
476 ent->state_current.active = true;
477 ent->render.model = cl.worldmodel = cl.model_precache[1];
478 ent->render.scale = 1; // some of the renderer still relies on scale
479 ent->render.alpha = 1;
480 ent->render.colormap = -1; // no special coloring
481 ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
482 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
483 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
484 CL_BoundingBoxForEntity(&ent->render);
491 // noclip is turned off at start
492 noclip_anglehack = false;
494 // check memory integrity
495 Mem_CheckSentinelsGlobal();
498 void CL_ValidateState(entity_state_t *s)
505 if (s->modelindex >= MAX_MODELS && (65536-s->modelindex) >= MAX_MODELS)
506 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
508 // colormap is client index + 1
509 if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
511 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
515 model = cl.model_precache[s->modelindex];
516 if (model && model->type && s->frame >= model->numframes)
518 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
521 if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
523 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
528 void CL_MoveLerpEntityStates(entity_t *ent)
530 float odelta[3], adelta[3];
531 CL_ValidateState(&ent->state_current);
532 VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
533 VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
534 if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
536 // reset all persistent stuff if this is a new entity
537 ent->persistent.lerpdeltatime = 0;
538 ent->persistent.lerpstarttime = cl.mtime[1];
539 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
540 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
541 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
542 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
543 // reset animation interpolation as well
544 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
545 ent->render.frame1time = ent->render.frame2time = cl.time;
546 ent->render.framelerp = 1;
547 // reset various persistent stuff
548 ent->persistent.muzzleflash = 0;
549 VectorCopy(ent->state_current.origin, ent->persistent.trail_origin);
551 else if (cls.timedemo || cl_nolerp.integer || DotProduct(odelta, odelta) > 1000*1000)
553 // don't interpolate the move
554 ent->persistent.lerpdeltatime = 0;
555 ent->persistent.lerpstarttime = cl.mtime[1];
556 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
557 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
558 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
559 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
561 else if (ent->state_current.flags & RENDER_STEP)
563 // monster interpolation
564 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
566 ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
567 ent->persistent.lerpstarttime = cl.mtime[1];
568 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
569 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
570 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
571 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
577 ent->persistent.lerpstarttime = ent->state_previous.time;
578 // no lerp if it's singleplayer
579 if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
580 ent->persistent.lerpdeltatime = 0;
582 ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
583 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
584 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
585 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
586 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
595 void CL_ParseBaseline (entity_t *ent, int large)
599 ent->state_baseline = defaultstate;
600 // FIXME: set ent->state_baseline.number?
601 ent->state_baseline.active = true;
604 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
605 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
609 ent->state_baseline.modelindex = MSG_ReadByte ();
610 ent->state_baseline.frame = MSG_ReadByte ();
612 ent->state_baseline.colormap = MSG_ReadByte();
613 ent->state_baseline.skin = MSG_ReadByte();
614 for (i = 0;i < 3;i++)
616 ent->state_baseline.origin[i] = MSG_ReadCoord(cl.protocol);
617 ent->state_baseline.angles[i] = MSG_ReadAngle(cl.protocol);
619 CL_ValidateState(&ent->state_baseline);
620 ent->state_previous = ent->state_current = ent->state_baseline;
628 Server information pertaining to this client only
631 void CL_ParseClientdata (void)
635 VectorCopy (cl.mpunchangle[0], cl.mpunchangle[1]);
636 VectorCopy (cl.mpunchvector[0], cl.mpunchvector[1]);
637 VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
638 cl.mviewzoom[1] = cl.mviewzoom[0];
640 if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
642 cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
643 cl.stats[STAT_ITEMS] = 0;
644 cl.stats[STAT_VIEWZOOM] = 255;
647 cl.mpunchangle[0][0] = 0;
648 cl.mpunchangle[0][1] = 0;
649 cl.mpunchangle[0][2] = 0;
650 cl.mpunchvector[0][0] = 0;
651 cl.mpunchvector[0][1] = 0;
652 cl.mpunchvector[0][2] = 0;
653 cl.mvelocity[0][0] = 0;
654 cl.mvelocity[0][1] = 0;
655 cl.mvelocity[0][2] = 0;
658 bits = (unsigned short) MSG_ReadShort ();
659 if (bits & SU_EXTEND1)
660 bits |= (MSG_ReadByte() << 16);
661 if (bits & SU_EXTEND2)
662 bits |= (MSG_ReadByte() << 24);
664 if (bits & SU_VIEWHEIGHT)
665 cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
667 if (bits & SU_IDEALPITCH)
668 cl.idealpitch = MSG_ReadChar ();
670 for (i = 0;i < 3;i++)
672 if (bits & (SU_PUNCH1<<i) )
674 if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE)
675 cl.mpunchangle[0][i] = MSG_ReadChar();
677 cl.mpunchangle[0][i] = MSG_ReadAngle16i();
679 if (bits & (SU_PUNCHVEC1<<i))
681 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
682 cl.mpunchvector[0][i] = MSG_ReadCoord16i();
684 cl.mpunchvector[0][i] = MSG_ReadCoord32f();
686 if (bits & (SU_VELOCITY1<<i) )
688 if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
689 cl.mvelocity[0][i] = MSG_ReadChar()*16;
691 cl.mvelocity[0][i] = MSG_ReadCoord32f();
695 // LordHavoc: hipnotic demos don't have this bit set but should
696 if (bits & SU_ITEMS || cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
697 cl.stats[STAT_ITEMS] = MSG_ReadLong ();
699 cl.onground = (bits & SU_ONGROUND) != 0;
700 csqc_onground = cl.onground; //[515]: cause without this csqc will receive not right value on svc_print =/
701 cl.inwater = (bits & SU_INWATER) != 0;
703 if (cl.protocol == PROTOCOL_DARKPLACES5)
705 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
706 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
707 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
708 cl.stats[STAT_HEALTH] = MSG_ReadShort();
709 cl.stats[STAT_AMMO] = MSG_ReadShort();
710 cl.stats[STAT_SHELLS] = MSG_ReadShort();
711 cl.stats[STAT_NAILS] = MSG_ReadShort();
712 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
713 cl.stats[STAT_CELLS] = MSG_ReadShort();
714 cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
716 else if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_QUAKEDP || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
718 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
719 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
720 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
721 cl.stats[STAT_HEALTH] = MSG_ReadShort();
722 cl.stats[STAT_AMMO] = MSG_ReadByte();
723 cl.stats[STAT_SHELLS] = MSG_ReadByte();
724 cl.stats[STAT_NAILS] = MSG_ReadByte();
725 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
726 cl.stats[STAT_CELLS] = MSG_ReadByte();
727 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
728 cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
730 cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
733 if (bits & SU_VIEWZOOM)
735 if (cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
736 cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
738 cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
741 // check for important changes
744 if (cl.olditems != cl.stats[STAT_ITEMS])
745 for (j = 0;j < 32;j++)
746 if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
747 cl.item_gettime[j] = cl.time;
748 cl.olditems = cl.stats[STAT_ITEMS];
750 // GAME_NEXUIZ hud needs weapon change time
751 if (cl.activeweapon != cl.stats[STAT_ACTIVEWEAPON])
752 cl.weapontime = cl.time;
753 cl.activeweapon = cl.stats[STAT_ACTIVEWEAPON];
755 // viewzoom interpolation
756 cl.mviewzoom[0] = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
760 =====================
762 =====================
764 void CL_ParseStatic (int large)
768 if (cl_num_static_entities >= cl_max_static_entities)
769 Host_Error ("Too many static entities");
770 ent = &cl_static_entities[cl_num_static_entities++];
771 CL_ParseBaseline (ent, large);
773 // copy it to the current state
774 ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
775 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
776 ent->render.framelerp = 0;
777 // make torchs play out of sync
778 ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
779 ent->render.colormap = -1; // no special coloring
780 ent->render.skinnum = ent->state_baseline.skin;
781 ent->render.effects = ent->state_baseline.effects;
782 ent->render.alpha = 1;
783 //ent->render.scale = 1;
785 //VectorCopy (ent->state_baseline.origin, ent->render.origin);
786 //VectorCopy (ent->state_baseline.angles, ent->render.angles);
788 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, ent->state_baseline.origin[0], ent->state_baseline.origin[1], ent->state_baseline.origin[2], ent->state_baseline.angles[0], ent->state_baseline.angles[1], ent->state_baseline.angles[2], 1);
789 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
790 CL_BoundingBoxForEntity(&ent->render);
792 // This is definitely cheating...
793 if (ent->render.model == NULL)
794 cl_num_static_entities--;
802 void CL_ParseStaticSound (int large)
805 int sound_num, vol, atten;
807 MSG_ReadVector(org, cl.protocol);
809 sound_num = (unsigned short) MSG_ReadShort ();
811 sound_num = MSG_ReadByte ();
812 vol = MSG_ReadByte ();
813 atten = MSG_ReadByte ();
815 S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
818 void CL_ParseEffect (void)
821 int modelindex, startframe, framecount, framerate;
823 MSG_ReadVector(org, cl.protocol);
824 modelindex = MSG_ReadByte ();
825 startframe = MSG_ReadByte ();
826 framecount = MSG_ReadByte ();
827 framerate = MSG_ReadByte ();
829 CL_Effect(org, modelindex, startframe, framecount, framerate);
832 void CL_ParseEffect2 (void)
835 int modelindex, startframe, framecount, framerate;
837 MSG_ReadVector(org, cl.protocol);
838 modelindex = (unsigned short) MSG_ReadShort ();
839 startframe = (unsigned short) MSG_ReadShort ();
840 framecount = MSG_ReadByte ();
841 framerate = MSG_ReadByte ();
843 CL_Effect(org, modelindex, startframe, framecount, framerate);
846 void CL_ParseBeam (model_t *m, int lightning)
852 ent = (unsigned short) MSG_ReadShort ();
853 MSG_ReadVector(start, cl.protocol);
854 MSG_ReadVector(end, cl.protocol);
856 if (ent >= MAX_EDICTS)
858 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
862 if (ent >= cl_max_entities)
863 CL_ExpandEntities(ent);
865 // override any beam with the same entity
868 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
869 if (b->entity == ent)
871 // if the entity was not found then just replace an unused beam
872 if (i == cl_max_beams)
873 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
874 if (!b->model || b->endtime < cl.time)
876 if (i < cl_max_beams)
879 b->lightning = lightning;
881 b->endtime = cl.time + 0.2;
882 VectorCopy (start, b->start);
883 VectorCopy (end, b->end);
884 b->relativestartvalid = 0;
885 if (ent && cl_entities[ent].state_current.active)
888 matrix4x4_t matrix, imatrix;
889 if (ent == cl.viewentity && cl.movement)
890 p = &cl_entities[b->entity].state_previous;
892 p = &cl_entities[b->entity].state_current;
893 // not really valid yet, we need to get the orientation now
894 // (ParseBeam flagged this because it is received before
895 // entities are received, by now they have been received)
896 // note: because players create lightning in their think
897 // function (which occurs before movement), they actually
898 // have some lag in it's location, so compare to the
899 // previous player state, not the latest
900 Matrix4x4_CreateFromQuakeEntity(&matrix, p->origin[0], p->origin[1], p->origin[2], -p->angles[0], p->angles[1], p->angles[2], 1);
901 Matrix4x4_Invert_Simple(&imatrix, &matrix);
902 Matrix4x4_Transform(&imatrix, b->start, b->relativestart);
903 Matrix4x4_Transform(&imatrix, b->end, b->relativeend);
904 b->relativestartvalid = 1;
908 Con_Print("beam list overflow!\n");
911 void CL_ParseTempEntity(void)
919 int colorStart, colorLength, count;
920 float velspeed, radius;
921 unsigned char *tempcolor;
922 matrix4x4_t tempmatrix;
924 type = MSG_ReadByte();
928 // spike hitting wall
929 MSG_ReadVector(pos, cl.protocol);
930 CL_FindNonSolidLocation(pos, pos, 4);
931 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
932 //CL_AllocDlight(NULL, &tempmatrix, 100, 0.12f, 0.50f, 0.12f, 500, 0.2, 0, -1, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
933 CL_RunParticleEffect(pos, vec3_origin, 20, 30);
934 S_StartSound(-1, 0, cl.sfx_wizhit, pos, 1, 1);
938 // spike hitting wall
939 MSG_ReadVector(pos, cl.protocol);
940 CL_FindNonSolidLocation(pos, pos, 4);
941 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
942 //CL_AllocDlight(NULL, &tempmatrix, 100, 0.50f, 0.30f, 0.10f, 500, 0.2, 0, -1, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
943 CL_RunParticleEffect(pos, vec3_origin, 226, 20);
944 S_StartSound(-1, 0, cl.sfx_knighthit, pos, 1, 1);
948 // spike hitting wall
949 MSG_ReadVector(pos, cl.protocol);
950 CL_FindNonSolidLocation(pos, pos, 4);
951 if (cl_particles_quake.integer)
952 CL_RunParticleEffect(pos, vec3_origin, 0, 10);
953 else if (cl_particles_bulletimpacts.integer)
955 CL_SparkShower(pos, vec3_origin, 15, 1);
956 CL_Smoke(pos, vec3_origin, 15);
960 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
965 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
967 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
969 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
973 // quad spike hitting wall
974 MSG_ReadVector(pos, cl.protocol);
975 CL_FindNonSolidLocation(pos, pos, 4);
976 if (cl_particles_quake.integer)
977 CL_RunParticleEffect(pos, vec3_origin, 0, 10);
978 else if (cl_particles_bulletimpacts.integer)
980 CL_SparkShower(pos, vec3_origin, 15, 1);
981 CL_Smoke(pos, vec3_origin, 15);
984 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
985 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
987 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
992 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
994 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
996 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1000 // super spike hitting wall
1001 MSG_ReadVector(pos, cl.protocol);
1002 CL_FindNonSolidLocation(pos, pos, 4);
1003 if (cl_particles_quake.integer)
1004 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1005 else if (cl_particles_bulletimpacts.integer)
1007 CL_SparkShower(pos, vec3_origin, 30, 1);
1008 CL_Smoke(pos, vec3_origin, 30);
1012 S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
1017 S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
1019 S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
1021 S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
1024 case TE_SUPERSPIKEQUAD:
1025 // quad super spike hitting wall
1026 MSG_ReadVector(pos, cl.protocol);
1027 CL_FindNonSolidLocation(pos, pos, 4);
1028 if (cl_particles_quake.integer)
1029 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1030 else if (cl_particles_bulletimpacts.integer)
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 if (cl_particles_quake.integer)
1125 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1128 CL_SparkShower(pos, vec3_origin, 15, 1);
1129 CL_Smoke(pos, vec3_origin, 15);
1134 case TE_GUNSHOTQUAD:
1135 // quad bullet hitting wall
1136 MSG_ReadVector(pos, cl.protocol);
1137 CL_FindNonSolidLocation(pos, pos, 4);
1138 if (cl_particles_quake.integer)
1139 CL_RunParticleEffect(pos, vec3_origin, 0, 20);
1142 CL_SparkShower(pos, vec3_origin, 15, 1);
1143 CL_Smoke(pos, vec3_origin, 15);
1146 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1147 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1152 MSG_ReadVector(pos, cl.protocol);
1153 CL_FindNonSolidLocation(pos, pos, 10);
1154 CL_ParticleExplosion(pos);
1155 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
1156 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1157 CL_AllocDlight(NULL, &tempmatrix, 350, 4.0f, 2.0f, 0.50f, 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1158 if (gamemode != GAME_NEXUIZ)
1159 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1162 case TE_EXPLOSIONQUAD:
1163 // quad rocket explosion
1164 MSG_ReadVector(pos, cl.protocol);
1165 CL_FindNonSolidLocation(pos, pos, 10);
1166 CL_ParticleExplosion(pos);
1167 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1168 CL_AllocDlight(NULL, &tempmatrix, 350, 2.5f, 2.0f, 4.0f, 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1169 if (gamemode != GAME_NEXUIZ)
1170 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1174 // Nehahra movie colored lighting explosion
1175 MSG_ReadVector(pos, cl.protocol);
1176 CL_FindNonSolidLocation(pos, pos, 10);
1177 CL_ParticleExplosion(pos);
1178 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1179 color[0] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1180 color[1] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1181 color[2] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1182 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1183 if (gamemode != GAME_NEXUIZ)
1184 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1187 case TE_EXPLOSIONRGB:
1188 // colored lighting explosion
1189 MSG_ReadVector(pos, cl.protocol);
1190 CL_FindNonSolidLocation(pos, pos, 10);
1191 CL_ParticleExplosion(pos);
1192 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1193 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1194 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1195 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1196 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1197 if (gamemode != GAME_NEXUIZ)
1198 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1201 case TE_TAREXPLOSION:
1202 // tarbaby explosion
1203 MSG_ReadVector(pos, cl.protocol);
1204 CL_FindNonSolidLocation(pos, pos, 10);
1205 CL_BlobExplosion(pos);
1207 if (gamemode != GAME_NEXUIZ)
1208 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1209 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1210 CL_AllocDlight(NULL, &tempmatrix, 600, 1.6f, 0.8f, 2.0f, 1200, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1214 MSG_ReadVector(pos, cl.protocol);
1215 CL_FindNonSolidLocation(pos, pos, 10);
1216 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1217 CL_AllocDlight(NULL, &tempmatrix, 200, 2, 2, 2, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1220 case TE_CUSTOMFLASH:
1221 MSG_ReadVector(pos, cl.protocol);
1222 CL_FindNonSolidLocation(pos, pos, 4);
1223 radius = (MSG_ReadByte() + 1) * 8;
1224 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
1225 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1226 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1227 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1228 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1229 CL_AllocDlight(NULL, &tempmatrix, radius, color[0], color[1], color[2], radius / velspeed, velspeed, 0, -1, true, 1, 0.25, 1, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1233 MSG_ReadVector(pos, cl.protocol);
1234 MSG_ReadVector(dir, cl.protocol);
1235 count = MSG_ReadByte();
1236 CL_Flames(pos, dir, count);
1241 CL_ParseBeam(cl.model_bolt, true);
1246 CL_ParseBeam(cl.model_bolt2, true);
1251 CL_ParseBeam(cl.model_bolt3, false);
1256 // grappling hook beam
1257 CL_ParseBeam(cl.model_beam, false);
1261 // LordHavoc: for compatibility with the Nehahra movie...
1262 case TE_LIGHTNING4NEH:
1263 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
1267 MSG_ReadVector(pos, cl.protocol);
1272 MSG_ReadVector(pos, cl.protocol);
1273 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1274 CL_AllocDlight(NULL, &tempmatrix, 200, 1.0f, 1.0f, 1.0f, 600, 99.0f, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1275 CL_TeleportSplash(pos);
1279 // color mapped explosion
1280 MSG_ReadVector(pos, cl.protocol);
1281 CL_FindNonSolidLocation(pos, pos, 10);
1282 colorStart = MSG_ReadByte();
1283 colorLength = MSG_ReadByte();
1284 CL_ParticleExplosion2(pos, colorStart, colorLength);
1285 tempcolor = (unsigned char *)&palette_complete[(rand()%colorLength) + colorStart];
1286 color[0] = tempcolor[0] * (2.0f / 255.0f);
1287 color[1] = tempcolor[1] * (2.0f / 255.0f);
1288 color[2] = tempcolor[2] * (2.0f / 255.0f);
1289 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1290 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1291 if (gamemode != GAME_NEXUIZ)
1292 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1296 MSG_ReadVector(pos, cl.protocol);
1297 MSG_ReadVector(pos2, cl.protocol);
1298 MSG_ReadVector(dir, cl.protocol);
1299 CL_BeamParticle(pos, pos2, 8, 1, 1, 1, 1, 1);
1303 MSG_ReadVector(pos, cl.protocol);
1304 MSG_ReadVector(dir, cl.protocol);
1305 count = MSG_ReadByte();
1306 CL_FindNonSolidLocation(pos, pos, 4);
1307 CL_Tei_Smoke(pos, dir, count);
1310 case TE_TEI_BIGEXPLOSION:
1311 MSG_ReadVector(pos, cl.protocol);
1312 CL_FindNonSolidLocation(pos, pos, 10);
1313 CL_ParticleExplosion(pos);
1314 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1315 CL_AllocDlight(NULL, &tempmatrix, 500, 2.5f, 2.0f, 1.0f, 500, 9999, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1316 if (gamemode != GAME_NEXUIZ)
1317 S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
1320 case TE_TEI_PLASMAHIT:
1321 MSG_ReadVector(pos, cl.protocol);
1322 MSG_ReadVector(dir, cl.protocol);
1323 count = MSG_ReadByte();
1324 CL_FindNonSolidLocation(pos, pos, 5);
1325 CL_Tei_PlasmaHit(pos, dir, count);
1326 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1327 CL_AllocDlight(NULL, &tempmatrix, 500, 0.6, 1.2, 2.0f, 2000, 9999, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1331 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
1335 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
1338 void CL_VM_Init (void);
1339 qboolean CL_VM_Parse_TempEntity (void);
1340 void CL_VM_Parse_StuffCmd (const char *msg);
1341 void CL_VM_Parse_CenterPrint (const char *msg);
1342 void CSQC_AddPrintText (const char *msg);
1343 void CSQC_ReadEntities (void);
1345 static unsigned char cgamenetbuffer[65536];
1348 =====================
1349 CL_ParseServerMessage
1350 =====================
1352 int parsingerror = false;
1353 void CL_ParseServerMessage(void)
1357 protocolversion_t protocol;
1358 unsigned char cmdlog[32];
1359 char *cmdlogname[32], *temp;
1360 int cmdindex, cmdcount = 0;
1361 qboolean sendmove = false;
1363 if (cls.demorecording)
1364 CL_WriteDemoMessage ();
1366 cl.last_received_message = realtime;
1369 // if recording demos, copy the message out
1371 if (cl_shownet.integer == 1)
1372 Con_Printf("%f %i\n", realtime, net_message.cursize);
1373 else if (cl_shownet.integer == 2)
1374 Con_Print("------------------\n");
1376 cl.onground = false; // unless the server says otherwise
1378 // parse the message
1380 //MSG_BeginReading ();
1382 parsingerror = true;
1387 Host_Error ("CL_ParseServerMessage: Bad server message");
1389 cmd = MSG_ReadByte ();
1393 SHOWNET("END OF MESSAGE");
1394 break; // end of message
1397 cmdindex = cmdcount & 31;
1399 cmdlog[cmdindex] = cmd;
1401 // if the high bit of the command byte is set, it is a fast update
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;
1407 SHOWNET("fast update");
1408 if (cls.signon == SIGNONS - 1)
1410 // first update is the final signon stage
1411 cls.signon = SIGNONS;
1414 EntityFrameQuake_ReadEntity (cmd&127);
1418 SHOWNET(svc_strings[cmd]);
1419 cmdlogname[cmdindex] = svc_strings[cmd];
1420 if (!cmdlogname[cmdindex])
1422 // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
1424 cmdlogname[cmdindex] = temp;
1432 char description[32*64], temp[64];
1434 strcpy (description, "packet dump: ");
1438 count = cmdcount - i;
1442 dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
1443 strlcat (description, temp, sizeof (description));
1448 description[strlen(description)-1] = '\n'; // replace the last space with a newline
1449 Con_Print(description);
1450 Host_Error ("CL_ParseServerMessage: Illegible server message");
1455 if (cls.signon < SIGNONS)
1456 Con_Print("<-- server to client keepalive\n");
1460 cl.mtime[1] = cl.mtime[0];
1461 cl.mtime[0] = MSG_ReadFloat ();
1465 case svc_clientdata:
1466 CL_ParseClientdata();
1470 i = MSG_ReadLong ();
1471 protocol = Protocol_EnumForNumber(i);
1472 if (protocol == PROTOCOL_UNKNOWN)
1473 Host_Error("CL_ParseServerMessage: Server is unrecognized protocol number (%i)", i);
1474 // hack for unmarked Nehahra movie demos which had a custom protocol
1475 if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
1476 protocol = PROTOCOL_NEHAHRAMOVIE;
1477 cl.protocol = protocol;
1480 case svc_disconnect:
1481 Con_Printf ("Server disconnected\n");
1482 if (cls.demonum != -1)
1489 CSQC_AddPrintText(MSG_ReadString()); //[515]: csqc
1492 case svc_centerprint:
1493 CL_VM_Parse_CenterPrint(MSG_ReadString ()); //[515]: csqc
1497 CL_VM_Parse_StuffCmd(MSG_ReadString ()); //[515]: csqc
1504 case svc_serverinfo:
1505 CL_ParseServerInfo ();
1506 CL_VM_Init(); //[515]: init csqc
1510 for (i=0 ; i<3 ; i++)
1511 cl.viewangles[i] = MSG_ReadAngle (cl.protocol);
1515 cl.viewentity = (unsigned short)MSG_ReadShort ();
1516 if (cl.viewentity >= MAX_EDICTS)
1517 Host_Error("svc_setview >= MAX_EDICTS");
1518 if (cl.viewentity >= cl_max_entities)
1519 CL_ExpandEntities(cl.viewentity);
1520 // LordHavoc: assume first setview recieved is the real player entity
1521 if (!cl.playerentity)
1522 cl.playerentity = cl.viewentity;
1525 case svc_lightstyle:
1526 i = MSG_ReadByte ();
1527 if (i >= MAX_LIGHTSTYLES)
1528 Host_Error ("svc_lightstyle >= MAX_LIGHTSTYLES");
1529 strlcpy (cl_lightstyle[i].map, MSG_ReadString(), sizeof (cl_lightstyle[i].map));
1530 cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
1531 cl_lightstyle[i].length = (int)strlen(cl_lightstyle[i].map);
1535 CL_ParseStartSoundPacket(false);
1539 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1541 // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
1542 CL_ParseStartSoundPacket(true);
1546 int i = (unsigned short)MSG_ReadShort();
1547 char *s = MSG_ReadString();
1550 if (i >= 1 && i < MAX_MODELS)
1552 model_t *model = Mod_ForName(s, false, false, i == 1);
1554 Con_Printf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
1555 cl.model_precache[i] = model;
1558 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
1563 if (i >= 1 && i < MAX_SOUNDS)
1565 sfx_t *sfx = S_PrecacheSound (s, true, false);
1566 if (!sfx && snd_initialized.integer)
1567 Con_Printf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
1568 cl.sound_precache[i] = sfx;
1571 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
1577 i = (unsigned short) MSG_ReadShort();
1578 S_StopSound(i>>3, i&7);
1581 case svc_updatename:
1582 i = MSG_ReadByte ();
1583 if (i >= cl.maxclients)
1584 Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
1585 strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
1588 case svc_updatefrags:
1589 i = MSG_ReadByte ();
1590 if (i >= cl.maxclients)
1591 Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
1592 cl.scores[i].frags = (signed short) MSG_ReadShort ();
1595 case svc_updatecolors:
1596 i = MSG_ReadByte ();
1597 if (i >= cl.maxclients)
1598 Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
1599 cl.scores[i].colors = MSG_ReadByte ();
1603 CL_ParseParticleEffect ();
1614 case svc_spawnbaseline:
1615 i = (unsigned short) MSG_ReadShort ();
1616 if (i < 0 || i >= MAX_EDICTS)
1617 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
1618 if (i >= cl_max_entities)
1619 CL_ExpandEntities(i);
1620 CL_ParseBaseline (cl_entities + i, false);
1622 case svc_spawnbaseline2:
1623 i = (unsigned short) MSG_ReadShort ();
1624 if (i < 0 || i >= MAX_EDICTS)
1625 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
1626 if (i >= cl_max_entities)
1627 CL_ExpandEntities(i);
1628 CL_ParseBaseline (cl_entities + i, true);
1630 case svc_spawnstatic:
1631 CL_ParseStatic (false);
1633 case svc_spawnstatic2:
1634 CL_ParseStatic (true);
1636 case svc_temp_entity:
1637 if(!CL_VM_Parse_TempEntity())
1638 CL_ParseTempEntity ();
1642 cl.paused = MSG_ReadByte ();
1647 S_PauseGameSounds (cl.paused);
1651 i = MSG_ReadByte ();
1652 // LordHavoc: it's rude to kick off the client if they missed the
1653 // reconnect somehow, so allow signon 1 even if at signon 1
1654 if (i <= cls.signon && i != 1)
1655 Host_Error ("Received signon %i when at %i", i, cls.signon);
1660 case svc_killedmonster:
1661 cl.stats[STAT_MONSTERS]++;
1664 case svc_foundsecret:
1665 cl.stats[STAT_SECRETS]++;
1668 case svc_updatestat:
1669 i = MSG_ReadByte ();
1670 if (i < 0 || i >= MAX_CL_STATS)
1671 Host_Error ("svc_updatestat: %i is invalid", i);
1672 cl.stats[i] = MSG_ReadLong ();
1675 case svc_updatestatubyte:
1676 i = MSG_ReadByte ();
1677 if (i < 0 || i >= MAX_CL_STATS)
1678 Host_Error ("svc_updatestat: %i is invalid", i);
1679 cl.stats[i] = MSG_ReadByte ();
1682 case svc_spawnstaticsound:
1683 CL_ParseStaticSound (false);
1686 case svc_spawnstaticsound2:
1687 CL_ParseStaticSound (true);
1691 cl.cdtrack = MSG_ReadByte ();
1692 cl.looptrack = MSG_ReadByte ();
1693 if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
1694 CDAudio_Play ((unsigned char)cls.forcetrack, true);
1696 CDAudio_Play ((unsigned char)cl.cdtrack, true);
1699 case svc_intermission:
1700 cl.intermission = 1;
1701 cl.completed_time = cl.time;
1705 cl.intermission = 2;
1706 cl.completed_time = cl.time;
1707 SCR_CenterPrint(MSG_ReadString ());
1711 cl.intermission = 3;
1712 cl.completed_time = cl.time;
1713 SCR_CenterPrint(MSG_ReadString ());
1716 case svc_sellscreen:
1717 Cmd_ExecuteString ("help", src_command);
1720 if (gamemode == GAME_TENEBRAE)
1722 // repeating particle effect
1723 MSG_ReadCoord(cl.protocol);
1724 MSG_ReadCoord(cl.protocol);
1725 MSG_ReadCoord(cl.protocol);
1726 MSG_ReadCoord(cl.protocol);
1727 MSG_ReadCoord(cl.protocol);
1728 MSG_ReadCoord(cl.protocol);
1735 SHOWLMP_decodehide();
1738 if (gamemode == GAME_TENEBRAE)
1741 MSG_ReadCoord(cl.protocol);
1742 MSG_ReadCoord(cl.protocol);
1743 MSG_ReadCoord(cl.protocol);
1748 SHOWLMP_decodeshow();
1751 R_SetSkyBox(MSG_ReadString());
1756 length = (int) ((unsigned short) MSG_ReadShort());
1757 for (i = 0;i < length;i++)
1758 cgamenetbuffer[i] = MSG_ReadByte();
1760 CL_CGVM_ParseNetwork(cgamenetbuffer, length);
1764 if (cls.signon == SIGNONS - 1)
1766 // first update is the final signon stage
1767 cls.signon = SIGNONS;
1770 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1771 EntityFrame_CL_ReadFrame();
1772 else if (cl.protocol == PROTOCOL_DARKPLACES4)
1773 EntityFrame4_CL_ReadFrame();
1775 EntityFrame5_CL_ReadFrame();
1777 case svc_csqcentities:
1778 CSQC_ReadEntities();
1783 EntityFrameQuake_ISeeDeadEntities();
1787 // send one move per server frame
1791 parsingerror = false;
1794 void CL_Parse_DumpPacket(void)
1798 Con_Print("Packet dump:\n");
1799 SZ_HexDumpToConsole(&net_message);
1800 parsingerror = false;
1803 void CL_Parse_Init(void)
1805 // LordHavoc: added demo_nehahra cvar
1806 Cvar_RegisterVariable (&demo_nehahra);
1807 if (gamemode == GAME_NEHAHRA)
1808 Cvar_SetValue("demo_nehahra", 1);
1809 Cvar_RegisterVariable(&developer_networkentities);
1812 void CL_Parse_Shutdown(void)