diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-25 23:08:47 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:06 +0200 |
| commit | 3d36d1d0254b8aeecc889a2a49cbcced458cbe9c (patch) | |
| tree | 38dd0851d8eaa6535d05b97f29f65fc35655a5ef /go/game/action.go | |
| parent | 19fb1a7e5c5883f49e944b6499fa1ced207a3e39 (diff) | |
| download | muhqs-game-3d36d1d0254b8aeecc889a2a49cbcced458cbe9c.tar.gz muhqs-game-3d36d1d0254b8aeecc889a2a49cbcced458cbe9c.zip | |
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
Diffstat (limited to 'go/game/action.go')
| -rw-r--r-- | go/game/action.go | 64 |
1 files changed, 52 insertions, 12 deletions
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 { |
