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,
10 /* model */ "campingrifle",
11 /* crosshair */ "gfx/crosshairrifle 0.5",
12 /* refname */ "rifle",
13 /* wepname */ _("Rifle")
16 #define RIFLE_SETTINGS(w_cvar,w_prop) RIFLE_SETTINGS_LIST(w_cvar, w_prop, RIFLE, rifle)
17 #define RIFLE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
18 w_cvar(id, sn, BOTH, ammo) \
19 w_cvar(id, sn, BOTH, animtime) \
20 w_cvar(id, sn, BOTH, bullethail) \
21 w_cvar(id, sn, BOTH, burstcost) \
22 w_cvar(id, sn, BOTH, damage) \
23 w_cvar(id, sn, BOTH, force) \
24 w_cvar(id, sn, BOTH, refire) \
25 w_cvar(id, sn, BOTH, shots) \
26 w_cvar(id, sn, BOTH, solidpenetration) \
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 pSolidPenetration, float pAmmo, float deathtype, 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 fireBullet(w_shotorg, w_shotdir, pSpread, pSolidPenetration, pDamage, pForce, deathtype, (pTracer ? EF_RED : EF_BLUE));
69 if (autocvar_g_casings >= 2)
70 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);
75 W_Rifle_FireBullet(WEP_CVAR_PRI(rifle, spread), WEP_CVAR_PRI(rifle, damage), WEP_CVAR_PRI(rifle, force), WEP_CVAR_PRI(rifle, solidpenetration), WEP_CVAR_PRI(rifle, ammo), WEP_RIFLE, WEP_CVAR_PRI(rifle, tracer), WEP_CVAR_PRI(rifle, shots), "weapons/campingrifle_fire.wav");
78 void W_Rifle_Attack2()
80 W_Rifle_FireBullet(WEP_CVAR_SEC(rifle, spread), WEP_CVAR_SEC(rifle, damage), WEP_CVAR_SEC(rifle, force), WEP_CVAR_SEC(rifle, solidpenetration), WEP_CVAR_SEC(rifle, ammo), WEP_RIFLE | HITTYPE_SECONDARY, WEP_CVAR_SEC(rifle, tracer), WEP_CVAR_SEC(rifle, shots), "weapons/campingrifle_fire2.wav");
83 .void(void) rifle_bullethail_attackfunc;
84 .float rifle_bullethail_frame;
85 .float rifle_bullethail_animtime;
86 .float rifle_bullethail_refire;
87 void W_Rifle_BulletHail_Continue()
91 sw = self.switchweapon; // make it not detect weapon changes as reason to abort firing
92 af = ATTACK_FINISHED(self);
93 self.switchweapon = self.weapon;
94 ATTACK_FINISHED(self) = time;
95 print(ftos(self.WEP_AMMO(RIFLE)), "\n");
96 r = weapon_prepareattack(self.rifle_bullethail_frame == WFRAME_FIRE2, self.rifle_bullethail_refire);
97 if(self.switchweapon == self.weapon)
98 self.switchweapon = sw;
101 self.rifle_bullethail_attackfunc();
102 weapon_thinkf(self.rifle_bullethail_frame, self.rifle_bullethail_animtime, W_Rifle_BulletHail_Continue);
103 print("thinkf set\n");
107 ATTACK_FINISHED(self) = af; // reset attack_finished if we didn't fire, so the last shot enforces the refire time
108 print("out of ammo... ", ftos(self.weaponentity.state), "\n");
112 void W_Rifle_BulletHail(float mode, void(void) AttackFunc, float fr, float animtime, float refire)
114 // if we get here, we have at least one bullet to fire
119 self.rifle_bullethail_attackfunc = AttackFunc;
120 self.rifle_bullethail_frame = fr;
121 self.rifle_bullethail_animtime = animtime;
122 self.rifle_bullethail_refire = refire;
123 weapon_thinkf(fr, animtime, W_Rifle_BulletHail_Continue);
128 weapon_thinkf(fr, animtime, w_ready);
132 .float bot_secondary_riflemooth;
133 float W_Rifle(float req)
141 self.BUTTON_ATCK=FALSE;
142 self.BUTTON_ATCK2=FALSE;
143 if(vlen(self.origin-self.enemy.origin) > 1000)
144 self.bot_secondary_riflemooth = 0;
145 if(self.bot_secondary_riflemooth == 0)
147 if(bot_aim(1000000, 0, 0.001, FALSE))
149 self.BUTTON_ATCK = TRUE;
150 if(random() < 0.01) self.bot_secondary_riflemooth = 1;
155 if(bot_aim(1000000, 0, 0.001, FALSE))
157 self.BUTTON_ATCK2 = TRUE;
158 if(random() < 0.03) self.bot_secondary_riflemooth = 0;
166 if(autocvar_g_balance_rifle_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo))) // forced reload
167 WEP_ACTION(self.weapon, WR_RELOAD);
170 self.rifle_accumulator = bound(time - WEP_CVAR(rifle, bursttime), self.rifle_accumulator, time);
171 if (self.BUTTON_ATCK)
172 if (weapon_prepareattack_check(0, WEP_CVAR_PRI(rifle, refire)))
173 if (time >= self.rifle_accumulator + WEP_CVAR_PRI(rifle, burstcost))
175 weapon_prepareattack_do(0, WEP_CVAR_PRI(rifle, refire));
176 W_Rifle_BulletHail(WEP_CVAR_PRI(rifle, bullethail), W_Rifle_Attack, WFRAME_FIRE1, WEP_CVAR_PRI(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
177 self.rifle_accumulator += WEP_CVAR_PRI(rifle, burstcost);
179 if (self.BUTTON_ATCK2)
181 if (WEP_CVAR(rifle, secondary))
183 if(WEP_CVAR_SEC(rifle, reload))
184 WEP_ACTION(self.weapon, WR_RELOAD);
187 if (weapon_prepareattack_check(1, WEP_CVAR_SEC(rifle, refire)))
188 if (time >= self.rifle_accumulator + WEP_CVAR_SEC(rifle, burstcost))
190 weapon_prepareattack_do(1, WEP_CVAR_SEC(rifle, refire));
191 W_Rifle_BulletHail(WEP_CVAR_SEC(rifle, bullethail), W_Rifle_Attack2, WFRAME_FIRE2, WEP_CVAR_SEC(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
192 self.rifle_accumulator += WEP_CVAR_SEC(rifle, burstcost);
203 precache_model ("models/weapons/g_campingrifle.md3");
204 precache_model ("models/weapons/v_campingrifle.md3");
205 precache_model ("models/weapons/h_campingrifle.iqm");
206 precache_sound ("weapons/campingrifle_fire.wav");
207 precache_sound ("weapons/campingrifle_fire2.wav");
208 RIFLE_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
213 ammo_amount = self.WEP_AMMO(RIFLE) >= WEP_CVAR_PRI(rifle, ammo);
214 ammo_amount += self.(weapon_load[WEP_RIFLE]) >= WEP_CVAR_PRI(rifle, ammo);
219 ammo_amount = self.WEP_AMMO(RIFLE) >= WEP_CVAR_SEC(rifle, ammo);
220 ammo_amount += self.(weapon_load[WEP_RIFLE]) >= WEP_CVAR_SEC(rifle, ammo);
225 RIFLE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
230 self.rifle_accumulator = time - WEP_CVAR(rifle, bursttime);
235 W_Reload(min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo)), "weapons/reload.wav");
238 case WR_SUICIDEMESSAGE:
240 return WEAPON_THINKING_WITH_PORTALS;
244 if(w_deathtype & HITTYPE_SECONDARY)
246 if(w_deathtype & HITTYPE_BOUNCE)
247 return WEAPON_RIFLE_MURDER_HAIL_PIERCING;
249 return WEAPON_RIFLE_MURDER_HAIL;
253 if(w_deathtype & HITTYPE_BOUNCE)
254 return WEAPON_RIFLE_MURDER_PIERCING;
256 return WEAPON_RIFLE_MURDER;
264 float W_Rifle(float req)
268 case WR_IMPACTEFFECT:
271 org2 = w_org + w_backoff * 2;
272 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
276 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
277 else if(w_random < 0.4)
278 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
279 else if(w_random < 0.5)
280 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
287 precache_sound("weapons/ric1.wav");
288 precache_sound("weapons/ric2.wav");
289 precache_sound("weapons/ric3.wav");
290 if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
292 precache_pic("gfx/reticle_nex");
298 if(button_zoom || zoomscript_caught)
300 reticle_image = "gfx/reticle_nex";
305 // no weapon specific image for this weapon