Documentation
¶
Overview ¶
Package cell is a board's cell as a place: what it is, who may stand on it, what runs across it and the moment of it rules are written for. The board (plugins/board) lays its grid of them and keeps their entities.
ID, Kind and Domain ¶
An ID names one cell. A Kind is a named terrain: whom it admits (Allows, of the [Domain]s Land, Water and Air, a game adding bits of its own), the share of its top speed a unit keeps on it (Pace, Kind.PaceFor by domain), whether it is solid, how much it veils sight; a board's Kinds holds those a game defined, by Name. Ground is the cell's kind on its entity, beside its Plot, and a Way (a road, a river) runs across it. Terrain is what a cell answers about its kind: a board is one.
Mobility ¶
A Mobility is how a game's units fare on the ground: the share of its top speed a unit keeps on a Step — onto a kind, on its Level, for its domain, over the slope between the two cells' middles — 1 full speed and nothing faster, 0 refusing the step; its factors multiply. The board fills the step and asks through PaceOf, which reads a Graded kind's slope as 0 and refuses a share out of [0, 1]; the planner prices a step at its length over the share and the pace slows a unit by it. DefaultHiking is Tobler's hiking function cut at the flat, a Hiking a game tunes or wraps; a game's own domain bits tell its mobility one class of unit from another, a cliff refused to one and climbed by another.
Terrain in maps and the Layout's entries ¶
A TerrainMap is terrain in plain maps: a board's seed, and a Terrain of its own where no board is wanted. The board's Layout names kinds by name, an Entry per cell and a WayEntry per way; an Entry also gives its cell what it is called and the roles it plays beyond its kind's:
cell.Entry{Kind: "well", Cell: c, Name: "well"}
water.Entry(c).Plays(lakeRole)
What stands on a cell ¶
An entity standing on the board carries On, the cell it stands on. Its knobs Floor, Wall and Rail build over the cell — a trapdoor over a pit, a bridge's deck, a gate, railings — gathered on the cell's entity as Built, whose Over is the kind as whoever crosses the cell meets it. A Floor at a Height is a storey of its cell, raised over it or sunk under it with the room Clear over it, and makes a Level of the cell beside its ground: Levels at most, the Floor's Storey saying which, so a bridge crosses over a tunnel on one cell. A Floor with its room Clear over it, dug under the ground or Standing on it at any height, is a room (Room, Dug): walled round its whole cells but where its Links lead, on into its storey or out by its Door, a Gap whoever walks in fits. An effect opens a Floor by altering its Allows, a Wall by its Keeps, to 0, and shuts a room's door by its Door. A Floor's Load bears no heavier body (unit.Mover.Weight); a Wall's Gap lets through whom it keeps off where the body fits, the cell admitting them.
Now ¶
Now is the cell at a step as a rule gets it, run for every cell playing a role that obeys one: board.Around(0) acts on the cell, board.Around(n) on the rings round it.
Occupancy ¶
An Occupancy tracks who holds each cell, on which level and in which domains: SingleOccupancy lets one entity per domain in on each level, MultipleOccupancy any number.
Vocabulary ¶
Moments, for a role's rules: Now (every cell a step; places board.Around). Knobs, for an effect's Alter: Ground, Floor, Wall, Rail.
Index ¶
- Constants
- Variables
- func PaceOf(m Mobility, s Step) float64
- type Built
- type Domain
- type Entry
- type Floor
- type Gap
- type Ground
- type Hiking
- type ID
- type Kind
- type Kinds
- type Level
- type Links
- type Mobility
- type MultipleOccupancy
- func (o *MultipleOccupancy) CanEnter(ID, Level, uid.UID64, Domain) bool
- func (o *MultipleOccupancy) Enter(c ID, level Level, entity uid.UID64, domain Domain)
- func (o *MultipleOccupancy) Holder(c ID, level Level, domain Domain) (uid.UID64, bool)
- func (o *MultipleOccupancy) Holders(c ID, visit func(uid.UID64, Domain, Level))
- func (o *MultipleOccupancy) Leave(c ID, entity uid.UID64)
- func (o *MultipleOccupancy) Release(gone func(uid.UID64) bool)
- type Name
- type Now
- type Occupancy
- type OccupancyRead
- type Of
- type On
- type Plot
- type Rail
- type SingleOccupancy
- func (o *SingleOccupancy) CanEnter(c ID, level Level, entity uid.UID64, domain Domain) bool
- func (o *SingleOccupancy) Enter(c ID, level Level, entity uid.UID64, domain Domain)
- func (o *SingleOccupancy) Holder(c ID, level Level, domain Domain) (uid.UID64, bool)
- func (o *SingleOccupancy) Holders(c ID, visit func(uid.UID64, Domain, Level))
- func (o *SingleOccupancy) Leave(c ID, entity uid.UID64)
- func (o *SingleOccupancy) Release(gone func(uid.UID64) bool)
- type Step
- type Terrain
- type TerrainMap
- func (t *TerrainMap) Cast(c ID, roles tag.Tags[cond.Roles])
- func (t *TerrainMap) Kind(c ID) Kind
- func (t *TerrainMap) Label(c ID, l ceremony.Label)
- func (t *TerrainMap) Passage() uint64
- func (t *TerrainMap) Set(c ID, kind Kind)
- func (t *TerrainMap) SetAll(kind Kind)
- func (t *TerrainMap) SetWay(c ID, w Way)
- func (t *TerrainMap) Version() uint64
- type Wall
- type Way
- type WayEntry
Constants ¶
const Levels = 4
Levels is how many levels a cell has at most: the ground and three storeys.
const MaxNameLen = 16
MaxNameLen is the longest Kind name, in bytes.
const Storeys = Levels - 1
Storeys is how many storeys a cell has.
Variables ¶
var DefaultHiking = Hiking{Rate: 3.5, Shift: 0.05, Free: Air}
DefaultHiking is Tobler's hiking function cut at the flat: half the pace at a rise of 1 in 5 and at a fall of 3 in 10, Air flying over.
Functions ¶
Types ¶
type Built ¶
Built is what the entities standing on a cell build over and under it, gathered on the cell's entity: the floor of its first storey, the wall and the railing, and the floors of the storeys past the first.
func (*Built) Levelled ¶ added in v0.22.0
Levelled reports whether a floor of b gives its cell a level beyond the ground's.
func (*Built) On ¶ added in v0.22.0
On is the floor making b's cell's level l, the zero Floor where none does.
type Domain ¶
type Domain uint8
Domain is a bitset of ways of moving: what a cell admits and what an entity uses. Land, Water and Air are given; a game may add bits of its own.
type Entry ¶
Entry sets Cell to the kind named Kind (none: the Layout's Default) and gives it the Name it bears, the Group it is in and the Roles this one cell plays beyond its kind's.
type Floor ¶
type Floor struct {
Pace float64
Height float32
Thickness float32
// Load is the most whoever it carries may weigh, in kg (unit.Mover.Weight); 0 bears anyone.
Load float32
Width float32
// Clear is the room over a floor sunk or Standing, up to its roof: whoever is taller stays
// out. A room is walled round its cell but where its Links lead: on along its storey, or out
// by its Door.
Clear float32
// Walls is how thick a Standing room's walls stand inside its cells' edges; zero, a
// sixteenth of a cell. A dug room's stand outside them, in the rock.
Walls float32
// Door is the opening of a room in the middle of each edge its Links lead out by to no floor
// of its storey: a zero Width is shut.
Door Gap
Allows Domain
Links Links
// Storey is which of the cell's storeys the floor is, the first 0: floors of one storey on a
// cell are one floor, floors of two cross over each other.
Storey uint8
Graded bool
// Standing has the room stand on the ground at any height, built, the ground cut where it
// rises into it (a house's); without, a room is dug under the ground, the ground its roof.
Standing bool
}
Floor is a knob of an entity standing on a cell carrying the domains Allows over it at Height over its level, or sunk a negative Height under it, whatever its ground takes, at Pace (0: the ground's). With a Width it is a band that wide from the cell's middle out to each neighbour its Links name; without, the whole cell.
func (Floor) Dug ¶ added in v0.22.0
Dug reports whether f's room is dug under the ground: a tunnel's, a chamber's.
func (Floor) Level ¶ added in v0.22.0
Level is the level of its cell f makes: the ground's where it lies on it, but for a room standing there, else its storey's.
type Gap ¶ added in v0.13.0
Gap is an opening through a wall: a body no wider across its step than Width and no taller than Height passes, a zero Height open at every height; a zero Width is no opening.
type Ground ¶
type Ground struct{ Kind Kind }
Ground is the terrain kind of a cell, on the cell's entity: an effect altering it alters the board.
type Hiking ¶ added in v0.7.0
Hiking is how whoever goes on foot fares on a slope: past a rise or a fall of Shift the pace falls by exp(-Rate·slope), a descent never quicker than the flat, and a domain in Free flies over at full speed.
type Kind ¶
type Kind struct {
Name Name
// Pace is the share of its top speed a unit keeps here: 1 full speed and nothing faster, 0.5
// half; a kind admitting someone gives one above 0.
Pace float64
// Allows is the domains that may stand here; one that ends up here anyway has fallen in.
Allows Domain
// Solid makes the cell solid ground: collision pushes out whoever Allows keeps out.
Solid bool
// Veil dims sight without blocking movement, 0 clear to 1 cutting it.
Veil float32
// Veils is whom the Veil dims; zero veils everyone.
Veils Domain
// Height is how tall what stands on the cell is. A Solid or veiled kind of no Height stands at
// every height.
Height float32
// Sway is how much what stands on the cell bends in the wind, 0 to 1.
Sway float32
// Graded ground is built into the slope, so the slope neither slows nor prices a step over it.
Graded bool
// Takes is which shade the cell takes and whether the lamps light it (render.Taking): zero
// all, render.Shines none.
Takes render.Taking
// SpriteID is the kind's slot in the board's atlas, given as it is defined.
SpriteID render.SpriteID
// Paces overrides Pace for units moving in a domain, Paces[i] for the domain bit i; 0 leaves
// Pace.
Paces [8]float64
}
Kind is a named terrain kind: whom it admits and what it does to movement and sight. A wall is Solid; water Allows Water; a hole Allows nobody and is not Solid; tall grass Allows Land and has a Veil.
type Kinds ¶
type Kinds interface {
// Define registers k under name and has every cell laid as it play plays. A name defined
// twice panics.
Define(name string, k Kind, plays ...*ceremony.Part)
// Named is the kind defined as name; an unknown name panics.
Named(name string) Of
// Get resolves name to the Kind registered under it.
Get(name string) (Kind, bool)
// All returns every registered Kind.
All() []Kind
}
Kinds is a board's registered set of Kinds, keyed by name as a Layout spells them.
type Level ¶ added in v0.7.0
type Level uint8
Level is which of a cell's levels a step is on: the ground, or one of the storeys built over or under it, the first OnDeck.
type Links ¶
type Links uint8
Links is which ways a Way runs on out of its cell: bit i the grid's i-th direction.
type Mobility ¶ added in v0.7.0
Mobility is how a game's units fare on the ground: the share of its top speed a unit keeps on a step, 1 full speed and nothing faster, 0 refusing the step. Factors multiply, and rest on the Step alone (whom the kind admits, its paces and grading, the slope and the domain): a share read off anything else goes stale, as the board counts only these in a cell's passage.
type MultipleOccupancy ¶
type MultipleOccupancy struct {
// contains filtered or unexported fields
}
MultipleOccupancy lets any number of entities share a cell. The zero value is ready.
func (*MultipleOccupancy) Holder ¶
Holder is the first entity holding c on a level in a domain domain shares, if any.
type Name ¶
type Name [MaxNameLen]byte
Name is a Kind's name as fixed-size bytes, so a Ground component stays contiguous in memory.
type Now ¶
type Now struct {
ID uid.UID64 // the cell's entity
Cell ID
Kind Kind // effects on its ground included
}
Now is a cell at a step, as the rules the board hosts get it.
type Occupancy ¶
type Occupancy interface {
OccupancyRead
// Enter has entity hold c on a level in domain, in place of the hold of c it had.
Enter(c ID, level Level, entity uid.UID64, domain Domain)
Leave(c ID, entity uid.UID64)
// Release lets go of every hold of an entity gone says is no more.
Release(gone func(uid.UID64) bool)
}
Occupancy tracks who holds each cell, on which of its levels and in which domains.
type OccupancyRead ¶ added in v0.4.0
type OccupancyRead interface {
// CanEnter reports whether entity, moving in domain, may hold c on level.
CanEnter(c ID, level Level, entity uid.UID64, domain Domain) bool
// Holders hands visit every hold of c.
Holders(c ID, visit func(entity uid.UID64, domain Domain, level Level))
}
OccupancyRead is who holds each cell, on which of its levels and in which domains, read.
type Of ¶
type Of struct {
// contains filtered or unexported fields
}
Of is one defined kind of cell, the handle a game builds on.
type On ¶
type On struct{ Cell ID }
On is the cell an entity standing on the board stands on for good (board.NewEntities).
type Rail ¶
Rail is a knob of an entity standing on a cell keeping the domains Keeps from crossing the edges of the cell's band, up to Height over the deck, 0 at every height: a bridge's railings, a fence.
type SingleOccupancy ¶
type SingleOccupancy struct {
// contains filtered or unexported fields
}
SingleOccupancy lets one entity per domain into a cell on each of its levels. The zero value is ready.
func (*SingleOccupancy) Holder ¶
Holder is the entity holding c on a level in a domain domain shares, if any.
type Step ¶ added in v0.7.0
Step is one step a unit moving in Domain takes onto To's Kind on its Level, from a neighbour or from To itself, over Slope: the rise over the run between the two cells' middles, 0 under a Graded kind.
type TerrainMap ¶
type TerrainMap struct {
Cells map[ID]Kind
Default Kind
// Ways is what runs across the cells over their kinds; Kind leaves them out.
Ways map[ID]Way
// Roles are the roles the cells play and Labels what they are called.
Roles map[ID]tag.Tags[cond.Roles]
Labels map[ID]ceremony.Label
// contains filtered or unexported fields
}
TerrainMap is a Terrain backed by plain maps: a board's seed, and its whole terrain on a board no ECS runs.
func NewTerrainMap ¶
func NewTerrainMap() *TerrainMap
func (*TerrainMap) Cast ¶
Cast has c play roles, none for 0, in place of those it played; Version stays as it was.
func (*TerrainMap) Kind ¶
func (t *TerrainMap) Kind(c ID) Kind
func (*TerrainMap) Label ¶
func (t *TerrainMap) Label(c ID, l ceremony.Label)
Label calls c as l says; Version stays as it was.
func (*TerrainMap) Passage ¶ added in v0.11.0
func (t *TerrainMap) Passage() uint64
Passage counts the changes to what a step over the cells reads, here every change Version counts.
func (*TerrainMap) Set ¶
func (t *TerrainMap) Set(c ID, kind Kind)
Set assigns c's terrain kind, taking effect immediately.
func (*TerrainMap) SetAll ¶
func (t *TerrainMap) SetAll(kind Kind)
SetAll resets every cell's terrain kind to kind, discarding any prior Set.
func (*TerrainMap) SetWay ¶
func (t *TerrainMap) SetWay(c ID, w Way)
SetWay lays w across c, the zero Way taking what ran there away.
func (*TerrainMap) Version ¶
func (t *TerrainMap) Version() uint64
Version counts the changes made through Set, SetAll and SetWay; a write that changes nothing does not count.
type Wall ¶
Wall is a knob of an entity standing on a cell keeping the domains Keeps off it up to Height over its level, 0 at every height: a gate. Whoever fits through its Gap passes all the same.
type Way ¶
type Way struct {
Kind Kind
Width float32
Links Links
Fade float32 // how far it has faded out across the cell, 0 to 1 gone
Mix float32 // how far its look has turned into another's, 0 to 1
}
Way is what runs across a cell over its ground, a band Width wide from the cell's middle out towards each neighbour its Links name; its Kind decides who may cross and what it costs. The zero Way is none.