item_armor: Initial implementation. Gives armor points and metal (to engineers)

This commit is contained in:
Marco Cawthorne 2022-07-10 14:18:43 -07:00
parent e2299d8d22
commit 49f9eec643
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
3 changed files with 181 additions and 0 deletions

176
src/server/item_armor.qc Normal file
View File

@ -0,0 +1,176 @@
/*
* Copyright (c) 2022 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 item_armor1 (0 0 0.8) (-16 -16 -36) (16 16 36)
TEAM FORTRESS/QUAKE (1996) ENTITY
Armor pickup, which will also replenish metal
-------- KEYS --------
"targetname" : Name
"areaname" : Name of the specified area
"team_no" : Which team can pick up the armor (0 = all)
"respawn_delay" : Time it takes to respawn after having been picked up
*/
/*QUAKED item_armor2 (0 0 0.8) (-16 -16 -36) (16 16 36)
TEAM FORTRESS/QUAKE (1996) ENTITY
Armor pickup, which will also replenish metal
-------- KEYS --------
"targetname" : Name
"areaname" : Name of the specified area
"team_no" : Which team can pick up the armor (0 = all)
"respawn_delay" : Time it takes to respawn after having been picked up
*/
/*QUAKED item_armor3 (0 0 0.8) (-16 -16 -36) (16 16 36)
TEAM FORTRESS/QUAKE (1996) ENTITY
Armor pickup, which will also replenish metal
-------- KEYS --------
"targetname" : Name
"areaname" : Name of the specified area
"team_no" : Which team can pick up the armor (0 = all)
"respawn_delay" : Time it takes to respawn after having been picked up
*/
class
item_armor:NSRenderableEntity
{
float m_flRespawnDelay;
int m_iTeamUses;
void(void) item_armor;
virtual void(entity) Touch;
virtual void(void) Respawn;
virtual void(string,string) SpawnKey;
};
void
item_armor::Touch(entity eToucher)
{
if (eToucher.classname != "player") {
return;
}
player pl = (player)eToucher;
/* check for team eligibility */
if (m_iTeamUses)
if (pl.team != m_iTeamUses)
return;
/* if we can't add anything, don't bother */
if (pl.armor >= pl.m_iMaxArmor && pl.m_iAmmoCells >= pl.m_iMaxCells)
return;
int ap;
int tp;
/* get remaining points */
ap = pl.m_iMaxArmor - pl.armor;
/* get the total points the armor can give */
switch (classname) {
case "item_armor1":
tp = 25;
break;
case "item_armor2":
tp = 50;
break;
case "item_armor3":
tp = 100;
break;
default:
print("^1item_armor: unknown armor type\n");
return;
}
/* if that's all we can give... */
if (ap > tp) {
pl.armor += tp;
} else {
/* give whatever armor points we need */
pl.armor += ap;
/* give the remaining as metal... engineers only!*/
if (pl.classtype == CLASS_ENGINEER) {
pl. m_iAmmoCells = bound(0, pl.m_iAmmoCells + (tp - ap), pl.m_iMaxCells);
}
}
/* hide and respawn */
Hide();
think = Respawn;
nextthink = time + m_flRespawnDelay;
}
void
item_armor::SpawnKey(string strKey, string strValue)
{
switch (strKey) {
case "team_no":
m_iTeamUses = stoi(strValue);
break;
case "respawn_delay":
m_flRespawnDelay = stof(strValue);
break;
default:
super::SpawnKey(strKey, strValue);
}
}
void
item_armor::Respawn(void)
{
SetModel("models/g_armor.mdl");
SetSize(VEC_HULL_MIN, VEC_HULL_MAX);
SetSolid(SOLID_TRIGGER);
SetOrigin(GetSpawnOrigin());
}
void
item_armor::item_armor(void)
{
}
void
item_armor1(void)
{
spawnfunc_item_armor();
self.classname = "item_armor1";
}
void
item_armor2(void)
{
spawnfunc_item_armor();
self.classname = "item_armor2";
}
void
item_armor3(void)
{
spawnfunc_item_armor();
self.classname = "item_armor3";
}

View File

@ -155,6 +155,8 @@ item_tfgoal::Touch(entity eToucher)
Hide();
pl.g_items |= ITEM_GOALITEM;
m_eActivator = pl;
think = __NULL__;
nextthink = 0.0f;
sound(this, CHAN_ITEM, m_strSound, 1.0f, ATTN_NONE);
@ -211,6 +213,8 @@ item_tfgoal::Respawn(void)
SetSolid(SOLID_TRIGGER);
SetOrigin(GetSpawnOrigin());
m_eActivator = __NULL__;
think = __NULL__;
nextthink = 0.0f;
}
void

View File

@ -35,6 +35,7 @@ info_player_teamspawn.qc
item_tfgoal.qc
info_tfgoal.qc
info_areadef.qc
item_armor.qc
gamerules.qc
client.qc