diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-08-21 23:54:38 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-21 23:54:38 +0200 |
| commit | 2cdacf8e51d30ca05e2700bff38b2be8c3daaf18 (patch) | |
| tree | 23416a75614dd9168fddb98b4196674ff5441426 | |
| parent | 6ea5f8fb816e876a6b434d90565660e42f27a7f3 (diff) | |
| download | muhqs-game-2cdacf8e51d30ca05e2700bff38b2be8c3daaf18.tar.gz muhqs-game-2cdacf8e51d30ca05e2700bff38b2be8c3daaf18.zip | |
fix upkeep cost calculation
| -rw-r--r-- | go/game/action.go | 21 | ||||
| -rw-r--r-- | 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() } |
