]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/damage.qc
Merge remote branch 'origin/master' into tzork/turrets-csqc
[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_ISTURRET(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_TURRET_EWHEEL:
86                 sound(self, CHAN_PROJECTILE, "weapons/laserimpact.wav", VOL_BASE, ATTN_MIN);
87                 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
88                 break;
89              
90              case DEATH_TURRET_FLAC:
91                 vector org2;
92                 org2 = w_org + w_backoff * 6;
93                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
94                 if (w_random<0.15)
95                     sound(self, CHAN_PROJECTILE, "weapons/hagexp1.wav", VOL_BASE, ATTN_NORM);
96                 else if (w_random<0.7)
97                     sound(self, CHAN_PROJECTILE, "weapons/hagexp2.wav", VOL_BASE, ATTN_NORM);
98                 else
99                     sound(self, CHAN_PROJECTILE, "weapons/hagexp3.wav", VOL_BASE, ATTN_NORM);
100                 
101                 break;
102                 
103              case DEATH_TURRET_MLRS:
104              case DEATH_TURRET_HK:
105              case DEATH_TURRET_WALKER_ROCKET:
106              case DEATH_TURRET_HELLION:
107                 sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_MIN);
108                 pointparticles(particleeffectnum("rocket_explode"), self.origin, w_backoff * 1000, 1);
109                 break;
110              
111              case DEATH_TURRET_MACHINEGUN:
112              case DEATH_TURRET_WALKER_GUN:
113                 string _snd;
114                 _snd = strcat("weapons/ric", ftos(1 + rint(random() * 2)), ".waw");
115                 sound(self, CHAN_PROJECTILE, _snd, VOL_BASE, ATTN_NORM);
116                 pointparticles(particleeffectnum("machinegun_impact"), self.origin, w_backoff * 1000, 1);
117                 break;
118                           
119              case DEATH_TURRET_PLASMA:
120                 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_MIN);
121                 pointparticles(particleeffectnum("electro_impact"), self.origin, w_backoff * 1000, 1);
122                 break;
123                           
124              case DEATH_TURRET_WALKER_MEELE:
125                 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_MIN);
126                 pointparticles(particleeffectnum("TE_SPARK"), self.origin, w_backoff * 1000, 1);
127                 break;
128
129              case DEATH_TURRET_PHASER:
130                 break;
131                 
132              case DEATH_TURRET_TESLA:
133                 te_smallflash(self.origin);
134                 break;
135
136         }        
137         }
138         
139         // TODO spawn particle effects and sounds based on w_deathtype
140         if(!DEATH_ISSPECIAL(w_deathtype))
141         {
142                 float hitwep;
143
144                 hitwep = DEATH_WEAPONOFWEAPONDEATH(w_deathtype);
145                 w_random = prandom();
146
147                 traceline(w_org - normalize(force) * 16, w_org + normalize(force) * 16, MOVE_NOMONSTERS, world);
148                 if(trace_fraction < 1 && hitwep != WEP_NEX && hitwep != WEP_MINSTANEX)
149                         w_backoff = trace_plane_normal;
150                 else
151                         w_backoff = -1 * normalize(force);
152                 setorigin(self, w_org + w_backoff * 2); // for sound() calls
153
154                 (get_weaponinfo(hitwep)).weapon_func(WR_IMPACTEFFECT);
155         }
156 }
157
158 void DamageInfo_Precache()
159 {
160         float i;
161         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
162                 (get_weaponinfo(i)).weapon_func(WR_PRECACHE);
163 }