8 string species_prefix(float specnum)
12 case SPECIES_HUMAN: return "";
13 case SPECIES_ALIEN: return "alien_";
14 case SPECIES_ROBOT_SHINY: return "robot_";
15 case SPECIES_ROBOT_RUSTY: return "robot_"; // use the same effects, only different gibs
16 case SPECIES_ROBOT_SOLID: return "robot_"; // use the same effects, only different gibs
17 case SPECIES_ANIMAL: return "animal_";
18 case SPECIES_RESERVED: return "reserved_";
23 void Gib_setmodel(entity gib, string mdlname, float specnum)
27 case SPECIES_ROBOT_RUSTY:
28 case SPECIES_ROBOT_SHINY:
29 case SPECIES_ROBOT_SOLID:
30 if(specnum != SPECIES_ROBOT_SOLID || mdlname == "models/gibs/chunk.mdl")
32 if(mdlname == "models/gibs/bloodyskull.md3")
33 setmodel(gib, "models/gibs/robo.md3");
35 setmodel(gib, strcat("models/gibs/robo", ftos(floor(random() * 8) + 1), ".md3"));
36 if(specnum == SPECIES_ROBOT_SHINY)
39 gib.colormod = '2 2 2';
45 setmodel(gib, mdlname);
51 void new_te_bloodshower (float ef, vector org, float explosionspeed, float howmany)
54 pmod = autocvar_cl_particles_quality;
55 for (i = 0; i < 250 * pmod; ++i)
56 pointparticles(ef, org, randomvec() * explosionspeed, howmany / 250);
59 void SUB_RemoveOnNoImpact()
61 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
67 // TODO maybe bounce of walls, make more gibs, etc.
69 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
76 sound(self, CH_PAIN, strcat("misc/gib_splat0", ftos(floor(prandom() * 4 + 1)), ".wav"), VOL_BASE, ATTN_NORM);
77 pointparticles(particleeffectnum(strcat(species_prefix(self.cnt), "blood")), self.origin + '0 0 1', '0 0 30', 10);
87 Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
91 if(self.touch == Gib_Touch) // don't do this for the "chunk" thingie...
92 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_SLIGHTBLOOD")), oldorg, self.origin);
94 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_BLOOD")), oldorg, self.origin);
97 self.alpha = bound(0, self.nextthink - time, 1);
99 if(self.alpha < ALPHA_MIN_VISIBLE)
106 void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector vrand, float specnum, float destroyontouch, float issilent)
110 // TODO remove some gibs according to cl_nogibs
111 gib = RubbleNew("gib");
112 gib.move_movetype = MOVETYPE_BOUNCE;
114 gib.solid = SOLID_CORPSE;
116 gib.silent = issilent;
117 Gib_setmodel(gib, mdlname, specnum);
119 setsize (gib, '-8 -8 -8', '8 8 8');
123 gib.move_touch = Gib_Touch;
125 gib.move_touch = SUB_RemoveOnNoImpact;
127 // don't spawn gibs inside solid - just don't
130 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
134 gib.move_origin = gib.origin = org;
135 gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
136 gib.move_avelocity = prandomvec() * vlen(gib.move_velocity);
137 gib.move_time = time;
138 gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
140 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
141 gib.drawmask = MASK_NORMAL;
143 RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
146 void Ent_GibSplash(float isNew)
148 float amount, type, specnum;
152 string gentle_prefix;
154 float c, randomvalue;
156 type = ReadByte(); // gibbage type
157 amount = ReadByte() / 16.0; // gibbage amount
158 org_x = ReadShort() * 4 + 2;
159 org_y = ReadShort() * 4 + 2;
160 org_z = ReadShort() * 4 + 2;
161 vel = decompressShortVector(ReadShort());
163 float cl_gentle_gibs = autocvar_cl_gentle_gibs;
164 if(cl_gentle_gibs || autocvar_cl_gentle)
165 type |= 0x80; // set gentle bit
169 if(cl_gentle_gibs == 2)
171 else if(cl_gentle_gibs == 3)
172 gentle_prefix = "happy_";
174 gentle_prefix = "morphed_";
176 else if(autocvar_cl_particlegibs)
179 gentle_prefix = "particlegibs_";
182 if not(cl_gentle_gibs || autocvar_cl_gentle)
183 amount *= 1 - autocvar_cl_nogibs;
188 if(amount <= 0 || !isNew)
191 self.origin = org; // for the sounds
193 specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
194 issilent = (type & 0x40);
195 type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
196 specstr = species_prefix(specnum);
202 sound (self, CH_PAIN, "misc/gib.wav", VOL_BASE, ATTN_NORM);
204 if(prandom() < amount)
205 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
206 new_te_bloodshower(particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
207 if(prandom() < amount)
208 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
210 for(c = 0; c < amount; ++c)
212 randomvalue = amount - c;
214 if(prandom() < randomvalue)
215 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
216 if(prandom() < randomvalue)
217 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
218 if(prandom() < randomvalue)
219 TossGib ("models/gibs/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
220 if(prandom() < randomvalue)
221 TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
222 if(prandom() < randomvalue)
223 TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
224 if(prandom() < randomvalue)
225 TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
227 // these splat on impact
228 if(prandom() < randomvalue)
229 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
230 if(prandom() < randomvalue)
231 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
232 if(prandom() < randomvalue)
233 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
234 if(prandom() < randomvalue)
235 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
239 pointparticles(particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
242 if(prandom() < amount)
243 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
246 pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
249 pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
252 // no gibs in gentle mode, sorry
257 void GibSplash_Precache()
259 precache_model("models/gibs/chunk.mdl");
260 precache_model("models/gibs/leg1.md3");
261 precache_model("models/gibs/leg2.md3");
262 precache_model("models/gibs/chest.md3");
263 precache_model("models/gibs/smallchest.md3");
264 precache_model("models/gibs/arm.md3");
265 precache_model("models/gibs/bloodyskull.md3");
266 precache_model("models/gibs/eye.md3");
268 precache_model("models/gibs/robo.md3");
269 precache_model("models/gibs/robo1.md3");
270 precache_model("models/gibs/robo2.md3");
271 precache_model("models/gibs/robo3.md3");
272 precache_model("models/gibs/robo4.md3");
273 precache_model("models/gibs/robo5.md3");
274 precache_model("models/gibs/robo6.md3");
275 precache_model("models/gibs/robo7.md3");
276 precache_model("models/gibs/robo8.md3");
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");