cell

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 11 Imported by: 1 module, 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 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

View Source
const Levels = 4

Levels is how many levels a cell has at most: the ground and three storeys.

View Source
const MaxNameLen = 16

MaxNameLen is the longest Kind name, in bytes.

View Source
const Storeys = Levels - 1

Storeys is how many storeys a cell has.

Variables

View Source
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

func PaceOf added in v0.7.0

func PaceOf(m Mobility, s Step) float64

PaceOf is the share m gives s, a Graded kind's slope read as 0; without m the kind's own. A share out of [0, 1] panics, naming the kind, the domain and the slope.

Types

type Built

type Built struct {
	Floor Floor
	Wall  Wall
	Rail  Rail
	More  [Levels - 2]Floor
}

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

func (b *Built) Levelled() bool

Levelled reports whether a floor of b gives its cell a level beyond the ground's.

func (*Built) On added in v0.22.0

func (b *Built) On(l Level) Floor

On is the floor making b's cell's level l, the zero Floor where none does.

func (Built) Over

func (b Built) Over(under Kind) Kind

Over is under as whoever crosses the cell meets it with what is built over it, on any level.

func (*Built) Storey added in v0.22.0

func (b *Built) Storey(s uint8) *Floor

Storey is b's floor of storey s.

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.

const (
	Land Domain = 1 << iota
	Water
	Air
)

type Entry

type Entry struct {
	Kind  string
	Cell  ID
	Name  string
	Group string
	Roles tag.Tags[cond.Roles]
}

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.

func (Entry) InGroup

func (e Entry) InGroup(group string) Entry

InGroup is the entry in group.

func (Entry) Named

func (e Entry) Named(name string) Entry

Named is the entry with the name this one cell bears.

func (Entry) Plays

func (e Entry) Plays(roles ...*ceremony.Part) Entry

Plays is the entry playing roles 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

func (f Floor) Dug() bool

Dug reports whether f's room is dug under the ground: a tunnel's, a chamber's.

func (Floor) Knob

func (Floor) Knob()

Knob: an effect may turn it (effect.Knob).

func (Floor) Level added in v0.22.0

func (f Floor) Level() Level

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.

func (Floor) Room added in v0.22.0

func (f Floor) Room() bool

Room reports whether f has a room over it (Clear): dug, sunk under the ground, or Standing.

func (Floor) Sunk added in v0.22.0

func (f Floor) Sunk() bool

Sunk reports whether f lies under its cell's level: a tunnel's floor, a house's dug into a slope.

type Gap added in v0.13.0

type Gap struct {
	Width  float32
	Height float32
}

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.

func (Ground) Knob

func (Ground) Knob()

Knob: an effect may turn it (effect.Knob).

type Hiking added in v0.7.0

type Hiking struct {
	Rate, Shift float64
	Free        Domain
}

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.

func (Hiking) Pace added in v0.7.0

func (h Hiking) Pace(s Step) float64

Pace is the kind's share for the domain, slowed by the slope.

type ID

type ID uint64

ID identifies one cell of a board's grid — encoding is the topology's.

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.

func (Kind) Admits

func (k Kind) Admits(d Domain) bool

Admits reports whether an entity moving in d may stand on this kind.

func (Kind) PaceFor added in v0.7.0

func (k Kind) PaceFor(d Domain) float64

PaceFor is the share of its top speed a unit moving in d keeps here: the best among the domains this kind admits and paces, else Pace.

func (Kind) Paced added in v0.7.0

func (k Kind) Paced(d Domain, share float64) Kind

Paced returns the kind with share as the pace of the domains in d.

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.

const (
	OnGround Level = iota
	OnDeck
)
type Links uint8

Links is which ways a Way runs on out of its cell: bit i the grid's i-th direction.

func (Links) Has

func (l Links) Has(i int) bool

Has reports whether the way runs out in direction i.

type Mobility added in v0.7.0

type Mobility interface {
	Pace(s Step) float64
}

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) CanEnter

func (o *MultipleOccupancy) CanEnter(ID, Level, uid.UID64, Domain) bool

