]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Moved USR into separate file.
authorLyberta <lyberta@lyberta.net>
Mon, 28 Aug 2017 18:44:19 +0000 (21:44 +0300)
committerLyberta <lyberta@lyberta.net>
Mon, 28 Aug 2017 18:44:19 +0000 (21:44 +0300)
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh
qcsrc/server/_mod.inc
qcsrc/server/_mod.qh
qcsrc/server/client.qc
qcsrc/server/resources.qc [new file with mode: 0644]
qcsrc/server/resources.qh [new file with mode: 0644]

index de0dcdba4e7a869e0e22f1a7e2b14e500a804ffd..3873a455026f2bff402571bee52add777d1147c2 100644 (file)
@@ -682,149 +682,6 @@ void Item_ScheduleInitialRespawn(entity e)
        Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
 }
 
-int GetResourceType(.float resource_property)
-{
-       switch (resource_property)
-       {
-               case health: { return RESOURCE_HEALTH; }
-               case armorvalue: { return RESOURCE_ARMOR; }
-               case ammo_shells: { return RESOURCE_SHELLS; }
-               case ammo_nails: { return RESOURCE_BULLETS; }
-               case ammo_rockets: { return RESOURCE_ROCKETS; }
-               case ammo_cells: { return RESOURCE_CELLS; }
-               case ammo_plasma: { return RESOURCE_PLASMA; }
-               case ammo_fuel: { return RESOURCE_FUEL; }
-       }
-       error("GetResourceType: Invalid property.");
-       return 0;
-}
-
-.float GetResourceProperty(int resource_type)
-{
-       switch (resource_type)
-       {
-               case RESOURCE_HEALTH: { return health; }
-               case RESOURCE_ARMOR: { return armorvalue; }
-               case RESOURCE_SHELLS: { return ammo_shells; }
-               case RESOURCE_BULLETS: { return ammo_nails; }
-               case RESOURCE_ROCKETS: { return ammo_rockets; }
-               case RESOURCE_CELLS: { return ammo_cells; }
-               case RESOURCE_PLASMA: { return ammo_plasma; }
-               case RESOURCE_FUEL: { return ammo_fuel; }
-       }
-       error("GetResourceProperty: Invalid resource type.");
-       return health;
-}
-
-float GetResourceLimit(entity e, int resource_type)
-{
-       float limit;
-       switch (resource_type)
-       {
-               case RESOURCE_HEALTH:
-               {
-                       limit = autocvar_g_balance_health_limit;
-                       break;
-               }
-               case RESOURCE_ARMOR:
-               {
-                       limit = autocvar_g_balance_armor_limit;
-                       break;
-               }
-               case RESOURCE_SHELLS:
-               {
-                       limit = g_pickup_shells_max;
-                       break;
-               }
-               case RESOURCE_BULLETS:
-               {
-                       limit = g_pickup_nails_max;
-                       break;
-               }
-               case RESOURCE_ROCKETS:
-               {
-                       limit = g_pickup_rockets_max;
-                       break;
-               }
-               case RESOURCE_CELLS:
-               {
-                       limit = g_pickup_cells_max;
-                       break;
-               }
-               case RESOURCE_PLASMA:
-               {
-                       limit = g_pickup_plasma_max;
-                       break;
-               }
-               case RESOURCE_FUEL:
-               {
-                       limit = autocvar_g_balance_fuel_limit;
-                       break;
-               }
-               default:
-               {
-                       error("GetResourceLimit: Invalid resource type.");
-                       return 0;
-               }
-       }
-       MUTATOR_CALLHOOK(GetResourceLimit, e, resource_type, limit);
-       limit = M_ARGV(2, float);
-       if (limit > RESOURCE_AMOUNT_HARD_LIMIT)
-       {
-               limit = RESOURCE_AMOUNT_HARD_LIMIT;
-       }
-       return limit;
-}
-
-void GiveResource(entity receiver, int resource_type, float amount)
-{
-       if (amount == 0)
-       {
-               return;
-       }
-       bool forbid = MUTATOR_CALLHOOK(GiveResource, receiver, resource_type,
-               amount);
-       if (forbid)
-       {
-               return;
-       }
-       resource_type = M_ARGV(1, int);
-       amount = M_ARGV(2, float);
-       .float resource_property = GetResourceProperty(resource_type);
-       float max_amount = GetResourceLimit(receiver, resource_type);
-       receiver.(resource_property) = bound(receiver.(resource_property),
-               receiver.(resource_property) + amount, max_amount);
-       switch (resource_type)
-       {
-               case RESOURCE_HEALTH:
-               {
-                       receiver.pauserothealth_finished =
-                               max(receiver.pauserothealth_finished, time +
-                               autocvar_g_balance_pause_health_rot);
-                       return;
-               }
-               case RESOURCE_ARMOR:
-               {
-                       receiver.pauserotarmor_finished =
-                               max(receiver.pauserotarmor_finished, time +
-                               autocvar_g_balance_pause_armor_rot);
-                       return;
-               }
-               case RESOURCE_FUEL:
-               {
-                       receiver.pauserotfuel_finished = max(receiver.pauserotfuel_finished,
-                               time + autocvar_g_balance_pause_fuel_rot);
-                       return;
-               }
-       }
-}
-
-void GiveResourceViaProperty(entity receiver, .float resource_property,
-       float amount)
-{
-       GiveResource(receiver, GetResourceType(resource_property), amount);
-}
-
 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax)
 {
        if (!item.(ammotype))
@@ -839,7 +696,7 @@ float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax
                        {
                                amount = ammomax - player.(ammotype);
                        }
-                       GiveResourceViaProperty(player, ammotype, amount);
+                       GiveResource(player, GetResourceType(ammotype), amount);
                        return true;
                }
        }
