299 lines
5.4 KiB
Plaintext
299 lines
5.4 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_handgrenade (0 0 1) (-16 -16 0) (16 16 32)
|
|
"model" "models/w_lego.mdl"
|
|
|
|
HALF-LIFE (1998) ENTITY
|
|
|
|
Handgrenade Weapon
|
|
|
|
*/
|
|
|
|
enum
|
|
{
|
|
LEGO_IDLE,
|
|
LEGO_DRAW,
|
|
LEGO_PULLPIN,
|
|
LEGO_THROW,
|
|
LEGO_HOLSTER
|
|
};
|
|
|
|
void
|
|
w_lego_precache(void)
|
|
{
|
|
#ifdef CLIENT
|
|
precache_model("sprites/hud_lego.spr");
|
|
precache_model("models/v_lego.mdl");
|
|
precache_model("models/p_lego.mdl");
|
|
#else
|
|
precache_model("models/w_lego.mdl");
|
|
precache_model("models/lego2.mdl");
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_lego_updateammo(player pl)
|
|
{
|
|
Weapons_UpdateAmmo(pl, -1, pl.ammo_legogrenade, -1);
|
|
}
|
|
|
|
string
|
|
w_lego_wmodel(void)
|
|
{
|
|
return "models/w_lego.mdl";
|
|
}
|
|
|
|
string
|
|
w_lego_pmodel(player pl)
|
|
{
|
|
return "models/p_lego.mdl";
|
|
}
|
|
|
|
string
|
|
w_lego_deathmsg(void)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
int
|
|
w_lego_pickup(player pl, int new, int startammo)
|
|
{
|
|
#ifdef SERVER
|
|
|
|
if (pl.ammo_legogrenade < MAX_A_LEGOGRENADE) {
|
|
pl.ammo_legogrenade = bound(0, pl.ammo_legogrenade + 1, MAX_A_LEGOGRENADE);
|
|
} else {
|
|
return (0);
|
|
}
|
|
#endif
|
|
return (1);
|
|
}
|
|
|
|
#ifdef SERVER
|
|
void
|
|
w_lego_throw(player pl)
|
|
{
|
|
static void WeaponLego_Throw_Touch(void) {
|
|
float dmg = Skill_GetValue("plr_hand_grenade", 150);
|
|
FX_Lego(trace_endpos);
|
|
Damage_Radius(self.origin, self.owner, dmg, dmg * 1.5f, TRUE, WEAPON_LEGO);
|
|
remove(self);
|
|
}
|
|
|
|
vector vPLAngle = pl.v_angle;
|
|
if (vPLAngle[0] < 0) {
|
|
vPLAngle[0] = -10 + vPLAngle[0] * ((90 - 10) / 90.0);
|
|
} else {
|
|
vPLAngle[0] = -10 + vPLAngle[0] * ((90 + 10) / 90.0);
|
|
}
|
|
|
|
float flVel = (90 - vPLAngle[0]) * 5;
|
|
if (flVel > 1000) {
|
|
flVel = 1000;
|
|
}
|
|
|
|
makevectors(vPLAngle);
|
|
vector vecSrc = pl.origin + pl.view_ofs + v_forward * 16;
|
|
vector vecThrow = v_forward * flVel + pl.velocity;
|
|
|
|
entity eGrenade = spawn();
|
|
eGrenade.owner = pl;
|
|
eGrenade.classname = "remove_me";
|
|
eGrenade.solid = SOLID_BBOX;
|
|
eGrenade.frame = 1;
|
|
eGrenade.velocity = vecThrow;
|
|
eGrenade.movetype = MOVETYPE_BOUNCE;
|
|
eGrenade.touch = WeaponLego_Throw_Touch;
|
|
eGrenade.nextthink = time + 4.0f;
|
|
setmodel(eGrenade, "models/lego2.mdl");
|
|
setsize(eGrenade, [0,0,0], [0,0,0]);
|
|
setorigin(eGrenade, vecSrc);
|
|
}
|
|
#endif
|
|
|
|
void
|
|
w_lego_draw(player pl)
|
|
{
|
|
Weapons_SetModel("models/v_lego.mdl");
|
|
Weapons_ViewAnimation(pl, LEGO_DRAW);
|
|
}
|
|
|
|
void
|
|
w_lego_holster(player pl)
|
|
{
|
|
|
|
}
|
|
|
|
void
|
|
w_lego_primary(player pl)
|
|
{
|
|
if (pl.w_attack_next > 0.0) {
|
|
return;
|
|
}
|
|
|
|
/* We're abusing this network variable for the holding check */
|
|
if (pl.a_ammo3 > 0) {
|
|
return;
|
|
}
|
|
|
|
/* Ammo check */
|
|
if (pl.ammo_legogrenade <= 0) {
|
|
return;
|
|
}
|
|
|
|
Weapons_ViewAnimation(pl, LEGO_PULLPIN);
|
|
|
|
pl.a_ammo3 = 1;
|
|
pl.w_attack_next = 0.5f;
|
|
pl.w_idle_next = 0.5f;
|
|
}
|
|
|
|
void
|
|
w_lego_hud(player pl)
|
|
{
|
|
#ifdef CLIENT
|
|
HUD_DrawAmmo2();
|
|
|
|
vector aicon_pos = g_hudmins + [g_hudres[0] - 42, g_hudres[1] - 64];
|
|
drawpic(
|
|
aicon_pos,
|
|
"sprites/hud_lego.spr_0.tga",
|
|
[32,64],
|
|
[1,1,1],
|
|
pSeatLocal->m_flAmmo2Alpha,
|
|
0
|
|
);
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_lego_release(player pl)
|
|
{
|
|
|
|
if (pl.w_idle_next > 0.0) {
|
|
return;
|
|
}
|
|
|
|
if (pl.a_ammo3 == 1) {
|
|
#ifdef SERVER
|
|
w_lego_throw(pl);
|
|
#endif
|
|
pl.ammo_legogrenade--;
|
|
Weapons_ViewAnimation(pl, LEGO_THROW);
|
|
pl.a_ammo3 = 2;
|
|
pl.w_attack_next = 1.0f;
|
|
pl.w_idle_next = 0.5f;
|
|
} else if (pl.a_ammo3 == 2) {
|
|
Weapons_ViewAnimation(pl, LEGO_DRAW);
|
|
#ifdef SERVER
|
|
if (!pl.ammo_legogrenade) {
|
|
Weapons_RemoveItem(pl, WEAPON_LEGO);
|
|
}
|
|
#endif
|
|
pl.w_attack_next = 0.5f;
|
|
pl.w_idle_next = 0.5f;
|
|
pl.a_ammo3 = 0;
|
|
} else {
|
|
Weapons_ViewAnimation(pl, LEGO_IDLE);
|
|
pl.w_idle_next = 3.0f;
|
|
}
|
|
}
|
|
|
|
float
|
|
w_lego_aimanim(player pl)
|
|
{
|
|
return pl.flags & FL_CROUCHING ? ANIM_CR_AIMCROWBAR : ANIM_AIMCROWBAR;
|
|
}
|
|
|
|
int
|
|
w_lego_isempty(player pl)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
w_lego_hudpic(player pl, int selected, vector pos, float a)
|
|
{
|
|
#ifdef CLIENT
|
|
if (w_lego_isempty(pl)) {
|
|
drawsubpic(
|
|
pos,
|
|
[80,40],
|
|
g_sprWeapons,
|
|
[80/256,200/256],
|
|
[80/256,40/256],
|
|
[1,1,1],
|
|
a,
|
|
DRAWFLAG_NORMAL
|
|
);
|
|
} else {
|
|
drawsubpic(
|
|
pos,
|
|
[80,40],
|
|
g_sprWeapons,
|
|
[0,200/256],
|
|
[80/256,40/256],
|
|
[1,1,1],
|
|
a,
|
|
DRAWFLAG_NORMAL
|
|
);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
weapontype_t w_lego_type(player pl)
|
|
{
|
|
return WPNTYPE_RANGED;
|
|
}
|
|
|
|
weapon_t w_lego =
|
|
{
|
|
.name = "lego",
|
|
.id = ITEM_LEGO,
|
|
.slot = 0,
|
|
.slot_pos = 5,
|
|
.draw = w_lego_draw,
|
|
.holster = w_lego_holster,
|
|
.primary = w_lego_primary,
|
|
.secondary = __NULL__,
|
|
.reload = __NULL__,
|
|
.release = w_lego_release,
|
|
.postdraw = w_lego_hud,
|
|
.precache = w_lego_precache,
|
|
.pickup = w_lego_pickup,
|
|
.updateammo = w_lego_updateammo,
|
|
.wmodel = w_lego_wmodel,
|
|
.pmodel = w_lego_pmodel,
|
|
.deathmsg = w_lego_deathmsg,
|
|
.aimanim = w_lego_aimanim,
|
|
.hudpic = w_lego_hudpic,
|
|
.weight = 7,
|
|
.isempty = w_lego_isempty,
|
|
.type = w_lego_type
|
|
};
|
|
|
|
#ifdef SERVER
|
|
void
|
|
weapon_lego(void)
|
|
{
|
|
Weapons_InitItem(WEAPON_LEGO);
|
|
/*item_pickup item = (item_pickup)self;
|
|
item.SetRenderMode(RM_FULLBRIGHT);
|
|
item.SetRenderAmt(1.0f);*/
|
|
}
|
|
#endif
|