Documentation
¶
Overview ¶
Package site is where a road may run and what laying it takes: Route finds the cheapest way from cell to cell over a Ground under the Rules, Plan turns a way into an Estimate (the cells, their links, the corners levelled and what it all comes to) or says why not (Refusal). It runs no game, so the roads plugin and a map maker (gramap, in gram-madeira-square) keep one set of rules.
A road is a cell.Way laid cell after cell. A Graded one lies as Transport Tycoon lays it (ground.RoadFits: level, or an even ramp straight up across opposite edges), a track follows the ground as it lies. The Rules are what the game allows, zero allowing nothing: how far a corner may be cut or filled and how much earth moved in all, how far from the road the levelling may ripple, how steep a ramp may be, whether a road may cross another, run over a bridge's deck or through a ford, how long one plan may be and whether it may end loose. Route prices a step by the slope the ground would have after the permitted levelling, so a road goes where the game would let it be built, and refuses a step the levelling cannot make fit; the levelling itself and its earth go into the Estimate. A Planner keeps Route's search for one road over one Ground, reads the ground anew on every route and allocates nothing once warm; Leaps add a map maker's bridges to the ways it may take.
Plan levels the ground as gramap graded Madeira's roads, on a square and a hex grid alike: the corners the neighbouring cells share classed together where a road cell lies level and along the edges where it ramps, the ramps relaxed to the slope allowed, the ground round the road following within the shaping's step, the corners that may not move holding. The Estimate's corners are what grading the cells of its Ways in order leaves on the ground; Estimate.Levelled is one cell's corners as the plan leaves them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Route ¶
func Route(g Ground, r Rules, from, to cell.ID, graded, levelling bool, leaps Leaps, dst []cell.ID) ([]cell.ID, error)
Route is the cheapest way for a road, graded or a track, from the cell from to the cell to over g under r, written into dst from from on, or a Refusal where none runs, or, its cells kept, where it runs more cells than Rules.Longest. A step costs its length at Rules.Metre (without it, one a step of the grid's Distance) by its ground's Price, dearer by Rules.Climb a unit of the slope left once a graded road's levelling digs and fills within Rules.Cut and Fill, its length alone along a road standing and over a span, a leap of leaps its Cost on top; none is taken steeper than Rules.Slope, into water but over a deck or through a ford the rules allow, onto ground that takes no road, onto a road without Rules.Crossings, across a deck, past a corner of water nor, graded, through a corner or round a bend on a cell the levelling cannot lay flat, as ground.RoadFits lays a road.
Types ¶
type CornerMove ¶
CornerMove is one corner of the ground moved by the levelling: where it lies, from what height to what.
type Estimate ¶
type Estimate struct {
// Cells are the road's cells in order, Links each one's ways out, Ways the entries to lay
// (board.BoardWrite.SetWay), the roads crossed or joined holding their old links too.
Cells []cell.ID
Links []cell.Links
Ways []cell.WayEntry
// Corners are the corners the levelling moves, as Shaper.Grade leaves them grading the cells
// of Ways in turn at their corners as Levelled says; Graded the cells whose corners move (the
// road's first, then those the levelling ripples to), Blocked those something stands on.
Corners []CornerMove
Graded []cell.ID
Blocked []cell.ID
// Crossings are the cells where the road meets a road standing, Decks and Fords those where
// it runs over a bridge's span and through a ford, no way laid on them.
Crossings []cell.ID
Decks []cell.ID
Fords []cell.ID
// Laid is how many of the cells get a way laid or a new link, Length the length of the road
// laid anew between its cells' middles, where no road ran already; Cut and Fill the earth dug
// and raised, in world units cubed; Lift and Drop the most a corner is raised and dug.
Laid int
Length float32
Cut, Fill float32
Lift float32
Drop float32
}
Estimate is a road planned: what is laid, what is levelled and what it comes to.
func Plan ¶
func Plan(g Ground, r Rules, cells []cell.ID, kind string, width float32, graded, levelling bool, step float32, extra []cell.Links) (Estimate, error)
Plan is the Estimate of a road of the kind named kind, width wide and Graded as graded says, laid through cells in order over g under r, each linked to the next where they neighbour and out as extra says (nil, or one entry a cell: a lone piece's way out) and, with levelling, levelled with the ground round it following within step (the shaping's MaxStep, 0 for none). On a Refusal of the first rule it breaks the Estimate holds what was worked out before it.
type Ground ¶
type Ground interface {
Grid() grid.Grid
// Heights are the ground's heights at c's outline, in CellOutline's order; level ground
// without a relief.
Heights(c cell.ID, dst []float32) []float32
// Takes reports whether c's ground may take a road.
Takes(c cell.ID) bool
// Wet reports whether water runs over c.
Wet(c cell.ID) bool
// Road is the links of the road running through c; none for none.
Road(c cell.ID) cell.Links
// Decked is the links of the piece of a bridge's deck lying over c, a road may run on: the
// way the deck runs, a head's one link toward the span; false without a deck.
Decked(c cell.ID) (cell.Links, bool)
// Ford reports whether c is a ford, a road may run through, whatever Wet says of it.
Ford(c cell.ID) bool
// Fixed reports whether c's corners may never move: water's bed, what stands on the cell, a
// bridge's head.
Fixed(c cell.ID) bool
// Held reports whether something stands on c that the levelling would move, a unit: the
// plan waits for the cell to be free.
Held(c cell.ID) bool
// Price is how dear a road over c is for its ground, 1 the plain price of a cell and the
// least, a lower one counted as 1; Route weighs its steps by it.
Price(c cell.ID) float32
}
Ground is what a road is planned over: a board and its heights, as the planner reads them.
type Leap ¶
Leap is a way over cells a road cannot run on, a bridge's: from a cell to the head To across the Spans cells between them, at Cost, never negative, on top of the road's length.
type Leaps ¶
Leaps gives the planner ways over what a road cannot run on, a map maker's bridges: every leap from c in the grid's direction way, appended to dst. nil for a road over the ground alone.
type Planner ¶
type Planner struct {
// contains filtered or unexported fields
}
Planner is Route kept for one road over one Ground: what it searches with is made once, so a route asked again allocates nothing; one goroutine asks it at a time.
func NewPlanner ¶
NewPlanner is the Planner of a graded road, or a track, over g under r, levelling the ground or not, over the leaps leaps makes.
type Refusal ¶
Refusal is why a road may not run or be built as planned, of the cell At.
type Rules ¶
type Rules struct {
// Cut and Fill are the most a corner may be dug down and raised, in world units.
Cut, Fill float32
// Earth is the most earth one plan may move, cut and fill together, in world units cubed.
Earth float32
// Spread is how far from the road's cells, in cells, the levelling may ripple as the ground
// round a moved corner follows it; 0 keeps it to the road's own cells.
Spread int
// Slope is the steepest ramp a Graded road may lie on, in radians, ground.RoadSlope at most;
// for a track, the steepest ground it may run over.
Slope float64
// Crossings lets a road cross and join the roads standing.
Crossings bool
// Decks lets a road run over a bridge's deck, Fords through a ford.
Decks, Fords bool
// Longest is the most cells one plan may lay, 0 or less no limit: a cap, not an allowance,
// so the one zero that forbids nothing.
Longest int
// Ends lets a road end loose in a cell; without it a road ends on a road, a deck or its
// target.
Ends bool
// Metre weighs a step's length in Route's cost (0 counts a step of the grid's Distance as 1)
// and Climb how much dearer a metre is per unit of the slope left after the permitted
// levelling; Cubic weighs the earth a leap's heads move, where a map maker's bridges lead.
Metre, Cubic, Climb float32
}
Rules are what the game allows a road: zero allows nothing, so the zero Rules lay a road on level ground alone, crossing nothing, with no earth moved.