368 lines
6.9 KiB
Plaintext
368 lines
6.9 KiB
Plaintext
/*
|
|
* Copyright (c) 2016-2020 Marco Cawthorne <marco@icculus.org>
|
|
* Copyright (c) 2019-2020 Gethyn ThomasQuail <xylemon@posteo.net>
|
|
*
|
|
* 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_forks (0 0 1) (-16 -16 0) (16 16 32)
|
|
"model" "models/w_fork.mdl"
|
|
|
|
Household DEATH! (2003) ENTITY
|
|
|
|
Throwable Forks Weapon
|
|
|
|
Pile of 6 forks.
|
|
|
|
*/
|
|
|
|
enum
|
|
{
|
|
FORKS_IDLE1,
|
|
FORKS_IDLE2,
|
|
FORKS_IDLE3,
|
|
FORKS_STAB,
|
|
FORKS_THROW,
|
|
FORKS_DRAW,
|
|
FORKS_HOLSTER
|
|
};
|
|
|
|
void
|
|
w_forks_precache(void)
|
|
{
|
|
#ifdef SERVER
|
|
Sound_Precache("weapon_forks.hit");
|
|
Sound_Precache("weapon_forks.hitbody");
|
|
Sound_Precache("weapon_forks.stick");
|
|
Sound_Precache("weapon_forks.throw");
|
|
precache_model("models/fork.mdl");
|
|
precache_model("models/w_fork.mdl");
|
|
#else
|
|
precache_model("sprites/hud_fork.spr");
|
|
precache_model("models/v_fork.mdl");
|
|
precache_model("models/p_fork.mdl");
|
|
g_crossFork = spriteframe("sprites/cross_fork.spr", 0, 0.0);
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_forks_updateammo(player pl)
|
|
{
|
|
Weapons_UpdateAmmo(pl, -1, pl.ammo_forks, -1);
|
|
}
|
|
|
|
string
|
|
w_forks_wmodel(void)
|
|
{
|
|
return "models/w_forks.mdl";
|
|
}
|
|
string
|
|
w_forks_pmodel(player pl)
|
|
{
|
|
return "models/p_fork.mdl";
|
|
}
|
|
|
|
string
|
|
w_forks_deathmsg(void)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
int
|
|
w_forks_pickup(player pl, int new, int startammo)
|
|
{
|
|
#ifdef SERVER
|
|
if (pl.ammo_forks < MAX_A_FORKS) {
|
|
pl.ammo_forks = bound(0, pl.ammo_forks + 6, MAX_A_FORKS);
|
|
} else {
|
|
return (0);
|
|
}
|
|
#endif
|
|
return (1);
|
|
}
|
|
void
|
|
w_forks_draw(player pl)
|
|
{
|
|
Weapons_SetModel("models/v_fork.mdl");
|
|
Weapons_ViewAnimation(pl, FORKS_DRAW);
|
|
|
|
#ifdef SERVER
|
|
if (!pl.ammo_forks) {
|
|
Weapons_RemoveItem(pl, WEAPON_FORKS);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_forks_holster(player pl)
|
|
{
|
|
Weapons_ViewAnimation(pl, FORKS_HOLSTER);
|
|
}
|
|
|
|
void
|
|
w_forks_primary(player pl)
|
|
{
|
|
int anim = 0;
|
|
vector src;
|
|
|
|
if (pl.w_attack_next) {
|
|
return;
|
|
}
|
|
|
|
Weapons_MakeVectors(pl);
|
|
src = pl.origin + pl.view_ofs;
|
|
traceline(src, src + (v_forward * 32), FALSE, pl);
|
|
|
|
|
|
pl.w_attack_next = 0.4f;
|
|
pl.w_idle_next = 2.5f;
|
|
|
|
Weapons_ViewAnimation(pl, FORKS_STAB);
|
|
|
|
if (pl.flags & FL_CROUCHING) {
|
|
Animation_PlayerTop(pl, ANIM_SHOOTCROWBAR, 0.5f);
|
|
} else {
|
|
Animation_PlayerTop(pl, ANIM_CR_SHOOTCROWBAR, 0.42f);
|
|
}
|
|
|
|
#ifdef SERVER
|
|
|
|
if (trace_fraction >= 1.0) {
|
|
return;
|
|
}
|
|
|
|
/* don't bother with decals, we got squibs */
|
|
if (trace_ent.iBleeds) {
|
|
FX_Blood(trace_endpos, [1,0,0]);
|
|
} else {
|
|
SurfData_Impact(trace_ent, trace_endpos, trace_plane_normal);
|
|
}
|
|
|
|
if (trace_ent.takedamage) {
|
|
Damage_Apply(trace_ent, pl, 5, WEAPON_FORKS, DMG_BLUNT);
|
|
if (trace_ent.iBleeds) {
|
|
Sound_Play(self, CHAN_WEAPON, "weapon_forks.hitbody");
|
|
}
|
|
} else {
|
|
Sound_Play(self, CHAN_WEAPON, "weapon_forks.hit");
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_forks_secondary(player pl)
|
|
{
|
|
|
|
if (pl.w_attack_next > 0.0) {
|
|
return;
|
|
}
|
|
|
|
/* Ammo check */
|
|
if (pl.ammo_forks <= 0) {
|
|
return;
|
|
}
|
|
|
|
/* Secondary has an ammo based throw function */
|
|
#ifdef SERVER
|
|
static void Fork_Touch(void) {
|
|
setmodel(self, "models/fork.mdl");
|
|
|
|
/* don't bother with decals, we got squibs */
|
|
if (trace_ent.iBleeds) {
|
|
FX_Blood(trace_endpos, [1,0,0]);
|
|
remove(self);
|
|
} else {
|
|
SurfData_Impact(trace_ent, trace_endpos, trace_plane_normal);
|
|
}
|
|
|
|
if (other.takedamage == DAMAGE_YES) {
|
|
Damage_Apply(other, self.owner, 15, WEAPON_FORKS, DMG_GENERIC);
|
|
Sound_Play(self, CHAN_WEAPON, "weapon_forks.hitbody");
|
|
} else {
|
|
Sound_Play(self, CHAN_WEAPON, "weapon_forks.stick");
|
|
}
|
|
self.movetype = MOVETYPE_NONE;
|
|
}
|
|
|
|
Weapons_MakeVectors(pl);
|
|
entity fork = spawn();
|
|
setmodel(fork, "models/fork.mdl");
|
|
setorigin(fork, Weapons_GetCameraPos(pl) + (v_forward * 16));
|
|
fork.owner = self;
|
|
fork.velocity = v_forward * 2000;
|
|
fork.movetype = MOVETYPE_FLY;
|
|
fork.solid = SOLID_BBOX;
|
|
fork.angles = vectoangles(fork.velocity);
|
|
fork.avelocity[2] = 10;
|
|
fork.touch = Fork_Touch;
|
|
setsize(fork, [0,0,0], [0,0,0]);
|
|
|
|
Sound_Play(pl, CHAN_WEAPON, "weapon_forks.throw");
|
|
#endif
|
|
|
|
pl.ammo_forks--;
|
|
|
|
Weapons_ViewPunchAngle(pl, [-2,0,0]);
|
|
Weapons_ViewAnimation(pl, FORKS_THROW);
|
|
|
|
pl.w_attack_next = 0.5f;
|
|
pl.w_idle_next = 5.0f;
|
|
}
|
|
|
|
void
|
|
w_forks_release(player pl)
|
|
{
|
|
if (pl.w_idle_next > 0.0) {
|
|
if (pl.w_attack_next <= 0.0) {
|
|
#ifdef SERVER
|
|
if (!pl.ammo_forks) {
|
|
Weapons_RemoveItem(pl, WEAPON_FORKS);
|
|
}
|
|
#endif
|
|
}
|
|
return;
|
|
}
|
|
|
|
int r;
|
|
r = (float)input_sequence % 3;
|
|
switch (r) {
|
|
case 1:
|
|
Weapons_ViewAnimation(pl, FORKS_IDLE1);
|
|
pl.w_idle_next = 1.3f;
|
|
break;
|
|
case 2:
|
|
Weapons_ViewAnimation(pl, FORKS_IDLE2);
|
|
pl.w_idle_next = 3.0f;
|
|
break;
|
|
default:
|
|
Weapons_ViewAnimation(pl, FORKS_IDLE3);
|
|
pl.w_idle_next = 1.285f;
|
|
}
|
|
}
|
|
|
|
void
|
|
w_forks_crosshair(player pl)
|
|
{
|
|
#ifdef CLIENT
|
|
static vector cross_pos;
|
|
cross_pos = g_hudmins + (g_hudres / 2) + [-16,-16];
|
|
drawsubpic(
|
|
cross_pos,
|
|
[32,32],
|
|
g_crossFork,
|
|
[0,0],
|
|
[1, 1],
|
|
[1,0,0],
|
|
1,
|
|
DRAWFLAG_NORMAL
|
|
);
|
|
|
|
HUD_DrawAmmo2();
|
|
|
|
vector aicon_pos = g_hudmins + [g_hudres[0] - 42, g_hudres[1] - 64];
|
|
drawpic(
|
|
aicon_pos,
|
|
"sprites/hud_fork.spr_0.tga",
|
|
[32,64],
|
|
[1,1,1],
|
|
pSeatLocal->m_flAmmo2Alpha,
|
|
0
|
|
);
|
|
#endif
|
|
}
|
|
|
|
float
|
|
w_forks_aimanim(player pl)
|
|
{
|
|
return w_broom_aimanim(pl);
|
|
}
|
|
|
|
int
|
|
w_forks_isempty(player pl)
|
|
{
|
|
return (pl.ammo_forks <= 0) ? true : false;
|
|
}
|
|
|
|
void
|
|
w_forks_hudpic(player pl, int selected, vector pos, float a)
|
|
{
|
|
#ifdef CLIENT
|
|
if (w_forks_isempty(pl)) {
|
|
drawsubpic(
|
|
pos,
|
|
[80,40],
|
|
g_sprWeapons,
|
|
[80/256,80/256],
|
|
[80/256,40/256],
|
|
[1,1,1],
|
|
a,
|
|
DRAWFLAG_NORMAL
|
|
);
|
|
} else {
|
|
drawsubpic(
|
|
pos,
|
|
[80,40],
|
|
g_sprWeapons,
|
|
[0,80/256],
|
|
[80/256,40/256],
|
|
[1,1,1],
|
|
a,
|
|
DRAWFLAG_NORMAL
|
|
);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
weapontype_t w_forks_type(player pl)
|
|
{
|
|
return WPNTYPE_RANGED;
|
|
}
|
|
|
|
weapon_t w_forks =
|
|
{
|
|
.name = "fork",
|
|
.id = ITEM_FORKS,
|
|
.slot = 0,
|
|
.slot_pos = 2,
|
|
.draw = w_forks_draw,
|
|
.holster = w_forks_holster,
|
|
.primary = w_forks_primary,
|
|
.secondary = w_forks_secondary,
|
|
.reload = __NULL__,
|
|
.release = w_forks_release,
|
|
.postdraw = w_forks_crosshair,
|
|
.precache = w_forks_precache,
|
|
.pickup = w_forks_pickup,
|
|
.updateammo = w_forks_updateammo,
|
|
.wmodel = w_forks_wmodel,
|
|
.pmodel = w_forks_pmodel,
|
|
.deathmsg = w_forks_deathmsg,
|
|
.aimanim = w_forks_aimanim,
|
|
.hudpic = w_forks_hudpic,
|
|
.weight = 3,
|
|
.isempty = w_forks_isempty,
|
|
.type = w_forks_type
|
|
};
|
|
|
|
/* entity definitions for pickups */
|
|
#ifdef SERVER
|
|
void
|
|
weapon_forks(void)
|
|
{
|
|
Weapons_InitItem(WEAPON_FORKS);
|
|
/*item_pickup item = (item_pickup)self;
|
|
item.SetRenderMode(RM_FULLBRIGHT);
|
|
item.SetRenderAmt(1.0f);*/
|
|
}
|
|
#endif
|