4 #include "../common/movetypes/movetypes.qh"
16 string species_prefix(int specnum)
20 case SPECIES_HUMAN: return "";
21 case SPECIES_ALIEN: return "alien_";
22 case SPECIES_ROBOT_SHINY: return "robot_";
23 case SPECIES_ROBOT_RUSTY: return "robot_"; // use the same effects, only different gibs
24 case SPECIES_ROBOT_SOLID: return "robot_"; // use the same effects, only different gibs
25 case SPECIES_ANIMAL: return "animal_";
26 case SPECIES_RESERVED: return "reserved_";
31 void Gib_setmodel(entity gib, string mdlname, int specnum)
35 case SPECIES_ROBOT_RUSTY:
36 case SPECIES_ROBOT_SHINY:
37 case SPECIES_ROBOT_SOLID:
38 if(specnum != SPECIES_ROBOT_SOLID || mdlname == "models/gibs/chunk.mdl")
40 if(mdlname == "models/gibs/bloodyskull.md3")
41 setmodel(gib, MDL_GIB_ROBO);
43 setmodel(gib, MDL_GIB_ROBO_RANDOM());
44 if(specnum == SPECIES_ROBOT_SHINY)
47 gib.colormod = '2 2 2';
53 _setmodel(gib, mdlname);
59 void new_te_bloodshower (int ef, vector org, float explosionspeed, int howmany)
62 pmod = autocvar_cl_particles_quality;
63 for (i = 0; i < 50 * pmod; ++i)
64 pointparticles(ef, org, randomvec() * explosionspeed, howmany / 50);
67 void SUB_RemoveOnNoImpact()
69 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
75 // TODO maybe bounce of walls, make more gibs, etc.
77 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
84 sound(self, CH_PAIN, SND_GIB_SPLAT_RANDOM(), VOL_BASE, ATTEN_NORM);
85 pointparticles(_particleeffectnum(strcat(species_prefix(self.cnt), "blood")), self.origin + '0 0 1', '0 0 30', 10);
90 void Gib_Draw(entity this)
95 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
99 if(self.touch == Gib_Touch) // don't do this for the "chunk" thingie...
100 // TODO somehow make it spray in a direction dependent on self.angles
101 trailparticles(self, _particleeffectnum(strcat(species_prefix(self.cnt), EFFECT_TR_SLIGHTBLOOD.eent_eff_name)), oldorg, self.origin);
103 trailparticles(self, _particleeffectnum(strcat(species_prefix(self.cnt), EFFECT_TR_BLOOD.eent_eff_name)), oldorg, self.origin);
105 self.renderflags = 0;
107 // make gibs die faster at low view quality
108 // if view_quality is 0.5, we want to have them die twice as fast
109 self.nextthink -= frametime * (1 / bound(0.01, view_quality, 1.00) - 1);
111 self.alpha = bound(0, self.nextthink - time, 1);
113 if(self.alpha < ALPHA_MIN_VISIBLE)
120 void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector vrand, int specnum, bool destroyontouch, bool issilent)
124 // TODO remove some gibs according to cl_nogibs
125 gib = RubbleNew("gib");
126 gib.classname = "gib";
127 gib.move_movetype = MOVETYPE_BOUNCE;
129 gib.solid = SOLID_CORPSE;
131 gib.silent = issilent;
132 Gib_setmodel(gib, mdlname, specnum);
134 setsize (gib, '-8 -8 -8', '8 8 8');
138 gib.move_touch = Gib_Touch;
140 gib.move_touch = SUB_RemoveOnNoImpact;
142 // don't spawn gibs inside solid - just don't
145 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
149 gib.move_origin = org;
151 gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
152 gib.move_avelocity = prandomvec() * vlen(gib.move_velocity) * autocvar_cl_gibs_avelocity_scale;
153 gib.move_time = time;
154 gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
156 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
157 gib.drawmask = MASK_NORMAL;
159 RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
162 void Ent_GibSplash(bool isNew)
164 int amount, type, specnum;
168 string gentle_prefix = "morphed_";
173 type = ReadByte(); // gibbage type
174 amount = ReadByte() / 16.0; // gibbage amount
175 org.x = ReadShort() * 4 + 2;
176 org.y = ReadShort() * 4 + 2;
177 org.z = ReadShort() * 4 + 2;
178 vel = decompressShortVector(ReadShort());
180 float cl_gentle_gibs = autocvar_cl_gentle_gibs;
181 if(cl_gentle_gibs || autocvar_cl_gentle)
182 type |= 0x80; // set gentle bit
186 if(cl_gentle_gibs == 2)
188 else if(cl_gentle_gibs == 3)
189 gentle_prefix = "happy_";
191 else if(autocvar_cl_particlegibs)
194 gentle_prefix = "particlegibs_";
197 if (!(cl_gentle_gibs || autocvar_cl_gentle))
198 amount *= 1 - autocvar_cl_nogibs;
203 if(amount <= 0 || !isNew)
206 setorigin(self, org); // for the sounds
208 specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
209 issilent = (type & 0x40);
210 type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
211 specstr = species_prefix(specnum);
217 sound (self, CH_PAIN, SND_GIB, VOL_BASE, ATTEN_NORM);
219 if(prandom() < amount)
220 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
221 new_te_bloodshower(_particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
222 if(prandom() < amount)
223 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
225 for(c = 0; c < amount; ++c)
227 randomvalue = amount - c;
229 if(prandom() < randomvalue)
230 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
231 if(prandom() < randomvalue)
232 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
233 if(prandom() < randomvalue)
234 TossGib ("models/gibs/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
235 if(prandom() < randomvalue)
236 TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
237 if(prandom() < randomvalue)
238 TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
239 if(prandom() < randomvalue)
240 TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
242 // these splat on impact
243 if(prandom() < randomvalue)
244 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
245 if(prandom() < randomvalue)
246 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
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);
254 pointparticles(_particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
257 if(prandom() < amount)
258 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
261 pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
264 pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
267 // no gibs in gentle mode, sorry