aboutsummaryrefslogtreecommitdiff
path: root/go/game/unit.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-01-26 22:16:10 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:44 +0100
commit926ca5cdd20a39e3e05aaa3486cb166718dab5ca (patch)
tree3d7bc8a0e1e0be1ce8d92d5503bdede878e718e9 /go/game/unit.go
parent8720ebf9c74d9e11001772b5c00c293fa3a8b9e5 (diff)
downloadmuhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.tar.gz
muhqs-game-926ca5cdd20a39e3e05aaa3486cb166718dab5ca.zip
intermeditae commit
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))
}