]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/gibs.qc
Remove the old way of showing damage effects on gibs. Currently, damage effects no...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / gibs.qc
1 .float silent;
2
3 void Gib_Delete()
4 {
5         remove(self);
6 }
7
8 string species_prefix(float specnum)
9 {
10         switch(specnum)
11         {
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_";
19                 default:         return "";
20         }
21 }
22
23 void Gib_setmodel(entity gib, string mdlname, float specnum)
24 {
25         switch(specnum)
26         {
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")
31                         {
32                                 if(mdlname == "models/gibs/bloodyskull.md3")
33                                         setmodel(gib, "models/gibs/robo.md3");
34                                 else
35                                         setmodel(gib, strcat("models/gibs/robo", ftos(floor(random() * 8) + 1), ".md3"));
36                                 if(specnum == SPECIES_ROBOT_SHINY)
37                                 {
38                                         gib.skin = 1;
39                                         gib.colormod = '2 2 2';
40                                 }
41                                 gib.scale = 1;
42                                 break;
43                         }
44                 default:
45                         setmodel(gib, mdlname);
46                         gib.skin = specnum;
47                         break;
48         }
49 }
50
51 void new_te_bloodshower (float ef, vector org, float explosionspeed, float howmany)
52 {
53         float i, pmod;
54         pmod = autocvar_cl_particles_quality;
55         for (i = 0; i < 50 * pmod; ++i)
56                 pointparticles(ef, org, randomvec() * explosionspeed, howmany / 50);
57 }
58
59 void SUB_RemoveOnNoImpact()
60 {
61         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
62                 Gib_Delete();
63 }
64
65 void Gib_Touch()
66 {
67         // TODO maybe bounce of walls, make more gibs, etc.
68
69         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
70         {
71                 Gib_Delete();
72                 return;
73         }
74
75         if(!self.silent)
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);
78
79         Gib_Delete();
80 }
81
82 void Gib_Draw()
83 {
84         vector oldorg;
85         oldorg = self.origin;
86
87         Movetype_Physics_MatchTicrate(autocvar_cl_gibs_ticrate, autocvar_cl_gibs_sloppy);
88         if(wasfreed(self))
89                 return;
90
91         if(self.touch == Gib_Touch) // don't do this for the "chunk" thingie...
92                 // TODO somehow make it spray in a direction dependent on self.angles
93                 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_SLIGHTBLOOD")), oldorg, self.origin);
94         else
95                 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_BLOOD")), oldorg, self.origin);
96
97         self.renderflags = 0;
98
99         // make gibs die faster at low view quality
100         // if view_quality is 0.5, we want to have them die twice as fast
101         self.nextthink -= frametime * (1 / bound(0.01, view_quality, 1.00) - 1);
102
103         self.alpha = bound(0, self.nextthink - time, 1);
104
105         if(self.alpha < ALPHA_MIN_VISIBLE)
106         {
107                 self.drawmask = 0;
108                 Gib_Delete();
109         }
110 }
111
112 void TossGib (string mdlname, vector safeorg, vector org, vector vconst, vector vrand, float specnum, float destroyontouch, float issilent)
113 {
114         entity gib;
115
116         // TODO remove some gibs according to cl_nogibs
117         gib = RubbleNew("gib");
118         gib.classname = "gib";
119         gib.move_movetype = MOVETYPE_BOUNCE;
120         gib.gravity = 1;
121         gib.solid = SOLID_CORPSE;
122         gib.cnt = specnum;
123         gib.silent = issilent;
124         Gib_setmodel(gib, mdlname, specnum);
125
126         setsize (gib, '-8 -8 -8', '8 8 8');
127
128         gib.draw = Gib_Draw;
129         if(destroyontouch)
130                 gib.move_touch = Gib_Touch;
131         else
132                 gib.move_touch = SUB_RemoveOnNoImpact;
133
134         // don't spawn gibs inside solid - just don't
135         if(org != safeorg)
136         {
137                 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
138                 org = trace_endpos;
139         }
140
141         gib.move_origin = gib.origin = org;
142         gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
143         gib.move_avelocity = prandomvec() * vlen(gib.move_velocity) * autocvar_cl_gibs_avelocity_scale;
144         gib.move_time = time;
145         gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
146
147         gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
148         gib.drawmask = MASK_NORMAL;
149
150         RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
151 }
152
153 void Ent_GibSplash(float isNew)
154 {
155         float amount, type, specnum, entnumber;
156         vector org, vel;
157         string specstr;
158         float issilent;
159         string gentle_prefix;
160
161         float c, randomvalue;
162
163         type = ReadByte(); // gibbage type
164         amount = ReadByte() / 16.0; // gibbage amount
165         entnumber = ReadByte(); // player num
166         org_x = ReadShort() * 4 + 2;
167         org_y = ReadShort() * 4 + 2;
168         org_z = ReadShort() * 4 + 2;
169         vel = decompressShortVector(ReadShort());
170
171         float cl_gentle_gibs = autocvar_cl_gentle_gibs;
172         if(cl_gentle_gibs || autocvar_cl_gentle)
173                 type |= 0x80; // set gentle bit
174
175         if(type & 0x80)
176         {
177                 if(cl_gentle_gibs == 2)
178                         gentle_prefix = "";
179                 else if(cl_gentle_gibs == 3) 
180                         gentle_prefix = "happy_";
181                 else
182                         gentle_prefix = "morphed_";
183         }
184         else if(autocvar_cl_particlegibs)
185         {
186                 type |= 0x80;
187                 gentle_prefix = "particlegibs_";
188         }
189
190         if not(cl_gentle_gibs || autocvar_cl_gentle)
191                 amount *= 1 - autocvar_cl_nogibs;
192
193         if(autocvar_ekg)
194                 amount *= 5;
195
196         if(amount <= 0 || !isNew)
197                 return;
198
199         self.origin = org; // for the sounds
200
201         specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
202         issilent = (type & 0x40);
203         type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
204         specstr = species_prefix(specnum);
205
206         switch(type)
207         {
208                 case 0x01:
209                         if(!issilent)
210                                 sound (self, CH_PAIN, "misc/gib.wav", VOL_BASE, ATTN_NORM);
211
212                         if(prandom() < amount)
213                                 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
214                         new_te_bloodshower(particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
215                         if(prandom() < amount)
216                                 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
217
218                         for(c = 0; c < amount; ++c)
219                         {
220                                 randomvalue = amount - c;
221
222                                 if(prandom() < randomvalue)
223                                         TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
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/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
228                                 if(prandom() < randomvalue)
229                                         TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
230                                 if(prandom() < randomvalue)
231                                         TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
232                                 if(prandom() < randomvalue)
233                                         TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
234
235                                 // these splat on impact
236                                 if(prandom() < randomvalue)
237                                         TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
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                         }
245                         break;
246                 case 0x02:
247                         pointparticles(particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
248                         break;
249                 case 0x03:
250                         if(prandom() < amount)
251                                 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
252                         break;
253                 case 0x81:
254                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
255                         break;
256                 case 0x82:
257                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
258                         break;
259                 case 0x83:
260                         // no gibs in gentle mode, sorry
261                         break;
262         }
263 }
264
265 void GibSplash_Precache()
266 {
267         precache_model("models/gibs/chunk.mdl");
268         precache_model("models/gibs/leg1.md3");
269         precache_model("models/gibs/leg2.md3");
270         precache_model("models/gibs/chest.md3");
271         precache_model("models/gibs/smallchest.md3");
272         precache_model("models/gibs/arm.md3");
273         precache_model("models/gibs/bloodyskull.md3");
274         precache_model("models/gibs/eye.md3");
275
276         precache_model("models/gibs/robo.md3");
277         precache_model("models/gibs/robo1.md3");
278         precache_model("models/gibs/robo2.md3");
279         precache_model("models/gibs/robo3.md3");
280         precache_model("models/gibs/robo4.md3");
281         precache_model("models/gibs/robo5.md3");
282         precache_model("models/gibs/robo6.md3");
283         precache_model("models/gibs/robo7.md3");
284         precache_model("models/gibs/robo8.md3");
285
286         precache_sound ("misc/gib.wav");
287     precache_sound ("misc/gib_splat01.wav");
288     precache_sound ("misc/gib_splat02.wav");
289     precache_sound ("misc/gib_splat03.wav");
290     precache_sound ("misc/gib_splat04.wav");
291 }