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.move_movetype = MOVETYPE_BOUNCE;
128 gib.solid = SOLID_CORPSE;
130 gib.silent = issilent;
131 Gib_setmodel(gib, mdlname, specnum);
133 setsize (gib, '-8 -8 -8', '8 8 8');
137 gib.move_touch = Gib_Touch;
139 gib.move_touch = SUB_RemoveOnNoImpact;
141 // don't spawn gibs inside solid - just don't
144 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
148 gib.move_origin = org;
150 gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
151 gib.move_avelocity = prandomvec() * vlen(gib.move_velocity) * autocvar_cl_gibs_avelocity_scale;
152 gib.move_time = time;
153 gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
155 gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
156 gib.drawmask = MASK_NORMAL;
158 RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
161 REGISTER_NET_TEMP(net_gibsplash, bool isNew)
163 Net_Accept(net_gibsplash);
165 string gentle_prefix = "morphed_";
167 int type = ReadByte(); // gibbage type
168 int amount = ReadByte() / 16.0; // gibbage amount
170 org.x = ReadShort() * 4 + 2;
171 org.y = ReadShort() * 4 + 2;
172 org.z = ReadShort() * 4 + 2;
173 vector vel = decompressShortVector(ReadShort());
175 float cl_gentle_gibs = autocvar_cl_gentle_gibs;
176 if(cl_gentle_gibs || autocvar_cl_gentle)
177 type |= 0x80; // set gentle bit
181 if(cl_gentle_gibs == 2)
183 else if(cl_gentle_gibs == 3)
184 gentle_prefix = "happy_";
186 else if(autocvar_cl_particlegibs)
189 gentle_prefix = "particlegibs_";
192 if (!(cl_gentle_gibs || autocvar_cl_gentle))
193 amount *= 1 - autocvar_cl_nogibs;
198 if(amount <= 0 || !isNew)
201 setorigin(this, org); // for the sounds
203 int specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
204 bool issilent = (type & 0x40);
205 type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
206 string specstr = species_prefix(specnum);
212 sound (this, CH_PAIN, SND_GIB, VOL_BASE, ATTEN_NORM);
214 if(prandom() < amount)
215 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
216 new_te_bloodshower(_particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
217 if(prandom() < amount)
218 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
220 for(int c = 0; c < amount; ++c)
222 int randomvalue = amount - c;
224 if(prandom() < randomvalue)
225 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
226 if(prandom() < randomvalue)
227 TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
228 if(prandom() < randomvalue)
229 TossGib ("models/gibs/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
230 if(prandom() < randomvalue)
231 TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
232 if(prandom() < randomvalue)
233 TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
234 if(prandom() < randomvalue)
235 TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
237 // these splat on impact
238 if(prandom() < randomvalue)
239 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
240 if(prandom() < randomvalue)
241 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
242 if(prandom() < randomvalue)
243 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
244 if(prandom() < randomvalue)
245 TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
249 __pointparticles(_particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
252 if(prandom() < amount)
253 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
256 __pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
259 __pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
262 // no gibs in gentle mode, sorry