Documentation
¶
Overview ¶
Package progression holds everything about a unit that is resolved before a battle starts: how its stats grow with level, and which evolution stage it has reached.
Stats grow linearly. A curve declares where a stat starts at level 1 and where it lands at the level cap, and any level in between is interpolated with a single integer division. Authoring a start and an end reads better than authoring a per-level increment, and it makes both endpoints exact instead of accumulating rounding error over sixty steps.
Evolution is resolved here too, never inside the battle engine: a level selects a stage, the stage carries a stat table, and the engine only ever receives the flat numbers that come out. That is why nothing downstream has to know evolution exists.
Index ¶
- Constants
- func EffectiveHP(values Values, rules combat.Rules) int64
- func EffectiveHPAgainst(values Values, rules combat.Rules, pierce int) int64
- func StageNames(stages []Stage) []string
- func ValidateStageName(name string) error
- type Curve
- type Kind
- type Limits
- type Line
- func (l Line) Allowed(level int) ([]Stage, error)
- func (l Line) Furthest(level int) ([]Stage, error)
- func (l Line) IsLeaf(name string) (bool, error)
- func (l Line) Leaves() ([]Stage, error)
- func (l Line) Parents() ([]int, error)
- func (l Line) Resolve(level int, stage string) (Values, Stage, error)
- func (l Line) StageAt(level int) (Stage, error)
- func (l Line) Validate(limits Limits, rules combat.Rules) error
- type Stage
- type Table
- type Values
Constants ¶
const Furthest = ""
Furthest is the stage a level reaches on its own, and it is what a caller passes when it is not choosing.
It is the empty string because "which form is this" and "the newest form this level allows" are the same answer whenever nobody has decided otherwise, and a second spelling would let a placement mean the default in two ways. Naming it is what keeps `Resolve(level, "")` from reading as a caller that forgot.
const KindCount = int(Dodge) + 1
KindCount is the number of stats.
const LevelCap = 60
LevelCap is the highest level a unit can reach. It is a fixed design decision rather than a tuning knob, so it lives in code; the data files declare it too and Limits.Validate rejects a mismatch.
Variables ¶
This section is empty.
Functions ¶
func EffectiveHP ¶
EffectiveHP returns how much raw damage a stat line absorbs: health scaled up by whatever its defence turns away.
It describes damage that does not pierce. That was every damage source in the game until piercing arrived and it is still all but one of them, which is why this stays the plain name and the bound is measured against it — but it is no longer the worst case, and anything showing the figure to an author has to say which case it means. See EffectiveHPAgainst.
func EffectiveHPAgainst ¶
EffectiveHPAgainst is the same figure against damage that ignores a share of the defence, in parts per thousand.
Against full piercing it comes back as the raw health, because that is what a unit with no defence left absorbs. That end of the range is the honest floor of a stat line's durability and the number an armour-heavy build should be read against, since piercing is the counter it was given.
func StageNames ¶
StageNames is the names of a list of stages, which is what a refusal offers somebody who has just named one that is not there.
func ValidateStageName ¶
ValidateStageName checks the shape of a stage name.
A stage name is an **identifier**, not display text, and this is the rule that keeps it one. Four things in this repository say so:
- Line.Resolve looks a stage up by comparing candidate.Name == stage, so the name is the lookup key rather than a caption beside one.
- Stage.After names a predecessor **by name** ("after": "Ivysaur"), which is a second hand-typed spelling of the same string.
- A roster entry or a squad placement writes "stage": "Ivysaur", and a learnset entry gates itself on a list of stage names — both spelled by hand in files the line itself never sees.
- Line.Validate refuses two stages sharing a name, "so naming one of them chooses neither". Only a key has a uniqueness constraint.
A string spelled by hand in four places and compared with == has to be typeable and has to have exactly one spelling, and both fail outside ASCII: "Tiên" has two Unicode encodings that draw identically — the composed ê and an e followed by a combining circumflex — and == calls them different names, so the visibly-correct key silently misses. Printable ASCII is how that is checked; it is the mechanical form of the rule rather than the rule itself.
The other half is that a stage name reaches the screen **unglossed, in both languages** — there is nothing to translate it to, so it is drawn exactly as the data writes it. A name authored in one language's own script is therefore that language's word on the other language's screen. Refusing anything outside ASCII refuses that too. There is deliberately no Lang.StageName accessor: the house rule is that an id is shown as the data writes it.
The rule is no tighter than that on purpose. Spaces, digits, hyphens, apostrophes and periods stay legal, because "Mega Charizard X", "Ho-Oh" and "Porygon2" are all plausible forms and none of them is a phrase in a language. What is refused is a name that is empty, carries a byte outside printable ASCII, carries no letter at all, or has a space at either end or two in a row — the last because a difference between two spellings of a key that nobody can see is exactly the failure the ASCII rule exists to prevent.
It is exported for the same reason cast.ValidateID and cast.ValidateImagePath are: an authoring tool has to be able to reject an answer as it is typed, rather than at the end of a wizard nobody wants to fill in twice.
Types ¶
type Curve ¶
Curve is a linear progression for one stat, from Base at level 1 to Max at LevelCap.
type Kind ¶
type Kind uint8
Kind identifies one of the four stats.
const ( HP Kind = iota Attack Defense Speed // Accuracy raises the chance a skill connects. It is a stat rather than a // per-skill constant because two units with the same skill should not be // equally reliable with it. Accuracy // Dodge lowers the chance an incoming skill connects. It is the answer to // accuracy: without it, whether an attack lands would be entirely the // attacker's business and stacking accuracy would have no counterplay. Dodge )
type Limits ¶
type Limits struct {
// LevelCap must match the LevelCap constant; the field exists so a data
// file that disagrees with the code fails loudly.
LevelCap int `json:"level_cap"`
// Ceilings is the highest each stat may reach at the level cap.
Ceilings Values `json:"ceilings"`
// MaxEffectiveHP bounds health and defence together.
//
// Health and damage reduction multiply, so a unit at both ceilings is not
// merely durable, it is durable squared: 4800 health behind 800 defence
// takes the same punishment as 17600 health behind none. Capping the
// product is what stops a unit being accidentally unkillable, and it turns
// the two stats into a trade rather than a stack.
MaxEffectiveHP int64 `json:"max_effective_hp"`
}
Limits are the design budget a unit's stats have to fit inside.
func ParseLimits ¶
ParseLimits reads a limits declaration. It never touches the filesystem.
func (Limits) CheckTable ¶
CheckTable rejects a stat table whose curve breaks the budget at any level.
With linear curves and the current reduction formula the budget is worst at the cap, so checking the cap alone would be enough today. Walking every level costs sixty comparisons, does not depend on that property holding, and names the first level that breaks, which is what an author needs to see.
func (Limits) CheckValues ¶
CheckValues rejects a resolved stat line that breaks the budget.
type Line ¶
type Line []Stage
Line is a unit's full evolution line, ordered by MinLevel.
func (Line) Allowed ¶
Allowed is every stage a level may be fielded as, in line order.
A level reaching Venusaur reaches Ivysaur and Bulbasaur too, so a line that does not fork answers with a prefix of itself — which is what makes "evolving" a threshold that is passed rather than a door that closes behind the unit.
A fork answers with **both arms** and everything before them, because each is a form the level may legally be fielded as. Fielding one is what makes the other moot, and that choice lives in the placement rather than here: nothing in the line marks an arm as taken, because nothing in a line knows about a unit.
func (Line) Furthest ¶
Furthest is every stage a level has reached that nothing reached grows out of: one stage on a line that does not fork, and one per arm on a line that does.
It is exported because "what are the alternatives" is a question a front-end asks in its own right — a picker offering the arms, a refusal listing them — and working it out from Allowed a second time is how two screens come to disagree about what a fork is.
func (Line) IsLeaf ¶
IsLeaf reports whether the named stage is a tip of the line: nothing in the line grows out of it.
A name the line does not answer to is an **error** rather than a false. The two are different mistakes — a typo and a form with something after it — and answering false to both would let a misspelled stage be refused for the wrong reason, in a gate whose whole job is to say which rule a squad broke.
func (Line) Leaves ¶
Leaves is every stage of the line that nothing grows out of: the tip of a line that does not fork, and one per arm of a line that does.
⚠️ **It is not Furthest, and the difference is the whole reason it exists.** Furthest is a fact about a *level* — the grown end of everything that level has reached — so it moves as the level moves and answers "what has this unit become". This is a fact about the *line* and moves only when the line is edited: it answers "is there anything after this form at all". A caller that wanted the second question and asked the first would get the right answer at the cap and a different one everywhere else, which is a silent wrong answer rather than an error.
The caller it was added for is a PvP room's join gate, which insists a squad field fully grown units. ⚠️ **Written as Furthest(LevelCap) that gate would be right — provably, not by luck — and substituting it reddens nothing in this repository.** Validate refuses a stage whose MinLevel is past the cap, so every stage of every line it accepts is reachable at the cap, and there the grown end of what the cap reaches *is* the tip of each arm. That was measured rather than reasoned: the substitution passes all twenty-one tests over this predicate and its gate, because no legal line can tell the two apart at that level.
So this exists to **name the question**, not to answer it differently, and the value of the name is the level that is no longer in it: the two answers diverge at every level below the cap, so a caller that wanted "is anything after this form" and reached for Furthest would have to supply a level, and the wrong level is a silent wrong answer rather than an error. The gate happens to ask only at 60 — it insists on level 60 before it asks — so it is the *next* caller this protects, and the difference that is real today is the error on a name the line does not answer to, below.
An earlier draft of this comment justified it as "would start refusing a legal squad the day a stage was authored above the cap". That day cannot come: Validate is what refuses it. The conclusion survived the correction and the reason did not.
It cannot be StageAt either, which refuses a fork outright rather than reporting both arms as tips.
Parentage is read through Parents and never worked out here, because Parents is the one place the two spellings of a line meet: a line where nothing names an After is read by order, and one where anything does is read by name only. A second reading of that rule is how a gate comes to disagree with the engine about what a file says.
func (Line) Parents ¶
Parents is each stage's predecessor by index, and -1 for the root.
It is exported because a summary line has to draw the shape of a line and cannot work the parentage out a second time: two readings of the same rule are how a screen comes to disagree with the engine about what a file says.
It is the one place the two spellings of a line meet. A line where nothing names an After is read by order — stage i grows out of stage i-1, which is what a line meant before it could fork. A line where anything names one is read by name only, and every stage but the first has to name a predecessor **declared before it**: that ordering requirement is what makes a cycle unwritable rather than something to go looking for, and it keeps a file readable top to bottom.
⚠️ Mixing the two is refused rather than resolved. A file that names some edges and leaves others to the order would have the order deciding parentage in a file that also states it, and the wrong answer would be a stat line rather than an error.
func (Line) Resolve ¶
Resolve flattens an evolution line, a level and a chosen stage into the stat line the battle engine works with. Nothing downstream sees the line itself.
Why the stage is a parameter ¶
It used to be derived: the stage was whatever the level reached, and there was no decision anywhere in it. A level should instead *allow* a form, with whoever is fielding the unit saying which one it fielded — otherwise "may evolve" and "does evolve" are the same sentence, and a learnset entry gated on a stage would be a second spelling of a level.
Furthest is the answer for a caller that is not choosing, and it is the behaviour every caller had before this: a browser showing a character at level 30 has no placement and therefore nobody to have chosen for it.
Naming a stage the level has not reached is refused rather than clamped. A clamp would field a different unit from the one that was written down, which is the one outcome worse than saying no.
func (Line) StageAt ¶
StageAt returns the furthest stage a unit of the given level has reached, and refuses when there is more than one.
This is what a level *allows*, not what a unit *is*: a placement may field an earlier form, and Allowed is the list it may choose from. What this answers is the question a browser asks — "show me this character at level 30" — where there is no placement and therefore nobody to have chosen.
⚠️ **A line that forks has no single furthest, and that is an error rather than a pick.** The furthest stages are the reached ones with no reached stage growing out of them, and on a linear line there is exactly one — so nothing about a line without forks changes. Where two arms are reachable, taking "whichever the file lists last" would hand a browser, a budget row or a balance table the wrong form's stat line with nothing anywhere saying so. The refusal names both arms, because the caller's fix is to choose one.
type Stage ¶
type Stage struct {
Name string `json:"name"`
// MinLevel is the level at which this stage takes over. The first stage
// must start at level 1.
MinLevel int `json:"min_level"`
// Image is this form's own art, and it is optional: a stage that names none
// shows the character's. The fallback is not applied here — see
// cast.Character.StageArt, which is the one place that decides it, because
// this package has no character to fall back to.
//
// It sits beside Name rather than one layer up because it is the same kind
// of fact: what this form is called and what it looks like both belong to
// the form, and a parallel list keyed by stage name would be a second thing
// to keep in step — one that goes stale exactly when a stage is renamed or
// removed. What this package does not do is check the path: that is
// cast.ValidateImagePath's job, the same division a skill's pattern name
// follows.
Image string `json:"image,omitempty"`
// Element is this form's own affinity, and it is optional in exactly the way
// Image is: a stage that names none is the character's. The fallback is not
// applied here — see cast.Character.ElementAt, which is the one place that
// decides it, because this package has no character to fall back to.
//
// ⚠️ **A pointer, and that is load-bearing rather than a style.** The zero
// element.Affinity is a *valid* single neutral affinity, so a value field
// would read "this form is neutral" on every stage that declared nothing —
// a silent wrong answer rather than an absence. It is the same trap
// Values.UnmarshalJSON guards with *int64 above, and the reason
// cast's characterFile.Element is already a pointer.
//
// It sits beside Image for Image's own reason: what a form is called, what
// it looks like and what it is made of are all facts about the form, and a
// parallel list keyed by stage name would be a second thing to keep in step
// — one that goes stale exactly when a stage is renamed. What this package
// does not do is check it: an affinity is only legal or illegal against the
// element chart, which this package has no more of than it has a picture
// directory. cast.resolveCharacter validates it, per stage, at parse time
// and only for a stage that names one.
Element *element.Affinity `json:"element,omitempty"`
// After is the stage this one grows out of, by name, and it is what lets a
// line fork: two stages naming the same predecessor are alternatives, and a
// placement picks which arm it fielded.
//
// It is optional, and its absence means "the stage declared before this one"
// — which is what every line meant before forks existed, so a linear line
// writes nothing and reads as it always did. ⚠️ **A line may not mix the
// two.** The moment any stage names a predecessor, every stage but the root
// has to, because otherwise the *order of the file* would decide who a stage
// grows out of in a file that also says so explicitly — which is a silent
// wrong answer rather than an error, and the exact failure this whole change
// is written to avoid. Line.Validate refuses the mixture.
After string `json:"after,omitempty"`
Stats Table `json:"stats"`
}
Stage is one step of an evolution line.
type Table ¶
Table holds one curve per stat.
func (Table) MarshalJSON ¶
MarshalJSON writes the curves by stat name.
func (*Table) UnmarshalJSON ¶
UnmarshalJSON requires a curve for every stat.
type Values ¶
Values is one number per stat. It serves both as a resolved stat line and as a set of ceilings.
func (Values) MarshalJSON ¶
MarshalJSON writes the stats by name.
func (*Values) UnmarshalJSON ¶
UnmarshalJSON requires all four stats to be present, so a typo in a data file cannot silently leave a stat at zero.