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));
}
}
return health;
}
-float GetResourceLimit(entity player, int resource_type)
+float GetResourceLimit(entity e, int resource_type)
{
float limit;
switch (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)
{
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)
{
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)
{
amount = ammomax - player.(ammotype);
}
- GivePlayerResourceViaProperty(player, ammotype, amount);
+ GiveResourceViaProperty(player, ammotype, amount);
return true;
}
}
float mi = min(item.(ammotype), ammomax);
if (player.(ammotype) < mi)
{
- GivePlayerResourceViaProperty(player, ammotype, mi -
- player.(ammotype));
+ GiveResourceViaProperty(player, ammotype, mi - player.(ammotype));
}
return true;
}
.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);
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) \