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 /* modelname */ "campingrifle",
11 /* model */ MDL_RIFLE_ITEM,
12 /* simplemdl */ "foobar",
13 /* crosshair */ "gfx/crosshairrifle 0.6",
14 /* wepimg */ "weaponrifle",
15 /* refname */ "rifle",
16 /* wepname */ _("Rifle")
19 #define RIFLE_SETTINGS(w_cvar,w_prop) RIFLE_SETTINGS_LIST(w_cvar, w_prop, RIFLE, rifle)
20 #define RIFLE_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
21 w_cvar(id, sn, BOTH, ammo) \
22 w_cvar(id, sn, BOTH, animtime) \
23 w_cvar(id, sn, BOTH, bullethail) \
24 w_cvar(id, sn, BOTH, burstcost) \
25 w_cvar(id, sn, BOTH, damage) \
26 w_cvar(id, sn, BOTH, force) \
27 w_cvar(id, sn, BOTH, refire) \
28 w_cvar(id, sn, BOTH, shots) \
29 w_cvar(id, sn, BOTH, solidpenetration) \
30 w_cvar(id, sn, BOTH, spread) \
31 w_cvar(id, sn, BOTH, tracer) \
32 w_cvar(id, sn, NONE, bursttime) \
33 w_cvar(id, sn, NONE, secondary) \
34 w_cvar(id, sn, SEC, reload) \
35 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
36 w_prop(id, sn, float, reloading_time, reload_time) \
37 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
38 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
39 w_prop(id, sn, string, weaponreplace, weaponreplace) \
40 w_prop(id, sn, float, weaponstart, weaponstart) \
41 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
42 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
45 RIFLE_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
46 .float rifle_accumulator;
51 void spawnfunc_weapon_rifle(void) { weapon_defaultspawnfunc(WEP_RIFLE.m_id); }
52 void spawnfunc_weapon_campingrifle(void) { spawnfunc_weapon_rifle(); }
53 void spawnfunc_weapon_sniperrifle(void) { spawnfunc_weapon_rifle(); }
55 void W_Rifle_FireBullet(float pSpread, float pDamage, float pForce, float pSolidPenetration, float pAmmo, int deathtype, float pTracer, float pShots, string pSound)
59 W_DecreaseAmmo(pAmmo);
61 W_SetupShot(self, true, 2, pSound, CH_WEAPON_A, pDamage * pShots);
63 Send_Effect(EFFECT_RIFLE_MUZZLEFLASH, w_shotorg, w_shotdir * 2000, 1);
65 if(self.BUTTON_ZOOM | self.BUTTON_ZOOMSCRIPT) // if zoomed, shoot from the eye
67 w_shotdir = v_forward;
68 w_shotorg = self.origin + self.view_ofs + ((w_shotorg - self.origin - self.view_ofs) * v_forward) * v_forward;
71 for(i = 0; i < pShots; ++i)
72 fireBullet(w_shotorg, w_shotdir, pSpread, pSolidPenetration, pDamage, pForce, deathtype, (pTracer ? EF_RED : EF_BLUE));
74 if(autocvar_g_casings >= 2)
75 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);
78 void W_Rifle_Attack(void)
80 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.m_id, WEP_CVAR_PRI(rifle, tracer), WEP_CVAR_PRI(rifle, shots), SND(CAMPINGRIFLE_FIRE));
83 void W_Rifle_Attack2(void)
85 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.m_id | HITTYPE_SECONDARY, WEP_CVAR_SEC(rifle, tracer), WEP_CVAR_SEC(rifle, shots), SND(CAMPINGRIFLE_FIRE2));
88 .void(void) rifle_bullethail_attackfunc;
89 .float rifle_bullethail_frame;
90 .float rifle_bullethail_animtime;
91 .float rifle_bullethail_refire;
92 void W_Rifle_BulletHail_Continue(void)
96 sw = self.switchweapon; // make it not detect weapon changes as reason to abort firing
97 af = ATTACK_FINISHED(self);
98 self.switchweapon = self.weapon;
99 ATTACK_FINISHED(self) = time;
100 LOG_INFO(ftos(self.WEP_AMMO(RIFLE)), "\n");
101 r = weapon_prepareattack(self.rifle_bullethail_frame == WFRAME_FIRE2, self.rifle_bullethail_refire);
102 if(self.switchweapon == self.weapon)
103 self.switchweapon = sw;
106 self.rifle_bullethail_attackfunc();
107 weapon_thinkf(self.rifle_bullethail_frame, self.rifle_bullethail_animtime, W_Rifle_BulletHail_Continue);
108 LOG_INFO("thinkf set\n");
112 ATTACK_FINISHED(self) = af; // reset attack_finished if we didn't fire, so the last shot enforces the refire time
113 LOG_INFO("out of ammo... ", ftos(self.weaponentity.state), "\n");
117 void W_Rifle_BulletHail(float mode, void(void) AttackFunc, float fr, float animtime, float refire)
119 // if we get here, we have at least one bullet to fire
124 self.rifle_bullethail_attackfunc = AttackFunc;
125 self.rifle_bullethail_frame = fr;
126 self.rifle_bullethail_animtime = animtime;
127 self.rifle_bullethail_refire = refire;
128 weapon_thinkf(fr, animtime, W_Rifle_BulletHail_Continue);
133 weapon_thinkf(fr, animtime, w_ready);
137 .float bot_secondary_riflemooth;
138 bool W_Rifle(entity thiswep, int req)
146 self.BUTTON_ATCK=false;
147 self.BUTTON_ATCK2=false;
148 if(vlen(self.origin-self.enemy.origin) > 1000)
149 self.bot_secondary_riflemooth = 0;
150 if(self.bot_secondary_riflemooth == 0)
152 if(bot_aim(1000000, 0, 0.001, false))
154 self.BUTTON_ATCK = true;
155 if(random() < 0.01) self.bot_secondary_riflemooth = 1;
160 if(bot_aim(1000000, 0, 0.001, false))
162 self.BUTTON_ATCK2 = true;
163 if(random() < 0.03) self.bot_secondary_riflemooth = 0;
171 if(autocvar_g_balance_rifle_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(rifle, ammo), WEP_CVAR_SEC(rifle, ammo))) // forced reload
172 _WEP_ACTION(self.weapon, WR_RELOAD);
175 self.rifle_accumulator = bound(time - WEP_CVAR(rifle, bursttime), self.rifle_accumulator, time);
177 if(weapon_prepareattack_check(0, WEP_CVAR_PRI(rifle, refire)))
178 if(time >= self.rifle_accumulator + WEP_CVAR_PRI(rifle, burstcost))
180 weapon_prepareattack_do(0, WEP_CVAR_PRI(rifle, refire));
181 W_Rifle_BulletHail(WEP_CVAR_PRI(rifle, bullethail), W_Rifle_Attack, WFRAME_FIRE1, WEP_CVAR_PRI(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
182 self.rifle_accumulator += WEP_CVAR_PRI(rifle, burstcost);
184 if(self.BUTTON_ATCK2)
186 if(WEP_CVAR(rifle, secondary))
188 if(WEP_CVAR_SEC(rifle, reload))
189 _WEP_ACTION(self.weapon, WR_RELOAD);
192 if(weapon_prepareattack_check(1, WEP_CVAR_SEC(rifle, refire)))
193 if(time >= self.rifle_accumulator + WEP_CVAR_SEC(rifle, burstcost))
195 weapon_prepareattack_do(1, WEP_CVAR_SEC(rifle, refire));
196 W_Rifle_BulletHail(WEP_CVAR_SEC(rifle, bullethail), W_Rifle_Attack2, WFRAME_FIRE2, WEP_CVAR_SEC(rifle, animtime), WEP_CVAR_PRI(rifle, refire));
197 self.rifle_accumulator += WEP_CVAR_SEC(rifle, burstcost);
208 RIFLE_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
213 ammo_amount = self.WEP_AMMO(RIFLE) >= WEP_CVAR_PRI(rifle, ammo);
214 ammo_amount += self.(weapon_load[WEP_RIFLE.m_id]) >= 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.m_id]) >= 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)), SND(RELOAD));
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 bool W_Rifle(entity thiswep, int req)
268 case WR_IMPACTEFFECT:
271 org2 = w_org + w_backoff * 2;
272 pointparticles(particleeffectnum(EFFECT_RIFLE_IMPACT), org2, w_backoff * 1000, 1);
276 sound(self, CH_SHOTS, SND_RIC1, VOL_BASE, ATTN_NORM);
277 else if(w_random < 0.4)
278 sound(self, CH_SHOTS, SND_RIC2, VOL_BASE, ATTN_NORM);
279 else if(w_random < 0.5)
280 sound(self, CH_SHOTS, SND_RIC3, VOL_BASE, ATTN_NORM);
287 if(autocvar_cl_reticle && autocvar_cl_reticle_weapon)
289 precache_pic("gfx/reticle_nex");
295 if(button_zoom || zoomscript_caught)
297 reticle_image = "gfx/reticle_nex";
302 // no weapon specific image for this weapon