]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/damage.qc
now all projectile hit effects are clientside
[divverent/nexuiz.git] / data / qcsrc / client / damage.qc
1 /*
2 ==================
3 findbetterlocation
4
5 Returns a point at least 12 units away from walls
6 (useful for explosion animations, although the blast is performed where it really happened)
7 Ripped from DPMod
8 ==================
9 */
10 vector findbetterlocation (vector org, float mindist)
11 {
12         vector loc, norm, norm2;
13         vector vec;
14         float c;
15         float h;
16
17         norm = '0 0 1';
18
19         vec = mindist * '1 0 0';
20         c = 0;
21         while (c < 6)
22         {
23                 traceline (org, org + vec, MOVE_WORLDONLY, world);
24                 vec = vec * -1;
25                 if (trace_fraction < 1)
26                 {
27                         loc = trace_endpos;
28                         norm2 = trace_plane_normal;
29                         traceline (loc, loc + vec, MOVE_WORLDONLY, world);
30                         if (trace_fraction >= 1)
31                         {
32                                 org = loc + vec;
33                                 norm = norm2;
34                         }
35                 }
36                 if (c & 1)
37                 {
38                         h = vec_y;
39                         vec_y = vec_x;
40                         vec_x = vec_z;
41                         vec_z = h;
42                 }
43                 c = c + 1;
44         }
45
46         trace_plane_normal = norm;
47
48         return org;
49 }
50
51 void Ent_DamageInfo()
52 {
53         float hittype, dmg, rad, edge, thisdmg;
54         vector force, org, thisforce;
55         entity oldself;
56
57         oldself = self;
58
59         hittype = ReadShort();
60         org_x = ReadCoord();
61         org_y = ReadCoord();
62         org_z = ReadCoord();
63
64         dmg = ReadByte();
65         rad = ReadByte();
66         edge = ReadByte();
67         force = decompressShortVector(ReadShort());
68
69         for(self = findradius(org, rad); self; self = self.chain)
70         {
71                 if(rad)
72                 {
73                         thisdmg = vlen(self.origin - org) / rad;
74                         if(thisdmg >= 1)
75                                 continue;
76                         thisdmg = dmg + (edge - dmg) * thisdmg;
77                         thisforce = vlen(force) * normalize(self.origin - org);
78                 }
79                 else
80                 {
81                         thisdmg = dmg;
82                         thisforce = force;
83                 }
84
85                 if(self.damageforcescale)
86                         if(vlen(thisforce))
87                         {
88                                 self.move_velocity = self.move_velocity + self.damageforcescale * thisforce;
89                                 self.move_flags &~= FL_ONGROUND;
90                         }
91
92                 if(self.event_damage)
93                         self.event_damage(thisdmg, hittype, org, thisforce);
94         }
95
96         self = oldself;
97
98         setorigin(self, org); // for sound() calls
99
100         // TODO spawn particle effects and sounds based on hittype
101         
102         if(!DEATH_ISSPECIAL(hittype))
103         {
104                 float hitwep, secondary, bounce, headshot;
105                 vector org2;
106                 float r;
107
108                 hitwep = DEATH_WEAPONOFWEAPONDEATH(hittype);
109                 secondary = hittype & HITTYPE_SECONDARY;
110                 bounce = hittype & HITTYPE_BOUNCE;
111                 headshot = hittype & HITTYPE_HEADSHOT;
112                 r = random();
113
114                 switch(hitwep)
115                 {
116                         case WEP_LASER:
117                                 org2 = findbetterlocation (org, 8);
118                                 pointparticles(particleeffectnum("laser_impact"), org2, trace_plane_normal * 1000, 1);
119                                 sound (self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
120                                 break;
121                         case WEP_SHOTGUN:
122                                 org2 = findbetterlocation (org, 2);
123                                 pointparticles(particleeffectnum("shotgun_impact"), org2, trace_plane_normal * 1000, 1);
124                                 break;
125                         case WEP_UZI:
126                                 org2 = findbetterlocation (org, 2);
127                                 pointparticles(particleeffectnum("machinegun_impact"), org2, trace_plane_normal * 1000, 1);
128                                 break;
129                         case WEP_GRENADE_LAUNCHER:
130                                 org2 = findbetterlocation (org, 12);
131                                 pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
132                                 sound (self, CHAN_PROJECTILE, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
133                                 break;
134                         case WEP_ELECTRO:
135                                 org2 = findbetterlocation (org, 8);
136                                 if(secondary)
137                                 {
138                                         sound (self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
139                                         pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
140                                 }
141                                 else
142                                 {
143                                         if(bounce)
144                                         {
145                                                 // this is sent as "primary bounce" to distinguish it from secondary bounced balls
146                                                 sound (self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
147                                                 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
148                                         }
149                                         else
150                                         {
151                                                 sound (self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
152                                                 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
153                                         }
154                                 }
155                         case WEP_CRYLINK:
156                                 if(secondary)
157                                 {
158                                         sound (self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
159                                         pointparticles(particleeffectnum("crylink_impact"), org, '0 0 0', 1);
160                                 }
161                                 else
162                                 {
163                                         sound (self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
164                                         pointparticles(particleeffectnum("crylink_impactbig"), org, '0 0 0', 1);
165                                 }
166                                 break;
167                         case WEP_NEX:
168                                 sound(self, CHAN_PROJECTILE, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
169                                 pointparticles(particleeffectnum("nex_impact"), org - normalize(force) * 6, '0 0 0', 1);
170                                 break;
171                         case WEP_HAGAR:
172                                 org2 = findbetterlocation (org, 12);
173                                 if (r<0.15)
174                                         sound (self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
175                                 else if (r<0.7)
176                                         sound (self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
177                                 else
178                                         sound (self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
179                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
180                                 break;
181                         case WEP_ROCKET_LAUNCHER:
182                                 org2 = findbetterlocation (org, 16);
183                                 sound (self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
184                                 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
185                                 break;
186                         case WEP_PORTO:
187                                 print("Since when does Porto send DamageInfo?\n");
188                                 break;
189                         case WEP_MINSTANEX:
190                                 sound(self, CHAN_PROJECTILE, "weapons/neximpact.wav", VOL_BASE, ATTN_NORM);
191                                 pointparticles(particleeffectnum("nex_impact"), org - normalize(force) * 6, '0 0 0', 1);
192                                 break;
193                         case WEP_HOOK:
194                                 org2 = findbetterlocation (org, 12);
195                                 sound (self, CHAN_PROJECTILE, "weapons/hookbomb_impact.wav", VOL_BASE, ATTN_NORM);
196                                 pointparticles(particleeffectnum("hookbomb_explode"), org2, '0 0 0', 1);
197                                 break;
198                         case WEP_SEEKER:
199                                 org2 = findbetterlocation (org, 12);
200                                 if(secondary)
201                                 {
202                                         if (r<0.15)
203                                                 sound (self, CHAN_PROJECTILE, "weapons/flacexp1.wav", 1, ATTN_NORM);
204                                         else if (r<0.7)
205                                                 sound (self, CHAN_PROJECTILE, "weapons/flacexp2.wav", 1, ATTN_NORM);
206                                         else
207                                                 sound (self, CHAN_PROJECTILE, "weapons/flacexp3.wav", 1, ATTN_NORM);
208                                         pointparticles(particleeffectnum("flac_explode"), org2, '0 0 0', 1);
209                                 }
210                                 else
211                                 {
212                                         if(bounce)
213                                         {
214                                                 if (r<0.15)
215                                                         sound (self, CHAN_PROJECTILE, "weapons/tagexp1.wav", 1, ATTN_NORM);
216                                                 else if (r<0.7)
217                                                         sound (self, CHAN_PROJECTILE, "weapons/tagexp2.wav", 1, ATTN_NORM);
218                                                 else
219                                                         sound (self, CHAN_PROJECTILE, "weapons/tagexp3.wav", 1, ATTN_NORM);
220                                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
221                                         }
222                                         else if(headshot)
223                                         {
224                                                 sound (self, CHAN_PROJECTILE, "weapons/tag_impact.wav", 1, ATTN_NORM);
225                                         }
226                                         else
227                                         {
228                                                 if (r<0.15)
229                                                         sound (self, CHAN_PROJECTILE, "weapons/seekerexp1.wav", 1, ATTN_NORM);
230                                                 else if (r<0.7)
231                                                         sound (self, CHAN_PROJECTILE, "weapons/seekerexp2.wav", 1, ATTN_NORM);
232                                                 else
233                                                         sound (self, CHAN_PROJECTILE, "weapons/seekerexp3.wav", 1, ATTN_NORM);
234                                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
235                                         }
236                                 }
237                                 break;
238                         case WEP_HLAC:
239                                 org2 = findbetterlocation (org, 12);
240                                 sound (self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
241                                 pointparticles(particleeffectnum("laser_impact"), org2, trace_plane_normal * 1000, 1);
242                                 break;
243                         case WEP_CAMPINGRIFLE:
244                                 org2 = findbetterlocation (org, 2);
245                                 pointparticles(particleeffectnum("machinegun_impact"), org, trace_plane_normal * 1000, 1);
246                                 break;
247                         default:
248                                 dprint("Unhandled damage of weapon ", ftos(hitwep), "\n");
249                                 break;
250                 }
251         }
252 }