proc/clamp(n, low, high)
return min(max(n, low), high)
// or
#define clamp(n, low, high) min(max(n, low), high)
This is to shorten this kind of code:
if(n > high)
n = high
else if(n < low)
n = low
// shortened into
n = clamp(n, low, high)
Example:
mob
var max_health = 100
var health = 100
proc/TakeDamage(damage)
// We don't want negative health, and
// we don't want health to be over max_health
health = clamp(health - damage, 0, max_health)
if(!health)
Die()