2022-05-25 16:45:23 -04:00
|
|
|
package simulator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/BurntSushi/toml"
|
|
|
|
)
|
|
|
|
|
|
|
|
//Resource is a game resource; can be planted
|
|
|
|
type Resource struct {
|
|
|
|
Id itemType `toml:"itemid"`
|
|
|
|
Name string `toml:"name"`
|
|
|
|
DisplayName string `toml:"displayName"`
|
2022-05-25 18:07:07 -04:00
|
|
|
Flavour string `toml:"flavour"`
|
2022-05-25 16:45:23 -04:00
|
|
|
Buildable bool `toml:"buildable"`
|
|
|
|
Rate int `toml:"rate"`
|
|
|
|
Icon string `toml:"icon"`
|
|
|
|
value int
|
|
|
|
growth int
|
|
|
|
}
|
|
|
|
|
|
|
|
type resources struct {
|
|
|
|
Resource []Resource
|
|
|
|
}
|
|
|
|
|
|
|
|
func newResource(k itemType) *Resource {
|
|
|
|
var res Resource
|
|
|
|
if template, ok := GlobalItems[k]; ok {
|
|
|
|
temp := template.(Resource)
|
|
|
|
res.DisplayName = temp.DisplayName
|
2022-05-25 18:07:07 -04:00
|
|
|
res.Flavour = temp.Flavour
|
2022-05-25 16:45:23 -04:00
|
|
|
res.Id = k
|
|
|
|
res.Name = temp.Name
|
|
|
|
res.Buildable = temp.Buildable
|
|
|
|
res.Rate = temp.Rate
|
2022-05-25 18:07:07 -04:00
|
|
|
res.Flavour = temp.Flavour
|
2022-05-25 16:45:23 -04:00
|
|
|
res.Icon = temp.Icon
|
|
|
|
res.value = 0
|
|
|
|
res.growth = 0
|
|
|
|
return &res
|
|
|
|
}
|
|
|
|
return &Resource{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Resource) Tick() {
|
|
|
|
if !r.Buildable {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
r.growth++
|
|
|
|
if r.growth > r.Rate {
|
|
|
|
r.value++
|
|
|
|
r.growth = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Resource) Get() Produce {
|
|
|
|
var pro Produce
|
|
|
|
pro.Value = r.value
|
|
|
|
pro.Kind = r.Id
|
|
|
|
r.value = 0
|
|
|
|
return pro
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Resource) String() string {
|
|
|
|
return r.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Resource) Render() string {
|
|
|
|
return r.Icon
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Resource) Describe() string {
|
|
|
|
return r.DisplayName
|
|
|
|
}
|
2022-05-25 18:07:07 -04:00
|
|
|
|
|
|
|
func (r Resource) Description() string {
|
|
|
|
return r.Flavour
|
|
|
|
}
|
2022-05-25 16:45:23 -04:00
|
|
|
func loadResources(filename string) {
|
|
|
|
var res resources
|
2022-05-25 18:07:07 -04:00
|
|
|
_, err := toml.DecodeFile(filename, &res)
|
2022-05-25 16:45:23 -04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
for _, v := range res.Resource {
|
|
|
|
newItem(v.Id, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Resource) ID() itemType {
|
|
|
|
return r.Id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Resource) Type() ObjectType {
|
|
|
|
return resourceObject
|
|
|
|
}
|