aboutsummaryrefslogtreecommitdiff
path: root/go/game/targets.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-07-24 05:25:12 -0400
committerFlorian Fischer <florian.fischer@muhq.space>2025-07-24 12:22:10 -0400
commite78e8fb6ae67e9cd188515c1c806dfa2751327c4 (patch)
tree373b070a267caafce3016f97ab0dd07f7e4cdb74 /go/game/targets.go
parented473052c558fbda6bb03d9083b425cb2e7a808f (diff)
downloadmuhqs-game-e78e8fb6ae67e9cd188515c1c806dfa2751327c4.tar.gz
muhqs-game-e78e8fb6ae67e9cd188515c1c806dfa2751327c4.zip
support street actions
Diffstat (limited to 'go/game/targets.go')
-rw-r--r--go/game/targets.go62
1 files changed, 56 insertions, 6 deletions
diff --git a/go/game/targets.go b/go/game/targets.go
index 236b4850..b4456f55 100644
--- a/go/game/targets.go
+++ b/go/game/targets.go
@@ -623,17 +623,22 @@ func availableTileConstraint(action Action, card *Card) TargetConstraintFunc {
}
}
-func moveConstraint(s *LocalState, action Action, u *Unit) TargetConstraintFunc {
- return func(t interface{}) (err error) {
+func moveConstraint(_ *LocalState, action Action, u *Unit) TargetConstraintFunc {
+ return func(t any) (err error) {
// Some actions allow also unit targets as though they were tiles
tile := relaxedTileTarget(action, t)
- if slices.Contains(u.MoveRangeTiles(s.Map()), tile) {
+ if slices.Contains(u.MoveRangeTiles(), tile) {
return nil
}
return fmt.Errorf("tile %v is not in %v's movement range", tile, u)
}
}
+var (
+ ErrTargetWrongTileType = errors.New("wrong tile type")
+ ErrTargetNotConnectedTile = errors.New("not connected")
+)
+
func parseTileTargetConstraint(desc string, s *LocalState, action Action) []TargetConstraintFunc {
constraints := []TargetConstraintFunc{}
@@ -656,6 +661,8 @@ func parseTileTargetConstraint(desc string, s *LocalState, action Action) []Targ
card = a.Card
case *MoveAction:
card = a.Card
+ case *StreetAction:
+ card = a.Card
}
if strings.Contains(desc, "spawn") {
@@ -663,7 +670,7 @@ func parseTileTargetConstraint(desc string, s *LocalState, action Action) []Targ
log.Panicf("Not implemented spawn tile constraint for %T", action)
}
- constraints = append(constraints, func(t interface{}) (err error) {
+ constraints = append(constraints, func(t any) (err error) {
tile := relaxedTileTarget(action, t)
if slices.Contains(s.AvailableSpawnTiles(player, card), tile) {
return nil
@@ -677,7 +684,7 @@ func parseTileTargetConstraint(desc string, s *LocalState, action Action) []Targ
}
if strings.Contains(desc, "water") {
- constraints = append(constraints, func(t interface{}) (err error) {
+ constraints = append(constraints, func(t any) (err error) {
tile := t.(*Tile)
if tile.Water {
return nil
@@ -691,7 +698,7 @@ func parseTileTargetConstraint(desc string, s *LocalState, action Action) []Targ
}
if strings.Contains(desc, "free") {
- constraints = append(constraints, func(t interface{}) (err error) {
+ constraints = append(constraints, func(t any) (err error) {
tile := t.(*Tile)
if tile.IsFree() {
return nil
@@ -700,6 +707,49 @@ func parseTileTargetConstraint(desc string, s *LocalState, action Action) []Targ
})
}
+ for name := range TileNames {
+ if strings.Contains(desc, name) {
+ tileType := TileNames[name]
+ if strings.Contains(desc, "connected") {
+ // Find connected tiles
+ u := action.Source().(*Unit)
+ graph := s.Map().generateConnectedMovementRangeGraphFor(u, tileType)
+ tiles := []*Tile{}
+ for _, pos := range PositionsInRange(u.Tile().Position, u.Movement.Range, false) {
+ tile := s.Map().TileAt(pos)
+ if tile == nil || tile.Type != tileType {
+ continue
+ }
+
+ _, err := findPathTo(graph, u, pos)
+ if err != nil {
+ continue
+ }
+
+ tiles = append(tiles, tile)
+ }
+
+ // Check if tile is connected
+ constraints = append(constraints, func(t any) (err error) {
+ tile := t.(*Tile)
+ if !slices.Contains(tiles, tile) {
+ err = ErrTargetNotConnectedTile
+ }
+ return
+ })
+ }
+
+ // Tile type constraint
+ constraints = append(constraints, func(t any) error {
+ tile := t.(*Tile)
+ if tile.Type == tileType {
+ return nil
+ }
+ return ErrTargetWrongTileType
+ })
+ }
+ }
+
return constraints
}