]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/gibs.qc
Merge branch 'master' into TimePath/debug_draw
[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, bool isNew)
162 {
163         Net_Accept(net_gibsplash);
164
165         string gentle_prefix = "morphed_";
166
167         int type = ReadByte(); // gibbage type
168         int amount = ReadByte() / 16.0; // gibbage amount
169         vector org;
170         org.x = ReadShort() * 4 + 2;
171         org.y = ReadShort() * 4 + 2;
172         org.z = ReadShort() * 4 + 2;
173         vector vel = decompressShortVector(ReadShort());
174
175         float cl_gentle_gibs = autocvar_cl_gentle_gibs;
176         if(cl_gentle_gibs || autocvar_cl_gentle)
177                 type |= 0x80; // set gentle bit
178
179         if(type & 0x80)
180         {
181                 if(cl_gentle_gibs == 2)
182                         gentle_prefix = "";
183                 else if(cl_gentle_gibs == 3)
184                         gentle_prefix = "happy_";
185         }
186         else if(autocvar_cl_particlegibs)
187         {
188                 type |= 0x80;
189                 gentle_prefix = "particlegibs_";
190         }
191
192         if (!(cl_gentle_gibs || autocvar_cl_gentle))
193                 amount *= 1 - autocvar_cl_nogibs;
194
195         if(autocvar_ekg)
196                 amount *= 5;
197
198         if(amount <= 0 || !isNew)
199                 return;
200
201         setorigin(this, org); // for the sounds
202
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);
207
208         switch(type)
209         {
210                 case 0x01:
211                         if(!issilent)
212                                 sound (this, CH_PAIN, SND_GIB, VOL_BASE, ATTEN_NORM);
213
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);
219
220                         for(int c = 0; c < amount; ++c)
221                         {
222                                 int randomvalue = amount - c;
223
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);
236
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);
246                         }
247                         break;
248                 case 0x02:
249                         __pointparticles(_particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
250                         break;
251                 case 0x03:
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?
254                         break;
255                 case 0x81:
256                         __pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
257                         break;
258                 case 0x82:
259                         __pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
260                         break;
261                 case 0x83:
262                         // no gibs in gentle mode, sorry
263                         break;
264         }
265         remove(this);
266 }