]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/gibs.qc
Remove arena gamemode
[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, ATTEN_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 = org;
142         setorigin(gib, org);
143         gib.move_velocity = vconst * autocvar_cl_gibs_velocity_scale + vrand * autocvar_cl_gibs_velocity_random + '0 0 1' * autocvar_cl_gibs_velocity_up;
144         gib.move_avelocity = prandomvec() * vlen(gib.move_velocity) * autocvar_cl_gibs_avelocity_scale;
145         gib.move_time = time;
146         gib.damageforcescale = autocvar_cl_gibs_damageforcescale;
147
148         gib.nextthink = time + autocvar_cl_gibs_lifetime * (1 + prandom() * 0.15);
149         gib.drawmask = MASK_NORMAL;
150
151         RubbleLimit("gib", autocvar_cl_gibs_maxcount, Gib_Delete);
152 }
153
154 void Ent_GibSplash(float isNew)
155 {
156         float amount, type, specnum;
157         vector org, vel;
158         string specstr;
159         float issilent;
160         string gentle_prefix = "morphed_";
161
162         float c, randomvalue;
163
164         type = ReadByte(); // gibbage type
165         amount = ReadByte() / 16.0; // gibbage amount
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         }
182         else if(autocvar_cl_particlegibs)
183         {
184                 type |= 0x80;
185                 gentle_prefix = "particlegibs_";
186         }
187
188         if not(cl_gentle_gibs || autocvar_cl_gentle)
189                 amount *= 1 - autocvar_cl_nogibs;
190
191         if(autocvar_ekg)
192                 amount *= 5;
193
194         if(amount <= 0 || !isNew)
195                 return;
196
197         setorigin(self, org); // for the sounds
198
199         specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
200         issilent = (type & 0x40);
201         type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
202         specstr = species_prefix(specnum);
203
204         switch(type)
205         {
206                 case 0x01:
207                         if(!issilent)
208                                 sound (self, CH_PAIN, "misc/gib.wav", VOL_BASE, ATTEN_NORM);
209
210                         if(prandom() < amount)
211                                 TossGib ("models/gibs/eye.md3", org, org, vel, prandomvec() * 150, specnum, 0, issilent);
212                         new_te_bloodshower(particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
213                         if(prandom() < amount)
214                                 TossGib ("models/gibs/bloodyskull.md3", org, org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
215
216                         for(c = 0; c < amount; ++c)
217                         {
218                                 randomvalue = amount - c;
219
220                                 if(prandom() < randomvalue)
221                                         TossGib ("models/gibs/arm.md3", org, org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
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/chest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
226                                 if(prandom() < randomvalue)
227                                         TossGib ("models/gibs/smallchest.md3", org, org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
228                                 if(prandom() < randomvalue)
229                                         TossGib ("models/gibs/leg1.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
230                                 if(prandom() < randomvalue)
231                                         TossGib ("models/gibs/leg2.md3", org, org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
232
233                                 // these splat on impact
234                                 if(prandom() < randomvalue)
235                                         TossGib ("models/gibs/chunk.mdl", org, org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
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                         }
243                         break;
244                 case 0x02:
245                         pointparticles(particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
246                         break;
247                 case 0x03:
248                         if(prandom() < amount)
249                                 TossGib ("models/gibs/chunk.mdl", org, org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
250                         break;
251                 case 0x81:
252                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
253                         break;
254                 case 0x82:
255                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
256                         break;
257                 case 0x83:
258                         // no gibs in gentle mode, sorry
259                         break;
260         }
261 }
262
263 void GibSplash_Precache()
264 {
265         precache_model("models/gibs/chunk.mdl");
266         precache_model("models/gibs/leg1.md3");
267         precache_model("models/gibs/leg2.md3");
268         precache_model("models/gibs/chest.md3");
269         precache_model("models/gibs/smallchest.md3");
270         precache_model("models/gibs/arm.md3");
271         precache_model("models/gibs/bloodyskull.md3");
272         precache_model("models/gibs/eye.md3");
273
274         precache_model("models/gibs/robo.md3");
275         precache_model("models/gibs/robo1.md3");
276         precache_model("models/gibs/robo2.md3");
277         precache_model("models/gibs/robo3.md3");
278         precache_model("models/gibs/robo4.md3");
279         precache_model("models/gibs/robo5.md3");
280         precache_model("models/gibs/robo6.md3");
281         precache_model("models/gibs/robo7.md3");
282         precache_model("models/gibs/robo8.md3");
283
284         precache_sound ("misc/gib.wav");
285     precache_sound ("misc/gib_splat01.wav");
286     precache_sound ("misc/gib_splat02.wav");
287     precache_sound ("misc/gib_splat03.wav");
288     precache_sound ("misc/gib_splat04.wav");
289 }