From 8c3456f5a120a00f8a4e89065d7d50f2c1b4ad0d Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 4 Feb 2023 18:51:31 +0100 Subject: improve permanent pile support * Fix alot of bugs caused by permanents without tiles * Implement a permanent choice to select the permanents in a pile * Fix how pile hooks are called --- go/game/unit.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'go/game/unit.go') diff --git a/go/game/unit.go b/go/game/unit.go index a0d6bfa4..d38d156d 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -146,11 +146,21 @@ func (u *Unit) move(s *State, tile *Tile) { } } +func (u *Unit) TileOrContainingPermTile() *Tile { + tile := u.tile + if tile == nil { + tile = u.containingPerm.Tile() + } + + return 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) { + origin := u.TileOrContainingPermTile().Position + for _, pos := range PositionsInRange(origin, u.Movement.Range, false) { tile := m.TileAt(pos) if tile == nil || !u.IsAvailableTile(tile) { continue @@ -171,6 +181,10 @@ func (u *Unit) MoveRangeTiles(m *Map) []*Tile { } func (u *Unit) AttackableTiles(m *Map) []*Tile { + // Units not on the map can not attack + if u.tile == nil { + return nil + } return TilesInRange(m, u, u.Attack.MaxRange()) } @@ -207,7 +221,8 @@ func (u *Unit) IsDestroyed() bool { } func (u *Unit) Attackable() bool { - return true + // Only units on the map are attackable + return u.tile != nil } func (u *Unit) HasFullAction() bool { -- cgit v1.2.3