aboutsummaryrefslogtreecommitdiff
path: root/go/game/unit.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/unit.go')
-rw-r--r--go/game/unit.go56
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)
+}