@@ -848,7 +705,8 @@ float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax
                float mi = min(item.(ammotype), ammomax);
                if (player.(ammotype) < mi)
                {
-                       GiveResourceViaProperty(player, ammotype, mi - player.(ammotype));
+                       GiveResource(player, GetResourceType(ammotype), mi -
+                               player.(ammotype));
                }
                return true;
        }
index a86810be31d33912093e1985031f098b88ace82e..ac77917914d5528b9654883c8a4f8bca2d9bafc6 100644 (file)
@@ -4,22 +4,6 @@
 #include <server/defs.qh>
 #endif
 
-/// \brief Unconditional maximum amount of resources the player can have.
-const int RESOURCE_AMOUNT_HARD_LIMIT = 999;
-
-/// \brief Describes the available resource types.
-enum
-{
-       RESOURCE_HEALTH, ///< Health.
-       RESOURCE_ARMOR, ///< Armor.
-       RESOURCE_SHELLS, ///< Shells (used by shotgun).
-       RESOURCE_BULLETS, ///< Bullets (used by machinegun and rifle)
-       RESOURCE_ROCKETS, ///< Rockets (used by mortar, hagar, devastator, etc).
-       RESOURCE_CELLS, ///< Cells (used by electro, crylink, vortex, etc)
-       RESOURCE_PLASMA, ///< Plasma (unused).
-       RESOURCE_FUEL ///< Fuel (used by jetpack).
-};
-
 const int AMMO_COUNT = 4; // amount of ammo types to show in the inventory panel
 
 // item networking
@@ -100,37 +84,6 @@ void Item_ScheduleRespawn(entity e);
 
 void Item_ScheduleInitialRespawn(entity e);
 
-/// \brief Converts resource entity property to resource type.
-/// \param[in] resource_property Resource entity property to convert.
-/// \return Resource type (a RESOURCE_* constant).
-int GetResourceType(.float resource_property);
-
-/// \brief Converts resource type (a RESOURCE_* constant) to entity property.
-/// \param[in] resource_type Type of the resource.
-/// \return Entity proprty for that resource.
-.float GetResourceProperty(int resource_type);
-
-/// \brief Returns the maximum amount of the given resource.
-/// \param[in] e Entity to check.
-/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).
-/// \return Maximum amount of the given resource.
-float GetResourceLimit(entity e, int resource_type);
-
-/// \brief Gives player a resource such as health, armor or ammo.
-/// \param[in,out] receiver Entity to give resource to.
-/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).
-/// \param[in] amount Amount of resource to give.
-/// \return No return.
-void GiveResource(entity receiver, int resource_type, float amount);
-
-/// \brief Gives player a resource such as health, armor or ammo.
-/// \param[in,out] e Entity to give resource to.
-/// \param[in] resource_property Entity property of the resource.
-/// \param[in] amount Amount of resource to give.
-/// \return No return.
-void GiveResourceViaProperty(entity receiver, .float resource_property,
-       float amount);
-
 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax);
 
 float Item_GiveTo(entity item, entity player);
