From: Lyberta Date: Mon, 28 Aug 2017 05:25:39 +0000 (+0300) Subject: URS: Not only players have resources. X-Git-Tag: xonotic-v0.8.5~2459^2~17^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8d7b303a0a324cb2acc91343328c4c1e50267119;p=xonotic%2Fxonotic-data.pk3dir.git URS: Not only players have resources. --- diff --git a/qcsrc/common/mutators/mutator/vampire/sv_vampire.qc b/qcsrc/common/mutators/mutator/vampire/sv_vampire.qc index 92c5943c3..1b07ecd66 100644 --- a/qcsrc/common/mutators/mutator/vampire/sv_vampire.qc +++ b/qcsrc/common/mutators/mutator/vampire/sv_vampire.qc @@ -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)); } } diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 458a0dcb2..de0dcdba4 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -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; } diff --git a/qcsrc/common/t_items.qh b/qcsrc/common/t_items.qh index 613a78dde..a86810be3 100644 --- a/qcsrc/common/t_items.qh +++ b/qcsrc/common/t_items.qh @@ -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); diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 6c286c607..5de969f01 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -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) \