]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/gibs.qc
Cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / gibs.qc
1 #include "gibs.qh"
2
3 #include "rubble.qh"
4 #include "../common/movetypes/movetypes.qh"
5
6 .float scale;
7 .float alpha;
8 .float cnt;
9 .float gravity;
10
11 void Gib_Delete()
12 {SELFPARAM();
13         remove(self);
14 }
15
16 string species_prefix(int specnum)
17 {
18         switch(specnum)
19         {
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_";
27                 default:         return "";
28         }
29 }
30
31 void Gib_setmodel(entity gib, string mdlname, int specnum)
32 {
33         switch(specnum)
34         {
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")
39                         {
40                                 if(mdlname == "models/gibs/bloodyskull.md3")
41                                         setmodel(gib, MDL_GIB_ROBO);
42                                 else
43                                         setmodel(gib, MDL_GIB_ROBO_RANDOM());
44                                 if(specnum == SPECIES_ROBOT_SHINY)
45                                 {
46                                         gib.skin = 1;
47                                         gib.colormod = '2 2 2';
48                                 }
49                                 gib.scale = 1;
50                                 break;
51                         }
52                 default:
53                         _setmodel(gib, mdlname);
54                         gib.skin = specnum;
55                         break;
56         }
57 }
58
59 void new_te_bloodshower (int ef, vector org, float explosionspeed, int howmany)
60 {
61         float i, pmod;
62         pmod = autocvar_cl_particles_quality;
63         for (i = 0; i < 50 * pmod; ++i)
64                 __pointparticles(ef, org, randomvec() * explosionspeed, howmany / 50);
65 }
66
67 void SUB_RemoveOnNoImpact()
68 {
69         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
70                 Gib_Delete();
71 }
72
73 void Gib_Touch()
74 {SELFPARAM();
75         // TODO maybe bounce of walls, make more gibs, etc.
76
77         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
78         {
79                 Gib_Delete();
80                 return;
81         }
82
83         if(!self.silent)
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);
86
87         Gib_Delete();
88 }
89
90 void Gib_Draw(entity this)
91 {
92         vector oldorg;
93         oldorg = self.origin;
94
95         Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
96         if(wasfreed(self))
97                 return;
98
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);
102         else
103                 __trailparticles(self, _particleeffectnum(strcat(species_prefix(self.cnt), EFFECT_TR_BLOOD.eent_eff_name)), oldorg, self.origin);
104
105         self.renderflags = 0;
106
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);
110
111         self.alpha = bound(0, self.nextthink - time, 1);
112
113         if(self.alpha < ALPHA_MIN_VISIBLE)
114         {
115                 self.drawmask = 0;
116                 Gib_Delete();
117         }
118 }
119
120 void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector vrand, int specnum, bool destroyontouch, bool issilent)
121 {
122         entity gib;
123
124         // TODO remove some gibs according to cl_nogibs
125         gib = RubbleNew("gib");
126         gib.move_movetype = MOVETYPE_BOUNCE;
127         gib.gravity = 1;
128         gib.solid = SOLID_CORPSE;
129         gib.cnt = specnum;
130         gib.silent = issilent;
131         Gib_setmodel(gib, mdlname, specnum);
132
133         setsize (gib, '-8 -8 -8', '8 8 8');
134
135         gib.draw = Gib_Draw;
136         if(destroyontouch)
137                 gib.move_touch = Gib_Touch;
138         else
139                 gib.move_touch = SUB_RemoveOnNoImpact;
140
141         // don't spawn gibs inside solid - just don't
142         if(org != safeorg)
143         {
144                 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
145                 org = trace_endpos;
146         }
147
148         gib.move_origin = org;
149         setorigin(gib, 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;
154
155         gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
156         gib.drawmask = MASK_NORMAL;
157
158         RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
159 }
160
161 REGISTER_NET_TEMP(net_gibsplash)
162
163 NET_HANDLE(net_gibsplash, bool isNew)
164 {
165         Net_Accept(net_gibsplash);
166
167         string gentle_prefix = "morphed_";
168
169         int type = ReadByte(); // gibbage type
170         int amount = ReadByte() / 16.0; // gibbage amount
171         vector org;
172         org.x = ReadShort() * 4 + 2;
173         org.y = ReadShort() * 4 + 2;
174         org.z = ReadShort() * 4 + 2;
175         vector vel = decompressShortVector(ReadShort());
176
177         return = true;
178
179         float cl_gentle_gibs = autocvar_cl_gentle_gibs;
180         if(cl_gentle_gibs || autocvar_cl_gentle)
181                 type |= 0x80; // set gentle bit
182
183         if(type & 0x80)
184         {
185                 if(cl_gentle_gibs == 2)
186                         gentle_prefix = "";
187                 else if(cl_gentle_gibs == 3)
188                         gentle_prefix = "happy_";
189         }
190         else if(autocvar_cl_particlegibs)
191         {
192                 type |= 0x80;
193                 gentle_prefix = "particlegibs_";
194         }
195
196         if (!(cl_gentle_gibs || autocvar_cl_gentle))
197                 amount *= 1 - autocvar_cl_nogibs;
198
199         if(autocvar_ekg)
200                 amount *= 5;
201
202         if(amount <= 0 || !isNew)
203                 return;
204
205         setorigin(this, org); // for the sounds
206
207         int specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
208         bool issilent = (type & 0x40);
209         type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
210         string specstr = species_prefix(specnum);
211
212         switch(type)
213         {
214                 case 0x01:
215                         if(!issilent)
216                                 sound (this, CH_PAIN, SND_GIB, VOL_BASE, ATTEN_NORM);
217
218                         if(prandom() < amount)
219                                 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
220                         new_te_bloodshower(_particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
221                         if(prandom() < amount)
222                                 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
223
224                         for(int c = 0; c < amount; ++c)
225                         {
226                                 int randomvalue = amount - c;
227
228                                 if(prandom() < randomvalue)
229                                         TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
230                                 if(prandom() < randomvalue)
231                                         TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
232                                 if(prandom() < randomvalue)
233                                         TossGib ("models/gibs/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
234                                 if(prandom() < randomvalue)
235                                         TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
236                                 if(prandom() < randomvalue)
237                                         TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
238                                 if(prandom() < randomvalue)
239                                         TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
240
241                                 // these splat on impact
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);
246                                 if(prandom() < randomvalue)
247                                         TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
248                                 if(prandom() < randomvalue)
249                                         TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
250                         }
251                         break;
252                 case 0x02:
253                         __pointparticles(_particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
254                         break;
255                 case 0x03:
256                         if(prandom() < amount)
257                                 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
258                         break;
259                 case 0x81:
260                         __pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
261                         break;
262                 case 0x82:
263                         __pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
264                         break;
265                 case 0x83:
266                         // no gibs in gentle mode, sorry
267                         break;
268         }
269         remove(this);
270 }