aboutsummaryrefslogtreecommitdiff
path: root/go/game/unit.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/unit.go')
-rw-r--r--go/game/unit.go33
1 files changed, 20 insertions, 13 deletions
diff --git a/go/game/unit.go b/go/game/unit.go
index 0d39e904..aa535086 100644
--- a/go/game/unit.go
+++ b/go/game/unit.go
@@ -2,8 +2,6 @@ package game
import (
"log"
-
- "golang.org/x/exp/slices"
)
type UnitState int
@@ -74,13 +72,6 @@ func NewUnitFromPath(cardPath string, tile *Tile, owner *Player) *Unit {
}
func (u *Unit) move(s *State, tile *Tile) {
- if !slices.Contains(u.MoveRangeTiles(s.Map), tile) {
- log.Panicf("Unit %s at %v can not move to %v", u.Card.Name, u.Tile.Position, tile.Position)
- }
- if tile.Permanent != nil {
- log.Panicf("Unit %s at %v can not move to occupied %v", u.Card.Name, u.Tile.Position, tile.Position)
- }
-
u.Tile.Permanent = nil
tile.Permanent = u
u.Tile = tile
@@ -88,11 +79,24 @@ func (u *Unit) move(s *State, tile *Tile) {
func (u *Unit) MoveRangeTiles(m *Map) []*Tile {
tiles := []*Tile{}
+ // TODO: build graph only containing possible tile in movement range
+ graph := m.generateMapGraphFor(u)
for _, pos := range PositionsInRange(u.Tile.Position, u.Movement.Range, false) {
tile := m.TileAt(pos)
- if tile != nil && u.IsAvailableTile(tile) {
- tiles = append(tiles, tile)
+ if tile == nil || !u.IsAvailableTile(tile) {
+ continue
+ }
+
+ path, err := findPathTo(graph, u, pos)
+ if err != nil {
+ continue
+ }
+
+ if path.Distance/2 > int64(u.Movement.Range) {
+ continue
}
+
+ tiles = append(tiles, tile)
}
return tiles
}
@@ -149,11 +153,14 @@ func (u *Unit) FullAction() {
func (u *Unit) GetAvailActionPrototypes() []ActionPrototype {
prototypes := []ActionPrototype{}
- if u.AvailMoveActions > 0 {
+ if u.AvailMoveActions > 0 && u.Movement != INVALID_MOVEMENT() {
prototypes = append(prototypes, NewMoveActionPrototype(u))
}
- if u.AvailAttackActions > 0 {
+ m := u.GetController().gameState.Map
+ if u.AvailAttackActions > 0 && u.Attack != INVALID_ATTACK() &&
+ len(u.AttackableEnemyPermanents(m)) > 0 {
+
prototypes = append(prototypes, NewAttackActionPrototype(u))
}