Documentation ¶
Overview ¶
Package genvillage provides a very simple generator which attempts to generate a self-sustaining settlement economy given a number of buildings that consume and/or produce a number of resources.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Building ¶
type Building struct {
*BuildingType
}
Building represents an instance of BuildingType.
type BuildingPool ¶
type BuildingPool struct { Types []*BuildingType // All known building types. Provides map[string][]*BuildingType // Maps resource ID to building types that provide it. Requires map[string][]*BuildingType // Maps resource ID to building types that require it. }
BuildingPool represents all known / registered building types.
func NewBuildingPool ¶
func NewBuildingPool() *BuildingPool
NewBuildingPool returns a new, empty building pool.
func (*BuildingPool) AddType ¶
func (bp *BuildingPool) AddType(b *BuildingType)
AddType registers the given building type in the pool.
func (*BuildingPool) FindType ¶
func (bp *BuildingPool) FindType(name string) *BuildingType
FindType returns the given building type from the pool.
func (*BuildingPool) Update ¶
func (bp *BuildingPool) Update()
Update rebuilds the internal mappings for looking up building types by resource ID.
type BuildingType ¶
type BuildingType struct { Name string // Name of the building type. *Production // Produces and requires which resources. }
BuildingType represents a class of building requiring and/or providing specific resources.
func NewBuildingType ¶
func NewBuildingType(name string) *BuildingType
NewBuildingType returns a new building type with the given name.
func (*BuildingType) NewBuilding ¶
func (bt *BuildingType) NewBuilding() *Building
NewBuilding returns a new building instance of this type.
func (*BuildingType) String ¶
func (bt *BuildingType) String() string
String implements the stringer function for this building type.
type Production ¶
Production provides information on transformation per cycle.
func NewProduction ¶
func NewProduction() *Production
NewProduction returns a new production index. This represents somewhat a business or process that requires a number of resources and in turn provides other resources.
Example: A bakery requires water, flour, fire-wood, and one worker to produce bread.
func (*Production) GetExcess ¶
func (p *Production) GetExcess() map[string]int
GetExcess returns all resources that are not needed but provided.
func (*Production) GetMissing ¶
func (p *Production) GetMissing() map[string]int
GetMissing returns all resources that are needed and not provided.
type Settlement ¶
type Settlement struct { Buildings []*Building // All buildings in the settlement. *Production // Production totals for the settlement. *BuildingPool // All known building types. }
Settlement represents a village with a number of buildings.
func NewSettlement ¶
func NewSettlement(p *BuildingPool) *Settlement
NewSettlement returns a new settlement with the given BuildingPool.
func (*Settlement) AddBuilding ¶
func (s *Settlement) AddBuilding(b *Building)
AddBuilding adds the given building to the settlement and updates the totals for each resource ID.
func (*Settlement) Solve ¶
func (s *Settlement) Solve()
Solve attempts to add known building types to the settlements until the local economy is self-sustaining.
func (*Settlement) Update ¶
func (s *Settlement) Update()
Update rebuilds the totals for each resource ID required and/or provided by the local economy.