]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/gibs.qc
prandom() - an attempt to make random decisions predictable (not sure if it actually...
[divverent/nexuiz.git] / data / qcsrc / client / gibs.qc
1 void SUB_RemoveOnNoImpact()
2 {
3         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
4                 remove(self);
5 }
6
7 void Gib_Touch()
8 {
9         // TODO maybe bounce of walls, make more gibs, etc.
10
11         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
12         {
13                 remove(self);
14                 return;
15         }
16         
17         sound(self, CHAN_PAIN, strcat("misc/gib_splat0", ftos(floor(prandom() * 4 + 1)), ".wav"), VOL_BASE, ATTN_NORM);
18         pointparticles(particleeffectnum("blood"), self.origin + '0 0 1', '0 0 30', 10);
19
20         remove(self);
21 }
22
23 void Gib_Draw()
24 {
25         vector oldorg;
26         oldorg = self.origin;
27
28         Movetype_Physics(FALSE);
29         
30         if(self.touch == Gib_Touch) // don't do this for the "chunk" thingie...
31                 trailparticles(self, particleeffectnum("TR_SLIGHTBLOOD"), oldorg, self.origin);
32         else
33                 trailparticles(self, particleeffectnum("TR_BLOOD"), oldorg, self.origin);
34
35         self.renderflags = 0;
36         self.alpha = bound(0, self.nextthink - time, 1);
37
38         if(self.alpha == 0)
39                 remove(self);
40         else
41                 R_AddEntity(self);
42 }
43
44 void TossGib (string mdlname, vector org, vector v, float destroyontouch)
45 {
46         entity gib;
47
48         // TODO remove some gibs according to cl_nogibs
49         
50         gib = spawn();
51         gib.classname = "gib";
52         gib.move_movetype = MOVETYPE_BOUNCE;
53         gib.gravity = 1;
54         gib.solid = SOLID_CORPSE;
55
56         setmodel (gib, mdlname); // precision set above
57
58         setsize (gib, '-8 -8 -8', '8 8 8');
59
60         gib.draw = Gib_Draw;
61         if(destroyontouch)
62                 gib.move_touch = Gib_Touch;
63         else
64                 gib.move_touch = SUB_RemoveOnNoImpact;
65
66         gib.move_origin = gib.origin = org;
67         gib.move_velocity = v + randomvec();
68         gib.move_avelocity = randomvec() * vlen(gib.move_velocity);
69         gib.move_time = time;
70         gib.damageforcescale = 3.5;
71
72         gib.nextthink = time + 12 + prandom () * 4;
73 }
74
75 void Ent_GibSplash()
76 {
77         float amount, type;
78         vector org, vel, mi, ma;
79
80         float c, gibfactor, randomvalue;
81
82         type = ReadByte(); // gibbage type
83         amount = ReadByte() / 16.0; // gibbage amount
84         org_x = ReadShort() * 4 + 2;
85         org_y = ReadShort() * 4 + 2;
86         org_z = ReadShort() * 4 + 2;
87         vel = decompressShortVector(ReadShort());
88         mi = decompressShortVector(ReadShort());
89         ma = decompressShortVector(ReadShort());
90
91         if(cvar("cl_gentle"))
92                 type |= 0x80; // set gentle bit
93
94         gibfactor = 1 - cvar("cl_nogibs");
95         if(gibfactor <= 0)
96                 return;
97         
98         amount *= gibfactor;
99
100         if(cvar("ekg"))
101                 amount *= 5;
102         
103         self.origin = org; // for the sounds
104
105         switch(type)
106         {
107                 case 0x01:
108                         sound (self, CHAN_PAIN, "misc/gib.wav", VOL_BASE, ATTN_NORM);
109
110                         if(prandom() < amount)
111                                 TossGib("models/gibs/eye.md3", org, vel + randomvec() * 150, 0);
112                         te_bloodshower(org + mi, org + ma, 1200, 1000 * amount);
113                         if(prandom() < amount)
114                                 TossGib("models/gibs/bloodyskull.md3", org, vel + randomvec() * 100, 0);
115
116                         for(c = 0; c < amount; ++c)
117                         {
118                                 randomvalue = amount - c;
119                                         
120                                 if(prandom() < randomvalue)
121                                         TossGib ("models/gibs/arm.md3", org, vel + randomvec() * (prandom() * 120 + 90),0);
122                                 if(prandom() < randomvalue)
123                                         TossGib ("models/gibs/arm.md3", org, vel + randomvec() * (prandom() * 120 + 90),0);
124                                 if(prandom() < randomvalue)
125                                         TossGib ("models/gibs/chest.md3", org + '0 0 -12', vel + randomvec() * (prandom() * 120 + 80),0);
126                                 if(prandom() < randomvalue)
127                                         TossGib ("models/gibs/smallchest.md3", org, vel + randomvec() * (prandom() * 120 + 80),0);
128                                 if(prandom() < randomvalue)
129                                         TossGib ("models/gibs/leg1.md3", org + '0 0 -5', vel + randomvec() * (prandom() * 120 + 85),0);
130                                 if(prandom() < randomvalue)
131                                         TossGib ("models/gibs/leg2.md3", org + '0 0 -9', vel + randomvec() * (prandom() * 120 + 85),0);
132
133                                 // these splat on impact
134                                 if(prandom() < randomvalue)
135                                         TossGib ("models/gibs/chunk.mdl", org, vel + randomvec() * 450,1);
136                                 if(prandom() < randomvalue)
137                                         TossGib ("models/gibs/chunk.mdl", org, vel + randomvec() * 450,1);
138                                 if(prandom() < randomvalue)
139                                         TossGib ("models/gibs/chunk.mdl", org, vel + randomvec() * 450,1);
140                                 if(prandom() < randomvalue)
141                                         TossGib ("models/gibs/chunk.mdl", org, vel + randomvec() * 450,1);
142                         }
143                         break;
144                 case 0x02:
145                         pointparticles(particleeffectnum("blood"), org, vel, amount * 16);
146                         break;
147                 case 0x03:
148                         if(prandom() < amount)
149                                 TossGib ("models/gibs/chunk.mdl", org, vel, 1);
150                         break;
151                 case 0x81:
152                         pointparticles(particleeffectnum("damage_dissolve"), org, vel, amount);
153                         break;
154                 case 0x82:
155                         pointparticles(particleeffectnum("damage_hit"), org, vel, amount * 16);
156                         break;
157                 case 0x83:
158                         // no gibs in gentle mode, sorry
159                         break;
160         }
161 }
162
163 void GibSplash_Precache()
164 {
165         precache_model("models/gibs/chunk.mdl");
166         precache_model("models/gibs/leg1.md3");
167         precache_model("models/gibs/leg2.md3");
168         precache_model("models/gibs/chest.md3");
169         precache_model("models/gibs/smallchest.md3");
170         precache_model("models/gibs/arm.md3");
171         precache_model("models/gibs/bloodyskull.md3");
172         precache_model("models/gibs/eye.md3");
173
174         precache_sound ("misc/gib.wav");
175     precache_sound ("misc/gib_splat01.wav");
176     precache_sound ("misc/gib_splat02.wav");
177     precache_sound ("misc/gib_splat03.wav");
178     precache_sound ("misc/gib_splat04.wav");
179 }