Compare commits

9 Commits

Author SHA1 Message Date
37d3b639bf Merge branch 'Rewrite-Stats-System' of https://git.chromaticdragon.app/kistaro/KoboldSim into effects_table
# 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
2024-09-29 12:51:39 -07:00
39e4c94b6f Merge branch 'Rewrite-Stats-System' of https://git.chromaticdragon.app/kistaro/KoboldSim into Rewrite-Stats-System 2024-09-29 12:48:46 -07:00
99c5e5af6d Converting cards to effectstables 2024-09-29 12:48:19 -07:00
a237fa81bf pull try out of Add
deferring a recovery handler is normal in Go but opaque. Pulling out a helper for this (`try`) makes it more obvious that this is just another "if this operation fails, return error" case.
2024-09-29 12:41:49 -07:00
68cab7d2be Remove stale "Add case" snippet
The reflection-driven implementation of Add no longer contains a huge boilerplate `switch` statement so we no longer need a snippet for the boilerplate.
2024-09-29 12:20:53 -07:00
2d16f97314 Remiplement Add to use reflection.
Now it matters whether `FieldLabel`s are spelled correctly, but in return, we don't have to write and maintain that obnoxious `switch` statement.
2024-09-29 12:19:07 -07:00
8a28f38d4d Finish converting second option of Pan-Tribal Festival of Bureaucracy. 2024-09-29 12:18:12 -07:00
b2099586fc reimplement clamp as mid
removes an opportunity to write a bug by swapping low and high
2024-09-29 12:09:11 -07:00
c4427885ca Converting cards to TablePolicy 2024-09-29 11:14:31 -07:00
5 changed files with 253 additions and 314 deletions

View File

@ -15,13 +15,4 @@
// ], // ],
// "description": "Log output to console" // "description": "Log output to console"
// } // }
"KoboldMine Add case": {
"scope": "go",
"prefix": "case",
"body": [
"case ${1:field}:",
"\tk.${1:field} += amount",
"\treturn k.${1:field}",
],
}
} }

View File

