aboutsummaryrefslogtreecommitdiff
path: root/go/game/action.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-17 00:29:26 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:50 +0100
commit65aa5f53d54b4590b98a559fccfb1cc7c7644187 (patch)
tree8b258625df3211a93efba1db889bd371e2f1d0ae /go/game/action.go
parent1c4651a7bba1e2b23a182152dc96902e9fb6868a (diff)
downloadmuhqs-game-65aa5f53d54b4590b98a559fccfb1cc7c7644187.tar.gz
muhqs-game-65aa5f53d54b4590b98a559fccfb1cc7c7644187.zip
implement unit and artifact switch action
Simplify the Choice Widget and make it a TextBox variant. Drive-by fixes: * ui.Collection: prioritize newer widgets during active widget selection * game.FullAction: fix incorrect cost function. Full actions cost all available actions. Also fix the cost check
Diffstat (limited to 'go/game/action.go')
-rw-r--r--go/game/action.go82
1 files changed, 60 insertions, 22 deletions
diff --git a/go/game/action.go b/go/game/action.go
index 77e9743f..1e25cd67 100644
--- a/go/game/action.go
+++ b/go/game/action.go
@@ -161,13 +161,7 @@ func NewMoveAction(u *Unit) *MoveAction {
u.move(s, tile)
}
- a.costFunc = func(*State) bool {
- if u.AvailMoveActions < 1 {
- return false
- }
- u.AvailMoveActions--
- return true
- }
+ a.costFunc = genMoveActionCost(u)
return a
}
@@ -182,6 +176,36 @@ func (a *MoveAction) String() string {
return fmt.Sprintf("%s -> %v", u.FmtWController(), t.Position)
}
+func genBaseActionCost(u *Unit, attack, move int) ActionCostFunc {
+ return func(*State) bool {
+ if u.AvailAttackActions < attack || u.AvailMoveActions < move {
+ return false
+ }
+ u.AvailAttackActions -= attack
+ u.AvailMoveActions -= move
+ return true
+ }
+}
+
+func genAttackActionCost(u *Unit) ActionCostFunc {
+ return genBaseActionCost(u, 1, 0)
+}
+
+func genMoveActionCost(u *Unit) ActionCostFunc {
+ return genBaseActionCost(u, 0, 1)
+}
+
+func genFullActionCost(u *Unit) ActionCostFunc {
+ return func(*State) bool {
+ if u.AvailAttackActions < 1 || u.AvailMoveActions < 1 {
+ return false
+ }
+ u.AvailAttackActions = 0
+ u.AvailMoveActions = 0
+ return true
+ }
+}
+
type AttackAction struct {
ActionBase
}
@@ -200,13 +224,7 @@ func NewAttackAction(u *Unit) *AttackAction {
s.Fight(u, a.Target().sel[0].(Permanent))
}
- a.costFunc = func(*State) bool {
- if u.AvailAttackActions < 1 {
- return false
- }
- u.AvailAttackActions--
- return true
- }
+ a.costFunc = genAttackActionCost(u)
return a
}
@@ -221,6 +239,33 @@ func (a *AttackAction) String() string {
return fmt.Sprintf("%s x %v", u.FmtWController(), target.Tile().Position)
}
+type ArtifactSwitchAction struct {
+ ActionBase
+ Artifact Permanent
+}
+
+func newArtifactSwitchAction(u *Unit, artifact Permanent) *ArtifactSwitchAction {
+ a := &ArtifactSwitchAction{
+ ActionBase{
+ source: u,
+ Card: u.Card(),
+ },
+ artifact,
+ }
+
+ a.resolveFunc = func(s *State) {
+ s.switchPermanents(a.Source().(*Unit), a.Artifact)
+ }
+
+ a.costFunc = genMoveActionCost(u)
+
+ return a
+}
+
+func (a *ArtifactSwitchAction) String() string {
+ return fmt.Sprintf("%s <-> %v", a.Source().(*Unit).FmtWController(), a.Artifact)
+}
+
type FullAction struct {
ActionBase
desc string
@@ -242,14 +287,7 @@ func NewFullAction(u *Unit, proto ActionFuncPrototype, desc string) *FullAction
rf(s)
}
- a.costFunc = func(*State) bool {
- if u.AvailAttackActions < 1 && u.AvailMoveActions < 1 {
- return false
- }
- u.AvailAttackActions--
- u.AvailMoveActions--
- return true
- }
+ a.costFunc = genFullActionCost(u)
return a
}