Kistaro Windrider
37d3b639bf
# Conflicts: # koboldsim/cards.go # koboldsim/stats.go cards.go -- Rakeela fixed a card differently from how I did stats.go -- expected; Rakeela added to the big switch statement I got rid of
249 lines
10 KiB
Go
249 lines
10 KiB
Go
package koboldsim
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"reflect"
|
|
|
|
"git.chromaticdragon.app/kistaro/CardSimEngine/cardsim"
|
|
)
|
|
|
|
// KoboldMine is the state of a kobold mine.
|
|
type KoboldMine struct {
|
|
BasePopulation float64 `cardsim:"stathidden"`
|
|
DragonCount float64 `cardsim:"stat" cardsim_name:"Dragon Population"`
|
|
|
|
Mining float64 `cardsim:"stathidden" cardsim_name:"Mining"`
|
|
Scavenging float64 `cardsim:"stathidden" cardsim_name:"Scavenging"`
|
|
Alchemy float64 `cardsim:"stathidden" cardsim_name:"Alchemy"`
|
|
Hospitality float64 `cardsim:"stathidden" cardsim_name:"Hospitality"`
|
|
Agriculture float64 `cardsim:"stathidden" cardsim_name:"Agriculture"`
|
|
Manufacturing float64 `cardsim:"stathidden" cardsim_name:"Manufacturing"`
|
|
PlanarConnections float64 `cardsim:"stathidden" cardsim_name:"Planar Connections"`
|
|
Publishing float64 `cardsim:"stathidden" cardsim_name:"Publishing"`
|
|
Forestry float64 `cardsim:"stathidden" cardsim_name:"Forestry"`
|
|
Finance float64 `cardsim:"stathidden" cardsim_name:"Finance"`
|
|
Gadgetry float64 `cardsim:"stathidden" cardsim_name:"Gadgetry"`
|
|
Fishing float64 `cardsim:"stathidden" cardsim_name:"Fishing"`
|
|
Construction float64 `cardsim:"stathidden" cardsim_name:"Construction"`
|
|
|
|
Propaganda float64 `cardsim:"stathidden" cardsim_name:"Propaganda"`
|
|
Bureaucracy float64 `cardsim:"stathidden" cardsim_name:"Bureaucracy"`
|
|
Militarism float64 `cardsim:"stathidden" cardsim_name:"Militarism"`
|
|
Welfare float64 `cardsim:"stathidden" cardsim_name:"Social Safety Net"`
|
|
Logistics float64 `cardsim:"stathidden" cardsim_name:"Logistics"`
|
|
DragonSubs float64 `cardsim:"stathidden" cardsim_name:"Dragon Subsidies"`
|
|
ResearchSubs float64 `cardsim:"stathidden" cardsim_name:"Research"`
|
|
Education float64 `cardsim:"stathidden" cardsim_name:"Education"`
|
|
Healthcare float64 `cardsim:"stathidden" cardsim_name:"Healthcare"`
|
|
ForeignRelExpense float64 `cardsim:"stathidden" cardsim_name:"Diplomatic Investment"`
|
|
ParksExpense float64 `cardsim:"stathidden" cardsim_name:"City Beautification"`
|
|
Faith float64 `cardsim:"stathidden" cardsim_name:"Faith"`
|
|
|
|
FoodSupply float64 `cardsim:"stathidden"`
|
|
ForeignRelations float64 `cardsim:"stathidden"`
|
|
HiddenRelPenalty float64 `cardsim:"stathidden"` // Lower is better.
|
|
Secrecy float64 `cardsim:"stathidden"`
|
|
Rebellion float64 `cardsim:"stathidden"`
|
|
Madness float64 `cardsim:"stathidden"`
|
|
Cruelty float64 `cardsim:"stat"`
|
|
Greed float64 `cardsim:"stathidden"`
|
|
Gullibility float64 `cardsim:"stathidden"`
|
|
Authoritarianism float64 `cardsim:"stat"`
|
|
|
|
Taxation float64 `cardsim:"stat"`
|
|
TaxEvasion float64 `cardsim:"stat"`
|
|
Squalor float64 `cardsim:"stat"`
|
|
// Idea for tax evasion. The corruption stat should increase tax evasion, while the squalor stat should reduce it. The link with corruption should be obvious, but for squalor: when the economy improves, more people have resources with which to attempt to protect their income. This is part of why rich people can evade taxes more effectively than poor people. It's not ALL lobbying advantage.
|
|
|
|
}
|
|
|
|
func (k *KoboldMine) Kobolds() int64 {
|
|
return int64((k.BasePopulation * (k.Healthcare + 1)) * (k.FoodSupply / 10) * (1 + k.TrueForeignRelations()/100))
|
|
}
|
|
|
|
const (
|
|
MinFoodSupply = 18
|
|
MaxFoodSupply = 37
|
|
MinForeignRelations = -11
|
|
MaxForeignRelations = 9
|
|
)
|
|
|
|
func (k *KoboldMine) DisplayedFoodSupply() float64 {
|
|
return 100 * (k.FoodSupply - MinFoodSupply) / (MaxFoodSupply - MinFoodSupply) //This returns a Policy Implementation Percentage, so that the player can see how good they are at capturing food supply. When it becomes possible for Food Supply to hit 0 and end the game in famine, the minimum survivable food supply PIP should be calculated and returned to the player as a warned-against failure threshold.
|
|
}
|
|
|
|
//func (k *KoboldMine) StatObesity() float64 {
|
|
//return (100 / (2.3 + math.Exp(-0.04*(k.DisplayedFoodSupply()-37)))) + 100/(2.3+math.Exp(-0.04*(k.StatObesogenicity()-37)))
|
|
//}
|
|
|
|
func (k *KoboldMine) TrueForeignRelations() float64 {
|
|
openness := 100 - clamp(k.Secrecy, 0, 100)
|
|
effectiveRel := clamp(k.ForeignRelations, -100, 100) - k.HiddenRelPenalty
|
|
return openness / 100 * effectiveRel
|
|
}
|
|
|
|
func (k *KoboldMine) DisplayedForeignRelations() float64 {
|
|
return 100 * (k.ForeignRelations - MinForeignRelations) / (MaxForeignRelations - MinForeignRelations)
|
|
}
|
|
|
|
func (k *KoboldMine) DisplayedSecrecy() float64 {
|
|
return k.Secrecy
|
|
}
|
|
|
|
func (k *KoboldMine) StatChaos() float64 {
|
|
return Mean(k.Rebellion, k.Madness, k.Cruelty)
|
|
}
|
|
|
|
// This is the "crimes of chaos" stat for my crime calculations. It will also be displayed to the player as just Chaos. The player can see Cruelty, but not Madness or Rebellion. I'm concerned some players may think, "Oh, chaos is a good thing, I want more of that as long as it's not cruel!" In that case, they'll have mad, rebellious colonies that commit crimes against those perceived to be cruel...
|
|
|
|
func (k *KoboldMine) StatCorruption() float64 {
|
|
return Mean(k.Greed, k.Gullibility, k.Authoritarianism)
|
|
}
|
|
|
|
// This is the "crimes of cunning" stat for my crime calculations. It will also be displayed to the player as just Corruption. The player can see Authoritarianism, but they'll have to infer the importance of Greed and Gullibility.
|
|
|
|
func (k *KoboldMine) Stats() []cardsim.Stat {
|
|
stats := cardsim.ExtractStats(k)
|
|
funcs := []cardsim.Stat{
|
|
cardsim.StatFunc(
|
|
"Foreign Relations",
|
|
k.DisplayedForeignRelations,
|
|
),
|
|
cardsim.StatFunc(
|
|
"Secrecy",
|
|
k.DisplayedSecrecy,
|
|
),
|
|
cardsim.StatFunc(
|
|
"Food Supply",
|
|
k.DisplayedFoodSupply,
|
|
),
|
|
cardsim.StatFunc(
|
|
"Kobolds",
|
|
k.Kobolds,
|
|
),
|
|
}
|
|
stats = append(stats, funcs...)
|
|
// cardsim.SortStats(stats)
|
|
return stats
|
|
}
|
|
|
|
func NewKoboldMine() *KoboldMine {
|
|
return &KoboldMine{
|
|
BasePopulation: 1025,
|
|
Mining: 0,
|
|
Scavenging: 0,
|
|
Alchemy: 0,
|
|
Hospitality: 0,
|
|
Agriculture: 0,
|
|
Manufacturing: 0,
|
|
PlanarConnections: 0,
|
|
Publishing: 0,
|
|
Forestry: 0,
|
|
Finance: 0,
|
|
Gadgetry: 0,
|
|
Fishing: 0,
|
|
Construction: 0,
|
|
Propaganda: 0,
|
|
Bureaucracy: 0,
|
|
Militarism: 0,
|
|
Welfare: 0,
|
|
Logistics: 0,
|
|
DragonSubs: 0,
|
|
ResearchSubs: 0,
|
|
Education: 0,
|
|
Healthcare: 0,
|
|
ForeignRelExpense: 0,
|
|
ParksExpense: 0,
|
|
Faith: 0,
|
|
FoodSupply: 20,
|
|
ForeignRelations: 0,
|
|
HiddenRelPenalty: 0,
|
|
Rebellion: 0,
|
|
Madness: 0,
|
|
Cruelty: 0,
|
|
Greed: 0,
|
|
Gullibility: 0,
|
|
Authoritarianism: 0,
|
|
Secrecy: 95,
|
|
}
|
|
}
|
|
|
|
// FieldLabel instances are strings exactly matching the name of an
|
|
// exported field in `KoboldMine`. These are used to map field names to
|
|
// amounts to change in `TablePolicy` instances, which are then looked
|
|
// up by name (via reflection) when adding the stat.
|
|
type FieldLabel string
|
|
|
|
const (
|
|
Alchemy FieldLabel = "Alchemy"
|
|
Authoritarianism FieldLabel = "Authoritarianism"
|
|
BasePopulation FieldLabel = "BasePopulation"
|
|
Bureaucracy FieldLabel = "Bureaucracy"
|
|
Construction FieldLabel = "Construction"
|
|
Cruelty FieldLabel = "Cruelty"
|
|
Education FieldLabel = "Education"
|
|
FoodSupply FieldLabel = "FoodSupply"
|
|
ForeignRelations FieldLabel = "ForeignRelations"
|
|
ForeignRelExpense FieldLabel = "ForeignRelExpense"
|
|
Gadgetry FieldLabel = "Gadgetry"
|
|
Greed FieldLabel = "Greed"
|
|
Gullibility FieldLabel = "Gullibility"
|
|
Healthcare FieldLabel = "Healthcare"
|
|
HiddenRelPenalty FieldLabel = "HiddenRelPenalty"
|
|
Hospitality FieldLabel = "Hospitality"
|
|
Logistics FieldLabel = "Logistics"
|
|
Madness FieldLabel = "Madness"
|
|
Manufacturing FieldLabel = "Manufacturing"
|
|
Militarism FieldLabel = "Militarism"
|
|
Mining FieldLabel = "Mining"
|
|
ParksExpense FieldLabel = "ParksExpense"
|
|
Publishing FieldLabel = "Publishing"
|
|
Rebellion FieldLabel = "Rebellion"
|
|
Scavenging FieldLabel = "Scavenging"
|
|
Secrecy FieldLabel = "Secrecy"
|
|
Welfare FieldLabel = "Welfare"
|
|
)
|
|
|
|
// ErrBadFieldLabel is an "error category" for all errors where a
|
|
// FieldLabel did not correctly name a Field that could be used in Add.
|
|
var ErrBadFieldLabel = errors.New("bad field label")
|
|
|
|
// ErrNoFieldLabel is a kind of `ErrBadFieldLabel` used when no field
|
|
// of the target has the exact name specified in the FieldLabel. Check
|
|
// spelling and capitalization.
|
|
var ErrNoFieldLabel = fmt.Errorf("%w: field does not exist", ErrBadFieldLabel)
|
|
|
|
// ErrFieldNotFloat is a kind of `ErrBadFieldLabel` used when it is not
|
|
// possible to read and assign a float to the named field. Is this the
|
|
// name of a calculated stat (a function) rather than a base stat?
|
|
var ErrFieldNotFloat = fmt.Errorf("%w: field type is not float", ErrBadFieldLabel)
|
|
|
|
// ErrFieldSetPanic is a kind of `ErrBadFieldLabel` used when trying to
|
|
// set the value of a field panicked. The panic message should be
|
|
// preserved in the error to diagnose the problem. If the problem is
|
|
// that the field is unexported, capitalize the name (including inside
|
|
// the KoboldMine type). Any other issue is a more complicated bug,
|
|
// because all of them that aren't already caught by ErrFieldNotFloat
|
|
// imply something very unexpected happened with `k` itself (in `Add`).
|
|
var ErrFieldSetPanic = fmt.Errorf("%w: panic when setting", ErrBadFieldLabel)
|
|
|
|
// Use a FieldLabel to add an amount to the matching field. If no such
|
|
// field can be found, the field is not exported, or the field is not
|
|
// of type float64, this returns an error ad does not change any values.
|
|
func (k *KoboldMine) Add(which FieldLabel, amount float64) error {
|
|
kv := reflect.ValueOf(k).Elem()
|
|
f := kv.FieldByName(string(which))
|
|
if !f.IsValid() {
|
|
return fmt.Errorf("cannot add %f to field %q: %w", amount, which, ErrNoFieldLabel)
|
|
}
|
|
if !f.CanFloat() {
|
|
return fmt.Errorf("cannot add %f to field %q: %w", amount, which, ErrFieldNotFloat)
|
|
}
|
|
|
|
if err := try(func() { f.SetFloat(f.Float() + amount) }); err != nil {
|
|
return fmt.Errorf("could not add %f to field %q: %w", amount, which, err)
|
|
}
|
|
return nil
|
|
}
|