247 lines
4.8 KiB
Plaintext
247 lines
4.8 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.
|
|
*/
|
|
|
|
enum
|
|
{
|
|
BROOM_IDLE,
|
|
BROOM_DRAW,
|
|
BROOM_HOLSTER,
|
|
BROOM_ATTACK1HIT,
|
|
BROOM_ATTACK1MISS,
|
|
BROOM_ATTACK2MISS,
|
|
BROOM_ATTACK2HIT,
|
|
BROOM_ATTACK3MISS,
|
|
BROOM_ATTACK3HIT
|
|
};
|
|
|
|
void
|
|
w_broom_precache(void)
|
|
{
|
|
#ifdef SERVER
|
|
Sound_Precache("weapon_broom.hit");
|
|
Sound_Precache("weapon_broom.miss");
|
|
Sound_Precache("weapon_broom.hitbody");
|
|
precache_model("models/w_broom.mdl");
|
|
#else
|
|
precache_model("models/v_broom.mdl");
|
|
precache_model("models/p_broom.mdl");
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_broom_updateammo(player pl)
|
|
{
|
|
Weapons_UpdateAmmo(pl, -1, -1, -1);
|
|
}
|
|
|
|
string
|
|
w_broom_wmodel(void)
|
|
{
|
|
return "models/w_broom.mdl";
|
|
}
|
|
|
|
string
|
|
w_broom_pmodel(player pl)
|
|
{
|
|
return "models/p_broom.mdl";
|
|
}
|
|
|
|
string
|
|
w_broom_deathmsg(void)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
void
|
|
w_broom_draw(player pl)
|
|
{
|
|
Weapons_SetModel("models/v_broom.mdl");
|
|
Weapons_ViewAnimation(pl, BROOM_DRAW);
|
|
}
|
|
|
|
void
|
|
w_broom_holster(player pl)
|
|
{
|
|
Weapons_ViewAnimation(pl, BROOM_HOLSTER);
|
|
}
|
|
|
|
void
|
|
w_broom_primary(player pl)
|
|
{
|
|
int anim = 0;
|
|
vector src;
|
|
|
|
if (pl.w_attack_next) {
|
|
return;
|
|
}
|
|
|
|
Weapons_MakeVectors(pl);
|
|
src = pl.origin + pl.view_ofs;
|
|
|
|
/* make sure we can gib corpses */
|
|
int oldhitcontents = self.hitcontentsmaski;
|
|
self.hitcontentsmaski = CONTENTBITS_POINTSOLID | CONTENTBIT_CORPSE;
|
|
traceline(src, src + (v_forward * 32), FALSE, pl);
|
|
self.hitcontentsmaski = oldhitcontents;
|
|
|
|
if (trace_fraction >= 1.0) {
|
|
pl.w_attack_next = 0.5f;
|
|
} else {
|
|
pl.w_attack_next = 0.25f;
|
|
}
|
|
pl.w_idle_next = 2.5f;
|
|
|
|
int r = (float)input_sequence % 3;
|
|
switch (r) {
|
|
case 0:
|
|
Weapons_ViewAnimation(pl, trace_fraction >= 1 ? BROOM_ATTACK1MISS:BROOM_ATTACK1HIT);
|
|
break;
|
|
case 1:
|
|
Weapons_ViewAnimation(pl, trace_fraction >= 1 ? BROOM_ATTACK2MISS:BROOM_ATTACK2HIT);
|
|
break;
|
|
default:
|
|
Weapons_ViewAnimation(pl, trace_fraction >= 1 ? BROOM_ATTACK3MISS:BROOM_ATTACK3HIT);
|
|
}
|
|
|
|
if (pl.flags & FL_CROUCHING) {
|
|
Animation_PlayerTop(pl, ANIM_SHOOTCROWBAR, 0.5f);
|
|
} else {
|
|
Animation_PlayerTop(pl, ANIM_CR_SHOOTCROWBAR, 0.42f);
|
|
}
|
|
|
|
#ifdef SERVER
|
|
|
|
Sound_Play(self, CHAN_WEAPON, "weapon_broom.miss");
|
|
|
|
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]);
|
|
}
|
|
|
|
if (trace_ent.takedamage) {
|
|
Damage_Apply(trace_ent, pl, Skill_GetValue("plr_crowbar", 10), WEAPON_BROOM, DMG_BLUNT);
|
|
if (trace_ent.iBleeds) {
|
|
Sound_Play(self, CHAN_WEAPON, "weapon_broom.hitbody");
|
|
}
|
|
} else {
|
|
Sound_Play(self, CHAN_WEAPON, "weapon_broom.hit");
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_broom_release(player pl)
|
|
{
|
|
|
|
if (pl.w_idle_next) {
|
|
return;
|
|
}
|
|
|
|
Weapons_ViewAnimation(pl, BROOM_IDLE);
|
|
pl.w_idle_next = 15.0f;
|
|
}
|
|
|
|
|
|
float
|
|
w_broom_aimanim(player pl)
|
|
{
|
|
return self.flags & FL_CROUCHING ? ANIM_CR_AIMCROWBAR : ANIM_AIMCROWBAR;
|
|
}
|
|
|
|
int
|
|
w_broom_isempty(player pl)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
w_broom_hudpic(player pl, int selected, vector pos, float a)
|
|
{
|
|
#ifdef CLIENT
|
|
if (w_broom_isempty(pl)) {
|
|
drawsubpic(
|
|
pos,
|
|
[80,40],
|
|
g_sprWeapons,
|
|
[80/256,0],
|
|
[80/256,40/256],
|
|
[1,1,1],
|
|
a,
|
|
DRAWFLAG_NORMAL
|
|
);
|
|
} else {
|
|
drawsubpic(
|
|
pos,
|
|
[80,40],
|
|
g_sprWeapons,
|
|
[0,0],
|
|
[80/256,40/256],
|
|
[1,1,1],
|
|
a,
|
|
DRAWFLAG_NORMAL
|
|
);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
weapontype_t w_broom_type(player pl)
|
|
{
|
|
return WPNTYPE_CLOSE;
|
|
}
|
|
|
|
weapon_t w_broom =
|
|
{
|
|
.name = "broom",
|
|
.id = ITEM_BROOM,
|
|
.slot = 0,
|
|
.slot_pos = 0,
|
|
.weight = 1,
|
|
.draw = w_broom_draw,
|
|
.holster = w_broom_holster,
|
|
.primary = w_broom_primary,
|
|
.secondary = __NULL__,
|
|
.reload = __NULL__,
|
|
.release = w_broom_release,
|
|
.postdraw = __NULL__,
|
|
.precache = w_broom_precache,
|
|
.pickup = __NULL__,
|
|
.updateammo = w_broom_updateammo,
|
|
.wmodel = w_broom_wmodel,
|
|
.pmodel = w_broom_pmodel,
|
|
.deathmsg = w_broom_deathmsg,
|
|
.aimanim = w_broom_aimanim,
|
|
.hudpic = w_broom_hudpic,
|
|
.isempty = w_broom_isempty,
|
|
.type = w_broom_type
|
|
};
|
|
|
|
/* entity definitions for pickups */
|
|
#ifdef SERVER
|
|
void
|
|
weapon_broom(void)
|
|
{
|
|
Weapons_InitItem(WEAPON_BROOM);
|
|
/*item_pickup item = (item_pickup)self;
|
|
item.SetRenderMode(RM_FULLBRIGHT);
|
|
item.SetRenderAmt(1.0f);*/
|
|
}
|
|
#endif
|