[NOT FOR 2.5.2] better gibs for robots (yes, by you-know-who)
[divverent/nexuiz.git] / data / 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_ANIMAL:      return "animal_";
17                 case SPECIES_RESERVED:    return "reserved_";
18                 default:         return "";
19         }
20 }
21
22 void Gib_setmodel(entity gib, string mdlname, float specnum)
23 {
24         switch(specnum)
25         {
26                 case SPECIES_ROBOT_RUSTY:
27                 case SPECIES_ROBOT_SHINY:
28                         if(mdlname == "models/gibs/bloodyskull.md3")
29                                 setmodel(gib, "models/gibs/robo.md3");
30                         else
31                                 setmodel(gib, strcat("models/gibs/robo", ftos(floor(random() * 8) + 1), ".md3"));
32                         if(specnum == SPECIES_ROBOT_SHINY)
33                         {
34                                 gib.skin = 1;
35                                 gib.colormod = '2 2 2';
36                         }
37                         gib.scale = 2;
38                         break;
39                 default:
40                         setmodel(gib, mdlname);
41                         gib.skin = specnum;
42                         break;
43         }
44 }
45
46 void new_te_bloodshower (float ef, vector org, float explosionspeed, float howmany)
47 {
48         float i, pmod;
49         pmod = cvar("cl_particles_quality");
50         for (i = 0; i < 250 * pmod; ++i)
51                 pointparticles(ef, org, randomvec() * explosionspeed, howmany / 250);
52 }
53
54 void SUB_RemoveOnNoImpact()
55 {
56         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
57                 Gib_Delete();
58 }
59
60 void Gib_Touch()
61 {
62         // TODO maybe bounce of walls, make more gibs, etc.
63
64         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
65         {
66                 Gib_Delete();
67                 return;
68         }
69
70         if(!self.silent)
71                 sound(self, CHAN_PAIN, strcat("misc/gib_splat0", ftos(floor(prandom() * 4 + 1)), ".wav"), VOL_BASE, ATTN_NORM);
72         pointparticles(particleeffectnum(strcat(species_prefix(self.cnt), "blood")), self.origin + '0 0 1', '0 0 30', 10);
73
74         Gib_Delete();
75 }
76
77 void Gib_Draw()
78 {
79         vector oldorg;
80         oldorg = self.origin;
81
82         Movetype_Physics_NoMatchServer();
83         if(wasfreed(self))
84                 return;
85
86         if(self.touch == Gib_Touch) // don't do this for the "chunk" thingie...
87                 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_SLIGHTBLOOD")), oldorg, self.origin);
88         else
89                 trailparticles(self, particleeffectnum(strcat(species_prefix(self.cnt), "TR_BLOOD")), oldorg, self.origin);
90
91         self.renderflags = 0;
92         self.alpha = bound(0, self.nextthink - time, 1);
93
94         if(self.alpha < ALPHA_MIN_VISIBLE)
95                 Gib_Delete();
96         else
97                 R_AddEntity(self);
98 }
99
100 void TossGib (string mdlname, vector org, vector vconst, vector vrand, float specnum, float destroyontouch, float issilent)
101 {
102         entity gib;
103
104         // TODO remove some gibs according to cl_nogibs
105         gib = RubbleNew("gib");
106         gib.move_movetype = MOVETYPE_BOUNCE;
107         gib.gravity = 1;
108         gib.solid = SOLID_CORPSE;
109         gib.cnt = specnum;
110         gib.silent = issilent;
111         Gib_setmodel(gib, mdlname, specnum);
112
113         setsize (gib, '-8 -8 -8', '8 8 8');
114
115         gib.draw = Gib_Draw;
116         if(destroyontouch)
117                 gib.move_touch = Gib_Touch;
118         else
119                 gib.move_touch = SUB_RemoveOnNoImpact;
120
121         gib.move_origin = gib.origin = org;
122         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");
123         gib.move_avelocity = prandomvec() * vlen(gib.move_velocity);
124         gib.move_time = time;
125         gib.damageforcescale = cvar_or("cl_gibs_damageforcescale", 3.5);
126
127         gib.nextthink = time + cvar_or("cl_gibs_lifetime", 14) * (1 + prandom() * 0.15);
128
129         RubbleLimit("gib", cvar_or("cl_gibs_maxcount",100), Gib_Delete);
130 }
131
132 void Ent_GibSplash()
133 {
134         float amount, type, specnum;
135         vector org, vel;
136         string specstr;
137         float issilent;
138         string gentle_prefix;
139
140         float c, randomvalue;
141
142         type = ReadByte(); // gibbage type
143         amount = ReadByte() / 16.0; // gibbage amount
144         org_x = ReadShort() * 4 + 2;
145         org_y = ReadShort() * 4 + 2;
146         org_z = ReadShort() * 4 + 2;
147         vel = decompressShortVector(ReadShort());
148
149         if(cvar("cl_gentle"))
150                 type |= 0x80; // set gentle bit
151
152         if(type & 0x80)
153         {
154                 if(cvar("cl_gentle") > 1)
155                         gentle_prefix = "";
156                 else
157                         gentle_prefix = "morphed_";
158         }
159         else if(cvar("cl_particlegibs"))
160         {
161                 type |= 0x80;
162                 gentle_prefix = "particlegibs_";
163         }
164
165         if not(cvar("cl_gentle"))
166                 amount *= 1 - cvar("cl_nogibs");
167
168         if(cvar("ekg"))
169                 amount *= 5;
170
171         if(amount <= 0)
172                 return;
173
174         self.origin = org; // for the sounds
175
176         specnum = (type & 0x78) / 8; // blood/gibmodel type: using four bits (0..7, bit indexes 3,4,5)
177         issilent = (type & 0x40);
178         type = type & 0x87; // remove the species bits: bit 7 = gentle, bit 0,1,2 = kind of gib
179         specstr = species_prefix(specnum);
180
181         switch(type)
182         {
183                 case 0x01:
184                         if(!issilent)
185                                 sound (self, CHAN_PAIN, "misc/gib.wav", VOL_BASE, ATTN_NORM);
186
187                         if(prandom() < amount)
188                                 TossGib ("models/gibs/eye.md3", org, vel, prandomvec() * 150, specnum, 0, issilent);
189                         new_te_bloodshower(particleeffectnum(strcat(specstr, "bloodshower")), org, 1200, amount);
190                         if(prandom() < amount)
191                                 TossGib ("models/gibs/bloodyskull.md3", org + 16 * prandomvec(), vel, prandomvec() * 100, specnum, 0, issilent);
192
193                         for(c = 0; c < amount; ++c)
194                         {
195                                 randomvalue = amount - c;
196
197                                 if(prandom() < randomvalue)
198                                         TossGib ("models/gibs/arm.md3", org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
199                                 if(prandom() < randomvalue)
200                                         TossGib ("models/gibs/arm.md3", org + 16 * prandomvec() + '0 0 8', vel, prandomvec() * (prandom() * 120 + 90), specnum,0, issilent);
201                                 if(prandom() < randomvalue)
202                                         TossGib ("models/gibs/chest.md3", org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
203                                 if(prandom() < randomvalue)
204                                         TossGib ("models/gibs/smallchest.md3", org + 16 * prandomvec(), vel, prandomvec() * (prandom() * 120 + 80), specnum,0, issilent);
205                                 if(prandom() < randomvalue)
206                                         TossGib ("models/gibs/leg1.md3", org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
207                                 if(prandom() < randomvalue)
208                                         TossGib ("models/gibs/leg2.md3", org + 16 * prandomvec() + '0 0 -5', vel, prandomvec() * (prandom() * 120 + 85), specnum,0, issilent);
209
210                                 // these splat on impact
211                                 if(prandom() < randomvalue)
212                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
213                                 if(prandom() < randomvalue)
214                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
215                                 if(prandom() < randomvalue)
216                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
217                                 if(prandom() < randomvalue)
218                                         TossGib ("models/gibs/chunk.mdl", org + 16 * prandomvec(), vel, prandomvec() * 450, specnum,1, issilent);
219                         }
220                         break;
221                 case 0x02:
222                         pointparticles(particleeffectnum(strcat(specstr, "blood")), org, vel, amount * 16);
223                         break;
224                 case 0x03:
225                         if(prandom() < amount)
226                                 TossGib ("models/gibs/chunk.mdl", org, vel, prandomvec() * (prandom() * 30 + 20), specnum, 1, issilent); // TODO maybe adjust to more randomization?
227                         break;
228                 case 0x81:
229                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_dissolve")), org, vel, amount);
230                         break;
231                 case 0x82:
232                         pointparticles(particleeffectnum(strcat(gentle_prefix, "damage_hit")), org, vel, amount * 16);
233                         break;
234                 case 0x83:
235                         // no gibs in gentle mode, sorry
236                         break;
237         }
238 }
239
240 void GibSplash_Precache()
241 {
242         precache_model("models/gibs/chunk.mdl");
243         precache_model("models/gibs/leg1.md3");
244         precache_model("models/gibs/leg2.md3");
245         precache_model("models/gibs/chest.md3");
246         precache_model("models/gibs/smallchest.md3");
247         precache_model("models/gibs/arm.md3");
248         precache_model("models/gibs/bloodyskull.md3");
249         precache_model("models/gibs/eye.md3");
250
251         precache_model("models/gibs/robo.md3");
252         precache_model("models/gibs/robo1.md3");
253         precache_model("models/gibs/robo2.md3");
254         precache_model("models/gibs/robo3.md3");
255         precache_model("models/gibs/robo4.md3");
256         precache_model("models/gibs/robo5.md3");
257         precache_model("models/gibs/robo6.md3");
258         precache_model("models/gibs/robo7.md3");
259         precache_model("models/gibs/robo8.md3");
260
261         precache_sound ("misc/gib.wav");
262     precache_sound ("misc/gib_splat01.wav");
263     precache_sound ("misc/gib_splat02.wav");
264     precache_sound ("misc/gib_splat03.wav");
265     precache_sound ("misc/gib_splat04.wav");
266 }