Documentation ¶
Index ¶
- Constants
- type ActionAttack
- type ActionConsumeItem
- type ActionIsTrue
- type ActionMoveTo
- type ActionPickUpItem
- type ActionTransferItems
- type ActionWander
- type Agent
- type CAiMemory
- type CAiPath
- type CAiPerception
- type CAiScheduler
- type CAiStatus
- func (c *CAiStatus) Eat()
- func (c *CAiStatus) HasFood() bool
- func (c *CAiStatus) Idle() bool
- func (c *CAiStatus) IsFunc(s string) func() bool
- func (c *CAiStatus) IsNotFunc(s string) func() bool
- func (c *CAiStatus) NoFood() bool
- func (c *CAiStatus) Sleep()
- func (c *CAiStatus) Update(s *CompStatus, delta float64)
- type CompAi
- type CompInventory
- func (in *CompInventory) Add(it *Item) bool
- func (in *CompInventory) Drop(it *Item) bool
- func (in *CompInventory) Find(tag string) *Item
- func (in *CompInventory) Has(itt *ItemType) bool
- func (in *CompInventory) IsFull() bool
- func (in *CompInventory) RemoveID(id int) bool
- func (in *CompInventory) TransferAll(to *CompInventory) bool
- type CompMovable
- type CompStatus
- func (c *CompStatus) Dead() bool
- func (c *CompStatus) Exhaustion() float64
- func (c *CompStatus) Health() float64
- func (c *CompStatus) Hunger() float64
- func (c *CompStatus) MaxHealth() float64
- func (c *CompStatus) Sleep()
- func (c *CompStatus) Stress() float64
- func (c *CompStatus) Thirst() float64
- func (c *CompStatus) Update(delta float64)
- func (c *CompStatus) Wake()
- type Item
- type ItemLocation
- type ItemType
- type Location
- type Manager
- func (m *Manager) Entities() []*Agent
- func (m *Manager) GetEntityFromID(id int) *Agent
- func (m *Manager) Items() []*Item
- func (m *Manager) Locations() []*Location
- func (m *Manager) NextID() int
- func (m *Manager) RegisterEntity(e *Agent)
- func (m *Manager) RegisterItem(it *Item)
- func (m *Manager) RegisterLocation(loc *Location)
- func (m *Manager) RemoveEntity(e *Agent)
- func (m *Manager) RemoveItem(it *Item)
- func (m *Manager) Reset()
- type Profession
- type ProfessionType
- type Project
- type StateAttack
- type StateEatFood
- type StateFindFood
- type StateFlee
- type StateIdle
- type StateRest
- type StateStoreFood
- type World
Constants ¶
const StateTypeAttack aistate.StateType = 2
const StateTypeFind aistate.StateType = 0
const StateTypeFlee aistate.StateType = 1
const StateTypeIdle aistate.StateType = 7
const StateTypeMunch aistate.StateType = 3
const StateTypeProfession aistate.StateType = 6
const StateTypeRest aistate.StateType = 4
const StateTypeStore aistate.StateType = 5
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionAttack ¶
type ActionAttack struct { TargetFunc func() *Agent // contains filtered or unexported fields }
func (*ActionAttack) Tick ¶
func (l *ActionAttack) Tick() aitree.State
type ActionConsumeItem ¶
type ActionConsumeItem struct { ItemFunc func() *Item // contains filtered or unexported fields }
func (*ActionConsumeItem) Tick ¶
func (l *ActionConsumeItem) Tick() aitree.State
type ActionIsTrue ¶
type ActionIsTrue struct { Eval func() bool // contains filtered or unexported fields }
func (*ActionIsTrue) Tick ¶
func (l *ActionIsTrue) Tick() aitree.State
type ActionMoveTo ¶
type ActionMoveTo struct { FailFunc func() bool PosFunc func() vectors.Vec2 // contains filtered or unexported fields }
func (*ActionMoveTo) Tick ¶
func (l *ActionMoveTo) Tick() aitree.State
type ActionPickUpItem ¶
type ActionPickUpItem struct { ItemFunc func() *Item // contains filtered or unexported fields }
func (*ActionPickUpItem) Tick ¶
func (l *ActionPickUpItem) Tick() aitree.State
type ActionTransferItems ¶
type ActionTransferItems struct { TargetFunc func() *CompInventory // contains filtered or unexported fields }
func (*ActionTransferItems) Tick ¶
func (l *ActionTransferItems) Tick() aitree.State
type ActionWander ¶
type ActionWander struct { EndCondition func() bool // contains filtered or unexported fields }
func (*ActionWander) Tick ¶
func (l *ActionWander) Tick() aitree.State
type Agent ¶
type Agent struct { *CompMovable *CompStatus *CompInventory *CompAi *Profession // contains filtered or unexported fields }
Agent is an independent entity in the world.
func (*Agent) SetProfession ¶
func (c *Agent) SetProfession(w *World, p *ProfessionType)
SetProfession assigns a profession to the agent. NOTE: This is just for experimentation and will probably be refactored into a more generic function that allows the extension of the AI.
type CAiMemory ¶
type CAiMemory struct { Locations map[string]*Location Positions map[string]vectors.Vec2 // contains filtered or unexported fields }
func (*CAiMemory) GetLocation ¶
func (*CAiMemory) SetLocation ¶
type CAiPath ¶
type CAiPath struct { Waypoints []vectors.Vec2 // Current list of waypoints. WaypointCurrent int // Current index in the waypoints array. Target vectors.Vec2 // Our current target. // contains filtered or unexported fields }
CAiPath is a path planning component.
func (*CAiPath) SetTarget ¶
SetTarget resets the current waypoints and sets the new target to move towards.
func (*CAiPath) Update ¶
func (c *CAiPath) Update(m *CompMovable, delta float64)
Update ticks the AI path planner by delta.
type CAiPerception ¶
type CAiPerception struct { Entities []*Agent Items []*Item // contains filtered or unexported fields }
func (*CAiPerception) CanSee ¶
func (c *CAiPerception) CanSee(it *Item) bool
CanSee returns true if we can see the given item. TODO: Deduplicate with CanSeeEntity.
func (*CAiPerception) CanSeeEntity ¶
func (c *CAiPerception) CanSeeEntity(it *Agent) bool
CanSeeEntity returns true if we can percieve the given entity (Agent). TODO: Deduplicate with CanSee.
func (*CAiPerception) Update ¶
func (c *CAiPerception) Update(m *CompMovable, delta float64)
Update updates the list of visible items / entities.
type CAiScheduler ¶
type CAiScheduler struct {
*aistate.StateMachine
}
func (*CAiScheduler) Update ¶
func (c *CAiScheduler) Update(delta float64)
type CAiStatus ¶
type CAiStatus struct {
// contains filtered or unexported fields
}
func (*CAiStatus) Update ¶
func (c *CAiStatus) Update(s *CompStatus, delta float64)
type CompAi ¶
type CompAi struct { *CAiPerception *CAiScheduler *CAiStatus *CAiMemory *CAiPath aifiver.SmallModel // contains filtered or unexported fields }
CompAi is the AI component.
func (*CompAi) Update ¶
func (c *CompAi) Update(m *CompMovable, s *CompStatus, delta float64)
Update updates the AI state, performs calculations and magic.
type CompInventory ¶
CompInventory represents a storage for items with a specified capacity.
func (*CompInventory) Add ¶
func (in *CompInventory) Add(it *Item) bool
Add adds the given item to the inventory and return success. NOTE: This will fail if the inventory is full.
func (*CompInventory) Drop ¶
func (in *CompInventory) Drop(it *Item) bool
Drop drops the specified item from inventory and returns true on success.
func (*CompInventory) Find ¶
func (in *CompInventory) Find(tag string) *Item
Find finds an item with a given tag in the inventory and returns the found item.
func (*CompInventory) Has ¶
func (in *CompInventory) Has(itt *ItemType) bool
Has returns true if an item with the given ItemType is present in the inventory. TODO: Maybe return count instead of bool or introduce a second method that returns the count.
func (*CompInventory) IsFull ¶
func (in *CompInventory) IsFull() bool
IsFull returns true if we have exceeded or have reached the inventory capacity
func (*CompInventory) RemoveID ¶
func (in *CompInventory) RemoveID(id int) bool
RemoveID removes the item with the given id from inventory and returns true on success.
func (*CompInventory) TransferAll ¶
func (in *CompInventory) TransferAll(to *CompInventory) bool
TransferAll transfers all items from the current inventory to the target inventory.
type CompMovable ¶
CompMovable is a movable component.
func (*CompMovable) Update ¶
func (c *CompMovable) Update(delta float64)
Update moves the position in the component by the speed within the given time.
type CompStatus ¶
type CompStatus struct { Sleeping bool // contains filtered or unexported fields }
CompStatus is a component that handles the status or state of an entity (Health, stamina, hunger, thirst...).
func (*CompStatus) Exhaustion ¶
func (c *CompStatus) Exhaustion() float64
Exhaustion returns the current exhaustion of the entity.
func (*CompStatus) Health ¶
func (c *CompStatus) Health() float64
Health returns the current health of the entity.
func (*CompStatus) Hunger ¶
func (c *CompStatus) Hunger() float64
Hunger returns the current hunger of the entity.
func (*CompStatus) MaxHealth ¶
func (c *CompStatus) MaxHealth() float64
MaxHealth returns the maximum health of the entity.
func (*CompStatus) Stress ¶
func (c *CompStatus) Stress() float64
Stress returns the current stress of the entity.
func (*CompStatus) Thirst ¶
func (c *CompStatus) Thirst() float64
Thirst returns the current thirst of the entity.
func (*CompStatus) Update ¶
func (c *CompStatus) Update(delta float64)
Update updates the status of the entity.
type Item ¶
type Item struct { Location ItemLocation // Type of location (world, inventory, ...) LocationID int // ID of the entity if in inventory Pos vectors.Vec2 // World position if in world *ItemType // Base information // contains filtered or unexported fields }
Item represents a movable item in the world.
type ItemLocation ¶
type ItemLocation int
ItemLocation indicates the type of location where an item is located.
const ( LocWorld ItemLocation = iota LocContainer LocInventory )
type ItemType ¶
type ItemType struct { Name string Tags []string // Food, Weapon Properties map[string]int // Price, weight, damage, ... Requires []*ItemType // Requires items to craft }
ItemType represents the base type of an item.
func NewItemType ¶
NewItemType returns a new item type with the given name and tags.
type Location ¶
type Location struct { Pos vectors.Vec2 // Position on the map *CompInventory // Location storage. // contains filtered or unexported fields }
Location represents a destination with storage space. (e.g. building, hut, hiding place, ...)
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a rudimentary entity manager. NOTE: This sucks. I really need to re-think and re-write this.
func (*Manager) GetEntityFromID ¶
GetEntityFromID returns the agent with the given ID (if any). NOTE: This should be generic and not be typed as *Agent.
func (*Manager) RegisterEntity ¶
RegisterEntity registers the given agent in the manager. NOTE: This should be generic and not be typed as *Agent.
func (*Manager) RegisterItem ¶
RegisterItem registers the given item in the manager.
func (*Manager) RegisterLocation ¶
RegisterLocation registers a new location.
func (*Manager) RemoveEntity ¶
RemoveEntity removes the given agent from the manager. NOTE: This should be generic and not be typed as *Agent.
func (*Manager) RemoveItem ¶
RemoveItem removes the given item from the world.
type Profession ¶
type Profession struct { *ProfessionType CurrentProject *Project // Current project? Would a queue be better? Missing []*ItemType // contains filtered or unexported fields }
Profession represents a career of an individual and performs tasks related to the production of items. Implements aistate.State.
func (*Profession) OnEnter ¶
func (s *Profession) OnEnter()
OnEnter is called when the state machine switches to this state.
func (*Profession) OnExit ¶
func (s *Profession) OnExit()
OnExit is called when the state machine switches to another state.
func (*Profession) Tick ¶
func (s *Profession) Tick(delta uint64)
Tick advances the tasks associated with the profession by the given time interval.
func (*Profession) Type ¶
func (s *Profession) Type() aistate.StateType
TODO: Implement state that solely handles work activity.
type ProfessionType ¶
ProfessionType is the general type of a profession. (e.g.: Baker, farmer, butcher, ...)
func NewProfessionType ¶
func NewProfessionType(name string, canCraft ...*ItemType) *ProfessionType
NewProfessionType returns a new profession of a given type.
func (*ProfessionType) New ¶
func (p *ProfessionType) New(w *World, a *Agent, workshop *Location) *Profession
type Project ¶
type Project struct { Produce *ItemType Progress uint64 // Amount of time invested Duration uint64 Complete bool }
Project represents a production task.
type StateAttack ¶
type StateAttack struct {
// contains filtered or unexported fields
}
StateAttack
func NewStateAttack ¶
func NewStateAttack(ai *CompAi) *StateAttack
func (*StateAttack) OnEnter ¶
func (s *StateAttack) OnEnter()
func (*StateAttack) OnExit ¶
func (s *StateAttack) OnExit()
func (*StateAttack) Tick ¶
func (s *StateAttack) Tick(delta uint64)
func (*StateAttack) Type ¶
func (s *StateAttack) Type() aistate.StateType
type StateEatFood ¶
type StateEatFood struct {
// contains filtered or unexported fields
}
StateEatFood will be active if the agent is hungry and we have food.
func NewStateEatFood ¶
func NewStateEatFood(ai *CompAi) *StateEatFood
func (*StateEatFood) OnEnter ¶
func (s *StateEatFood) OnEnter()
func (*StateEatFood) OnExit ¶
func (s *StateEatFood) OnExit()
func (*StateEatFood) Tick ¶
func (s *StateEatFood) Tick(delta uint64)
func (*StateEatFood) Type ¶
func (s *StateEatFood) Type() aistate.StateType
type StateFindFood ¶
type StateFindFood struct {
// contains filtered or unexported fields
}
func NewStateFindFood ¶
func NewStateFindFood(ai *CompAi) *StateFindFood
func (*StateFindFood) OnEnter ¶
func (s *StateFindFood) OnEnter()
func (*StateFindFood) OnExit ¶
func (s *StateFindFood) OnExit()
func (*StateFindFood) Tick ¶
func (s *StateFindFood) Tick(delta uint64)
func (*StateFindFood) Type ¶
func (s *StateFindFood) Type() aistate.StateType
type StateFlee ¶
type StateFlee struct {
// contains filtered or unexported fields
}
StateFlee
func NewStateFlee ¶
type StateIdle ¶
type StateIdle struct {
// contains filtered or unexported fields
}
func NewStateIdle ¶
type StateRest ¶
type StateRest struct {
// contains filtered or unexported fields
}
StateRest will be active once an agent is exhausted. In this state, the agent will attempt to return home to rest.
func NewStateRest ¶
type StateStoreFood ¶
type StateStoreFood struct {
// contains filtered or unexported fields
}
func NewStateStoreFood ¶
func NewStateStoreFood(ai *CompAi) *StateStoreFood
func (*StateStoreFood) OnEnter ¶
func (s *StateStoreFood) OnEnter()
func (*StateStoreFood) OnExit ¶
func (s *StateStoreFood) OnExit()
func (*StateStoreFood) Tick ¶
func (s *StateStoreFood) Tick(delta uint64)
func (*StateStoreFood) Type ¶
func (s *StateStoreFood) Type() aistate.StateType
Source Files ¶
- ai_actions.go
- ai_memory.go
- ai_path.go
- ai_perception.go
- ai_state_exhausted.go
- ai_state_hungry.go
- ai_state_idle.go
- ai_state_threatened.go
- ai_statemachine.go
- ai_status.go
- compAi.go
- compInventory.go
- compMovable.go
- compStatus.go
- entityAgent.go
- entityItem.go
- entityLocation.go
- gamecs.go
- manager.go
- profession.go