diff options
Diffstat (limited to 'go/game/targets.go')
| -rw-r--r-- | go/game/targets.go | 33 |
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) |
