]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
GunGame: Moved from server to common.
authorLyberta <lyberta@lyberta.net>
Thu, 31 Aug 2017 09:52:12 +0000 (12:52 +0300)
committerLyberta <lyberta@lyberta.net>
Thu, 31 Aug 2017 09:52:12 +0000 (12:52 +0300)
qcsrc/common/gamemodes/gamemode/_mod.inc
qcsrc/common/gamemodes/gamemode/_mod.qh
qcsrc/common/gamemodes/gamemode/gungame/_mod.inc [new file with mode: 0644]
qcsrc/common/gamemodes/gamemode/gungame/_mod.qh [new file with mode: 0644]
qcsrc/common/gamemodes/gamemode/gungame/sv_gungame.qc [new file with mode: 0644]
qcsrc/common/gamemodes/gamemode/gungame/sv_gungame.qh [new file with mode: 0644]
qcsrc/server/mutators/mutator/_mod.inc
qcsrc/server/mutators/mutator/_mod.qh
qcsrc/server/mutators/mutator/gamemode_gungame.qc [deleted file]
qcsrc/server/mutators/mutator/gamemode_gungame.qh [deleted file]

index 2fc2c404678883117dcd9205365e36317f5e997e..6cec1df9234e455ccc86742dfa5877a4964e6bbc 100644 (file)
@@ -1,4 +1,5 @@
 // generated file; do not modify
 
+#include <common/gamemodes/gamemode/gungame/_mod.inc>
 #include <common/gamemodes/gamemode/nexball/_mod.inc>
 #include <common/gamemodes/gamemode/onslaught/_mod.inc>
index d79957012609493478bdf9e0a03ea2116fec63c3..f06b224d8fecf6f81ad0c446c38e5b482ce5c7b2 100644 (file)
@@ -1,4 +1,5 @@
 // generated file; do not modify
 
+#include <common/gamemodes/gamemode/gungame/_mod.qh>
 #include <common/gamemodes/gamemode/nexball/_mod.qh>
 #include <common/gamemodes/gamemode/onslaught/_mod.qh>
