-
Notifications
You must be signed in to change notification settings - Fork 4
/
compAi.go
62 lines (51 loc) · 1.26 KB
/
compAi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gamecs
import (
"math/rand"
"github.com/Flokey82/aifiver"
)
// CompAi is the AI component.
type CompAi struct {
id int
w *World
*CAiPerception
*CAiScheduler
*CAiStatus
*CAiMemory
*CAiPath
aifiver.SmallModel
}
// newCompAi returns a new AI component.
func newCompAi(w *World, id int) *CompAi {
c := &CompAi{
id: id,
w: w,
CAiPerception: newCAiPerception(),
CAiScheduler: newCAiScheduler(),
CAiStatus: newCAiStatus(),
CAiMemory: newCAiMemory(),
CAiPath: newCAiPath(),
}
// Randomize.
c.SmallModel[aifiver.FactorAgreeableness] = rand.Intn(10) - 5
c.CAiPerception.init(c)
c.CAiScheduler.init(c)
c.CAiStatus.init(c)
c.CAiMemory.init(c)
c.CAiPath.init(c)
return c
}
// Conflict returns true if the personality indicates low agreeableness.
func (c *CompAi) Conflict() bool {
return c.Get(aifiver.FactorAgreeableness) <= 0
}
// Update updates the AI state, performs calculations and magic.
func (c *CompAi) Update(m *CompMovable, s *CompStatus, delta float64) {
// Update perception.
c.CAiPerception.Update(m, delta)
// Update states.
c.CAiStatus.Update(s, delta)
// Re-evaluate current plans, tasks, or states.
c.CAiScheduler.Update(delta)
// Update any path charted.
c.CAiPath.Update(m, delta)
}