diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-08-02 14:47:01 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:33 +0200 |
| commit | c696829f9e37e9f3752fdb89ebaadd4b3b237bea (patch) | |
| tree | a205a17da9618e04f61e44d49cb028ede23dd732 /go/game/unit.go | |
| parent | ca083639a4b52215b39bb863031f71c0a8209ee9 (diff) | |
| download | muhqs-game-c696829f9e37e9f3752fdb89ebaadd4b3b237bea.tar.gz muhqs-game-c696829f9e37e9f3752fdb89ebaadd4b3b237bea.zip | |
add support for flexible attacks
Diffstat (limited to 'go/game/unit.go')
| -rw-r--r-- | go/game/unit.go | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/go/game/unit.go b/go/game/unit.go index 463a1ad9..7032d464 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -122,6 +122,16 @@ func (u *Unit) MoveRangeTiles() []*Tile { return tiles } +func (u *Unit) AttackableTile(t *Tile) (bool, Attack) { + if flexAttack := u.Attack.flexAttack; flexAttack != nil { + if _, ok := flexAttack(u, t); ok { + return true, u.Attack + } + } + + return IsPositionInRange(u.Tile().Position, t.Position, u.Attack.MaxRange()), u.Attack +} + func (u *Unit) AttackableTiles() []*Tile { // Units not on the map can not attack if u.tile == nil { @@ -129,9 +139,14 @@ func (u *Unit) AttackableTiles() []*Tile { } m := u.controller.gameState.Map() - tilesInRange := TilesInRange(m, u, u.Attack.MaxRange()) - if u.Attack.MaxRange() == 1 { - return tilesInRange + var tilesInRange []*Tile + if flexAttack := u.Attack.flexAttack; flexAttack != nil { + tilesInRange = m.FilterTiles(func(t *Tile) bool { _, ok := flexAttack(u, t); return ok }) + } else { + tilesInRange = TilesInRange(m, u, u.Attack.MaxRange()) + if u.Attack.MaxRange() == 1 { + return tilesInRange + } } // House tiles are not attackable from ranges > 1 @@ -169,8 +184,10 @@ func (u *Unit) AttackableEnemyPermanents() []Permanent { } func (u *Unit) fight(p Permanent) { - r := DistanceBetweenPermanents(p, u) - DealDamage(u, p, u.Attack.DamageInRange(r)) + d, reachable := u.Attack.DamageForTile(u, p.Tile()) + if reachable { + DealDamage(u, p, d) + } } func (u *Unit) IsDestroyed() bool { @@ -202,7 +219,7 @@ func (u *Unit) AvailSlowActions() (actions []Action) { } m := u.Controller().gameState.Map() - if u.AvailAttackActions > 0 && !INVALID_ATTACK(u.Attack) && + if u.AvailAttackActions > 0 && u.Attack.Valid() && len(u.AttackableEnemyPermanents()) > 0 { actions = append(actions, NewAttackAction(u)) |