func (*MultipleOccupancy) Enter

func (o *MultipleOccupancy) Enter(c ID, level Level, entity uid.UID64, domain Domain)

func (*MultipleOccupancy) Holder

func (o *MultipleOccupancy) Holder(c ID, level Level, domain Domain) (uid.UID64, bool)

Holder is the first entity holding c on a level in a domain domain shares, if any.

func (*MultipleOccupancy) Holders

func (o *MultipleOccupancy) Holders(c ID, visit func(uid.UID64, Domain, Level))

func (*MultipleOccupancy) Leave

func (o *MultipleOccupancy) Leave(c ID, entity uid.UID64)

func (*MultipleOccupancy) Release

func (o *MultipleOccupancy) Release(gone func(uid.UID64) bool)

type Name

type Name [MaxNameLen]byte

Name is a Kind's name as fixed-size bytes, so a Ground component stays contiguous in memory.

func Named

func Named(s string) Name

Named is the Name for s; it panics past MaxNameLen.

func (Name) String

func (n Name) String() string

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.

func (Now) Who

func (n Now) Who() uid.UID64

Who is the cell's entity.

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.

func OfKind

func OfKind(k Kind) Of

OfKind is k as the handle Named hands out.

func (Of) Entry

func (o Of) Entry(c ID) Entry

Entry is a Layout entry laying this kind at c.

func (Of) Kind

func (o Of) Kind() Kind

Kind is the kind as it was defined.

func (Of) SpriteID

func (o Of) SpriteID() render.SpriteID

SpriteID is the atlas slot the kind's cells are drawn from.

type On

type On struct{ Cell ID }

On is the cell an entity standing on the board stands on for good (board.NewEntities).

type Plot

type Plot struct{ Cell ID }

Plot is which cell a cell's entity is.

type Rail

type Rail struct {
	Keeps  Domain
	Height float32
}

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.

func (Rail) Knob

func (Rail) Knob()

Knob: an effect may turn it (effect.Knob).

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) CanEnter

func (o *SingleOccupancy) CanEnter(c ID, level Level, entity uid.UID64, domain Domain) bool

func (*SingleOccupancy) Enter

func (o *SingleOccupancy) Enter(c ID, level Level, entity uid.UID64, domain Domain)

func (*SingleOccupancy) Holder

func (o *SingleOccupancy) Holder(c ID, level Level, domain Domain) (uid.UID64, bool)

Holder is the entity holding c on a level in a domain domain shares, if any.

func (*SingleOccupancy) Holders

func (o *SingleOccupancy) Holders(c ID, visit func(uid.UID64, Domain, Level))

func (*SingleOccupancy) Leave

func (o *SingleOccupancy) Leave(c ID, entity uid.UID64)

func (*SingleOccupancy) Release

func (o *SingleOccupancy) Release(gone func(uid.UID64) bool)

type Step added in v0.7.0

type Step struct {
	From, To ID
	Level    Level
	Kind     Kind
	Domain   Domain
	Slope    float64
}

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 Terrain

type Terrain interface {
	Kind(c ID) Kind
}

Terrain reports one cell's terrain kind, independent of the grid's topology.

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

func (t *TerrainMap) Cast(c ID, roles tag.Tags[cond.Roles])

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

type Wall struct {
	Keeps  Domain
	Height float32
	Gap    Gap
}

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.

func (Wall) Knob

func (Wall) Knob()

Knob: an effect may turn it (effect.Knob).

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.

func (Way) Over

func (w Way) Over(ground Kind) Kind

Over is ground as whoever crosses the cell meets it: who may, the pace and the grading from the Way's kind, the rest from the ground.

func (Way) Runs

func (w Way) Runs() bool

Runs reports whether anything runs across the cell.

type WayEntry

type WayEntry struct {
	Kind  string
	Cell  ID
	Width float32
	Links Links
	Fade  float32
	Mix   float32
}

WayEntry lays a Way of the kind named Kind across Cell.

Jump to

Keyboard shortcuts

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