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