From 42065fea660be32ff56376845e73fcebbfa5181e Mon Sep 17 00:00:00 2001 From: Lyberta Date: Thu, 25 May 2017 22:22:30 +0300 Subject: [PATCH] Started Player Templates mutator. --- qcsrc/common/mutators/mutator/_mod.inc | 1 + qcsrc/common/mutators/mutator/_mod.qh | 1 + .../mutators/mutator/playertemplates/_mod.inc | 4 + .../mutators/mutator/playertemplates/_mod.qh | 4 + .../playertemplates/sv_playertemplates.qc | 116 ++++++++++++++++++ .../playertemplates/sv_playertemplates.qh | 35 ++++++ 6 files changed, 161 insertions(+) create mode 100644 qcsrc/common/mutators/mutator/playertemplates/_mod.inc create mode 100644 qcsrc/common/mutators/mutator/playertemplates/_mod.qh create mode 100644 qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc create mode 100644 qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh diff --git a/qcsrc/common/mutators/mutator/_mod.inc b/qcsrc/common/mutators/mutator/_mod.inc index 0d6326fef0..dc47cc70d6 100644 --- a/qcsrc/common/mutators/mutator/_mod.inc +++ b/qcsrc/common/mutators/mutator/_mod.inc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/_mod.qh b/qcsrc/common/mutators/mutator/_mod.qh index 917dc6557c..f5fbe79fe6 100644 --- a/qcsrc/common/mutators/mutator/_mod.qh +++ b/qcsrc/common/mutators/mutator/_mod.qh @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/playertemplates/_mod.inc b/qcsrc/common/mutators/mutator/playertemplates/_mod.inc new file mode 100644 index 0000000000..91771cfa56 --- /dev/null +++ b/qcsrc/common/mutators/mutator/playertemplates/_mod.inc @@ -0,0 +1,4 @@ +// generated file; do not modify +#ifdef SVQC + #include +#endif diff --git a/qcsrc/common/mutators/mutator/playertemplates/_mod.qh b/qcsrc/common/mutators/mutator/playertemplates/_mod.qh new file mode 100644 index 0000000000..b4b3c5a8db --- /dev/null +++ b/qcsrc/common/mutators/mutator/playertemplates/_mod.qh @@ -0,0 +1,4 @@ +// generated file; do not modify +#ifdef SVQC + #include +#endif diff --git a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc new file mode 100644 index 0000000000..0df375f5c4 --- /dev/null +++ b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc @@ -0,0 +1,116 @@ +/// \file +/// \brief Source file that contains implementation of the Player Templates +/// mutator. +/// \author Lyberta +/// \copyright GNU GPLv3 or any later version. + +const string playertemplate_cvar_prefix = "g_player_template_"; + +float PlayerTemplate_GetFloatCvar(string template, string variable) +{ + return cvar(strcat(playertemplate_cvar_prefix, template, "_", variable)); +} + +string PlayerTemplate_GetStringCvar(string template, string variable) +{ + return cvar_string(strcat(playertemplate_cvar_prefix, template, "_", + variable)); +} + +void PlayerTemplate_PlayerSpawn(entity player, string template) +{ + // Give health, armor and ammo. + player.health = PlayerTemplate_GetFloatCvar(template, "start_health"); + player.armorvalue = PlayerTemplate_GetFloatCvar(template, "start_armor"); + if (PlayerTemplate_GetFloatCvar(template, "unlimited_ammo")) + { + player.items |= IT_UNLIMITED_AMMO; + } + else + { + player.ammo_shells = PlayerTemplate_GetFloatCvar(template, + "start_ammo_shells"); + player.ammo_nails = PlayerTemplate_GetFloatCvar(template, + "start_ammo_bullets"); + player.ammo_rockets = PlayerTemplate_GetFloatCvar(template, + "start_ammo_rockets"); + player.ammo_cells = PlayerTemplate_GetFloatCvar(template, + "start_ammo_cells"); + } + // Give weapons. + if (PlayerTemplate_GetFloatCvar(template, "default_start_weapons")) + { + FOREACH(Weapons, it != WEP_Null, + { + if (it.weaponstart) + { + player.weapons |= it.m_wepset; + } + }); + } + int numweapons = tokenize_console(PlayerTemplate_GetStringCvar(template, + "start_weapons")); + for (int i = 0; i < numweapons; ++i) + { + string weapon = argv(i); + FOREACH(Weapons, it != WEP_Null, + { + if (it.netname == weapon) + { + player.weapons |= it.m_wepset; + break; + } + }); + } + // Give random weapons. + int numrandomweapons = PlayerTemplate_GetFloatCvar(template, + "num_random_start_weapons"); + numweapons = tokenize_console(PlayerTemplate_GetStringCvar(template, + "random_start_weapons")); + if (warmup_stage) + { + // Give all weapons during warmup stage. + for (int i = 0; i < numweapons; ++i) + { + string weapon = argv(i); + FOREACH(Weapons, it != WEP_Null, + { + if (it.netname == weapon) + { + player.weapons |= it.m_wepset; + break; + } + }); + } + return; + } + for (int i = 0; i < numrandomweapons; ++i) + { + // Finding weapon which player doesn't have. + WepSet weaponbit = WEPSET(Null); + int numattempts = 0; + do + { + string weapon = argv(floor(random() * numweapons)); + FOREACH(Weapons, it != WEP_Null, + { + if (it.netname == weapon) + { + weaponbit = it.m_wepset; + break; + } + }); + ++numattempts; + } + while ((player.weapons & weaponbit) && (numattempts < 10)); + player.weapons |= weaponbit; + } +} + +float PlayerTemplate_Damage_Calculate(entity attacker, string attackertemplate, + entity victim, string victimtemplate, float damage) +{ + damage *= PlayerTemplate_GetFloatCvar(attackertemplate, "attack_scale"); + damage /= PlayerTemplate_GetFloatCvar(victimtemplate, "defense_scale"); + return damage; +} diff --git a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh new file mode 100644 index 0000000000..6133f5c028 --- /dev/null +++ b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh @@ -0,0 +1,35 @@ +/// \file +/// \brief Header file that describes the Player Templates mutator. +/// \author Lyberta +/// \copyright GNU GPLv3 or any later version. + +#pragma once + +/// \brief Gets the floating point value of the variable from the given +/// template. +/// \param[in] template Name of the template. +/// \param[in] variable Name of the variable. +/// \return Value of the variable. +float PlayerTemplate_GetFloatCvar(string template, string variable); + +/// \brief Gets the string value of the variable from the given template. +/// \param[in] template Name of the template. +/// \param[in] variable Name of the variable. +/// \return Value of the variable. +string PlayerTemplate_GetStringCvar(string template, string variable); + +/// \brief Setups the player during spawn according to the given template. +/// \param[in] player Player to setup. +/// \param[in] template Name of the template. +/// \return No return. +void PlayerTemplate_PlayerSpawn(entity player, string template); + +/// \brief Changes the damage done using templates' attack and defense scales. +/// \param[in] attacke Attacker entity. +/// \param[in] attackertemplate Template of the attacker. +/// \param[in] victim Victim entity. +/// \param[in] victimtemplate Template of the victim. +/// \param[in] damage Damage to adjust. +/// \return Adjusted damage. +float PlayerTemplate_Damage_Calculate(entity attacker, string attackertemplate, + entity victim, string victimtemplate, float damage); -- 2.39.5