]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Player Templates: Added default fallbacks.
authorLyberta <lyberta@lyberta.net>
Fri, 26 May 2017 21:49:33 +0000 (00:49 +0300)
committerLyberta <lyberta@lyberta.net>
Fri, 26 May 2017 21:49:33 +0000 (00:49 +0300)
qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc
qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh

index 0df375f5c4ccd96f5e593ce95fea7df65ac50bd1..8906a9a92b70a01fd428bf622a1a8ed413ab2cfb 100644 (file)
 
 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;
 }
index 6133f5c02864b9db4486e8b1ae5b8568b3b20981..1bb7d6e87eeeea04b59c3173466594adf1884321 100644 (file)
@@ -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.