aboutsummaryrefslogtreecommitdiff
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-01-27 16:43:54 +0100
commit0229868f43c09b3e0a89182dc0214984b089c3e4 (patch)
tree8375d15f52c6a6945e48877e22d35a35101ddacf
parent53f15bcda076043dbd6763fc85f6bd85cc7f3e71 (diff)
downloadmuhqs-game-0229868f43c09b3e0a89182dc0214984b089c3e4.tar.gz
muhqs-game-0229868f43c09b3e0a89182dc0214984b089c3e4.zip
improve tile connection detection
-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) {