]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_sniperrifle.qc
Merge remote-tracking branch 'origin/fruitiex/disable-shootanim'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_sniperrifle.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(SNIPERRIFLE, w_sniperrifle, IT_NAILS, 7, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_MID, "campingrifle", "sniperrifle", _("Sniper Rifle"))
3 #else
4 #ifdef SVQC
5
6 .float sniperrifle_accumulator;
7
8 void W_SniperRifle_FireBullet(float pSpread, float pDamage, float pHeadshotAddedDamage, float pForce, float pSpeed, float pLifetime, float pAmmo, float deathtype, float pBulletConstant, float pTracer, float pShots, string pSound)
9 {
10         float i;
11
12         W_DecreaseAmmo(ammo_nails, pAmmo, autocvar_g_balance_sniperrifle_reload_ammo);
13
14         W_SetupShot (self, autocvar_g_antilag_bullets && pSpeed >= autocvar_g_antilag_bullets, 2, pSound, CHAN_WEAPON, (pDamage + pHeadshotAddedDamage) * pShots);
15
16         pointparticles(particleeffectnum("sniperrifle_muzzleflash"), w_shotorg, w_shotdir * 2000, 1);
17
18         if(self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) // if zoomed, shoot from the eye
19         {
20                 w_shotdir = v_forward;
21                 w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
22         }
23
24         for(i = 0; i < pShots; ++i)
25                 fireBallisticBullet(w_shotorg, w_shotdir, pSpread, pSpeed, pLifetime, pDamage, pHeadshotAddedDamage / pDamage, pForce, deathtype, (pTracer ? EF_RED : EF_BLUE), 1, pBulletConstant);
26         endFireBallisticBullet();
27
28         if (autocvar_g_casings >= 2)
29                 SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self);
30 }
31
32 void W_SniperRifle_Attack()
33 {
34         W_SniperRifle_FireBullet(autocvar_g_balance_sniperrifle_primary_spread, autocvar_g_balance_sniperrifle_primary_damage, autocvar_g_balance_sniperrifle_primary_headshotaddeddamage, autocvar_g_balance_sniperrifle_primary_force, autocvar_g_balance_sniperrifle_primary_speed, autocvar_g_balance_sniperrifle_primary_lifetime, autocvar_g_balance_sniperrifle_primary_ammo, WEP_SNIPERRIFLE, autocvar_g_balance_sniperrifle_primary_bulletconstant, autocvar_g_balance_sniperrifle_primary_tracer, autocvar_g_balance_sniperrifle_primary_shots, "weapons/campingrifle_fire.wav");
35 }
36
37 void W_SniperRifle_Attack2()
38 {
39         W_SniperRifle_FireBullet(autocvar_g_balance_sniperrifle_secondary_spread, autocvar_g_balance_sniperrifle_secondary_damage, autocvar_g_balance_sniperrifle_secondary_headshotaddeddamage, autocvar_g_balance_sniperrifle_secondary_force, autocvar_g_balance_sniperrifle_secondary_speed, autocvar_g_balance_sniperrifle_secondary_lifetime, autocvar_g_balance_sniperrifle_secondary_ammo, WEP_SNIPERRIFLE | HITTYPE_SECONDARY, autocvar_g_balance_sniperrifle_secondary_bulletconstant, autocvar_g_balance_sniperrifle_secondary_tracer, autocvar_g_balance_sniperrifle_secondary_shots, "weapons/campingrifle_fire2.wav");
40 }
41
42 void spawnfunc_weapon_sniperrifle (void)
43 {
44         weapon_defaultspawnfunc(WEP_SNIPERRIFLE);
45 }
46
47 // compatibility alias
48 void spawnfunc_weapon_campingrifle (void)
49 {
50         spawnfunc_weapon_sniperrifle();
51 }
52
53 .void(void) sniperrifle_bullethail_attackfunc;
54 .float sniperrifle_bullethail_frame;
55 .float sniperrifle_bullethail_animtime;
56 .float sniperrifle_bullethail_refire;
57 void W_SniperRifle_BulletHail_Continue()
58 {
59         float r, sw, af;
60
61         sw = self.switchweapon; // make it not detect weapon changes as reason to abort firing
62         af = ATTACK_FINISHED(self);
63         self.switchweapon = self.weapon;
64         ATTACK_FINISHED(self) = time;
65         print(ftos(self.ammo_nails), "\n");
66         r = weapon_prepareattack(self.sniperrifle_bullethail_frame == WFRAME_FIRE2, self.sniperrifle_bullethail_refire);
67         if(self.switchweapon == self.weapon)
68                 self.switchweapon = sw;
69         if(r)
70         {
71                 self.sniperrifle_bullethail_attackfunc();
72                 weapon_thinkf(self.sniperrifle_bullethail_frame, self.sniperrifle_bullethail_animtime, W_SniperRifle_BulletHail_Continue);
73                 print("thinkf set\n");
74         }
75         else
76         {
77                 ATTACK_FINISHED(self) = af; // reset attack_finished if we didn't fire, so the last shot enforces the refire time
78                 print("out of ammo... ", ftos(self.weaponentity.state), "\n");
79         }
80 }
81
82 void W_SniperRifle_BulletHail(float mode, void(void) AttackFunc, float fr, float animtime, float refire)
83 {
84         // if we get here, we have at least one bullet to fire
85         AttackFunc();
86         if(mode)
87         {
88                 // continue hail
89                 self.sniperrifle_bullethail_attackfunc = AttackFunc;
90                 self.sniperrifle_bullethail_frame = fr;
91                 self.sniperrifle_bullethail_animtime = animtime;
92                 self.sniperrifle_bullethail_refire = refire;
93                 weapon_thinkf(fr, animtime, W_SniperRifle_BulletHail_Continue);
94         }
95         else
96         {
97                 // just one shot
98                 weapon_thinkf(fr, animtime, w_ready);
99         }
100 }
101
102 .float bot_secondary_sniperriflemooth;
103 float w_sniperrifle(float req)
104 {
105         float ammo_amount;
106
107         if (req == WR_AIM)
108         {
109                 self.BUTTON_ATCK=FALSE;
110                 self.BUTTON_ATCK2=FALSE;
111                 if(vlen(self.origin-self.enemy.origin) > 1000)
112                         self.bot_secondary_sniperriflemooth = 0;
113                 if(self.bot_secondary_sniperriflemooth == 0)
114                 {
115                         if(bot_aim(autocvar_g_balance_sniperrifle_primary_speed, 0, autocvar_g_balance_sniperrifle_primary_lifetime, TRUE))
116                         {
117                                 self.BUTTON_ATCK = TRUE;
118                                 if(random() < 0.01) self.bot_secondary_sniperriflemooth = 1;
119                         }
120                 }
121                 else
122                 {
123                         if(bot_aim(autocvar_g_balance_sniperrifle_secondary_speed, 0, autocvar_g_balance_sniperrifle_secondary_lifetime, TRUE))
124                         {
125                                 self.BUTTON_ATCK2 = TRUE;
126                                 if(random() < 0.03) self.bot_secondary_sniperriflemooth = 0;
127                         }
128                 }
129         }
130         else if (req == WR_THINK)
131         {
132                 if(autocvar_g_balance_sniperrifle_reload_ammo && self.clip_load < min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo)) // forced reload
133             weapon_action(self.weapon, WR_RELOAD);
134                 else
135                 {
136                         self.sniperrifle_accumulator = bound(time - autocvar_g_balance_sniperrifle_bursttime, self.sniperrifle_accumulator, time);
137                         if (self.BUTTON_ATCK)
138                         if (weapon_prepareattack_check(0, autocvar_g_balance_sniperrifle_primary_refire))
139                         if (time >= self.sniperrifle_accumulator + autocvar_g_balance_sniperrifle_primary_burstcost)
140                         {
141                                 weapon_prepareattack_do(0, autocvar_g_balance_sniperrifle_primary_refire);
142                                 W_SniperRifle_BulletHail(autocvar_g_balance_sniperrifle_primary_bullethail, W_SniperRifle_Attack, WFRAME_FIRE1, autocvar_g_balance_sniperrifle_primary_animtime, autocvar_g_balance_sniperrifle_primary_refire);
143                                 self.sniperrifle_accumulator += autocvar_g_balance_sniperrifle_primary_burstcost;
144                         }
145                         if (self.BUTTON_ATCK2)
146                         {       
147                                 if (autocvar_g_balance_sniperrifle_secondary)
148                                 {
149                     if(autocvar_g_balance_sniperrifle_secondary_reload)
150                         weapon_action(self.weapon, WR_RELOAD);
151                     else
152                     {
153                         if (weapon_prepareattack_check(1, autocvar_g_balance_sniperrifle_secondary_refire))
154                         if (time >= self.sniperrifle_accumulator + autocvar_g_balance_sniperrifle_secondary_burstcost)
155                         {
156                             weapon_prepareattack_do(1, autocvar_g_balance_sniperrifle_secondary_refire);
157                             W_SniperRifle_BulletHail(autocvar_g_balance_sniperrifle_secondary_bullethail, W_SniperRifle_Attack2, WFRAME_FIRE2, autocvar_g_balance_sniperrifle_secondary_animtime, autocvar_g_balance_sniperrifle_primary_refire);
158                             self.sniperrifle_accumulator += autocvar_g_balance_sniperrifle_secondary_burstcost;
159                         }
160                     }
161                                 }
162                         }
163                 }
164         }
165         else if (req == WR_PRECACHE)
166         {
167                 precache_model ("models/weapons/g_campingrifle.md3");
168                 precache_model ("models/weapons/v_campingrifle.md3");
169                 precache_model ("models/weapons/h_campingrifle.iqm");
170                 precache_sound ("weapons/campingrifle_fire.wav");
171                 precache_sound ("weapons/campingrifle_fire2.wav");
172                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
173         }
174         else if (req == WR_SETUP)
175         {
176                 weapon_setup(WEP_SNIPERRIFLE);
177                 self.current_ammo = ammo_nails;
178         }
179         else if (req == WR_CHECKAMMO1)
180         {
181                 ammo_amount = self.ammo_nails >= autocvar_g_balance_sniperrifle_primary_ammo;
182                 ammo_amount += self.weapon_load[WEP_SNIPERRIFLE] >= autocvar_g_balance_sniperrifle_primary_ammo;
183                 return ammo_amount;
184         }
185         else if (req == WR_CHECKAMMO2)
186         {
187                 ammo_amount = self.ammo_nails >= autocvar_g_balance_sniperrifle_secondary_ammo;
188                 ammo_amount += self.weapon_load[WEP_SNIPERRIFLE] >= autocvar_g_balance_sniperrifle_secondary_ammo;
189                 return ammo_amount;
190         }
191         else if (req == WR_RESETPLAYER)
192         {
193                 self.sniperrifle_accumulator = time - autocvar_g_balance_sniperrifle_bursttime;
194         }
195         else if (req == WR_RELOAD)
196         {
197                 W_Reload(min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo), autocvar_g_balance_sniperrifle_reload_ammo, autocvar_g_balance_sniperrifle_reload_time, "weapons/reload.wav");
198         }
199         return TRUE;
200 };
201 #endif
202 #ifdef CSQC
203 float w_sniperrifle(float req)
204 {
205         if(req == WR_IMPACTEFFECT)
206         {
207                 vector org2;
208                 org2 = w_org + w_backoff * 2;
209                 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
210                 if(!w_issilent)
211                 {
212                         if(w_random < 0.2)
213                                 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
214                         else if(w_random < 0.4)
215                                 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
216                         else if(w_random < 0.5)
217                                 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
218                 }
219         }
220         else if(req == WR_PRECACHE)
221         {
222                 precache_sound("weapons/ric1.wav");
223                 precache_sound("weapons/ric2.wav");
224                 precache_sound("weapons/ric3.wav");
225         }
226         else if (req == WR_SUICIDEMESSAGE)
227         {
228                 if(w_deathtype & HITTYPE_SECONDARY)
229                         w_deathtypestring = _("%s shot themself automatically");
230                 else
231                         w_deathtypestring = _("%s sniped themself somehow");
232         }
233         else if (req == WR_KILLMESSAGE)
234         {
235                 if(w_deathtype & HITTYPE_SECONDARY)
236                 {
237                         if(w_deathtype & HITTYPE_BOUNCE)
238                                 w_deathtypestring = _("%s failed to hide from %s's bullet hail");
239                         else
240                                 w_deathtypestring = _("%s died in %s's bullet hail");
241                 }
242                 else
243                 {
244                         if(w_deathtype & HITTYPE_BOUNCE)
245                         {
246                                 // TODO special headshot message here too?
247                                 w_deathtypestring = _("%s failed to hide from %s's rifle");
248                         }
249                         else
250                         {
251                                 if(w_deathtype & HITTYPE_HEADSHOT)
252                                         w_deathtypestring = _("%s got hit in the head by %s");
253                                 else
254                                         w_deathtypestring = _("%s was sniped by %s");
255                         }
256                 }
257         }
258         return TRUE;
259 }
260 #endif
261 #endif