index 87a8d56892d69577c7d07d2cbe9f9ced6cc5162e..99115fbdc4fcaa48d2b3b33f8aca6458d530d718 100644 (file)
@@ -20,6 +20,7 @@
 #include <server/playerdemo.qc>
 #include <server/portals.qc>
 #include <server/race.qc>
+#include <server/resources.qc>
 #include <server/round_handler.qc>
 #include <server/scores.qc>
 #include <server/scores_rules.qc>
index 2967c110ce9a5a58db86abcf00a996c27b53172b..3a8898670354511f40a1e515d25aeae0d5b28068 100644 (file)
@@ -20,6 +20,7 @@
 #include <server/playerdemo.qh>
 #include <server/portals.qh>
 #include <server/race.qh>
+#include <server/resources.qh>
 #include <server/round_handler.qh>
 #include <server/scores.qh>
 #include <server/scores_rules.qh>
index b7d3a294c5d0bafec6cf1e88728d810e3d152171..22543766be9af89c136c5725490481e9643c626c 100644 (file)
@@ -12,6 +12,7 @@
 #include "teamplay.qh"
 #include "playerdemo.qh"
 #include "spawnpoints.qh"
+#include "resources.qh"
 #include "g_damage.qh"
 #include "g_hook.qh"
 #include "command/common.qh"
