]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/damage.qc
font fix for accuracy stats screen
[divverent/nexuiz.git] / data / qcsrc / client / damage.qc
1 .float silent;
2
3 void Ent_DamageInfo()
4 {
5         float hittype, dmg, rad, edge, thisdmg, forcemul;
6         float issilent;
7         vector force, org, thisforce;
8         entity oldself;
9
10         oldself = self;
11
12         hittype = ReadShort();
13
14         issilent = (hittype & 0x8000);
15         hittype = (hittype & 0x7FFF);
16
17         org_x = ReadCoord();
18         org_y = ReadCoord();
19         org_z = ReadCoord();
20
21         dmg = ReadByte();
22         rad = ReadByte();
23         edge = ReadByte();
24         force = decompressShortVector(ReadShort());
25
26         if(rad < 0)
27         {
28                 rad = -rad;
29                 forcemul = -1;
30         }
31         else
32                 forcemul = 1;
33
34         for(self = findradius(org, rad); self; self = self.chain)
35         {
36                 if(rad)
37                 {
38                         thisdmg = vlen(self.origin - org) / rad;
39                         if(thisdmg >= 1)
40                                 continue;
41                         if(dmg)
42                         {
43                                 thisdmg = dmg + (edge - dmg) * thisdmg;
44                                 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - org);
45                         }
46                         else
47                         {
48                                 thisdmg = 0;
49                                 thisforce = forcemul * vlen(force) * normalize(self.origin - org);
50                         }
51                 }
52                 else
53                 {
54                         thisdmg = dmg;
55                         thisforce = forcemul * force;
56                 }
57
58                 //print("check ", ftos(num_for_edict(self)), " ", self.classname, "\n");
59                 //print(ftos(self.damageforcescale), "\n");
60                 //print(vtos(thisforce), "\n");
61                 if(self.damageforcescale)
62                         if(vlen(thisforce))
63                         {
64                                 self.move_velocity = self.move_velocity + self.damageforcescale * thisforce;
65                                 self.move_flags &~= FL_ONGROUND;
66                                 //print("pushed ", ftos(num_for_edict(self)), " loose\n");
67                         }
68
69                 if(issilent)
70                         self.silent = 1;
71
72                 if(self.event_damage)
73                         self.event_damage(thisdmg, hittype, org, thisforce);
74         }
75
76         self = oldself;
77
78         // TODO spawn particle effects and sounds based on hittype
79         
80         if(!DEATH_ISSPECIAL(hittype))
81         {
82                 float hitwep, secondary, bounce, headshot;
83                 vector org2, backoff;
84                 float r;
85
86                 hitwep = DEATH_WEAPONOFWEAPONDEATH(hittype);
87                 secondary = hittype & HITTYPE_SECONDARY;
88                 bounce = hittype & HITTYPE_BOUNCE;
89                 headshot = hittype & HITTYPE_HEADSHOT;
90                 r = prandom();
91
92                 traceline(org - normalize(force) * 16, org + normalize(force) * 16, MOVE_NOMONSTERS, world);
93                 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
94                         backoff = trace_plane_normal;
95                 else
96                         backoff = -1 * normalize(force);
97
98                 setorigin(self, org + backoff * 2); // for sound() calls
99
100                 switch(hitwep)
101                 {
102                         case WEP_LASER:
103                                 org2 = org + backoff * 6;
104                                 pointparticles(particleeffectnum("laser_impact"), org2, backoff * 1000, 1);
105                                 if(!issilent)
106                                         sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
107                                 break;
108                         case WEP_SHOTGUN:
109                                 org2 = org + backoff * 2;
110                                 pointparticles(particleeffectnum("shotgun_impact"), org2, backoff * 1000, 1);
111                                 if(!issilent)
112                                 {
113                                         if(r < 0.05)
114                                                 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
115                                         else if(r < 0.1)
116                                                 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
117                                         else if(r < 0.2)
118                                                 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
119                                 }
120                                 break;
121                         case WEP_UZI:
122                                 org2 = org + backoff * 2;
123                                 pointparticles(particleeffectnum("machinegun_impact"), org2, backoff * 1000, 1);
124                                 if(!issilent)
125                                         if(r < 0.05)
126                                                 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
127                                         else if(r < 0.1)
128                                                 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
129                                         else if(r < 0.2)
130                                                 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
131                                 break;
132                         case WEP_GRENADE_LAUNCHER:
133                                 org2 = org + backoff * 12;
134                                 pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
135                                 if(!issilent)
136                                         sound(self, CHAN_PROJECTILE, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
137                                 break;
138                         case WEP_ELECTRO:
139                                 org2 = org + backoff * 6;
140                                 if(secondary)
141                                 {
142                                         pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
143                                         if(!issilent)
144                                                 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
145                                 }
146                                 else
147                                 {
148                                         if(bounce)
149                                         {
150                                                 // this is sent as "primary bounce" to distinguish it from secondary bounced balls
151                                                 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
152                                                 if(!issilent)
153                                                         sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
154                                         }
155                                         else
156                                         {
157                                                 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
158                                                 if(!issilent)
159                                                         sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
160                                         }
161                                 }
162                                 break;
163                         case WEP_CRYLINK:
164                                 org2 = org + backoff * 2;
165                                 if(secondary)
166                                 {
167                                         pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
168                                         if(!issilent)
169                                                 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
170                                 }
171                                 else
172                                 {
173                                         pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
174                                         if(!issilent)
175                                                 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
176                                 }
177                                 break;
178                         case WEP_NEX:
179                                 org2 = org + backoff * 6;
180                                 pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
181                                 if(!issilent)
182                                         sound(self, CHAN_PROJECTILE, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
183                                 break;
184                         case WEP_HAGAR:
185                                 org2 = org + backoff * 6;
186                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
187                                 if(!issilent)
188                                 {
189                                         if (r<0.15)
190                                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
191                                         else if (r<0.7)
192                                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
193                                         else
194                                                 sound(self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
195                                 }
196                                 break;
197                         case WEP_ROCKET_LAUNCHER:
198                                 org2 = org + backoff * 12;
199                                 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
200                                 if(!issilent)
201                                         sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
202                                 break;
203                         case WEP_PORTO:
204                                 print("Since when does Porto send DamageInfo?\n");
205                                 break;
206                         case WEP_MINSTANEX:
207                                 org2 = org + backoff * 6;
208                                 pointparticles(particleeffectnum("nex_impact"), org2, '0 0 0', 1);
209                                 if(!issilent)
210                                         sound(self, CHAN_PROJECTILE, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
211                                 break;
212                         case WEP_HOOK:
213                                 org2 = org + backoff * 2;
214                                 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
215                                 if(!issilent)
216                                         sound(self, CHAN_PROJECTILE, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
217                                 break;
218                         case WEP_HLAC:
219                                 org2 = org + backoff * 6;
220                                 pointparticles(particleeffectnum("laser_impact"), org2, backoff * 1000, 1);
221                                 if(!issilent)
222                                         sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
223                                 break;
224                         case WEP_CAMPINGRIFLE:
225                                 org2 = org + backoff * 2;
226                                 pointparticles(particleeffectnum("machinegun_impact"), org2, backoff * 1000, 1);
227                                 if(!issilent)
228                                 {
229                                         if(r < 0.2)
230                                                 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
231                                         else if(r < 0.4)
232                                                 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
233                                         else if(r < 0.5)
234                                                 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
235                                 }
236                                 break;
237                         case WEP_TUBA:
238                                 break;
239                         case WEP_FIREBALL:
240                                 if(secondary)
241                                 {
242                                         org2 = org + backoff * 16;
243                                         pointparticles(particleeffectnum("fireball_explode"), org2, '0 0 0', 1);
244                                         if(!issilent)
245                                                 sound(self, CHAN_PROJECTILE, "weapons/fireball_impact2.wav", VOL_BASE, ATTN_NORM * 0.25); // long range boom
246                                 }
247                                 else
248                                 {
249                                         // firemine goes out silently
250                                 }
251                                 break;
252                         default:
253                                 dprint("Unhandled damage of weapon ", ftos(hitwep), "\n");
254                                 break;
255                 }
256         }
257 }
258
259 void DamageInfo_Precache()
260 {
261         precache_sound("weapons/crylink_impact2.wav");
262         precache_sound("weapons/crylink_impact.wav");
263         precache_sound("weapons/electro_impact.wav");
264         precache_sound("weapons/electro_impact_combo.wav");
265         precache_sound("weapons/grenade_impact.wav");
266         precache_sound("weapons/hagexp1.wav");
267         precache_sound("weapons/hagexp2.wav");
268         precache_sound("weapons/hagexp3.wav");
269         precache_sound("weapons/flacexp1.wav");
270         precache_sound("weapons/flacexp2.wav");
271         precache_sound("weapons/flacexp3.wav");
272         precache_sound("weapons/hookbomb_impact.wav");
273         precache_sound("weapons/laserimpact.wav");
274         precache_sound("weapons/neximpact.wav");
275         precache_sound("weapons/ric1.wav");
276         precache_sound("weapons/ric2.wav");
277         precache_sound("weapons/ric3.wav");
278         precache_sound("weapons/rocket_impact.wav");
279         precache_sound("weapons/fireball_impact.wav");
280         precache_sound("weapons/fireball_impact2.wav");
281 }