4 /* function */ w_rifle,
5 /* ammotype */ IT_NAILS,
7 /* flags */ WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating */ BOT_PICKUP_RATING_MID,
9 /* model */ "campingrifle",
10 /* shortname */ "rifle",
11 /* fullname */ _("Rifle")
16 .float rifle_accumulator;
18 void W_Rifle_FireBullet(float pSpread, float pDamage, float pForce, float pSpeed, float pLifetime, float pAmmo, float deathtype, float pBulletConstant, float pTracer, float pShots, string pSound)
22 W_DecreaseAmmo(ammo_nails, pAmmo, autocvar_g_balance_rifle_reload_ammo);
24 W_SetupShot (self, autocvar_g_antilag_bullets && pSpeed >= autocvar_g_antilag_bullets, 2, pSound, CH_WEAPON_A, pDamage * pShots);
26 pointparticles(particleeffectnum("rifle_muzzleflash"), w_shotorg, w_shotdir * 2000, 1);
28 if(self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) // if zoomed, shoot from the eye
30 w_shotdir = v_forward;
31 w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
34 for(i = 0; i < pShots; ++i)
35 fireBallisticBullet(w_shotorg, w_shotdir, pSpread, pSpeed, pLifetime, pDamage, pForce, deathtype, (pTracer ? EF_RED : EF_BLUE), 1, pBulletConstant);
36 endFireBallisticBullet();
38 if (autocvar_g_casings >= 2)
39 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);
44 W_Rifle_FireBullet(autocvar_g_balance_rifle_primary_spread, autocvar_g_balance_rifle_primary_damage, autocvar_g_balance_rifle_primary_force, autocvar_g_balance_rifle_primary_speed, autocvar_g_balance_rifle_primary_lifetime, autocvar_g_balance_rifle_primary_ammo, WEP_RIFLE, autocvar_g_balance_rifle_primary_bulletconstant, autocvar_g_balance_rifle_primary_tracer, autocvar_g_balance_rifle_primary_shots, "weapons/campingrifle_fire.wav");
47 void W_Rifle_Attack2()
49 W_Rifle_FireBullet(autocvar_g_balance_rifle_secondary_spread, autocvar_g_balance_rifle_secondary_damage, autocvar_g_balance_rifle_secondary_force, autocvar_g_balance_rifle_secondary_speed, autocvar_g_balance_rifle_secondary_lifetime, autocvar_g_balance_rifle_secondary_ammo, WEP_RIFLE | HITTYPE_SECONDARY, autocvar_g_balance_rifle_secondary_bulletconstant, autocvar_g_balance_rifle_secondary_tracer, autocvar_g_balance_rifle_secondary_shots, "weapons/campingrifle_fire2.wav");
52 void spawnfunc_weapon_rifle (void)
54 weapon_defaultspawnfunc(WEP_RIFLE);
57 // compatibility alias
58 void spawnfunc_weapon_campingrifle (void)
60 spawnfunc_weapon_rifle();
62 void spawnfunc_weapon_sniperrifle (void)
64 spawnfunc_weapon_rifle();
67 .void(void) rifle_bullethail_attackfunc;
68 .float rifle_bullethail_frame;
69 .float rifle_bullethail_animtime;
70 .float rifle_bullethail_refire;
71 void W_Rifle_BulletHail_Continue()
75 sw = self.switchweapon; // make it not detect weapon changes as reason to abort firing
76 af = ATTACK_FINISHED(self);
77 self.switchweapon = self.weapon;
78 ATTACK_FINISHED(self) = time;
79 print(ftos(self.ammo_nails), "\n");
80 r = weapon_prepareattack(self.rifle_bullethail_frame == WFRAME_FIRE2, self.rifle_bullethail_refire);
81 if(self.switchweapon == self.weapon)
82 self.switchweapon = sw;
85 self.rifle_bullethail_attackfunc();
86 weapon_thinkf(self.rifle_bullethail_frame, self.rifle_bullethail_animtime, W_Rifle_BulletHail_Continue);
87 print("thinkf set\n");
91 ATTACK_FINISHED(self) = af; // reset attack_finished if we didn't fire, so the last shot enforces the refire time
92 print("out of ammo... ", ftos(self.weaponentity.state), "\n");
96 void W_Rifle_BulletHail(float mode, void(void) AttackFunc, float fr, float animtime, float refire)
98 // if we get here, we have at least one bullet to fire
103 self.rifle_bullethail_attackfunc = AttackFunc;
104 self.rifle_bullethail_frame = fr;
105 self.rifle_bullethail_animtime = animtime;
106 self.rifle_bullethail_refire = refire;
107 weapon_thinkf(fr, animtime, W_Rifle_BulletHail_Continue);
112 weapon_thinkf(fr, animtime, w_ready);
116 .float bot_secondary_riflemooth;
117 float w_rifle(float req)
123 self.BUTTON_ATCK=FALSE;
124 self.BUTTON_ATCK2=FALSE;
125 if(vlen(self.origin-self.enemy.origin) > 1000)
126 self.bot_secondary_riflemooth = 0;
127 if(self.bot_secondary_riflemooth == 0)
129 if(bot_aim(autocvar_g_balance_rifle_primary_speed, 0, autocvar_g_balance_rifle_primary_lifetime, FALSE))
131 self.BUTTON_ATCK = TRUE;
132 if(random() < 0.01) self.bot_secondary_riflemooth = 1;
137 if(bot_aim(autocvar_g_balance_rifle_secondary_speed, 0, autocvar_g_balance_rifle_secondary_lifetime, FALSE))
139 self.BUTTON_ATCK2 = TRUE;
140 if(random() < 0.03) self.bot_secondary_riflemooth = 0;
144 else if (req == WR_THINK)
146 if(autocvar_g_balance_rifle_reload_ammo && self.clip_load < min(autocvar_g_balance_rifle_primary_ammo, autocvar_g_balance_rifle_secondary_ammo)) // forced reload
147 weapon_action(self.weapon, WR_RELOAD);
150 self.rifle_accumulator = bound(time - autocvar_g_balance_rifle_bursttime, self.rifle_accumulator, time);
151 if (self.BUTTON_ATCK)
152 if (weapon_prepareattack_check(0, autocvar_g_balance_rifle_primary_refire))
153 if (time >= self.rifle_accumulator + autocvar_g_balance_rifle_primary_burstcost)
155 weapon_prepareattack_do(0, autocvar_g_balance_rifle_primary_refire);
156 W_Rifle_BulletHail(autocvar_g_balance_rifle_primary_bullethail, W_Rifle_Attack, WFRAME_FIRE1, autocvar_g_balance_rifle_primary_animtime, autocvar_g_balance_rifle_primary_refire);
157 self.rifle_accumulator += autocvar_g_balance_rifle_primary_burstcost;
159 if (self.BUTTON_ATCK2)
161 if (autocvar_g_balance_rifle_secondary)
163 if(autocvar_g_balance_rifle_secondary_reload)
164 weapon_action(self.weapon, WR_RELOAD);
167 if (weapon_prepareattack_check(1, autocvar_g_balance_rifle_secondary_refire))
168 if (time >= self.rifle_accumulator + autocvar_g_balance_rifle_secondary_burstcost)
170 weapon_prepareattack_do(1, autocvar_g_balance_rifle_secondary_refire);
171 W_Rifle_BulletHail(autocvar_g_balance_rifle_secondary_bullethail, W_Rifle_Attack2, WFRAME_FIRE2, autocvar_g_balance_rifle_secondary_animtime, autocvar_g_balance_rifle_primary_refire);
172 self.rifle_accumulator += autocvar_g_balance_rifle_secondary_burstcost;
179 else if (req == WR_PRECACHE)
181 precache_model ("models/weapons/g_campingrifle.md3");
182 precache_model ("models/weapons/v_campingrifle.md3");
183 precache_model ("models/weapons/h_campingrifle.iqm");
184 precache_sound ("weapons/campingrifle_fire.wav");
185 precache_sound ("weapons/campingrifle_fire2.wav");
186 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
188 else if (req == WR_SETUP)
190 weapon_setup(WEP_RIFLE);
191 self.current_ammo = ammo_nails;
193 else if (req == WR_CHECKAMMO1)
195 ammo_amount = self.ammo_nails >= autocvar_g_balance_rifle_primary_ammo;
196 ammo_amount += self.(weapon_load[WEP_RIFLE]) >= autocvar_g_balance_rifle_primary_ammo;
199 else if (req == WR_CHECKAMMO2)
201 ammo_amount = self.ammo_nails >= autocvar_g_balance_rifle_secondary_ammo;
202 ammo_amount += self.(weapon_load[WEP_RIFLE]) >= autocvar_g_balance_rifle_secondary_ammo;
205 else if (req == WR_RESETPLAYER)
207 self.rifle_accumulator = time - autocvar_g_balance_rifle_bursttime;
209 else if (req == WR_RELOAD)
211 W_Reload(min(autocvar_g_balance_rifle_primary_ammo, autocvar_g_balance_rifle_secondary_ammo), autocvar_g_balance_rifle_reload_ammo, autocvar_g_balance_rifle_reload_time, "weapons/reload.wav");
213 else if (req == WR_SUICIDEMESSAGE)
215 return WEAPON_THINKING_WITH_PORTALS;
217 else if (req == WR_KILLMESSAGE)
219 if(w_deathtype & HITTYPE_SECONDARY)
221 if(w_deathtype & HITTYPE_BOUNCE)
222 return WEAPON_RIFLE_MURDER_HAIL_PIERCING;
224 return WEAPON_RIFLE_MURDER_HAIL;
228 if(w_deathtype & HITTYPE_BOUNCE)
229 return WEAPON_RIFLE_MURDER_PIERCING;
231 return WEAPON_RIFLE_MURDER;
238 float w_rifle(float req)
240 if(req == WR_IMPACTEFFECT)
243 org2 = w_org + w_backoff * 2;
244 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
248 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
249 else if(w_random < 0.4)
250 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
251 else if(w_random < 0.5)
252 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
255 else if(req == WR_PRECACHE)
257 precache_sound("weapons/ric1.wav");
258 precache_sound("weapons/ric2.wav");
259 precache_sound("weapons/ric3.wav");