4 REGISTER_NET_TEMP(net_gibsplash)
10 bool Violence_GibSplash_SendEntity(entity this, entity to, int sf)
12 int channel = MSG_ONE;
14 WriteHeader(channel, net_gibsplash);
15 WriteByte(channel, this.state); // actually type
16 WriteByte(channel, bound(1, this.cnt * 16, 255)); // gibbage amount multiplier
17 WriteShort(channel, floor(this.origin.x / 4)); // not using a coord here, as gibs don't need this accuracy
18 WriteShort(channel, floor(this.origin.y / 4)); // not using a coord here, as gibs don't need this accuracy
19 WriteShort(channel, floor(this.origin.z / 4)); // not using a coord here, as gibs don't need this accuracy
20 WriteShort(channel, this.oldorigin.x); // acrually compressed velocity
24 void Violence_GibSplash_At(vector org, vector dir, float type, float amount, entity gibowner, entity attacker)
26 if(g_cts) // no gibs in CTS
29 entity e = new(gibsplash);
31 e.state = type; // should stay smaller than 15
32 if(!sound_allowed(MSG_BROADCAST, gibowner) || !sound_allowed(MSG_BROADCAST, attacker))
33 e.state |= 0x40; // "silence" bit
34 e.state |= 8 * gibowner.species; // gib type, ranges from 0 to 15
36 // if this is a copied dead body, send the num of its player instead
37 // TODO: remove this field, read from model txt files
38 if(gibowner.classname == "body")
39 e.team = etof(gibowner.enemy);
41 e.team = etof(gibowner);
46 e.oldorigin_x = compressShortVector(e.velocity);
48 FOREACH_CLIENT(IS_REAL_CLIENT(it), Violence_GibSplash_SendEntity(e, it, 0));
52 void Violence_GibSplash(entity source, float type, float amount, entity attacker)
54 Violence_GibSplash_At(source.origin + source.view_ofs, source.velocity, type, amount, source, attacker);
64 #include <common/physics/movetypes/movetypes.qh>
71 void Gib_Delete(entity this)
76 string species_prefix(int specnum);
78 void Gib_setmodel(entity gib, string mdlname, int specnum)
82 case SPECIES_ROBOT_RUSTY:
83 case SPECIES_ROBOT_SHINY:
84 case SPECIES_ROBOT_SOLID:
85 if(specnum != SPECIES_ROBOT_SOLID || mdlname == "models/gibs/chunk.mdl")
87 if(mdlname == "models/gibs/bloodyskull.md3")
88 setmodel(gib, MDL_GIB_ROBO);
90 setmodel(gib, MDL_GIB_ROBO_RANDOM());
91 if(specnum == SPECIES_ROBOT_SHINY)
94 gib.colormod = '2 2 2';
100 _setmodel(gib, mdlname);
106 void new_te_bloodshower (int ef, vector org, float explosionspeed, int howmany)
109 pmod = autocvar_cl_particles_quality;
110 for (i = 0; i < 50 * pmod; ++i)
111 __pointparticles(ef, org, randomvec() * explosionspeed, howmany / 50);
114 void SUB_RemoveOnNoImpact()
117 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
123 // TODO maybe bounce of walls, make more gibs, etc.
125 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
132 sound(self, CH_PAIN, SND_GIB_SPLAT_RANDOM(), VOL_BASE, ATTEN_NORM);
133 __pointparticles(_particleeffectnum(strcat(species_prefix(self.cnt), "blood")), self.origin + '0 0 1', '0 0 30', 10);
138 void Gib_Draw(entity this)
141 oldorg = this.origin;
143 Movetype_Physics_MatchTicrate(this, autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
147 if(gettouch(this) == Gib_Touch) // don't do this for the "chunk" thingie...
148 // TODO somehow make it spray in a direction dependent on this.angles
149 __trailparticles(this, _particleeffectnum(strcat(species_prefix(this.cnt), EFFECT_TR_SLIGHTBLOOD.eent_eff_name)), oldorg, this.origin);
151 __trailparticles(this, _particleeffectnum(strcat(species_prefix(this.cnt), EFFECT_TR_BLOOD.eent_eff_name)), oldorg, this.origin);
153 this.renderflags = 0;
155 // make gibs die faster at low view quality
156 // if view_quality is 0.5, we want to have them die twice as fast
157 this.nextthink -= frametime * (1 / bound(0.01, view_quality, 1.00) - 1);
159 this.alpha = bound(0, this.nextthink - time, 1);
161 if(this.alpha < ALPHA_MIN_VISIBLE)
168 void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector vrand, int specnum, bool destroyontouch, bool issilent)
172 // TODO remove some gibs according to cl_nogibs
173 gib = RubbleNew("gib");
174 gib.move_movetype = MOVETYPE_BOUNCE;
176 gib.solid = SOLID_CORPSE;
178 gib.silent = issilent;
179 Gib_setmodel(gib, mdlname, specnum);
181 setsize (gib, '-8 -8 -8', '8 8 8');
185 settouch(gib, Gib_Touch);
187 settouch(gib, SUB_RemoveOnNoImpact);
189 // don't spawn gibs inside solid - just don't
192 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
196 gib.move_origin = org;
198 gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
199 gib.move_avelocity = prandomvec() * vlen(gib.move_velocity) * autocvar_cl_gibs_avelocity_scale;
200 gib.move_time = time;
201 gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
203 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
204 gib.drawmask = MASK_NORMAL;
206 RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
209 NET_HANDLE(net_gibsplash, bool isNew)
211 Net_Accept(net_gibsplash);
213 string gentle_prefix = "morphed_";
215 int type = ReadByte(); // gibbage type
216 int amount = ReadByte() / 16.0; // gibbage amount
218 org.x = ReadShort() * 4 + 2;
219 org.y = ReadShort() * 4 + 2;
220 org.z = ReadShort() * 4 + 2;
221 vector vel = decompressShortVector(ReadShort());
225 float cl_gentle_gibs = autocvar_cl_gentle_gibs;
226 if(cl_gentle_gibs || autocvar_cl_gentle)
227 type |= 0x80; // set gentle bit
231 if(cl_gentle_gibs == 2)
233 else if(cl_gentle_gibs == 3)
234 gentle_prefix = "happy_";
236 else if(autocvar_cl_particlegibs)
239 gentle_prefix = "particlegibs_";
242 if (!(cl_gentle_gibs || autocvar_cl_gentle))
243 amount *= 1 - autocvar_cl_nogibs;
248 if(amount <= 0 || !isNew)
251 setorigin(this, org); // for the sounds
253 int specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
254 bool issilent = (type & 0x40);
255 type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
256 string specstr = species_prefix(specnum);
262 sound (this, CH_PAIN, SND_GIB, VOL_BASE, ATTEN_NORM);
264 if(prandom() < amount)
265 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
266 new_te_bloodshower(_particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
267 if(prandom() < amount)
268 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
270 for(int c = 0; c < amount; ++c)
272 int randomvalue = amount - c;
274 if(prandom() < randomvalue)
275 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
276 if(prandom() < randomvalue)
277 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
278 if(prandom() < randomvalue)
279 TossGib ("models/gibs/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
280 if(prandom() < randomvalue)
281 TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
282 if(prandom() < randomvalue)
283 TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
284 if(prandom() < randomvalue)
285 TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
287 // these splat on impact
288 if(prandom() < randomvalue)
289 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
290 if(prandom() < randomvalue)
291 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
292 if(prandom() < randomvalue)
293 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
294 if(prandom() < randomvalue)
295 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
299 __pointparticles(_particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
302 if(prandom() < amount)
303 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
306 __pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
309 __pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
312 // no gibs in gentle mode, sorry