Hide the MOTD when going spec
[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.classname = "gib";
127         gib.move_movetype = MOVETYPE_BOUNCE;
128         gib.gravity = 1;
129         gib.solid = SOLID_CORPSE;
130         gib.cnt = specnum;
131         gib.silent = issilent;
132         Gib_setmodel(gib, mdlname, specnum);
133
134         setsize (gib, '-8 -8 -8', '8 8 8');
135
136         gib.draw = Gib_Draw;
137         if(destroyontouch)
138                 gib.move_touch = Gib_Touch;
139         else
140                 gib.move_touch = SUB_RemoveOnNoImpact;
141
142         // don't spawn gibs inside solid - just don't
143         if(org != safeorg)
144         {
145                 tracebox(safeorg, gib.mins, gib.maxs, org, MOVE_NOMONSTERS, gib);
146                 org = trace_endpos;
147         }
148
149         gib.move_origin = org;
150         setorigin(gib, org);
151         gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
152         gib.move_avelocity = prandomvec() * vlen(gib.move_velocity) * autocvar_cl_gibs_avelocity_scale;
153         gib.move_time = time;
154         gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
155
156         gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
157         gib.drawmask = MASK_NORMAL;
158
159         RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
160 }
161
162 void Ent_GibSplash(bool isNew)
163 {SELFPARAM();
164         int amount, type, specnum;
165         vector org, vel;
166         string specstr;
167         bool issilent;
168         string gentle_prefix = "morphed_";
169
170         float randomvalue;
171         int c;
172
173         type = ReadByte(); // gibbage type
174         amount = ReadByte() / 16.0; // gibbage amount
175         org.x = ReadShort() * 4 + 2;
176         org.y = ReadShort() * 4 + 2;
177         org.z = ReadShort() * 4 + 2;
178         vel = decompressShortVector(ReadShort());
179
180         float cl_gentle_gibs = autocvar_cl_gentle_gibs;
181         if(cl_gentle_gibs || autocvar_cl_gentle)
182                 type |= 0x80; // set gentle bit
183
184         if(type & 0x80)
185         {
186                 if(cl_gentle_gibs == 2)
187                         gentle_prefix = "";
188                 else if(cl_gentle_gibs == 3)
189                         gentle_prefix = "happy_";
190         }
191         else if(autocvar_cl_particlegibs)
192         {
193                 type |= 0x80;
194                 gentle_prefix = "particlegibs_";
195         }
196
197         if (!(cl_gentle_gibs || autocvar_cl_gentle))
198                 amount *= 1 - autocvar_cl_nogibs;
199
200         if(autocvar_ekg)
201                 amount *= 5;
202
203         if(amount <= 0 || !isNew)
204                 return;
205
206         setorigin(self, org); // for the sounds
207
208         specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
209         issilent = (type & 0x40);
210         type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
211         specstr = species_prefix(specnum);
212
213         switch(type)
214         {
215                 case 0x01:
216                         if(!issilent)
217                                 sound (self, CH_PAIN, SND_GIB, VOL_BASE, ATTEN_NORM);
218
219                         if(prandom() < amount)
220                                 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
221                         new_te_bloodshower(_particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
222                         if(prandom() < amount)
223                                 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
224
225                         for(c = 0; c < amount; ++c)
226                         {
227                                 randomvalue = amount - c;
228
229                                 if(prandom() < randomvalue)
230                                         TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
231                                 if(prandom() < randomvalue)
232                                         TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
233                                 if(prandom() < randomvalue)
234                                         TossGib ("models/gibs/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
235                                 if(prandom() < randomvalue)
236                                         TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
237                                 if(prandom() < randomvalue)
238                                         TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
239                                 if(prandom() < randomvalue)
240                                         TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
241
242                                 // these splat on impact
243                                 if(prandom() < randomvalue)
244                                         TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
245                                 if(prandom() < randomvalue)
246                                         TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
247                                 if(prandom() < randomvalue)
248                                         TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
249                                 if(prandom() < randomvalue)
250                                         TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
251                         }
252                         break;
253                 case 0x02:
254                         pointparticles(_particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
255                         break;
256                 case 0x03:
257                         if(prandom() < amount)
258                                 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
259                         break;
260                 case 0x81:
261                         pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
262                         break;
263                 case 0x82:
264                         pointparticles(_particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
265                         break;
266                 case 0x83:
267                         // no gibs in gentle mode, sorry
268                         break;
269         }
270 }