diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-07-04 10:15:40 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-07-06 11:49:19 -0400 |
| commit | 232145193498c9d34f687485b7ad212e0100612b (patch) | |
| tree | 14c3d7d1f8bb87b642c33fa1be8a67ad4f426ff6 | |
| parent | 2289d2fb1fd7f6cbedbb1c275c4e82e9763c7b87 (diff) | |
| download | muhqs-game-232145193498c9d34f687485b7ad212e0100612b.tar.gz muhqs-game-232145193498c9d34f687485b7ad212e0100612b.zip | |
add methods to control a LocalState without enforcing game rules
| -rw-r--r-- | go/game/state.go | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/go/game/state.go b/go/game/state.go index 25385f31..6c77a42f 100644 --- a/go/game/state.go +++ b/go/game/state.go @@ -571,13 +571,38 @@ func (s *LocalState) addNewEquipment(card *Card, pos Position, owner *Player) *E return e } -func (s *LocalState) removePermanent(p Permanent) { +// MovePermanent moves a permanent without doing anything else. +// This method does not perform any checks or trigger effects. +// Its purpose is to modify the game state in situations where rules are not enforced (ui.FreeMapControl). +func (s *LocalState) MovePermanent(p Permanent, t *Tile) { + if cp := p.ContainingPerm(); cp != nil { + removePermanentFromPile(cp, p) + } else { + p.Tile().Permanent = nil + } + + if cp := t.Permanent; cp != nil { + addPermanentToPile(cp, p) + } else { + t.Permanent = p + p.SetTile(t) + } +} + +// RemovePermanent removes a Permanent from the game state. +// This method does not perform checks or triggers effects. +func (s *LocalState) RemovePermanent(p Permanent) { for i, perm := range s.permanents { if perm == p { s.permanents[i] = s.permanents[len(s.permanents)-1] s.permanents = s.permanents[:len(s.permanents)-1] } } + + switch p := p.(type) { + case *Unit: + s.units = removePtr(s.units, p) + } } func removePtr[P *Unit](collection []P, ptr P) []P { @@ -594,12 +619,7 @@ func (s *LocalState) destroyPermanent(p Permanent) { t := TileOrContainingPermTile(p) _leaveTile(p) - s.removePermanent(p) - - switch p := p.(type) { - case *Unit: - s.units = removePtr(s.units, p) - } + s.RemovePermanent(p) if pile := p.Pile(); len(pile) > 0 { dropAction := newPileDropAction(p, t, pile) @@ -794,3 +814,16 @@ func (s *LocalState) endOfTurn() { s.events = append(s.events, newEotEvent()) s.stateBasedActions() } + +// ResolveAction resolves an action without using the stack. +func (s *LocalState) ResolveAction(a Action) { + a.resolve(s) +} + +func (s *LocalState) SetPhase(p PhaseType) { + s.activePhase = p +} + +func (s *LocalState) SetActivePlayer(p *Player) { + s.activePlayerId = p.Id +} |
