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