Skip to content

Unified resource system - step 2

username-removed-143684 requested to merge Lyberta/URS2 into master

The most important change in this MR is the introduction of resource types (RESOURCE_* constants) that abstract the implementation of resources. This way we will have the freedom to refactor them as we wish without breaking the code that uses this system. Another very important change is the notion that not only players have resources. Monsters, turrets and other NPCs can have resources too, so functions were renamed accordingly. Finally, this system was moved into separate file. Here's the summary of the changes in this MR:

New public API functions:

  • GetResourceLimit - returns the maximum amount of a given resource an entity can have. Can return different amount for different entities.
  • GetResourceAmount - returns the amount of resource the entity has.
  • SetResourceAmount - sets the amount of resource the entity will have.
  • GiveResource - better version of GivePlayerResource.
  • GiveResourceWithLimit - Same as GiveResource but allows to set a limit. Clamps the value and calls GiveResource.

New internal functions:

  • GetResourceType - converts entity field into abstracted resource type. Used to interface with legacy code.
  • GetResourceField - does the opposite. It breaks abstraction so it should only be used in the resource system itself.

Changed functions:

  • Item_GiveAmmoTo - now uses resource type instead of the entity field.
  • player_regen - now uses GetResourceLimit under the hood.
  • Ported server/g_damage.qc to URS.
  • Ported Buffs mutator to URS.
  • Ported Vampire mutator to URS.
  • Ported Blood loss mutator to URS.
  • Ported Instagib mutator to URS.
  • Ported NIX mutator to URS.
  • Ported Campcheck mutator to URS.
  • Ported Nades mutator to URS.

Removed functions:

  • GivePlayerHealth, GivePlayerArmor, GivePlayerAmmo, GivePlayerFuel, GivePlayerResource - obsoleted by GiveResource. Hey, I needed some dirty code so I can learn.

New mutator hooks:

  • GetResourceLimit - can be used to override resource limit, for example, Mario said that his mod has mushroom that can give 250 health. This function can now be used to handle this case without conflicts with other code. However, it can't override the hard limit of 999.
  • SetResourceAmount - can be used to override setting resource amount.
  • GiveResource - can be used to override the type and amount of resource the player or NPC will be given when they pickup an item or get health via vampire, etc.

Next step: unifying regeneration.

Edited by username-removed-143684

Merge request reports