]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/gibs.qc
Send the dead body / gibbed status as a separate WriteByte. I really see no other...
[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 < 250 * pmod; ++i)
56                 pointparticles(ef, org, randomvec() * explosionspeed, howmany / 250);
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, CHAN_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                 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_SLIGHTBLOOD")), oldorg, self.origin);
93         else
94                 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_BLOOD")), oldorg, self.origin);
95
96         self.renderflags = 0;
97         self.alpha = bound(0, self.nextthink - time, 1);
98
99         if(self.alpha < ALPHA_MIN_VISIBLE)
100         {
101                 self.drawmask = 0;
102                 Gib_Delete();
103         }
104 }
105
106 void TossGib (string mdlname, vector org, vector vconst, vector vrand, float specnum, float destroyontouch, float issilent, float gibownernum)
107 {
108         entity gib;
109
110         // TODO remove some gibs according to cl_nogibs
111         gib = RubbleNew("gib");
112         gib.classname = "gib";
113         gib.move_movetype = MOVETYPE_BOUNCE;
114         gib.gravity = 1;
115         gib.solid = SOLID_CORPSE;
116         gib.cnt = specnum;
117         gib.silent = issilent;
118         gib.team = gibownernum;
119         Gib_setmodel(gib, mdlname, specnum);
120
121         setsize (gib, '-8 -8 -8', '8 8 8');
122
123         gib.draw = Gib_Draw;
124         if(destroyontouch)
125                 gib.move_touch = Gib_Touch;
126         else
127                 gib.move_touch = SUB_RemoveOnNoImpact;
128
129         gib.move_origin = gib.origin = org;
130         gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
131         gib.move_avelocity = prandomvec() * vlen(gib.move_velocity);
132         gib.move_time = time;
133         gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
134
135         gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
136         gib.drawmask = MASK_NORMAL;
137
138         RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
139 }
140
141 void Ent_GibSplash(float isNew)
142 {
143         float amount, type, specnum, entnumber, body;
144         vector org, vel;
145         string specstr;
146         float issilent;
147         string gentle_prefix;
148
149         float c, randomvalue;
150
151         type = ReadByte(); // gibbage type
152         amount = ReadByte() / 16.0; // gibbage amount
153         entnumber = ReadByte(); // player num
154         body = ReadByte(); // is dead body / gibbed
155         org_x = ReadShort() * 4 + 2;
156         org_y = ReadShort() * 4 + 2;
157         org_z = ReadShort() * 4 + 2;
158         vel = decompressShortVector(ReadShort());
159
160         float cl_gentle_gibs = autocvar_cl_gentle_gibs;
161         if(cl_gentle_gibs || autocvar_cl_gentle)
162                 type |= 0x80; // set gentle bit
163
164         if(type & 0x80)
165         {
166                 if(cl_gentle_gibs == 2)
167                         gentle_prefix = "";
168                 else if(cl_gentle_gibs == 3) 
169                         gentle_prefix = "happy_";
170                 else
171                         gentle_prefix = "morphed_";
172         }
173         else if(autocvar_cl_particlegibs)
174         {
175                 type |= 0x80;
176                 gentle_prefix = "particlegibs_";
177         }
178
179         if not(cl_gentle_gibs || autocvar_cl_gentle)
180                 amount *= 1 - autocvar_cl_nogibs;
181
182         if(autocvar_ekg)
183                 amount *= 5;
184
185         if(amount <= 0 || !isNew)
186                 return;
187
188         self.origin = org; // for the sounds
189
190         specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
191         issilent = (type & 0x40);
192         type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
193         specstr = species_prefix(specnum);
194
195         switch(type)
196         {
197                 case 0x01:
198                         if(!issilent)
199                                 sound (self, CHAN_PAIN, "misc/gib.wav", VOL_BASE, ATTN_NORM);
200
201                         if(prandom() < amount)
202                                 TossGib ("models/gibs/eye.md3", org, vel, prandomvec() * 150, specnum, 0, issilent, entnumber);
203                         new_te_bloodshower(particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
204                         if(prandom() < amount)
205                                 TossGib ("models/gibs/bloodyskull.md3", org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent, entnumber);
206
207                         for(c = 0; c < amount; ++c)
208                         {
209                                 randomvalue = amount - c;
210
211                                 if(prandom() < randomvalue)
212                                         TossGib ("models/gibs/arm.md3", org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent, entnumber);
213                                 if(prandom() < randomvalue)
214                                         TossGib ("models/gibs/arm.md3", org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent, entnumber);
215                                 if(prandom() < randomvalue)
216                                         TossGib ("models/gibs/chest.md3", org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent, entnumber);
217                                 if(prandom() < randomvalue)
218                                         TossGib ("models/gibs/smallchest.md3", org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent, entnumber);
219                                 if(prandom() < randomvalue)
220                                         TossGib ("models/gibs/leg1.md3", org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent, entnumber);
221                                 if(prandom() < randomvalue)
222                                         TossGib ("models/gibs/leg2.md3", org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent, entnumber);
223
224                                 // these splat on impact
225                                 if(prandom() < randomvalue)
226                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent, entnumber);
227                                 if(prandom() < randomvalue)
228                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent, entnumber);
229                                 if(prandom() < randomvalue)
230                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent, entnumber);
231                                 if(prandom() < randomvalue)
232                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent, entnumber);
233                         }
234                         break;
235                 case 0x02:
236                         pointparticles(particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
237                         break;
238                 case 0x03:
239                         if(prandom() < amount)
240                                 TossGib ("models/gibs/chunk.mdl", org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent, entnumber); // TODO maybe adjust to more randomization?
241                         break;
242                 case 0x81:
243                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
244                         break;
245                 case 0x82:
246                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
247                         break;
248                 case 0x83:
249                         // no gibs in gentle mode, sorry
250                         break;
251         }
252 }
253
254 void GibSplash_Precache()
255 {
256         precache_model("models/gibs/chunk.mdl");
257         precache_model("models/gibs/leg1.md3");
258         precache_model("models/gibs/leg2.md3");
259         precache_model("models/gibs/chest.md3");
260         precache_model("models/gibs/smallchest.md3");
261         precache_model("models/gibs/arm.md3");
262         precache_model("models/gibs/bloodyskull.md3");
263         precache_model("models/gibs/eye.md3");
264
265         precache_model("models/gibs/robo.md3");
266         precache_model("models/gibs/robo1.md3");
267         precache_model("models/gibs/robo2.md3");
268         precache_model("models/gibs/robo3.md3");
269         precache_model("models/gibs/robo4.md3");
270         precache_model("models/gibs/robo5.md3");
271         precache_model("models/gibs/robo6.md3");
272         precache_model("models/gibs/robo7.md3");
273         precache_model("models/gibs/robo8.md3");
274
275         precache_sound ("misc/gib.wav");
276     precache_sound ("misc/gib_splat01.wav");
277     precache_sound ("misc/gib_splat02.wav");
278     precache_sound ("misc/gib_splat03.wav");
279     precache_sound ("misc/gib_splat04.wav");
280 }
281
282 void Ent_DamageEffect()
283 {
284         float type, specnum1, specnum2, entnumber;
285         vector org;
286         string specstr, effectnum;
287         entity e;
288
289         type = ReadByte(); // damage weapon
290         specnum1 = ReadByte(); // player species
291         entnumber = ReadByte(); // player entnum
292         org_x = ReadCoord();
293         org_y = ReadCoord();
294         org_z = ReadCoord();
295
296         if not(autocvar_cl_damageeffect)
297                 return;
298         if(autocvar_cl_gentle || autocvar_cl_gentle_damage)
299                 return;
300
301         e = get_weaponinfo(type);
302
303         specnum2 = (specnum1 & 0x78) / 8; // blood type: using four bits (0..7, bit indexes 3,4,5)
304         specstr = species_prefix(specnum2);
305
306         effectnum = strcat("weapondamage_", e.netname);
307         // If the weapon is a bullet weapon, its damage effect is blood.
308         // Since blood is species dependent, we make this effect per-species.
309         if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_SNIPERRIFLE)
310         if(specstr != "")
311         {
312                 effectnum = strcat(effectnum, "_", specstr);
313                 effectnum = substring(effectnum, 0, strlen(effectnum) - 1); // remove the _ symbol at the end of the species name
314         }
315
316         entity head;
317
318         // Scan the owner of all gibs in the world. If a gib owner is the same as the player we're applying the
319         // effect to, it means our player is gibbed. Therefore, apply the particles to the gibs as well.
320         if(autocvar_cl_damageeffect_gibs)
321         for(head = world; (head = find(head, classname, "gib")); )
322         {
323                 if(head.team == entnumber)
324                 if(random() < autocvar_cl_damageeffect_gibs)
325                         pointparticles(particleeffectnum(effectnum), head.origin, '0 0 0', 1);
326         }
327
328         // if we aren't in third person mode, hide our own damage effect
329         if(entnumber == player_localentnum && !autocvar_chase_active)
330                 return;
331
332         // Now apply the effect to the player. This shouldn't be done on gibbed bodies, but there's no way
333         // to tell between them and the respawned player, if both have damage effects at the same time.
334         if(random() < autocvar_cl_damageeffect)
335                 pointparticles(particleeffectnum(effectnum), org, '0 0 0', 1);
336 }