dmc/src/shared/w_shotgun.qc

235 lines
5.2 KiB
Plaintext

/*
* Copyright (c) 2023 Marco Cawthorne <marco@icculus.org>
*
* 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.
*/
/*QUAKED weapon_shotgun (0 0 1) (-16 -16 0) (16 16 32)
"model" "models/g_shotgun.mdl"
HALF-LIFE (1998) ENTITY
Shotgun Weapon
*/
enum
{
SHOTGUN_IDLE1,
SHOTGUN_FIRE1
};
#ifdef CLIENT
void w_shotgun_ejectshell(void)
{
static void w_shotgun_ejectshell_death(void) {
remove(self);
}
static void w_shotgun_ejectshell_touch(void) {
if (other == world)
Sound_Play(self, CHAN_BODY, "modelevent_shotgunshell.land");
}
entity eShell = spawn();
setmodel(eShell, "models/shotgunshell.mdl");
eShell.solid = SOLID_BBOX;
eShell.movetype = MOVETYPE_BOUNCE;
eShell.drawmask = MASK_ENGINE;
eShell.angles = [pSeat->m_eViewModel.angles[0], pSeat->m_eViewModel.angles[1], 0];
eShell.velocity = pSeat->m_vecPredictedVelocity;
makevectors(pSeat->m_eViewModel.angles);
eShell.velocity += (v_forward * 0);
eShell.velocity += (v_right * 80);
eShell.velocity += (v_up * 100);
eShell.touch = w_shotgun_ejectshell_touch;
eShell.avelocity = [0,45,900];
eShell.think = w_shotgun_ejectshell_death;
eShell.nextthink = time + 2.5f;
setsize(eShell, [0,0,0], [0,0,0]);
setorigin(eShell, pSeat->m_eViewModel.origin + (v_forward * 20) + (v_up * -16));
}
#endif
void w_shotgun_precache(void)
{
#ifdef SERVER
Sound_Precache("weapon_shotgun.shoot");
precache_model("models/g_shot.mdl");
precache_model("models/shotgunshell.mdl");
#else
precache_model("models/v_shot.mdl");
precache_model("models/p_shot.mdl");
precache_model("models/shotgunshell.mdl");
Sound_Precache("modelevent_shotgunshell.land");
#endif
}
void
w_shotgun_updateammo(player pl)
{
Weapons_UpdateAmmo(pl, -1, pl.ammo_shells, -1);
}
string
w_shotgun_wmodel(void)
{
return "models/g_shot.mdl";
}
string
w_shotgun_pmodel(player pl)
{
return "models/p_shot.mdl";
}
string
w_shotgun_deathmsg(void)
{
return "";
}
int
w_shotgun_pickup(player pl, int new, int startammo)
{
#ifdef SERVER
if (pl.ammo_shells < MAX_A_SHELLS) {
pl.ammo_shells = bound(0, pl.ammo_shells + 5, MAX_A_SHELLS);
} else {
if (!new)
return (0);
}
#endif
return (1);
}
void
w_shotgun_draw(player pl)
{
Weapons_SetModel("models/v_shot.mdl");
}
void
w_shotgun_primary(player pl)
{
if (pl.w_attack_next > 0.0)
return;
if (pl.ammo_shells <= 0)
return;
#ifdef SERVER
/* Singleplayer is more accurate */
TraceAttack_FireBulletsWithDecal(6, pl.origin + pl.view_ofs, Skill_GetValue("plr_shotgun_dmg", 4), [0.1,0.1], WEAPON_SHOTGUN, "Impact.BigShot");
Sound_Play(pl, CHAN_WEAPON, "weapon_shotgun.shoot");
#else
//View_AddEvent(w_shotgun_ejectshell, 0.25f);
#endif
Weapons_ViewAnimation(pl, SHOTGUN_FIRE1);
Weapons_ViewPunchAngle(pl, [-5,0,0]);
Animation_PlayerTop(pl, (pl.flags & FL_CROUCHING) ? ANIM_CR_SHOOTSHOTGUN : ANIM_SHOOTSHOTGUN, 0.5f);
pl.ammo_shells--;
pl.w_idle_next = 0.5f;
pl.w_attack_next = 0.5;
}
void
w_shotgun_crosshair(player pl)
{
#ifdef CLIENT
Cross_DrawSub(g_cross_spr, [24,24], [48/128,24/128], [0.1875, 0.1875]);
HUD_DrawAmmo2();
vector aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42];
drawsubpic(aicon_pos, [24,24], g_hudsgammo, [0, 0], [1,1], g_hud_color, pSeatLocal->m_flAmmo2Alpha, DRAWFLAG_ADDITIVE);
#endif
}
float
w_shotgun_aimanim(player pl)
{
return pl.flags & FL_CROUCHING ? ANIM_CR_AIMSHOTGUN : ANIM_AIMSHOTGUN;
}
int
w_shotgun_isempty(player pl)
{
if (pl.ammo_shells <= 0)
return 1;
return 0;
}
void
w_shotgun_hudpic(player pl, int selected, vector pos, float a)
{
#ifdef CLIENT
vector hud_col;
if (w_shotgun_isempty(pl))
hud_col = [1,0,0];
else
hud_col = g_hud_color;
if (selected) {
drawsubpic(pos, [170,45], g_hudsg_spr, [0,0], [1,0.625], hud_col, a, DRAWFLAG_ADDITIVE);
} else {
drawsubpic(pos, [170,45], g_hudsg_spr, [0,0], [1,0.625], hud_col, a, DRAWFLAG_ADDITIVE);
}
HUD_DrawAmmoBar(pos, pl.ammo_shells, MAX_A_SHELLS, a);
#endif
}
weapontype_t
w_shotgun_type(player pl)
{
return WPNTYPE_RANGED;
}
weapon_t w_shotgun =
{
.name = "shotgun",
.id = ITEM_SHOTGUN,
.slot = 1,
.slot_pos = 0,
.weight = 15,
.draw = w_shotgun_draw,
.holster = __NULL__,
.primary = w_shotgun_primary,
.secondary = __NULL__,
.reload = __NULL__,
.release = __NULL__,
.postdraw = w_shotgun_crosshair,
.precache = w_shotgun_precache,
.pickup = w_shotgun_pickup,
.updateammo = w_shotgun_updateammo,
.wmodel = w_shotgun_wmodel,
.pmodel = w_shotgun_pmodel,
.deathmsg = w_shotgun_deathmsg,
.aimanim = w_shotgun_aimanim,
.isempty = w_shotgun_isempty,
.type = w_shotgun_type,
.hudpic = w_shotgun_hudpic
};
#ifdef SERVER
void
weapon_shotgun(void)
{
Weapons_InitItem(WEAPON_SHOTGUN);
}
#endif