hhdeath/src/shared/w_sodalauncher.qc

365 lines
7.2 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_sodalauncher (0 0 1) (-16 -16 0) (16 16 32)
"model" "models/w_soda.mdl"
HALF-LIFE (1998) ENTITY
MP5/9mmAR Weapon
Same as weapon_9mmAR
*/
/* Animations */
enum
{
SODA_IDLE,
SODA_IDLE_NOSODA,
SODA_SHOOT_RELOAD,
SODA_SHOOT,
SODA_DRAW,
SODA_DRAW_NOSODA,
SODA_HOLSTER,
SODA_HOLSTER_NOSODA
};
void
w_sodalauncher_precache(void)
{
#ifdef SERVER
Sound_Precache("weapon_sodalauncher.fire");
Sound_Precache("weapon_sodalauncher.explode");
precache_model("models/sodacan.mdl");
precache_model("models/w_soda.mdl");
#else
precache_model("sprites/hud_sodacan.spr");
precache_model("sprites/co2_puff.spr");
precache_model("models/v_soda.mdl");
precache_model("models/p_soda.mdl");
g_crossSoda = spriteframe("sprites/cross_soda.spr", 0, 0.0);
#endif
}
int
w_sodalauncher_pickup(player pl, int new, int startammo)
{
#ifdef SERVER
if (pl.ammo_soda < MAX_A_SODA) {
pl.ammo_soda = bound(0, pl.ammo_soda + 3, MAX_A_SODA);
} else {
return (0);
}
#endif
return (1);
}
void
w_sodalauncher_updateammo(player pl)
{
Weapons_UpdateAmmo(pl, -1, pl.ammo_soda, -1);
}
string
w_sodalauncher_wmodel(void)
{
return "models/w_soda.mdl";
}
string
w_sodalauncher_pmodel(player pl)
{
return "models/p_soda.mdl";
}
string
w_sodalauncher_deathmsg(void)
{
return "";
}
void
w_sodalauncher_draw(player pl)
{
Weapons_SetModel("models/v_soda.mdl");
Weapons_ViewAnimation(pl, SODA_DRAW);
}
void
w_sodalauncher_holster(player pl)
{
Weapons_ViewAnimation(pl, SODA_HOLSTER);
}
/* TODO now just need parameters */
#ifdef SERVER
void
w_sodalauncher_shoot(player pl)
{
/* Apply force */
if (pl.flags & FL_ONGROUND) {
pl.velocity += v_forward * -100;
} else {
pl.velocity += v_forward * -300;
}
static void Soda_ExplodeTouch(void) {
float dmg = Skill_GetValue("plr_9mmAR_grenade", 150);
FX_Soda(trace_endpos, self.skin);
Damage_Radius(self.origin, self.owner, dmg, dmg * 2.5f, TRUE, WEAPON_SODALAUNCHER);
Sound_Play(self, 1, "weapon_sodalauncher.explode");
remove(self);
}
Weapons_MakeVectors(pl);
entity soda = spawn();
setmodel(soda, "models/sodacan.mdl");
setorigin(soda, Weapons_GetCameraPos(pl) + (v_forward * 16));
soda.skin = pl.soda_choice;
soda.owner = self;
soda.velocity = v_forward * 800;
soda.angles = vectoangles(soda.velocity);
soda.avelocity[0] = random(-100, -500);
soda.gravity = 0.5f;
soda.movetype = MOVETYPE_BOUNCE;
//soda.flags |= FL_LAGGEDMOVE;
soda.solid = SOLID_BBOX;
setsize(soda, [0,0,0], [0,0,0]);
soda.touch = Soda_ExplodeTouch;
}
#else
/* TODO make server side
* Sprite code in Nuclide is still WIP
* so this is client-only for now */
void
w_sodalauncher_exhaust(player pl) {
env_sprite eExhaust = spawn(env_sprite);
setorigin(eExhaust, Weapons_GetCameraPos(pl) + (v_forward * 16));
setmodel(eExhaust, "sprites/co2_puff.spr");
eExhaust.SetRenderMode(RM_ADDITIVE);
eExhaust.SetRenderColor([1,1,1]);
eExhaust.SetRenderAmt(1.0);
eExhaust.drawmask = MASK_ENGINE;
eExhaust.SetMaxFrame(modelframecount(eExhaust.modelindex));
eExhaust.SetLoopFlag(false);
eExhaust.SetScale(0.5f);
eExhaust.SetFramerate(20);
eExhaust.nextthink = time + 0.05f;
}
#endif
void
w_sodalauncher_primary(player pl)
{
if (pl.w_attack_next > 0.0) {
return;
}
/* Ammo check */
if (pl.ammo_soda <= 0) {
return;
}
Weapons_ViewPunchAngle(pl, [-10,0,0]);
Weapons_ViewAnimation(pl, SODA_SHOOT_RELOAD);
/* Actual firing
* TODO make this one fast straight */
#ifdef CLIENT
w_sodalauncher_exhaust(pl);
#else
w_sodalauncher_shoot(pl);
pl.ammo_soda--;
Sound_Play(pl, CHAN_WEAPON, "weapon_sodalauncher.fire");
#endif
pl.soda_choice++;
if (pl.soda_choice > 5) {
pl.soda_choice = 0;
}
#ifdef CLIENT
View_SetViewmodelSkin(pl.soda_choice);
#endif
pl.w_attack_next = 1.0f;
pl.w_idle_next = 10.0f;
}
/* TODO Actual secondary fire is the current primary fire code, just WIP */
void
w_sodalauncher_secondary(player pl)
{
if (pl.w_attack_next > 0.0) {
return;
}
/* Ammo check */
if (pl.ammo_soda <= 0) {
return;
}
Weapons_ViewPunchAngle(pl, [-10,0,0]);
Weapons_ViewAnimation(pl, SODA_SHOOT_RELOAD);
/* TODO make this one sag and slower */
#ifdef CLIENT
w_sodalauncher_exhaust(pl);
#else
w_sodalauncher_shoot(pl);
pl.ammo_soda--;
Sound_Play(pl, CHAN_WEAPON, "weapon_sodalauncher.fire");
#endif
pl.w_attack_next = 1.0f;
pl.w_idle_next = 10.0f;
}
void
w_sodalauncher_release(player pl)
{
if (pl.w_idle_next) {
return;
}
Weapons_ViewAnimation(pl, SODA_IDLE);
pl.w_idle_next = 3.0f;
}
void
w_sodalauncher_crosshair(player pl)
{
#ifdef CLIENT
static vector cross_pos;
cross_pos = g_hudmins + (g_hudres / 2) + [-12,-12];
drawsubpic(
cross_pos,
[32,32],
g_crossSoda,
[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_sodacan.spr_0.tga",
[32,64],
[1,1,1],
pSeatLocal->m_flAmmo2Alpha,
0
);
#endif
}
float
w_sodalauncher_aimanim(player pl)
{
return self.flags & FL_CROUCHING ? ANIM_CR_AIMBOW : ANIM_AIMBOW;
}
int
w_sodalauncher_isempty(player pl)
{
return (pl.ammo_soda <= 0) ? true : false;
}
void
w_sodalauncher_hudpic(player pl, int selected, vector pos, float a)
{
#ifdef CLIENT
if (w_sodalauncher_isempty(pl)) {
drawsubpic(
pos,
[80,40],
g_sprWeapons,
[80/256,160/256],
[80/256,40/256],
[1,1,1],
a,
DRAWFLAG_NORMAL
);
} else {
drawsubpic(
pos,
[80,40],
g_sprWeapons,
[0,160/256],
[80/256,40/256],
[1,1,1],
a,
DRAWFLAG_NORMAL
);
}
#endif
}
weapontype_t w_sodalauncher_type(player pl)
{
return WPNTYPE_RANGED;
}
weapon_t w_sodalauncher = {
.name = "sodacan",
.id = ITEM_SODALAUNCHER,
.slot = 0,
.slot_pos = 4,
.draw = w_sodalauncher_draw,
.holster = w_sodalauncher_holster,
.primary = w_sodalauncher_primary,
.secondary = w_sodalauncher_secondary,
.reload = __NULL__,
.release = w_sodalauncher_release,
.postdraw = w_sodalauncher_crosshair,
.precache = w_sodalauncher_precache,
.pickup = w_sodalauncher_pickup,
.updateammo = w_sodalauncher_updateammo,
.wmodel = w_sodalauncher_wmodel,
.pmodel = w_sodalauncher_pmodel,
.deathmsg = w_sodalauncher_deathmsg,
.aimanim = w_sodalauncher_aimanim,
.hudpic = w_sodalauncher_hudpic,
.weight = -10,
.isempty = w_sodalauncher_isempty,
.type = w_sodalauncher_type
};
#ifdef SERVER
void
weapon_sodalauncher(void)
{
Weapons_InitItem(WEAPON_SODALAUNCHER);
/*item_pickup item = (item_pickup)self;
item.SetRenderMode(RM_FULLBRIGHT);
item.SetRenderAmt(1.0f);
item.SetFloating(TRUE);*/
}
#endif