-
Notifications
You must be signed in to change notification settings - Fork 4
/
plant.go
83 lines (70 loc) · 2.08 KB
/
plant.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import ("mud"
"fmt")
type Plant struct {
mud.PhysicalObject
AgingTimeListener
universe *mud.Universe
room *mud.Room
name string
ping chan int
stage LifeStage
lastChange int
hasMadeTree bool
}
var plantStages map[int]LifeStage
func init() {
plantStages = make(map[int]LifeStage)
hiddenSeed := LifeStage{StageNo: 0, Name: "hidden-sprout", StageChangeDelay: 10000}
sprout := LifeStage{StageNo: 1, Name: "sprout", StageChangeDelay: 20000}
stalk := LifeStage{StageNo: 2, Name: "stalk", StageChangeDelay: 40000}
miniTree := LifeStage{StageNo: 3, Name: "infant tree", StageChangeDelay: 20000}
miniTree.Post = BecomeTree
defunct := LifeStage{StageNo: 4, Name: "defunct", StageChangeDelay: -1}
addLs(hiddenSeed, plantStages)
addLs(sprout, plantStages)
addLs(stalk, plantStages)
addLs(miniTree, plantStages)
addLs(defunct, plantStages)
}
func (p Plant) Visible() bool {
return (p.stage.Name != "hidden-sprout" &&
p.stage.Name != "defunct")
}
func (p Plant) Carryable() bool { return false }
func (p Plant) TextHandles() []string {
return []string{p.name}
}
func (p Plant) Description() string {
return fmt.Sprintf("A %s.\n", p.stage.Name);
}
func (p *Plant) SetRoom(r *mud.Room) { p.room = r }
func (p Plant) Room() *mud.Room { return p.room }
func (p *Plant) Ping() chan int { return p.ping }
func (p Plant) LastChange() int { return p.lastChange }
func (p Plant) LifeStages() map[int]LifeStage { return plantStages }
func (p Plant) Stage() LifeStage { return p.stage }
func (p *Plant) SetStage(l LifeStage) { p.stage = l }
func (p *Plant) SetStageChanged(now int) { p.lastChange = now }
func BecomeTree(atl AgingTimeListener) {
p := atl.(*Plant)
if(p.Room() != nil) {
mud.Log("Age MakeTree clause, room =",p.Room())
if(TreeCount(p.Room()) < 3) {
t := MakeFruitTree(p.universe, p.name)
p.Room().AddChild(t)
} else {
p.Room().Actions() <- mud.VanishAction{Target: p}
}
}
}
func MakePlant(u *mud.Universe, name string) *Plant {
p := new(Plant)
p.universe = u
p.name = name
p.ping = make(chan int)
p.stage = plantStages[0]
u.Add(p)
go AgeLoop(p)
return p
}