]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/gibs.qc
Merge remote branch 'refs/remotes/origin/divVerent/mapinfo-cleanup'
[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 = cvar("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                 Gib_Delete();
101         else
102                 R_AddEntity(self);
103 }
104
105 void TossGib (string mdlname, vector org, vector vconst, vector vrand, float specnum, float destroyontouch, float issilent)
106 {
107         entity gib;
108
109         // TODO remove some gibs according to cl_nogibs
110         gib = RubbleNew("gib");
111         gib.move_movetype = MOVETYPE_BOUNCE;
112         gib.gravity = 1;
113         gib.solid = SOLID_CORPSE;
114         gib.cnt = specnum;
115         gib.silent = issilent;
116         Gib_setmodel(gib, mdlname, specnum);
117
118         setsize (gib, '-8 -8 -8', '8 8 8');
119
120         gib.draw = Gib_Draw;
121         if(destroyontouch)
122                 gib.move_touch = Gib_Touch;
123         else
124                 gib.move_touch = SUB_RemoveOnNoImpact;
125
126         gib.move_origin = gib.origin = org;
127         gib.move_velocity = vconst * cvar_or("cl_gibs_velocity_scale", 1) + vrand * cvar_or("cl_gibs_velocity_random", 1) + '0 0 1' * cvar("cl_gibs_velocity_up");
128         gib.move_avelocity = prandomvec() * vlen(gib.move_velocity);
129         gib.move_time = time;
130         gib.damageforcescale = cvar_or("cl_gibs_damageforcescale", 3.5);
131
132         gib.nextthink = time + cvar_or("cl_gibs_lifetime", 14) * (1 + prandom() * 0.15);
133
134         RubbleLimit("gib", cvar_or("cl_gibs_maxcount",100), Gib_Delete);
135 }
136
137 void Ent_GibSplash(float isNew)
138 {
139         float amount, type, specnum;
140         vector org, vel;
141         string specstr;
142         float issilent;
143         string gentle_prefix;
144
145         float c, randomvalue;
146
147         type = ReadByte(); // gibbage type
148         amount = ReadByte() / 16.0; // gibbage amount
149         org_x = ReadShort() * 4 + 2;
150         org_y = ReadShort() * 4 + 2;
151         org_z = ReadShort() * 4 + 2;
152         vel = decompressShortVector(ReadShort());
153
154         if(cvar("cl_gentle_gibs") || cvar("cl_gentle"))
155                 type |= 0x80; // set gentle bit
156
157         if(type & 0x80)
158         {
159                 if(cvar("cl_gentle_gibs") == 2)
160                         gentle_prefix = "";
161                 else if(cvar("cl_gentle_gibs") == 3) 
162                         gentle_prefix = "happy_";
163                 else
164                         gentle_prefix = "morphed_";
165         }
166         else if(cvar("cl_particlegibs"))
167         {
168                 type |= 0x80;
169                 gentle_prefix = "particlegibs_";
170         }
171
172         if not(cvar("cl_gentle_gibs") || cvar("cl_gentle"))
173                 amount *= 1 - cvar("cl_nogibs");
174
175         if(cvar("ekg"))
176                 amount *= 5;
177
178         if(amount <= 0 || !isNew)
179                 return;
180
181         self.origin = org; // for the sounds
182
183         specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
184         issilent = (type & 0x40);
185         type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
186         specstr = species_prefix(specnum);
187
188         switch(type)
189         {
190                 case 0x01:
191                         if(!issilent)
192                                 sound (self, CHAN_PAIN, "misc/gib.wav", VOL_BASE, ATTN_NORM);
193
194                         if(prandom() < amount)
195                                 TossGib ("models/gibs/eye.md3", org, vel, prandomvec() * 150, specnum, 0, issilent);
196                         new_te_bloodshower(particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
197                         if(prandom() < amount)
198                                 TossGib ("models/gibs/bloodyskull.md3", org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
199
200                         for(c = 0; c < amount; ++c)
201                         {
202                                 randomvalue = amount - c;
203
204                                 if(prandom() < randomvalue)
205                                         TossGib ("models/gibs/arm.md3", org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
206                                 if(prandom() < randomvalue)
207                                         TossGib ("models/gibs/arm.md3", org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
208                                 if(prandom() < randomvalue)
209                                         TossGib ("models/gibs/chest.md3", org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
210                                 if(prandom() < randomvalue)
211                                         TossGib ("models/gibs/smallchest.md3", org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
212                                 if(prandom() < randomvalue)
213                                         TossGib ("models/gibs/leg1.md3", org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
214                                 if(prandom() < randomvalue)
215                                         TossGib ("models/gibs/leg2.md3", org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
216
217                                 // these splat on impact
218                                 if(prandom() < randomvalue)
219                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
220                                 if(prandom() < randomvalue)
221                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
222                                 if(prandom() < randomvalue)
223                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
224                                 if(prandom() < randomvalue)
225                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
226                         }
227                         break;
228                 case 0x02:
229                         pointparticles(particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
230                         break;
231                 case 0x03:
232                         if(prandom() < amount)
233                                 TossGib ("models/gibs/chunk.mdl", org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
234                         break;
235                 case 0x81:
236                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
237                         break;
238                 case 0x82:
239                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
240                         break;
241                 case 0x83:
242                         // no gibs in gentle mode, sorry
243                         break;
244         }
245 }
246
247 void GibSplash_Precache()
248 {
249         precache_model("models/gibs/chunk.mdl");
250         precache_model("models/gibs/leg1.md3");
251         precache_model("models/gibs/leg2.md3");
252         precache_model("models/gibs/chest.md3");
253         precache_model("models/gibs/smallchest.md3");
254         precache_model("models/gibs/arm.md3");
255         precache_model("models/gibs/bloodyskull.md3");
256         precache_model("models/gibs/eye.md3");
257
258         precache_model("models/gibs/robo.md3");
259         precache_model("models/gibs/robo1.md3");
260         precache_model("models/gibs/robo2.md3");
261         precache_model("models/gibs/robo3.md3");
262         precache_model("models/gibs/robo4.md3");
263         precache_model("models/gibs/robo5.md3");
264         precache_model("models/gibs/robo6.md3");
265         precache_model("models/gibs/robo7.md3");
266         precache_model("models/gibs/robo8.md3");
267
268         precache_sound ("misc/gib.wav");
269     precache_sound ("misc/gib_splat01.wav");
270     precache_sound ("misc/gib_splat02.wav");
271     precache_sound ("misc/gib_splat03.wav");
272     precache_sound ("misc/gib_splat04.wav");
273 }