2022-05-17 23:29:59 -04:00
|
|
|
package simulator
|
|
|
|
|
|
|
|
import (
|
2022-05-19 15:18:03 -04:00
|
|
|
"fmt"
|
2022-05-17 23:29:59 -04:00
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
//Plant is a plant that grows per tick
|
|
|
|
type Plant struct {
|
2022-05-19 17:09:46 -04:00
|
|
|
kind itemType
|
2022-05-19 12:58:37 -04:00
|
|
|
value int
|
|
|
|
growth int
|
2022-05-19 17:09:46 -04:00
|
|
|
rate int
|
2022-05-19 12:58:37 -04:00
|
|
|
}
|
|
|
|
|
2022-05-19 17:09:46 -04:00
|
|
|
func getPlant(k itemType) plantEntry {
|
|
|
|
return Lookup(k).(plantEntry)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newPlant(k itemType) *Plant {
|
2022-05-19 12:58:37 -04:00
|
|
|
return &Plant{
|
|
|
|
kind: k,
|
|
|
|
value: 0,
|
|
|
|
growth: 0,
|
2022-05-19 17:09:46 -04:00
|
|
|
rate: getPlant(k).rate,
|
2022-05-19 12:58:37 -04:00
|
|
|
}
|
2022-05-17 23:29:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//Tick one iteration
|
|
|
|
func (p *Plant) Tick() {
|
2022-05-19 12:58:37 -04:00
|
|
|
p.growth++
|
2022-05-19 17:09:46 -04:00
|
|
|
if p.growth > p.rate {
|
2022-05-19 12:58:37 -04:00
|
|
|
p.value++
|
|
|
|
p.growth = 0
|
|
|
|
}
|
2022-05-17 23:29:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//Get produced plant
|
|
|
|
func (p *Plant) Get() Produce {
|
|
|
|
var pro Produce
|
|
|
|
pro.Value = p.value
|
|
|
|
pro.Kind = p.kind
|
|
|
|
p.value = 0
|
|
|
|
return pro
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Plant) String() string {
|
2022-05-19 17:09:46 -04:00
|
|
|
return Lookup(p.kind).Render()
|
2022-05-17 23:29:59 -04:00
|
|
|
}
|
2022-05-19 15:18:03 -04:00
|
|
|
|
|
|
|
//Describe returns a human useful string
|
|
|
|
func (p *Plant) Describe() string {
|
2022-05-19 17:09:46 -04:00
|
|
|
return fmt.Sprintf("a %v plant with %v value", Lookup(p.kind).Name(), strconv.Itoa(p.value))
|
|
|
|
}
|
|
|
|
|
|
|
|
//Type returns producer
|
|
|
|
func (p *Plant) Type() ObjectType {
|
|
|
|
return producerObject
|
|
|
|
}
|
|
|
|
|
|
|
|
type plantEntry struct {
|
|
|
|
id itemType
|
|
|
|
rate int
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p plantEntry) Render() string {
|
|
|
|
return "w"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p plantEntry) Name() string {
|
|
|
|
return p.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p plantEntry) ID() string {
|
|
|
|
return p.id.String()
|
2022-05-19 15:18:03 -04:00
|
|
|
}
|