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