@ -27,70 +27,45 @@ var cards = []Card{
EnactionDesc: cardsim.MsgStr("Kobolds are known to be born warriors."), EnactionDesc: cardsim.MsgStr("Kobolds are known to be born warriors."),
CanDo: YesWeAlsoCan, CanDo: YesWeAlsoCan,
}, },
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`Your head miner considers the matter worriedly. "Creches under military control? No. That would invite chaos. We need to dig deeper; we can have a peaceful, orderly society if we just get far enough away from surfacers."`), UnenactedDesc: cardsim.MsgStr(`Your head miner considers the matter worriedly. "Creches under military control? No. That would invite chaos. We need to dig deeper; we can have a peaceful, orderly society if we just get far enough away from surfacers."`),
EnactedDesc: cardsim.MsgStr("[current policy] Your head miner is presently leading a project to dig as far away from the surface as possible."), EnactedDesc: cardsim.MsgStr("[current policy] Your head miner is presently leading a project to dig as far away from the surface as possible."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation += 40 BasePopulation: 40,
p.Stats.Mining += 2 Mining: 2,
p.Stats.Construction += 1 Construction: 1,
p.Stats.Manufacturing += 1 Manufacturing: 1,
p.Stats.Bureaucracy += 1 Bureaucracy: 1,
p.Stats.FoodSupply -= 1 FoodSupply: -1,
p.Stats.Secrecy += 3 Secrecy: 3,
return cardsim.MsgStr("Kobolds are known to be cowards hiding in the dark."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("Kobolds are known to be cowards hiding in the dark."),
p.Stats.BasePopulation -= 40 CanDo: YesWeAlsoCan,
p.Stats.Mining -= 2
p.Stats.Manufacturing -= 1
p.Stats.Construction -= 1
p.Stats.Bureaucracy -= 1
p.Stats.FoodSupply += 1
p.Stats.Secrecy -= 3
return nil
},
CanDo: YesWeCan,
}, },
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`Your nursery director is incensed. "Creches under military control? Never! Let young kobolds play! In fact, cut the military just for suggesting this. The threats facing us are completely overstated."`), UnenactedDesc: cardsim.MsgStr(`Your nursery director is incensed. "Creches under military control? Never! Let young kobolds play! In fact, cut the military just for suggesting this. The threats facing us are completely overstated."`),
EnactedDesc: cardsim.MsgStr("[current policy] Military funding has been diverted into early childhood education."), EnactedDesc: cardsim.MsgStr("[current policy] Military funding has been diverted into early childhood education."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation -= 40 BasePopulation: -40,
p.Stats.Scavenging -= 1 Scavenging: -1,
p.Stats.Militarism -= 2 Militarism: -2,
p.Stats.Education += 1 Education: 1,
p.Stats.FoodSupply -= 1 FoodSupply: -2,
p.Stats.ForeignRelations += 2 ForeignRelations: 2,
p.Stats.Madness -= 1 Madness: -1,
p.Stats.Cruelty -= 1 Cruelty: -1,
return cardsim.MsgStr("An undefended hunting outpost near the surface was recently wiped out by a raid."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("An undefended hunting outpost near the surface was recently wiped out by a raid."),
p.Stats.BasePopulation += 40 CanDo: YesWeAlsoCan,
p.Stats.Scavenging += 1
p.Stats.Militarism += 2
p.Stats.Education -= 1
p.Stats.FoodSupply += 1
p.Stats.ForeignRelations -= 2
p.Stats.Madness += 1
p.Stats.Cruelty += 1
return nil
},
CanDo: YesWeCan,
}, },
&VerbosePolicy{ &VerbosePolicy{
Default: &BasicPolicy{ Default: &TablePolicy{
UnenactedDesc: cardsim.MsgStr("This isn't about a disaster and can probably be safely dismissed."), UnenactedDesc: cardsim.MsgStr("This isn't about a disaster and can probably be safely dismissed."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation += 20 BasePopulation: 20,
return cardsim.MsgStr("Creche control doesn't shift that easily."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("Creche control doesn't shift that easily."),
p.Stats.BasePopulation -= 20 CanDo: YesWeAlsoCan,
return nil
},
CanDo: YesWeCan,
}, },
Variants: []Policy{ Variants: []Policy{
&BasicPolicy{ &BasicPolicy{
@ -118,93 +93,66 @@ var cards = []Card{
Desc: cardsim.MsgStr(" Good times are upon us! A great festival has been declared between many kobold tribes, celebrating the orderly nature of the kobold soul! That's right, it's the Pan-Tribal Festival of Bureaucracy!"), Desc: cardsim.MsgStr(" Good times are upon us! A great festival has been declared between many kobold tribes, celebrating the orderly nature of the kobold soul! That's right, it's the Pan-Tribal Festival of Bureaucracy!"),
After: ShuffleIntoBottomHalf, After: ShuffleIntoBottomHalf,
Policies: []Policy{ Policies: []Policy{
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`Your Minister of Administration is practically jumping for joy. "This is our opportunity to prove that we're a prosperous society and attract some fresh blood! We need to raise salaries in the bureaucracy, grant some time off to our bureaucrats to make sure they can attend, and try to hire talent away from other tribes. We'll forge productive trade relations by this, you'll see!`), UnenactedDesc: cardsim.MsgStr(`Your Minister of Administration is practically jumping for joy. "This is our opportunity to prove that we're a prosperous society and attract some fresh blood! We need to raise salaries in the bureaucracy, grant some time off to our bureaucrats to make sure they can attend, and try to hire talent away from other tribes. We'll forge productive trade relations by this, you'll see!`),
EnactedDesc: cardsim.MsgStr("[current policy] Your bureaucrats are really looking forward to attending, where they can boast about how the festival boosted their salaries."), EnactedDesc: cardsim.MsgStr("[current policy] Your bureaucrats are really looking forward to attending, where they can boast about how the festival boosted their salaries."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation += 60 BasePopulation: 60,
p.Stats.Scavenging += 1 Scavenging: 1,
p.Stats.Bureaucracy += 3 Bureaucracy: 3,
p.Stats.FoodSupply += 2 FoodSupply: 1,
p.Stats.Gullibility -= 1 Gullibility: -1,
return cardsim.MsgStr("Bureaucrats are considered pillars of society."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("Bureaucrats are considered pillars of society."),
p.Stats.BasePopulation -= 80 CanDo: YesWeAlsoCan,
p.Stats.Scavenging -= 1
p.Stats.Bureaucracy -= 3
p.Stats.FoodSupply -= 2
p.Stats.Gullibility += 1
return nil
},
CanDo: YesWeCan,
}, },
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`Your Minister of Finance pulls you aside. "This is a good opportunity to head-hunt. Bureaucrats from many tribes will be attending. There's got to be some who'll work for less than the ones we've got. There are some terribly threatened or impoverished communities among kobolds.`), UnenactedDesc: cardsim.MsgStr(`Your Minister of Finance pulls you aside. "This is a good opportunity to head-hunt. Bureaucrats from many tribes will be attending. There's got to be some who'll work for less than the ones we've got. There are some terribly threatened or impoverished communities among kobolds.`),
EnactedDesc: cardsim.MsgStr("[current policy] Your tribe's policy is clear: the festival of bureaucracy is a chance to trade workers with other kobold tribes in your attempts to build a more efficient government."), EnactedDesc: cardsim.MsgStr("[current policy] Your tribe's policy is clear: the festival of bureaucracy is a chance to trade workers with other kobold tribes in your attempts to build a more efficient government."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation += 20 BasePopulation: 20,
p.Stats.Bureaucracy -= 1 Bureaucracy: -1,
p.Stats.Gullibility -= 1
return cardsim.MsgStr("Immigrant bureaucrats complain about being under-appreciated."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("Immigrant bureaucrats complain about being under-appreciated."),
p.Stats.BasePopulation -= 20 CanDo: func(t *TablePolicy, p *Player) bool {
p.Stats.Bureaucracy += 1 return p.Stats.Bureaucracy >= 2 && t.LastEnactedIdx != 3
p.Stats.Gullibility += 1
return nil
},
CanDo: func(b *BasicPolicy, p *Player) bool {
return p.Stats.Bureaucracy >= 2 && b.LastEnactedIdx != 3
}, },
}, },
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`Your Minister of Finance greets you exuberantly. "We've trimmed the wages of the bureaucracy beautifully, but maybe we can scout some outright volunteers. Some tribes are absolute disasters, after all.`), UnenactedDesc: cardsim.MsgStr(`Your Minister of Finance greets you exuberantly. "We've trimmed the wages of the bureaucracy beautifully, but maybe we can scout some outright volunteers. Some tribes are absolute disasters, after all.`),
EnactedDesc: cardsim.MsgStr(`[current policy] It's hard to find volunteer workers at the festival, but your tribe is doing its best.`), EnactedDesc: cardsim.MsgStr(`[current policy] It's hard to find volunteer workers at the festival, but your tribe is doing its best.`),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation += 10 BasePopulation: 10,
p.Stats.Bureaucracy -= 2 Bureaucracy: -2,
p.Stats.Rebellion += 1 Rebellion: 1,
return cardsim.MsgStr("The local bureaucracy is staffed by volunteer labor."), nil Gullibility: 2,
Authoritarianism: -1,
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("The local bureaucracy is staffed by volunteer labor."),
p.Stats.BasePopulation -= 10 CanDo: func(t *TablePolicy, p *Player) bool {
p.Stats.Bureaucracy += 2 return p.Stats.Bureaucracy < 2 && t.LastEnactedIdx != 3
p.Stats.Rebellion -= 1
return nil
},
CanDo: func(b *BasicPolicy, p *Player) bool {
return p.Stats.Bureaucracy < 2 && b.LastEnactedIdx != 3
}, },
}, },
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`One of your non-bureaucrat friends has been in a foul temper. "This festival is everything that's wrong with our society. Life isn't about filling out forms. We ought to snub this festival and outright fire some bureaucrats."`), UnenactedDesc: cardsim.MsgStr(`One of your non-bureaucrat friends has been in a foul temper. "This festival is everything that's wrong with our society. Life isn't about filling out forms. We ought to snub this festival and outright fire a bunch of paper-pushers."`),
EnactedDesc: cardsim.MsgStr("Your tribe currently bans the Pan-Tribal Festival of Bureaucracy. There will be no local celebration without a policy change."), EnactedDesc: cardsim.MsgStr("Your tribe currently bans the Pan-Tribal Festival of Bureaucracy. There will be no local celebration without a policy change."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation -= 80 BasePopulation: 80,
p.Stats.Bureaucracy -= 4 Bureaucracy: 4,
return cardsim.MsgStr("A wave of bureaucrats just emigrated along with kobolds incensed by the tribe's lack of respect for administration."), nil Gullibility: 4,
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("A wave of bureaucrats just emigrated along with kobolds incensed by the tribe's lack of respect for administration."),
p.Stats.BasePopulation += 80 CanDo: YesWeAlsoCan,
p.Stats.Bureaucracy += 4
return nil
},
CanDo: YesWeCan,
}, },
&VerbosePolicy{ &VerbosePolicy{
Default: &BasicPolicy{ Default: &TablePolicy{
UnenactedDesc: cardsim.MsgStr("Some kobolds will attend the festival on their own, and we may face desertions for our lack of interest."), UnenactedDesc: cardsim.MsgStr("Some kobolds will attend the festival on their own, and we may face desertions for our lack of interest."),
EnactedDesc: cardsim.MsgStr("Some kobolds will attend the festival on their own. No change is expected."), EnactedDesc: cardsim.MsgStr("Some kobolds will attend the festival on their own. No change is expected."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation -= 20 BasePopulation: -20,
return cardsim.MsgStr("A festival of bureaucracy lured away a few kobolds to other tribes."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("A festival of bureaucracy lured away a few kobolds to other tribes."),
p.Stats.BasePopulation += 20 CanDo: YesWeAlsoCan,
return nil
},
CanDo: YesWeCan,
}, },
Variants: []Policy{ Variants: []Policy{
nil, nil,
@ -234,137 +182,81 @@ var cards = []Card{
Desc: cardsim.MsgStr("An inevitable concern of kobold tribes is the matter of trade. Trade with other kobolds is straightforward, but overland caravans are unsafe. Trade with surfacers is vital... but achieving it is difficult owing to anti-kobold sentiment."), Desc: cardsim.MsgStr("An inevitable concern of kobold tribes is the matter of trade. Trade with other kobolds is straightforward, but overland caravans are unsafe. Trade with surfacers is vital... but achieving it is difficult owing to anti-kobold sentiment."),
After: ShuffleIntoBottomHalf, After: ShuffleIntoBottomHalf,
Policies: []Policy{ Policies: []Policy{
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`Speaking for the conservative opinion, one prospective merchant says, "We need illusions. Our priority needs to be studying or trading to acquire or create spells or artifacts of disguising. The high start-up costs will be balanced by subsequent free movement in a surface society that detests us."`), UnenactedDesc: cardsim.MsgStr(`Speaking for the conservative opinion, one prospective merchant says, "We need illusions. Our priority needs to be studying or trading to acquire or create spells or artifacts of disguising. The high start-up costs will be balanced by subsequent free movement in a surface society that detests us."`),
EnactedDesc: cardsim.MsgStr("[current policy] Your merchants rely on magical disguises to avoid being identified as kobolds while doing business on the surface."), EnactedDesc: cardsim.MsgStr("[current policy] Your merchants rely on magical disguises to avoid being identified as kobolds while doing business on the surface."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.Manufacturing += 3 Manufacturing: 3,
p.Stats.Logistics += 4 Logistics: 4,
p.Stats.Mining += 1 Mining: 1,
p.Stats.Alchemy += 1 Alchemy: 1,
p.Stats.Gadgetry += 1 Gadgetry: 1,
p.Stats.Scavenging += 1 Scavenging: 1,
p.Stats.FoodSupply += 1 FoodSupply: 1,
p.Stats.Secrecy += 5 Secrecy: 5,
p.Stats.Rebellion += 1 Rebellion: 1,
p.Stats.Greed += 1 Greed: 1,
p.Stats.Gullibility += 1 Gullibility: 1,
return cardsim.MsgStr("Nobody ever meets a kobold merchant."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("Nobody ever meets a kobold merchant."),
p.Stats.Manufacturing -= 3 CanDo: YesWeAlsoCan,
p.Stats.Logistics -= 4
p.Stats.Mining -= 1
p.Stats.Alchemy -= 1
p.Stats.Gadgetry -= 1
p.Stats.Scavenging -= 1
p.Stats.FoodSupply -= 1
p.Stats.Secrecy -= 5
p.Stats.Rebellion -= 1
p.Stats.Greed -= 1
p.Stats.Gullibility -= 1
return nil
},
CanDo: YesWeCan,
}, },
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`Brave but potentially headstrong, another prospective merchant has attended the meeting with the following plea. "We must take head-on the risk of improving the status of kobolds! Only by bravely attending the surface markets can we hope to achieve a true and lasting peace!"`), UnenactedDesc: cardsim.MsgStr(`Brave but potentially headstrong, another prospective merchant has attended the meeting with the following plea. "We must take head-on the risk of improving the status of kobolds! Only by bravely attending the surface markets can we hope to achieve a true and lasting peace!"`),
EnactedDesc: cardsim.MsgStr(`[current policy] Your merchants represent the tribe's peaceful ideals by visiting the surface openly despite occasional casaulties.`), EnactedDesc: cardsim.MsgStr(`[current policy] Your merchants represent the tribe's peaceful ideals by visiting the surface openly despite occasional casaulties.`),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation -= 15 BasePopulation: -15,
p.Stats.Manufacturing += 3 Manufacturing: 3,
p.Stats.Logistics += 4 Logistics: 4,
p.Stats.Mining += 1 Mining: 2,
p.Stats.Alchemy += 2 Alchemy: 1,
p.Stats.Gadgetry += 2 Gadgetry: 2,
p.Stats.Hospitality += 1 Hospitality: 1,
p.Stats.Publishing += 1 Publishing: 1,
p.Stats.ForeignRelExpense += 1 ForeignRelExpense: 1,
p.Stats.Militarism -= 1 Militarism: -1,
p.Stats.Scavenging -= 1 Scavenging: -1,
p.Stats.Secrecy -= 10 Secrecy: -10,
p.Stats.ForeignRelations += 5 ForeignRelations: 5,
p.Stats.FoodSupply += 3 FoodSupply: 3,
p.Stats.Greed += 1 Greed: 1,
p.Stats.Madness -= 1 Madness: -1,
p.Stats.Cruelty -= 1 Cruelty: -1,
return cardsim.MsgStr("The tribe formally plans for attrition among its merchants."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("The tribe formally plans for attrition among its merchants."),
p.Stats.BasePopulation += 15 CanDo: YesWeAlsoCan,
p.Stats.Manufacturing -= 3
p.Stats.Logistics -= 4
p.Stats.Mining -= 1
p.Stats.Alchemy -= 2
p.Stats.Gadgetry -= 2
p.Stats.Hospitality -= 1
p.Stats.Publishing -= 1
p.Stats.ForeignRelExpense -= 1
p.Stats.Militarism += 1
p.Stats.Scavenging += 1
p.Stats.Secrecy += 10
p.Stats.ForeignRelations -= 5
p.Stats.FoodSupply -= 3
p.Stats.Greed -= 1
p.Stats.Madness -= 1
p.Stats.Cruelty -= 1
return nil
},
CanDo: YesWeCan,
}, },
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`A shady scavenger has offered to change careers and become a merchant. Their proposal is, "Surfacers aren't all monolithic. If we talk to the ones who are more greedy than prejudiced, we don't need magic or idealism. We can get in contact with lots of people who'll buy lots of things from us, even things that might not have a market if we worked with 'good' merchants."`), UnenactedDesc: cardsim.MsgStr(`A shady scavenger has offered to change careers and become a merchant. Their proposal is, "Surfacers aren't all monolithic. If we talk to the ones who are more greedy than prejudiced, we don't need magic or idealism. We can get in contact with lots of people who'll buy lots of things from us, even things that might not have a market if we worked with 'good' merchants."`),
EnactedDesc: cardsim.MsgStr("[current policy] Your merchants work with the underworld of the surface, forging connections with the people who are ironically less likely to murder them."), EnactedDesc: cardsim.MsgStr("[current policy] Your merchants work with the underworld of the surface, forging connections with the people who are ironically less likely to murder them."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.BasePopulation -= 5 BasePopulation: -5,
p.Stats.Logistics += 1 Logistics: 1,
p.Stats.Scavenging += 3 Scavenging: 3,
p.Stats.Alchemy += 2 Alchemy: 2,
p.Stats.Gadgetry += 2 Gadgetry: 2,
p.Stats.Mining -= 1 Mining: -1,
p.Stats.Manufacturing -= 1 Manufacturing: -1,
p.Stats.HiddenRelPenalty += 2 // High is bad on this hidden stat. HiddenRelPenalty: 2, //High is bad on this hidden stat.
p.Stats.Greed += 3 Greed: 3,
p.Stats.Gullibility -= 2 Gullibility: -2,
return cardsim.MsgStr("Kobold merchants are instantly suspected of black market connections."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("Kobold merchants are instantly suspected of black market connections."),
p.Stats.BasePopulation += 5 CanDo: YesWeAlsoCan,
p.Stats.Logistics -= 1
p.Stats.Scavenging -= 3
p.Stats.Alchemy -= 2
p.Stats.Gadgetry -= 3
p.Stats.Mining += 1
p.Stats.Manufacturing += 1
p.Stats.HiddenRelPenalty -= 2
p.Stats.Greed -= 3
p.Stats.Gullibility += 2
return nil
},
CanDo: YesWeCan,
}, },
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`A mining forebold registered for the right to attend this meeting, and says, "Surfacers can't be trusted and we shouldn't be supporting them with trade. We need underground roads to ease trade with other kobolds. It's a massive investment, but think of the reward: a world of underground civilizations supporting each other."`), UnenactedDesc: cardsim.MsgStr(`A mining forebold registered for the right to attend this meeting to say, "Surfacers can't be trusted and we shouldn't be supporting them with trade. We need underground roads to ease trade with other kobolds. It's a massive investment, but think of the reward: a world of underground civilizations supporting each other."`),
EnactedDesc: cardsim.MsgStr(`[currentpolicy] Your merchants have been directed to focus on trade with other kobolds, and your miners are perpetually tunnelling towards other kobold tribes in pursuit of the dream of a world of underground roads.`), EnactedDesc: cardsim.MsgStr(`[currentpolicy] Your merchants have been directed to focus on trade with other kobolds, and your miners are perpetually tunnelling towards other kobold tribes in pursuit of the dream of a world of underground roads.`),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.Mining += 5 Mining: 5,
p.Stats.Construction += 2 Construction: 2,
p.Stats.Logistics += 4 Logistics: 3,
p.Stats.FoodSupply -= 1 FoodSupply: -1,
p.Stats.Secrecy += 15 Secrecy: 15,
p.Stats.Gullibility -= 2 Gullibility: -2,
return cardsim.MsgStr("The vast network of caverns under the surface of the world is not a natural phenomenon."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("The vast network of caverns under the surface of the world is not a natural phenomenon."),
p.Stats.Mining -= 5 CanDo: YesWeAlsoCan,
p.Stats.Construction -= 2
p.Stats.Logistics -= 4
p.Stats.FoodSupply += 1
p.Stats.Secrecy -= 15
p.Stats.Gullibility += 2
return nil
},
CanDo: YesWeCan,
}, },
&VerbosePolicy{ &VerbosePolicy{
Default: &BasicPolicy{ Default: &BasicPolicy{
@ -383,7 +275,7 @@ var cards = []Card{
UnenactedDesc: cardsim.MsgStr("Rejecting the illusion-based merchantry will cost us a great deal in trade and surface food, but we can certainly do it."), UnenactedDesc: cardsim.MsgStr("Rejecting the illusion-based merchantry will cost us a great deal in trade and surface food, but we can certainly do it."),
}, },
&BasicPolicy{ &BasicPolicy{
UnenactedDesc: cardsim.MsgStr("Rejecting our idealistic approach to surface trade will save a few lives directly, but consider how much we need the food we might buy!"), UnenactedDesc: cardsim.MsgStr("Rejecting our idealistic approach to surface trade will save a few lives directly, but consider how much we need the food we buy!"),
}, },
&BasicPolicy{ &BasicPolicy{
UnenactedDesc: cardsim.MsgStr("The surfacers' governments would certainly prefer us to abandon our underworld connections in their cities. Do we care about that? We'd be giving up some excellent profits."), UnenactedDesc: cardsim.MsgStr("The surfacers' governments would certainly prefer us to abandon our underworld connections in their cities. Do we care about that? We'd be giving up some excellent profits."),
@ -400,32 +292,21 @@ var cards = []Card{
Desc: cardsim.MsgStr("Nobody would ever say a kobold smells bad, but the constant burrowing, manufacturing, and metallurgy that is common to kobold life is still a recipe for tense muscles and filthy scales. A slate of proposals have come through to address this issue."), Desc: cardsim.MsgStr("Nobody would ever say a kobold smells bad, but the constant burrowing, manufacturing, and metallurgy that is common to kobold life is still a recipe for tense muscles and filthy scales. A slate of proposals have come through to address this issue."),
After: ShuffleIntoBottomHalf, After: ShuffleIntoBottomHalf,
Policies: []Policy{ Policies: []Policy{
&BasicPolicy{ &TablePolicy{
UnenactedDesc: cardsim.MsgStr(`A calm and cheerful scribe says, "We should have public baths! We have more problems with flooding than drought in the deep underground, so we've got plenty of water. We just need to channel it. We could create a hub of social life while improving the health of everybody!"`), UnenactedDesc: cardsim.MsgStr(`A calm and cheerful scribe says, "We should have public baths! We have more problems with flooding than drought in the deep underground, so we've got plenty of water. We just need to channel it. We could create a hub of social life while improving the health of everybody!"`),
EnactedDesc: cardsim.MsgStr("[current policy] Public bathing is a staple social policy in the mines and warrens of your tribe."), EnactedDesc: cardsim.MsgStr("[current policy] Public bathing is a staple social policy in the mines and warrens of your tribe."),
Do: func(p *Player) (cardsim.Message, error) { EffectsTable: map[FieldLabel]float64{
p.Stats.Construction += 2 Construction: 2,
p.Stats.Welfare += 1 Welfare: 1,
p.Stats.Healthcare += 1 Healthcare: 1,
p.Stats.ParksExpense += 4 ParksExpense: 4,
p.Stats.Hospitality += 1 Hospitality: 1,
p.Stats.Madness -= 1 Madness: -1,
p.Stats.Cruelty -= 1 Cruelty: -1,
p.Stats.Greed -= 1 Greed: -1,
return cardsim.MsgStr("The company of others makes cold water tolerable."), nil
}, },
Undo: func(p *Player) error { EnactionDesc: cardsim.MsgStr("The company of others makes cold water tolerable."),
p.Stats.Construction -= 2 CanDo: YesWeAlsoCan,
p.Stats.Welfare -= 1
p.Stats.Healthcare -= 1
p.Stats.ParksExpense -= 4
p.Stats.Hospitality -= 1
p.Stats.Madness += 1
p.Stats.Cruelty += 1
p.Stats.Greed += 1
return nil
},
CanDo: YesWeCan,
}, },
&BasicPolicy{ &BasicPolicy{
UnenactedDesc: cardsim.MsgStr(`Your Minister of Finance is scandalized. "A free service? And such an expensive one to construct? No, no, no. The baths must pull their weight in the budget if they're ot be made at all. We must set an entry fee."`), UnenactedDesc: cardsim.MsgStr(`Your Minister of Finance is scandalized. "A free service? And such an expensive one to construct? No, no, no. The baths must pull their weight in the budget if they're ot be made at all. We must set an entry fee."`),

View File

@ -9,7 +9,6 @@ import (
var ( var (
ErrOptionNotEnabled = errors.New("option not enabled") ErrOptionNotEnabled = errors.New("option not enabled")
ErrPolicyNotEnacted = errors.New("cannot unenact policy that is not enacted") ErrPolicyNotEnacted = errors.New("cannot unenact policy that is not enacted")
ErrNoFieldLabel = errors.New("field does not exist")
// ErrUnimplemented and ErrKeepMessaage are "non-errors". They are used // ErrUnimplemented and ErrKeepMessaage are "non-errors". They are used
// as special signals that the result needs to be handled in a special way; // as special signals that the result needs to be handled in a special way;

View File

@ -1,7 +1,9 @@
package koboldsim package koboldsim
import ( import (
"errors"
"fmt" "fmt"
"reflect"
"git.chromaticdragon.app/kistaro/CardSimEngine/cardsim" "git.chromaticdragon.app/kistaro/CardSimEngine/cardsim"
) )
@ -167,49 +169,80 @@ func NewKoboldMine() *KoboldMine {
} }
} }
// 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 type FieldLabel string
const ( const (
BasePopulation FieldLabel = "BasePopulation" Alchemy FieldLabel = "Alchemy"
Scavenging FieldLabel = "Scavenging" Authoritarianism FieldLabel = "Authoritarianism"
Militarism FieldLabel = "Militarism" BasePopulation FieldLabel = "BasePopulation"
FoodSupply FieldLabel = "FoodSupply" Bureaucracy FieldLabel = "Bureaucracy"
ForeignRelations FieldLabel = "ForeignRelations" Construction FieldLabel = "Construction"
Rebellion FieldLabel = "Rebellion" Cruelty FieldLabel = "Cruelty"
Madness FieldLabel = "Madness" Education FieldLabel = "Education"
Cruelty FieldLabel = "Cruelty" FoodSupply FieldLabel = "FoodSupply"
Authoritarianism FieldLabel = "Authoritarianism" 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 { func (k *KoboldMine) Add(which FieldLabel, amount float64) error {
switch which { kv := reflect.ValueOf(k).Elem()
case BasePopulation: f := kv.FieldByName(string(which))
k.BasePopulation += amount if !f.IsValid() {
return nil return fmt.Errorf("cannot add %f to field %q: %w", amount, which, ErrNoFieldLabel)
case Scavenging:
k.Scavenging += amount
return nil
case Militarism:
k.Militarism += amount
return nil
case FoodSupply:
k.FoodSupply += amount
return nil
case ForeignRelations:
k.ForeignRelations += amount
return nil
case Rebellion:
k.Rebellion += amount
return nil
case Madness:
k.Madness += amount
return nil
case Cruelty:
k.Cruelty += amount
return nil
case Authoritarianism:
k.Authoritarianism += amount
return nil
} }
return fmt.Errorf("cannot add %f to %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
} }

View File

@ -1,6 +1,8 @@
package koboldsim package koboldsim
import ( import (
"errors"
"fmt"
"math" "math"
"golang.org/x/exp/constraints" "golang.org/x/exp/constraints"
@ -25,12 +27,45 @@ func Mean(vals ...float64) float64 {
return total / float64(len(vals)) return total / float64(len(vals))
} }
func clamp[T constraints.Ordered](val, low, high T) T { // clamp returns the middle of the three provided values. It doesn't
if val < low { // matter which order the values are in. This function is known as `mid` in
return low // Pico-8's library, among others. It is usually used to clamp a value to a
// range, and it doesn't care which order the range is written in.
func clamp[T constraints.Ordered](a, b, c T) T {
if a <= b && a <= c {
// `a` is least; mid is lower of `b` or `c`
if b <= c {
return b
}
return c
} }
if val > high { if a >= b && a >= c {
return high // `a` is most; mid is greater of `b` or `c`
if b >= c {
return b
}
return c
} }
return val // `a` is neither most nor least; therefore, `a` is mid
return a
}
var ErrWrappedPanic = errors.New("panic")
// try catches a panic in the provided func and demotes it to an error, if any
// panic occurs. The returned error, if any, wraps `ErrWrappedPanic`. If the
// panic argument is itself an error, it is also wrapped; otherwise, it is
// stringified into the error message using `%v`.
func try(f func()) (finalErr error) {
defer func() {
if r := recover(); r != nil {
if e, ok := r.(error); ok {
finalErr = fmt.Errorf("%w: %w", ErrWrappedPanic, e)
return
}
finalErr = fmt.Errorf("%w: %v", ErrWrappedPanic, r)
}
}()
f()
return nil
} }