338 lines
6.6 KiB
Plaintext
338 lines
6.6 KiB
Plaintext
/*
|
|
* Copyright (c) 2016-2020 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_knife (0 0 1) (-16 -16 0) (16 16 32)
|
|
"model" "models/w_knife.mdl"
|
|
|
|
Household DEATH! (2003) ENTITY
|
|
|
|
Throwable Butcher/Cleaver Knife Weapon
|
|
|
|
*/
|
|
|
|
enum
|
|
{
|
|
KNIFE_IDLE1,
|
|
KNIFE_IDLE2,
|
|
KNIFE_IDLE3,
|
|
KNIFE_THROW,
|
|
KNIFE_DRAW,
|
|
KNIFE_HOLSTER
|
|
};
|
|
|
|
void
|
|
w_knife_precache(void)
|
|
{
|
|
#ifdef SERVER
|
|
Sound_Precache("weapon_knife.hitbody");
|
|
Sound_Precache("weapon_knife.move");
|
|
Sound_Precache("weapon_knife.stick");
|
|
Sound_Precache("weapon_knife.throw");
|
|
precache_model("models/w_knife.mdl");
|
|
precache_model("models/knife.mdl");
|
|
#else
|
|
precache_model("sprites/hud_knife.spr");
|
|
precache_model("models/v_knife.mdl");
|
|
precache_model("models/p_knife.mdl");
|
|
g_crossKnife = spriteframe("sprites/cross_knife.spr", 0, 0.0);
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_knife_updateammo(player pl)
|
|
{
|
|
Weapons_UpdateAmmo(pl, -1, pl.ammo_knives, -1);
|
|
}
|
|
|
|
string
|
|
w_knife_wmodel(void)
|
|
{
|
|
return "models/w_knife.mdl";
|
|
}
|
|
|
|
string
|
|
w_knife_pmodel(player pl)
|
|
{
|
|
return "models/p_knife.mdl";
|
|
}
|
|
|
|
string
|
|
w_knife_deathmsg(void)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
int
|
|
w_knife_pickup(player pl, int new, int startammo)
|
|
{
|
|
#ifdef SERVER
|
|
|
|
if (pl.ammo_knives < MAX_A_KNIVES) {
|
|
pl.ammo_knives = bound(0, pl.ammo_knives + 1, MAX_A_KNIVES);
|
|
} else {
|
|
return (0);
|
|
}
|
|
#endif
|
|
return (1);
|
|
}
|
|
|
|
void
|
|
w_knife_draw(player pl)
|
|
{
|
|
Weapons_SetModel("models/v_knife.mdl");
|
|
Weapons_ViewAnimation(pl, KNIFE_DRAW);
|
|
|
|
#ifdef SERVER
|
|
if (!pl.ammo_knives) {
|
|
Weapons_RemoveItem(pl, WEAPON_KNIFE);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_knife_holster(player pl)
|
|
{
|
|
Weapons_ViewAnimation(pl, KNIFE_HOLSTER);
|
|
}
|
|
|
|
void
|
|
w_knife_primary(player pl)
|
|
{
|
|
|
|
if (pl.w_attack_next > 0.0) {
|
|
return;
|
|
}
|
|
|
|
/* Ammo check */
|
|
if (pl.ammo_knives <= 0) {
|
|
return;
|
|
}
|
|
|
|
/* Actual firing */
|
|
#ifdef SERVER
|
|
static void Knife_Touch(void) {
|
|
/* Has two submodels, changes random in view and world model */
|
|
setmodel(self, "models/knife.mdl");
|
|
|
|
/* Bleed and remove model if player, stick and spark if wall */
|
|
if (trace_ent.iBleeds) {
|
|
FX_Blood(trace_endpos, [1,0,0]);
|
|
remove(self);
|
|
} else {
|
|
pointparticles(particleeffectnum("fx_spark.main"), trace_endpos, trace_plane_normal, 1);
|
|
}
|
|
|
|
if (other.takedamage == DAMAGE_YES) {
|
|
Damage_Apply(other, self.owner, 15, WEAPON_KNIFE, DMG_GENERIC);
|
|
Sound_Play(self, CHAN_WEAPON, "weapon_knife.hitbody");
|
|
} else {
|
|
Sound_Play(self, CHAN_WEAPON, "weapon_knife.stick");
|
|
}
|
|
self.movetype = MOVETYPE_NONE;
|
|
}
|
|
|
|
Weapons_MakeVectors(pl);
|
|
entity knife = spawn();
|
|
setmodel(knife, "models/w_knife.mdl");
|
|
setorigin(knife, Weapons_GetCameraPos(pl));
|
|
knife.owner = self;
|
|
knife.velocity = v_forward * 1200;
|
|
knife.movetype = MOVETYPE_FLY;
|
|
knife.solid = SOLID_BBOX;
|
|
knife.angles = vectoangles(knife.velocity);
|
|
knife.avelocity[2] = 10;
|
|
knife.touch = Knife_Touch;
|
|
/* TODO Knife randomly changes submodel upon firing, no API support yet
|
|
* int r = (float)input_sequence % 2;
|
|
* setcustomskin(knife, "", r == 1 ? "geomset 1 0\n" : "geomset 1 1\n"); */
|
|
setsize(knife, [0,0,0], [0,0,0]);
|
|
|
|
/* The thrown knife has it's own movement sound */
|
|
Sound_Play(knife, CHAN_WEAPON, "weapon_knife.move");
|
|
|
|
Sound_Play(pl, CHAN_WEAPON, "weapon_knife.throw");
|
|
|
|
/* Remove weapon if we run out of knives */
|
|
if (pl.ammo_knives <= 0) {
|
|
Weapons_RemoveItem(pl, WEAPON_KNIFE);
|
|
return;
|
|
}
|
|
#else
|
|
/* Knife randomly changes submodel upon firing */
|
|
int r = (float)input_sequence % 2;
|
|
Weapons_SetGeomset(r == 1 ? "geomset 0 0\n" : "geomset 0 1\n");
|
|
#endif
|
|
|
|
pl.ammo_knives--;
|
|
Weapons_ViewPunchAngle(pl, [-2,0,0]);
|
|
Weapons_ViewAnimation(pl, KNIFE_THROW);
|
|
|
|
pl.w_attack_next = 0.8f;
|
|
pl.w_idle_next = 5.0f;
|
|
}
|
|
|
|
void
|
|
w_knife_release(player pl)
|
|
{
|
|
if (pl.w_idle_next > 0.0) {
|
|
if (pl.w_attack_next <= 0.0) {
|
|
#ifdef SERVER
|
|
if (!pl.ammo_knives) {
|
|
Weapons_RemoveItem(pl, WEAPON_KNIFE);
|
|
}
|
|
#endif
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (pl.w_idle_next > 0.0) {
|
|
return;
|
|
}
|
|
|
|
int r;
|
|
r = (float)input_sequence % 3;
|
|
switch (r) {
|
|
case 1:
|
|
Weapons_ViewAnimation(pl, KNIFE_IDLE1);
|
|
pl.w_idle_next = 2.0f;
|
|
break;
|
|
case 2:
|
|
Weapons_ViewAnimation(pl, KNIFE_IDLE2);
|
|
pl.w_idle_next = 3.0f;
|
|
break;
|
|
default:
|
|
Weapons_ViewAnimation(pl, KNIFE_IDLE3);
|
|
pl.w_idle_next = 1.285f;
|
|
}
|
|
}
|
|
|
|
void
|
|
w_knife_crosshair(player pl)
|
|
{
|
|
#ifdef CLIENT
|
|
static vector cross_pos;
|
|
cross_pos = g_hudmins + (g_hudres / 2) + [-12,-12];
|
|
drawsubpic(
|
|
cross_pos,
|
|
[32,32],
|
|
g_crossKnife,
|
|
[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_knife.spr_0.tga",
|
|
[32,64],
|
|
[1,1,1],
|
|
pSeatLocal->m_flAmmo2Alpha,
|
|
0
|
|
);
|
|
#endif
|
|
}
|
|
|
|
float
|
|
w_knife_aimanim(player pl)
|
|
{
|
|
return self.flags & FL_CROUCHING ? ANIM_CR_AIMBOW : ANIM_AIMBOW;
|
|
}
|
|
|
|
int
|
|
w_knife_isempty(player pl)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
w_knife_hudpic(player pl, int selected, vector pos, float a)
|
|
{
|
|
#ifdef CLIENT
|
|
if (w_knife_isempty(pl)) {
|
|
drawsubpic(
|
|
pos,
|
|
[80,40],
|
|
g_sprWeapons,
|
|
[80/256,120/256],
|
|
[80/256,40/256],
|
|
[1,1,1],
|
|
a,
|
|
DRAWFLAG_NORMAL
|
|
);
|
|
} else {
|
|
drawsubpic(
|
|
pos,
|
|
[80,40],
|
|
g_sprWeapons,
|
|
[0,120/256],
|
|
[80/256,40/256],
|
|
[1,1,1],
|
|
a,
|
|
DRAWFLAG_NORMAL
|
|
);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
weapontype_t w_knife_type(player pl)
|
|
{
|
|
return WPNTYPE_CLOSE;
|
|
}
|
|
|
|
weapon_t w_knife =
|
|
{
|
|
.name = "knife",
|
|
.id = ITEM_KNIFE,
|
|
.slot = 0,
|
|
.slot_pos = 3,
|
|
.draw = w_knife_draw,
|
|
.holster = w_knife_holster,
|
|
.primary = w_knife_primary,
|
|
.secondary = __NULL__,
|
|
.reload = __NULL__,
|
|
.release = w_knife_release,
|
|
.postdraw = w_knife_crosshair,
|
|
.precache = w_knife_precache,
|
|
.pickup = w_knife_pickup,
|
|
.updateammo = w_knife_updateammo,
|
|
.wmodel = w_knife_wmodel,
|
|
.pmodel = w_knife_pmodel,
|
|
.deathmsg = w_knife_deathmsg,
|
|
.aimanim = w_knife_aimanim,
|
|
.hudpic = w_knife_hudpic,
|
|
.weight = 5,
|
|
.isempty = w_knife_isempty,
|
|
.type = w_knife_type
|
|
};
|
|
|
|
#ifdef SERVER
|
|
void
|
|
weapon_knife(void)
|
|
{
|
|
Weapons_InitItem(WEAPON_KNIFE);
|
|
/*item_pickup item = (item_pickup)self;
|
|
item.SetRenderMode(RM_FULLBRIGHT);
|
|
item.SetRenderAmt(1.0f);
|
|
item.SetFloating(TRUE);*/
|
|
}
|
|
#endif
|
|
|