2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // cl_parse.c -- parse a message received from the server
24 #include "cl_collision.h"
26 char *svc_strings[128] =
32 "svc_version", // [long] server version
33 "svc_setview", // [short] entity number
34 "svc_sound", // <see code>
35 "svc_time", // [float] server time
36 "svc_print", // [string] null terminated string
37 "svc_stufftext", // [string] stuffed into client's console buffer
38 // the string should be \n terminated
39 "svc_setangle", // [vec3] set the view angle to this absolute value
41 "svc_serverinfo", // [long] version
42 // [string] signon string
43 // [string]..[0]model cache [string]...[0]sounds cache
44 // [string]..[0]item cache
45 "svc_lightstyle", // [byte] [string]
46 "svc_updatename", // [byte] [string]
47 "svc_updatefrags", // [byte] [short]
48 "svc_clientdata", // <shortbits + data>
49 "svc_stopsound", // <see code>
50 "svc_updatecolors", // [byte] [byte]
51 "svc_particle", // [vec3] <variable>
52 "svc_damage", // [byte] impact [byte] blood [vec3] from
55 "OBSOLETE svc_spawnbinary",
58 "svc_temp_entity", // <variable>
64 "svc_spawnstaticsound",
66 "svc_finale", // [string] music [string] text
67 "svc_cdtrack", // [byte] track [byte] looptrack
70 "svc_showlmp", // [string] iconlabel [string] lmpfile [short] x [short] y
71 "svc_hidelmp", // [string] iconlabel
72 "svc_skybox", // [string] skyname
85 "svc_cgame", // 50 // [short] length [bytes] data
86 "svc_updatestatubyte", // 51 // [byte] stat [byte] value
87 "svc_effect", // 52 // [vector] org [byte] modelindex [byte] startframe [byte] framecount [byte] framerate
88 "svc_effect2", // 53 // [vector] org [short] modelindex [short] startframe [byte] framecount [byte] framerate
89 "svc_sound2", // 54 // short soundindex instead of byte
90 "svc_spawnbaseline2", // 55 // short modelindex instead of byte
91 "svc_spawnstatic2", // 56 // short modelindex instead of byte
92 "svc_entities", // 57 // [int] deltaframe [int] thisframe [float vector] eye [variable length] entitydata
93 "svc_unusedlh3", // 58
94 "svc_spawnstaticsound2", // 59 // [coord3] [short] samp [byte] vol [byte] aten
97 //=============================================================================
99 cvar_t demo_nehahra = {0, "demo_nehahra", "0"};
100 cvar_t developer_networkentities = {0, "developer_networkentities", "0"};
102 mempool_t *cl_scores_mempool;
106 CL_ParseStartSoundPacket
109 void CL_ParseStartSoundPacket(int largesoundindex)
118 field_mask = MSG_ReadByte();
120 if (field_mask & SND_VOLUME)
121 volume = MSG_ReadByte ();
123 volume = DEFAULT_SOUND_PACKET_VOLUME;
125 if (field_mask & SND_ATTENUATION)
126 attenuation = MSG_ReadByte () / 64.0;
128 attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
130 if (field_mask & SND_LARGEENTITY)
132 ent = (unsigned short) MSG_ReadShort ();
133 channel = MSG_ReadByte ();
137 channel = (unsigned short) MSG_ReadShort ();
142 if (largesoundindex || field_mask & SND_LARGESOUND)
143 sound_num = (unsigned short) MSG_ReadShort ();
145 sound_num = MSG_ReadByte ();
147 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);
210 void CL_ParseEntityLump(char *entdata)
213 char key[128], value[4096];
214 FOG_clear(); // LordHavoc: no fog until set
215 // LordHavoc: default to the map's sky (q3 shader parsing sets this)
216 R_SetSkyBox(cl.worldmodel->brush.skybox);
220 if (!COM_ParseToken(&data, false))
222 if (com_token[0] != '{')
226 if (!COM_ParseToken(&data, false))
228 if (com_token[0] == '}')
229 break; // end of worldspawn
230 if (com_token[0] == '_')
231 strlcpy (key, com_token + 1, sizeof (key));
233 strlcpy (key, com_token, sizeof (key));
234 while (key[strlen(key)-1] == ' ') // remove trailing spaces
235 key[strlen(key)-1] = 0;
236 if (!COM_ParseToken(&data, false))
238 strlcpy (value, com_token, sizeof (value));
239 if (!strcmp("sky", key))
241 else if (!strcmp("skyname", key)) // non-standard, introduced by QuakeForge... sigh.
243 else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
245 else if (!strcmp("fog", key))
246 sscanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue);
247 else if (!strcmp("fog_density", key))
248 fog_density = atof(value);
249 else if (!strcmp("fog_red", key))
250 fog_red = atof(value);
251 else if (!strcmp("fog_green", key))
252 fog_green = atof(value);
253 else if (!strcmp("fog_blue", key))
254 fog_blue = atof(value);
259 =====================
262 An svc_signonnum has been received, perform a client side setup
263 =====================
265 static void CL_SignonReply (void)
269 Con_DPrintf("CL_SignonReply: %i\n", cls.signon);
274 MSG_WriteByte (&cls.message, clc_stringcmd);
275 MSG_WriteString (&cls.message, "prespawn");
279 MSG_WriteByte (&cls.message, clc_stringcmd);
280 MSG_WriteString (&cls.message, va("name \"%s\"\n", cl_name.string));
282 MSG_WriteByte (&cls.message, clc_stringcmd);
283 MSG_WriteString (&cls.message, va("color %i %i\n", cl_color.integer >> 4, cl_color.integer & 15));
285 if (cl_pmodel.integer)
287 MSG_WriteByte (&cls.message, clc_stringcmd);
288 MSG_WriteString (&cls.message, va("pmodel %i\n", cl_pmodel.integer));
290 if (*cl_playermodel.string)
292 MSG_WriteByte (&cls.message, clc_stringcmd);
293 MSG_WriteString (&cls.message, va("playermodel %s\n", cl_playermodel.string));
295 if (*cl_playerskin.string)
297 MSG_WriteByte (&cls.message, clc_stringcmd);
298 MSG_WriteString (&cls.message, va("playerskin %s\n", cl_playerskin.string));
301 MSG_WriteByte (&cls.message, clc_stringcmd);
302 MSG_WriteString (&cls.message, va("rate %i\n", cl_rate.integer));
304 MSG_WriteByte (&cls.message, clc_stringcmd);
305 MSG_WriteString (&cls.message, "spawn");
309 MSG_WriteByte (&cls.message, clc_stringcmd);
310 MSG_WriteString (&cls.message, "begin");
324 // FIXME: this is a lot of memory to be keeping around, this needs to be dynamically allocated and freed
325 static char parse_model_precache[MAX_MODELS][MAX_QPATH];
326 static char parse_sound_precache[MAX_SOUNDS][MAX_QPATH];
327 void CL_ParseServerInfo (void)
331 int nummodels, numsounds;
334 Con_DPrint("Serverinfo packet received.\n");
336 // wipe the client_state_t struct
340 // parse protocol version number
342 // hack for unmarked Nehahra movie demos which had a custom protocol
343 if (i == PROTOCOL_QUAKE && cls.demoplayback && demo_nehahra.integer)
344 i = PROTOCOL_NEHAHRAMOVIE;
345 if (i != PROTOCOL_QUAKE && i != PROTOCOL_DARKPLACES1 && i != PROTOCOL_DARKPLACES2 && i != PROTOCOL_DARKPLACES3 && i != PROTOCOL_DARKPLACES4 && i != PROTOCOL_DARKPLACES5 && i != PROTOCOL_DARKPLACES6 && i != PROTOCOL_NEHAHRAMOVIE)
347 Host_Error("CL_ParseServerInfo: Server is protocol %i, not %i (Quake), %i (DP1), %i (DP2), %i (DP3), %i (DP4), %i (DP5), %i (DP6), or %i (Nehahra movie)", i, PROTOCOL_QUAKE, PROTOCOL_DARKPLACES1, PROTOCOL_DARKPLACES2, PROTOCOL_DARKPLACES3, PROTOCOL_DARKPLACES4, PROTOCOL_DARKPLACES5, PROTOCOL_DARKPLACES6, PROTOCOL_NEHAHRAMOVIE);
351 Con_DPrintf("Server protocol is %i\n", cl.protocol);
354 cl.maxclients = MSG_ReadByte ();
355 if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
357 Host_Error("Bad maxclients (%u) from server\n", cl.maxclients);
360 Mem_EmptyPool(cl_scores_mempool);
361 cl.scores = Mem_Alloc(cl_scores_mempool, cl.maxclients*sizeof(*cl.scores));
364 cl.gametype = MSG_ReadByte ();
366 // parse signon message
367 str = MSG_ReadString ();
368 strlcpy (cl.levelname, str, sizeof(cl.levelname));
370 // seperate the printfs so the server message can have a color
371 if (cl.protocol != PROTOCOL_NEHAHRAMOVIE) // no messages when playing the Nehahra movie
372 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);
374 // check memory integrity
375 Mem_CheckSentinelsGlobal();
378 // if server is active, we already began a loading plaque
380 SCR_BeginLoadingPlaque();
382 // disable until we get textures for it
385 memset(cl.model_precache, 0, sizeof(cl.model_precache));
386 memset(cl.sound_precache, 0, sizeof(cl.sound_precache));
388 // parse model precache list
389 for (nummodels=1 ; ; nummodels++)
391 str = MSG_ReadString();
394 if (nummodels==MAX_MODELS)
395 Host_Error ("Server sent too many model precaches\n");
396 if (strlen(str) >= MAX_QPATH)
397 Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
398 strlcpy (parse_model_precache[nummodels], str, sizeof (parse_model_precache[nummodels]));
400 // parse sound precache list
401 for (numsounds=1 ; ; numsounds++)
403 str = MSG_ReadString();
406 if (numsounds==MAX_SOUNDS)
407 Host_Error("Server sent too many sound precaches\n");
408 if (strlen(str) >= MAX_QPATH)
409 Host_Error("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
410 strlcpy (parse_sound_precache[numsounds], str, sizeof (parse_sound_precache[numsounds]));
413 // touch all of the precached models that are still loaded so we can free
414 // anything that isn't needed
416 for (i = 1;i < nummodels;i++)
417 Mod_FindName(parse_model_precache[i]);
420 // do the same for sounds
421 S_ServerSounds (parse_sound_precache, numsounds);
423 // now we try to load everything that is new
426 CL_KeepaliveMessage ();
427 cl.model_precache[1] = Mod_ForName(parse_model_precache[1], false, false, true);
428 if (cl.model_precache[1] == NULL)
429 Con_Printf("Map %s not found\n", parse_model_precache[1]);
432 for (i=2 ; i<nummodels ; i++)
434 CL_KeepaliveMessage();
435 if ((cl.model_precache[i] = Mod_ForName(parse_model_precache[i], false, false, false)) == NULL)
436 Con_Printf("Model %s not found\n", parse_model_precache[i]);
440 for (i=1 ; i<numsounds ; i++)
442 CL_KeepaliveMessage();
444 // Don't lock the sfx here, S_ServerSounds already did that
445 cl.sound_precache[i] = S_PrecacheSound (parse_sound_precache[i], true, false);
449 ent = &cl_entities[0];
450 // entire entity array was cleared, so just fill in a few fields
451 ent->state_current.active = true;
452 ent->render.model = cl.worldmodel = cl.model_precache[1];
453 ent->render.scale = 1; // some of the renderer still relies on scale
454 ent->render.alpha = 1;
455 ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
456 Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
457 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
458 CL_BoundingBoxForEntity(&ent->render);
465 // noclip is turned off at start
466 noclip_anglehack = false;
468 // check memory integrity
469 Mem_CheckSentinelsGlobal();
472 void CL_ValidateState(entity_state_t *s)
479 if (s->modelindex >= MAX_MODELS)
480 Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
482 // colormap is client index + 1
483 if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
485 Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
489 model = cl.model_precache[s->modelindex];
490 Mod_CheckLoaded(model);
491 if (model && model->type && s->frame >= model->numframes)
493 Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
496 if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
498 Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
503 void CL_MoveLerpEntityStates(entity_t *ent)
505 float odelta[3], adelta[3];
506 CL_ValidateState(&ent->state_current);
507 VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
508 VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
509 if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)
511 // reset all persistent stuff if this is a new entity
512 ent->persistent.lerpdeltatime = 0;
513 ent->persistent.lerpstarttime = cl.mtime[1];
514 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
515 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
516 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
517 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
518 // reset animation interpolation as well
519 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
520 ent->render.frame1time = ent->render.frame2time = cl.time;
521 ent->render.framelerp = 1;
522 // reset various persistent stuff
523 ent->persistent.muzzleflash = 0;
524 VectorCopy(ent->state_current.origin, ent->persistent.trail_origin);
526 else if (cls.timedemo || cl_nolerp.integer || DotProduct(odelta, odelta) > 1000*1000)
528 // don't interpolate the move
529 ent->persistent.lerpdeltatime = 0;
530 ent->persistent.lerpstarttime = cl.mtime[1];
531 VectorCopy(ent->state_current.origin, ent->persistent.oldorigin);
532 VectorCopy(ent->state_current.angles, ent->persistent.oldangles);
533 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
534 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
536 else if (ent->state_current.flags & RENDER_STEP)
538 // monster interpolation
539 if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
541 ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
542 ent->persistent.lerpstarttime = cl.mtime[1];
543 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
544 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
545 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
546 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
552 ent->persistent.lerpstarttime = ent->state_previous.time;
553 // no lerp if it's singleplayer
555 ent->persistent.lerpdeltatime = 0;
557 ent->persistent.lerpdeltatime = bound(0, ent->state_current.time - ent->state_previous.time, 0.1);
558 VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
559 VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
560 VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
561 VectorCopy(ent->state_current.angles, ent->persistent.newangles);
570 void CL_ParseBaseline (entity_t *ent, int large)
574 ent->state_baseline = defaultstate;
575 // FIXME: set ent->state_baseline.number?
576 ent->state_baseline.active = true;
579 ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
580 ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
584 ent->state_baseline.modelindex = MSG_ReadByte ();
585 ent->state_baseline.frame = MSG_ReadByte ();
587 ent->state_baseline.colormap = MSG_ReadByte();
588 ent->state_baseline.skin = MSG_ReadByte();
589 for (i = 0;i < 3;i++)
591 ent->state_baseline.origin[i] = MSG_ReadCoord(cl.protocol);
592 ent->state_baseline.angles[i] = MSG_ReadAngle(cl.protocol);
594 CL_ValidateState(&ent->state_baseline);
595 ent->state_previous = ent->state_current = ent->state_baseline;
603 Server information pertaining to this client only
606 void CL_ParseClientdata (int bits)
610 VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
612 if (cl.protocol != PROTOCOL_DARKPLACES6)
614 cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
615 cl.stats[STAT_ITEMS] = 0;
616 cl.stats[STAT_VIEWZOOM] = 255;
619 cl.punchangle[0] = 0;
620 cl.punchangle[1] = 0;
621 cl.punchangle[2] = 0;
622 cl.punchvector[0] = 0;
623 cl.punchvector[1] = 0;
624 cl.punchvector[2] = 0;
625 cl.mvelocity[0][0] = 0;
626 cl.mvelocity[0][1] = 0;
627 cl.mvelocity[0][2] = 0;
630 if (bits & SU_EXTEND1)
631 bits |= (MSG_ReadByte() << 16);
632 if (bits & SU_EXTEND2)
633 bits |= (MSG_ReadByte() << 24);
635 if (bits & SU_VIEWHEIGHT)
636 cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
638 if (bits & SU_IDEALPITCH)
639 cl.idealpitch = MSG_ReadChar ();
641 for (i = 0;i < 3;i++)
643 if (bits & (SU_PUNCH1<<i) )
645 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4 || cl.protocol == PROTOCOL_DARKPLACES5 || cl.protocol == PROTOCOL_DARKPLACES6)
646 cl.punchangle[i] = MSG_ReadAngle16i();
647 else if (cl.protocol == PROTOCOL_QUAKE || cl.protocol == PROTOCOL_NEHAHRAMOVIE)
648 cl.punchangle[i] = MSG_ReadChar();
650 Host_Error("CL_ParseClientData: unknown cl.protocol %i\n", cl.protocol);
652 if (bits & (SU_PUNCHVEC1<<i))
654 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3 || cl.protocol == PROTOCOL_DARKPLACES4)
655 cl.punchvector[i] = MSG_ReadCoord16i();
656 else if (cl.protocol == PROTOCOL_DARKPLACES5 || cl.protocol == PROTOCOL_DARKPLACES6)
657 cl.punchvector[i] = MSG_ReadCoord32f();
659 Host_Error("CL_ParseClientData: unknown cl.protocol %i\n", cl.protocol);
661 if (bits & (SU_VELOCITY1<<i) )
663 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)
664 cl.mvelocity[0][i] = MSG_ReadChar()*16;
665 else if (cl.protocol == PROTOCOL_DARKPLACES5 || cl.protocol == PROTOCOL_DARKPLACES6)
666 cl.mvelocity[0][i] = MSG_ReadCoord32f();
668 Host_Error("CL_ParseClientData: unknown cl.protocol %i\n", cl.protocol);
673 cl.stats[STAT_ITEMS] = MSG_ReadLong ();
675 cl.onground = (bits & SU_ONGROUND) != 0;
676 cl.inwater = (bits & SU_INWATER) != 0;
678 if (cl.protocol == PROTOCOL_DARKPLACES6)
681 else if (cl.protocol == PROTOCOL_DARKPLACES5)
683 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
684 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
685 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
686 cl.stats[STAT_HEALTH] = MSG_ReadShort();
687 cl.stats[STAT_AMMO] = MSG_ReadShort();
688 cl.stats[STAT_SHELLS] = MSG_ReadShort();
689 cl.stats[STAT_NAILS] = MSG_ReadShort();
690 cl.stats[STAT_ROCKETS] = MSG_ReadShort();
691 cl.stats[STAT_CELLS] = MSG_ReadShort();
692 cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
696 cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
697 cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
698 cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
699 cl.stats[STAT_HEALTH] = MSG_ReadShort();
700 cl.stats[STAT_AMMO] = MSG_ReadByte();
701 cl.stats[STAT_SHELLS] = MSG_ReadByte();
702 cl.stats[STAT_NAILS] = MSG_ReadByte();
703 cl.stats[STAT_ROCKETS] = MSG_ReadByte();
704 cl.stats[STAT_CELLS] = MSG_ReadByte();
705 if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
706 cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
708 cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
711 if (bits & SU_VIEWZOOM)
713 if (cl.protocol == PROTOCOL_DARKPLACES5 || cl.protocol == PROTOCOL_DARKPLACES6)
714 cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
716 cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
719 // check for important changes
722 if (cl.olditems != cl.stats[STAT_ITEMS])
723 for (j = 0;j < 32;j++)
724 if ((cl.stats[STAT_ITEMS] & (1<<j)) && !(cl.olditems & (1<<j)))
725 cl.item_gettime[j] = cl.time;
726 cl.olditems = cl.stats[STAT_ITEMS];
728 // GAME_NEXUIZ hud needs weapon change time
729 if (cl.activeweapon != cl.stats[STAT_ACTIVEWEAPON])
730 cl.weapontime = cl.time;
731 cl.activeweapon = cl.stats[STAT_ACTIVEWEAPON];
733 // viewzoom interpolation
734 cl.viewzoomold = cl.viewzoomnew;
735 cl.viewzoomnew = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
739 =====================
741 =====================
743 void CL_ParseStatic (int large)
747 if (cl_num_static_entities >= cl_max_static_entities)
748 Host_Error ("Too many static entities");
749 ent = &cl_static_entities[cl_num_static_entities++];
750 CL_ParseBaseline (ent, large);
752 // copy it to the current state
753 ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
754 ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
755 ent->render.framelerp = 0;
756 // make torchs play out of sync
757 ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
758 ent->render.colormap = -1; // no special coloring
759 ent->render.skinnum = ent->state_baseline.skin;
760 ent->render.effects = ent->state_baseline.effects;
761 ent->render.alpha = 1;
762 //ent->render.scale = 1;
764 //VectorCopy (ent->state_baseline.origin, ent->render.origin);
765 //VectorCopy (ent->state_baseline.angles, ent->render.angles);
767 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);
768 Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
769 CL_BoundingBoxForEntity(&ent->render);
771 // This is definitely cheating...
772 if (ent->render.model == NULL)
773 cl_num_static_entities--;
781 void CL_ParseStaticSound (int large)
784 int sound_num, vol, atten;
786 MSG_ReadVector(org, cl.protocol);
788 sound_num = (unsigned short) MSG_ReadShort ();
790 sound_num = MSG_ReadByte ();
791 vol = MSG_ReadByte ();
792 atten = MSG_ReadByte ();
794 S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
797 void CL_ParseEffect (void)
800 int modelindex, startframe, framecount, framerate;
802 MSG_ReadVector(org, cl.protocol);
803 modelindex = MSG_ReadByte ();
804 startframe = MSG_ReadByte ();
805 framecount = MSG_ReadByte ();
806 framerate = MSG_ReadByte ();
808 CL_Effect(org, modelindex, startframe, framecount, framerate);
811 void CL_ParseEffect2 (void)
814 int modelindex, startframe, framecount, framerate;
816 MSG_ReadVector(org, cl.protocol);
817 modelindex = (unsigned short) MSG_ReadShort ();
818 startframe = (unsigned short) MSG_ReadShort ();
819 framecount = MSG_ReadByte ();
820 framerate = MSG_ReadByte ();
822 CL_Effect(org, modelindex, startframe, framecount, framerate);
825 model_t *cl_model_bolt = NULL;
826 model_t *cl_model_bolt2 = NULL;
827 model_t *cl_model_bolt3 = NULL;
828 model_t *cl_model_beam = NULL;
830 sfx_t *cl_sfx_wizhit;
831 sfx_t *cl_sfx_knighthit;
836 sfx_t *cl_sfx_r_exp3;
843 void CL_InitTEnts (void)
845 cl_sfx_wizhit = S_PrecacheSound ("sound/wizard/hit.wav", false, true);
846 cl_sfx_knighthit = S_PrecacheSound ("sound/hknight/hit.wav", false, true);
847 cl_sfx_tink1 = S_PrecacheSound ("sound/weapons/tink1.wav", false, true);
848 cl_sfx_ric1 = S_PrecacheSound ("sound/weapons/ric1.wav", false, true);
849 cl_sfx_ric2 = S_PrecacheSound ("sound/weapons/ric2.wav", false, true);
850 cl_sfx_ric3 = S_PrecacheSound ("sound/weapons/ric3.wav", false, true);
851 cl_sfx_r_exp3 = S_PrecacheSound ("sound/weapons/r_exp3.wav", false, true);
854 void CL_ParseBeam (model_t *m, int lightning)
860 ent = (unsigned short) MSG_ReadShort ();
861 MSG_ReadVector(start, cl.protocol);
862 MSG_ReadVector(end, cl.protocol);
864 if (ent >= MAX_EDICTS)
866 Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
870 // override any beam with the same entity
871 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
873 if (b->entity == ent)
876 b->lightning = lightning;
877 b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
879 b->endtime = cl.time + 0.2;
880 VectorCopy (start, b->start);
881 VectorCopy (end, b->end);
887 for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
889 if (!b->model || b->endtime < cl.time)
892 b->lightning = lightning;
893 b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
895 b->endtime = cl.time + 0.2;
896 VectorCopy (start, b->start);
897 VectorCopy (end, b->end);
901 Con_Print("beam list overflow!\n");
904 void CL_ParseTempEntity(void)
912 int colorStart, colorLength, count;
913 float velspeed, radius;
915 matrix4x4_t tempmatrix;
917 type = MSG_ReadByte();
921 // spike hitting wall
922 MSG_ReadVector(pos, cl.protocol);
923 CL_FindNonSolidLocation(pos, pos, 4);
924 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
925 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);
926 CL_RunParticleEffect(pos, vec3_origin, 20, 30);
927 S_StartSound(-1, 0, cl_sfx_wizhit, pos, 1, 1);
931 // spike hitting wall
932 MSG_ReadVector(pos, cl.protocol);
933 CL_FindNonSolidLocation(pos, pos, 4);
934 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
935 CL_AllocDlight(NULL, &tempmatrix, 100, 0.50f, 0.30f, 0.10f, 500, 0.2, 0, -1, false, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
936 CL_RunParticleEffect(pos, vec3_origin, 226, 20);
937 S_StartSound(-1, 0, cl_sfx_knighthit, pos, 1, 1);
941 // spike hitting wall
942 MSG_ReadVector(pos, cl.protocol);
943 CL_FindNonSolidLocation(pos, pos, 4);
944 if (cl_particles_bulletimpacts.integer)
946 CL_SparkShower(pos, vec3_origin, 15, 1);
947 CL_Smoke(pos, vec3_origin, 15);
951 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
956 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
958 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
960 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
964 // quad spike hitting wall
965 MSG_ReadVector(pos, cl.protocol);
966 CL_FindNonSolidLocation(pos, pos, 4);
967 // LordHavoc: changed to spark shower
968 if (cl_particles_bulletimpacts.integer)
970 CL_SparkShower(pos, vec3_origin, 15, 1);
971 CL_Smoke(pos, vec3_origin, 15);
974 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
975 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);
976 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
978 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
983 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
985 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
987 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
991 // super spike hitting wall
992 MSG_ReadVector(pos, cl.protocol);
993 CL_FindNonSolidLocation(pos, pos, 4);
994 // LordHavoc: changed to dust shower
995 if (cl_particles_bulletimpacts.integer)
997 CL_SparkShower(pos, vec3_origin, 30, 1);
998 CL_Smoke(pos, vec3_origin, 30);
1002 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
1007 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
1009 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
1011 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
1014 case TE_SUPERSPIKEQUAD:
1015 // quad super spike hitting wall
1016 MSG_ReadVector(pos, cl.protocol);
1017 CL_FindNonSolidLocation(pos, pos, 4);
1018 // LordHavoc: changed to dust shower
1019 if (cl_particles_bulletimpacts.integer)
1021 CL_SparkShower(pos, vec3_origin, 30, 1);
1022 CL_Smoke(pos, vec3_origin, 30);
1025 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1026 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);
1028 S_StartSound(-1, 0, cl_sfx_tink1, pos, 1, 1);
1033 S_StartSound(-1, 0, cl_sfx_ric1, pos, 1, 1);
1035 S_StartSound(-1, 0, cl_sfx_ric2, pos, 1, 1);
1037 S_StartSound(-1, 0, cl_sfx_ric3, pos, 1, 1);
1040 // LordHavoc: added for improved blood splatters
1043 MSG_ReadVector(pos, cl.protocol);
1044 CL_FindNonSolidLocation(pos, pos, 4);
1045 dir[0] = MSG_ReadChar();
1046 dir[1] = MSG_ReadChar();
1047 dir[2] = MSG_ReadChar();
1048 count = MSG_ReadByte();
1049 CL_BloodPuff(pos, dir, count);
1053 MSG_ReadVector(pos, cl.protocol);
1054 CL_FindNonSolidLocation(pos, pos, 4);
1055 dir[0] = MSG_ReadChar();
1056 dir[1] = MSG_ReadChar();
1057 dir[2] = MSG_ReadChar();
1058 count = MSG_ReadByte();
1059 CL_SparkShower(pos, dir, count, 1);
1062 MSG_ReadVector(pos, cl.protocol);
1063 CL_FindNonSolidLocation(pos, pos, 4);
1064 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1065 CL_AllocDlight(NULL, &tempmatrix, 200, 1, 1, 1, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1068 // LordHavoc: added for improved gore
1069 case TE_BLOODSHOWER:
1071 MSG_ReadVector(pos, cl.protocol); // mins
1072 MSG_ReadVector(pos2, cl.protocol); // maxs
1073 velspeed = MSG_ReadCoord(cl.protocol); // speed
1074 count = (unsigned short) MSG_ReadShort(); // number of particles
1075 CL_BloodShower(pos, pos2, velspeed, count);
1077 case TE_PARTICLECUBE:
1078 // general purpose particle effect
1079 MSG_ReadVector(pos, cl.protocol); // mins
1080 MSG_ReadVector(pos2, cl.protocol); // maxs
1081 MSG_ReadVector(dir, cl.protocol); // dir
1082 count = (unsigned short) MSG_ReadShort(); // number of particles
1083 colorStart = MSG_ReadByte(); // color
1084 colorLength = MSG_ReadByte(); // gravity (1 or 0)
1085 velspeed = MSG_ReadCoord(cl.protocol); // randomvel
1086 CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength, velspeed);
1089 case TE_PARTICLERAIN:
1090 // general purpose particle effect
1091 MSG_ReadVector(pos, cl.protocol); // mins
1092 MSG_ReadVector(pos2, cl.protocol); // maxs
1093 MSG_ReadVector(dir, cl.protocol); // dir
1094 count = (unsigned short) MSG_ReadShort(); // number of particles
1095 colorStart = MSG_ReadByte(); // color
1096 CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
1099 case TE_PARTICLESNOW:
1100 // general purpose particle effect
1101 MSG_ReadVector(pos, cl.protocol); // mins
1102 MSG_ReadVector(pos2, cl.protocol); // maxs
1103 MSG_ReadVector(dir, cl.protocol); // dir
1104 count = (unsigned short) MSG_ReadShort(); // number of particles
1105 colorStart = MSG_ReadByte(); // color
1106 CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
1110 // bullet hitting wall
1111 MSG_ReadVector(pos, cl.protocol);
1112 CL_FindNonSolidLocation(pos, pos, 4);
1113 CL_SparkShower(pos, vec3_origin, 15, 1);
1114 CL_Smoke(pos, vec3_origin, 15);
1118 case TE_GUNSHOTQUAD:
1119 // quad bullet hitting wall
1120 MSG_ReadVector(pos, cl.protocol);
1121 CL_FindNonSolidLocation(pos, pos, 4);
1122 CL_SparkShower(pos, vec3_origin, 15, 1);
1123 CL_Smoke(pos, vec3_origin, 15);
1125 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1126 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);
1131 MSG_ReadVector(pos, cl.protocol);
1132 CL_FindNonSolidLocation(pos, pos, 10);
1133 CL_ParticleExplosion(pos);
1134 // LordHavoc: boosted color from 1.0, 0.8, 0.4 to 1.25, 1.0, 0.5
1135 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1136 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);
1137 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1140 case TE_EXPLOSIONQUAD:
1141 // quad rocket explosion
1142 MSG_ReadVector(pos, cl.protocol);
1143 CL_FindNonSolidLocation(pos, pos, 10);
1144 CL_ParticleExplosion(pos);
1145 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1146 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);
1147 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1151 // Nehahra movie colored lighting explosion
1152 MSG_ReadVector(pos, cl.protocol);
1153 CL_FindNonSolidLocation(pos, pos, 10);
1154 CL_ParticleExplosion(pos);
1155 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1156 color[0] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1157 color[1] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1158 color[2] = MSG_ReadCoord(cl.protocol) * (2.0f / 1.0f);
1159 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);
1160 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1163 case TE_EXPLOSIONRGB:
1164 // colored lighting explosion
1165 MSG_ReadVector(pos, cl.protocol);
1166 CL_FindNonSolidLocation(pos, pos, 10);
1167 CL_ParticleExplosion(pos);
1168 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1169 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1170 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1171 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1172 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);
1173 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1176 case TE_TAREXPLOSION:
1177 // tarbaby explosion
1178 MSG_ReadVector(pos, cl.protocol);
1179 CL_FindNonSolidLocation(pos, pos, 10);
1180 CL_BlobExplosion(pos);
1182 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1183 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1184 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1185 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);
1189 MSG_ReadVector(pos, cl.protocol);
1190 CL_FindNonSolidLocation(pos, pos, 10);
1191 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1192 CL_AllocDlight(NULL, &tempmatrix, 200, 2, 2, 2, 1000, 0.2, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1195 case TE_CUSTOMFLASH:
1196 MSG_ReadVector(pos, cl.protocol);
1197 CL_FindNonSolidLocation(pos, pos, 4);
1198 radius = MSG_ReadByte() * 8;
1199 velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
1200 color[0] = MSG_ReadByte() * (2.0f / 255.0f);
1201 color[1] = MSG_ReadByte() * (2.0f / 255.0f);
1202 color[2] = MSG_ReadByte() * (2.0f / 255.0f);
1203 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1204 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);
1208 MSG_ReadVector(pos, cl.protocol);
1209 MSG_ReadVector(dir, cl.protocol);
1210 count = MSG_ReadByte();
1211 CL_Flames(pos, dir, count);
1217 cl_model_bolt = Mod_ForName("progs/bolt.mdl", false, false, false);
1218 CL_ParseBeam(cl_model_bolt, true);
1223 if (!cl_model_bolt2)
1224 cl_model_bolt2 = Mod_ForName("progs/bolt2.mdl", false, false, false);
1225 CL_ParseBeam(cl_model_bolt2, true);
1230 if (!cl_model_bolt3)
1231 cl_model_bolt3 = Mod_ForName("progs/bolt3.mdl", true, false, false);
1232 CL_ParseBeam(cl_model_bolt3, false);
1237 // grappling hook beam
1239 cl_model_beam = Mod_ForName("progs/beam.mdl", true, false, false);
1240 CL_ParseBeam(cl_model_beam, false);
1244 // LordHavoc: for compatibility with the Nehahra movie...
1245 case TE_LIGHTNING4NEH:
1246 CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
1250 MSG_ReadVector(pos, cl.protocol);
1255 MSG_ReadVector(pos, cl.protocol);
1256 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1257 CL_AllocDlight(NULL, &tempmatrix, 500, 1.0f, 1.0f, 1.0f, 1500, 99.0f, 0, -1, true, 1, 0.25, 1, 0, 0, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
1258 // CL_TeleportSplash(pos);
1262 // color mapped explosion
1263 MSG_ReadVector(pos, cl.protocol);
1264 CL_FindNonSolidLocation(pos, pos, 10);
1265 colorStart = MSG_ReadByte();
1266 colorLength = MSG_ReadByte();
1267 CL_ParticleExplosion2(pos, colorStart, colorLength);
1268 tempcolor = (qbyte *)&palette_complete[(rand()%colorLength) + colorStart];
1269 color[0] = tempcolor[0] * (2.0f / 255.0f);
1270 color[1] = tempcolor[1] * (2.0f / 255.0f);
1271 color[2] = tempcolor[2] * (2.0f / 255.0f);
1272 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1273 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);
1274 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1278 MSG_ReadVector(pos, cl.protocol);
1279 MSG_ReadVector(pos2, cl.protocol);
1280 MSG_ReadVector(dir, cl.protocol);
1281 CL_BeamParticle(pos, pos2, 8, 1, 1, 1, 1, 1);
1285 MSG_ReadVector(pos, cl.protocol);
1286 MSG_ReadVector(dir, cl.protocol);
1287 count = MSG_ReadByte();
1288 CL_FindNonSolidLocation(pos, pos, 4);
1289 CL_Tei_Smoke(pos, dir, count);
1292 case TE_TEI_BIGEXPLOSION:
1293 MSG_ReadVector(pos, cl.protocol);
1294 CL_FindNonSolidLocation(pos, pos, 10);
1295 CL_ParticleExplosion(pos);
1296 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1297 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);
1298 S_StartSound(-1, 0, cl_sfx_r_exp3, pos, 1, 1);
1301 case TE_TEI_PLASMAHIT:
1302 MSG_ReadVector(pos, cl.protocol);
1303 MSG_ReadVector(dir, cl.protocol);
1304 count = MSG_ReadByte();
1305 CL_FindNonSolidLocation(pos, pos, 5);
1306 CL_Tei_PlasmaHit(pos, dir, count);
1307 Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
1308 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);
1312 Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
1316 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
1318 static qbyte cgamenetbuffer[65536];
1321 =====================
1322 CL_ParseServerMessage
1323 =====================
1325 int parsingerror = false;
1326 void CL_ParseServerMessage(void)
1331 char *cmdlogname[32], *temp;
1332 int cmdindex, cmdcount = 0;
1334 if (cls.demorecording)
1335 CL_WriteDemoMessage ();
1337 cl.last_received_message = realtime;
1340 // if recording demos, copy the message out
1342 if (cl_shownet.integer == 1)
1343 Con_Printf("%f %i\n", realtime, net_message.cursize);
1344 else if (cl_shownet.integer == 2)
1345 Con_Print("------------------\n");
1347 cl.onground = false; // unless the server says otherwise
1349 // parse the message
1351 //MSG_BeginReading ();
1353 parsingerror = true;
1358 Host_Error ("CL_ParseServerMessage: Bad server message");
1360 cmd = MSG_ReadByte ();
1364 SHOWNET("END OF MESSAGE");
1365 break; // end of message
1368 cmdindex = cmdcount & 31;
1370 cmdlog[cmdindex] = cmd;
1372 // if the high bit of the command byte is set, it is a fast update
1375 // 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)
1377 cmdlogname[cmdindex] = temp;
1378 SHOWNET("fast update");
1379 if (cls.signon == SIGNONS - 1)
1381 // first update is the final signon stage
1382 cls.signon = SIGNONS;
1385 EntityFrameQuake_ReadEntity (cmd&127);
1389 SHOWNET(svc_strings[cmd]);
1390 cmdlogname[cmdindex] = svc_strings[cmd];
1391 if (!cmdlogname[cmdindex])
1393 // 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)
1395 cmdlogname[cmdindex] = temp;
1403 char description[32*64], temp[64];
1405 strcpy (description, "packet dump: ");
1409 count = cmdcount - i;
1413 snprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
1414 strlcat (description, temp, sizeof (description));
1419 description[strlen(description)-1] = '\n'; // replace the last space with a newline
1420 Con_Print(description);
1421 Host_Error ("CL_ParseServerMessage: Illegible server message\n");
1426 if (cls.signon < SIGNONS)
1427 Con_Print("<-- server to client keepalive\n");
1431 cl.mtime[1] = cl.mtime[0];
1432 cl.mtime[0] = MSG_ReadFloat ();
1435 case svc_clientdata:
1436 i = (unsigned short) MSG_ReadShort ();
1437 CL_ParseClientdata (i);
1441 i = MSG_ReadLong ();
1442 // hack for unmarked Nehahra movie demos which had a custom protocol
1443 if (i == PROTOCOL_QUAKE && cls.demoplayback && demo_nehahra.integer)
1444 i = PROTOCOL_NEHAHRAMOVIE;
1445 if (i != PROTOCOL_QUAKE && i != PROTOCOL_DARKPLACES1 && i != PROTOCOL_DARKPLACES2 && i != PROTOCOL_DARKPLACES3 && i != PROTOCOL_DARKPLACES4 && i != PROTOCOL_DARKPLACES5 && i != PROTOCOL_DARKPLACES6 && i != PROTOCOL_NEHAHRAMOVIE)
1446 Host_Error("CL_ParseServerMessage: Server is protocol %i, not %i (Quake), %i (DP1), %i (DP2), %i (DP3), %i (DP4), %i (DP5), %i (DP6), or %i (Nehahra movie)", i, PROTOCOL_QUAKE, PROTOCOL_DARKPLACES1, PROTOCOL_DARKPLACES2, PROTOCOL_DARKPLACES3, PROTOCOL_DARKPLACES4, PROTOCOL_DARKPLACES5, PROTOCOL_DARKPLACES6, PROTOCOL_NEHAHRAMOVIE);
1450 case svc_disconnect:
1451 Con_Printf ("Server disconnected\n");
1452 if (cls.demonum != -1)
1459 Con_Print(MSG_ReadString());
1462 case svc_centerprint:
1463 SCR_CenterPrint(MSG_ReadString ());
1467 Cbuf_AddText (MSG_ReadString ());
1474 case svc_serverinfo:
1475 CL_ParseServerInfo ();
1479 for (i=0 ; i<3 ; i++)
1480 cl.viewangles[i] = MSG_ReadAngle (cl.protocol);
1484 cl.viewentity = (unsigned short)MSG_ReadShort ();
1485 if (cl.viewentity >= MAX_EDICTS)
1486 Host_Error("svc_setview >= MAX_EDICTS\n");
1487 // LordHavoc: assume first setview recieved is the real player entity
1488 if (!cl.playerentity)
1489 cl.playerentity = cl.viewentity;
1492 case svc_lightstyle:
1493 i = MSG_ReadByte ();
1494 if (i >= MAX_LIGHTSTYLES)
1495 Host_Error ("svc_lightstyle >= MAX_LIGHTSTYLES");
1496 strlcpy (cl_lightstyle[i].map, MSG_ReadString(), sizeof (cl_lightstyle[i].map));
1497 cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
1498 cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
1502 CL_ParseStartSoundPacket(false);
1506 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1508 // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
1509 CL_ParseStartSoundPacket(true);
1513 int i = (unsigned short)MSG_ReadShort();
1514 char *s = MSG_ReadString();
1517 if (i >= 1 && i < MAX_MODELS)
1519 model_t *model = Mod_ForName(s, false, false, i == 1);
1521 Con_Printf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
1522 cl.model_precache[i] = model;
1525 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
1530 if (i >= 1 && i < MAX_SOUNDS)
1532 sfx_t *sfx = S_PrecacheSound (s, true, false);
1533 if (!sfx && snd_initialized.integer)
1534 Con_Printf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
1535 cl.sound_precache[i] = sfx;
1538 Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
1544 i = (unsigned short) MSG_ReadShort();
1545 S_StopSound(i>>3, i&7);
1548 case svc_updatename:
1549 i = MSG_ReadByte ();
1550 if (i >= cl.maxclients)
1551 Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
1552 strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
1555 case svc_updatefrags:
1556 i = MSG_ReadByte ();
1557 if (i >= cl.maxclients)
1558 Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
1559 cl.scores[i].frags = (signed short) MSG_ReadShort ();
1562 case svc_updatecolors:
1563 i = MSG_ReadByte ();
1564 if (i >= cl.maxclients)
1565 Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
1566 cl.scores[i].colors = MSG_ReadByte ();
1570 CL_ParseParticleEffect ();
1581 case svc_spawnbaseline:
1582 i = (unsigned short) MSG_ReadShort ();
1583 if (i < 0 || i >= MAX_EDICTS)
1584 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
1585 CL_ParseBaseline (cl_entities + i, false);
1587 case svc_spawnbaseline2:
1588 i = (unsigned short) MSG_ReadShort ();
1589 if (i < 0 || i >= MAX_EDICTS)
1590 Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
1591 CL_ParseBaseline (cl_entities + i, true);
1593 case svc_spawnstatic:
1594 CL_ParseStatic (false);
1596 case svc_spawnstatic2:
1597 CL_ParseStatic (true);
1599 case svc_temp_entity:
1600 CL_ParseTempEntity ();
1604 cl.paused = MSG_ReadByte ();
1609 S_PauseGameSounds (cl.paused);
1613 i = MSG_ReadByte ();
1614 // LordHavoc: it's rude to kick off the client if they missed the
1615 // reconnect somehow, so allow signon 1 even if at signon 1
1616 if (i <= cls.signon && i != 1)
1617 Host_Error ("Received signon %i when at %i", i, cls.signon);
1622 case svc_killedmonster:
1623 cl.stats[STAT_MONSTERS]++;
1626 case svc_foundsecret:
1627 cl.stats[STAT_SECRETS]++;
1630 case svc_updatestat:
1631 i = MSG_ReadByte ();
1632 if (i < 0 || i >= MAX_CL_STATS)
1633 Host_Error ("svc_updatestat: %i is invalid", i);
1634 cl.stats[i] = MSG_ReadLong ();
1637 case svc_updatestatubyte:
1638 i = MSG_ReadByte ();
1639 if (i < 0 || i >= MAX_CL_STATS)
1640 Host_Error ("svc_updatestat: %i is invalid", i);
1641 cl.stats[i] = MSG_ReadByte ();
1644 case svc_spawnstaticsound:
1645 CL_ParseStaticSound (false);
1648 case svc_spawnstaticsound2:
1649 CL_ParseStaticSound (true);
1653 cl.cdtrack = MSG_ReadByte ();
1654 cl.looptrack = MSG_ReadByte ();
1655 if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
1656 CDAudio_Play ((qbyte)cls.forcetrack, true);
1658 CDAudio_Play ((qbyte)cl.cdtrack, true);
1661 case svc_intermission:
1662 cl.intermission = 1;
1663 cl.completed_time = cl.time;
1667 cl.intermission = 2;
1668 cl.completed_time = cl.time;
1669 SCR_CenterPrint(MSG_ReadString ());
1673 cl.intermission = 3;
1674 cl.completed_time = cl.time;
1675 SCR_CenterPrint(MSG_ReadString ());
1678 case svc_sellscreen:
1679 Cmd_ExecuteString ("help", src_command);
1682 if (gamemode == GAME_TENEBRAE)
1684 // repeating particle effect
1685 MSG_ReadCoord(cl.protocol);
1686 MSG_ReadCoord(cl.protocol);
1687 MSG_ReadCoord(cl.protocol);
1688 MSG_ReadCoord(cl.protocol);
1689 MSG_ReadCoord(cl.protocol);
1690 MSG_ReadCoord(cl.protocol);
1697 SHOWLMP_decodehide();
1700 if (gamemode == GAME_TENEBRAE)
1703 MSG_ReadCoord(cl.protocol);
1704 MSG_ReadCoord(cl.protocol);
1705 MSG_ReadCoord(cl.protocol);
1710 SHOWLMP_decodeshow();
1713 R_SetSkyBox(MSG_ReadString());
1718 length = (int) ((unsigned short) MSG_ReadShort());
1719 for (i = 0;i < length;i++)
1720 cgamenetbuffer[i] = MSG_ReadByte();
1722 CL_CGVM_ParseNetwork(cgamenetbuffer, length);
1726 if (cls.signon == SIGNONS - 1)
1728 // first update is the final signon stage
1729 cls.signon = SIGNONS;
1732 if (cl.protocol == PROTOCOL_DARKPLACES1 || cl.protocol == PROTOCOL_DARKPLACES2 || cl.protocol == PROTOCOL_DARKPLACES3)
1733 EntityFrame_CL_ReadFrame();
1734 else if (cl.protocol == PROTOCOL_DARKPLACES4)
1735 EntityFrame4_CL_ReadFrame();
1736 else if (cl.protocol == PROTOCOL_DARKPLACES5 || cl.protocol == PROTOCOL_DARKPLACES6)
1737 EntityFrame5_CL_ReadFrame();
1739 Host_Error("CL_ParseServerMessage: svc_entities: unknown cl.protocol %i\n", cl.protocol);
1744 EntityFrameQuake_ISeeDeadEntities();
1746 parsingerror = false;
1749 void CL_Parse_DumpPacket(void)
1753 Con_Print("Packet dump:\n");
1754 SZ_HexDumpToConsole(&net_message);
1755 parsingerror = false;
1758 void CL_Parse_Init(void)
1760 // LordHavoc: added demo_nehahra cvar
1761 cl_scores_mempool = Mem_AllocPool("client player info", 0, NULL);
1762 Cvar_RegisterVariable (&demo_nehahra);
1763 if (gamemode == GAME_NEHAHRA)
1764 Cvar_SetValue("demo_nehahra", 1);
1765 Cvar_RegisterVariable(&developer_networkentities);
1768 void CL_Parse_Shutdown(void)
1770 Mem_FreePool (&cl_scores_mempool);