2020-05-10 21:00:19 +00:00
|
|
|
package tins2020
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
import "opslag.de/schobers/geom"
|
|
|
|
|
2020-05-10 21:00:19 +00:00
|
|
|
type Map struct {
|
|
|
|
Temp NoiseMap
|
|
|
|
Humid NoiseMap
|
|
|
|
Variant NoiseMap
|
|
|
|
PlaceX NoiseMap // displacement map of props
|
|
|
|
PlaceY NoiseMap
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
Center geom.Point
|
|
|
|
Flowers map[geom.Point]Flower
|
2020-05-10 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (m *Map) AddFlower(pos geom.Point, id string, traits FlowerTraits) {
|
2020-05-10 21:00:19 +00:00
|
|
|
m.Flowers[pos] = m.NewFlower(pos, id, traits)
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (m *Map) FlowersOnAdjacentTiles(pos geom.Point) int {
|
2020-05-14 06:39:42 +00:00
|
|
|
var count int
|
2020-05-17 08:56:56 +00:00
|
|
|
if _, ok := m.Flowers[geom.Pt(pos.X+1, pos.Y)]; ok {
|
2020-05-14 06:39:42 +00:00
|
|
|
count++
|
|
|
|
}
|
2020-05-17 08:56:56 +00:00
|
|
|
if _, ok := m.Flowers[geom.Pt(pos.X-1, pos.Y)]; ok {
|
2020-05-14 06:39:42 +00:00
|
|
|
count++
|
|
|
|
}
|
2020-05-17 08:56:56 +00:00
|
|
|
if _, ok := m.Flowers[geom.Pt(pos.X, pos.Y+1)]; ok {
|
2020-05-14 06:39:42 +00:00
|
|
|
count++
|
|
|
|
}
|
2020-05-17 08:56:56 +00:00
|
|
|
if _, ok := m.Flowers[geom.Pt(pos.X, pos.Y-1)]; ok {
|
2020-05-14 06:39:42 +00:00
|
|
|
count++
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (m *Map) DigFlower(pos geom.Point) string {
|
2020-05-10 21:00:19 +00:00
|
|
|
flower, ok := m.Flowers[pos]
|
|
|
|
if !ok {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
delete(m.Flowers, pos)
|
|
|
|
return flower.ID
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (m *Map) HasFlower(pos geom.Point) bool {
|
2020-05-11 13:27:22 +00:00
|
|
|
_, ok := m.Flowers[pos]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:56:56 +00:00
|
|
|
func (m *Map) NewFlower(pos geom.Point, id string, traits FlowerTraits) Flower {
|
2020-05-10 21:00:19 +00:00
|
|
|
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
|
|
|
|
}
|