]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
URS: Not only players have resources.
authorLyberta <lyberta@lyberta.net>
Mon, 28 Aug 2017 05:25:39 +0000 (08:25 +0300)
committerLyberta <lyberta@lyberta.net>
Mon, 28 Aug 2017 05:25:39 +0000 (08:25 +0300)
qcsrc/common/mutators/mutator/vampire/sv_vampire.qc
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh
qcsrc/server/mutators/events.qh

index 92c5943c3d75455f7bc3d41b6f95184df7ba8555..1b07ecd669b5467d9307fc66b239086cf2602931 100644 (file)
@@ -12,7 +12,8 @@ MUTATOR_HOOKFUNCTION(vampire, PlayerDamage_SplitHealthArmor)
        if(frag_target != frag_attacker)
        if(!IS_DEAD(frag_target))
        {
-               GivePlayerHealth(frag_attacker, bound(0, damage_take, frag_target.health));
+               GiveResource(frag_attacker, RESOURCE_HEALTH,
+                       bound(0, damage_take, frag_target.health));
        }
 }
 
index 458a0dcb2edc7e309dae661a5cfacadf47064576..de0dcdba4e7a869e0e22f1a7e2b14e500a804ffd 100644 (file)
@@ -716,7 +716,7 @@ int GetResourceType(.float resource_property)
        return health;
 }
 
-float GetResourceLimit(entity player, int resource_type)
+float GetResourceLimit(entity e, int resource_type)
 {
        float limit;
        switch (resource_type)
@@ -767,7 +767,7 @@ float GetResourceLimit(entity player, int resource_type)
                        return 0;
                }
        }
-       MUTATOR_CALLHOOK(GetResourceLimit, player, resource_type, limit);
+       MUTATOR_CALLHOOK(GetResourceLimit, e, resource_type, limit);
        limit = M_ARGV(2, float);
        if (limit > RESOURCE_AMOUNT_HARD_LIMIT)
        {
@@ -776,13 +776,13 @@ float GetResourceLimit(entity player, int resource_type)
        return limit;
 }
 
-void GivePlayerResource(entity player, int resource_type, float amount)
+void GiveResource(entity receiver, int resource_type, float amount)
 {
        if (amount == 0)
        {
                return;
        }
-       bool forbid = MUTATOR_CALLHOOK(GivePlayerResource, player, resource_type,
+       bool forbid = MUTATOR_CALLHOOK(GiveResource, receiver, resource_type,
                amount);
        if (forbid)
        {
@@ -791,51 +791,38 @@ void GivePlayerResource(entity player, int resource_type, float amount)
        resource_type = M_ARGV(1, int);
        amount = M_ARGV(2, float);
        .float resource_property = GetResourceProperty(resource_type);
-       float max_amount = GetResourceLimit(player, resource_type);
-       player.(resource_property) = bound(player.(resource_property),
-               player.(resource_property) + amount, max_amount);
+       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:
                {
-                       player.pauserothealth_finished = max(player.pauserothealth_finished,
-                               time + autocvar_g_balance_pause_health_rot);
+                       receiver.pauserothealth_finished =
+                               max(receiver.pauserothealth_finished, time +
+                               autocvar_g_balance_pause_health_rot);
                        return;
                }
                case RESOURCE_ARMOR:
                {
-                       player.pauserotarmor_finished = max(player.pauserotarmor_finished,
-                               time + autocvar_g_balance_pause_armor_rot);
+                       receiver.pauserotarmor_finished =
+                               max(receiver.pauserotarmor_finished, time +
+                               autocvar_g_balance_pause_armor_rot);
                        return;
                }
                case RESOURCE_FUEL:
                {
-                       player.pauserotfuel_finished = max(player.pauserotfuel_finished,
+                       receiver.pauserotfuel_finished = max(receiver.pauserotfuel_finished,
                                time + autocvar_g_balance_pause_fuel_rot);
                        return;
                }
        }
 }
 
-void GivePlayerResourceViaProperty(entity player, .float resource_property,
+void GiveResourceViaProperty(entity receiver, .float resource_property,
        float amount)
 {
-       GivePlayerResource(player, GetResourceType(resource_property), amount);
-}
-
-void GivePlayerHealth(entity player, float amount)
-{
-       GivePlayerResource(player, RESOURCE_HEALTH, amount);
-}
-
-void GivePlayerArmor(entity player, float amount)
-{
-       GivePlayerResource(player, RESOURCE_ARMOR, amount);
-}
-
-void GivePlayerFuel(entity player, float amount)
-{
-       GivePlayerResource(player, RESOURCE_FUEL, amount);
+       GiveResource(receiver, GetResourceType(resource_property), amount);
 }
 
 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax)
@@ -852,7 +839,7 @@ float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax
                        {
                                amount = ammomax - player.(ammotype);
                        }
-                       GivePlayerResourceViaProperty(player, ammotype, amount);
+                       GiveResourceViaProperty(player, ammotype, amount);
                        return true;
                }
        }
