From 2cdacf8e51d30ca05e2700bff38b2be8c3daaf18 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 21 Aug 2025 23:54:38 +0200 Subject: fix upkeep cost calculation --- go/game/action.go | 21 +++++++++++++++------ go/game/player.go | 1 - 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/go/game/action.go b/go/game/action.go index 5a564b07..b8c92712 100644 --- a/go/game/action.go +++ b/go/game/action.go @@ -3,10 +3,12 @@ package game import ( "errors" "fmt" - "log" "regexp" "strings" + "golang.org/x/exp/slices" + + "muhq.space/muhqs-game/go/log" "muhq.space/muhqs-game/go/utils" ) @@ -742,16 +744,22 @@ type UpkeepAction struct { func (a *UpkeepAction) PayCosts(*LocalState) bool { costs := 0 - for _, t := range a.Target().sel { - u := t.(*Unit) - costs += u.UpkeepCost() - } + p := a.player + disbanded := utils.InterfaceSliceToTypedSlice[*Unit](a.Target().sel) + + p.gameState.FilterUnits(func(u *Unit) bool { + if u.controller == p && !slices.Contains(disbanded, u) { + costs += u.UpkeepCost() + } + return false + }) + log.Debug("calculated total upkeep costs", "costs", costs) if a.player.Resource < costs { return false } - a.player.Resource -= costs + // Paying the upkeep costs is part of the resolution return true } @@ -769,6 +777,7 @@ func (a *UpkeepAction) resolve(*LocalState) { continue } + log.Debug("pay for upkeep", "costs", u.UpkeepCost(), "unit", u) p.Resource -= u.UpkeepCost() u.onUpkeep() } diff --git a/go/game/player.go b/go/game/player.go index 4eb8df2a..cd5a4b5a 100644 --- a/go/game/player.go +++ b/go/game/player.go @@ -144,7 +144,6 @@ func (p *Player) upkeep() []*Player { return s._map.WinCondition.check(s) } - // FIXME: upkeep action is special paying is part of its effect s.declareAction(a) return s.stack.resolve() } -- cgit v1.2.3