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