diff --git a/qcsrc/server/resources.qc b/qcsrc/server/resources.qc
new file mode 100644 (file)
index 0000000..a6e0e07
--- /dev/null
@@ -0,0 +1,140 @@
+#include "resources.qh"
+
+//#include <server/autocvars.qh>
+
+float GetResourceLimit(entity e, int resource_type)
+{
+       float limit;
+       switch (resource_type)
+       {
+               case RESOURCE_HEALTH:
+               {
+                       limit = autocvar_g_balance_health_limit;
+                       break;
+               }
+               case RESOURCE_ARMOR:
+               {
+                       limit = autocvar_g_balance_armor_limit;
+                       break;
+               }
+               case RESOURCE_SHELLS:
+               {
+                       limit = g_pickup_shells_max;
+                       break;
+               }
+               case RESOURCE_BULLETS:
+               {
+                       limit = g_pickup_nails_max;
+                       break;
+               }
+               case RESOURCE_ROCKETS:
+               {
+                       limit = g_pickup_rockets_max;
+                       break;
+               }
+               case RESOURCE_CELLS:
+               {
+                       limit = g_pickup_cells_max;
+                       break;
+               }
+               case RESOURCE_PLASMA:
+               {
+                       limit = g_pickup_plasma_max;
+                       break;
+               }
+               case RESOURCE_FUEL:
+               {
+                       limit = autocvar_g_balance_fuel_limit;
+                       break;
+               }
+               default:
+               {
+                       error("GetResourceLimit: Invalid resource type.");
+                       return 0;
+               }
+       }
+       MUTATOR_CALLHOOK(GetResourceLimit, e, resource_type, limit);
+       limit = M_ARGV(2, float);
+       if (limit > RESOURCE_AMOUNT_HARD_LIMIT)
+       {
+               limit = RESOURCE_AMOUNT_HARD_LIMIT;
+       }
+       return limit;
+}
+
+void GiveResource(entity receiver, int resource_type, float amount)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       bool forbid = MUTATOR_CALLHOOK(GiveResource, receiver, resource_type,
+               amount);
+       if (forbid)
+       {
+               return;
+       }
+       resource_type = M_ARGV(1, int);
+       amount = M_ARGV(2, float);
+       .float resource_property = GetResourceProperty(resource_type);
+       float max_amount = GetResourceLimit(receiver, resource_type);
+       receiver.(resource_property) = bound(receiver.(resource_property),
+               receiver.(resource_property) + amount, max_amount);
+       switch (resource_type)
+       {
+               case RESOURCE_HEALTH:
+               {
+                       receiver.pauserothealth_finished =
+                               max(receiver.pauserothealth_finished, time +
+                               autocvar_g_balance_pause_health_rot);
+                       return;
+               }
+               case RESOURCE_ARMOR:
+               {
+                       receiver.pauserotarmor_finished =
+                               max(receiver.pauserotarmor_finished, time +
+                               autocvar_g_balance_pause_armor_rot);
+                       return;
+               }
+               case RESOURCE_FUEL:
+               {
+                       receiver.pauserotfuel_finished = max(receiver.pauserotfuel_finished,
+                               time + autocvar_g_balance_pause_fuel_rot);
+                       return;
+               }
+       }
+}
+
+int GetResourceType(.float resource_property)
+{
+       switch (resource_property)
+       {
+               case health: { return RESOURCE_HEALTH; }
+               case armorvalue: { return RESOURCE_ARMOR; }
+               case ammo_shells: { return RESOURCE_SHELLS; }
+               case ammo_nails: { return RESOURCE_BULLETS; }
+               case ammo_rockets: { return RESOURCE_ROCKETS; }
+               case ammo_cells: { return RESOURCE_CELLS; }
+               case ammo_plasma: { return RESOURCE_PLASMA; }
+               case ammo_fuel: { return RESOURCE_FUEL; }
+       }
+       error("GetResourceType: Invalid property.");
+       return 0;
+}
+
+.float GetResourceProperty(int resource_type)
+{
+       switch (resource_type)
+       {
+               case RESOURCE_HEALTH: { return health; }
+               case RESOURCE_ARMOR: { return armorvalue; }
+               case RESOURCE_SHELLS: { return ammo_shells; }
+               case RESOURCE_BULLETS: { return ammo_nails; }
+               case RESOURCE_ROCKETS: { return ammo_rockets; }
+               case RESOURCE_CELLS: { return ammo_cells; }
+               case RESOURCE_PLASMA: { return ammo_plasma; }
+               case RESOURCE_FUEL: { return ammo_fuel; }
+       }
+       error("GetResourceProperty: Invalid resource type.");
+       return health;
+}
diff --git a/qcsrc/server/resources.qh b/qcsrc/server/resources.qh
new file mode 100644 (file)
index 0000000..5785e27
--- /dev/null
@@ -0,0 +1,44 @@
+#pragma once
+
+/// \brief Unconditional maximum amount of resources the player can have.
+const int RESOURCE_AMOUNT_HARD_LIMIT = 999;
+
+/// \brief Describes the available resource types.
+enum
+{
+       RESOURCE_HEALTH, ///< Health.
+       RESOURCE_ARMOR, ///< Armor.
+       RESOURCE_SHELLS, ///< Shells (used by shotgun).
+       RESOURCE_BULLETS, ///< Bullets (used by machinegun and rifle)
+       RESOURCE_ROCKETS, ///< Rockets (used by mortar, hagar, devastator, etc).
+       RESOURCE_CELLS, ///< Cells (used by electro, crylink, vortex, etc)
+       RESOURCE_PLASMA, ///< Plasma (unused).
+       RESOURCE_FUEL ///< Fuel (used by jetpack).
+};
+
+// ============================ Public API ====================================
+
+/// \brief Returns the maximum amount of the given resource.
+/// \param[in] e Entity to check.
+/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).
+/// \return Maximum amount of the given resource.
+float GetResourceLimit(entity e, int resource_type);
+
+/// \brief Gives player a resource such as health, armor or ammo.
+/// \param[in,out] receiver Entity to give resource to.
+/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).
+/// \param[in] amount Amount of resource to give.
+/// \return No return.
+void GiveResource(entity receiver, int resource_type, float amount);
+
+// ===================== Legacy and/or internal API ===========================
+
+/// \brief Converts resource entity property to resource type.
+/// \param[in] resource_property Resource entity property to convert.
+/// \return Resource type (a RESOURCE_* constant).
+int GetResourceType(.float resource_property);
+
+/// \brief Converts resource type (a RESOURCE_* constant) to entity property.
+/// \param[in] resource_type Type of the resource.
+/// \return Entity proprty for that resource.
+.float GetResourceProperty(int resource_type);