fix compilation errors and warnings

This commit is contained in:
Kistaro Windrider 2024-09-29 10:27:15 -07:00
parent ba5171fd67
commit d2a00d2044
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8
3 changed files with 23 additions and 17 deletions

2
go.mod
View File

@ -8,5 +8,5 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
)

View File

@ -9,7 +9,7 @@ import (
var (
ErrOptionNotEnabled = errors.New("option not enabled")
ErrPolicyNotEnacted = errors.New("cannot unenact policy that is not enacted")
ErrNoFieldLabel = errors.New("field does not exist")
ErrNoFieldLabel = errors.New("field does not exist")
// ErrUnimplemented and ErrKeepMessaage are "non-errors". They are used
// as special signals that the result needs to be handled in a special way;
@ -191,7 +191,7 @@ type BasicPolicy struct {
}
// YesWeCan returns true. It's the default value for BasicPolicy.CanDo / BasicPolicy.CanUndo.
func YesWeCan[T any](T, *Player) bool {
func YesWeCan(*BasicPolicy, *Player) bool {
return true
}
@ -262,15 +262,15 @@ func (b *BasicPolicy) Is(p Policy) bool {
}
// TablePolicy is a Policy where all numerical changes are defined by
// adding a constant to some set of fields (defined by `EffectsTable``)
// adding a constant to some set of fields (defined by `EffectsTable)
// and subtracting it back out when de-enacting. If the currently
// enacted option is re-enacted, it refunds the player's action point.
type TablePolicy struct {
Desc cardsim.Message
UnenactedDesc cardsim.Message
EnactedDesc cardsim.Message
NothingChanged cardsim.message
EffectsTable map[FieldLabel]float64
NothingChanged cardsim.Message
EffectsTable map[FieldLabel]float64
CanDo func(*TablePolicy, *Player) bool
CurrentlyEnacted bool
@ -278,6 +278,10 @@ type TablePolicy struct {
LastEnactedIdx int
}
func YesWeAlsoCan(*TablePolicy, *Player) bool {
return true
}
// LastEnacted notifies t about the last-enacted policy in its group. It updates
// t.currentlyEnacted accordingly.
func (t *TablePolicy) LastEnacted(i int, p Policy) {
@ -326,7 +330,7 @@ func (t *TablePolicy) Unenact(p *Player) error {
}
var errs cardsim.ErrorCollector
for label, amount := range t.EffectsTable {
errs.Add(p.Stats.Add(label, -amount)
errs.Add(p.Stats.Add(label, -amount))
}
return errs.Emit()
}
@ -344,7 +348,7 @@ func (t *TablePolicy) Enabled(p *Player) bool {
func (t *TablePolicy) Is(p Policy) bool {
if o, ok := p.(*TablePolicy); ok {
return o == b
return o == t
}
return false
}

View File

@ -1,6 +1,8 @@
package koboldsim
import (
"fmt"
"git.chromaticdragon.app/kistaro/CardSimEngine/cardsim"
)
@ -168,19 +170,19 @@ func NewKoboldMine() *KoboldMine {
type FieldLabel string
const (
BasePopulation FieldLabel = "BasePopulation"
Scavenging FieldLabel = "Scavenging"
Militarism FieldLabel = "Militarism"
FoodSupply FieldLabel = "FoodSupply"
BasePopulation FieldLabel = "BasePopulation"
Scavenging FieldLabel = "Scavenging"
Militarism FieldLabel = "Militarism"
FoodSupply FieldLabel = "FoodSupply"
ForeignRelations FieldLabel = "ForeignRelations"
Rebellion FieldLabel = "Rebellion"
Madness FieldLabel = "Madness"
Cruelty FieldLabel = "Cruelty"
Rebellion FieldLabel = "Rebellion"
Madness FieldLabel = "Madness"
Cruelty FieldLabel = "Cruelty"
Authoritarianism FieldLabel = "Authoritarianism"
)
func (k *KoboldMine) Add(which FieldLabel, amount float64) error {
switch(which) {
switch which {
case BasePopulation:
k.BasePopulation += amount
return nil
@ -209,5 +211,5 @@ func (k *KoboldMine) Add(which FieldLabel, amount float64) error {
k.Authoritarianism += amount
return nil
}
return fmt.Errorf("cannot add %d to %q: %w", amount, which, ErrNoFieldLabel)
return fmt.Errorf("cannot add %f to %q: %w", amount, which, ErrNoFieldLabel)
}