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 /* netname */ "rifle",
11 /* fullname */ _("Rifle")
14 #define RIFLE_SETTINGS(w_cvar,w_prop) \
15 w_cvar(WEP_RIFLE, rifle, MO_BOTH, ammo) \
16 w_cvar(WEP_RIFLE, rifle, MO_BOTH, animtime) \
17 w_cvar(WEP_RIFLE, rifle, MO_BOTH, bulletconstant) \
18 w_cvar(WEP_RIFLE, rifle, MO_BOTH, bullethail) \
19 w_cvar(WEP_RIFLE, rifle, MO_BOTH, burstcost) \
20 w_cvar(WEP_RIFLE, rifle, MO_BOTH, damage) \
21 w_cvar(WEP_RIFLE, rifle, MO_BOTH, force) \
22 w_cvar(WEP_RIFLE, rifle, MO_BOTH, lifetime) \
23 w_cvar(WEP_RIFLE, rifle, MO_BOTH, refire) \
24 w_cvar(WEP_RIFLE, rifle, MO_BOTH, shots) \
25 w_cvar(WEP_RIFLE, rifle, MO_BOTH, speed) \
26 w_cvar(WEP_RIFLE, rifle, MO_BOTH, spread) \
27 w_cvar(WEP_RIFLE, rifle, MO_BOTH, tracer) \
28 w_cvar(WEP_RIFLE, rifle, MO_NONE, bursttime) \
29 w_cvar(WEP_RIFLE, rifle, MO_NONE, secondary) \
30 w_cvar(WEP_RIFLE, rifle, MO_SEC, reload) \
31 w_prop(WEP_RIFLE, rifle, float, reloading_ammo, reload_ammo) \
32 w_prop(WEP_RIFLE, rifle, float, reloading_time, reload_time) \
33 w_prop(WEP_RIFLE, rifle, float, switchdelay_raise, switchdelay_raise) \
34 w_prop(WEP_RIFLE, rifle, float, switchdelay_drop, switchdelay_drop)
37 RIFLE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
38 .float rifle_accumulator;
42 void spawnfunc_weapon_rifle (void) { weapon_defaultspawnfunc(WEP_RIFLE); }
43 void spawnfunc_weapon_campingrifle (void) { spawnfunc_weapon_rifle(); }
44 void spawnfunc_weapon_sniperrifle (void) { spawnfunc_weapon_rifle(); }
46 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)
50 W_DecreaseAmmo(ammo_nails, pAmmo, autocvar_g_balance_rifle_reload_ammo);
52 W_SetupShot (self, TRUE, 2, pSound, CH_WEAPON_A, pDamage * pShots);
54 pointparticles(particleeffectnum("rifle_muzzleflash"), w_shotorg, w_shotdir * 2000, 1);
56 if(self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) // if zoomed, shoot from the eye
58 w_shotdir = v_forward;
59 w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
62 for(i = 0; i < pShots; ++i)
63 fireBallisticBullet(w_shotorg, w_shotdir, pSpread, pSpeed, pLifetime, pDamage, pForce, deathtype, (pTracer ? EF_RED : EF_BLUE), pBulletConstant);
64 endFireBallisticBullet();
66 if (autocvar_g_casings >= 2)
67 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);
72 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");
75 void W_Rifle_Attack2()
77 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");
80 .void(void) rifle_bullethail_attackfunc;
81 .float rifle_bullethail_frame;
82 .float rifle_bullethail_animtime;
83 .float rifle_bullethail_refire;
84 void W_Rifle_BulletHail_Continue()
88 sw = self.switchweapon; // make it not detect weapon changes as reason to abort firing
89 af = ATTACK_FINISHED(self);
90 self.switchweapon = self.weapon;
91 ATTACK_FINISHED(self) = time;
92 print(ftos(self.ammo_nails), "\n");
93 r = weapon_prepareattack(self.rifle_bullethail_frame == WFRAME_FIRE2, self.rifle_bullethail_refire);
94 if(self.switchweapon == self.weapon)
95 self.switchweapon = sw;
98 self.rifle_bullethail_attackfunc();
99 weapon_thinkf(self.rifle_bullethail_frame, self.rifle_bullethail_animtime, W_Rifle_BulletHail_Continue);
100 print("thinkf set\n");
104 ATTACK_FINISHED(self) = af; // reset attack_finished if we didn't fire, so the last shot enforces the refire time
105 print("out of ammo... ", ftos(self.weaponentity.state), "\n");
109 void W_Rifle_BulletHail(float mode, void(void) AttackFunc, float fr, float animtime, float refire)
111 // if we get here, we have at least one bullet to fire
116 self.rifle_bullethail_attackfunc = AttackFunc;
117 self.rifle_bullethail_frame = fr;
118 self.rifle_bullethail_animtime = animtime;
119 self.rifle_bullethail_refire = refire;
120 weapon_thinkf(fr, animtime, W_Rifle_BulletHail_Continue);
125 weapon_thinkf(fr, animtime, w_ready);
129 .float bot_secondary_riflemooth;
130 float w_rifle(float req)
138 self.BUTTON_ATCK=FALSE;
139 self.BUTTON_ATCK2=FALSE;
140 if(vlen(self.origin-self.enemy.origin) > 1000)
141 self.bot_secondary_riflemooth = 0;
142 if(self.bot_secondary_riflemooth == 0)
144 if(bot_aim(WEP_CVAR_PRI(rifle, speed), 0, WEP_CVAR_PRI(rifle, lifetime), FALSE))
146 self.BUTTON_ATCK = TRUE;
147 if(random() < 0.01) self.bot_secondary_riflemooth = 1;
152 if(bot_aim(WEP_CVAR_SEC(rifle, speed), 0, WEP_CVAR_SEC(rifle, lifetime), FALSE))
154 self.BUTTON_ATCK2 = TRUE;
155 if(random() < 0.03) self.bot_secondary_riflemooth = 0;
163 if(autocvar_g_balance_rifle_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo))) // forced reload
164 WEP_ACTION(self.weapon, WR_RELOAD);
167 self.rifle_accumulator = bound(time - WEP_CVAR(rifle, bursttime), self.rifle_accumulator, time);
168 if (self.BUTTON_ATCK)
169 if (weapon_prepareattack_check(0, WEP_CVAR_PRI(rifle, refire)))
170 if (time >= self.rifle_accumulator + WEP_CVAR_PRI(rifle, burstcost))
172 weapon_prepareattack_do(0, WEP_CVAR_PRI(rifle, refire));
173 W_Rifle_BulletHail(WEP_CVAR_PRI(rifle, bullethail), W_Rifle_Attack, WFRAME_FIRE1, WEP_CVAR_PRI(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
174 self.rifle_accumulator += WEP_CVAR_PRI(rifle, burstcost);
176 if (self.BUTTON_ATCK2)
178 if (WEP_CVAR(rifle, secondary))
180 if(WEP_CVAR_SEC(rifle, reload))
181 WEP_ACTION(self.weapon, WR_RELOAD);
184 if (weapon_prepareattack_check(1, WEP_CVAR_SEC(rifle, refire)))
185 if (time >= self.rifle_accumulator + WEP_CVAR_SEC(rifle, burstcost))
187 weapon_prepareattack_do(1, WEP_CVAR_SEC(rifle, refire));
188 W_Rifle_BulletHail(WEP_CVAR_SEC(rifle, bullethail), W_Rifle_Attack2, WFRAME_FIRE2, WEP_CVAR_SEC(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
189 self.rifle_accumulator += WEP_CVAR_SEC(rifle, burstcost);
200 precache_model ("models/weapons/g_campingrifle.md3");
201 precache_model ("models/weapons/v_campingrifle.md3");
202 precache_model ("models/weapons/h_campingrifle.iqm");
203 precache_sound ("weapons/campingrifle_fire.wav");
204 precache_sound ("weapons/campingrifle_fire2.wav");
205 RIFLE_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
210 self.current_ammo = ammo_nails;
215 ammo_amount = self.ammo_nails >= WEP_CVAR_PRI(rifle, ammo);
216 ammo_amount += self.(weapon_load[WEP_RIFLE]) >= WEP_CVAR_PRI(rifle, ammo);
221 ammo_amount = self.ammo_nails >= WEP_CVAR_SEC(rifle, ammo);
222 ammo_amount += self.(weapon_load[WEP_RIFLE]) >= WEP_CVAR_SEC(rifle, ammo);
227 RIFLE_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
232 self.rifle_accumulator = time - WEP_CVAR(rifle, bursttime);
237 W_Reload(min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo)), "weapons/reload.wav");
240 case WR_SUICIDEMESSAGE:
242 return WEAPON_THINKING_WITH_PORTALS;
246 if(w_deathtype & HITTYPE_SECONDARY)
248 if(w_deathtype & HITTYPE_BOUNCE)
249 return WEAPON_RIFLE_MURDER_HAIL_PIERCING;
251 return WEAPON_RIFLE_MURDER_HAIL;
255 if(w_deathtype & HITTYPE_BOUNCE)
256 return WEAPON_RIFLE_MURDER_PIERCING;
258 return WEAPON_RIFLE_MURDER;
266 float w_rifle(float req)
270 case WR_IMPACTEFFECT:
273 org2 = w_org + w_backoff * 2;
274 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
278 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
279 else if(w_random < 0.4)
280 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
281 else if(w_random < 0.5)
282 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
289 precache_sound("weapons/ric1.wav");
290 precache_sound("weapons/ric2.wav");
291 precache_sound("weapons/ric3.wav");