From 49f9eec6438458c38a040602103a9280832ce83e Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Sun, 10 Jul 2022 14:18:43 -0700 Subject: [PATCH] item_armor: Initial implementation. Gives armor points and metal (to engineers) --- src/server/item_armor.qc | 176 ++++++++++++++++++++++++++++++++++++++ src/server/item_tfgoal.qc | 4 + src/server/progs.src | 1 + 3 files changed, 181 insertions(+) create mode 100644 src/server/item_armor.qc diff --git a/src/server/item_armor.qc b/src/server/item_armor.qc new file mode 100644 index 0000000..461e7ed --- /dev/null +++ b/src/server/item_armor.qc @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2022 Marco Cawthorne + * + * 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"; +} \ No newline at end of file diff --git a/src/server/item_tfgoal.qc b/src/server/item_tfgoal.qc index 85d80e0..ba69863 100644 --- a/src/server/item_tfgoal.qc +++ b/src/server/item_tfgoal.qc @@ -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 diff --git a/src/server/progs.src b/src/server/progs.src index e1e79a6..f28c353 100644 --- a/src/server/progs.src +++ b/src/server/progs.src @@ -35,6 +35,7 @@ info_player_teamspawn.qc item_tfgoal.qc info_tfgoal.qc info_areadef.qc +item_armor.qc gamerules.qc client.qc