@@ -861,8 +848,7 @@ float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax
                float mi = min(item.(ammotype), ammomax);
                if (player.(ammotype) < mi)
                {
-                       GivePlayerResourceViaProperty(player, ammotype, mi -
-                               player.(ammotype));
+                       GiveResourceViaProperty(player, ammotype, mi - player.(ammotype));
                }
                return true;
        }
index 613a78dde8503b4ebd2dcd2c0c4bc5f2f44f814c..a86810be31d33912093e1985031f098b88ace82e 100644 (file)
@@ -111,44 +111,26 @@ int GetResourceType(.float resource_property);
 .float GetResourceProperty(int resource_type);
 
 /// \brief Returns the maximum amount of the given resource.
-/// \param[in] player Player to check.
+/// \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 player, int resource_type);
+float GetResourceLimit(entity e, int resource_type);
 
 /// \brief Gives player a resource such as health, armor or ammo.
-/// \param[in,out] player Player to give resource to.
+/// \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 GivePlayerResource(entity player, int resource_type, float amount);
+void GiveResource(entity receiver, int resource_type, float amount);
 
 /// \brief Gives player a resource such as health, armor or ammo.
-/// \param[in,out] player Player to give resource to.
+/// \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 GivePlayerResourceViaProperty(entity player, .float resource_property,
+void GiveResourceViaProperty(entity receiver, .float resource_property,
        float amount);
 
-/// \brief Gives health to the player.
-/// \param[in,out] player Player to give health to.
-/// \param[in] amount Amount of health to give.
-/// \return No return.
-void GivePlayerHealth(entity player, float amount);
-
-/// \brief Gives armor to the player.
-/// \param[in,out] player Player to give armor to.
-/// \param[in] amount Amount of armor to give.
-/// \return No return.
-void GivePlayerArmor(entity player, float amount);
-
-/// \brief Gives fuel to the player.
-/// \param[in,out] player Player to give fuel to.
-/// \param[in] amount Amount of fuel to give.
-/// \return No return.
-void GivePlayerFuel(entity player, float amount);
-
 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax);
 
 float Item_GiveTo(entity item, entity player);
index 6c286c60728a1a112d34bcd32fee974afb25cd0e..5de969f01987336fb129c6e2bc0fb3d22c984f49 100644 (file)
@@ -620,26 +620,26 @@ enum {
        MUT_ITEMTOUCH_PICKUP // return this flag to have the item "picked up" and taken even after mutator handled it
 };
 
-/** Called when the amount of player resources changes. Can be used to override
+/** Called when the amount of entity resources changes. Can be used to override
 resource limit. */
 #define EV_GetResourceLimit(i, o) \
-       /** player */        i(entity, MUTATOR_ARGV_0_entity) \
-       /** resource type */ i(int, MUTATOR_ARGV_1_int) \
-       /** limit */         i(float, MUTATOR_ARGV_2_float) \
-       /**/                 o(float, MUTATOR_ARGV_2_float) \
+       /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \
+       /** resource type */  i(int, MUTATOR_ARGV_1_int) \
+       /** limit */          i(float, MUTATOR_ARGV_2_float) \
+       /**/                  o(float, MUTATOR_ARGV_2_float) \
        /**/
 MUTATOR_HOOKABLE(GetResourceLimit, EV_GetResourceLimit);
 
-/** Called when player is being given some resource. See RESOURCE_* constants
+/** Called when entity is being given some resource. See RESOURCE_* constants
 for resource types. Return true to forbid giving. */
-#define EV_GivePlayerResource(i, o) \
-       /** player */        i(entity, MUTATOR_ARGV_0_entity) \
+#define EV_GiveResource(i, o) \
+       /** receiver */      i(entity, MUTATOR_ARGV_0_entity) \
        /** resource type */ i(int, MUTATOR_ARGV_1_int) \
        /**/                 o(int, MUTATOR_ARGV_1_int) \
        /** amount */        i(float, MUTATOR_ARGV_2_float) \
        /**/                 o(float, MUTATOR_ARGV_2_float) \
        /**/
-MUTATOR_HOOKABLE(GivePlayerResource, EV_GivePlayerResource);
+MUTATOR_HOOKABLE(GiveResource, EV_GiveResource);
 
 /** called at when a player connect */
 #define EV_ClientConnect(i, o) \