Documentation
¶
Overview ¶
Package plan is what an entity does over time: loops run on its mind every step, made of the same steps a rule has and of what lasts.
plan.New("order", plan.OneOf(
plan.Loop[Received]{
Name: "fulfil",
When: cond.Self.If(cond.Always),
Then: plan.Self.Do(Invoice{}),
Until: cond.Self.If(Paid{}),
Timeout: 14 * 24 * time.Hour,
},
plan.Loop[any]{Name: "idle", When: cond.Self.If(cond.Always), Then: plan.Self.Idle()},
))
Loops ¶
A Loop says when it begins (When), what it does (Then) and when it ends: Until, a condition that comes to hold from its start — a fact's value in it, cond.Self.If(reply{}), is the fact come afresh — Timeout, after which it fails, and Cooldown, within which it does not begin again. A plan done begins again the next step. Steps runs loops in turn, OneOf the first whose When holds, an earlier one taking over once it can.
Steps ¶
Self has every step a rule's act.Self has, and Entity.Wait and Entity.Idle, which last; Other is act.Other. A rule's steps and groups (act.Self.Do, act.Steps) are parts of a plan too; a plan's are not a rule's.
Plans ¶
New makes a Planned, the plan's mind as a kind's component; Plans runs every plan registered on it (Plans.Register) over the entities a store's binding hands it (Plans.Bind, Plans.Tick) on the clock and the seed it was made with (NewPlans).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Self is the entity the plan is about. Self = Entity{act.Self} // Other is the subject of the fact the loop stands on; a step of it fails while there is // none. Other = act.Other )
var At = act.At
At is a rule's; a plan has no places.
Functions ¶
This section is empty.
Types ¶
type Entity ¶
Entity is the entity the plan is about, with the steps that last besides a rule's.
type Loop ¶
type Loop[P any] struct { Name string // required at the top of a plan When cond.Cond // required: cond.Self.If(cond.Always) for every time Then Part // required Until cond.Cond // ends well once it holds; a fact in it is one come afresh Timeout time.Duration // fails once it has run this long Cooldown time.Duration // does not begin again within this of its last run }
Loop is what an entity does over time on the fact P (any for none): Then run from the start as When comes to hold, going on until Until holds, failing after Timeout, not beginning again within Cooldown of its last run. A loop of a fact begins once as the fact comes to hold its When and runs to the end; one of any runs while its When holds.
type Part ¶
Part is a part of a plan: a rule's step (act.Step), a step that lasts (Self.Wait, Self.Idle), a Loop, or Steps and OneOf of them.
type Planned ¶ added in v0.2.0
Planned is what New makes: the plan's mind as a kind's component, registered on the Plans of the world the kind is defined in.
type Plans ¶
type Plans struct {
// contains filtered or unexported fields
}
Plans runs the plans of every entity with a store.Mind, once every step of the simulation: a store's binding binds it and ticks it over the blocks of entities it walks.
func NewPlans ¶
func NewPlans(now func() time.Duration, seed uint64, fx effect.Runtime, commands *command.Carrier) *Plans
NewPlans is the plans on the clock now, drawing Chance from seed, casting fx and giving their commands to commands.
func (*Plans) Bind ¶ added in v0.2.0
Bind lays every plan out and binds the facts their steps read and write to the store's columns. The binding calls it once, as it sets up; a plan registered after panics.
func (*Plans) Facts ¶ added in v0.2.0
Facts are the types of the facts the plans read and write, for the store to keep.
func (*Plans) Register ¶ added in v0.2.0
Register defines p on the plans, once; a name defined twice, or after Bind, panics.