diff --git a/go.mod b/go.mod index 9ead3ca..9ccec38 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/koboldsim/cardtypes.go b/koboldsim/cardtypes.go index 9336949..7d53ad5 100644 --- a/koboldsim/cardtypes.go +++ b/koboldsim/cardtypes.go @@ -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 } diff --git a/koboldsim/stats.go b/koboldsim/stats.go index 9a11fca..a069b99 100644 --- a/koboldsim/stats.go +++ b/koboldsim/stats.go @@ -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) }