aboutsummaryrefslogtreecommitdiff
path: root/go/game/targets.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-04 18:51:31 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:47 +0100
commite9070ef3752c5d2ab1f9faac48095995772ce726 (patch)
treed1842db95e73039224476d0a5794d951e3fdfb3b /go/game/targets.go
parentea54efacae089aa3644cfe00c8e180d5cc2c8d9e (diff)
downloadmuhqs-game-e9070ef3752c5d2ab1f9faac48095995772ce726.tar.gz
muhqs-game-e9070ef3752c5d2ab1f9faac48095995772ce726.zip
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
Diffstat (limited to 'go/game/targets.go')
-rw-r--r--go/game/targets.go33
1 files changed, 27 insertions, 6 deletions
diff --git a/go/game/targets.go b/go/game/targets.go
index 0ab61cbc..046c53d6 100644
--- a/go/game/targets.go
+++ b/go/game/targets.go
@@ -165,6 +165,7 @@ func attackableTargetConstraint(action Action) TargetConstraintFunc {
p, _ := t.(Permanent)
if !p.Attackable() {
err = fmt.Errorf("Permanent %v is not attackable", p)
+ return
}
if attackAction, ok := action.(*AttackAction); ok {
@@ -215,7 +216,6 @@ func parsePermanentTargetConstraint(desc string, s *State, action Action) []Targ
}
if strings.Contains(desc, "attackable ") {
- log.Println("adding attackable constrained")
constraints = append(constraints, attackableTargetConstraint(action))
}
@@ -271,6 +271,25 @@ func parseArtifactTargetConstraint(constraint string, s *State, action Action) [
return constraints
}
+func relaxedTileTarget(action Action, t interface{}) *Tile {
+ // Strict case
+ if _, ok := action.(*MoveAction); !ok {
+ return t.(*Tile)
+ }
+
+ // Move actions allow to also move to Tile occupied by a crewable permanent
+ switch t := t.(type) {
+ case *Tile:
+ return t
+ case *Unit:
+ return t.Tile()
+ default:
+ log.Fatalf("Not handled target type %T", t)
+ }
+
+ return nil
+}
+
var tileTargetConstraint TargetConstraintFunc = func(t interface{}) (err error) {
_, ok := t.(*Tile)
if !ok {
@@ -280,18 +299,20 @@ var tileTargetConstraint TargetConstraintFunc = func(t interface{}) (err error)
}
func parseTileTargetConstraint(desc string, s *State, action Action) []TargetConstraintFunc {
- log.Println("parsing", desc)
- constraints := []TargetConstraintFunc{tileTargetConstraint}
+ constraints := []TargetConstraintFunc{}
if moveAction, ok := action.(*MoveAction); ok {
u := moveAction.Source().(*Unit)
constraints = append(constraints, func(t interface{}) (err error) {
- tile := t.(*Tile)
+ tile := relaxedTileTarget(action, t)
if slices.Contains(u.MoveRangeTiles(s.Map), tile) {
return nil
}
return fmt.Errorf("tile %v is not in %v's movement range", tile, u)
})
+ // Move action allow also unit targets as though they were tiles
+ } else {
+ constraints = append(constraints, tileTargetConstraint)
}
var player *Player
@@ -314,7 +335,7 @@ func parseTileTargetConstraint(desc string, s *State, action Action) []TargetCon
}
constraints = append(constraints, func(t interface{}) (err error) {
- tile := t.(*Tile)
+ tile := relaxedTileTarget(action, t)
if slices.Contains(s.AvailableSpawnTiles(player, card), tile) {
return nil
}
@@ -324,7 +345,7 @@ func parseTileTargetConstraint(desc string, s *State, action Action) []TargetCon
if strings.Contains(desc, "available") {
constraints = append(constraints, func(t interface{}) (err error) {
- tile := t.(*Tile)
+ tile := relaxedTileTarget(action, t)
if card == nil {
log.Fatalf("Not implemented availability tile constraint for %T", action)