aboutsummaryrefslogtreecommitdiff
path: root/go/game/attack.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-08-06 09:34:33 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:34 +0200
commit6eb0cde9c815527db2059a006ec9bbd664b6f65d (patch)
tree18ef881ee8ef07713421c53d319780494f2e4124 /go/game/attack.go
parentdeee4b76b6ab1a94e5578818aba4b94e22e6ac89 (diff)
downloadmuhqs-game-6eb0cde9c815527db2059a006ec9bbd664b6f65d.tar.gz
muhqs-game-6eb0cde9c815527db2059a006ec9bbd664b6f65d.zip
consider houses when determining damage for a tile
Diffstat (limited to 'go/game/attack.go')
-rw-r--r--go/game/attack.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/go/game/attack.go b/go/game/attack.go
index e7d2e836..83ea6383 100644
--- a/go/game/attack.go
+++ b/go/game/attack.go
@@ -22,15 +22,27 @@ func (a Attack) Valid() bool {
}
// DamageForTile returns the damage inflicted by this attack to a tile
-func (a Attack) DamageForTile(u *Unit, t *Tile) (int, bool) {
+func (a Attack) DamageForTile(u *Unit, t *Tile) (d int, ok bool) {
+ o := u.Tile().Position
+ trgt := t.Position
+ dist := DistanceBetweenPositions(o, trgt)
+
if a.flexAttack != nil {
- return a.flexAttack(u, t)
+ d, ok = a.flexAttack(u, t)
+ } else {
+ d = a.DamageInRange(dist)
+ ok = IsPositionInRange(o, trgt, a.MaxRange())
}
- o := u.Tile().Position
- trgt := t.Position
- d := DistanceBetweenPositions(o, trgt)
- return a.DamageInRange(d), IsPositionInRange(o, trgt, a.MaxRange())
+ if !ok {
+ return
+ }
+
+ if dist > 1 && t.Type == TileTypes.House {
+ return 0, false
+ }
+
+ return
}
// MaxRange returns the biggest attackable range.