From 18a348178facdf58a9c385d98a76b894735dc1d9 Mon Sep 17 00:00:00 2001 From: Richard Helgeby Date: Sun, 29 Mar 2015 17:11:03 +0200 Subject: [PATCH] Add cvars component for ZTele. This reduces coupling between cvars and ZTele logic. --- src/zr/cvars.inc | 24 +---------- src/zr/ztele/cvars.inc | 94 ++++++++++++++++++++++++++++++++++++++++++ src/zr/ztele/ztele.inc | 42 ++++--------------- 3 files changed, 102 insertions(+), 58 deletions(-) create mode 100644 src/zr/ztele/cvars.inc diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index 24130aa..cc02d15 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -173,15 +173,6 @@ enum CvarsList Handle:CVAR_ZSPAWN_TIMELIMIT, Handle:CVAR_ZSPAWN_TIMELIMIT_TIME, Handle:CVAR_ZSPAWN_TIMELIMIT_ZOMBIE, - Handle:CVAR_ZTELE_ZOMBIE, - Handle:CVAR_ZTELE_HUMAN_BEFORE, - Handle:CVAR_ZTELE_HUMAN_AFTER, - Handle:CVAR_ZTELE_DELAY_ZOMBIE, - Handle:CVAR_ZTELE_DELAY_HUMAN, - Handle:CVAR_ZTELE_MAX_ZOMBIE, - Handle:CVAR_ZTELE_MAX_HUMAN, - Handle:CVAR_ZTELE_AUTOCANCEL, - Handle:CVAR_ZTELE_AUTOCANCEL_DISTANCE, Handle:CVAR_ZHP, Handle:CVAR_ZHP_DEFAULT, } @@ -503,26 +494,13 @@ CvarsCreate() g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_ZOMBIE] = CreateConVar("zr_zspawn_timelimit_zombie", "1", "Spawn player on the zombie team AFTER the timelimit is up. ['-1' = Block ZSpawn | '0' = Spawn as human | '1' = Spawn as zombie | Dependency: zr_zspawn_timelimit]"); - // =========================== - // ZTele (module) - // =========================== - g_hCvarsList[CVAR_ZTELE_ZOMBIE] = CreateConVar("zr_ztele_zombie", "1", "Allow zombies to use ZTele."); - g_hCvarsList[CVAR_ZTELE_HUMAN_BEFORE] = CreateConVar("zr_ztele_human_before", "1", "Allow humans to use ZTele before the mother zombie has spawned."); - g_hCvarsList[CVAR_ZTELE_HUMAN_AFTER] = CreateConVar("zr_ztele_human_after", "1", "Allow humans to use ZTele after the mother zombie has spawned."); - g_hCvarsList[CVAR_ZTELE_DELAY_ZOMBIE] = CreateConVar("zr_ztele_delay_zombie", "3.0", "Time between using ZTele command and teleportation for zombies. [Dependency: zr_ztele_zombie]"); - g_hCvarsList[CVAR_ZTELE_DELAY_HUMAN] = CreateConVar("zr_ztele_delay_human", "3.0", "Time between using ZTele command and teleportation for humans. [Dependency: zr_ztele_human_(before)/(after)]"); - g_hCvarsList[CVAR_ZTELE_MAX_ZOMBIE] = CreateConVar("zr_ztele_max_zombie", "3", "Max number of times a zombie is allowed to use ZTele per round. [Dependency: zr_ztele_zombie]"); - g_hCvarsList[CVAR_ZTELE_MAX_HUMAN] = CreateConVar("zr_ztele_max_human", "1", "Max number of times a human is allowed to use ZTele per round. [Dependency: zr_ztele_human_(before)/(after)]"); - g_hCvarsList[CVAR_ZTELE_AUTOCANCEL] = CreateConVar("zr_ztele_autocancel", "1", "Automatically cancel ZTele if player moves out of a set boundary. [Dependency: zr_ztele_(zombie)/(human)[_(before)/(after)]]"); - g_hCvarsList[CVAR_ZTELE_AUTOCANCEL_DISTANCE] = CreateConVar("zr_ztele_autocancel_distance", "20", "Maximum distance, in feet, player is allowed to travel before teleport is cancelled. [Dependency: zr_ztele_autocancel]"); - - // =========================== // ZHP (module) // =========================== g_hCvarsList[CVAR_ZHP] = CreateConVar("zr_zhp", "1", "Allow player to toggle real HP display as a zombie."); g_hCvarsList[CVAR_ZHP_DEFAULT] = CreateConVar("zr_zhp_default", "1", "Default ZHP toggle state set on connecting player. [Dependency: zr_zhp]"); + ZTeleOnCvarsCreate(); // Auto-generate config file if it doesn't exist, then execute. AutoExecConfig(true, "zombiereloaded", "sourcemod/zombiereloaded"); diff --git a/src/zr/ztele/cvars.inc b/src/zr/ztele/cvars.inc new file mode 100644 index 0000000..af35342 --- /dev/null +++ b/src/zr/ztele/cvars.inc @@ -0,0 +1,94 @@ +/* + * ============================================================================ + * + * Zombie:Reloaded + * + * File: ztele/cvars.inc + * Type: Module Component + * Description: Console variables for ZTele. + * + * Copyright (C) 2009-2015 Greyscale, Richard Helgeby + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * ============================================================================ + */ + +Handle ZTeleCvar_Zombie; +Handle ZTeleCvar_HumanBefore; +Handle ZTeleCvar_HumanAfter; +Handle ZTeleCvar_DelayZombie; +Handle ZTeleCvar_DelayHuman; +Handle ZTeleCvar_MaxZombie; +Handle ZTeleCvar_MaxHuman; +Handle ZTeleCvar_AutoCancel; +Handle ZTeleCvar_AutoCancelDistance; + +void ZTeleOnCvarsCreate() +{ + ZTeleCvar_Zombie = CreateConVar("zr_ztele_zombie", "1", "Allow zombies to use ZTele."); + ZTeleCvar_HumanBefore = CreateConVar("zr_ztele_human_before", "1", "Allow humans to use ZTele before the mother zombie has spawned."); + ZTeleCvar_HumanAfter = CreateConVar("zr_ztele_human_after", "1", "Allow humans to use ZTele after the mother zombie has spawned."); + ZTeleCvar_DelayZombie = CreateConVar("zr_ztele_delay_zombie", "3.0", "Time between using ZTele command and teleportation for zombies. [Dependency: zr_ztele_zombie]"); + ZTeleCvar_DelayHuman = CreateConVar("zr_ztele_delay_human", "3.0", "Time between using ZTele command and teleportation for humans. [Dependency: zr_ztele_human_(before)/(after)]"); + ZTeleCvar_MaxZombie = CreateConVar("zr_ztele_max_zombie", "3", "Max number of times a zombie is allowed to use ZTele per round. [Dependency: zr_ztele_zombie]"); + ZTeleCvar_MaxHuman = CreateConVar("zr_ztele_max_human", "1", "Max number of times a human is allowed to use ZTele per round. [Dependency: zr_ztele_human_(before)/(after)]"); + ZTeleCvar_AutoCancel = CreateConVar("zr_ztele_autocancel", "1", "Automatically cancel ZTele if player moves out of a set boundary. [Dependency: zr_ztele_(zombie)/(human)[_(before)/(after)]]"); + ZTeleCvar_AutoCancelDistance = CreateConVar("zr_ztele_autocancel_distance", "20", "Maximum distance, in feet, player is allowed to travel before teleport is cancelled. [Dependency: zr_ztele_autocancel]"); +} + +bool ZTeleZombieCanTeleport() +{ + return GetConVarBool(ZTeleCvar_Zombie); +} + +bool ZTeleHumanCanTeleportBeforeInfection() +{ + return GetConVarBool(ZTeleCvar_HumanBefore); +} + +bool ZTeleHumanCanTeleportAfterInfection() +{ + return GetConVarBool(ZTeleCvar_HumanAfter); +} + +int ZTeleGetZombieDelay() +{ + return GetConVarInt(ZTeleCvar_DelayZombie); +} + +int ZTeleGetHumanDelay() +{ + return GetConVarInt(ZTeleCvar_DelayHuman); +} + +int ZTeleGetZombieLimit() +{ + return GetConVarInt(ZTeleCvar_MaxZombie); +} + +int ZTeleGetHumanLimit() +{ + return GetConVarInt(ZTeleCvar_MaxHuman); +} + +bool ZTeleIsAutoCancelEnabled() +{ + return GetConVarBool(ZTeleCvar_AutoCancel); +} + +float ZTeleGetAutoCancelDistance() +{ + return GetConVarFloat(ZTeleCvar_AutoCancelDistance); +} diff --git a/src/zr/ztele/ztele.inc b/src/zr/ztele/ztele.inc index a5fcf7b..efd50bf 100644 --- a/src/zr/ztele/ztele.inc +++ b/src/zr/ztele/ztele.inc @@ -5,9 +5,9 @@ * * File: ztele.inc * Type: Module - * Description: ZTele handle functions. + * Description: Player teleporter. * - * Copyright (C) 2009-2013 Greyscale, Richard Helgeby + * Copyright (C) 2009-2015 Greyscale, Richard Helgeby * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,8 @@ #pragma newdecls required +#include "zr/ztele/cvars" + /** * Array to store client's spawn location. */ @@ -412,7 +414,7 @@ public Action ZTeleTimer(Handle timer, int client) g_iZTeleCount[client]++; // Get max teleports per round. - int ztelemax = InfectIsClientInfected(client) ? GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_ZOMBIE]) : GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_HUMAN]); + int ztelemax = InfectIsClientInfected(client) ? ZTeleGetZombieLimit() : ZTeleGetHumanLimit(); // Tell client spawn protection is over. TranslationPrintCenterText(client, "ZTele countdown end", g_iZTeleCount[client], ztelemax); @@ -445,7 +447,7 @@ void ZTeleStopTimer(int client) bool ZTeleMustBeHuman(int client) { bool infected = InfectIsClientInfected(client); - bool ztelezombie = GetConVarBool(g_hCvarsList[CVAR_ZTELE_ZOMBIE]); + bool ztelezombie = ZTeleZombieCanTeleport(); return (infected && !ztelezombie); } @@ -454,17 +456,7 @@ bool ZTeleCanHumanTeleport() { // There are individual restrictions whether a human can teleport before or // after zombies have spawned. - return InfectHasZombieSpawned() ? GetConVarBool(g_hCvarsList[CVAR_ZTELE_HUMAN_AFTER]) : GetConVarBool(g_hCvarsList[CVAR_ZTELE_HUMAN_BEFORE]); -} - -int ZTeleGetZombieLimit() -{ - return GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_ZOMBIE]); -} - -int ZTeleGetHumanLimit() -{ - return GetConVarInt(g_hCvarsList[CVAR_ZTELE_MAX_HUMAN]); + return InfectHasZombieSpawned() ? ZTeleHumanCanTeleportAfterInfection() : ZTeleHumanCanTeleportBeforeInfection(); } int ZTeleGetTeleportCount(int client) @@ -484,31 +476,11 @@ bool ZTeleHasReachedLimit(int client) return teleportCount >= maxTeleports; } -int ZTeleGetZombieDelay() -{ - return GetConVarInt(g_hCvarsList[CVAR_ZTELE_DELAY_ZOMBIE]); -} - -int ZTeleGetHumanDelay() -{ - return GetConVarInt(g_hCvarsList[CVAR_ZTELE_DELAY_HUMAN]); -} - int ZTeleGetClientDelay(int client) { InfectIsClientInfected(client) ? ZTeleGetZombieDelay() : ZTeleGetHumanDelay(); } -bool ZTeleIsAutoCancelEnabled() -{ - return GetConVarBool(g_hCvarsList[CVAR_ZTELE_AUTOCANCEL]); -} - -float ZTeleGetAutoCancelDistance() -{ - return GetConVarFloat(g_hCvarsList[CVAR_ZTELE_AUTOCANCEL_DISTANCE]); -} - bool ZTelePlayerWalkedTooFar(int client) { if (!ZTeleIsAutoCancelEnabled())