+/*
+==================
+CL_ParseBaseline
+==================
+*/
+void CL_ParseBaseline (entity_t *ent, int large)
+{
+ int i;
+
+ ent->state_baseline = defaultstate;
+ // FIXME: set ent->state_baseline.number?
+ ent->state_baseline.active = true;
+ if (large)
+ {
+ ent->state_baseline.modelindex = (unsigned short) MSG_ReadShort ();
+ ent->state_baseline.frame = (unsigned short) MSG_ReadShort ();
+ }
+ else
+ {
+ ent->state_baseline.modelindex = MSG_ReadByte ();
+ ent->state_baseline.frame = MSG_ReadByte ();
+ }
+ ent->state_baseline.colormap = MSG_ReadByte();
+ ent->state_baseline.skin = MSG_ReadByte();
+ for (i = 0;i < 3;i++)
+ {
+ ent->state_baseline.origin[i] = MSG_ReadCoord(cls.protocol);
+ ent->state_baseline.angles[i] = MSG_ReadAngle(cls.protocol);
+ }
+ CL_ValidateState(&ent->state_baseline);
+ ent->state_previous = ent->state_current = ent->state_baseline;
+}
+
+
+/*
+==================
+CL_ParseClientdata
+
+Server information pertaining to this client only
+==================
+*/
+void CL_ParseClientdata (void)
+{
+ int i, bits;
+
+ VectorCopy (cl.mpunchangle[0], cl.mpunchangle[1]);
+ VectorCopy (cl.mpunchvector[0], cl.mpunchvector[1]);
+ VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
+ cl.mviewzoom[1] = cl.mviewzoom[0];
+
+ if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4 || cls.protocol == PROTOCOL_DARKPLACES5)
+ {
+ cl.stats[STAT_VIEWHEIGHT] = DEFAULT_VIEWHEIGHT;
+ cl.stats[STAT_ITEMS] = 0;
+ cl.stats[STAT_VIEWZOOM] = 255;
+ }
+ cl.idealpitch = 0;
+ cl.mpunchangle[0][0] = 0;
+ cl.mpunchangle[0][1] = 0;
+ cl.mpunchangle[0][2] = 0;
+ cl.mpunchvector[0][0] = 0;
+ cl.mpunchvector[0][1] = 0;
+ cl.mpunchvector[0][2] = 0;
+ cl.mvelocity[0][0] = 0;
+ cl.mvelocity[0][1] = 0;
+ cl.mvelocity[0][2] = 0;
+ cl.mviewzoom[0] = 1;
+
+ bits = (unsigned short) MSG_ReadShort ();
+ if (bits & SU_EXTEND1)
+ bits |= (MSG_ReadByte() << 16);
+ if (bits & SU_EXTEND2)
+ bits |= (MSG_ReadByte() << 24);
+
+ if (bits & SU_VIEWHEIGHT)
+ cl.stats[STAT_VIEWHEIGHT] = MSG_ReadChar ();
+
+ if (bits & SU_IDEALPITCH)
+ cl.idealpitch = MSG_ReadChar ();
+
+ for (i = 0;i < 3;i++)
+ {
+ if (bits & (SU_PUNCH1<<i) )
+ {
+ if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE)
+ cl.mpunchangle[0][i] = MSG_ReadChar();
+ else
+ cl.mpunchangle[0][i] = MSG_ReadAngle16i();
+ }
+ if (bits & (SU_PUNCHVEC1<<i))
+ {
+ if (cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
+ cl.mpunchvector[0][i] = MSG_ReadCoord16i();
+ else
+ cl.mpunchvector[0][i] = MSG_ReadCoord32f();
+ }
+ if (bits & (SU_VELOCITY1<<i) )
+ {
+ if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
+ cl.mvelocity[0][i] = MSG_ReadChar()*16;
+ else
+ cl.mvelocity[0][i] = MSG_ReadCoord32f();
+ }
+ }
+
+ // LordHavoc: hipnotic demos don't have this bit set but should
+ if (bits & SU_ITEMS || cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4 || cls.protocol == PROTOCOL_DARKPLACES5)
+ cl.stats[STAT_ITEMS] = MSG_ReadLong ();
+
+ cl.onground = (bits & SU_ONGROUND) != 0;
+ cl.inwater = (bits & SU_INWATER) != 0;
+
+ if (cls.protocol == PROTOCOL_DARKPLACES5)
+ {
+ cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadShort() : 0;
+ cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadShort() : 0;
+ cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadShort() : 0;
+ cl.stats[STAT_HEALTH] = MSG_ReadShort();
+ cl.stats[STAT_AMMO] = MSG_ReadShort();
+ cl.stats[STAT_SHELLS] = MSG_ReadShort();
+ cl.stats[STAT_NAILS] = MSG_ReadShort();
+ cl.stats[STAT_ROCKETS] = MSG_ReadShort();
+ cl.stats[STAT_CELLS] = MSG_ReadShort();
+ cl.stats[STAT_ACTIVEWEAPON] = (unsigned short) MSG_ReadShort ();
+ }
+ else if (cls.protocol == PROTOCOL_QUAKE || cls.protocol == PROTOCOL_QUAKEDP || cls.protocol == PROTOCOL_NEHAHRAMOVIE || cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
+ {
+ cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
+ cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
+ cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
+ cl.stats[STAT_HEALTH] = MSG_ReadShort();
+ cl.stats[STAT_AMMO] = MSG_ReadByte();
+ cl.stats[STAT_SHELLS] = MSG_ReadByte();
+ cl.stats[STAT_NAILS] = MSG_ReadByte();
+ cl.stats[STAT_ROCKETS] = MSG_ReadByte();
+ cl.stats[STAT_CELLS] = MSG_ReadByte();
+ if (gamemode == GAME_HIPNOTIC || gamemode == GAME_ROGUE || gamemode == GAME_NEXUIZ)
+ cl.stats[STAT_ACTIVEWEAPON] = (1<<MSG_ReadByte ());
+ else
+ cl.stats[STAT_ACTIVEWEAPON] = MSG_ReadByte ();
+ }
+
+ if (bits & SU_VIEWZOOM)
+ {
+ if (cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3 || cls.protocol == PROTOCOL_DARKPLACES4)
+ cl.stats[STAT_VIEWZOOM] = MSG_ReadByte();
+ else
+ cl.stats[STAT_VIEWZOOM] = (unsigned short) MSG_ReadShort();
+ }
+
+ // viewzoom interpolation
+ cl.mviewzoom[0] = (float) max(cl.stats[STAT_VIEWZOOM], 2) * (1.0f / 255.0f);
+
+ // force a recalculation of the player prediction
+ cl.movement_replay = true;
+}
+
+/*
+=====================
+CL_ParseStatic
+=====================
+*/
+void CL_ParseStatic (int large)
+{
+ entity_t *ent;
+
+ if (cl.num_static_entities >= cl.max_static_entities)
+ Host_Error ("Too many static entities");
+ ent = &cl.static_entities[cl.num_static_entities++];
+ CL_ParseBaseline (ent, large);
+
+// copy it to the current state
+ ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
+ ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
+ ent->render.framelerp = 0;
+ // make torchs play out of sync
+ ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
+ ent->render.colormap = -1; // no special coloring
+ ent->render.skinnum = ent->state_baseline.skin;
+ ent->render.effects = ent->state_baseline.effects;
+ ent->render.alpha = 1;
+ //ent->render.scale = 1;
+
+ //VectorCopy (ent->state_baseline.origin, ent->render.origin);
+ //VectorCopy (ent->state_baseline.angles, ent->render.angles);
+
+ 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);
+ Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
+ CL_BoundingBoxForEntity(&ent->render);
+
+ // This is definitely cheating...
+ if (ent->render.model == NULL)
+ cl.num_static_entities--;
+}
+
+/*
+===================
+CL_ParseStaticSound
+===================
+*/
+void CL_ParseStaticSound (int large)
+{
+ vec3_t org;
+ int sound_num, vol, atten;
+
+ MSG_ReadVector(org, cls.protocol);
+ if (large)
+ sound_num = (unsigned short) MSG_ReadShort ();
+ else
+ sound_num = MSG_ReadByte ();
+ vol = MSG_ReadByte ();
+ atten = MSG_ReadByte ();
+
+ S_StaticSound (cl.sound_precache[sound_num], org, vol/255.0f, atten);
+}
+
+void CL_ParseEffect (void)
+{
+ vec3_t org;
+ int modelindex, startframe, framecount, framerate;
+
+ MSG_ReadVector(org, cls.protocol);
+ modelindex = MSG_ReadByte ();
+ startframe = MSG_ReadByte ();
+ framecount = MSG_ReadByte ();
+ framerate = MSG_ReadByte ();
+
+ CL_Effect(org, modelindex, startframe, framecount, framerate);
+}
+
+void CL_ParseEffect2 (void)
+{
+ vec3_t org;
+ int modelindex, startframe, framecount, framerate;
+
+ MSG_ReadVector(org, cls.protocol);
+ modelindex = (unsigned short) MSG_ReadShort ();
+ startframe = (unsigned short) MSG_ReadShort ();
+ framecount = MSG_ReadByte ();
+ framerate = MSG_ReadByte ();
+
+ CL_Effect(org, modelindex, startframe, framecount, framerate);
+}
+
+void CL_NewBeam (int ent, vec3_t start, vec3_t end, model_t *m, int lightning)
+{
+ int i;
+ beam_t *b = NULL;
+
+ if (ent >= MAX_EDICTS)
+ {
+ Con_Printf("CL_NewBeam: invalid entity number %i\n", ent);
+ ent = 0;
+ }
+
+ if (ent >= cl.max_entities)
+ CL_ExpandEntities(ent);
+
+ // override any beam with the same entity
+ i = cl.max_beams;
+ if (ent)
+ for (i = 0, b = cl.beams;i < cl.max_beams;i++, b++)
+ if (b->entity == ent)
+ break;
+ // if the entity was not found then just replace an unused beam
+ if (i == cl.max_beams)
+ for (i = 0, b = cl.beams;i < cl.max_beams;i++, b++)
+ if (!b->model)
+ break;
+ if (i < cl.max_beams)
+ {
+ cl.num_beams = max(cl.num_beams, i + 1);
+ b->entity = ent;
+ b->lightning = lightning;
+ b->model = m;
+ b->endtime = cl.mtime[0] + 0.2;
+ VectorCopy (start, b->start);
+ VectorCopy (end, b->end);
+ }
+ else
+ Con_Print("beam list overflow!\n");
+}
+
+void CL_ParseBeam (model_t *m, int lightning)
+{
+ int ent;
+ vec3_t start, end;
+
+ ent = (unsigned short) MSG_ReadShort ();
+ MSG_ReadVector(start, cls.protocol);
+ MSG_ReadVector(end, cls.protocol);
+
+ if (ent >= MAX_EDICTS)
+ {
+ Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
+ ent = 0;
+ }
+
+ CL_NewBeam(ent, start, end, m, lightning);
+}
+
+void CL_ParseTempEntity(void)
+{
+ int type;
+ vec3_t pos, pos2;
+ vec3_t vel1, vel2;
+ vec3_t dir;
+ vec3_t color;
+ int rnd;
+ int colorStart, colorLength, count;
+ float velspeed, radius;
+ unsigned char *tempcolor;
+ matrix4x4_t tempmatrix;
+
+ if (cls.protocol == PROTOCOL_QUAKEWORLD)
+ {
+ type = MSG_ReadByte();
+ switch (type)
+ {
+ case QW_TE_WIZSPIKE:
+ // spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_WIZSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_wizhit, pos, 1, 1);
+ break;
+
+ case QW_TE_KNIGHTSPIKE:
+ // spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_KNIGHTSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_knighthit, pos, 1, 1);
+ break;
+
+ case QW_TE_SPIKE:
+ // spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_SPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ if (rand() % 5)
+ S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
+ else
+ {
+ rnd = rand() & 3;
+ if (rnd == 1)
+ S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
+ else if (rnd == 2)
+ S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
+ else
+ S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
+ }
+ break;
+ case QW_TE_SUPERSPIKE:
+ // super spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_SUPERSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ if (rand() % 5)
+ S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
+ else
+ {
+ rnd = rand() & 3;
+ if (rnd == 1)
+ S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
+ else if (rnd == 2)
+ S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
+ else
+ S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
+ }
+ break;
+
+ case QW_TE_EXPLOSION:
+ // rocket explosion
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ CL_ParticleEffect(EFFECT_TE_EXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
+ CL_Effect(pos, cl.qw_modelindex_s_explod, 0, 6, 10);
+ break;
+
+ case QW_TE_TAREXPLOSION:
+ // tarbaby explosion
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ CL_ParticleEffect(EFFECT_TE_TAREXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case QW_TE_LIGHTNING1:
+ // lightning bolts
+ CL_ParseBeam(cl.model_bolt, true);
+ break;
+
+ case QW_TE_LIGHTNING2:
+ // lightning bolts
+ CL_ParseBeam(cl.model_bolt2, true);
+ break;
+
+ case QW_TE_LIGHTNING3:
+ // lightning bolts
+ CL_ParseBeam(cl.model_bolt3, false);
+ break;
+
+ case QW_TE_LAVASPLASH:
+ MSG_ReadVector(pos, cls.protocol);
+ CL_ParticleEffect(EFFECT_TE_LAVASPLASH, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case QW_TE_TELEPORT:
+ MSG_ReadVector(pos, cls.protocol);
+ CL_ParticleEffect(EFFECT_TE_TELEPORT, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case QW_TE_GUNSHOT:
+ // bullet hitting wall
+ radius = MSG_ReadByte();
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ VectorSet(pos2, pos[0] + radius, pos[1] + radius, pos[2] + radius);
+ VectorSet(pos, pos[0] - radius, pos[1] - radius, pos[2] - radius);
+ CL_ParticleEffect(EFFECT_TE_GUNSHOT, radius, pos, pos2, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case QW_TE_BLOOD:
+ count = MSG_ReadByte();
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_BLOOD, count, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case QW_TE_LIGHTNINGBLOOD:
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_BLOOD, 2.5, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ default:
+ Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
+ }
+ }
+ else
+ {
+ type = MSG_ReadByte();
+ switch (type)
+ {
+ case TE_WIZSPIKE:
+ // spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_WIZSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_wizhit, pos, 1, 1);
+ break;
+
+ case TE_KNIGHTSPIKE:
+ // spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_KNIGHTSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_knighthit, pos, 1, 1);
+ break;
+
+ case TE_SPIKE:
+ // spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_SPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ if (rand() % 5)
+ S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
+ else
+ {
+ rnd = rand() & 3;
+ if (rnd == 1)
+ S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
+ else if (rnd == 2)
+ S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
+ else
+ S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
+ }
+ break;
+ case TE_SPIKEQUAD:
+ // quad spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_SPIKEQUAD, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ if (rand() % 5)
+ S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
+ else
+ {
+ rnd = rand() & 3;
+ if (rnd == 1)
+ S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
+ else if (rnd == 2)
+ S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
+ else
+ S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
+ }
+ break;
+ case TE_SUPERSPIKE:
+ // super spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_SUPERSPIKE, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ if (rand() % 5)
+ S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
+ else
+ {
+ rnd = rand() & 3;
+ if (rnd == 1)
+ S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
+ else if (rnd == 2)
+ S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
+ else
+ S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
+ }
+ break;
+ case TE_SUPERSPIKEQUAD:
+ // quad super spike hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_SUPERSPIKEQUAD, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ if (rand() % 5)
+ S_StartSound(-1, 0, cl.sfx_tink1, pos, 1, 1);
+ else
+ {
+ rnd = rand() & 3;
+ if (rnd == 1)
+ S_StartSound(-1, 0, cl.sfx_ric1, pos, 1, 1);
+ else if (rnd == 2)
+ S_StartSound(-1, 0, cl.sfx_ric2, pos, 1, 1);
+ else
+ S_StartSound(-1, 0, cl.sfx_ric3, pos, 1, 1);
+ }
+ break;
+ // LordHavoc: added for improved blood splatters
+ case TE_BLOOD:
+ // blood puff
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ dir[0] = MSG_ReadChar();
+ dir[1] = MSG_ReadChar();
+ dir[2] = MSG_ReadChar();
+ count = MSG_ReadByte();
+ CL_ParticleEffect(EFFECT_TE_BLOOD, count, pos, pos, dir, dir, NULL, 0);
+ break;
+ case TE_SPARK:
+ // spark shower
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ dir[0] = MSG_ReadChar();
+ dir[1] = MSG_ReadChar();
+ dir[2] = MSG_ReadChar();
+ count = MSG_ReadByte();
+ CL_ParticleEffect(EFFECT_TE_SPARK, count, pos, pos, dir, dir, NULL, 0);
+ break;
+ case TE_PLASMABURN:
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_PLASMABURN, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+ // LordHavoc: added for improved gore
+ case TE_BLOODSHOWER:
+ // vaporized body
+ MSG_ReadVector(pos, cls.protocol); // mins
+ MSG_ReadVector(pos2, cls.protocol); // maxs
+ velspeed = MSG_ReadCoord(cls.protocol); // speed
+ count = (unsigned short) MSG_ReadShort(); // number of particles
+ vel1[0] = -velspeed;
+ vel1[1] = -velspeed;
+ vel1[2] = -velspeed;
+ vel2[0] = velspeed;
+ vel2[1] = velspeed;
+ vel2[2] = velspeed;
+ CL_ParticleEffect(EFFECT_TE_BLOOD, count, pos, pos2, vel1, vel2, NULL, 0);
+ break;
+
+ case TE_PARTICLECUBE:
+ // general purpose particle effect
+ MSG_ReadVector(pos, cls.protocol); // mins
+ MSG_ReadVector(pos2, cls.protocol); // maxs
+ MSG_ReadVector(dir, cls.protocol); // dir
+ count = (unsigned short) MSG_ReadShort(); // number of particles
+ colorStart = MSG_ReadByte(); // color
+ colorLength = MSG_ReadByte(); // gravity (1 or 0)
+ velspeed = MSG_ReadCoord(cls.protocol); // randomvel
+ CL_ParticleCube(pos, pos2, dir, count, colorStart, colorLength != 0, velspeed);
+ break;
+
+ case TE_PARTICLERAIN:
+ // general purpose particle effect
+ MSG_ReadVector(pos, cls.protocol); // mins
+ MSG_ReadVector(pos2, cls.protocol); // maxs
+ MSG_ReadVector(dir, cls.protocol); // dir
+ count = (unsigned short) MSG_ReadShort(); // number of particles
+ colorStart = MSG_ReadByte(); // color
+ CL_ParticleRain(pos, pos2, dir, count, colorStart, 0);
+ break;
+
+ case TE_PARTICLESNOW:
+ // general purpose particle effect
+ MSG_ReadVector(pos, cls.protocol); // mins
+ MSG_ReadVector(pos2, cls.protocol); // maxs
+ MSG_ReadVector(dir, cls.protocol); // dir
+ count = (unsigned short) MSG_ReadShort(); // number of particles
+ colorStart = MSG_ReadByte(); // color
+ CL_ParticleRain(pos, pos2, dir, count, colorStart, 1);
+ break;
+
+ case TE_GUNSHOT:
+ // bullet hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_GUNSHOT, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case TE_GUNSHOTQUAD:
+ // quad bullet hitting wall
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_GUNSHOTQUAD, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case TE_EXPLOSION:
+ // rocket explosion
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ CL_ParticleEffect(EFFECT_TE_EXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case TE_EXPLOSIONQUAD:
+ // quad rocket explosion
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ CL_ParticleEffect(EFFECT_TE_EXPLOSIONQUAD, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case TE_EXPLOSION3:
+ // Nehahra movie colored lighting explosion
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ color[0] = MSG_ReadCoord(cls.protocol) * (2.0f / 1.0f);
+ color[1] = MSG_ReadCoord(cls.protocol) * (2.0f / 1.0f);
+ color[2] = MSG_ReadCoord(cls.protocol) * (2.0f / 1.0f);
+ CL_ParticleExplosion(pos);
+ Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
+ 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);
+ S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case TE_EXPLOSIONRGB:
+ // colored lighting explosion
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ CL_ParticleExplosion(pos);
+ color[0] = MSG_ReadByte() * (2.0f / 255.0f);
+ color[1] = MSG_ReadByte() * (2.0f / 255.0f);
+ color[2] = MSG_ReadByte() * (2.0f / 255.0f);
+ Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
+ 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);
+ S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case TE_TAREXPLOSION:
+ // tarbaby explosion
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ CL_ParticleEffect(EFFECT_TE_TAREXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case TE_SMALLFLASH:
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ CL_ParticleEffect(EFFECT_TE_SMALLFLASH, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case TE_CUSTOMFLASH:
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 4);
+ radius = (MSG_ReadByte() + 1) * 8;
+ velspeed = (MSG_ReadByte() + 1) * (1.0 / 256.0);
+ color[0] = MSG_ReadByte() * (2.0f / 255.0f);
+ color[1] = MSG_ReadByte() * (2.0f / 255.0f);
+ color[2] = MSG_ReadByte() * (2.0f / 255.0f);
+ Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
+ 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);
+ break;
+
+ case TE_FLAMEJET:
+ MSG_ReadVector(pos, cls.protocol);
+ MSG_ReadVector(dir, cls.protocol);
+ count = MSG_ReadByte();
+ CL_ParticleEffect(EFFECT_TE_FLAMEJET, count, pos, pos, dir, dir, NULL, 0);
+ break;
+
+ case TE_LIGHTNING1:
+ // lightning bolts
+ CL_ParseBeam(cl.model_bolt, true);
+ break;
+
+ case TE_LIGHTNING2:
+ // lightning bolts
+ CL_ParseBeam(cl.model_bolt2, true);
+ break;
+
+ case TE_LIGHTNING3:
+ // lightning bolts
+ CL_ParseBeam(cl.model_bolt3, false);
+ break;
+
+ // PGM 01/21/97
+ case TE_BEAM:
+ // grappling hook beam
+ CL_ParseBeam(cl.model_beam, false);
+ break;
+ // PGM 01/21/97
+
+ // LordHavoc: for compatibility with the Nehahra movie...
+ case TE_LIGHTNING4NEH:
+ CL_ParseBeam(Mod_ForName(MSG_ReadString(), true, false, false), false);
+ break;
+
+ case TE_LAVASPLASH:
+ MSG_ReadVector(pos, cls.protocol);
+ CL_ParticleEffect(EFFECT_TE_LAVASPLASH, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case TE_TELEPORT:
+ MSG_ReadVector(pos, cls.protocol);
+ CL_ParticleEffect(EFFECT_TE_TELEPORT, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case TE_EXPLOSION2:
+ // color mapped explosion
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ colorStart = MSG_ReadByte();
+ colorLength = MSG_ReadByte();
+ CL_ParticleExplosion2(pos, colorStart, colorLength);
+ tempcolor = (unsigned char *)&palette_complete[(rand()%colorLength) + colorStart];
+ color[0] = tempcolor[0] * (2.0f / 255.0f);
+ color[1] = tempcolor[1] * (2.0f / 255.0f);
+ color[2] = tempcolor[2] * (2.0f / 255.0f);
+ Matrix4x4_CreateTranslate(&tempmatrix, pos[0], pos[1], pos[2]);
+ 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);
+ S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case TE_TEI_G3:
+ MSG_ReadVector(pos, cls.protocol);
+ MSG_ReadVector(pos2, cls.protocol);
+ MSG_ReadVector(dir, cls.protocol);
+ CL_ParticleEffect(EFFECT_TE_TEI_G3, 1, pos, pos2, dir, dir, NULL, 0);
+ break;
+
+ case TE_TEI_SMOKE:
+ MSG_ReadVector(pos, cls.protocol);
+ MSG_ReadVector(dir, cls.protocol);
+ count = MSG_ReadByte();
+ CL_FindNonSolidLocation(pos, pos, 4);
+ CL_ParticleEffect(EFFECT_TE_TEI_SMOKE, count, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ case TE_TEI_BIGEXPLOSION:
+ MSG_ReadVector(pos, cls.protocol);
+ CL_FindNonSolidLocation(pos, pos, 10);
+ CL_ParticleEffect(EFFECT_TE_TEI_BIGEXPLOSION, 1, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ S_StartSound(-1, 0, cl.sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case TE_TEI_PLASMAHIT:
+ MSG_ReadVector(pos, cls.protocol);
+ MSG_ReadVector(dir, cls.protocol);
+ count = MSG_ReadByte();
+ CL_FindNonSolidLocation(pos, pos, 5);
+ CL_ParticleEffect(EFFECT_TE_TEI_PLASMAHIT, count, pos, pos, vec3_origin, vec3_origin, NULL, 0);
+ break;
+
+ default:
+ Host_Error("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
+ }
+ }
+}
+
+// look for anything interesting like player IP addresses or ping reports
+qboolean CL_ExaminePrintString(const char *text)
+{
+ const char *t;
+ if (!strcmp(text, "Client ping times:\n"))
+ {
+ cl.parsingtextmode = CL_PARSETEXTMODE_PING;
+ for(cl.parsingtextplayerindex = 0; cl.parsingtextplayerindex < cl.maxclients && !cl.scores[cl.parsingtextplayerindex].name[0]; cl.parsingtextplayerindex++)
+ ;
+ if (cl.parsingtextplayerindex >= cl.maxclients) // should never happen, since the client itself should be in cl.scores
+ {
+ Con_Printf("ping reply but empty scoreboard?!?\n");
+ cl.parsingtextmode = CL_PARSETEXTMODE_NONE;
+ cl.parsingtextexpectingpingforscores = 0;
+ }
+ cl.parsingtextexpectingpingforscores = cl.parsingtextexpectingpingforscores ? 2 : 0;
+ return !cl.parsingtextexpectingpingforscores;
+ }
+ if (!strncmp(text, "host: ", 9))
+ {
+ // cl.parsingtextexpectingpingforscores = false; // really?
+ cl.parsingtextmode = CL_PARSETEXTMODE_STATUS;
+ cl.parsingtextplayerindex = 0;
+ return true;
+ }
+ if (cl.parsingtextmode == CL_PARSETEXTMODE_PING)
+ {
+ // if anything goes wrong, we'll assume this is not a ping report
+ qboolean expected = cl.parsingtextexpectingpingforscores;
+ cl.parsingtextexpectingpingforscores = 0;
+ cl.parsingtextmode = CL_PARSETEXTMODE_NONE;
+ t = text;
+ while (*t == ' ')
+ t++;
+ if ((*t >= '0' && *t <= '9') || *t == '-')
+ {
+ int ping = atoi(t);
+ while ((*t >= '0' && *t <= '9') || *t == '-')
+ t++;
+ if (*t == ' ')
+ {
+ int charindex = 0;
+ t++;
+ if(cl.parsingtextplayerindex < cl.maxclients)
+ {
+ for (charindex = 0;cl.scores[cl.parsingtextplayerindex].name[charindex] == t[charindex];charindex++)
+ ;
+ if (cl.scores[cl.parsingtextplayerindex].name[charindex] == 0 && t[charindex] == '\n')
+ {
+ cl.scores[cl.parsingtextplayerindex].qw_ping = bound(0, ping, 9999);
+ for (cl.parsingtextplayerindex++;cl.parsingtextplayerindex < cl.maxclients && !cl.scores[cl.parsingtextplayerindex].name[0];cl.parsingtextplayerindex++)
+ ;
+ //if (cl.parsingtextplayerindex < cl.maxclients) // we could still get unconnecteds!
+ {
+ // we parsed a valid ping entry, so expect another to follow
+ cl.parsingtextmode = CL_PARSETEXTMODE_PING;
+ cl.parsingtextexpectingpingforscores = expected;
+ }
+ return !expected;
+ }
+ }
+ if (!strncmp(t, "unconnected\n", 12))
+ {
+ // just ignore
+ cl.parsingtextmode = CL_PARSETEXTMODE_PING;
+ cl.parsingtextexpectingpingforscores = expected;
+ return !expected;
+ }
+ else
+ Con_DPrintf("player names '%s' and '%s' didn't match\n", cl.scores[cl.parsingtextplayerindex].name, t);
+ }
+ }
+ }
+ if (cl.parsingtextmode == CL_PARSETEXTMODE_STATUS)
+ {
+ if (!strncmp(text, "players: ", 9))
+ {
+ cl.parsingtextmode = CL_PARSETEXTMODE_STATUS_PLAYERID;
+ cl.parsingtextplayerindex = 0;
+ return true;
+ }
+ else if (!strstr(text, ": "))
+ {
+ cl.parsingtextmode = CL_PARSETEXTMODE_NONE; // status report ended
+ return true;
+ }
+ }
+ if (cl.parsingtextmode == CL_PARSETEXTMODE_STATUS_PLAYERID)
+ {
+ // if anything goes wrong, we'll assume this is not a status report
+ cl.parsingtextmode = CL_PARSETEXTMODE_NONE;
+ if (text[0] == '#' && text[1] >= '0' && text[1] <= '9')
+ {
+ t = text + 1;
+ cl.parsingtextplayerindex = atoi(t);
+ while (*t >= '0' && *t <= '9')
+ t++;
+ if (*t == ' ')
+ {
+ cl.parsingtextmode = CL_PARSETEXTMODE_STATUS_PLAYERIP;
+ return true;
+ }
+ }
+ }
+ if (cl.parsingtextmode == CL_PARSETEXTMODE_STATUS_PLAYERIP)
+ {
+ // if anything goes wrong, we'll assume this is not a status report
+ cl.parsingtextmode = CL_PARSETEXTMODE_NONE;
+ if (text[0] == ' ')
+ {
+ t = text;
+ while (*t == ' ')
+ t++;
+ // botclient is perfectly valid, but we don't care about bots
+ if (strcmp(t, "botclient\n"))
+ {
+ lhnetaddress_t address;
+ LHNETADDRESS_FromString(&address, t, 0);
+ // TODO: log the IP address and player name?
+ }
+ cl.parsingtextmode = CL_PARSETEXTMODE_STATUS_PLAYERID;
+ return true;
+ }
+ }
+ return true;
+}
+
+#define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
+
+//[515]: csqc
+void CL_VM_Init (void);
+qboolean CL_VM_Parse_TempEntity (void);
+void CL_VM_Parse_StuffCmd (const char *msg);
+void CL_VM_Parse_CenterPrint (const char *msg);
+void CSQC_AddPrintText (const char *msg);
+void CSQC_ReadEntities (void);
+
+/*
+=====================
+CL_ParseServerMessage
+=====================
+*/
+int parsingerror = false;
+void CL_ParseServerMessage(void)
+{
+ int cmd;
+ int i;
+ protocolversion_t protocol;
+ unsigned char cmdlog[32];
+ char *cmdlogname[32], *temp;
+ int cmdindex, cmdcount = 0;
+
+ if (cls.demorecording)
+ CL_WriteDemoMessage ();
+
+ cl.last_received_message = realtime;
+
+//
+// if recording demos, copy the message out
+//
+ if (cl_shownet.integer == 1)
+ Con_Printf("%f %i\n", realtime, net_message.cursize);
+ else if (cl_shownet.integer == 2)
+ Con_Print("------------------\n");
+
+//
+// parse the message
+//
+ //MSG_BeginReading ();
+
+ parsingerror = true;
+
+ if (cls.protocol == PROTOCOL_QUAKEWORLD)
+ {
+ cl.mtime[1] = cl.mtime[0];
+ cl.mtime[0] = realtime; // qw has no clock
+ cl.movement_needupdate = true;
+ cl.onground = false; // since there's no clientdata parsing, clear the onground flag here
+ // if true the cl.viewangles are interpolated from cl.mviewangles[]
+ // during this frame
+ // (makes spectating players much smoother and prevents mouse movement from turning)
+ cl.fixangle[1] = cl.fixangle[0];
+ cl.fixangle[0] = false;
+ if (!cls.demoplayback)
+ VectorCopy(cl.mviewangles[0], cl.mviewangles[1]);
+
+ // force a recalculation of the player prediction
+ cl.movement_replay = true;
+
+ // slightly kill qw player entities each frame
+ for (i = 1;i < cl.maxclients;i++)
+ cl.entities_active[i] = false;
+
+ // kill all qw nails
+ cl.qw_num_nails = 0;
+
+ // fade weapon view kick
+ cl.qw_weaponkick = min(cl.qw_weaponkick + 10 * (cl.time - cl.oldtime), 0);
+
+ while (1)
+ {
+ if (msg_badread)
+ Host_Error ("CL_ParseServerMessage: Bad QW server message");
+
+ cmd = MSG_ReadByte ();
+
+ if (cmd == -1)
+ {
+ SHOWNET("END OF MESSAGE");
+ break; // end of message
+ }
+
+ cmdindex = cmdcount & 31;
+ cmdcount++;
+ cmdlog[cmdindex] = cmd;
+
+ SHOWNET(qw_svc_strings[cmd]);
+ cmdlogname[cmdindex] = qw_svc_strings[cmd];
+ if (!cmdlogname[cmdindex])
+ {
+ // 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)
+ temp = "<unknown>";
+ cmdlogname[cmdindex] = temp;
+ }
+
+ // other commands
+ switch (cmd)
+ {
+ default:
+ {
+ char description[32*64], temp[64];
+ int count;
+ strlcpy(description, "packet dump: ", sizeof(description));
+ i = cmdcount - 32;
+ if (i < 0)
+ i = 0;
+ count = cmdcount - i;
+ i &= 31;
+ while(count > 0)
+ {
+ dpsnprintf(temp, sizeof(temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
+ strlcat(description, temp, sizeof(description));
+ count--;
+ i++;
+ i &= 31;
+ }
+ description[strlen(description)-1] = '\n'; // replace the last space with a newline
+ Con_Print(description);
+ Host_Error("CL_ParseServerMessage: Illegible server message");
+ }
+ break;
+
+ case qw_svc_nop:
+ //Con_Printf("qw_svc_nop\n");
+ break;
+
+ case qw_svc_disconnect:
+ Con_Printf("Server disconnected\n");
+ if (cls.demonum != -1)
+ CL_NextDemo();
+ else
+ CL_Disconnect();
+ return;
+
+ case qw_svc_print:
+ i = MSG_ReadByte();
+ temp = MSG_ReadString();
+ if (CL_ExaminePrintString(temp)) // look for anything interesting like player IP addresses or ping reports
+ {
+ if (i == 3) // chat
+ CSQC_AddPrintText(va("\1%s", temp)); //[515]: csqc
+ else
+ CSQC_AddPrintText(temp);
+ }
+ break;
+
+ case qw_svc_centerprint:
+ CL_VM_Parse_CenterPrint(MSG_ReadString ()); //[515]: csqc
+ break;
+
+ case qw_svc_stufftext:
+ CL_VM_Parse_StuffCmd(MSG_ReadString ()); //[515]: csqc
+ break;
+
+ case qw_svc_damage:
+ // svc_damage protocol is identical to nq
+ V_ParseDamage ();
+ break;
+
+ case qw_svc_serverdata:
+ //Cbuf_Execute(); // make sure any stuffed commands are done
+ CL_ParseServerInfo();
+ CL_VM_Init(); //[515]: init csqc
+ break;
+
+ case qw_svc_setangle:
+ for (i=0 ; i<3 ; i++)
+ cl.viewangles[i] = MSG_ReadAngle (cls.protocol);
+ if (!cls.demoplayback)
+ {
+ cl.fixangle[0] = true;
+ VectorCopy(cl.viewangles, cl.mviewangles[0]);
+ // disable interpolation if this is new
+ if (!cl.fixangle[1])
+ VectorCopy(cl.viewangles, cl.mviewangles[1]);
+ }
+ break;
+
+ case qw_svc_lightstyle:
+ i = MSG_ReadByte ();
+ if (i >= cl.max_lightstyle)
+ {
+ Con_Printf ("svc_lightstyle >= MAX_LIGHTSTYLES");
+ break;
+ }
+ strlcpy (cl.lightstyle[i].map, MSG_ReadString(), sizeof (cl.lightstyle[i].map));
+ cl.lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
+ cl.lightstyle[i].length = (int)strlen(cl.lightstyle[i].map);
+ break;
+
+ case qw_svc_sound:
+ CL_ParseStartSoundPacket(false);
+ break;
+
+ case qw_svc_stopsound:
+ i = (unsigned short) MSG_ReadShort();
+ S_StopSound(i>>3, i&7);
+ break;
+
+ case qw_svc_updatefrags:
+ i = MSG_ReadByte();
+ if (i >= cl.maxclients)
+ Host_Error("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
+ cl.scores[i].frags = (signed short) MSG_ReadShort();
+ break;
+
+ case qw_svc_updateping:
+ i = MSG_ReadByte();
+ if (i >= cl.maxclients)
+ Host_Error("CL_ParseServerMessage: svc_updateping >= cl.maxclients");
+ cl.scores[i].qw_ping = MSG_ReadShort();
+ break;
+
+ case qw_svc_updatepl:
+ i = MSG_ReadByte();
+ if (i >= cl.maxclients)
+ Host_Error("CL_ParseServerMessage: svc_updatepl >= cl.maxclients");
+ cl.scores[i].qw_packetloss = MSG_ReadByte();
+ break;
+
+ case qw_svc_updateentertime:
+ i = MSG_ReadByte();
+ if (i >= cl.maxclients)
+ Host_Error("CL_ParseServerMessage: svc_updateentertime >= cl.maxclients");
+ // seconds ago
+ cl.scores[i].qw_entertime = cl.time - MSG_ReadFloat();
+ break;
+
+ case qw_svc_spawnbaseline:
+ i = (unsigned short) MSG_ReadShort();
+ if (i < 0 || i >= MAX_EDICTS)
+ Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
+ if (i >= cl.max_entities)
+ CL_ExpandEntities(i);
+ CL_ParseBaseline(cl.entities + i, false);
+ break;
+ case qw_svc_spawnstatic:
+ CL_ParseStatic(false);
+ break;
+ case qw_svc_temp_entity:
+ if(!CL_VM_Parse_TempEntity())
+ CL_ParseTempEntity ();
+ break;
+
+ case qw_svc_killedmonster:
+ cl.stats[STAT_MONSTERS]++;
+ break;
+
+ case qw_svc_foundsecret:
+ cl.stats[STAT_SECRETS]++;
+ break;
+
+ case qw_svc_updatestat:
+ i = MSG_ReadByte ();
+ if (i < 0 || i >= MAX_CL_STATS)
+ Host_Error ("svc_updatestat: %i is invalid", i);
+ cl.stats[i] = MSG_ReadByte ();
+ break;
+
+ case qw_svc_updatestatlong:
+ i = MSG_ReadByte ();
+ if (i < 0 || i >= MAX_CL_STATS)
+ Host_Error ("svc_updatestatlong: %i is invalid", i);
+ cl.stats[i] = MSG_ReadLong ();
+ break;
+
+ case qw_svc_spawnstaticsound:
+ CL_ParseStaticSound (false);
+ break;
+
+ case qw_svc_cdtrack:
+ cl.cdtrack = cl.looptrack = MSG_ReadByte ();
+ if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
+ CDAudio_Play ((unsigned char)cls.forcetrack, true);
+ else
+ CDAudio_Play ((unsigned char)cl.cdtrack, true);
+ break;
+
+ case qw_svc_intermission:
+ cl.intermission = 1;
+ cl.completed_time = cl.time;
+ MSG_ReadVector(cl.qw_intermission_origin, cls.protocol);
+ for (i = 0;i < 3;i++)
+ cl.qw_intermission_angles[i] = MSG_ReadAngle(cls.protocol);
+ break;
+
+ case qw_svc_finale:
+ cl.intermission = 2;
+ cl.completed_time = cl.time;
+ SCR_CenterPrint(MSG_ReadString ());
+ break;
+
+ case qw_svc_sellscreen:
+ Cmd_ExecuteString ("help", src_command);
+ break;
+
+ case qw_svc_smallkick:
+ cl.qw_weaponkick = -2;
+ break;
+ case qw_svc_bigkick:
+ cl.qw_weaponkick = -4;
+ break;
+
+ case qw_svc_muzzleflash:
+ i = (unsigned short) MSG_ReadShort();
+ // NOTE: in QW this only worked on clients
+ if (i < 0 || i >= MAX_EDICTS)
+ Host_Error("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
+ if (i >= cl.max_entities)
+ CL_ExpandEntities(i);
+ cl.entities[i].persistent.muzzleflash = 1.0f;
+ break;
+
+ case qw_svc_updateuserinfo:
+ QW_CL_UpdateUserInfo();
+ break;
+
+ case qw_svc_setinfo:
+ QW_CL_SetInfo();
+ break;
+
+ case qw_svc_serverinfo:
+ QW_CL_ServerInfo();
+ break;
+
+ case qw_svc_download:
+ QW_CL_ParseDownload();
+ break;
+
+ case qw_svc_playerinfo:
+ EntityStateQW_ReadPlayerUpdate();
+ break;
+
+ case qw_svc_nails:
+ QW_CL_ParseNails();
+ break;
+
+ case qw_svc_chokecount:
+ i = MSG_ReadByte();
+ // FIXME: apply to netgraph
+ //for (j = 0;j < i;j++)
+ // cl.frames[(cls.netcon->qw.incoming_acknowledged-1-j)&QW_UPDATE_MASK].receivedtime = -2;
+ break;
+
+ case qw_svc_modellist:
+ QW_CL_ParseModelList();
+ break;
+
+ case qw_svc_soundlist:
+ QW_CL_ParseSoundList();
+ break;
+
+ case qw_svc_packetentities:
+ EntityFrameQW_CL_ReadFrame(false);
+ // first update is the final signon stage
+ if (cls.signon == SIGNONS - 1)
+ cls.signon = SIGNONS;
+ break;
+
+ case qw_svc_deltapacketentities:
+ EntityFrameQW_CL_ReadFrame(true);
+ // first update is the final signon stage
+ if (cls.signon == SIGNONS - 1)
+ cls.signon = SIGNONS;
+ break;
+
+ case qw_svc_maxspeed:
+ cl.qw_movevars_maxspeed = MSG_ReadFloat();
+ break;
+
+ case qw_svc_entgravity:
+ cl.qw_movevars_entgravity = MSG_ReadFloat();
+ break;
+
+ case qw_svc_setpause:
+ cl.paused = MSG_ReadByte ();
+ if (cl.paused)
+ CDAudio_Pause ();
+ else
+ CDAudio_Resume ();
+ S_PauseGameSounds (cl.paused);
+ break;
+ }
+ }
+
+ // fully kill the still slightly dead qw player entities each frame
+ for (i = 1;i < cl.maxclients;i++)
+ if (!cl.entities_active[i])
+ cl.entities[i].state_current.active = false;
+ }
+ else
+ {
+ while (1)
+ {
+ if (msg_badread)
+ Host_Error ("CL_ParseServerMessage: Bad server message");
+
+ cmd = MSG_ReadByte ();
+
+ if (cmd == -1)
+ {
+ SHOWNET("END OF MESSAGE");
+ break; // end of message
+ }
+
+ cmdindex = cmdcount & 31;
+ cmdcount++;
+ cmdlog[cmdindex] = cmd;
+
+ // if the high bit of the command byte is set, it is a fast update
+ if (cmd & 128)
+ {
+ // 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)
+ temp = "entity";
+ cmdlogname[cmdindex] = temp;
+ SHOWNET("fast update");
+ if (cls.signon == SIGNONS - 1)
+ {
+ // first update is the final signon stage
+ cls.signon = SIGNONS;
+ CL_SignonReply ();
+ }
+ EntityFrameQuake_ReadEntity (cmd&127);
+ continue;
+ }
+
+ SHOWNET(svc_strings[cmd]);
+ cmdlogname[cmdindex] = svc_strings[cmd];
+ if (!cmdlogname[cmdindex])
+ {
+ // 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)
+ temp = "<unknown>";
+ cmdlogname[cmdindex] = temp;
+ }
+
+ // other commands
+ switch (cmd)
+ {
+ default:
+ {
+ char description[32*64], temp[64];
+ int count;
+ strlcpy (description, "packet dump: ", sizeof(description));
+ i = cmdcount - 32;
+ if (i < 0)
+ i = 0;
+ count = cmdcount - i;
+ i &= 31;
+ while(count > 0)
+ {
+ dpsnprintf (temp, sizeof (temp), "%3i:%s ", cmdlog[i], cmdlogname[i]);
+ strlcat (description, temp, sizeof (description));
+ count--;
+ i++;
+ i &= 31;
+ }
+ description[strlen(description)-1] = '\n'; // replace the last space with a newline
+ Con_Print(description);
+ Host_Error ("CL_ParseServerMessage: Illegible server message");
+ }
+ break;
+
+ case svc_nop:
+ if (cls.signon < SIGNONS)
+ Con_Print("<-- server to client keepalive\n");
+ break;
+
+ case svc_time:
+ cl.mtime[1] = cl.mtime[0];
+ cl.mtime[0] = MSG_ReadFloat ();
+ cl.movement_needupdate = true;
+ // if true the cl.viewangles are interpolated from cl.mviewangles[]
+ // during this frame
+ // (makes spectating players much smoother and prevents mouse movement from turning)
+ cl.fixangle[1] = cl.fixangle[0];
+ cl.fixangle[0] = false;
+ if (!cls.demoplayback)
+ VectorCopy(cl.mviewangles[0], cl.mviewangles[1]);
+ break;
+
+ case svc_clientdata:
+ CL_ParseClientdata();
+ break;
+
+ case svc_version:
+ i = MSG_ReadLong ();
+ protocol = Protocol_EnumForNumber(i);
+ if (protocol == PROTOCOL_UNKNOWN)
+ Host_Error("CL_ParseServerMessage: Server is unrecognized protocol number (%i)", i);
+ // hack for unmarked Nehahra movie demos which had a custom protocol
+ if (protocol == PROTOCOL_QUAKEDP && cls.demoplayback && demo_nehahra.integer)
+ protocol = PROTOCOL_NEHAHRAMOVIE;
+ cls.protocol = protocol;
+ break;
+
+ case svc_disconnect:
+ Con_Printf ("Server disconnected\n");
+ if (cls.demonum != -1)
+ CL_NextDemo ();
+ else
+ CL_Disconnect ();
+ break;
+
+ case svc_print:
+ temp = MSG_ReadString();
+ if (CL_ExaminePrintString(temp)) // look for anything interesting like player IP addresses or ping reports
+ CSQC_AddPrintText(temp); //[515]: csqc
+ break;
+
+ case svc_centerprint:
+ CL_VM_Parse_CenterPrint(MSG_ReadString ()); //[515]: csqc
+ break;
+
+ case svc_stufftext:
+ CL_VM_Parse_StuffCmd(MSG_ReadString ()); //[515]: csqc
+ break;
+
+ case svc_damage:
+ V_ParseDamage ();
+ break;
+
+ case svc_serverinfo:
+ CL_ParseServerInfo ();
+ CL_VM_Init(); //[515]: init csqc
+ break;
+
+ case svc_setangle:
+ for (i=0 ; i<3 ; i++)
+ cl.viewangles[i] = MSG_ReadAngle (cls.protocol);
+ if (!cls.demoplayback)
+ {
+ cl.fixangle[0] = true;
+ VectorCopy(cl.viewangles, cl.mviewangles[0]);
+ // disable interpolation if this is new
+ if (!cl.fixangle[1])
+ VectorCopy(cl.viewangles, cl.mviewangles[1]);
+ }
+ break;
+
+ case svc_setview:
+ cl.viewentity = (unsigned short)MSG_ReadShort ();
+ if (cl.viewentity >= MAX_EDICTS)
+ Host_Error("svc_setview >= MAX_EDICTS");
+ if (cl.viewentity >= cl.max_entities)
+ CL_ExpandEntities(cl.viewentity);
+ // LordHavoc: assume first setview recieved is the real player entity
+ if (!cl.playerentity)
+ cl.playerentity = cl.viewentity;
+ break;
+
+ case svc_lightstyle:
+ i = MSG_ReadByte ();
+ if (i >= cl.max_lightstyle)
+ {
+ Con_Printf ("svc_lightstyle >= MAX_LIGHTSTYLES");
+ break;
+ }
+ strlcpy (cl.lightstyle[i].map, MSG_ReadString(), sizeof (cl.lightstyle[i].map));
+ cl.lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
+ cl.lightstyle[i].length = (int)strlen(cl.lightstyle[i].map);
+ break;
+
+ case svc_sound:
+ CL_ParseStartSoundPacket(false);
+ break;
+
+ case svc_precache:
+ if (cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3)
+ {
+ // was svc_sound2 in protocols 1, 2, 3, removed in 4, 5, changed to svc_precache in 6
+ CL_ParseStartSoundPacket(true);
+ }
+ else
+ {
+ int i = (unsigned short)MSG_ReadShort();
+ char *s = MSG_ReadString();
+ if (i < 32768)
+ {
+ if (i >= 1 && i < MAX_MODELS)
+ {
+ model_t *model = Mod_ForName(s, false, false, i == 1);
+ if (!model)
+ Con_Printf("svc_precache: Mod_ForName(\"%s\") failed\n", s);
+ cl.model_precache[i] = model;
+ }
+ else
+ Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_MODELS);
+ }
+ else
+ {
+ i -= 32768;
+ if (i >= 1 && i < MAX_SOUNDS)
+ {
+ sfx_t *sfx = S_PrecacheSound (s, true, false);
+ if (!sfx && snd_initialized.integer)
+ Con_Printf("svc_precache: S_PrecacheSound(\"%s\") failed\n", s);
+ cl.sound_precache[i] = sfx;
+ }
+ else
+ Con_Printf("svc_precache: index %i outside range %i...%i\n", i, 1, MAX_SOUNDS);
+ }
+ }
+ break;
+
+ case svc_stopsound:
+ i = (unsigned short) MSG_ReadShort();
+ S_StopSound(i>>3, i&7);
+ break;
+
+ case svc_updatename:
+ i = MSG_ReadByte ();
+ if (i >= cl.maxclients)
+ Host_Error ("CL_ParseServerMessage: svc_updatename >= cl.maxclients");
+ strlcpy (cl.scores[i].name, MSG_ReadString (), sizeof (cl.scores[i].name));
+ break;
+
+ case svc_updatefrags:
+ i = MSG_ReadByte ();
+ if (i >= cl.maxclients)
+ Host_Error ("CL_ParseServerMessage: svc_updatefrags >= cl.maxclients");
+ cl.scores[i].frags = (signed short) MSG_ReadShort ();
+ break;
+
+ case svc_updatecolors:
+ i = MSG_ReadByte ();
+ if (i >= cl.maxclients)
+ Host_Error ("CL_ParseServerMessage: svc_updatecolors >= cl.maxclients");
+ cl.scores[i].colors = MSG_ReadByte ();
+ break;
+
+ case svc_particle:
+ CL_ParseParticleEffect ();
+ break;
+
+ case svc_effect:
+ CL_ParseEffect ();
+ break;
+
+ case svc_effect2:
+ CL_ParseEffect2 ();
+ break;
+
+ case svc_spawnbaseline:
+ i = (unsigned short) MSG_ReadShort ();
+ if (i < 0 || i >= MAX_EDICTS)
+ Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
+ if (i >= cl.max_entities)
+ CL_ExpandEntities(i);
+ CL_ParseBaseline (cl.entities + i, false);
+ break;
+ case svc_spawnbaseline2:
+ i = (unsigned short) MSG_ReadShort ();
+ if (i < 0 || i >= MAX_EDICTS)
+ Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
+ if (i >= cl.max_entities)
+ CL_ExpandEntities(i);
+ CL_ParseBaseline (cl.entities + i, true);
+ break;
+ case svc_spawnstatic:
+ CL_ParseStatic (false);
+ break;
+ case svc_spawnstatic2:
+ CL_ParseStatic (true);
+ break;
+ case svc_temp_entity:
+ if(!CL_VM_Parse_TempEntity())
+ CL_ParseTempEntity ();
+ break;
+
+ case svc_setpause:
+ cl.paused = MSG_ReadByte ();
+ if (cl.paused)
+ CDAudio_Pause ();
+ else
+ CDAudio_Resume ();
+ S_PauseGameSounds (cl.paused);
+ break;
+
+ case svc_signonnum:
+ i = MSG_ReadByte ();
+ // LordHavoc: it's rude to kick off the client if they missed the
+ // reconnect somehow, so allow signon 1 even if at signon 1
+ if (i <= cls.signon && i != 1)
+ Host_Error ("Received signon %i when at %i", i, cls.signon);
+ cls.signon = i;
+ CL_SignonReply ();
+ break;
+
+ case svc_killedmonster:
+ cl.stats[STAT_MONSTERS]++;
+ break;
+
+ case svc_foundsecret:
+ cl.stats[STAT_SECRETS]++;
+ break;
+
+ case svc_updatestat:
+ i = MSG_ReadByte ();
+ if (i < 0 || i >= MAX_CL_STATS)
+ Host_Error ("svc_updatestat: %i is invalid", i);
+ cl.stats[i] = MSG_ReadLong ();
+ break;
+
+ case svc_updatestatubyte:
+ i = MSG_ReadByte ();
+ if (i < 0 || i >= MAX_CL_STATS)
+ Host_Error ("svc_updatestat: %i is invalid", i);
+ cl.stats[i] = MSG_ReadByte ();
+ break;
+
+ case svc_spawnstaticsound:
+ CL_ParseStaticSound (false);
+ break;
+
+ case svc_spawnstaticsound2:
+ CL_ParseStaticSound (true);
+ break;
+
+ case svc_cdtrack:
+ cl.cdtrack = MSG_ReadByte ();
+ cl.looptrack = MSG_ReadByte ();
+ if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
+ CDAudio_Play ((unsigned char)cls.forcetrack, true);
+ else
+ CDAudio_Play ((unsigned char)cl.cdtrack, true);
+ break;
+
+ case svc_intermission:
+ cl.intermission = 1;
+ cl.completed_time = cl.time;
+ break;
+
+ case svc_finale:
+ cl.intermission = 2;
+ cl.completed_time = cl.time;
+ SCR_CenterPrint(MSG_ReadString ());
+ break;
+
+ case svc_cutscene:
+ cl.intermission = 3;
+ cl.completed_time = cl.time;
+ SCR_CenterPrint(MSG_ReadString ());
+ break;
+
+ case svc_sellscreen:
+ Cmd_ExecuteString ("help", src_command);
+ break;
+ case svc_hidelmp:
+ if (gamemode == GAME_TENEBRAE)
+ {
+ // repeating particle effect
+ MSG_ReadCoord(cls.protocol);
+ MSG_ReadCoord(cls.protocol);
+ MSG_ReadCoord(cls.protocol);
+ MSG_ReadCoord(cls.protocol);
+ MSG_ReadCoord(cls.protocol);
+ MSG_ReadCoord(cls.protocol);
+ MSG_ReadByte();
+ MSG_ReadLong();
+ MSG_ReadLong();
+ MSG_ReadString();
+ }
+ else
+ SHOWLMP_decodehide();
+ break;
+ case svc_showlmp:
+ if (gamemode == GAME_TENEBRAE)
+ {
+ // particle effect
+ MSG_ReadCoord(cls.protocol);
+ MSG_ReadCoord(cls.protocol);
+ MSG_ReadCoord(cls.protocol);
+ MSG_ReadByte();
+ MSG_ReadString();
+ }
+ else
+ SHOWLMP_decodeshow();
+ break;
+ case svc_skybox:
+ R_SetSkyBox(MSG_ReadString());
+ break;
+ case svc_entities:
+ if (cls.signon == SIGNONS - 1)
+ {
+ // first update is the final signon stage
+ cls.signon = SIGNONS;
+ CL_SignonReply ();
+ }
+ if (cls.protocol == PROTOCOL_DARKPLACES1 || cls.protocol == PROTOCOL_DARKPLACES2 || cls.protocol == PROTOCOL_DARKPLACES3)
+ EntityFrame_CL_ReadFrame();
+ else if (cls.protocol == PROTOCOL_DARKPLACES4)
+ EntityFrame4_CL_ReadFrame();
+ else
+ EntityFrame5_CL_ReadFrame();
+ break;
+ case svc_csqcentities:
+ CSQC_ReadEntities();
+ break;
+ }
+ }
+ }
+
+ CL_UpdateItemsAndWeapon();
+
+ EntityFrameQuake_ISeeDeadEntities();
+
+ parsingerror = false;
+}
+
+void CL_Parse_DumpPacket(void)
+{
+ if (!parsingerror)
+ return;
+ Con_Print("Packet dump:\n");
+ SZ_HexDumpToConsole(&net_message);
+ parsingerror = false;
+}
+
+void CL_Parse_ErrorCleanUp(void)
+{
+ if (cls.qw_downloadmemory)
+ {
+ Mem_Free(cls.qw_downloadmemory);
+ cls.qw_downloadmemory = NULL;
+ }
+ cls.qw_downloadpercent = 0;
+ QW_CL_StopUpload();
+}
+
+void CL_Parse_Init(void)
+{
+ // LordHavoc: added demo_nehahra cvar
+ Cvar_RegisterVariable (&demo_nehahra);
+ if (gamemode == GAME_NEHAHRA)
+ Cvar_SetValue("demo_nehahra", 1);
+ Cvar_RegisterVariable(&developer_networkentities);
+
+ Cvar_RegisterVariable(&cl_sound_wizardhit);
+ Cvar_RegisterVariable(&cl_sound_hknighthit);
+ Cvar_RegisterVariable(&cl_sound_tink1);
+ Cvar_RegisterVariable(&cl_sound_ric1);
+ Cvar_RegisterVariable(&cl_sound_ric2);
+ Cvar_RegisterVariable(&cl_sound_ric3);
+ Cvar_RegisterVariable(&cl_sound_r_exp3);
+
+ Cmd_AddCommand("nextul", QW_CL_NextUpload, "sends next fragment of current upload buffer (screenshot for example)");
+ Cmd_AddCommand("stopul", QW_CL_StopUpload, "aborts current upload (screenshot for example)");
+ Cmd_AddCommand("skins", QW_CL_Skins_f, "downloads missing qw skins from server");
+ Cmd_AddCommand("changing", QW_CL_Changing_f, "sent by qw servers to tell client to wait for level change");
+}
+
+void CL_Parse_Shutdown(void)
+{