diff options
Diffstat (limited to 'go/game/unit.go')
| -rw-r--r-- | go/game/unit.go | 85 |
1 files changed, 62 insertions, 23 deletions
diff --git a/go/game/unit.go b/go/game/unit.go index f4f7d9cc..2bc90992 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -1,24 +1,65 @@ package game -type UnitState int +import ( + "log" +) + +type UnitMark int const ( - Paralysis UnitState = iota + 1 - Poison - Panic - Rage - Ward + paralysis UnitMark = iota + 1 + poison + panic_ + rage + ward + faith ) +func (mark UnitMark) String() string { + switch mark { + case paralysis: + return "paralysis" + case poison: + return "poison" + case panic_: + return "panic" + case rage: + return "rage" + case ward: + return "ward" + case faith: + return "faith" + default: + log.Fatalf("Unhandled unit mark %d", mark) + return "" + } +} + +var UnitMarks = struct { + Paralysis UnitMark + Poison UnitMark + Panic UnitMark + Rage UnitMark + Ward UnitMark + Faith UnitMark +}{ + Paralysis: paralysis, + Poison: poison, + Panic: panic_, + Rage: rage, + Ward: ward, + Faith: faith, +} + type Unit struct { PermanentBase Health int Movement Movement Attack Attack Upkeep int - FullActions []*FullActionPrototype - FreeActions []*FreeActionPrototype - States []UnitState + FullActions []*FullAction + FreeActions []*FreeAction + States map[UnitMark]int // Effects []Effects AvailMoveActions int AvailAttackActions int @@ -52,12 +93,13 @@ func NewUnit(card *Card, tile *Tile, owner *Player) *Unit { Movement: movement, Attack: attack, Upkeep: upkeep, + States: make(map[UnitMark]int), AvailMoveActions: 1, AvailAttackActions: 1, } - u.FullActions = card.Impl.fullActionPrototypes(u) - u.FreeActions = card.Impl.freeActionPrototypes(u) + u.FullActions = card.Impl.fullActions(u) + u.FreeActions = card.Impl.freeActions(u) tile.Permanent = u return u @@ -124,10 +166,6 @@ func (u *Unit) AttackableEnemyPermanents(m *Map) []Permanent { return permanents } -func (u *Unit) IsAvailableTile(tile *Tile) bool { - return tile.IsAvailableForCard(u.card) -} - func (u *Unit) Fight(p Permanent) { DealDamage(u, p, u.Attack.Damage) } @@ -147,26 +185,27 @@ func (u *Unit) HasFullAction() bool { func (u *Unit) FullAction() { } -func (u *Unit) AvailActionPrototypes() []ActionPrototype { - prototypes := []ActionPrototype{} +func (u *Unit) AvailActions() (actions []Action) { if u.AvailMoveActions > 0 && u.Movement != INVALID_MOVEMENT() { - prototypes = append(prototypes, NewMoveActionPrototype(u)) + actions = append(actions, NewMoveAction(u)) } m := u.Controller().gameState.Map if u.AvailAttackActions > 0 && u.Attack != INVALID_ATTACK() && len(u.AttackableEnemyPermanents(m)) > 0 { - prototypes = append(prototypes, NewAttackActionPrototype(u)) + actions = append(actions, NewAttackAction(u)) } - for _, p := range u.FullActions { - prototypes = append(prototypes, p) + if u.AvailAttackActions > 0 && u.AvailMoveActions > 0 { + for _, p := range u.FullActions { + actions = append(actions, p) + } } for _, p := range u.FreeActions { - prototypes = append(prototypes, p) + actions = append(actions, p) } - return prototypes + return actions } |
