2022-05-17 23:29:59 -04:00
|
|
|
package simulator
|
|
|
|
|
2022-05-19 15:18:03 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
2022-05-24 18:26:34 -04:00
|
|
|
"strconv"
|
2022-05-19 15:18:03 -04:00
|
|
|
)
|
2022-05-17 23:29:59 -04:00
|
|
|
|
|
|
|
//Player is a player controlled mob
|
|
|
|
type Player struct {
|
2022-05-19 17:09:46 -04:00
|
|
|
Resources map[itemType]int
|
2022-05-24 18:26:34 -04:00
|
|
|
Techs map[Tech]struct{}
|
2022-05-19 15:18:03 -04:00
|
|
|
CurrentTile *Tile
|
2022-05-24 18:26:34 -04:00
|
|
|
log []string
|
|
|
|
logIndex int
|
2022-05-17 23:29:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//NewPlayer initializes a player
|
|
|
|
func NewPlayer() *Player {
|
2022-05-24 18:26:34 -04:00
|
|
|
return &Player{Resources: make(map[itemType]int), Techs: make(map[Tech]struct{})}
|
2022-05-17 23:29:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Player) String() string {
|
|
|
|
var res string
|
|
|
|
res += "Resources: \n"
|
2022-05-19 17:09:46 -04:00
|
|
|
for _, i := range GlobalItemList {
|
|
|
|
if p.Resources[i] != 0 {
|
|
|
|
res += fmt.Sprintf("%v: %v\n", Lookup(i).Name(), p.Resources[i])
|
|
|
|
}
|
2022-05-17 23:29:59 -04:00
|
|
|
}
|
2022-05-19 15:18:03 -04:00
|
|
|
res += "\nLocation: \n"
|
|
|
|
if p.CurrentTile != nil {
|
|
|
|
res += p.CurrentTile.String()
|
|
|
|
}
|
2022-05-17 23:29:59 -04:00
|
|
|
return res
|
|
|
|
}
|
2022-05-24 18:26:34 -04:00
|
|
|
|
|
|
|
func (p *Player) research() {
|
|
|
|
for k, v := range p.Resources {
|
|
|
|
if k == itemPlantTea && v > 10 {
|
|
|
|
if _, ok := p.Techs[techPulper]; !ok {
|
|
|
|
p.Techs[techPulper] = struct{}{}
|
|
|
|
p.Announce("New Tech: Pulper")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Announce adds an entry to a players log
|
|
|
|
func (p *Player) Announce(msg string) {
|
|
|
|
p.logIndex++
|
|
|
|
p.log = append(p.log, strconv.Itoa(p.logIndex)+" "+msg)
|
|
|
|
if len(p.log) > 3 {
|
|
|
|
p.log = p.log[1:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Log returns the player log
|
|
|
|
func (p *Player) Log() string {
|
|
|
|
res := "Log:\n"
|
|
|
|
for _, v := range p.log {
|
|
|
|
res += v + "\n"
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|