Documentation
¶
Overview ¶
Package scale holds the proportional arithmetic the whole engine shares.
Every ratio in the game — a skill's power, an elemental multiplier, a buff, a hit chance — is an integer in parts per thousand against Base. Keeping one denominator means a value can be handed from one system to another without a conversion step, and a mismatch cannot silently scale a number by a thousand.
Index ¶
Constants ¶
const Base = 1000
Base is the denominator every proportional value is expressed against.
Variables ¶
This section is empty.
Functions ¶
func AtOrAboveShare ¶ added in v0.2.0
AtOrAboveShare reports whether a value is at or over a share of its maximum.
It is the twin of AtOrBelowShare and is written the same way, as a cross-multiplication rather than as a comparison against Apply(maximum, share), for the same reason: dividing first rounds the threshold down and puts a value sitting exactly on the line on the wrong side of it.
⚠️ **The two overlap at exactly one point, and that is the design rather than an edge to tidy away.** A value *on* the threshold satisfies both, so a pair of rules written either side of one number covers the whole bar with nobody falling through: for every value at least one of the two answers yes, and the only value both answer yes to is the threshold itself. Narrowing this to strictly-above would open a gap of one point that no rule covered, which is worse than an overlap a reader can see.
A maximum of nought answers no rather than dividing by it, exactly as the other end does — something with no maximum is neither low nor high — so the two still agree where neither can be answered.
func AtOrBelowShare ¶
AtOrBelowShare reports whether a value is at or under a share of its maximum.
It is written as a cross-multiplication rather than as Apply(maximum, share) so the comparison is exact: dividing first would round the threshold down and put a unit sitting exactly on the line on the wrong side of it once every few hundred health.
At or under, not strictly under: a threshold of a third means a third counts. A maximum of nought answers no rather than dividing by it — something with no maximum is not something that is low.
It lives here because two packages ask the same question about different subjects: a trait asks it about its holder, a skill asks it about its target. Sharing the *type* would leave one Condition that could not say which unit it meant, and the first mistake would be passing the wrong one's health. Sharing the arithmetic costs one function and cannot be passed the wrong thing silently, because the caller names both numbers at the call site.
func Saturate ¶
Saturate applies a change to a base value with diminishing returns, so the result approaches a limit without ever reaching it.
result = base + gap * delta / (gap + delta)
The gap is the distance from base to the limit in the direction of the change. A small delta relative to that gap is worth almost its face value; a delta the size of the gap covers exactly half of it; an unbounded delta converges on the limit. Because saturation depends only on the ratio of delta to gap, stats of completely different magnitudes saturate at the same rate.
A hard clamp would do the same job at the edges and nothing in between, which is what makes stacking buffs feel either free or worthless with no middle ground. This way each additional buff is worth measurably less than the last, and no stack of them can push a stat past its limit.
Types ¶
This section is empty.