aboutsummaryrefslogtreecommitdiff
path: root/go/game/state.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/state.go')
-rw-r--r--go/game/state.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/go/game/state.go b/go/game/state.go
index d5a9bfc6..16670263 100644
--- a/go/game/state.go
+++ b/go/game/state.go
@@ -644,11 +644,25 @@ func (s *LocalState) destroyPermanent(p Permanent) {
s.events = append(s.events, Event{eventType: EventTypes.Destruction, affected: []any{p}})
}
+// fight implements the effect of two permanents fighting.
func (s *LocalState) fight(p1, p2 Permanent) {
p1.fight(p2)
p2.fight(p1)
}
+// attack implements the effects of a permanent p1 attacking another permanent p2.
+func (s *LocalState) attack(p1, p2 Permanent) {
+ if p1 == p2 {
+ log.Panic("A unit can not attack itself")
+ }
+ d := DistanceBetweenPermanents(p1, p2)
+ if d > 1 && p2.RangeProtected() {
+ log.Panic("Range protected unit can only be attacked in melee combat")
+ }
+
+ s.fight(p1, p2)
+}
+
func (s *LocalState) switchPermanents(p1 Permanent, p2 Permanent) {
t1 := TileOrContainingPermTile(p1)
t2 := TileOrContainingPermTile(p2)