247 lines
5.1 KiB
Plaintext
247 lines
5.1 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_crossbow (0 0 1) (-16 -16 0) (16 16 32)
|
|
"model" "models/g_light.mdl"
|
|
|
|
HALF-LIFE (1998) ENTITY
|
|
|
|
Crossbow Weapon
|
|
|
|
*/
|
|
|
|
enum
|
|
{
|
|
LIGHTNING_IDLE,
|
|
LIGHTNING_SHOOT,
|
|
};
|
|
|
|
void
|
|
w_lightning_precache(void)
|
|
{
|
|
#ifdef SERVER
|
|
Sound_Precache("weapon_lightning.start");
|
|
precache_model("models/g_light.mdl");
|
|
#else
|
|
precache_model("models/v_light.mdl");
|
|
precache_model("models/p_light.mdl");
|
|
#endif
|
|
}
|
|
|
|
void
|
|
w_lightning_updateammo(player pl)
|
|
{
|
|
Weapons_UpdateAmmo(pl, -1, pl.ammo_cells, -1);
|
|
}
|
|
|
|
string
|
|
w_lightning_wmodel(void)
|
|
{
|
|
return "models/g_light.mdl";
|
|
}
|
|
|
|
string
|
|
w_lightning_pmodel(player pl)
|
|
{
|
|
return "models/p_light.mdl";
|
|
}
|
|
|
|
string
|
|
w_lightning_deathmsg(void)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
int
|
|
w_lightning_pickup(player pl, int new, int startammo)
|
|
{
|
|
#ifdef SERVER
|
|
if (pl.ammo_cells < MAX_A_CELLS) {
|
|
pl.ammo_cells = bound(0, pl.ammo_cells + 15, MAX_A_CELLS);
|
|
} else {
|
|
if (!new)
|
|
return (0);
|
|
}
|
|
|
|
#endif
|
|
return (1);
|
|
}
|
|
|
|
void
|
|
w_lightning_draw(player pl)
|
|
{
|
|
Weapons_SetModel("models/v_light.mdl");
|
|
Weapons_ViewAnimation(pl, LIGHTNING_IDLE);
|
|
}
|
|
|
|
void
|
|
w_lightning_primary(player pl)
|
|
{
|
|
if (pl.w_attack_next > 0.0)
|
|
return;
|
|
if (pl.ammo_cells <= 0) {
|
|
Weapons_SwitchBest(pl, 0);
|
|
return;
|
|
}
|
|
|
|
pl.ammo_cells--;
|
|
|
|
#ifdef SERVER
|
|
{
|
|
if (pl.WaterLevel() > 1) {
|
|
// we're underwater... fry everyone */
|
|
} else {
|
|
vector startPos = Weapons_GetCameraPos(pl);
|
|
Weapons_MakeVectors(pl);
|
|
traceline(startPos, startPos + v_forward * 600, MOVE_NORMAL, pl);
|
|
|
|
WriteByte(MSG_MULTICAST, SVC_TEMPENTITY);
|
|
WriteByte(MSG_MULTICAST, TE_LIGHTNING2);
|
|
WriteEntity(MSG_MULTICAST, pl);
|
|
WriteCoord(MSG_MULTICAST, startPos[0]);
|
|
WriteCoord(MSG_MULTICAST, startPos[1]);
|
|
WriteCoord(MSG_MULTICAST, startPos[2]);
|
|
WriteCoord(MSG_MULTICAST, trace_endpos[0]);
|
|
WriteCoord(MSG_MULTICAST, trace_endpos[1]);
|
|
WriteCoord(MSG_MULTICAST, trace_endpos[2]);
|
|
multicast(startPos, MULTICAST_PHS);
|
|
|
|
if (trace_ent.takedamage) {
|
|
Damage_Apply(trace_ent, pl, Skill_GetValue("plr_lightning", 30), WEAPON_LIGHTNING, DMG_BLUNT);
|
|
|
|
/* throw players into the air */
|
|
if (trace_ent.classname == "player") {
|
|
NSClientPlayer tp = (NSClientPlayer)trace_ent;
|
|
tp.SetVelocity(tp.GetVelocity() + [0, 0, 400]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (pl.HasQuadDamage()) {
|
|
Sound_Play(pl, CHAN_ITEM, "item_artifact_super_damage.attack");
|
|
}
|
|
Sound_Play(pl, CHAN_WEAPON, "weapon_lightning.start");
|
|
#endif
|
|
|
|
Weapons_ViewAnimation(pl, LIGHTNING_SHOOT);
|
|
Animation_PlayerTop(pl, (pl.flags & FL_CROUCHING) ? ANIM_CR_SHOOTGAUSS : ANIM_SHOOTGAUSS, 0.43f);
|
|
|
|
Weapons_ViewPunchAngle(pl, [-2,0,0]);
|
|
|
|
pl.w_attack_next = 0.1f;
|
|
}
|
|
|
|
void
|
|
w_lightning_crosshair(player pl)
|
|
{
|
|
#ifdef CLIENT
|
|
vector aicon_pos;
|
|
|
|
Cross_DrawSub(g_cross_spr, [24,24], [72/128,0], [0.1875, 0.1875]);
|
|
|
|
HUD_DrawAmmo2();
|
|
|
|
aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42];
|
|
drawsubpic(
|
|
aicon_pos,
|
|
[24,24],
|
|
g_hudlgammo,
|
|
[0, 0],
|
|
[24/24, 24/24],
|
|
g_hud_color,
|
|
pSeatLocal->m_flAmmo2Alpha,
|
|
DRAWFLAG_ADDITIVE
|
|
);
|
|
#endif
|
|
}
|
|
|
|
float
|
|
w_lightning_aimanim(player pl)
|
|
{
|
|
return pl.flags & FL_CROUCHING ? ANIM_CR_AIMGAUSS : ANIM_AIMGAUSS;
|
|
}
|
|
|
|
int
|
|
w_lightning_isempty(player pl)
|
|
{
|
|
if (pl.ammo_cells <= 0)
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
w_lightning_hudpic(player pl, int selected, vector pos, float a)
|
|
{
|
|
#ifdef CLIENT
|
|
vector hud_col;
|
|
|
|
if (w_lightning_isempty(pl))
|
|
hud_col = [1,0,0];
|
|
else
|
|
hud_col = g_hud_color;
|
|
|
|
if (selected) {
|
|
drawsubpic(pos, [170,45], g_hudlg_spr, [0,0], [1,0.625], hud_col, a, DRAWFLAG_ADDITIVE);
|
|
} else {
|
|
drawsubpic(pos, [170,45], g_hudlg_spr, [0,0], [1,0.625], hud_col, a, DRAWFLAG_ADDITIVE);
|
|
}
|
|
|
|
HUD_DrawAmmoBar(pos, pl.ammo_cells, MAX_A_CELLS, a);
|
|
#endif
|
|
}
|
|
|
|
weapontype_t
|
|
w_lightning_type(player pl)
|
|
{
|
|
return WPNTYPE_RANGED;
|
|
}
|
|
|
|
weapon_t w_lightning =
|
|
{
|
|
.name = "lightning",
|
|
.id = ITEM_LIGHTNING,
|
|
.slot = 7,
|
|
.slot_pos = 0,
|
|
.weight = 1,
|
|
.draw = w_lightning_draw,
|
|
.holster = __NULL__,
|
|
.primary = w_lightning_primary,
|
|
.secondary = __NULL__,
|
|
.reload = __NULL__,
|
|
.release = __NULL__,
|
|
.postdraw = w_lightning_crosshair,
|
|
.precache = w_lightning_precache,
|
|
.pickup = w_lightning_pickup,
|
|
.updateammo = w_lightning_updateammo,
|
|
.wmodel = w_lightning_wmodel,
|
|
.pmodel = w_lightning_pmodel,
|
|
.deathmsg = w_lightning_deathmsg,
|
|
.aimanim = w_lightning_aimanim,
|
|
.isempty = w_lightning_isempty,
|
|
.type = w_lightning_type,
|
|
.hudpic = w_lightning_hudpic
|
|
};
|
|
|
|
#ifdef SERVER
|
|
void
|
|
weapon_lightning(void)
|
|
{
|
|
Weapons_InitItem(WEAPON_LIGHTNING);
|
|
}
|
|
#endif
|