From: Lyberta Date: Mon, 28 Aug 2017 19:06:24 +0000 (+0300) Subject: URS: Renamed GetResourceProperty to GetResourceField, added GetResourceAmount. X-Git-Tag: xonotic-v0.8.5~2459^2~15^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b53f83be7a4bd0fe234af6dc68671497f432b768;p=xonotic%2Fxonotic-data.pk3dir.git URS: Renamed GetResourceProperty to GetResourceField, added GetResourceAmount. --- diff --git a/qcsrc/server/resources.qc b/qcsrc/server/resources.qc index a6e0e0724..eede42b2e 100644 --- a/qcsrc/server/resources.qc +++ b/qcsrc/server/resources.qc @@ -62,6 +62,12 @@ float GetResourceLimit(entity e, int resource_type) return limit; } +float GetResourceAmount(entity e, int resource_type) +{ + .float resource_field = GetResourceField(resource_type); + return e.(resource_field); +} + void GiveResource(entity receiver, int resource_type, float amount) { if (amount == 0) @@ -76,10 +82,10 @@ void GiveResource(entity receiver, int resource_type, float amount) } resource_type = M_ARGV(1, int); amount = M_ARGV(2, float); - .float resource_property = GetResourceProperty(resource_type); + .float resource_field = GetResourceField(resource_type); float max_amount = GetResourceLimit(receiver, resource_type); - receiver.(resource_property) = bound(receiver.(resource_property), - receiver.(resource_property) + amount, max_amount); + receiver.(resource_field) = bound(receiver.(resource_field), + receiver.(resource_field) + amount, max_amount); switch (resource_type) { case RESOURCE_HEALTH: @@ -105,9 +111,9 @@ void GiveResource(entity receiver, int resource_type, float amount) } } -int GetResourceType(.float resource_property) +int GetResourceType(.float resource_field) { - switch (resource_property) + switch (resource_field) { case health: { return RESOURCE_HEALTH; } case armorvalue: { return RESOURCE_ARMOR; } @@ -118,11 +124,11 @@ int GetResourceType(.float resource_property) case ammo_plasma: { return RESOURCE_PLASMA; } case ammo_fuel: { return RESOURCE_FUEL; } } - error("GetResourceType: Invalid property."); + error("GetResourceType: Invalid field."); return 0; } -.float GetResourceProperty(int resource_type) +.float GetResourceField(int resource_type) { switch (resource_type) { @@ -135,6 +141,6 @@ int GetResourceType(.float resource_property) case RESOURCE_PLASMA: { return ammo_plasma; } case RESOURCE_FUEL: { return ammo_fuel; } } - error("GetResourceProperty: Invalid resource type."); + error("GetResourceField: Invalid resource type."); return health; } diff --git a/qcsrc/server/resources.qh b/qcsrc/server/resources.qh index 51cc78bd6..d81b6ac6a 100644 --- a/qcsrc/server/resources.qh +++ b/qcsrc/server/resources.qh @@ -24,7 +24,13 @@ enum /// \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. +/// \brief Returns the current amount of resource the given entity has. +/// \param[in] e Entity to check. +/// \param[in] resource_type Type of the resource (a RESOURCE_* constant). +/// \return Current amount of resource the given entity has. +float GetResourceAmount(entity e, int resource_type); + +/// \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). /// \param[in] amount Amount of resource to give. @@ -33,12 +39,12 @@ 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. +/// \brief Converts an entity field to resource type. +/// \param[in] resource_field Entity field to convert. /// \return Resource type (a RESOURCE_* constant). -int GetResourceType(.float resource_property); +int GetResourceType(.float resource_field); -/// \brief Converts resource type (a RESOURCE_* constant) to entity property. +/// \brief Converts resource type (a RESOURCE_* constant) to entity field. /// \param[in] resource_type Type of the resource. -/// \return Entity proprty for that resource. -.float GetResourceProperty(int resource_type); +/// \return Entity field for that resource. +.float GetResourceField(int resource_type);