From: Lyberta Date: Fri, 26 May 2017 21:49:33 +0000 (+0300) Subject: Player Templates: Added default fallbacks. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2b3f88b6e8e66fbadc008de32553588fe64b202d;p=xonotic%2Fxonotic-data.pk3dir.git Player Templates: Added default fallbacks. --- diff --git a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc index 0df375f5c4..8906a9a92b 100644 --- a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc +++ b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc @@ -6,39 +6,167 @@ const string playertemplate_cvar_prefix = "g_player_template_"; -float PlayerTemplate_GetFloatCvar(string template, string variable) +string PlayerTemplate_GetFullCvarName(string template, string variable) { - return cvar(strcat(playertemplate_cvar_prefix, template, "_", variable)); + return strcat(playertemplate_cvar_prefix, template, "_", variable); } -string PlayerTemplate_GetStringCvar(string template, string variable) +string PlayerTemplate_GetDefaultCvarName(string variable) { - return cvar_string(strcat(playertemplate_cvar_prefix, template, "_", - variable)); + switch (variable) + { + case "start_health": + { + return "g_balance_health_start"; + } + case "start_armor": + { + return "g_balance_armor_start"; + } + case "unlimited_ammo": + { + return "g_use_ammunition"; + } + case "start_ammo_shells": + { + return "g_start_ammo_shells"; + } + case "start_ammo_bullets": + { + return "g_start_ammo_nails"; + } + case "start_ammo_rockets": + { + return "g_start_ammo_rockets"; + } + case "start_ammo_cells": + { + return "g_start_ammo_cells"; + } + case "start_ammo_plasma": + { + return "g_start_ammo_plasma"; + } + case "start_ammo_fuel": + { + return "g_start_ammo_fuel"; + } + default: + { + // TODO: Report error. + return ""; + } + } +} + +float PlayerTemplate_GetDefaultFloatValue(string variable) +{ + switch (variable) + { + case "start_health": + case "start_armor": + case "unlimited_ammo": + case "start_ammo_shells": + case "start_ammo_bullets": + case "start_ammo_rockets": + case "start_ammo_cells": + case "start_ammo_plasma": + case "start_ammo_fuel": + { + return cvar(PlayerTemplate_GetDefaultCvarName(variable)); + } + case "default_start_weapons": + { + return 1; + } + case "num_random_start_weapons": + { + return 0; + } + case "attack_scale": + case "defense_scale": + { + return 1; + } + default: + { + // TODO: Report error. + return 0; + } + } +} + +string PlayerTemplate_GetDefaultStringValue(string variable) +{ + switch (variable) + { + case "start_weapons": + case "random_start_weapons": + { + return ""; + } + default: + { + // TODO: Report error. + return ""; + } + } +} + +float PlayerTemplate_GetFloatValue(string template, string variable) +{ + if (template == "default") + { + return PlayerTemplate_GetDefaultFloatValue(variable); + } + string fullname = PlayerTemplate_GetFullCvarName(template, variable); + if (cvar_string(fullname) == "default") + { + return PlayerTemplate_GetDefaultFloatValue(variable); + } + return cvar(fullname); +} + +string PlayerTemplate_GetStringValue(string template, string variable) +{ + if (template == "default") + { + return PlayerTemplate_GetDefaultStringValue(variable); + } + string fullname = PlayerTemplate_GetFullCvarName(template, variable); + if (cvar_string(fullname) == "default") + { + return PlayerTemplate_GetDefaultStringValue(variable); + } + return cvar_string(fullname); } void PlayerTemplate_PlayerSpawn(entity player, string template) { + if (template == "default") + { + return; + } // 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.health = PlayerTemplate_GetFloatValue(template, "start_health"); + player.armorvalue = PlayerTemplate_GetFloatValue(template, "start_armor"); + if (PlayerTemplate_GetFloatValue(template, "unlimited_ammo")) { player.items |= IT_UNLIMITED_AMMO; } else { - player.ammo_shells = PlayerTemplate_GetFloatCvar(template, + player.ammo_shells = PlayerTemplate_GetFloatValue(template, "start_ammo_shells"); - player.ammo_nails = PlayerTemplate_GetFloatCvar(template, + player.ammo_nails = PlayerTemplate_GetFloatValue(template, "start_ammo_bullets"); - player.ammo_rockets = PlayerTemplate_GetFloatCvar(template, + player.ammo_rockets = PlayerTemplate_GetFloatValue(template, "start_ammo_rockets"); - player.ammo_cells = PlayerTemplate_GetFloatCvar(template, + player.ammo_cells = PlayerTemplate_GetFloatValue(template, "start_ammo_cells"); } // Give weapons. - if (PlayerTemplate_GetFloatCvar(template, "default_start_weapons")) + if (PlayerTemplate_GetFloatValue(template, "default_start_weapons")) { FOREACH(Weapons, it != WEP_Null, { @@ -48,7 +176,7 @@ void PlayerTemplate_PlayerSpawn(entity player, string template) } }); } - int numweapons = tokenize_console(PlayerTemplate_GetStringCvar(template, + int numweapons = tokenize_console(PlayerTemplate_GetStringValue(template, "start_weapons")); for (int i = 0; i < numweapons; ++i) { @@ -63,9 +191,9 @@ void PlayerTemplate_PlayerSpawn(entity player, string template) }); } // Give random weapons. - int numrandomweapons = PlayerTemplate_GetFloatCvar(template, + int numrandomweapons = PlayerTemplate_GetFloatValue(template, "num_random_start_weapons"); - numweapons = tokenize_console(PlayerTemplate_GetStringCvar(template, + numweapons = tokenize_console(PlayerTemplate_GetStringValue(template, "random_start_weapons")); if (warmup_stage) { @@ -110,7 +238,7 @@ void PlayerTemplate_PlayerSpawn(entity player, string template) 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"); + damage *= PlayerTemplate_GetFloatValue(attackertemplate, "attack_scale"); + damage /= PlayerTemplate_GetFloatValue(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 index 6133f5c028..1bb7d6e87e 100644 --- a/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh +++ b/qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh @@ -5,18 +5,40 @@ #pragma once +/// \brief Returns the full name of the player template cvar. +/// \param[in] template Name of the template. +/// \param[in] variable Name of the variable. +/// \return Full name of the variable. +string PlayerTemplate_GetFullCvarName(string template, string variable); + +/// \brief Returns the name of the cvar that is used for default value. +/// \param[in] Name of the player template variable. +/// \return Name of the cvar that is used for default value. +string PlayerTemplate_GetDefaultCvarName(string variable); + +/// \brief Returns the default floating point value of the player template +/// variable. +/// \param[in] variable Name of the variable. +/// \return Default floating point value of the player template variable. +float PlayerTemplate_GetDefaultFloatValue(string variable); + +/// \brief Returns the default string value of the player template variable. +/// \param[in] variable Name of the variable. +/// \return Default string value of the player template variable. +string PlayerTemplate_GetDefaultStringValue(string variable); + /// \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); +float PlayerTemplate_GetFloatValue(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); +string PlayerTemplate_GetStringValue(string template, string variable); /// \brief Setups the player during spawn according to the given template. /// \param[in] player Player to setup.