aboutsummaryrefslogtreecommitdiff
path: root/go/game
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2024-03-25 16:04:31 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:09 +0200
commit770bc6cf967fc779775ccadc49fa4347859185a3 (patch)
treeb80e6db7582bb6c9d060288065bf2ae5f2cb07c6 /go/game
parentab1125a0d3b3bef3125f46672b7b2bcc3be98c85 (diff)
downloadmuhqs-game-770bc6cf967fc779775ccadc49fa4347859185a3.tar.gz
muhqs-game-770bc6cf967fc779775ccadc49fa4347859185a3.zip
improve tile connection detection
Diffstat (limited to 'go/game')
-rw-r--r--go/game/map.go39
1 files changed, 13 insertions, 26 deletions
diff --git a/go/game/map.go b/go/game/map.go
index 5ed1335e..378e9f2c 100644
--- a/go/game/map.go
+++ b/go/game/map.go
@@ -140,52 +140,39 @@ func (m *Map) FindNeighbours(x, y int) (left, right, above, below *Tile) {
return left, right, above, below
}
-func (m *Map) FindAnyConnections(x, y int) (connections int, left, right, above, below bool) {
+func (m *Map) FindConnections(x, y int, isConnection func(TileType) bool) (connections int, left, right, above, below bool) {
leftT, rightT, aboveT, belowT := m.FindNeighbours(x, y)
connections = 0
- if leftT != nil && leftT.Type != TileTypes.Neutral {
+ if leftT != nil && isConnection(leftT.Type) {
left = true
connections += 1
}
- if rightT != nil && rightT.Type != TileTypes.Neutral {
+ if rightT != nil && isConnection(rightT.Type) {
right = true
connections += 1
}
- if aboveT != nil && aboveT.Type != TileTypes.Neutral {
+ if aboveT != nil && isConnection(aboveT.Type) {
above = true
connections += 1
}
- if belowT != nil && belowT.Type != TileTypes.Neutral {
+ if belowT != nil && isConnection(belowT.Type) {
below = true
connections += 1
}
-
return
}
-func (m *Map) FindStreetConnections(x int, y int) (connections int, left, right, above, below bool) {
- leftT, rightT, aboveT, belowT := m.FindNeighbours(x, y)
- connections = 0
+func (m *Map) FindAnyConnections(x, y int) (connections int, left, right, above, below bool) {
+ return m.FindConnections(x, y, func(t TileType) bool { return t != TileTypes.Neutral })
+}
- if leftT != nil && leftT.Type == TileTypes.Street {
- left = true
- connections += 1
- }
- if rightT != nil && rightT.Type == TileTypes.Street {
- right = true
- connections += 1
- }
- if aboveT != nil && aboveT.Type == TileTypes.Street {
- above = true
- connections += 1
- }
- if belowT != nil && belowT.Type == TileTypes.Street {
- below = true
- connections += 1
- }
+func (m *Map) FindStreetConnections(x int, y int) (connections int, left, right, above, below bool) {
+ return m.FindConnections(x, y, func(t TileType) bool { return t == TileTypes.Street })
+}
- return
+func (m *Map) FindFortificationConnections(x int, y int) (connections int, left, right, above, below bool) {
+ return m.FindConnections(x, y, func(t TileType) bool { return t.IsFortification() })
}
func GetMap(name string) (*Map, error) {