2021-03-08 02:47:30 -08:00
|
|
|
/*
|
2022-03-13 16:58:53 -07:00
|
|
|
* Copyright (c) 2016-2021 Marco Cawthorne <marco@icculus.org>
|
2021-03-08 02:47:30 -08:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SNIPER_DRAW,
|
|
|
|
SNIPER_IDLE1,
|
|
|
|
SNIPER_FIRE1,
|
|
|
|
SNIPER_FIRE2,
|
|
|
|
SNIPER_RELOAD1,
|
|
|
|
SNIPER_RELOAD2,
|
|
|
|
SNIPER_RELOAD3,
|
|
|
|
SNIPER_IDLE2,
|
|
|
|
SNIPER_HOLSTER,
|
|
|
|
SNIPER_DRAW
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
w_sniperrifle_precache(void)
|
|
|
|
{
|
|
|
|
#ifdef SERVER
|
|
|
|
precache_model("models/w_m40a1.mdl");
|
|
|
|
precache_sound("weapons/sniper_fire.wav");
|
|
|
|
#else
|
|
|
|
precache_model("models/v_m40a1.mdl");
|
|
|
|
precache_model("models/p_m40a1.mdl");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_pickup(player pl, int new, int startammo)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
#ifdef SERVER
|
2023-06-28 08:53:25 -07:00
|
|
|
int addAmmo = (startammo == -1) ? 5 : startammo;
|
2021-03-08 02:47:30 -08:00
|
|
|
|
|
|
|
if (new) {
|
2023-06-28 08:53:25 -07:00
|
|
|
pl.sniper_mag = addAmmo;
|
2021-03-08 02:47:30 -08:00
|
|
|
} else {
|
|
|
|
if (pl.ammo_762 < MAX_A_762) {
|
2023-06-28 08:53:25 -07:00
|
|
|
pl.ammo_762 = bound(0, pl.ammo_762 + addAmmo, MAX_A_762);
|
2021-03-08 02:47:30 -08:00
|
|
|
} else {
|
2021-05-09 23:18:36 -07:00
|
|
|
return (0);
|
2021-03-08 02:47:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-05-09 23:18:36 -07:00
|
|
|
return (1);
|
2021-03-08 02:47:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
w_sniperrifle_updateammo(player pl)
|
|
|
|
{
|
|
|
|
Weapons_UpdateAmmo(pl, pl.sniper_mag, pl.ammo_762, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
w_sniperrifle_wmodel(void)
|
|
|
|
{
|
|
|
|
return "models/w_m40a1.mdl";
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_pmodel(player pl)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
return "models/p_m40a1.mdl";
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
w_sniperrifle_deathmsg(void)
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_draw(player pl)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
Weapons_SetModel("models/v_m40a1.mdl");
|
2022-03-15 19:34:53 -07:00
|
|
|
Weapons_ViewAnimation(pl, SNIPER_DRAW);
|
2021-03-08 02:47:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_holster(player pl)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
2022-03-15 19:34:53 -07:00
|
|
|
Weapons_ViewAnimation(pl, SNIPER_HOLSTER);
|
2021-03-08 02:47:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_primary(player pl)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
|
2021-05-08 08:47:25 -07:00
|
|
|
if (pl.w_attack_next > 0.0)
|
2021-03-08 02:47:30 -08:00
|
|
|
return;
|
2021-05-08 08:47:25 -07:00
|
|
|
if (pl.sniper_mag <= 0)
|
2021-03-08 02:47:30 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
pl.sniper_mag--;
|
2022-03-15 19:34:53 -07:00
|
|
|
Weapons_ViewPunchAngle(pl, [-10,0,0]);
|
2021-03-08 02:47:30 -08:00
|
|
|
|
|
|
|
if (pl.sniper_mag) {
|
2022-03-15 19:34:53 -07:00
|
|
|
Weapons_ViewAnimation(pl, SNIPER_FIRE1);
|
2021-03-08 02:47:30 -08:00
|
|
|
} else {
|
2022-03-15 19:34:53 -07:00
|
|
|
Weapons_ViewAnimation(pl, SNIPER_FIRE2);
|
2021-03-08 02:47:30 -08:00
|
|
|
}
|
2021-05-08 08:47:25 -07:00
|
|
|
|
|
|
|
#ifdef SERVER
|
2021-05-24 23:38:06 -07:00
|
|
|
if (pl.viewzoom != 1.0)
|
|
|
|
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, 65, [0, 0], WEAPON_SNIPERRIFLE);
|
|
|
|
else
|
|
|
|
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, 65, [0.05, 0.05], WEAPON_SNIPERRIFLE);
|
|
|
|
|
2021-05-08 08:47:25 -07:00
|
|
|
sound(pl, CHAN_WEAPON, "weapons/sniper_fire.wav", 1, ATTN_NORM);
|
|
|
|
#else
|
|
|
|
View_SetMuzzleflash(MUZZLE_SMALL);
|
2021-03-08 02:47:30 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
pl.w_attack_next = 1.75f;
|
|
|
|
pl.w_idle_next = 10.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_secondary(player pl)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
if (pl.w_attack_next > 0.0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Simple toggle of fovs */
|
|
|
|
if (pl.viewzoom == 1.0f) {
|
|
|
|
pl.viewzoom = 0.25f;
|
|
|
|
} else {
|
|
|
|
pl.viewzoom = 1.0f;
|
|
|
|
}
|
|
|
|
pl.w_attack_next = 0.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_reload(player pl)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
if (pl.w_attack_next > 0.0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pl.sniper_mag >= 5) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pl.ammo_762 <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Audio-Visual bit */
|
|
|
|
/* TODO has a couple reloading states */
|
2022-03-15 19:34:53 -07:00
|
|
|
Weapons_ViewAnimation(pl, SNIPER_RELOAD3);
|
2021-03-08 02:47:30 -08:00
|
|
|
#ifdef SERVER
|
2021-05-22 11:36:25 -07:00
|
|
|
static void w_sniperrifle_reload_done(void) {
|
|
|
|
player pl = (player)self;
|
|
|
|
Weapons_ReloadWeapon(pl, player::sniper_mag, player::ammo_762, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
pl.think = w_sniperrifle_reload_done;
|
|
|
|
pl.nextthink = time + 2.3f;
|
2021-03-08 02:47:30 -08:00
|
|
|
#endif
|
|
|
|
pl.w_attack_next = 2.3f;
|
|
|
|
pl.w_idle_next = 10.0f;
|
|
|
|
}
|
|
|
|
void
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_release(player pl)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
|
|
|
|
/* auto-reload if need be */
|
|
|
|
if (pl.w_attack_next <= 0.0)
|
|
|
|
if (pl.sniper_mag == 0 && pl.ammo_762 > 0) {
|
2022-03-15 19:34:53 -07:00
|
|
|
Weapons_Reload(pl);
|
2021-03-08 02:47:30 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pl.w_idle_next > 0.0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int r = (float)input_sequence % 2;
|
|
|
|
if (r == 1) {
|
2022-03-15 19:34:53 -07:00
|
|
|
Weapons_ViewAnimation(pl, SNIPER_IDLE1);
|
2021-03-08 02:47:30 -08:00
|
|
|
} else {
|
2022-03-15 19:34:53 -07:00
|
|
|
Weapons_ViewAnimation(pl, SNIPER_IDLE2);
|
2021-03-08 02:47:30 -08:00
|
|
|
}
|
|
|
|
pl.w_idle_next = 15.0f;
|
|
|
|
}
|
2021-05-08 08:47:25 -07:00
|
|
|
|
2021-03-08 02:47:30 -08:00
|
|
|
void
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_crosshair(player pl)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
#ifdef CLIENT
|
|
|
|
if (pl.viewzoom == 1.0f) {
|
2022-12-28 16:53:13 -08:00
|
|
|
Cross_DrawSub(
|
2023-06-07 13:55:36 -07:00
|
|
|
g_ofch1_spr,
|
2022-12-28 16:53:13 -08:00
|
|
|
[24,24],
|
2021-03-08 02:47:30 -08:00
|
|
|
[0,48/72],
|
2022-12-28 16:53:13 -08:00
|
|
|
[24/72, 24/72]
|
2021-03-08 02:47:30 -08:00
|
|
|
);
|
|
|
|
} else {
|
2022-12-28 16:53:13 -08:00
|
|
|
Cross_Draw(
|
2023-06-28 09:24:05 -07:00
|
|
|
g_ofch2_spr,
|
2022-12-28 16:53:13 -08:00
|
|
|
[256,256]
|
2021-03-08 02:47:30 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
HUD_DrawAmmo1();
|
|
|
|
HUD_DrawAmmo2();
|
|
|
|
|
|
|
|
vector aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42];
|
2021-03-31 04:43:59 -07:00
|
|
|
drawsubpic(aicon_pos, [24,24], "sprites/640hud7.spr_0.tga", [24/256,72/128], [24/256, 24/128], g_hud_color, pSeatLocal->m_flAmmo2Alpha, DRAWFLAG_ADDITIVE);
|
2021-03-08 02:47:30 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_aimanim(player pl)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
return self.flags & FL_CROUCHING ? ANIM_CR_AIMPYTHON : ANIM_AIMPYTHON;
|
|
|
|
}
|
|
|
|
|
2021-05-24 23:38:06 -07:00
|
|
|
int
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_isempty(player pl)
|
2021-05-24 23:38:06 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
if (pl.sniper_mag <= 0 && pl.ammo_762 <= 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-08 02:47:30 -08:00
|
|
|
void
|
2022-03-15 19:34:53 -07:00
|
|
|
w_sniperrifle_hudpic(player pl, int s, vector pos, float a)
|
2021-03-08 02:47:30 -08:00
|
|
|
{
|
|
|
|
#ifdef CLIENT
|
|
|
|
vector hud_col;
|
|
|
|
|
2022-03-15 19:34:53 -07:00
|
|
|
if (w_sniperrifle_isempty(pl))
|
2021-03-08 02:47:30 -08:00
|
|
|
hud_col = [1,0,0];
|
|
|
|
else
|
|
|
|
hud_col = g_hud_color;
|
|
|
|
|
|
|
|
HUD_DrawAmmoBar(pos, pl.ammo_762, MAX_A_762, a);
|
|
|
|
|
|
|
|
if (s) {
|
2023-06-07 13:55:36 -07:00
|
|
|
drawsubpic(pos, [170,45], g_ofhud4_spr, [0,135/256], [170/256,45/256], hud_col, a, DRAWFLAG_ADDITIVE);
|
2021-03-08 02:47:30 -08:00
|
|
|
} else {
|
2023-06-07 13:55:36 -07:00
|
|
|
drawsubpic(pos, [170,45], g_ofhud3_spr, [0,135/256], [170/256,45/256], hud_col, a, DRAWFLAG_ADDITIVE);
|
2021-03-08 02:47:30 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
weapon_t w_sniperrifle =
|
|
|
|
{
|
|
|
|
.name = "sniperrifle",
|
2021-05-08 08:47:25 -07:00
|
|
|
.id = ITEM_SNIPERRIFLE,
|
2021-03-08 02:47:30 -08:00
|
|
|
.slot = 5,
|
|
|
|
.slot_pos = 2,
|
|
|
|
.draw = w_sniperrifle_draw,
|
|
|
|
.holster = w_sniperrifle_holster,
|
|
|
|
.primary = w_sniperrifle_primary,
|
|
|
|
.secondary = w_sniperrifle_secondary,
|
|
|
|
.reload = w_sniperrifle_reload,
|
|
|
|
.release = w_sniperrifle_release,
|
2022-03-15 19:34:53 -07:00
|
|
|
.postdraw = w_sniperrifle_crosshair,
|
2021-03-08 02:47:30 -08:00
|
|
|
.precache = w_sniperrifle_precache,
|
|
|
|
.pickup = w_sniperrifle_pickup,
|
|
|
|
.updateammo = w_sniperrifle_updateammo,
|
|
|
|
.wmodel = w_sniperrifle_wmodel,
|
|
|
|
.pmodel = w_sniperrifle_pmodel,
|
|
|
|
.deathmsg = w_sniperrifle_deathmsg,
|
|
|
|
.aimanim = w_sniperrifle_aimanim,
|
2021-05-24 23:38:06 -07:00
|
|
|
.hudpic = w_sniperrifle_hudpic,
|
|
|
|
.isempty = w_sniperrifle_isempty
|
2023-05-27 13:02:08 -07:00
|
|
|
};
|