6 #include "../common/constants.qh"
7 #include "../common/movetypes/movetypes.qh"
8 #include "../common/util.qh"
20 string species_prefix(int specnum)
24 case SPECIES_HUMAN: return "";
25 case SPECIES_ALIEN: return "alien_";
26 case SPECIES_ROBOT_SHINY: return "robot_";
27 case SPECIES_ROBOT_RUSTY: return "robot_"; // use the same effects, only different gibs
28 case SPECIES_ROBOT_SOLID: return "robot_"; // use the same effects, only different gibs
29 case SPECIES_ANIMAL: return "animal_";
30 case SPECIES_RESERVED: return "reserved_";
35 void Gib_setmodel(entity gib, string mdlname, int specnum)
39 case SPECIES_ROBOT_RUSTY:
40 case SPECIES_ROBOT_SHINY:
41 case SPECIES_ROBOT_SOLID:
42 if(specnum != SPECIES_ROBOT_SOLID || mdlname == "models/gibs/chunk.mdl")
44 if(mdlname == "models/gibs/bloodyskull.md3")
45 setmodel(gib, MDL_GIB_ROBO);
47 setmodel(gib, MDL_GIB_ROBO_RANDOM());
48 if(specnum == SPECIES_ROBOT_SHINY)
51 gib.colormod = '2 2 2';
57 _setmodel(gib, mdlname);
63 void new_te_bloodshower (int ef, vector org, float explosionspeed, int howmany)
66 pmod = autocvar_cl_particles_quality;
67 for (i = 0; i < 50 * pmod; ++i)
68 pointparticles(ef, org, randomvec() * explosionspeed, howmany / 50);
71 void SUB_RemoveOnNoImpact()
73 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
79 // TODO maybe bounce of walls, make more gibs, etc.
81 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
88 sound(self, CH_PAIN, strcat("misc/gib_splat0", ftos(floor(prandom() * 4 + 1)), ".wav"), VOL_BASE, ATTEN_NORM);
89 pointparticles(_particleeffectnum(strcat(species_prefix(self.cnt), "blood")), self.origin + '0 0 1', '0 0 30', 10);
99 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
103 if(self.touch == Gib_Touch) // don't do this for the "chunk" thingie...
104 // TODO somehow make it spray in a direction dependent on self.angles
105 trailparticles(self, _particleeffectnum(strcat(species_prefix(self.cnt), EFFECT_TR_SLIGHTBLOOD.eent_eff_name)), oldorg, self.origin);
107 trailparticles(self, _particleeffectnum(strcat(species_prefix(self.cnt), EFFECT_TR_BLOOD.eent_eff_name)), oldorg, self.origin);
109 self.renderflags = 0;
111 // make gibs die faster at low view quality
112 // if view_quality is 0.5, we want to have them die twice as fast
113 self.nextthink -= frametime * (1 / bound(0.01, view_quality, 1.00) - 1);
115 self.alpha = bound(0, self.nextthink - time, 1);
117 if(self.alpha < ALPHA_MIN_VISIBLE)
124 void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector vrand, int specnum, bool destroyontouch, bool issilent)
128 // TODO remove some gibs according to cl_nogibs
129 gib = RubbleNew("gib");
130 gib.classname = "gib";
131 gib.move_movetype = MOVETYPE_BOUNCE;
133 gib.solid = SOLID_CORPSE;
135 gib.silent = issilent;
136 Gib_setmodel(gib, mdlname, specnum);
138 setsize (gib, '-8 -8 -8', '8 8 8');
142 gib.move_touch = Gib_Touch;
144 gib.move_touch = SUB_RemoveOnNoImpact;
146 // don't spawn gibs inside solid - just don't
149 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
153 gib.move_origin = org;
155 gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
156 gib.move_avelocity = prandomvec() * vlen(gib.move_velocity) * autocvar_cl_gibs_avelocity_scale;
157 gib.move_time = time;
158 gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
160 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
161 gib.drawmask = MASK_NORMAL;
163 RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
166 void Ent_GibSplash(bool isNew)
168 int amount, type, specnum;
172 string gentle_prefix = "morphed_";
177 type = ReadByte(); // gibbage type
178 amount = ReadByte() / 16.0; // gibbage amount
179 org.x = ReadShort() * 4 + 2;
180 org.y = ReadShort() * 4 + 2;
181 org.z = ReadShort() * 4 + 2;
182 vel = decompressShortVector(ReadShort());
184 float cl_gentle_gibs = autocvar_cl_gentle_gibs;
185 if(cl_gentle_gibs || autocvar_cl_gentle)
186 type |= 0x80; // set gentle bit
190 if(cl_gentle_gibs == 2)
192 else if(cl_gentle_gibs == 3)
193 gentle_prefix = "happy_";
195 else if(autocvar_cl_particlegibs)
198 gentle_prefix = "particlegibs_";
201 if (!(cl_gentle_gibs || autocvar_cl_gentle))
202 amount *= 1 - autocvar_cl_nogibs;
207 if(amount <= 0 || !isNew)
210 setorigin(self, org); // for the sounds
212 specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
213 issilent = (type & 0x40);
214 type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
215 specstr = species_prefix(specnum);
221 sound (self, CH_PAIN, "misc/gib.wav", VOL_BASE, ATTEN_NORM);
223 if(prandom() < amount)
224 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
225 new_te_bloodshower(_particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
226 if(prandom() < amount)
227 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
229 for(c = 0; c < amount; ++c)
231 randomvalue = amount - c;
233 if(prandom() < randomvalue)
234 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
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/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
239 if(prandom() < randomvalue)
240 TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
241 if(prandom() < randomvalue)
242 TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
243 if(prandom() < randomvalue)
244 TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
246 // these splat on impact
247 if(prandom() < randomvalue)
248 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
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);
258 pointparticles(_particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
261 if(prandom() < amount)
262 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
265 pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
268 pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
271 // no gibs in gentle mode, sorry
276 void GibSplash_Precache()
278 precache_sound ("misc/gib.wav");
279 precache_sound ("misc/gib_splat01.wav");
280 precache_sound ("misc/gib_splat02.wav");
281 precache_sound ("misc/gib_splat03.wav");
282 precache_sound ("misc/gib_splat04.wav");