2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // cl_parse.c -- parse a message received from the server
24 #include "cl_collision.h"
26 char *svc_strings[128] =
32 "svc_version", // [long] server version
33 "svc_setview", // [short] entity number
34 "svc_sound", // <see code>
35 "svc_time", // [float] server time
36 "svc_print", // [string] null terminated string
37 "svc_stufftext", // [string] stuffed into client's console buffer
38 // the string should be \n terminated
39 "svc_setangle", // [vec3] set the view angle to this absolute value
41 "svc_serverinfo", // [long] version
42 // [string] signon string
43 // [string]..[0]model cache [string]...[0]sounds cache
44 // [string]..[0]item cache
45 "svc_lightstyle", // [byte] [string]
46 "svc_updatename", // [byte] [string]
47 "svc_updatefrags", // [byte] [short]
48 "svc_clientdata", // <shortbits + data>
49 "svc_stopsound", // <see code>
50 "svc_updatecolors", // [byte] [byte]
51 "svc_particle", // [vec3] <variable>
52 "svc_damage", // [byte] impact [byte] blood [vec3] from
55 "OBSOLETE svc_spawnbinary",
58 "svc_temp_entity", // <variable>
64 "svc_spawnstaticsound",
66 "svc_finale", // [string] music [string] text
67 "svc_cdtrack", // [byte] track [byte] looptrack
70 "svc_showlmp", // [string] iconlabel [string] lmpfile [short] x [short] y
71 "svc_hidelmp", // [string] iconlabel
72 "svc_skybox", // [string] skyname
85 "svc_cgame", // 50 // [short] length [bytes] data
86 "svc_unusedlh1", // 51 // unused
87 "svc_effect", // 52 // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate
88 "svc_effect2", // 53 // [vector] org [short] modelindex [short] startframe [byte] framecount [byte] framerate
89 "svc_sound2", // 54 // short soundindex instead of byte
90 "svc_spawnbaseline2", // 55 // short modelindex instead of byte
91 "svc_spawnstatic2", // 56 // short modelindex instead of byte
92 "svc_entities", // 57 // [int] deltaframe [int] thisframe [float vector] eye [variable length] entitydata
93 "svc_unusedlh3", // 58
94 "svc_spawnstaticsound2", // 59 // [coord3] [short] samp [byte] vol [byte] aten
97 //=============================================================================
99 cvar_t demo_nehahra = {0, "demo_nehahra", "0"};
100 cvar_t developer_networkentities = {0, "developer_networkentities", "0"};
102 mempool_t *cl_scores_mempool;
106 CL_ParseStartSoundPacket
109 void CL_ParseStartSoundPacket(int largesoundindex)
118 field_mask = MSG_ReadByte();
120 if (field_mask & SND_VOLUME)
121 volume = MSG_ReadByte ();
123 volume = DEFAULT_SOUND_PACKET_VOLUME;
125 if (field_mask & SND_ATTENUATION)
126 attenuation = MSG_ReadByte () / 64.0;
128 attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
130 if (field_mask & SND_LARGEENTITY)
132 ent = (unsigned short) MSG_ReadShort ();
133 channel = MSG_ReadByte ();
137 channel = (unsigned short) MSG_ReadShort ();
142 if (largesoundindex || field_mask & SND_LARGESOUND)
143 sound_num = (unsigned short) MSG_ReadShort ();
145 sound_num = MSG_ReadByte ();
147 if (sound_num >= MAX_SOUNDS)
148 Host_Error("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
151 if (ent >= MAX_EDICTS)
152 Host_Error ("CL_ParseStartSoundPacket: ent = %i", ent);
154 MSG_ReadVector(pos, cl.protocol);
156 S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation);
163 When the client is taking a long time to load stuff, send keepalive messages
164 so the server doesn't disconnect.
168 static qbyte olddata[NET_MAXMESSAGE];
169 void CL_KeepaliveMessage (void)
172 static float lastmsg;
177 // no need if server is local and definitely not if this is a demo
178 if (sv.active || cls.demoplayback)
181 // read messages from server, should just be nops
182 oldreadcount = msg_readcount;
183 oldbadread = msg_badread;
185 memcpy(olddata, net_message.data, net_message.cursize);
187 NetConn_ClientFrame();
189 msg_readcount = oldreadcount;
190 msg_badread = oldbadread;
192 memcpy(net_message.data, olddata, net_message.cursize);
194 if (cls.netcon && NetConn_CanSendMessage(cls.netcon) && (time = Sys_DoubleTime()) - lastmsg >= 5)
200 // LordHavoc: must use unreliable because reliable could kill the sigon message!
201 Con_Print("--> client to server keepalive\n");
203 msg.maxsize = sizeof(buf);
205 MSG_WriteChar(&msg, svc_nop);
206 NetConn_SendUnreliableMessage(cls.netcon, &msg);
207 // try not to utterly crush the computer with work, that's just rude
212 void CL_ParseEntityLump(char *entdata)
215 char key[128], value[4096];
216 FOG_clear(); // LordHavoc: no fog until set
217 // LordHavoc: default to the map's sky (q3 shader parsing sets this)
218 R_SetSkyBox(cl.worldmodel->brush.skybox);
222 if (!COM_ParseToken(&data, false))
224 if (com_token[0] != '{')
228 if (!COM_ParseToken(&data, false))
230 if (com_token[0] == '}')
231 break; // end of worldspawn
232 if (com_token[0] == '_')
233 strlcpy (key, com_token + 1, sizeof (key));
235 strlcpy (key, com_token, sizeof (key));
236 while (key[strlen(key)-1] == ' ') // remove trailing spaces
237 key[strlen(key)-1] = 0;
238 if (!COM_ParseToken(&data, false))
240 strlcpy (value, com_token, sizeof (value));
241 if (!strcmp("sky", key))
243 else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
245 else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
247 else if (!strcmp("fog", key))
248 sscanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue);
249 else if (!strcmp("fog_density", key))
250 fog_density = atof(value);
251 else if (!strcmp("fog_red", key))
252 fog_red = atof(value);
253 else if (!strcmp("fog_green", key))
254 fog_green = atof(value);
255 else if (!strcmp("fog_blue", key))
256 fog_blue = atof(value);
261 =====================
264 An svc_signonnum has been received, perform a client side setup
265 =====================
267 static void CL_SignonReply (void)
271 Con_DPrintf("CL_SignonReply: %i\n", cls.signon);
276 MSG_WriteByte (&cls.message, clc_stringcmd);
277 MSG_WriteString (&cls.message, "prespawn");
281 MSG_WriteByte (&cls.message, clc_stringcmd);
282 MSG_WriteString (&cls.message, va("name \"%s\"\n", cl_name.string));
284 MSG_WriteByte (&cls.message, clc_stringcmd);
285 MSG_WriteString (&cls.message, va("color %i %i\n", cl_color.integer >> 4, cl_color.integer & 15));
287 if (cl_pmodel.integer)
289 MSG_WriteByte (&cls.message, clc_stringcmd);
290 MSG_WriteString (&cls.message, va("pmodel %i\n", cl_pmodel.integer));
293 MSG_WriteByte (&cls.message, clc_stringcmd);
294 MSG_WriteString (&cls.message, va("rate %i\n", cl_rate.integer));
296 MSG_WriteByte (&cls.message, clc_stringcmd);
297 MSG_WriteString (&cls.message, "spawn");
301 MSG_WriteByte (&cls.message, clc_stringcmd);
302 MSG_WriteString (&cls.message, "begin");
316 // FIXME: this is a lot of memory to be keeping around, this needs to be dynamically allocated and freed
317 static char parse_model_precache[MAX_MODELS][MAX_QPATH];
318 static char parse_sound_precache[MAX_SOUNDS][MAX_QPATH];
319 void CL_ParseServerInfo (void)
323 int nummodels, numsounds;
326 Con_DPrint("Serverinfo packet received.\n");
328 // wipe the client_state_t struct
332 // parse protocol version number
334 // hack for unmarked Nehahra movie demos which had a custom protocol
335 if (i == PROTOCOL_QUAKE && cls.demoplayback && demo_nehahra.integer)
336 i = PROTOCOL_NEHAHRAMOVIE;
337 if (i != PROTOCOL_QUAKE && i != PROTOCOL_DARKPLACES1 && i != PROTOCOL_DARKPLACES2 && i != PROTOCOL_DARKPLACES3 && i != PROTOCOL_DARKPLACES4 && i != PROTOCOL_DARKPLACES5 && i != PROTOCOL_NEHAHRAMOVIE)
339 Host_Error("CL_ParseServerInfo: Server is protocol %i, not %i (Quake), %i (DP1), %i (DP2), %i (DP3), %i (DP4), %i (DP5), or %i (Nehahra movie)", i, PROTOCOL_QUAKE, PROTOCOL_DARKPLACES1, PROTOCOL_DARKPLACES2, PROTOCOL_DARKPLACES3, PROTOCOL_DARKPLACES4, PROTOCOL_DARKPLACES5, PROTOCOL_NEHAHRAMOVIE);
343 Con_DPrintf("Protocol %i\n", cl.protocol);
346 cl.maxclients = MSG_ReadByte ();
347 if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
349 Con_Printf("Bad maxclients (%u) from server\n", cl.maxclients);
352 Mem_EmptyPool(cl_scores_mempool);
353 cl.scores = Mem_Alloc(cl_scores_mempool, cl.maxclients*sizeof(*cl.scores));
356 cl.gametype = MSG_ReadByte ();
358 // parse signon message
359 str = MSG_ReadString ();
360 strlcpy (cl.levelname, str, sizeof(cl.levelname));
362 // seperate the printfs so the server message can have a color
363 if (cl.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
364 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);
366 // check memory integrity
367 Mem_CheckSentinelsGlobal();
369 // disable until we get textures for it
372 memset(cl.model_precache, 0, sizeof(cl.model_precache));
373 memset(cl.sound_precache, 0, sizeof(cl.sound_precache));
375 // parse model precache list
376 for (nummodels=1 ; ; nummodels++)
378 str = MSG_ReadString();
381 if (nummodels==MAX_MODELS)
382 Host_Error ("Server sent too many model precaches\n");
383 if (strlen(str) >= MAX_QPATH)
384 Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
385 strlcpy (parse_model_precache[nummodels], str, sizeof (parse_model_precache[nummodels]));
387 // parse sound precache list
388 for (numsounds=1 ; ; numsounds++)
390 str = MSG_ReadString();
393 if (numsounds==MAX_SOUNDS)
394 Host_Error("Server sent too many sound precaches\n");
395 if (strlen(str) >= MAX_QPATH)
396 Host_Error("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
397 strlcpy (parse_sound_precache[numsounds], str, sizeof (parse_sound_precache[numsounds]));
400 // touch all of the precached models that are still loaded so we can free
401 // anything that isn't needed
403 for (i = 1;i < nummodels;i++)
405 CL_KeepaliveMessage();
406 Mod_FindName(parse_model_precache[i]);
410 // do the same for sounds
411 S_ServerSounds (parse_sound_precache, numsounds);
413 // now we try to load everything that is new
416 CL_KeepaliveMessage ();
417 cl.model_precache[1] = Mod_ForName(parse_model_precache[1], false, false, true);
418 if (cl.model_precache[1] == NULL)
419 Con_Printf("Map %s not found\n", parse_model_precache[1]);
422 for (i=2 ; i<nummodels ; i++)
424 CL_KeepaliveMessage();
425 if ((cl.model_precache[i] = Mod_ForName(parse_model_precache[i], false, false, false)) == NULL)
426 Con_Printf("Model %s not found\n", parse_model_precache[i]);
430 for (i=1 ; i<numsounds ; i++)
432 CL_KeepaliveMessage();
434 // Don't lock the sfx here, S_ServerSounds already did that
435 cl.sound_precache[i] = S_PrecacheSound (parse_sound_precache[i], true, false);
439 ent = &cl_entities[0];
440 // entire entity array was cleared, so just fill in a few fields
441 ent->state_current.active = true;
442 ent->render.model = cl.worldmodel = cl.model_precache[1];
443 ent->render.scale = 1; // some of the renderer still relies on scale
444 ent->render.alpha = 1;
445 ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
446 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
447 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
448 CL_BoundingBoxForEntity(&ent->render);
455 // noclip is turned off at start
456 noclip_anglehack = false;
458 // check memory integrity
459 Mem_CheckSentinelsGlobal();
462 void CL_ValidateState(entity_state_t *s)
469 if (s->modelindex >= MAX_MODELS)
470 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
472 // colormap is client index + 1
473 if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
475 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
479 model = cl.model_precache[s->modelindex];
480 Mod_CheckLoaded(model);
481 if (model && model->type && s->frame >= model->numframes)
483 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
486 if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
488 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
493 void CL_MoveLerpEntityStates(entity_t *ent)
495 float odelta[3], adelta[3];
496 CL_ValidateState(&ent->state_current);
497 VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
498 VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
499 if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
501 // reset all persistent stuff if this is a new entity
502 ent->persistent.lerpdeltatime = 0;
503 ent->persistent.lerpstarttime = cl.mtime[1];
504 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
505 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
506 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
507 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
508 // reset animation interpolation as well
509 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
510 ent->render.frame1time = ent->render.frame2time = cl.time;
511 ent->render.framelerp = 1;
512 // reset various persistent stuff
513 ent->persistent.muzzleflash = 0;
514 VectorCopy(ent->state_current.origin, ent->persistent.trail_origin);
516 else if (cls.timedemo || cl_nolerp.integer || DotProduct(odelta, odelta) > 1000*1000)
518 // don't interpolate the move
519 ent->persistent.lerpdeltatime = 0;
520 ent->persistent.lerpstarttime = cl.mtime[1];
521 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
522 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
523 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
524 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
526 else if (ent->state_current.flags & RENDER_STEP)
528 // monster interpolation
529 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
531 ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
532 ent->persistent.lerpstarttime = cl.mtime[1];
533 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
534 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
535 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
536 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
542 ent->persistent.lerpstarttime = ent->state_previous.time;
543 // no lerp if it's singleplayer
545 ent->persistent.lerpdeltatime = 0;
547 ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
548 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
549 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
550 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
551 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
560 void CL_ParseBaseline (entity_t *ent, int large)
564 ent->state_baseline = defaultstate;
565 // FIXME: set ent->state_baseline.number?
566 ent->state_baseline.active = true;
569 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
570 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
574 ent->state_baseline.modelindex = MSG_ReadByte ();
575 ent->state_baseline.frame = MSG_ReadByte ();
577 ent->state_baseline.colormap = MSG_ReadByte();
578 ent->state_baseline.skin = MSG_ReadByte();
579 for (i = 0;i < 3;i++)
581 ent->state_baseline.origin[i] = MSG_ReadCoord(cl.protocol);
582 ent->state_baseline.angles[i] = MSG_ReadAngle(cl.protocol);
584 CL_ValidateState(&ent->state_baseline);
585 ent->state_previous = ent->state_current = ent->state_baseline;
593 Server information pertaining to this client only
596 void CL_ParseClientdata (int bits)
601 if (bits & SU_EXTEND1)
602 bits |= (MSG_ReadByte() << 16);
603 if (bits & SU_EXTEND2)
604 bits |= (MSG_ReadByte() << 24);
606 if (bits & SU_VIEWHEIGHT)
607 cl.viewheight = MSG_ReadChar ();
609 cl.viewheight = DEFAULT_VIEWHEIGHT;
611 if (bits & SU_IDEALPITCH)
612 cl.idealpitch = MSG_ReadChar ();
616 VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
617 for (i = 0;i < 3;i++)
619 if (bits & (SU_PUNCH1<<i) )
621 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5)
622 cl.punchangle[i] = MSG_ReadAngle16i();
623 else if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_NEHAHRAMOVIE)
624 cl.punchangle[i] = MSG_ReadChar();
626 Host_Error("CL_ParseClientData: unknown cl.protocol %i\n", cl.protocol);
629 cl.punchangle[i] = 0;
630 if (bits & (SU_PUNCHVEC1<<i))
632 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
633 cl.punchvector[i] = MSG_ReadCoord16i();
634 else if (cl.protocol == PROTOCOL_DARKPLACES5)
635 cl.punchvector[i] = MSG_ReadCoord32f();
637 Host_Error("CL_ParseClientData: unknown cl.protocol %i\n", cl.protocol);
640 cl.punchvector[i] = 0;
641 if (bits & (SU_VELOCITY1<<i) )
643 if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_NEHAHRAMOVIE || cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
644 cl.mvelocity[0][i] = MSG_ReadChar()*16;
645 else if (cl.protocol == PROTOCOL_DARKPLACES5)
646 cl.mvelocity[0][i] = MSG_ReadCoord32f();
648 Host_Error("CL_ParseClientData: unknown cl.protocol %i\n", cl.protocol);
651 cl.mvelocity[0][i] = 0;
657 for (j=0 ; j<32 ; j++)
658 if ( (i & (1<<j)) && !(cl.items & (1<<j)))
659 cl.item_gettime[j] = cl.time;
663 cl.onground = (bits & SU_ONGROUND) != 0;
664 cl.inwater = (bits & SU_INWATER) != 0;
666 if (cl.protocol == PROTOCOL_DARKPLACES5)
668 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
669 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
670 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
671 cl.stats[STAT_HEALTH] = MSG_ReadShort();
672 cl.stats[STAT_AMMO] = MSG_ReadShort();
674 cl.stats[STAT_SHELLS] = MSG_ReadShort();
675 cl.stats[STAT_NAILS] = MSG_ReadShort();
676 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
677 cl.stats[STAT_CELLS] = MSG_ReadShort();
678 //cl.stats[STAT_GENERIC1] = MSG_ReadShort();
679 //cl.stats[STAT_GENERIC2] = MSG_ReadShort();
680 //cl.stats[STAT_GENERIC3] = MSG_ReadShort();
681 //cl.stats[STAT_GENERIC4] = MSG_ReadShort();
682 //cl.stats[STAT_GENERIC5] = MSG_ReadShort();
683 //cl.stats[STAT_GENERIC6] = MSG_ReadShort();
685 i = (unsigned short) MSG_ReadShort ();
689 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
690 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
691 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
692 cl.stats[STAT_HEALTH] = MSG_ReadShort();
693 cl.stats[STAT_AMMO] = MSG_ReadByte();
695 cl.stats[STAT_SHELLS] = MSG_ReadByte();
696 cl.stats[STAT_NAILS] = MSG_ReadByte();
697 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
698 cl.stats[STAT_CELLS] = MSG_ReadByte();
701 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE)
705 // GAME_NEXUIZ hud needs weapon change time
706 // GAME_NEXUIZ uses a bit number as it's STAT_ACTIVEWEAPON, not a bitfield
708 if (cl.stats[STAT_ACTIVEWEAPON] != i)
709 cl.weapontime = cl.time;
710 cl.stats[STAT_ACTIVEWEAPON] = i;
712 cl.viewzoomold = cl.viewzoomnew; // for interpolation
713 if (bits & SU_VIEWZOOM)
715 if (cl.protocol == PROTOCOL_DARKPLACES5)
716 i = (unsigned short) MSG_ReadShort();
721 cl.viewzoomnew = (float) i * (1.0f / 255.0f);
729 =====================
731 =====================
733 void CL_ParseStatic (int large)
737 if (cl_num_static_entities >= cl_max_static_entities)
738 Host_Error ("Too many static entities");
739 ent = &cl_static_entities[cl_num_static_entities++];
740 CL_ParseBaseline (ent, large);
742 // copy it to the current state
743 ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
744 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
745 ent->render.framelerp = 0;
746 // make torchs play out of sync
747 ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
748 ent->render.colormap = -1; // no special coloring
749 ent->render.skinnum = ent->state_baseline.skin;
750 ent->render.effects = ent->state_baseline.effects;
751 ent->render.alpha = 1;
752 //ent->render.scale = 1;
754 //VectorCopy (ent->state_baseline.origin, ent->render.origin);
755 //VectorCopy (ent->state_baseline.angles, ent->render.angles);
757 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);
758 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
759 CL_BoundingBoxForEntity(&ent->render);
761 // This is definitely cheating...
762 if (ent->render.model == NULL)
763 cl_num_static_entities--;
771 void CL_ParseStaticSound (int large)
774 int sound_num, vol, atten;
776 MSG_ReadVector(org, cl.protocol);
778 sound_num = (unsigned short) MSG_ReadShort ();
780 sound_num = MSG_ReadByte ();
781 vol = MSG_ReadByte ();
782 atten = MSG_ReadByte ();
784 S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
787 void CL_ParseEffect (void)
790 int modelindex, startframe, framecount, framerate;
792 MSG_ReadVector(org, cl.protocol);
793 modelindex = MSG_ReadByte ();
794 startframe = MSG_ReadByte ();
795 framecount = MSG_ReadByte ();
796 framerate = MSG_ReadByte ();
798 CL_Effect(org, modelindex, startframe, framecount, framerate);
801 void CL_ParseEffect2 (void)
804 int modelindex, startframe, framecount, framerate;
806 MSG_ReadVector(org, cl.protocol);
807 modelindex = (unsigned short) MSG_ReadShort ();
808 startframe = (unsigned short) MSG_ReadShort ();
809 framecount = MSG_ReadByte ();
810 framerate = MSG_ReadByte ();
812 CL_Effect(org, modelindex, startframe, framecount, framerate);
815 model_t *cl_model_bolt = NULL;
816 model_t *cl_model_bolt2 = NULL;
817 model_t *cl_model_bolt3 = NULL;
818 model_t *cl_model_beam = NULL;
820 sfx_t *cl_sfx_wizhit;
821 sfx_t *cl_sfx_knighthit;
826 sfx_t *cl_sfx_r_exp3;
829 void CL_InitTEnts (void)
831 cl_sfx_wizhit = S_PrecacheSound ("sound/wizard/hit.wav", false, true);
832 cl_sfx_knighthit = S_PrecacheSound ("sound/hknight/hit.wav", false, true);
833 cl_sfx_tink1 = S_PrecacheSound ("sound/weapons/tink1.wav", false, true);
834 cl_sfx_ric1 = S_PrecacheSound ("sound/weapons/ric1.wav", false, true);
835 cl_sfx_ric2 = S_PrecacheSound ("sound/weapons/ric2.wav", false, true);
836 cl_sfx_ric3 = S_PrecacheSound ("sound/weapons/ric3.wav", false, true);
837 cl_sfx_r_exp3 = S_PrecacheSound ("sound/weapons/r_exp3.wav", false, true);
840 void CL_ParseBeam (model_t *m, int lightning)
846 ent = (unsigned short) MSG_ReadShort ();
847 MSG_ReadVector(start, cl.protocol);
848 MSG_ReadVector(end, cl.protocol);
850 if (ent >= MAX_EDICTS)
852 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
856 // override any beam with the same entity
857 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
859 if (b->entity == ent)
862 b->lightning = lightning;
863 b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
865 b->endtime = cl.time + 0.2;
866 VectorCopy (start, b->start);
867 VectorCopy (end, b->end);
873 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
875 if (!b->model || b->endtime < cl.time)
878 b->lightning = lightning;
879 b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
881 b->endtime = cl.time + 0.2;
882 VectorCopy (start, b->start);
883 VectorCopy (end, b->end);
887 Con_Print("beam list overflow!\n");
890 void CL_ParseTempEntity(void)
898 int colorStart, colorLength, count;
899 float velspeed, radius;
901 matrix4x4_t tempmatrix;
903 type = MSG_ReadByte();
907 // spike hitting wall
908 MSG_ReadVector(pos, cl.protocol);
909 CL_FindNonSolidLocation(pos, pos, 4);
910 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
911 CL_AllocDlight(NULL, &tempmatrix, 100, 0.12f, 0.50f, 0.12f, 500, 0.2, 0, 0, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
912 CL_RunParticleEffect(pos, vec3_origin, 20, 30);
913 S_StartSound(-1, 0, cl_sfx_wizhit, pos, 1, 1);
917 // spike hitting wall
918 MSG_ReadVector(pos, cl.protocol);
919 CL_FindNonSolidLocation(pos, pos, 4);
920 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
921 CL_AllocDlight(NULL, &tempmatrix, 100, 0.50f, 0.30f, 0.10f, 500, 0.2, 0, 0, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
922 CL_RunParticleEffect(pos, vec3_origin, 226, 20);
923 S_StartSound(-1, 0, cl_sfx_knighthit, pos, 1, 1);
927 // spike hitting wall
928 MSG_ReadVector(pos, cl.protocol);
929 CL_FindNonSolidLocation(pos, pos, 4);
930 if (cl_particles_bulletimpacts.integer)
932 CL_SparkShower(pos, vec3_origin, 15, 1);
933 CL_Smoke(pos, vec3_origin, 15);
937 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
942 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
944 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
946 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
950 // quad spike hitting wall
951 MSG_ReadVector(pos, cl.protocol);
952 CL_FindNonSolidLocation(pos, pos, 4);
953 // LordHavoc: changed to spark shower
954 if (cl_particles_bulletimpacts.integer)
956 CL_SparkShower(pos, vec3_origin, 15, 1);
957 CL_Smoke(pos, vec3_origin, 15);
960 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
961 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, 0, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
962 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
964 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
969 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
971 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
973 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
977 // super spike hitting wall
978 MSG_ReadVector(pos, cl.protocol);
979 CL_FindNonSolidLocation(pos, pos, 4);
980 // LordHavoc: changed to dust shower
981 if (cl_particles_bulletimpacts.integer)
983 CL_SparkShower(pos, vec3_origin, 30, 1);
984 CL_Smoke(pos, vec3_origin, 30);
988 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
993 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
995 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
997 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
1000 case TE_SUPERSPIKEQUAD:
1001 // quad super spike hitting wall
1002 MSG_ReadVector(pos, cl.protocol);
1003 CL_FindNonSolidLocation(pos, pos, 4);
1004 // LordHavoc: changed to dust shower
1005 if (cl_particles_bulletimpacts.integer)
1007 CL_SparkShower(pos, vec3_origin, 30, 1);
1008 CL_Smoke(pos, vec3_origin, 30);
1011 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1012 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, 0, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1014 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
1019 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
1021 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
1023 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
1026 // LordHavoc: added for improved blood splatters
1029 MSG_ReadVector(pos, cl.protocol);
1030 CL_FindNonSolidLocation(pos, pos, 4);
1031 dir[0] = MSG_ReadChar();
1032 dir[1] = MSG_ReadChar();
1033 dir[2] = MSG_ReadChar();
1034 count = MSG_ReadByte();
1035 CL_BloodPuff(pos, dir, count);
1039 MSG_ReadVector(pos, cl.protocol);
1040 CL_FindNonSolidLocation(pos, pos, 4);
1041 dir[0] = MSG_ReadChar();
1042 dir[1] = MSG_ReadChar();
1043 dir[2] = MSG_ReadChar();
1044 count = MSG_ReadByte();
1045 CL_SparkShower(pos, dir, count, 1);
1048 MSG_ReadVector(pos, cl.protocol);
1049 CL_FindNonSolidLocation(pos, pos, 4);
1050 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1051 CL_AllocDlight(NULL, &tempmatrix, 200, 1, 1, 1, 1000, 0.2, 0, 0, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1054 // LordHavoc: added for improved gore
1055 case TE_BLOODSHOWER:
1057 MSG_ReadVector(pos, cl.protocol); // mins
1058 MSG_ReadVector(pos2, cl.protocol); // maxs
1059 velspeed = MSG_ReadCoord(cl.protocol); // speed
1060 count = (unsigned short) MSG_ReadShort(); // number of particles
1061 CL_BloodShower(pos, pos2, velspeed, count);
1063 case TE_PARTICLECUBE:
1064 // general purpose particle effect
1065 MSG_ReadVector(pos, cl.protocol); // mins
1066 MSG_ReadVector(pos2, cl.protocol); // maxs
1067 MSG_ReadVector(dir, cl.protocol); // dir
1068 count = (unsigned short) MSG_ReadShort(); // number of particles
1069 colorStart = MSG_ReadByte(); // color
1070 colorLength = MSG_ReadByte(); // gravity (1 or 0)
1071 velspeed = MSG_ReadCoord(cl.protocol); // randomvel
1072 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
1075 case TE_PARTICLERAIN:
1076 // general purpose particle effect
1077 MSG_ReadVector(pos, cl.protocol); // mins
1078 MSG_ReadVector(pos2, cl.protocol); // maxs
1079 MSG_ReadVector(dir, cl.protocol); // dir
1080 count = (unsigned short) MSG_ReadShort(); // number of particles
1081 colorStart = MSG_ReadByte(); // color
1082 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
1085 case TE_PARTICLESNOW:
1086 // general purpose particle effect
1087 MSG_ReadVector(pos, cl.protocol); // mins
1088 MSG_ReadVector(pos2, cl.protocol); // maxs
1089 MSG_ReadVector(dir, cl.protocol); // dir
1090 count = (unsigned short) MSG_ReadShort(); // number of particles
1091 colorStart = MSG_ReadByte(); // color
1092 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
1096 // bullet hitting wall
1097 MSG_ReadVector(pos, cl.protocol);
1098 CL_FindNonSolidLocation(pos, pos, 4);
1099 CL_SparkShower(pos, vec3_origin, 15, 1);
1100 CL_Smoke(pos, vec3_origin, 15);
1104 case TE_GUNSHOTQUAD:
1105 // quad bullet hitting wall
1106 MSG_ReadVector(pos, cl.protocol);
1107 CL_FindNonSolidLocation(pos, pos, 4);
1108 CL_SparkShower(pos, vec3_origin, 15, 1);
1109 CL_Smoke(pos, vec3_origin, 15);
1111 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1112 CL_AllocDlight(NULL, &tempmatrix, 100, 0.15f, 0.15f, 1.5f, 500, 0.2, 0, 0, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1117 MSG_ReadVector(pos, cl.protocol);
1118 CL_FindNonSolidLocation(pos, pos, 10);
1119 CL_ParticleExplosion(pos);
1120 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
1121 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1122 CL_AllocDlight(NULL, &tempmatrix, 350, 4.0f, 2.0f, 0.50f, 700, 0.5, 0, 0, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1123 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1126 case TE_EXPLOSIONQUAD:
1127 // quad rocket explosion
1128 MSG_ReadVector(pos, cl.protocol);
1129 CL_FindNonSolidLocation(pos, pos, 10);
1130 CL_ParticleExplosion(pos);
1131 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1132 CL_AllocDlight(NULL, &tempmatrix, 350, 2.5f, 2.0f, 4.0f, 700, 0.5, 0, 0, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1133 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1137 // Nehahra movie colored lighting explosion
1138 MSG_ReadVector(pos, cl.protocol);
1139 CL_FindNonSolidLocation(pos, pos, 10);
1140 CL_ParticleExplosion(pos);
1141 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1142 color[0] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1143 color[1] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1144 color[2] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1145 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, 0, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1146 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1149 case TE_EXPLOSIONRGB:
1150 // colored lighting explosion
1151 MSG_ReadVector(pos, cl.protocol);
1152 CL_FindNonSolidLocation(pos, pos, 10);
1153 CL_ParticleExplosion(pos);
1154 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1155 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1156 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1157 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1158 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, 0, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1159 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1162 case TE_TAREXPLOSION:
1163 // tarbaby explosion
1164 MSG_ReadVector(pos, cl.protocol);
1165 CL_FindNonSolidLocation(pos, pos, 10);
1166 CL_BlobExplosion(pos);
1168 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1169 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1170 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1171 CL_AllocDlight(NULL, &tempmatrix, 600, 1.6f, 0.8f, 2.0f, 1200, 0.5, 0, 0, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1175 MSG_ReadVector(pos, cl.protocol);
1176 CL_FindNonSolidLocation(pos, pos, 10);
1177 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1178 CL_AllocDlight(NULL, &tempmatrix, 200, 2, 2, 2, 1000, 0.2, 0, 0, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1181 case TE_CUSTOMFLASH:
1182 MSG_ReadVector(pos, cl.protocol);
1183 CL_FindNonSolidLocation(pos, pos, 4);
1184 radius = MSG_ReadByte() * 8;
1185 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
1186 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1187 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1188 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1189 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1190 CL_AllocDlight(NULL, &tempmatrix, radius, color[0], color[1], color[2], radius / velspeed, velspeed, 0, 0, true, 1, 0.25, 1, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1194 MSG_ReadVector(pos, cl.protocol);
1195 MSG_ReadVector(dir, cl.protocol);
1196 count = MSG_ReadByte();
1197 CL_Flames(pos, dir, count);
1203 cl_model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
1204 CL_ParseBeam(cl_model_bolt, true);
1209 if (!cl_model_bolt2)
1210 cl_model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
1211 CL_ParseBeam(cl_model_bolt2, true);
1216 if (!cl_model_bolt3)
1217 cl_model_bolt3 = Mod_ForName("progs/bolt3.mdl", true, false, false);
1218 CL_ParseBeam(cl_model_bolt3, false);
1223 // grappling hook beam
1225 cl_model_beam = Mod_ForName("progs/beam.mdl", true, false, false);
1226 CL_ParseBeam(cl_model_beam, false);
1230 // LordHavoc: for compatibility with the Nehahra movie...
1231 case TE_LIGHTNING4NEH:
1232 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
1236 MSG_ReadVector(pos, cl.protocol);
1241 MSG_ReadVector(pos, cl.protocol);
1242 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1243 CL_AllocDlight(NULL, &tempmatrix, 500, 1.0f, 1.0f, 1.0f, 1500, 99.0f, 0, 0, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1244 // CL_TeleportSplash(pos);
1248 // color mapped explosion
1249 MSG_ReadVector(pos, cl.protocol);
1250 CL_FindNonSolidLocation(pos, pos, 10);
1251 colorStart = MSG_ReadByte();
1252 colorLength = MSG_ReadByte();
1253 CL_ParticleExplosion2(pos, colorStart, colorLength);
1254 tempcolor = (qbyte *)&palette_complete[(rand()%colorLength) + colorStart];
1255 color[0] = tempcolor[0] * (2.0f / 255.0f);
1256 color[1] = tempcolor[1] * (2.0f / 255.0f);
1257 color[2] = tempcolor[2] * (2.0f / 255.0f);
1258 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1259 CL_AllocDlight(NULL, &tempmatrix, 350, color[0], color[1], color[2], 700, 0.5, 0, 0, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1260 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1264 MSG_ReadVector(pos, cl.protocol);
1265 MSG_ReadVector(pos2, cl.protocol);
1266 MSG_ReadVector(dir, cl.protocol);
1267 CL_BeamParticle(pos, pos2, 12, 1, 0.3, 0.1, 1, 1);
1268 CL_BeamParticle(pos, pos2, 5, 1, 0.9, 0.3, 1, 1);
1272 MSG_ReadVector(pos, cl.protocol);
1273 MSG_ReadVector(dir, cl.protocol);
1274 count = MSG_ReadByte();
1275 CL_FindNonSolidLocation(pos, pos, 4);
1276 CL_Tei_Smoke(pos, dir, count);
1279 case TE_TEI_BIGEXPLOSION:
1280 MSG_ReadVector(pos, cl.protocol);
1281 CL_FindNonSolidLocation(pos, pos, 10);
1282 CL_ParticleExplosion(pos);
1283 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1284 CL_AllocDlight(NULL, &tempmatrix, 500, 2.5f, 2.0f, 1.0f, 500, 9999, 0, 0, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1285 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1288 case TE_TEI_PLASMAHIT:
1289 MSG_ReadVector(pos, cl.protocol);
1290 MSG_ReadVector(dir, cl.protocol);
1291 count = MSG_ReadByte();
1292 CL_FindNonSolidLocation(pos, pos, 5);
1293 CL_Tei_PlasmaHit(pos, dir, count);
1294 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1295 CL_AllocDlight(NULL, &tempmatrix, 500, 0.6, 1.2, 2.0f, 2000, 9999, 0, 0, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1299 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
1303 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
1305 static qbyte cgamenetbuffer[65536];
1308 =====================
1309 CL_ParseServerMessage
1310 =====================
1312 int parsingerror = false;
1313 void CL_ParseServerMessage(void)
1318 char *cmdlogname[32], *temp;
1319 int cmdindex, cmdcount = 0;
1321 if (cls.demorecording)
1322 CL_WriteDemoMessage ();
1324 cl.last_received_message = realtime;
1327 // if recording demos, copy the message out
1329 if (cl_shownet.integer == 1)
1330 Con_Printf("%f %i\n", realtime, net_message.cursize);
1331 else if (cl_shownet.integer == 2)
1332 Con_Print("------------------\n");
1334 cl.onground = false; // unless the server says otherwise
1336 // parse the message
1338 //MSG_BeginReading ();
1340 parsingerror = true;
1345 Host_Error ("CL_ParseServerMessage: Bad server message");
1347 cmd = MSG_ReadByte ();
1351 SHOWNET("END OF MESSAGE");
1352 break; // end of message
1355 cmdindex = cmdcount & 31;
1357 cmdlog[cmdindex] = cmd;
1359 // if the high bit of the command byte is set, it is a fast update
1362 // 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)
1364 cmdlogname[cmdindex] = temp;
1365 SHOWNET("fast update");
1366 if (cls.signon == SIGNONS - 1)
1368 // first update is the final signon stage
1369 cls.signon = SIGNONS;
1372 EntityFrameQuake_ReadEntity (cmd&127);
1376 SHOWNET(svc_strings[cmd]);
1377 cmdlogname[cmdindex] = svc_strings[cmd];
1378 if (!cmdlogname[cmdindex])
1380 // 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)
1382 cmdlogname[cmdindex] = temp;
1390 char description[32*64], temp[64];
1392 strcpy (description, "packet dump: ");
1396 count = cmdcount - i;
1400 snprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
1401 strlcat (description, temp, sizeof (description));
1406 description[strlen(description)-1] = '\n'; // replace the last space with a newline
1407 Con_Print(description);
1408 Host_Error ("CL_ParseServerMessage: Illegible server message\n");
1413 if (cls.signon < SIGNONS)
1414 Con_Print("<-- server to client keepalive\n");
1418 cl.mtime[1] = cl.mtime[0];
1419 cl.mtime[0] = MSG_ReadFloat ();
1422 case svc_clientdata:
1423 i = (unsigned short) MSG_ReadShort ();
1424 CL_ParseClientdata (i);
1428 i = MSG_ReadLong ();
1429 // hack for unmarked Nehahra movie demos which had a custom protocol
1430 if (i == PROTOCOL_QUAKE && cls.demoplayback && demo_nehahra.integer)
1431 i = PROTOCOL_NEHAHRAMOVIE;
1432 if (i != PROTOCOL_QUAKE && i != PROTOCOL_DARKPLACES1 && i != PROTOCOL_DARKPLACES2 && i != PROTOCOL_DARKPLACES3 && i != PROTOCOL_DARKPLACES4 && i != PROTOCOL_DARKPLACES5 && i != PROTOCOL_NEHAHRAMOVIE)
1433 Host_Error("CL_ParseServerMessage: Server is protocol %i, not %i (Quake), %i (DP1), %i (DP2), %i (DP3), %i (DP4), %i (DP5), or %i (Nehahra movie)", i, PROTOCOL_QUAKE, PROTOCOL_DARKPLACES1, PROTOCOL_DARKPLACES2, PROTOCOL_DARKPLACES3, PROTOCOL_DARKPLACES4, PROTOCOL_DARKPLACES5, PROTOCOL_NEHAHRAMOVIE);
1437 case svc_disconnect:
1438 Con_Printf ("Server disconnected\n");
1439 if (cls.demonum != -1)
1446 Con_Print(MSG_ReadString());
1449 case svc_centerprint:
1450 SCR_CenterPrint(MSG_ReadString ());
1454 Cbuf_AddText (MSG_ReadString ());
1461 case svc_serverinfo:
1462 CL_ParseServerInfo ();
1466 for (i=0 ; i<3 ; i++)
1467 cl.viewangles[i] = MSG_ReadAngle (cl.protocol);
1471 cl.viewentity = (unsigned short)MSG_ReadShort ();
1472 if (cl.viewentity >= MAX_EDICTS)
1473 Host_Error("svc_setview >= MAX_EDICTS\n");
1474 // LordHavoc: assume first setview recieved is the real player entity
1475 if (!cl.playerentity)
1476 cl.playerentity = cl.viewentity;
1479 case svc_lightstyle:
1480 i = MSG_ReadByte ();
1481 if (i >= MAX_LIGHTSTYLES)
1482 Host_Error ("svc_lightstyle >= MAX_LIGHTSTYLES");
1483 strlcpy (cl_lightstyle[i].map, MSG_ReadString(), sizeof (cl_lightstyle[i].map));
1484 cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
1485 cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
1489 CL_ParseStartSoundPacket(false);
1493 CL_ParseStartSoundPacket(true);
1497 i = (unsigned short) MSG_ReadShort();
1498 S_StopSound(i>>3, i&7);
1501 case svc_updatename:
1502 i = MSG_ReadByte ();
1503 if (i >= cl.maxclients)
1504 Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
1505 strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
1508 case svc_updatefrags:
1509 i = MSG_ReadByte ();
1510 if (i >= cl.maxclients)
1511 Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
1512 cl.scores[i].frags = (signed short) MSG_ReadShort ();
1515 case svc_updatecolors:
1516 i = MSG_ReadByte ();
1517 if (i >= cl.maxclients)
1518 Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
1519 cl.scores[i].colors = MSG_ReadByte ();
1523 CL_ParseParticleEffect ();
1534 case svc_spawnbaseline:
1535 i = (unsigned short) MSG_ReadShort ();
1536 if (i < 0 || i >= MAX_EDICTS)
1537 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
1538 CL_ParseBaseline (cl_entities + i, false);
1540 case svc_spawnbaseline2:
1541 i = (unsigned short) MSG_ReadShort ();
1542 if (i < 0 || i >= MAX_EDICTS)
1543 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
1544 CL_ParseBaseline (cl_entities + i, true);
1546 case svc_spawnstatic:
1547 CL_ParseStatic (false);
1549 case svc_spawnstatic2:
1550 CL_ParseStatic (true);
1552 case svc_temp_entity:
1553 CL_ParseTempEntity ();
1557 cl.paused = MSG_ReadByte ();
1562 S_PauseGameSounds (cl.paused);
1566 i = MSG_ReadByte ();
1567 if (i <= cls.signon)
1568 Host_Error ("Received signon %i when at %i", i, cls.signon);
1573 case svc_killedmonster:
1574 cl.stats[STAT_MONSTERS]++;
1577 case svc_foundsecret:
1578 cl.stats[STAT_SECRETS]++;
1581 case svc_updatestat:
1582 i = MSG_ReadByte ();
1583 if (i < 0 || i >= MAX_CL_STATS)
1584 Host_Error ("svc_updatestat: %i is invalid", i);
1585 cl.stats[i] = MSG_ReadLong ();
1588 case svc_spawnstaticsound:
1589 CL_ParseStaticSound (false);
1592 case svc_spawnstaticsound2:
1593 CL_ParseStaticSound (true);
1597 cl.cdtrack = MSG_ReadByte ();
1598 cl.looptrack = MSG_ReadByte ();
1599 if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
1600 CDAudio_Play ((qbyte)cls.forcetrack, true);
1602 CDAudio_Play ((qbyte)cl.cdtrack, true);
1605 case svc_intermission:
1606 cl.intermission = 1;
1607 cl.completed_time = cl.time;
1611 cl.intermission = 2;
1612 cl.completed_time = cl.time;
1613 SCR_CenterPrint(MSG_ReadString ());
1617 cl.intermission = 3;
1618 cl.completed_time = cl.time;
1619 SCR_CenterPrint(MSG_ReadString ());
1622 case svc_sellscreen:
1623 Cmd_ExecuteString ("help", src_command);
1626 if (gamemode == GAME_TENEBRAE)
1628 // repeating particle effect
1629 MSG_ReadCoord(cl.protocol);
1630 MSG_ReadCoord(cl.protocol);
1631 MSG_ReadCoord(cl.protocol);
1632 MSG_ReadCoord(cl.protocol);
1633 MSG_ReadCoord(cl.protocol);
1634 MSG_ReadCoord(cl.protocol);
1641 SHOWLMP_decodehide();
1644 if (gamemode == GAME_TENEBRAE)
1647 MSG_ReadCoord(cl.protocol);
1648 MSG_ReadCoord(cl.protocol);
1649 MSG_ReadCoord(cl.protocol);
1654 SHOWLMP_decodeshow();
1657 R_SetSkyBox(MSG_ReadString());
1662 length = (int) ((unsigned short) MSG_ReadShort());
1663 for (i = 0;i < length;i++)
1664 cgamenetbuffer[i] = MSG_ReadByte();
1666 CL_CGVM_ParseNetwork(cgamenetbuffer, length);
1670 if (cls.signon == SIGNONS - 1)
1672 // first update is the final signon stage
1673 cls.signon = SIGNONS;
1676 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1677 EntityFrame_CL_ReadFrame();
1678 else if (cl.protocol == PROTOCOL_DARKPLACES4)
1679 EntityFrame4_CL_ReadFrame();
1680 else if (cl.protocol == PROTOCOL_DARKPLACES5)
1681 EntityFrame5_CL_ReadFrame();
1683 Host_Error("CL_ParseServerMessage: svc_entities: unknown cl.protocol %i\n", cl.protocol);
1688 EntityFrameQuake_ISeeDeadEntities();
1690 parsingerror = false;
1693 void CL_Parse_DumpPacket(void)
1697 Con_Print("Packet dump:\n");
1698 SZ_HexDumpToConsole(&net_message);
1699 parsingerror = false;
1702 void CL_Parse_Init(void)
1704 // LordHavoc: added demo_nehahra cvar
1705 cl_scores_mempool = Mem_AllocPool("client player info", 0, NULL);
1706 Cvar_RegisterVariable (&demo_nehahra);
1707 if (gamemode == GAME_NEHAHRA)
1708 Cvar_SetValue("demo_nehahra", 1);
1709 Cvar_RegisterVariable(&developer_networkentities);