dmc/src/shared/w_multi_rocket.qc

219 lines
4.7 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_rocketlauncher (0 0 1) (-16 -16 0) (16 16 32)
"model" "models/g_rock2.mdl"
HALF-LIFE (1998) ENTITY
RPG Weapon
*/
enum
{
RPG_IDLE,
RPG_SHOOT
};
void
w_multi_rocket_precache(void)
{
#ifdef SERVER
Sound_Precache("weapon_rocketlauncher.shoot");
Sound_Precache("weapon_rocketlauncher.explode");
precache_model("models/g_mrock2.mdl");
precache_model("models/mrocket.mdl");
#else
precache_model("models/v_mrock2.mdl");
precache_model("models/p_mrock2.mdl");
#endif
}
void
w_multi_rocket_updateammo(player pl)
{
Weapons_UpdateAmmo(pl, -1, pl.ammo_rockets, -1);
}
string
w_multi_rocket_wmodel(void)
{
return "models/g_mrock2.mdl";
}
string
w_multi_rocket_pmodel(player pl)
{
return "models/p_mrock2.mdl";
}
string
w_multi_rocket_deathmsg(void)
{
return "";
}
int
w_multi_rocket_pickup(player pl, int new, int startammo)
{
#ifdef SERVER
if (pl.ammo_rockets < MAX_A_ROCKETS) {
pl.ammo_rockets = bound(0, pl.ammo_rockets + 5, MAX_A_ROCKETS);
} else {
if (!new)
return (0);
}
#endif
return (1);
}
void
w_multi_rocket_draw(player pl)
{
Weapons_SetModel("models/v_mrock2.mdl");
Weapons_ViewAnimation(pl, RPG_IDLE);
}
void
w_multi_rocket_primary(player pl)
{
if (pl.w_attack_next > 0.0)
return;
if (pl.ammo_rockets <= 0) {
Weapons_SwitchBest(pl, 0);
return;
}
/* visual fluff */
Weapons_ViewAnimation(pl, RPG_SHOOT);
Weapons_ViewPunchAngle(pl, [-10,0,0]);
Animation_PlayerTop(pl, (pl.flags & FL_CROUCHING) ? ANIM_CR_SHOOTGAUSS : ANIM_SHOOTGAUSS, 0.43f);
pl.w_attack_next = 0.8f;
pl.ammo_rockets--;
#ifdef SERVER
vector startPos;
Weapons_MakeVectors(pl);
startPos = Weapons_GetCameraPos(pl) + (v_forward * 16) + (v_up * -5);
NSProjectile_SpawnDefAtPosition("projectile_mrocket", pl, startPos, pl.v_angle + [0, -10, 0] * 0.66);
NSProjectile_SpawnDefAtPosition("projectile_mrocket", pl, startPos, pl.v_angle + [0, -5, 0] * 0.66);
NSProjectile_SpawnDefAtPosition("projectile_mrocket", pl, startPos, pl.v_angle + [0, 5, 0] * 0.66);
NSProjectile_SpawnDefAtPosition("projectile_mrocket", pl, startPos, pl.v_angle + [0, 10, 0] * 0.66);
Sound_Play(pl, CHAN_WEAPON, "weapon_rocketlauncher.shoot");
if (pl.HasQuadDamage()) {
Sound_Play(pl, CHAN_ITEM, "item_artifact_super_damage.attack");
}
#endif
}
float
w_multi_rocket_aimanim(player pl)
{
return pl.flags & FL_CROUCHING ? ANIM_CR_AIMGAUSS : ANIM_AIMGAUSS;
}
int
w_multi_rocket_isempty(player pl)
{
if (pl.ammo_rockets <= 0)
return 1;
return 0;
}
void
w_multi_rocket_hudpic(player pl, int selected, vector pos, float a)
{
#ifdef CLIENT
vector hud_col;
if (w_multi_rocket_isempty(pl))
hud_col = [1,0,0];
else
hud_col = g_hud_color;
if (selected) {
drawsubpic(pos, [170,45], g_hudrl_spr, [0,0], [1,0.625], hud_col, a, DRAWFLAG_ADDITIVE);
} else {
drawsubpic(pos, [170,45], g_hudrl_spr, [0,0], [1,0.625], hud_col, a, DRAWFLAG_ADDITIVE);
}
HUD_DrawAmmoBar(pos, pl.ammo_rockets, MAX_A_ROCKETS, a);
#endif
}
void
w_multi_rocket_hud(player pl)
{
#ifdef CLIENT
vector aicon_pos;
HUD_DrawQuakeCrosshair();
HUD_DrawAmmo2();
/* ammo icon */
aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42];
drawsubpic(
aicon_pos,
[24,24],
g_hudrlammo,
[0, 0],
[24/24, 24/24],
g_hud_color,
pSeatLocal->m_flAmmo2Alpha,
DRAWFLAG_ADDITIVE
);
#endif
}
weapontype_t
w_multi_rocket_type(player pl)
{
return WPNTYPE_RANGED;
}
weapon_t
w_multi_rocket =
{
.name = "rocketl",
.id = ITEM_MULTIROCKET,
.slot = 6,
.slot_pos = 1,
.weight = 2,
.draw = w_multi_rocket_draw,
.holster = __NULL__,
.primary = w_multi_rocket_primary,
.secondary = __NULL__,
.reload = __NULL__,
.release = __NULL__,
.postdraw = w_multi_rocket_hud,
.precache = w_multi_rocket_precache,
.pickup = w_multi_rocket_pickup,
.updateammo = w_multi_rocket_updateammo,
.wmodel = w_multi_rocket_wmodel,
.pmodel = w_multi_rocket_pmodel,
.deathmsg = w_multi_rocket_deathmsg,
.aimanim = w_multi_rocket_aimanim,
.isempty = w_multi_rocket_isempty,
.type = w_multi_rocket_type,
.hudpic = w_multi_rocket_hudpic
};