3 #include "autocvars.qh"
6 #include "movetypes.qh"
9 #include "../common/constants.qh"
10 #include "../common/util.qh"
22 string species_prefix(int specnum)
26 case SPECIES_HUMAN: return "";
27 case SPECIES_ALIEN: return "alien_";
28 case SPECIES_ROBOT_SHINY: return "robot_";
29 case SPECIES_ROBOT_RUSTY: return "robot_"; // use the same effects, only different gibs
30 case SPECIES_ROBOT_SOLID: return "robot_"; // use the same effects, only different gibs
31 case SPECIES_ANIMAL: return "animal_";
32 case SPECIES_RESERVED: return "reserved_";
37 void Gib_setmodel(entity gib, string mdlname, int specnum)
41 case SPECIES_ROBOT_RUSTY:
42 case SPECIES_ROBOT_SHINY:
43 case SPECIES_ROBOT_SOLID:
44 if(specnum != SPECIES_ROBOT_SOLID || mdlname == "models/gibs/chunk.mdl")
46 if(mdlname == "models/gibs/bloodyskull.md3")
47 setmodel(gib, "models/gibs/robo.md3");
49 setmodel(gib, strcat("models/gibs/robo", ftos(floor(random() * 8) + 1), ".md3"));
50 if(specnum == SPECIES_ROBOT_SHINY)
53 gib.colormod = '2 2 2';
59 setmodel(gib, mdlname);
65 void new_te_bloodshower (int ef, vector org, float explosionspeed, int howmany)
68 pmod = autocvar_cl_particles_quality;
69 for (i = 0; i < 50 * pmod; ++i)
70 pointparticles(ef, org, randomvec() * explosionspeed, howmany / 50);
73 void SUB_RemoveOnNoImpact()
75 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
81 // TODO maybe bounce of walls, make more gibs, etc.
83 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
90 sound(self, CH_PAIN, strcat("misc/gib_splat0", ftos(floor(prandom() * 4 + 1)), ".wav"), VOL_BASE, ATTEN_NORM);
91 pointparticles(particleeffectnum(strcat(species_prefix(self.cnt), "blood")), self.origin + '0 0 1', '0 0 30', 10);
101 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
105 if(self.touch == Gib_Touch) // don't do this for the "chunk" thingie...
106 // TODO somehow make it spray in a direction dependent on self.angles
107 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_SLIGHTBLOOD")), oldorg, self.origin);
109 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_BLOOD")), oldorg, self.origin);
111 self.renderflags = 0;
113 // make gibs die faster at low view quality
114 // if view_quality is 0.5, we want to have them die twice as fast
115 self.nextthink -= frametime * (1 / bound(0.01, view_quality, 1.00) - 1);
117 self.alpha = bound(0, self.nextthink - time, 1);
119 if(self.alpha < ALPHA_MIN_VISIBLE)
126 void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector vrand, int specnum, bool destroyontouch, bool issilent)
130 // TODO remove some gibs according to cl_nogibs
131 gib = RubbleNew("gib");
132 gib.classname = "gib";
133 gib.move_movetype = MOVETYPE_BOUNCE;
135 gib.solid = SOLID_CORPSE;
137 gib.silent = issilent;
138 Gib_setmodel(gib, mdlname, specnum);
140 setsize (gib, '-8 -8 -8', '8 8 8');
144 gib.move_touch = Gib_Touch;
146 gib.move_touch = SUB_RemoveOnNoImpact;
148 // don't spawn gibs inside solid - just don't
151 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
155 gib.move_origin = org;
157 gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
158 gib.move_avelocity = prandomvec() * vlen(gib.move_velocity) * autocvar_cl_gibs_avelocity_scale;
159 gib.move_time = time;
160 gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
162 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
163 gib.drawmask = MASK_NORMAL;
165 RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
168 void Ent_GibSplash(bool isNew)
170 int amount, type, specnum;
174 string gentle_prefix = "morphed_";
179 type = ReadByte(); // gibbage type
180 amount = ReadByte() / 16.0; // gibbage amount
181 org.x = ReadShort() * 4 + 2;
182 org.y = ReadShort() * 4 + 2;
183 org.z = ReadShort() * 4 + 2;
184 vel = decompressShortVector(ReadShort());
186 float cl_gentle_gibs = autocvar_cl_gentle_gibs;
187 if(cl_gentle_gibs || autocvar_cl_gentle)
188 type |= 0x80; // set gentle bit
192 if(cl_gentle_gibs == 2)
194 else if(cl_gentle_gibs == 3)
195 gentle_prefix = "happy_";
197 else if(autocvar_cl_particlegibs)
200 gentle_prefix = "particlegibs_";
203 if (!(cl_gentle_gibs || autocvar_cl_gentle))
204 amount *= 1 - autocvar_cl_nogibs;
209 if(amount <= 0 || !isNew)
212 setorigin(self, org); // for the sounds
214 specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
215 issilent = (type & 0x40);
216 type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
217 specstr = species_prefix(specnum);
223 sound (self, CH_PAIN, "misc/gib.wav", VOL_BASE, ATTEN_NORM);
225 if(prandom() < amount)
226 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
227 new_te_bloodshower(particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
228 if(prandom() < amount)
229 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
231 for(c = 0; c < amount; ++c)
233 randomvalue = amount - c;
235 if(prandom() < randomvalue)
236 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
237 if(prandom() < randomvalue)
238 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
239 if(prandom() < randomvalue)
240 TossGib ("models/gibs/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
241 if(prandom() < randomvalue)
242 TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
243 if(prandom() < randomvalue)
244 TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
245 if(prandom() < randomvalue)
246 TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
248 // these splat on impact
249 if(prandom() < randomvalue)
250 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
251 if(prandom() < randomvalue)
252 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
253 if(prandom() < randomvalue)
254 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
255 if(prandom() < randomvalue)
256 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
260 pointparticles(particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
263 if(prandom() < amount)
264 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
267 pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
270 pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
273 // no gibs in gentle mode, sorry
278 void GibSplash_Precache()
280 precache_model("models/gibs/chunk.mdl");
281 precache_model("models/gibs/leg1.md3");
282 precache_model("models/gibs/leg2.md3");
283 precache_model("models/gibs/chest.md3");
284 precache_model("models/gibs/smallchest.md3");
285 precache_model("models/gibs/arm.md3");
286 precache_model("models/gibs/bloodyskull.md3");
287 precache_model("models/gibs/eye.md3");
289 precache_model("models/gibs/robo.md3");
290 precache_model("models/gibs/robo1.md3");
291 precache_model("models/gibs/robo2.md3");
292 precache_model("models/gibs/robo3.md3");
293 precache_model("models/gibs/robo4.md3");
294 precache_model("models/gibs/robo5.md3");
295 precache_model("models/gibs/robo6.md3");
296 precache_model("models/gibs/robo7.md3");
297 precache_model("models/gibs/robo8.md3");
299 precache_sound ("misc/gib.wav");
300 precache_sound ("misc/gib_splat01.wav");
301 precache_sound ("misc/gib_splat02.wav");
302 precache_sound ("misc/gib_splat03.wav");
303 precache_sound ("misc/gib_splat04.wav");