]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/damage.qc
Merge branch 'tzork/vehicles-2' of ssh://git.xonotic.org/xonotic-data.pk3dir into...
[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); self; self = self.chain)
34         {
35                 if(rad)
36                 {
37                         thisdmg = vlen(self.origin - w_org) / rad;
38                         if(thisdmg >= 1)
39                                 continue;
40                         if(dmg)
41                         {
42                                 thisdmg = dmg + (edge - dmg) * thisdmg;
43                                 thisforce = forcemul * vlen(force) * (thisdmg / dmg) * normalize(self.origin - w_org);
44                         }
45                         else
46                         {
47                                 thisdmg = 0;
48                                 thisforce = forcemul * vlen(force) * normalize(self.origin - w_org);
49                         }
50                 }
51                 else
52                 {
53                         thisdmg = dmg;
54                         thisforce = forcemul * force;
55                 }
56
57                 if(self.damageforcescale)
58                         if(vlen(thisforce))
59                         {
60                                 self.move_velocity = self.move_velocity + damage_explosion_calcpush(self.damageforcescale * thisforce, self.move_velocity, autocvar_g_balance_damagepush_speedfactor);
61                                 self.move_flags &~= FL_ONGROUND;
62                         }
63
64                 if(w_issilent)
65                         self.silent = 1;
66
67                 if(self.event_damage)
68                         self.event_damage(thisdmg, w_deathtype, w_org, thisforce);
69         }
70
71         self = oldself;
72         
73         if(DEATH_ISVEHICLE(w_deathtype))
74         {
75             traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
76             if(trace_plane_normal != '0 0 0')       
77             w_backoff = trace_plane_normal;
78         else
79             w_backoff = -1 * normalize(w_org - (w_org + normalize(force) * 16));
80             
81             setorigin(self, w_org + w_backoff * 2); // for sound() calls
82             
83             switch(w_deathtype)
84             {            
85             case DEATH_VHCRUSH:
86                 break;
87                 
88             case DEATH_SBMINIGUN:
89                 string _snd;
90                 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
91                 sound(self, CHAN_PROJECTILE, _snd, VOL_BASE, ATTN_NORM);
92                 pointparticles(particleeffectnum("spiderbot_minigun_impact"), self.origin, w_backoff * 1000, 1);
93                 break;
94             case DEATH_SBROCKET:
95                 sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
96                 pointparticles(particleeffectnum("spiderbot_rocket_explode"), self.origin, w_backoff * 1000, 1);
97                 break;
98             case DEATH_SBBLOWUP:
99                 sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
100                 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
101                 break;
102                 
103             case DEATH_WAKIGUN:
104                 sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
105                 pointparticles(particleeffectnum("wakizashi_gun_impact"), self.origin, w_backoff * 1000, 1);
106                 break;
107             case DEATH_WAKIROCKET:
108                 sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
109                 pointparticles(particleeffectnum("wakizashi_rocket_explode"), self.origin, w_backoff * 1000, 1);
110                 break;
111             case DEATH_WAKIBLOWUP:
112                 sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
113                 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
114                 break;
115                 
116             case DEATH_RAPTOR_CANNON:
117                 sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_NORM);
118                 pointparticles(particleeffectnum("raptor_cannon_impact"), self.origin, w_backoff * 1000, 1);
119                 break;
120             case DEATH_RAPTOR_BOMB_SPLIT:
121                 sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
122                 pointparticles(particleeffectnum("raptor_bomb_spread"), self.origin, w_backoff * 1000, 1);
123                 break;
124             case DEATH_RAPTOR_BOMB:
125                 sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
126                 pointparticles(particleeffectnum("raptor_bomb_impact"), self.origin, w_backoff * 1000, 1);
127                 break;
128             case DEATH_RAPTOR_DEATH:
129                 sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
130                 pointparticles(particleeffectnum("explosion_big"), self.origin, w_backoff * 1000, 1);
131                 break;
132             }
133         }
134         
135         // TODO spawn particle effects and sounds based on w_deathtype
136         if(!DEATH_ISSPECIAL(w_deathtype))
137         {
138                 float hitwep;
139
140                 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
141                 w_random = prandom();
142
143                 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
144                 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
145                         w_backoff = trace_plane_normal;
146                 else
147                         w_backoff = -1 * normalize(force);
148                 setorigin(self, w_org + w_backoff * 2); // for sound() calls
149
150                 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
151         }
152 }
153
154 void DamageInfo_Precache()
155 {
156         float i;
157         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
158                 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
159 }