return e.(resource_field);
}
+void SetResourceAmount(entity e, int resource_type, float amount)
+{
+ .float resource_field = GetResourceField(resource_type);
+ if (e.(resource_field) == amount)
+ {
+ return;
+ }
+ float max_amount = GetResourceLimit(e, resource_type);
+ if (amount > max_amount)
+ {
+ amount = max_amount;
+ }
+ e.(resource_field) = amount;
+}
+
void GiveResource(entity receiver, int resource_type, float amount)
{
if (amount == 0)
}
resource_type = M_ARGV(1, int);
amount = M_ARGV(2, float);
- .float resource_field = GetResourceField(resource_type);
- float max_amount = GetResourceLimit(receiver, resource_type);
- receiver.(resource_field) = bound(receiver.(resource_field),
- receiver.(resource_field) + amount, max_amount);
+ if (amount <= 0)
+ {
+ return;
+ }
+ SetResourceAmount(receiver, resource_type,
+ GetResourceAmount(receiver, resource_type) + amount);
switch (resource_type)
{
case RESOURCE_HEALTH:
/// \return Current amount of resource the given entity has.
float GetResourceAmount(entity e, int resource_type);
+/// \brief Sets the current amount of resource the given entity will have.
+/// \param[in,out] e Entity to adjust.
+/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).
+/// \param[in] amount Amount of resource to set.
+/// \return No return.
+void SetResourceAmount(entity e, int resource_type, float amount);
+
/// \brief Gives an entity some resource.
/// \param[in,out] receiver Entity to give resource to.
/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).