4 /* function */ W_Rifle,
5 /* ammotype */ ammo_nails,
7 /* flags */ WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating */ BOT_PICKUP_RATING_MID,
9 /* model */ "campingrifle",
10 /* netname */ "rifle",
11 /* fullname */ _("Rifle")
14 #define RIFLE_SETTINGS(w_cvar,w_prop) RIFLE_SETTINGS_LIST(w_cvar, w_prop, RIFLE, rifle)
15 #define RIFLE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
16 w_cvar(id, sn, BOTH, ammo) \
17 w_cvar(id, sn, BOTH, animtime) \
18 w_cvar(id, sn, BOTH, bulletconstant) \
19 w_cvar(id, sn, BOTH, bullethail) \
20 w_cvar(id, sn, BOTH, burstcost) \
21 w_cvar(id, sn, BOTH, damage) \
22 w_cvar(id, sn, BOTH, force) \
23 w_cvar(id, sn, BOTH, lifetime) \
24 w_cvar(id, sn, BOTH, refire) \
25 w_cvar(id, sn, BOTH, shots) \
26 w_cvar(id, sn, BOTH, speed) \
27 w_cvar(id, sn, BOTH, spread) \
28 w_cvar(id, sn, BOTH, tracer) \
29 w_cvar(id, sn, NONE, bursttime) \
30 w_cvar(id, sn, NONE, secondary) \
31 w_cvar(id, sn, SEC, reload) \
32 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
33 w_prop(id, sn, float, reloading_time, reload_time) \
34 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
35 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
36 w_prop(id, sn, string, weaponreplace, weaponreplace) \
37 w_prop(id, sn, float, weaponstart, weaponstart) \
38 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride)
41 RIFLE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
42 .float rifle_accumulator;
46 void spawnfunc_weapon_rifle (void) { weapon_defaultspawnfunc(WEP_RIFLE); }
47 void spawnfunc_weapon_campingrifle (void) { spawnfunc_weapon_rifle(); }
48 void spawnfunc_weapon_sniperrifle (void) { spawnfunc_weapon_rifle(); }
50 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)
54 W_DecreaseAmmo(pAmmo);
56 W_SetupShot (self, TRUE, 2, pSound, CH_WEAPON_A, pDamage * pShots);
58 pointparticles(particleeffectnum("rifle_muzzleflash"), w_shotorg, w_shotdir * 2000, 1);
60 if(self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) // if zoomed, shoot from the eye
62 w_shotdir = v_forward;
63 w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
66 for(i = 0; i < pShots; ++i)
67 fireBallisticBullet(w_shotorg, w_shotdir, pSpread, pSpeed, pLifetime, pDamage, pForce, deathtype, (pTracer ? EF_RED : EF_BLUE), pBulletConstant);
68 endFireBallisticBullet();
70 if (autocvar_g_casings >= 2)
71 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);
76 W_Rifle_FireBullet(WEP_CVAR_PRI(rifle, spread), WEP_CVAR_PRI(rifle, damage), WEP_CVAR_PRI(rifle, force), WEP_CVAR_PRI(rifle, speed), WEP_CVAR_PRI(rifle, lifetime), WEP_CVAR_PRI(rifle, ammo), WEP_RIFLE, WEP_CVAR_PRI(rifle, bulletconstant), WEP_CVAR_PRI(rifle, tracer), WEP_CVAR_PRI(rifle, shots), "weapons/campingrifle_fire.wav");
79 void W_Rifle_Attack2()
81 W_Rifle_FireBullet(WEP_CVAR_SEC(rifle, spread), WEP_CVAR_SEC(rifle, damage), WEP_CVAR_SEC(rifle, force), WEP_CVAR_SEC(rifle, speed), WEP_CVAR_SEC(rifle, lifetime), WEP_CVAR_SEC(rifle, ammo), WEP_RIFLE | HITTYPE_SECONDARY, WEP_CVAR_SEC(rifle, bulletconstant), WEP_CVAR_SEC(rifle, tracer), WEP_CVAR_SEC(rifle, shots), "weapons/campingrifle_fire2.wav");
84 .void(void) rifle_bullethail_attackfunc;
85 .float rifle_bullethail_frame;
86 .float rifle_bullethail_animtime;
87 .float rifle_bullethail_refire;
88 void W_Rifle_BulletHail_Continue()
92 sw = self.switchweapon; // make it not detect weapon changes as reason to abort firing
93 af = ATTACK_FINISHED(self);
94 self.switchweapon = self.weapon;
95 ATTACK_FINISHED(self) = time;
96 print(ftos(self.(self.current_ammo)), "\n");
97 r = weapon_prepareattack(self.rifle_bullethail_frame == WFRAME_FIRE2, self.rifle_bullethail_refire);
98 if(self.switchweapon == self.weapon)
99 self.switchweapon = sw;
102 self.rifle_bullethail_attackfunc();
103 weapon_thinkf(self.rifle_bullethail_frame, self.rifle_bullethail_animtime, W_Rifle_BulletHail_Continue);
104 print("thinkf set\n");
108 ATTACK_FINISHED(self) = af; // reset attack_finished if we didn't fire, so the last shot enforces the refire time
109 print("out of ammo... ", ftos(self.weaponentity.state), "\n");
113 void W_Rifle_BulletHail(float mode, void(void) AttackFunc, float fr, float animtime, float refire)
115 // if we get here, we have at least one bullet to fire
120 self.rifle_bullethail_attackfunc = AttackFunc;
121 self.rifle_bullethail_frame = fr;
122 self.rifle_bullethail_animtime = animtime;
123 self.rifle_bullethail_refire = refire;
124 weapon_thinkf(fr, animtime, W_Rifle_BulletHail_Continue);
129 weapon_thinkf(fr, animtime, w_ready);
133 .float bot_secondary_riflemooth;
134 float W_Rifle(float req)
142 self.BUTTON_ATCK=FALSE;
143 self.BUTTON_ATCK2=FALSE;
144 if(vlen(self.origin-self.enemy.origin) > 1000)
145 self.bot_secondary_riflemooth = 0;
146 if(self.bot_secondary_riflemooth == 0)
148 if(bot_aim(WEP_CVAR_PRI(rifle, speed), 0, WEP_CVAR_PRI(rifle, lifetime), FALSE))
150 self.BUTTON_ATCK = TRUE;
151 if(random() < 0.01) self.bot_secondary_riflemooth = 1;
156 if(bot_aim(WEP_CVAR_SEC(rifle, speed), 0, WEP_CVAR_SEC(rifle, lifetime), FALSE))
158 self.BUTTON_ATCK2 = TRUE;
159 if(random() < 0.03) self.bot_secondary_riflemooth = 0;
167 if(autocvar_g_balance_rifle_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo))) // forced reload
168 WEP_ACTION(self.weapon, WR_RELOAD);
171 self.rifle_accumulator = bound(time - WEP_CVAR(rifle, bursttime), self.rifle_accumulator, time);
172 if (self.BUTTON_ATCK)
173 if (weapon_prepareattack_check(0, WEP_CVAR_PRI(rifle, refire)))
174 if (time >= self.rifle_accumulator + WEP_CVAR_PRI(rifle, burstcost))
176 weapon_prepareattack_do(0, WEP_CVAR_PRI(rifle, refire));
177 W_Rifle_BulletHail(WEP_CVAR_PRI(rifle, bullethail), W_Rifle_Attack, WFRAME_FIRE1, WEP_CVAR_PRI(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
178 self.rifle_accumulator += WEP_CVAR_PRI(rifle, burstcost);
180 if (self.BUTTON_ATCK2)
182 if (WEP_CVAR(rifle, secondary))
184 if(WEP_CVAR_SEC(rifle, reload))
185 WEP_ACTION(self.weapon, WR_RELOAD);
188 if (weapon_prepareattack_check(1, WEP_CVAR_SEC(rifle, refire)))
189 if (time >= self.rifle_accumulator + WEP_CVAR_SEC(rifle, burstcost))
191 weapon_prepareattack_do(1, WEP_CVAR_SEC(rifle, refire));
192 W_Rifle_BulletHail(WEP_CVAR_SEC(rifle, bullethail), W_Rifle_Attack2, WFRAME_FIRE2, WEP_CVAR_SEC(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
193 self.rifle_accumulator += WEP_CVAR_SEC(rifle, burstcost);
204 precache_model ("models/weapons/g_campingrifle.md3");
205 precache_model ("models/weapons/v_campingrifle.md3");
206 precache_model ("models/weapons/h_campingrifle.iqm");
207 precache_sound ("weapons/campingrifle_fire.wav");
208 precache_sound ("weapons/campingrifle_fire2.wav");
209 RIFLE_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
214 ammo_amount = self.(self.current_ammo) >= WEP_CVAR_PRI(rifle, ammo);
215 ammo_amount += self.(weapon_load[WEP_RIFLE]) >= WEP_CVAR_PRI(rifle, ammo);
220 ammo_amount = self.(self.current_ammo) >= WEP_CVAR_SEC(rifle, ammo);
221 ammo_amount += self.(weapon_load[WEP_RIFLE]) >= WEP_CVAR_SEC(rifle, ammo);
226 RIFLE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
231 self.rifle_accumulator = time - WEP_CVAR(rifle, bursttime);
236 W_Reload(min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo)), "weapons/reload.wav");
239 case WR_SUICIDEMESSAGE:
241 return WEAPON_THINKING_WITH_PORTALS;
245 if(w_deathtype & HITTYPE_SECONDARY)
247 if(w_deathtype & HITTYPE_BOUNCE)
248 return WEAPON_RIFLE_MURDER_HAIL_PIERCING;
250 return WEAPON_RIFLE_MURDER_HAIL;
254 if(w_deathtype & HITTYPE_BOUNCE)
255 return WEAPON_RIFLE_MURDER_PIERCING;
257 return WEAPON_RIFLE_MURDER;
265 float W_Rifle(float req)
269 case WR_IMPACTEFFECT:
272 org2 = w_org + w_backoff * 2;
273 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
277 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
278 else if(w_random < 0.4)
279 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
280 else if(w_random < 0.5)
281 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
288 precache_sound("weapons/ric1.wav");
289 precache_sound("weapons/ric2.wav");
290 precache_sound("weapons/ric3.wav");