From 3d36d1d0254b8aeecc889a2a49cbcced458cbe9c Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 25 Feb 2023 23:08:47 +0100 Subject: intermediate commit * Implement move artifact action * Fix widget update memory leak * update the highlights not during on each frame * do not update the unchanged label of a button * Allow to exit the game by pressing 'q' * Implement some cards from the magic set * Improve permanent formatting * Some tweaks to UnitAI code --- go/game/unit.go | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'go/game/unit.go') diff --git a/go/game/unit.go b/go/game/unit.go index 99c7c28d..f1e38078 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -1,10 +1,5 @@ package game -import ( - "fmt" - "log" -) - const ( DEFAULT_AVAIL_MOVE_ACTIONS = 1 DEFAULT_AVAIL_ATTACK_ACTIONS = 1 @@ -62,12 +57,8 @@ func NewUnit(card *Card, tile *Tile, owner *Player) *Unit { return u } -func (u *Unit) Fmt() string { - return fmt.Sprintf("%s@%v", u.Card().Name, TileOrContainingPermTile(u)) -} - -func (u *Unit) FmtWController() string { - return fmt.Sprintf("%s's %s@%v", u.Controller().Name, u.Card().Name, TileOrContainingPermTile(u)) +func (u *Unit) String() string { + return FmtPermanent(u) } func NewUnitFromPath(cardPath string, tile *Tile, owner *Player) *Unit { @@ -88,24 +79,11 @@ func (u *Unit) onUpkeep() { u.resetBaseActions() } -func (u *Unit) move(s *State, tile *Tile) { - if !u.IsAvailableTile(tile) { - log.Panicf("moving to not available tile %v", tile) - } - - if u.containingPerm != nil { - removePermanentFromPile(u.containingPerm, u) - } else { - leaveTile(u) - } - - enterTileOrPile(u, tile) -} - func (u *Unit) MoveRangeTiles(m *Map) []*Tile { tiles := []*Tile{} // TODO: build graph only containing possible tile in movement range graph := m.generateMapGraphFor(u) + // graph := m.generateMovementRangeGraphFor(u) origin := TileOrContainingPermTile(u).Position for _, pos := range PositionsInRange(origin, u.Movement.Range, false) { tile := m.TileAt(pos) @@ -215,6 +193,10 @@ func (u *Unit) AvailSlowActions() (actions []Action) { actions = append(actions, NewEquipAction(u, equipment)) } } + + if tile.Permanent.Card().Type.IsArtifact() { + actions = append(actions, newArtifactMoveAction(u, tile.Permanent)) + } } } @@ -288,13 +270,13 @@ func (u *Unit) removeFullAction(tag string) { } } -func (u *Unit) addDamage(damage int) { - if u.Marks(UnitMarks.Ward) > 0 { +func (u *Unit) adjustDamage(damage int) { + if damage > 0 && u.Marks(UnitMarks.Ward) > 0 { u.adjustMarks(UnitMarks.Ward, -1) return } - u.permanentBase.addDamage(damage) + u.permanentBase.adjustDamage(damage) } func (u *Unit) equip(e *Equipment) { -- cgit v1.2.3