tins2020/map.go

60 lines
1.2 KiB
Go
Raw Normal View History

package tins2020
import "opslag.de/schobers/geom"
type Map struct {
Temp NoiseMap
Humid NoiseMap
Variant NoiseMap
PlaceX NoiseMap // displacement map of props
PlaceY NoiseMap
Center geom.Point
Flowers map[geom.Point]Flower
}
func (m *Map) AddFlower(pos geom.Point, id string, traits FlowerTraits) {
m.Flowers[pos] = m.NewFlower(pos, id, traits)
}
func (m *Map) FlowersOnAdjacentTiles(pos geom.Point) int {
var count int
if _, ok := m.Flowers[geom.Pt(pos.X+1, pos.Y)]; ok {
count++
}
if _, ok := m.Flowers[geom.Pt(pos.X-1, pos.Y)]; ok {
count++
}
if _, ok := m.Flowers[geom.Pt(pos.X, pos.Y+1)]; ok {
count++
}
if _, ok := m.Flowers[geom.Pt(pos.X, pos.Y-1)]; ok {
count++
}
return count
}
func (m *Map) DigFlower(pos geom.Point) string {
flower, ok := m.Flowers[pos]
if !ok {
return ""
}
delete(m.Flowers, pos)
return flower.ID
}
func (m *Map) HasFlower(pos geom.Point) bool {
_, ok := m.Flowers[pos]
return ok
}
func (m *Map) NewFlower(pos geom.Point, id string, traits FlowerTraits) Flower {
flower := Flower{
ID: id,
Traits: traits,
}
temp, humid := float32(m.Temp.Value(pos.X, pos.Y)), float32(m.Humid.Value(pos.X, pos.Y))
flower.Traits.UpdateModifier(temp, humid)
return flower
}