hhdeath/src/server/item_weaponbox.qc

89 lines
2.4 KiB
Plaintext

/*
* Copyright (c) 2016-2020 Marco Hladik <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.
*/
class item_weaponbox:CBaseEntity
{
int ammo_forks;
int ammo_knives;
int ammo_legogrenade;
int ammo_legos;
int ammo_soda;
int ammo_spray;
int weapon_items;
void(void) item_weaponbox;
virtual void(void) touch;
virtual void(player) setup;
};
void item_weaponbox::touch(void)
{
if (other.classname != "player") {
return;
}
player pl = (player)other;
Logging_Pickup(other, this, __NULL__);
sound(pl, CHAN_ITEM, "items/gunpickup2.wav", 1, ATTN_NORM);
pl.ammo_forks += ammo_forks;
pl.ammo_knives += ammo_knives;
pl.ammo_legogrenade += ammo_legogrenade;
pl.ammo_legos += ammo_legos;
pl.ammo_soda += ammo_soda;
pl.ammo_spray += ammo_spray;
/* cull */
pl.ammo_forks = min(pl.ammo_forks, MAX_A_FORKS);
pl.ammo_knives = min(pl.ammo_knives, MAX_A_KNIVES);
pl.ammo_legogrenade = min(pl.ammo_legogrenade, MAX_A_LEGOGRENADE);
pl.ammo_legos = min(pl.ammo_legos, MAX_A_LEGOS);
pl.ammo_soda = min(pl.ammo_soda, MAX_A_SODA);
pl.ammo_spray = min(pl.ammo_spray, MAX_A_SPRAY);
pl.g_items |= weapon_items;
Weapons_RefreshAmmo(pl);
remove(this);
}
void item_weaponbox::setup(player pl)
{
/* TODO: Should the magazine bits be transferred too? */
ammo_forks = pl.ammo_forks;
ammo_knives = pl.ammo_knives;
ammo_legogrenade = pl.ammo_legogrenade;
ammo_legos = pl.ammo_legos;
ammo_soda = pl.ammo_soda;
ammo_spray = pl.ammo_spray;
weapon_items = pl.g_items;
}
void item_weaponbox::item_weaponbox(void)
{
SetModel("models/basket.mdl");
SetSize([-16,-16,0], [16,16,16]);
SetSolid(SOLID_TRIGGER);
SetMovetype(MOVETYPE_TOSS);
}
void weaponbox_spawn(player spawner)
{
item_weaponbox weaponbox = spawn(item_weaponbox);
weaponbox.SetOrigin(spawner.origin);
weaponbox.setup(spawner);
}