diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-04 14:37:15 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:47 +0100 |
| commit | ea54efacae089aa3644cfe00c8e180d5cc2c8d9e (patch) | |
| tree | 8b83151059e1d7661a366d350ef18eb913f4ce3d /go/game/unit.go | |
| parent | 9fc26075aa486e6887dbb28640224bffd1d57330 (diff) | |
| download | muhqs-game-ea54efacae089aa3644cfe00c8e180d5cc2c8d9e.tar.gz muhqs-game-ea54efacae089aa3644cfe00c8e180d5cc2c8d9e.zip | |
support crewing
* Introduce new callback for leaving a pile without beeing dropped
* Fix equipment contrsuctor
* Implement attack inheritance
Diffstat (limited to 'go/game/unit.go')
| -rw-r--r-- | go/game/unit.go | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/go/game/unit.go b/go/game/unit.go index fba85f30..a0d6bfa4 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -125,9 +125,25 @@ func (u *Unit) onUpkeep() { } func (u *Unit) move(s *State, tile *Tile) { - u.tile.Permanent = nil - tile.Permanent = u - u.tile = tile + if !u.IsAvailableTile(tile) { + log.Fatalf("moveing to not available tile %v", tile) + } + + if u.tile != nil { + u.tile.Permanent = nil + } else if u.containingPerm != nil { + RemovePermanentFromPile(u.containingPerm, u) + } else { + log.Fatalf("unit has no current location") + } + + if tile.Permanent == nil { + tile.Permanent = u + u.tile = tile + } else { // crew permanent at tile + AddPermanentToPile(tile.Permanent, u) + u.tile = nil + } } func (u *Unit) MoveRangeTiles(m *Map) []*Tile { @@ -226,14 +242,36 @@ func (u *Unit) AvailActions() (actions []Action) { return actions } -func (u *Unit) OnPile(containing Permanent) { - if _, ok := containing.(*Unit); ok { - // TODO: add attack +func (u *Unit) onPile(containing Permanent) { + u.PermanentBase.onPile(u) + if baseUnit, ok := containing.(*Unit); ok { + baseUnitAttackRange := baseUnit.Attack.MaxRange() + for r, a := range u.Attack.attacks { + if r > baseUnitAttackRange-1 { + baseUnit.Attack.attacks = append(baseUnit.Attack.attacks, a) + } else { + baseUnit.Attack.attacks[r] += a + } + } } } -func (u *Unit) OnDrop(containing Permanent) { - if _, ok := containing.(*Unit); ok { - // TODO: remove attack +func (u *Unit) onUnpile(containing Permanent) { + u.PermanentBase.onUnpile(u) + if baseUnit, ok := containing.(*Unit); ok { + for r, a := range baseUnit.Attack.attacks { + if a == u.Attack.attacks[r] { + // Remove all further attacks since they must all be from the + // dropped unit + baseUnit.Attack.attacks = baseUnit.Attack.attacks[:r] + break + } else { + baseUnit.Attack.attacks[r] -= u.Attack.attacks[r] + } + } } } + +func (u *Unit) onDrop(containing Permanent) { + u.onUnpile(containing) +} |
