]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Started Player Templates mutator.
authorLyberta <lyberta@lyberta.net>
Thu, 25 May 2017 19:22:30 +0000 (22:22 +0300)
committerLyberta <lyberta@lyberta.net>
Thu, 25 May 2017 19:22:30 +0000 (22:22 +0300)
qcsrc/common/mutators/mutator/_mod.inc
qcsrc/common/mutators/mutator/_mod.qh
qcsrc/common/mutators/mutator/playertemplates/_mod.inc [new file with mode: 0644]
qcsrc/common/mutators/mutator/playertemplates/_mod.qh [new file with mode: 0644]
qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qc [new file with mode: 0644]
qcsrc/common/mutators/mutator/playertemplates/sv_playertemplates.qh [new file with mode: 0644]

index 0d6326fef0712b405f0ad88a856c27a61ef646ab..dc47cc70d644935e5e8819a78fe19be4558a34b5 100644 (file)
@@ -23,6 +23,7 @@
 #include <common/mutators/mutator/overkill/_mod.inc>
 #include <common/mutators/mutator/physical_items/_mod.inc>
 #include <common/mutators/mutator/pinata/_mod.inc>
+#include <common/mutators/mutator/playertemplates/_mod.inc>
 #include <common/mutators/mutator/random_gravity/_mod.inc>
 #include <common/mutators/mutator/rocketflying/_mod.inc>
 #include <common/mutators/mutator/rocketminsta/_mod.inc>
index 917dc6557ceb02b2415649bc6d9546e6a400c9c6..f5fbe79fe6035d35703caf6121acd6b5c6784b64 100644 (file)
@@ -23,6 +23,7 @@
 #include <common/mutators/mutator/overkill/_mod.qh>
 #include <common/mutators/mutator/physical_items/_mod.qh>
 #include <common/mutators/mutator/pinata/_mod.qh>
+#include <common/mutators/mutator/playertemplates/_mod.qh>
 #include <common/mutators/mutator/random_gravity/_mod.qh>
 #include <common/mutators/mutator/rocketflying/_mod.qh>
 #include <common/mutators/mutator/rocketminsta/_mod.qh>
diff --git a/qcsrc/common/mutators/mutator/playertemplates/_mod.inc b/qcsrc/common/mutators/mutator/playertemplates/_mod.inc
new file mode 100644 (file)
index 0000000..91771cf
--- /dev/null
@@ -0,0 +1,4 @@
+// generated file; do not modify
+#ifdef SVQC
+    #include <common/mutators/mutator/playertemplates/sv_playertemplates.qc>
+#endif
diff --git a/qcsrc/common/mutators/mutator/playertemplates/_mod.qh b/qcsrc/common/mutators/mutator/playertemplates/_mod.qh
new file mode 100644 (file)
index 0000000..b4b3c5a
--- /dev/null
@@ -0,0 +1,4 @@
+// generated file; do not modify
+#ifdef SVQC
+    #include <common/mutators/mutator/playertemplates/sv_playertemplates.qh>
+#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 (file)
index 0000000..0df375f
--- /dev/null
@@ -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 (file)
index 0000000..6133f5c
--- /dev/null
@@ -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);