]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/damage.qc
Merge remote-tracking branch 'origin/master' into tzork/gm_nexball
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / damage.qc
1 void Ent_DamageInfo(float isNew)
2 {
3         float dmg, rad, edge, thisdmg, forcemul;
4         vector force, thisforce;
5         entity oldself;
6
7         oldself = self;
8
9         w_deathtype = ReadShort();
10         w_issilent = (w_deathtype & 0x8000);
11         w_deathtype = (w_deathtype & 0x7FFF);
12
13         w_org_x = ReadCoord();
14         w_org_y = ReadCoord();
15         w_org_z = ReadCoord();
16
17         dmg = ReadByte();
18         rad = ReadByte();
19         edge = ReadByte();
20         force = decompressShortVector(ReadShort());
21
22         if not(isNew)
23                 return;
24
25         if(rad < 0)
26         {
27                 rad = -rad;
28                 forcemul = -1;
29         }
30         else
31                 forcemul = 1;
32         
33         for(self = findradius(w_org, rad + MAX_DAMAGEEXTRARADIUS); self; self = self.chain)
34         {
35                 vector nearest = NearestPointOnBox(self, w_org);
36                 if(rad)
37                 {
38                         thisdmg = ((vlen (nearest - w_org) - bound(MIN_DAMAGEEXTRARADIUS, self.damageextraradius, MAX_DAMAGEEXTRARADIUS)) / rad);
39                         if(thisdmg >= 1)
40                                 continue;
41                         if(thisdmg < 0)
42                                 thisdmg = 0;
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
77         self = oldself;
78         
79         if(DEATH_ISVEHICLE(w_deathtype))
80         {
81             traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
82             if(trace_plane_normal != '0 0 0')       
83             w_backoff = trace_plane_normal;
84         else
85             w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
86             
87             setorigin(self, w_org + w_backoff * 2); // for sound() calls
88             
89             switch(w_deathtype)
90             {            
91             case DEATH_VHCRUSH:
92                 break;
93                 
94             case DEATH_SBMINIGUN:
95                 string _snd;
96                 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
97                 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
98                 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
99                 break;
100             case DEATH_SBROCKET:
101                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
102                 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
103                 break;
104             case DEATH_SBBLOWUP:
105                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
106                 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
107                 break;
108                 
109             case DEATH_WAKIGUN:
110                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
111                 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
112                 break;
113             case DEATH_WAKIROCKET:
114                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
115                 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
116                 break;
117             case DEATH_WAKIBLOWUP:
118                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
119                 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
120                 break;
121                 
122             case DEATH_RAPTOR_CANNON:
123                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
124                 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
125                 break;
126             case DEATH_RAPTOR_BOMB_SPLIT:
127                 float i;
128                 vector ang, vel;
129                 for(i = 1; i < 4; ++i)
130                 {
131                     vel = normalize(w_org - (w_org + normalize(force) * 16)) + randomvec() * 128;
132                     ang = vectoangles(vel);
133                     RaptorCBShellfragToss(w_org, vel, ang + '0 0 1' * (120 * i));
134                 }
135                     
136                 
137                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
138                 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
139                 break;
140             case DEATH_RAPTOR_BOMB:
141                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
142                 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
143                 break;
144             case DEATH_RAPTOR_DEATH:
145                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
146                 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
147                 break;
148             }
149         }
150         
151         
152         if(DEATH_ISTURRET(w_deathtype))
153         {           
154             string _snd;
155             traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
156             if(trace_plane_normal != '0 0 0')       
157             w_backoff = trace_plane_normal;
158         else
159             w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
160             
161             setorigin(self, w_org + w_backoff * 2); // for sound() calls
162             
163             switch(w_deathtype)
164             {   
165              case DEATH_TURRET_EWHEEL:
166                 sound(self, CH_SHOTS, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
167                 pointparticles(particleeffectnum("laser_impact"), self.origin, w_backoff * 1000, 1);
168                 break;
169              
170              case DEATH_TURRET_FLAC:
171                 pointparticles(particleeffectnum("hagar_explode"), w_org, '0 0 0', 1);
172                 _snd = strcat("weapons/hagexp", ftos(1 + rint(random() * 2)), ".waw");
173                 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);                
174                 break;
175                 
176              case DEATH_TURRET_MLRS:
177              case DEATH_TURRET_HK:
178              case DEATH_TURRET_WALKER_ROCKET:
179              case DEATH_TURRET_HELLION:
180                 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
181                 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
182                 break;
183              
184              case DEATH_TURRET_MACHINEGUN:
185              case DEATH_TURRET_WALKER_GUN:
186                 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
187                 sound(self, CH_SHOTS, _snd, VOL_BASE, ATTN_NORM);
188                 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
189                 break;
190                           
191              case DEATH_TURRET_PLASMA:
192                 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
193                 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
194                 break;
195                           
196              case DEATH_TURRET_WALKER_MEELE:
197                 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
198                 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
199                 break;
200
201              case DEATH_TURRET_PHASER:
202                 break;
203                 
204              case DEATH_TURRET_TESLA:
205                 te_smallflash(self.origin);
206                 break;
207
208         }        
209         }
210         
211         // TODO spawn particle effects and sounds based on w_deathtype
212         if(!DEATH_ISSPECIAL(w_deathtype))
213         {
214                 float hitwep;
215
216                 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
217                 w_random = prandom();
218
219                 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
220                 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
221                         w_backoff = trace_plane_normal;
222                 else
223                         w_backoff = -1 * normalize(force);
224                 setorigin(self, w_org + w_backoff * 2); // for sound() calls
225
226                 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
227         }
228 }
229
230 void DamageInfo_Precache()
231 {
232         float i;
233         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
234                 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
235 }