diff --git a/qcsrc/common/gamemodes/gamemode/gungame/_mod.inc b/qcsrc/common/gamemodes/gamemode/gungame/_mod.inc
new file mode 100644 (file)
index 0000000..a0bb673
--- /dev/null
@@ -0,0 +1,4 @@
+// generated file; do not modify
+#ifdef SVQC
+    #include <common/gamemodes/gamemode/gungame/sv_gungame.qc>
+#endif
diff --git a/qcsrc/common/gamemodes/gamemode/gungame/_mod.qh b/qcsrc/common/gamemodes/gamemode/gungame/_mod.qh
new file mode 100644 (file)
index 0000000..d97ca6f
--- /dev/null
@@ -0,0 +1,4 @@
+// generated file; do not modify
+#ifdef SVQC
+    #include <common/gamemodes/gamemode/gungame/sv_gungame.qh>
+#endif
diff --git a/qcsrc/common/gamemodes/gamemode/gungame/sv_gungame.qc b/qcsrc/common/gamemodes/gamemode/gungame/sv_gungame.qc
new file mode 100644 (file)
index 0000000..7a926e0
--- /dev/null
@@ -0,0 +1,230 @@
+/// \file
+/// \brief Source file that contains implementation of the GunGame gamemode.
+/// \author Lyberta
+/// \copyright GNU GPLv3 or any later version.
+
+#include "sv_gungame.qh"
+
+//============================ Constants ======================================
+
+const string GUNGAME_WEAPONS = "g_gg_weapons";
+
+//======================= Global variables ====================================
+
+.int gungame_leading_weapon_stat = _STAT(GUNGAME_LEADING_WEAPON);
+
+int gungame_maxlevel; ///< Player who reaches this level wins.
+string gungame_weapons; ///< Holds weapons corresponding to levels.
+
+entity gungame_leading_player; ///< Holds the leading player.
+int gungame_leading_level; ///< Holds the leading level.
+entity gungame_leading_weapon; ///< Holds the leading weapon.
+
+//====================== Forward declarations =================================
+
+/// \brief Resets the state to initial one.
+/// \return No return.
+void GunGame_Reset();
+
+/// \brief Returns the weapon that corresponds to the given level.
+/// \param[in] level Level of the weapon.
+/// \return Weapon corresponding to the given level.
+entity GunGame_GetWeapon(int level);
+
+/// \brief Updates stats of all players.
+/// \return No return.
+void GunGame_UpdateStats();
+
+//========================= Free functions ====================================
+
+void GunGame_Initialize()
+{
+       GunGame_Reset();
+}
+
+void GunGame_Reset()
+{
+       if (gungame_weapons)
+       {
+               strunzone(gungame_weapons);
+       }
+       gungame_weapons = strzone(cvar_string(GUNGAME_WEAPONS));
+       gungame_maxlevel = tokenize_console(gungame_weapons);
+       if (gungame_maxlevel == 0)
+       {
+               error("GunGame: Invalid weapon configuration.");
+       }
+       GameRules_limit_score(gungame_maxlevel);
+       gungame_leading_player = NULL;
+       gungame_leading_level = 0;
+       gungame_leading_weapon = GunGame_GetWeapon(0);
+       GunGame_UpdateStats();
+}
+
+entity GunGame_GetWeapon(int level)
+{
+       if (level >= gungame_maxlevel)
+       {
+               return NULL;
+       }
+       tokenize_console(gungame_weapons);
+       string weapon = argv(level);
+       FOREACH(Weapons, it != WEP_Null,
+       {
+               if (it.netname == weapon)
+               {
+                       return it;
+               }
+       });
+       error("GunGame_GetWeapon: Invalid level or weapon name");
+       return NULL;
+}
+
+/// \brief Returns the player level.
+/// \param[in] player Player to check.
+/// \return Level of the player.
+int GunGame_GetPlayerLevel(entity player)
+{
+       return PlayerScore_Get(player, SP_SCORE);
+}
+
+/// \brief Updates the information about the leading player.
+/// \return No return.
+void GunGame_UpdateLeadingPlayer()
+{
+       entity previous_leader = gungame_leading_player;
+       FOREACH_CLIENT(true,
+       {
+               if (gungame_leading_player == NULL)
+               {
+                       gungame_leading_player = it;
+                       continue;
+               }
+               if (GunGame_GetPlayerLevel(it) > GunGame_GetPlayerLevel(
+                       gungame_leading_player))
+               {
+                       gungame_leading_player = it;
+               }
+       });
+       if (gungame_leading_player == NULL)
+       {
+               return;
+       }
+       if ((gungame_leading_player == previous_leader) &&
+               (GunGame_GetPlayerLevel(gungame_leading_player) ==
+               gungame_leading_level))
+       {
+               return;
+       }
+       gungame_leading_level = GunGame_GetPlayerLevel(gungame_leading_player);
+       gungame_leading_weapon = GunGame_GetWeapon(gungame_leading_level);
+       GunGame_UpdateStats();
+       //PrintToChatAll(strcat(gungame_leading_player.netname,
+       //      " is leading with level ", ftos(gungame_leading_level)));
+}
+
+void GunGame_UpdateStats()
+{
+       FOREACH_CLIENT(IS_REAL_CLIENT(it),
+       {
+               it.gungame_leading_weapon_stat = gungame_leading_weapon.m_id;
+       });
+}
+
+/// \brief Gives the player a weapon that corresponds to their level.
+/// \param[in,out] player Player to give weapon to.
+/// \return No return.
+void GunGame_GivePlayerWeapon(entity player)
+{
+       int level = GunGame_GetPlayerLevel(player);
+       if (level >= gungame_maxlevel)
+       {
+               return;
+       }
+       entity weapon = GunGame_GetWeapon(level);
+       player.weapons |= weapon.m_wepset;
+       centerprint(player, strcat("^3Level ", ftos(level + 1), ": ^2",
+               weapon.m_name));
+}
+
+//============================= Hooks ========================================
+
+/// \brief Hook that is called to determine if there is a weapon arena.
+MUTATOR_HOOKFUNCTION(gg, SetWeaponArena)
+{
+       //PrintToChatAll("SetWeaponArena");
+       M_ARGV(0, string) = "off";
+}
+
+/// \brief Hook that is called to determine start items of all players.
+MUTATOR_HOOKFUNCTION(gg, SetStartItems)
+{
+       //PrintToChatAll("SetStartItems");
+       start_weapons = WEPSET(Null);
+       warmup_start_weapons = WEPSET(Null);
+}
+
+/// \brief Hook that is called when an item is about to spawn.
+MUTATOR_HOOKFUNCTION(gg, FilterItem)
+{
+       //PrintToChatAll("FilterItem");
+       entity item = M_ARGV(0, entity);
+       if (item.itemdef.instanceOfWeaponPickup)
+       {
+               // Block weapons from spawning.
+               return true;
+       }
+}
+
+/// \brief Hook that is called when player connects to the server.
+MUTATOR_HOOKFUNCTION(gg, ClientConnect)
+{
+       entity player = M_ARGV(0, entity);
+       if (!IS_REAL_CLIENT(player))
+       {
+               return true;
+       }
+       player.gungame_leading_weapon_stat = gungame_leading_weapon.m_id;
+       return true;
+}
+
+MUTATOR_HOOKFUNCTION(gg, reset_map_global)
+{
+       GunGame_Reset();
+}
+
+/// \brief Hook that is called when player spawns.
+MUTATOR_HOOKFUNCTION(gg, PlayerSpawn, CBC_ORDER_LAST)
+{
+       entity player = M_ARGV(0, entity);
+       player.weapons = WEPSET(Null);
+       GunGame_GivePlayerWeapon(player);
+       player.items |= IT_UNLIMITED_AMMO;
+}
+
+/// \brief Hook which is called when the player tries to throw their weapon.
+MUTATOR_HOOKFUNCTION(gg, ForbidThrowCurrentWeapon)
+{
+       return true;
+}
+
+/// \brief Hook that is called when player dies.
+MUTATOR_HOOKFUNCTION(gg, PlayerDies)
+{
+       GunGame_UpdateLeadingPlayer();
+       entity attacker = M_ARGV(1, entity);
+       if (!IS_PLAYER(attacker) || IS_DEAD(attacker) || (GunGame_GetPlayerLevel(
+               attacker) >= gungame_maxlevel))
+       {
+               return;
+       }
+       attacker.weapons = WEPSET(Null);
+       GunGame_GivePlayerWeapon(attacker);
+}
+
+/// \brief Hook that determines whether remaining frags are announced.
+MUTATOR_HOOKFUNCTION(gg, Scores_CountFragsRemaining)
+{
+       // announce remaining frags
+       return true;
+}
diff --git a/qcsrc/common/gamemodes/gamemode/gungame/sv_gungame.qh b/qcsrc/common/gamemodes/gamemode/gungame/sv_gungame.qh
new file mode 100644 (file)
index 0000000..a427048
--- /dev/null
@@ -0,0 +1,22 @@
+/// \file
+/// \brief Header file that describes the GunGame gamemode.
+/// \author Lyberta
+/// \copyright GNU GPLv3 or any later version.
+
+#pragma once
+
+//#include "../gamemode.qh"
+
+/// \brief Initializes global data for the gametype.
+/// \return No return.
+void GunGame_Initialize();
+
+REGISTER_MUTATOR(gg, false)
+{
+       MUTATOR_STATIC();
+       MUTATOR_ONADD
+       {
+               GunGame_Initialize();
+       }
+       return 0;
+}
index 4645a343d6f1adae08ced7d9012a00a9570975cf..6835f5d560b9a325a96e671c21ec17348915ff2a 100644 (file)
@@ -6,7 +6,6 @@
 #include <server/mutators/mutator/gamemode_deathmatch.qc>
 #include <server/mutators/mutator/gamemode_domination.qc>
 #include <server/mutators/mutator/gamemode_freezetag.qc>
