scale

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Base = 1000

Base is the denominator every proportional value is expressed against.

Variables

This section is empty.

Functions

func Apply

func Apply(value, permille int64) int64

Apply returns value scaled by a proportional factor.

func AtOrAboveShare added in v0.2.0

func AtOrAboveShare(value, maximum int64, share int) bool

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

func AtOrBelowShare(value, maximum int64, share int) bool

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

func Saturate(base, delta, ceiling, floor int64) int64

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL