Merge branch 'master' into mirceakitsune/hud_postprocessing
[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 + self.damageforcescale * thisforce;
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         // TODO spawn particle effects and sounds based on w_deathtype
74         
75         if(!DEATH_ISSPECIAL(w_deathtype))
76         {
77                 float hitwep;
78
79                 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
80                 w_random = prandom();
81
82                 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
83                 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
84                         w_backoff = trace_plane_normal;
85                 else
86                         w_backoff = -1 * normalize(force);
87                 setorigin(self, w_org + w_backoff * 2); // for sound() calls
88
89                 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
90         }
91 }
92
93 void DamageInfo_Precache()
94 {
95         float i;
96         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
97                 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
98 }