-#include <server/mutators/mutator/gamemode_gungame.qc>
 #include <server/mutators/mutator/gamemode_invasion.qc>
 #include <server/mutators/mutator/gamemode_keepaway.qc>
 #include <server/mutators/mutator/gamemode_keyhunt.qc>
index 5cc6e55b6282c5a00745e070493419ee397b542d..aef0b332abbaa9a3c5c27560d3e0bcca21297005 100644 (file)
@@ -6,7 +6,6 @@
 #include <server/mutators/mutator/gamemode_deathmatch.qh>
 #include <server/mutators/mutator/gamemode_domination.qh>
 #include <server/mutators/mutator/gamemode_freezetag.qh>
-#include <server/mutators/mutator/gamemode_gungame.qh>
 #include <server/mutators/mutator/gamemode_invasion.qh>
 #include <server/mutators/mutator/gamemode_keepaway.qh>
 #include <server/mutators/mutator/gamemode_keyhunt.qh>
diff --git a/qcsrc/server/mutators/mutator/gamemode_gungame.qc b/qcsrc/server/mutators/mutator/gamemode_gungame.qc
deleted file mode 100644 (file)
index 27c6231..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/// \file
-/// \brief Source file that contains implementation of the GunGame gamemode.
-/// \author Lyberta
-/// \copyright GNU GPLv3 or any later version.
-
-#include "gamemode_gungame.qh"
-
-//============================ Constants ======================================
-
-const string GUNGAME_WEAPONS = "g_gg_weapons";
-
-//======================= Global variables ====================================
-
-.int gungame_leading_weapon_stat = _STAT(GUNGAME_LEADING_WEAPON);
-
-int gungame_maxlevel; ///< Player who reaches this level wins.
-string gungame_weapons; ///< Holds weapons corresponding to levels.
-
-entity gungame_leading_player; ///< Holds the leading player.
-int gungame_leading_level; ///< Holds the leading level.
-entity gungame_leading_weapon; ///< Holds the leading weapon.
-
-//====================== Forward declarations =================================
-
-/// \brief Resets the state to initial one.
-/// \return No return.
-void GunGame_Reset();
-
-/// \brief Returns the weapon that corresponds to the given level.
-/// \param[in] level Level of the weapon.
-/// \return Weapon corresponding to the given level.
-entity GunGame_GetWeapon(int level);
-
-/// \brief Updates stats of all players.
-/// \return No return.
-void GunGame_UpdateStats();
-
-//========================= Free functions ====================================
-
-void GunGame_Initialize()
-{
-       GunGame_Reset();
-}
-
-void GunGame_Reset()
-{
-       if (gungame_weapons)
-       {
-               strunzone(gungame_weapons);
-       }
-       gungame_weapons = strzone(cvar_string(GUNGAME_WEAPONS));
-       gungame_maxlevel = tokenize_console(gungame_weapons);
-       if (gungame_maxlevel == 0)
-       {
-               error("GunGame: Invalid weapon configuration.");
-       }
-       GameRules_limit_score(gungame_maxlevel);
-       gungame_leading_player = NULL;
-       gungame_leading_level = 0;
-       gungame_leading_weapon = GunGame_GetWeapon(0);
-       GunGame_UpdateStats();
-}
-
-entity GunGame_GetWeapon(int level)
-{
-       if (level >= gungame_maxlevel)
-       {
-               return NULL;
-       }
-       tokenize_console(gungame_weapons);
-       string weapon = argv(level);
-       FOREACH(Weapons, it != WEP_Null,
-       {
-               if (it.netname == weapon)
-               {
-                       return it;
-               }
-       });
-       error("GunGame_GetWeapon: Invalid level or weapon name");
-       return NULL;
-}
-
-/// \brief Returns the player level.
-/// \param[in] player Player to check.
-/// \return Level of the player.
-int GunGame_GetPlayerLevel(entity player)
-{
-       return PlayerScore_Get(player, SP_SCORE);
-}
-
-/// \brief Updates the information about the leading player.
-/// \return No return.
-void GunGame_UpdateLeadingPlayer()
-{
-       entity previous_leader = gungame_leading_player;
-       FOREACH_CLIENT(true,
-       {
-               if (gungame_leading_player == NULL)
-               {
-                       gungame_leading_player = it;
-                       continue;
-               }
-               if (GunGame_GetPlayerLevel(it) > GunGame_GetPlayerLevel(
-                       gungame_leading_player))
-               {
-                       gungame_leading_player = it;
-               }
-       });
-       if (gungame_leading_player == NULL)
-       {
-               return;
-       }
-       if ((gungame_leading_player == previous_leader) &&
-               (GunGame_GetPlayerLevel(gungame_leading_player) ==
-               gungame_leading_level))
-       {
-               return;
-       }
-       gungame_leading_level = GunGame_GetPlayerLevel(gungame_leading_player);
-       gungame_leading_weapon = GunGame_GetWeapon(gungame_leading_level);
-       GunGame_UpdateStats();
-       //PrintToChatAll(strcat(gungame_leading_player.netname,
-       //      " is leading with level ", ftos(gungame_leading_level)));
-}
-
-void GunGame_UpdateStats()
-{
-       FOREACH_CLIENT(IS_REAL_CLIENT(it),
-       {
-               it.gungame_leading_weapon_stat = gungame_leading_weapon.m_id;
-       });
-}
-
-/// \brief Gives the player a weapon that corresponds to their level.
-/// \param[in,out] player Player to give weapon to.
-/// \return No return.
-void GunGame_GivePlayerWeapon(entity player)
-{
-       int level = GunGame_GetPlayerLevel(player);
-       if (level >= gungame_maxlevel)
-       {
-               return;
-       }
-       entity weapon = GunGame_GetWeapon(level);
-       player.weapons |= weapon.m_wepset;
-       centerprint(player, strcat("^3Level ", ftos(level + 1), ": ^2",
-               weapon.m_name));
-}
-
-//============================= Hooks ========================================
-
-/// \brief Hook that is called to determine if there is a weapon arena.
-MUTATOR_HOOKFUNCTION(gg, SetWeaponArena)
-{
-       //PrintToChatAll("SetWeaponArena");
-       M_ARGV(0, string) = "off";
-}
-
-/// \brief Hook that is called to determine start items of all players.
-MUTATOR_HOOKFUNCTION(gg, SetStartItems)
-{
-       //PrintToChatAll("SetStartItems");
-       start_weapons = WEPSET(Null);
-       warmup_start_weapons = WEPSET(Null);
-}
-
-/// \brief Hook that is called when an item is about to spawn.
-MUTATOR_HOOKFUNCTION(gg, FilterItem)
-{
-       //PrintToChatAll("FilterItem");
-       entity item = M_ARGV(0, entity);
-       if (item.itemdef.instanceOfWeaponPickup)
-       {
-               // Block weapons from spawning.
-               return true;
-       }
-}
-
-/// \brief Hook that is called when player connects to the server.
-MUTATOR_HOOKFUNCTION(gg, ClientConnect)
-{
-       entity player = M_ARGV(0, entity);
-       if (!IS_REAL_CLIENT(player))
-       {
-               return true;
-       }
-       player.gungame_leading_weapon_stat = gungame_leading_weapon.m_id;
-       return true;
-}
-
-MUTATOR_HOOKFUNCTION(gg, reset_map_global)
-{
-       GunGame_Reset();
-}
-
-/// \brief Hook that is called when player spawns.
-MUTATOR_HOOKFUNCTION(gg, PlayerSpawn, CBC_ORDER_LAST)
-{
-       entity player = M_ARGV(0, entity);
-       player.weapons = WEPSET(Null);
-       GunGame_GivePlayerWeapon(player);
-       player.items |= IT_UNLIMITED_AMMO;
-}
-
-/// \brief Hook which is called when the player tries to throw their weapon.
-MUTATOR_HOOKFUNCTION(gg, ForbidThrowCurrentWeapon)
-{
-       return true;
-}
-
-/// \brief Hook that is called when player dies.
-MUTATOR_HOOKFUNCTION(gg, PlayerDies)
-{
-       GunGame_UpdateLeadingPlayer();
-       entity attacker = M_ARGV(1, entity);
-       if (!IS_PLAYER(attacker) || IS_DEAD(attacker) || (GunGame_GetPlayerLevel(
-               attacker) >= gungame_maxlevel))
-       {
-               return;
-       }
-       attacker.weapons = WEPSET(Null);
-       GunGame_GivePlayerWeapon(attacker);
-}
-
-/// \brief Hook that determines whether remaining frags are announced.
-MUTATOR_HOOKFUNCTION(gg, Scores_CountFragsRemaining)
-{
-       // announce remaining frags
-       return true;
-}
diff --git a/qcsrc/server/mutators/mutator/gamemode_gungame.qh b/qcsrc/server/mutators/mutator/gamemode_gungame.qh
deleted file mode 100644 (file)
index e36b592..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/// \file
-/// \brief Header file that describes the GunGame gamemode.
-/// \author Lyberta
-/// \copyright GNU GPLv3 or any later version.
-
-#pragma once
-
-#include "../gamemode.qh"
-
-/// \brief Initializes global data for the gametype.
-/// \return No return.
-void GunGame_Initialize();
-
-REGISTER_MUTATOR(gg, false)
-{
-       MUTATOR_STATIC();
-       MUTATOR_ONADD
-       {
-               GunGame_Initialize();
-       }
-       return 0;
-}