]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/damage.qc
Remove the old way of showing damage effects on gibs. Currently, damage effects no...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / damage.qc
1 void DamageEffect(vector hitorg, float dmg, float type, float specnum1, float entnumber);
2 void Ent_DamageInfo(float isNew)
3 {
4         float dmg, rad, edge, thisdmg, forcemul, species;
5         vector force, thisforce;
6         entity oldself;
7
8         oldself = self;
9
10         w_deathtype = ReadShort();
11         w_issilent = (w_deathtype & 0x8000);
12         w_deathtype = (w_deathtype & 0x7FFF);
13
14         w_org_x = ReadCoord();
15         w_org_y = ReadCoord();
16         w_org_z = ReadCoord();
17
18         dmg = ReadByte();
19         rad = ReadByte();
20         edge = ReadByte();
21         force = decompressShortVector(ReadShort());
22         species = ReadByte();
23
24         if not(isNew)
25                 return;
26
27         if(rad < 0)
28         {
29                 rad = -rad;
30                 forcemul = -1;
31         }
32         else
33                 forcemul = 1;
34         
35         for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
36         {
37                 vector nearest = NearestPointOnBox(self, w_org);
38                 if(rad)
39                 {
40                         thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
41                         if(thisdmg >= 1)
42                                 continue;
43                         if(dmg)
44                         {
45                                 thisdmg = dmg + (edge - dmg) * thisdmg;
46                                 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
47                         }
48                         else
49                         {
50                                 thisdmg = 0;
51                                 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
52                         }
53                 }
54                 else
55                 {
56                         if(vlen(nearest - w_org) > bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS))
57                                 continue;
58
59                         thisdmg = dmg;
60                         thisforce = forcemul * force;
61                 }
62
63                 if(self.damageforcescale)
64                         if(vlen(thisforce))
65                         {
66                                 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
67                                 self.move_flags &~= FL_ONGROUND;
68                         }
69
70                 if(w_issilent)
71                         self.silent = 1;
72
73                 if(self.event_damage)
74                         self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
75
76                 DamageEffect(w_org, thisdmg, w_deathtype, species, self.entnum - 1);
77         }
78
79         self = oldself;
80         
81         if(DEATH_ISVEHICLE(w_deathtype))
82         {
83             traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
84             if(trace_plane_normal != '0 0 0')       
85             w_backoff = trace_plane_normal;
86         else
87             w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
88             
89             setorigin(self, w_org + w_backoff * 2); // for sound() calls
90             
91             switch(w_deathtype)
92             {            
93             case DEATH_VHCRUSH:
94                 break;
95                 
96             case DEATH_SBMINIGUN:
97                 string _snd;
98                 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
99                 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
100                 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
101                 break;
102             case DEATH_SBROCKET:
103                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
104                 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
105                 break;
106             case DEATH_SBBLOWUP:
107                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
108                 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
109                 break;
110                 
111             case DEATH_WAKIGUN:
112                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
113                 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
114                 break;
115             case DEATH_WAKIROCKET:
116                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
117                 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
118                 break;
119             case DEATH_WAKIBLOWUP:
120                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
121                 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
122                 break;
123                 
124             case DEATH_RAPTOR_CANNON:
125                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
126                 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
127                 break;
128             case DEATH_RAPTOR_BOMB_SPLIT:
129                 float i;
130                 vector ang, vel;
131                 for(i = 1; i < 4; ++i)
132                 {
133                     vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
134                     ang = vectoangles(vel);
135                     RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
136                 }
137                     
138                 
139                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
140                 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
141                 break;
142             case DEATH_RAPTOR_BOMB:
143                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
144                 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
145                 break;
146             case DEATH_RAPTOR_DEATH:
147                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
148                 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
149                 break;
150             }
151         }
152         
153         
154         if(DEATH_ISTURRET(w_deathtype))
155         {           
156             string _snd;
157             traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
158             if(trace_plane_normal != '0 0 0')       
159             w_backoff = trace_plane_normal;
160         else
161             w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
162             
163             setorigin(self, w_org + w_backoff * 2); // for sound() calls
164             
165             switch(w_deathtype)
166             {   
167              case DEATH_TURRET_EWHEEL:
168                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
169                 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
170                 break;
171              
172              case DEATH_TURRET_FLAC:
173                 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
174                 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
175                 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);                
176                 break;
177                 
178              case DEATH_TURRET_MLRS:
179              case DEATH_TURRET_HK:
180              case DEATH_TURRET_WALKER_ROCKET:
181              case DEATH_TURRET_HELLION:
182                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
183                 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
184                 break;
185              
186              case DEATH_TURRET_MACHINEGUN:
187              case DEATH_TURRET_WALKER_GUN:
188                 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
189                 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
190                 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
191                 break;
192                           
193              case DEATH_TURRET_PLASMA:
194                 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
195                 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
196                 break;
197                           
198              case DEATH_TURRET_WALKER_MEELE:
199                 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
200                 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
201                 break;
202
203              case DEATH_TURRET_PHASER:
204                 break;
205                 
206              case DEATH_TURRET_TESLA:
207                 te_smallflash(self.origin);
208                 break;
209
210         }        
211         }
212         
213         // TODO spawn particle effects and sounds based on w_deathtype
214         if(!DEATH_ISSPECIAL(w_deathtype))
215         {
216                 float hitwep;
217
218                 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
219                 w_random = prandom();
220
221                 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
222                 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
223                         w_backoff = trace_plane_normal;
224                 else
225                         w_backoff = -1 * normalize(force);
226                 setorigin(self, w_org + w_backoff * 2); // for sound() calls
227
228                 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
229         }
230 }
231
232 void DamageInfo_Precache()
233 {
234         float i;
235         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
236                 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
237 }
238
239 // damage effect
240
241 .entity dmgent;
242 .float dmgpartnum, dmgtime;
243 .float lifetime;
244 .float bone;
245
246 void DamageEffect_Think()
247 {
248         self.nextthink = time;
249         vector org;
250
251         if(time >= self.lifetime)
252         {
253                 remove(self);
254                 self = world;
255                 return;
256         }
257         if(self.dmgtime > time)
258                 return;
259         if(!autocvar_cl_damageeffect)
260                 return; // don't show effects on the invisible dead body if gibs exist
261         if(self.team == player_localentnum - 1 && !autocvar_chase_active)
262                 return; // if we aren't in third person mode, hide own damage effect
263
264         // Now apply the effect to the player
265         org = gettaginfo(self.owner, self.bone);
266         pointparticles(self.dmgpartnum, org, '0 0 0', 1);
267         self.dmgtime = time + autocvar_cl_damageeffect;
268 }
269
270 void DamageEffect(vector hitorg, float dmg, float type, float specnum, float entnumber)
271 {
272         float life, i;
273         string specstr, effectnum;
274         entity e;
275
276         if(!autocvar_cl_damageeffect || autocvar_cl_gentle || autocvar_cl_gentle_damage)
277                 return;
278         if(self.model == "" || !self.model)
279                 return;
280
281         // if we reached our damage count limit for this player, return
282         for(e = world; (e = find(e, classname, "damageeffect")); )
283         {
284                 if(e.team == entnumber)
285                         i += 1;
286         }
287         if(i >= autocvar_cl_damageeffect_limit)
288                 return;
289
290         specstr = species_prefix(specnum);
291         life = bound(0, dmg * autocvar_cl_damageeffect_lifetime, autocvar_cl_damageeffect_lifetime_max);
292
293         e = get_weaponinfo(type);
294         effectnum = strcat("weapondamage_", e.netname);
295         // If the weapon is a bullet weapon, its damage effect is blood.
296         // Since blood is species dependent, we make this effect per-species.
297         if(type == WEP_SHOTGUN || type == WEP_UZI || type == WEP_RIFLE)
298         if(specstr != "")
299         {
300                 effectnum = strcat(effectnum, "_", specstr);
301                 effectnum = substring(effectnum, 0, strlen(effectnum) - 1); // remove the _ symbol at the end of the species name
302         }
303
304         float closest;
305         for(i = 1; gettaginfo(self, i); i++)
306         {
307                 // go through all tags on the player model, choose the one closest to the damage origin
308                 if(!closest || vlen(hitorg - gettaginfo(self, i)) <= vlen(hitorg - gettaginfo(self, closest)))
309                         closest = i;
310         }
311         e = spawn();
312         e.owner = self;
313         e.bone = closest;
314         e.classname = "damageeffect";
315         e.team = entnumber;
316         e.dmgpartnum = particleeffectnum(effectnum);
317         e.lifetime = time + life;
318         e.think = DamageEffect_Think;
319         e.nextthink = time;
320 }