4 #include "movetypes.qh"
8 #include "../common/constants.qh"
9 #include "../common/util.qh"
21 string species_prefix(int specnum)
25 case SPECIES_HUMAN: return "";
26 case SPECIES_ALIEN: return "alien_";
27 case SPECIES_ROBOT_SHINY: return "robot_";
28 case SPECIES_ROBOT_RUSTY: return "robot_"; // use the same effects, only different gibs
29 case SPECIES_ROBOT_SOLID: return "robot_"; // use the same effects, only different gibs
30 case SPECIES_ANIMAL: return "animal_";
31 case SPECIES_RESERVED: return "reserved_";
36 void Gib_setmodel(entity gib, string mdlname, int specnum)
40 case SPECIES_ROBOT_RUSTY:
41 case SPECIES_ROBOT_SHINY:
42 case SPECIES_ROBOT_SOLID:
43 if(specnum != SPECIES_ROBOT_SOLID || mdlname == "models/gibs/chunk.mdl")
45 if(mdlname == "models/gibs/bloodyskull.md3")
46 setmodel(gib, "models/gibs/robo.md3");
48 setmodel(gib, strcat("models/gibs/robo", ftos(floor(random() * 8) + 1), ".md3"));
49 if(specnum == SPECIES_ROBOT_SHINY)
52 gib.colormod = '2 2 2';
58 setmodel(gib, mdlname);
64 void new_te_bloodshower (int ef, vector org, float explosionspeed, int howmany)
67 pmod = autocvar_cl_particles_quality;
68 for (i = 0; i < 50 * pmod; ++i)
69 pointparticles(ef, org, randomvec() * explosionspeed, howmany / 50);
72 void SUB_RemoveOnNoImpact()
74 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
80 // TODO maybe bounce of walls, make more gibs, etc.
82 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
89 sound(self, CH_PAIN, strcat("misc/gib_splat0", ftos(floor(prandom() * 4 + 1)), ".wav"), VOL_BASE, ATTEN_NORM);
90 pointparticles(particleeffectnum(strcat(species_prefix(self.cnt), "blood")), self.origin + '0 0 1', '0 0 30', 10);
100 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
104 if(self.touch == Gib_Touch) // don't do this for the "chunk" thingie...
105 // TODO somehow make it spray in a direction dependent on self.angles
106 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_SLIGHTBLOOD")), oldorg, self.origin);
108 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_BLOOD")), oldorg, self.origin);
110 self.renderflags = 0;
112 // make gibs die faster at low view quality
113 // if view_quality is 0.5, we want to have them die twice as fast
114 self.nextthink -= frametime * (1 / bound(0.01, view_quality, 1.00) - 1);
116 self.alpha = bound(0, self.nextthink - time, 1);
118 if(self.alpha < ALPHA_MIN_VISIBLE)
125 void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector vrand, int specnum, bool destroyontouch, bool issilent)
129 // TODO remove some gibs according to cl_nogibs
130 gib = RubbleNew("gib");
131 gib.classname = "gib";
132 gib.move_movetype = MOVETYPE_BOUNCE;
134 gib.solid = SOLID_CORPSE;
136 gib.silent = issilent;
137 Gib_setmodel(gib, mdlname, specnum);
139 setsize (gib, '-8 -8 -8', '8 8 8');
143 gib.move_touch = Gib_Touch;
145 gib.move_touch = SUB_RemoveOnNoImpact;
147 // don't spawn gibs inside solid - just don't
150 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
154 gib.move_origin = org;
156 gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
157 gib.move_avelocity = prandomvec() * vlen(gib.move_velocity) * autocvar_cl_gibs_avelocity_scale;
158 gib.move_time = time;
159 gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
161 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
162 gib.drawmask = MASK_NORMAL;
164 RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
167 void Ent_GibSplash(bool isNew)
169 int amount, type, specnum;
173 string gentle_prefix = "morphed_";
178 type = ReadByte(); // gibbage type
179 amount = ReadByte() / 16.0; // gibbage amount
180 org.x = ReadShort() * 4 + 2;
181 org.y = ReadShort() * 4 + 2;
182 org.z = ReadShort() * 4 + 2;
183 vel = decompressShortVector(ReadShort());
185 float cl_gentle_gibs = autocvar_cl_gentle_gibs;
186 if(cl_gentle_gibs || autocvar_cl_gentle)
187 type |= 0x80; // set gentle bit
191 if(cl_gentle_gibs == 2)
193 else if(cl_gentle_gibs == 3)
194 gentle_prefix = "happy_";
196 else if(autocvar_cl_particlegibs)
199 gentle_prefix = "particlegibs_";
202 if (!(cl_gentle_gibs || autocvar_cl_gentle))
203 amount *= 1 - autocvar_cl_nogibs;
208 if(amount <= 0 || !isNew)
211 setorigin(self, org); // for the sounds
213 specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
214 issilent = (type & 0x40);
215 type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
216 specstr = species_prefix(specnum);
222 sound (self, CH_PAIN, "misc/gib.wav", VOL_BASE, ATTEN_NORM);
224 if(prandom() < amount)
225 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
226 new_te_bloodshower(particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
227 if(prandom() < amount)
228 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
230 for(c = 0; c < amount; ++c)
232 randomvalue = amount - c;
234 if(prandom() < randomvalue)
235 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
236 if(prandom() < randomvalue)
237 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
238 if(prandom() < randomvalue)
239 TossGib ("models/gibs/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
240 if(prandom() < randomvalue)
241 TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
242 if(prandom() < randomvalue)
243 TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
244 if(prandom() < randomvalue)
245 TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
247 // these splat on impact
248 if(prandom() < randomvalue)
249 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
250 if(prandom() < randomvalue)
251 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
252 if(prandom() < randomvalue)
253 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
254 if(prandom() < randomvalue)
255 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
259 pointparticles(particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
262 if(prandom() < amount)
263 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
266 pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
269 pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
272 // no gibs in gentle mode, sorry
277 void GibSplash_Precache()
279 precache_model("models/gibs/chunk.mdl");
280 precache_model("models/gibs/leg1.md3");
281 precache_model("models/gibs/leg2.md3");
282 precache_model("models/gibs/chest.md3");
283 precache_model("models/gibs/smallchest.md3");
284 precache_model("models/gibs/arm.md3");
285 precache_model("models/gibs/bloodyskull.md3");
286 precache_model("models/gibs/eye.md3");
288 precache_model("models/gibs/robo.md3");
289 precache_model("models/gibs/robo1.md3");
290 precache_model("models/gibs/robo2.md3");
291 precache_model("models/gibs/robo3.md3");
292 precache_model("models/gibs/robo4.md3");
293 precache_model("models/gibs/robo5.md3");
294 precache_model("models/gibs/robo6.md3");
295 precache_model("models/gibs/robo7.md3");
296 precache_model("models/gibs/robo8.md3");
298 precache_sound ("misc/gib.wav");
299 precache_sound ("misc/gib_splat01.wav");
300 precache_sound ("misc/gib_splat02.wav");
301 precache_sound ("misc/gib_splat03.wav");
302 precache_sound ("misc/gib_splat04.wav");