aboutsummaryrefslogtreecommitdiff
path: root/go/game/state.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-25 23:08:47 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:57:06 +0200
commit3d36d1d0254b8aeecc889a2a49cbcced458cbe9c (patch)
tree38dd0851d8eaa6535d05b97f29f65fc35655a5ef /go/game/state.go
parent19fb1a7e5c5883f49e944b6499fa1ced207a3e39 (diff)
downloadmuhqs-game-3d36d1d0254b8aeecc889a2a49cbcced458cbe9c.tar.gz
muhqs-game-3d36d1d0254b8aeecc889a2a49cbcced458cbe9c.zip
intermediate commit
* Implement move artifact action * Fix widget update memory leak * update the highlights not during on each frame * do not update the unchanged label of a button * Allow to exit the game by pressing 'q' * Implement some cards from the magic set * Improve permanent formatting * Some tweaks to UnitAI code
Diffstat (limited to 'go/game/state.go')
-rw-r--r--go/game/state.go43
1 files changed, 39 insertions, 4 deletions
diff --git a/go/game/state.go b/go/game/state.go
index 82dccf15..604e4530 100644
--- a/go/game/state.go
+++ b/go/game/state.go
@@ -25,6 +25,7 @@ type State struct {
Permanents []Permanent
Units []*Unit
Rand *rand.Rand
+ EotEffects []effect
}
func NewState() *State {
@@ -88,6 +89,8 @@ func (s *State) Loop() []*Player {
s.ActivePhase = Phases.DiscardPhase
p.discardPhase()
+ s.endOfTurn()
+
winners = s.Map.WinCondition(s)
}
}
@@ -233,6 +236,27 @@ func (s *State) IsValidArtifactSwitch(a *ArtifactSwitchAction) error {
return nil
}
+func (s *State) IsValidArtifactMove(a *ArtifactMoveAction) error {
+ if s.ActivePhase != Phases.ActionPhase {
+ return fmt.Errorf("Play actions can only be declared during one's actions phase")
+ }
+
+ u := a.Source().(*Unit)
+ uTile := TileOrContainingPermTile(u)
+ artifact := a.Artifact
+ aTile := TileOrContainingPermTile(artifact)
+ if !IsPositionInRange(uTile.Position, aTile.Position, 1) {
+ return fmt.Errorf("Can only switch position with adjacent equipments")
+ }
+
+ solid, err := artifact.XEffect("solid")
+ if err != nil && artifact.Controller() != u.Controller() && solid > 0 {
+ return fmt.Errorf("Can only switch with solid artifacts you control")
+ }
+
+ return nil
+}
+
func (s *State) ValidateAction(a Action) (err error) {
err = a.CheckTargets(s)
if err != nil {
@@ -250,6 +274,8 @@ func (s *State) ValidateAction(a Action) (err error) {
err = s.IsValidEquip(a)
case *ArtifactSwitchAction:
err = s.IsValidArtifactSwitch(a)
+ case *ArtifactMoveAction:
+ err = s.IsValidArtifactMove(a)
case *BuyAction:
}
@@ -407,10 +433,6 @@ func (s *State) fight(p1, p2 Permanent) {
p2.fight(p1)
}
-func (s *State) MoveUnit(u *Unit, t *Tile) {
- u.move(s, t)
-}
-
func (s *State) switchPermanents(p1 Permanent, p2 Permanent) {
t1 := TileOrContainingPermTile(p1)
t2 := TileOrContainingPermTile(p2)
@@ -555,3 +577,16 @@ func (s *State) redistributeMapStoreCards() {
p.clearKnownStore()
}
}
+
+func (s *State) addEotEffect(e effect) {
+ e.apply(s)
+ s.EotEffects = append(s.EotEffects, e)
+}
+
+func (s *State) endOfTurn() {
+ for _, e := range s.EotEffects {
+ e.end(s)
+ }
+
+ s.EotEffects = []effect{}
+}