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/action.go | 64 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 12 deletions(-) (limited to 'go/game/action.go') diff --git a/go/game/action.go b/go/game/action.go index 09c3ec68..271f5f51 100644 --- a/go/game/action.go +++ b/go/game/action.go @@ -156,8 +156,10 @@ func NewPlayAction(p *Player, c *Card, args ...interface{}) *PlayAction { s := p.gameState if c.IsPermanent() { a.targets = newTargets(newTarget(s, permanentPlayActionTarget, a)) - } else if targetDesc := c.Impl.playTargets(); targetDesc != nil { - a.targets = newTargets(newTarget(s, *targetDesc, a)) + } else if targetDesc := c.Impl.playTargets(); targetDesc != INVALID_TARGET_DESC { + a.targets = newTargets(newTarget(s, targetDesc, a)) + } else { + a.targets = newTargets() } a.resolveFunc = func(s *State) { @@ -182,8 +184,7 @@ type MoveAction struct { var moveActionTargetDesc = TargetDesc{"available tile", "1"} -func (a *MoveAction) targetTile() *Tile { - t := a.Target() +func targetTile(t *Target) *Tile { if tile, ok := t.sel[0].(*Tile); ok { return tile } @@ -202,8 +203,8 @@ func NewMoveAction(u *Unit) *MoveAction { a.targets = newTargets(newTarget(u.Controller().gameState, moveActionTargetDesc, a)) a.resolveFunc = func(s *State) { - tile := a.targetTile() - u.move(s, tile) + t := targetTile(a.Target()) + movePermanent(u, t) } a.costFunc = genMoveActionCost(u) @@ -217,8 +218,8 @@ func (a *MoveAction) String() string { return fmt.Sprintf("move %s", u.Movement.String()) } - t := a.targetTile() - return fmt.Sprintf("%s -> %v", u.FmtWController(), t.Position) + t := targetTile(a.Target()) + return fmt.Sprintf("%v -> %v", u, t.Position) } func genBaseActionCost(u *Unit, attack, move int) ActionCostFunc { @@ -274,7 +275,7 @@ func NewEquipAction(u *Unit, e *Equipment) *EquipAction { func (a *EquipAction) String() string { u := a.source.(*Unit) - return fmt.Sprintf("%s equip %v", u.FmtWController(), a.equipment) + return fmt.Sprintf("%v equip %v", u, a.equipment) } type AttackAction struct { @@ -307,7 +308,7 @@ func (a *AttackAction) String() string { } target := a.Target().sel[0].(Permanent) - return fmt.Sprintf("%s x %v", u.FmtWController(), target.Tile().Position) + return fmt.Sprintf("%v x %v", u, target.Tile().Position) } type ArtifactSwitchAction struct { @@ -334,7 +335,46 @@ func newArtifactSwitchAction(u *Unit, artifact Permanent) *ArtifactSwitchAction } func (a *ArtifactSwitchAction) String() string { - return fmt.Sprintf("%s <-> %v", a.Source().(*Unit).FmtWController(), a.Artifact) + return fmt.Sprintf("%v <-> %v", a.Source().(*Unit), a.Artifact) +} + +type ArtifactMoveAction struct { + ActionBase + Artifact Permanent +} + +func newArtifactMoveAction(u *Unit, artifact Permanent) *ArtifactMoveAction { + a := &ArtifactMoveAction{ + ActionBase{ + source: u, + Card: u.Card(), + }, + artifact, + } + + a.targets = newArtifactMoveTargets(u.Controller().gameState, a) + + a.resolveFunc = func(s *State) { + tile := targetTile(a.Targets().ts[0]) + movePermanent(u, tile) + + tile = targetTile(a.Targets().ts[1]) + movePermanent(artifact, tile) + } + + a.costFunc = genFullActionCost(u) + + return a +} + +func (a *ArtifactMoveAction) String() string { + if !a.Targets().HasSelections() { + return fmt.Sprintf("%v move %v", a.Source().(*Unit), a.Artifact) + } + + t1 := targetTile(a.Targets().ts[0]) + t2 := targetTile(a.Targets().ts[1]) + return fmt.Sprintf("%v,%v -> %v,%v", a.Source().(*Unit), a.Artifact, t1, t2) } type FullAction struct { @@ -368,7 +408,7 @@ func (a *FullAction) String() string { return fmt.Sprintf("↻ %s", a.desc) } - return fmt.Sprintf("%s ↻@%v", u.FmtWController(), a.targets) + return fmt.Sprintf("%v↻@%v", u, a.targets) } type FreeAction struct { -- cgit v1.2.3