Compare commits
5 Commits
2c1fc73ef5
...
refactor-p
Author | SHA1 | Date | |
---|---|---|---|
1eedfb50e8
|
|||
c2d637b109
|
|||
7313ac0d73
|
|||
140d7b6cbb
|
|||
5af762474c
|
@ -23,6 +23,7 @@ var cards = []Card{
|
|||||||
p.Stats.GovWarExpense.Value -= 0.02
|
p.Stats.GovWarExpense.Value -= 0.02
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
CanDo: YesWeCan,
|
||||||
},
|
},
|
||||||
&BasicPolicy{
|
&BasicPolicy{
|
||||||
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."`),
|
||||||
@ -39,6 +40,7 @@ var cards = []Card{
|
|||||||
p.Stats.GovBureaucracyExpense.Value -= 0.01
|
p.Stats.GovBureaucracyExpense.Value -= 0.01
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
CanDo: YesWeCan,
|
||||||
},
|
},
|
||||||
&BasicPolicy{
|
&BasicPolicy{
|
||||||
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."`),
|
||||||
@ -55,9 +57,10 @@ var cards = []Card{
|
|||||||
p.Stats.GovWarExpense.Value += 0.02
|
p.Stats.GovWarExpense.Value += 0.02
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
CanDo: YesWeCan,
|
||||||
},
|
},
|
||||||
&VerbosePolicy{
|
&VerbosePolicy{
|
||||||
BasicPolicy: &BasicPolicy{
|
Default: &BasicPolicy{
|
||||||
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) {
|
Do: func(p *Player) (cardsim.Message, error) {
|
||||||
p.Stats.Kobolds.Value += 20
|
p.Stats.Kobolds.Value += 20
|
||||||
@ -67,23 +70,24 @@ var cards = []Card{
|
|||||||
p.Stats.Kobolds.Value -= 20
|
p.Stats.Kobolds.Value -= 20
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
CanDo: YesWeCan,
|
||||||
},
|
},
|
||||||
Content: []DescResult{
|
Variants: []Policy{
|
||||||
{
|
&BasicPolicy{
|
||||||
Desc: cardsim.MsgStr("Rejecting this issue will also reject the military's natalist stance."),
|
UnenactedDesc: cardsim.MsgStr("Rejecting this issue will also reject the military's natalist stance."),
|
||||||
Result: cardsim.MsgStr("Militant natalism has been reduced by policy."),
|
Do: OverrideMsg(cardsim.MsgStr("Militant natalism has been reduced by policy.")),
|
||||||
},
|
},
|
||||||
{
|
&BasicPolicy{
|
||||||
Desc: cardsim.MsgStr(`"Dig deeper" pressures in your nation may be excessive.`),
|
UnenactedDesc: cardsim.MsgStr(`"Dig deeper" pressures in your nation may be excessive.`),
|
||||||
Result: cardsim.MsgStr("Some of the lower depths are being abandoned."),
|
Do: OverrideMsg(cardsim.MsgStr("Some of the lower depths are being abandoned.")),
|
||||||
},
|
},
|
||||||
{
|
&BasicPolicy{
|
||||||
Desc: cardsim.MsgStr("Near-surface patrols may need to be increased."),
|
UnenactedDesc: cardsim.MsgStr("Near-surface patrols may need to be increased."),
|
||||||
Result: cardsim.MsgStr("More and better-armed hunting outposts are being established."),
|
Do: OverrideMsg(cardsim.MsgStr("More and better-armed hunting outposts are being established.")),
|
||||||
},
|
},
|
||||||
{
|
&BasicPolicy{
|
||||||
Desc: cardsim.MsgStr("This isn't about a disaster and can probably continue to be safely dismissed."),
|
EnactedDesc: cardsim.MsgStr("This isn't about a disaster and can probably continue to be safely dismissed."),
|
||||||
Result: cardsim.MsgStr("Creche control doesn't shift that easily."),
|
Do: OverrideMsg(cardsim.MsgStr("Creche control doesn't shift that easily.")),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -109,6 +113,7 @@ var cards = []Card{
|
|||||||
p.Stats.GovBureaucracyExpense.Value -= 0.03
|
p.Stats.GovBureaucracyExpense.Value -= 0.03
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
CanDo: YesWeCan,
|
||||||
},
|
},
|
||||||
&BasicPolicy{
|
&BasicPolicy{
|
||||||
UnenactedDesc: cardsim.MsgStr(`Your Minister of Education pulls you aside. "This is a good opportunity to head-hunt. Bureaucrats from many nations 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 Education pulls you aside. "This is a good opportunity to head-hunt. Bureaucrats from many nations 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.`),
|
||||||
@ -123,7 +128,8 @@ var cards = []Card{
|
|||||||
p.Stats.GovBureaucracyExpense.Value += 0.01
|
p.Stats.GovBureaucracyExpense.Value += 0.01
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
// This option should only be available if the fourth option isn't the status quo and bureaucratic expense is at least 0.02.
|
CanDo: YesWeCan,
|
||||||
|
// TODO(rakeela): This option should only be available if the fourth option isn't the status quo and bureaucratic expense is at least 0.02.
|
||||||
},
|
},
|
||||||
&BasicPolicy{
|
&BasicPolicy{
|
||||||
UnenactedDesc: cardsim.MsgStr(`Your Minister of Education greets you exuberantly. "We've trimmed the wages of the bureaucracy beautifully, but maybe we can scout some outright volunteers. Some nations are absolute disasters, after all.`),
|
UnenactedDesc: cardsim.MsgStr(`Your Minister of Education greets you exuberantly. "We've trimmed the wages of the bureaucracy beautifully, but maybe we can scout some outright volunteers. Some nations are absolute disasters, after all.`),
|
||||||
@ -138,7 +144,8 @@ var cards = []Card{
|
|||||||
p.Stats.GovBureaucracyExpense.Value += 0.02
|
p.Stats.GovBureaucracyExpense.Value += 0.02
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
// This option should only be available if the fourth option isn't the status quo and bureaucratic expense is less than 0.02.
|
CanDo: YesWeCan,
|
||||||
|
// TODO(rakeela): This option should only be available if the fourth option isn't the status quo and bureaucratic expense is less than 0.02.
|
||||||
},
|
},
|
||||||
&BasicPolicy{
|
&BasicPolicy{
|
||||||
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 some bureaucrats."`),
|
||||||
@ -153,10 +160,12 @@ var cards = []Card{
|
|||||||
p.Stats.GovBureaucracyExpense.Value += 0.04
|
p.Stats.GovBureaucracyExpense.Value += 0.04
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
CanDo: YesWeCan,
|
||||||
},
|
},
|
||||||
&VerbosePolicy{
|
&VerbosePolicy{
|
||||||
BasicPolicy: &BasicPolicy{
|
Default: &BasicPolicy{
|
||||||
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."),
|
||||||
Do: func(p *Player) (cardsim.Message, error) {
|
Do: func(p *Player) (cardsim.Message, error) {
|
||||||
p.Stats.Kobolds.Value -= 20
|
p.Stats.Kobolds.Value -= 20
|
||||||
return cardsim.MsgStr("A festival of bureaucracy lured away a few kobolds to other nations."), nil
|
return cardsim.MsgStr("A festival of bureaucracy lured away a few kobolds to other nations."), nil
|
||||||
@ -165,6 +174,27 @@ var cards = []Card{
|
|||||||
p.Stats.Kobolds.Value += 20
|
p.Stats.Kobolds.Value += 20
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
CanDo: YesWeCan,
|
||||||
|
},
|
||||||
|
Variants: []Policy{
|
||||||
|
nil,
|
||||||
|
&DisabledPolicy{cardsim.MsgStr("TODO(rakeela): write")},
|
||||||
|
&DisabledPolicy{cardsim.MsgStr("TODO(rakeela): write")},
|
||||||
|
&FuncPolicy{
|
||||||
|
OptionTextFunc: func(p *Player) (cardsim.Message, error) {
|
||||||
|
if p.Stats.GovBureaucracyExpense.Value >= -0.03 {
|
||||||
|
return cardsim.MsgStr("Permitting the festival will yield some immigration, but we'll be expected to rebuild our bureaucracy."), nil
|
||||||
|
}
|
||||||
|
return cardsim.MsgStr("Permitting the festival will yield some immigration."), nil
|
||||||
|
},
|
||||||
|
EnactFunc: func(p *Player) (cardsim.Message, error) {
|
||||||
|
if p.Stats.GovBureaucracyExpense.Value >= -0.03 {
|
||||||
|
return cardsim.MsgStr("A festival of bureaucracy just saw the nation's bureaucracy rebuilt."), ErrKeepMessage
|
||||||
|
}
|
||||||
|
return cardsim.MsgStr("A festival of bureaucracy brought in immigrants wondering at the nation's lack thereof."), ErrKeepMessage
|
||||||
|
},
|
||||||
|
},
|
||||||
|
nil, // remember, if using a BasicPolicy, this uses EnactedDesc
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@ var (
|
|||||||
// If these are returned in a context that does not know how to respond
|
// If these are returned in a context that does not know how to respond
|
||||||
// to them, then they're just errors.
|
// to them, then they're just errors.
|
||||||
ErrUnimplemented = errors.New("unimplemented policy element")
|
ErrUnimplemented = errors.New("unimplemented policy element")
|
||||||
ErrKeepMessaage = errors.New("use the default behavior but this message")
|
ErrKeepMessage = errors.New("use the default behavior but this message")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Policy interface {
|
type Policy interface {
|
||||||
@ -257,7 +257,7 @@ func (v *VerbosePolicy) fillDefaults() {
|
|||||||
for len(v.Variants) <= v.lastIdx {
|
for len(v.Variants) <= v.lastIdx {
|
||||||
v.Variants = append(v.Variants, v.Default)
|
v.Variants = append(v.Variants, v.Default)
|
||||||
}
|
}
|
||||||
if v.Variants[v.lastIdx] == nil {
|
if v.lastIdx > 0 && v.Variants[v.lastIdx] == nil {
|
||||||
v.Variants[v.lastIdx] = v.Default
|
v.Variants[v.lastIdx] = v.Default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,7 +270,9 @@ func (v *VerbosePolicy) OptionText(p *Player) (cardsim.Message, error) {
|
|||||||
} else {
|
} else {
|
||||||
msg, err = v.Variants[v.lastIdx].OptionText(p)
|
msg, err = v.Variants[v.lastIdx].OptionText(p)
|
||||||
}
|
}
|
||||||
if errors.Is(err, ErrUnimplemented) {
|
if errors.Is(err, ErrKeepMessage) {
|
||||||
|
_, err = v.Default.OptionText(p)
|
||||||
|
} else if errors.Is(err, ErrUnimplemented) {
|
||||||
msg, err = v.Default.OptionText(p)
|
msg, err = v.Default.OptionText(p)
|
||||||
}
|
}
|
||||||
return msg, err
|
return msg, err
|
||||||
@ -284,7 +286,9 @@ func (v *VerbosePolicy) Enact(p *Player) (cardsim.Message, error) {
|
|||||||
} else {
|
} else {
|
||||||
msg, err = v.Variants[v.lastIdx].Enact(p)
|
msg, err = v.Variants[v.lastIdx].Enact(p)
|
||||||
}
|
}
|
||||||
if errors.Is(err, ErrUnimplemented) {
|
if errors.Is(err, ErrKeepMessage) {
|
||||||
|
_, err = v.Default.Enact(p)
|
||||||
|
} else if errors.Is(err, ErrUnimplemented) {
|
||||||
msg, err = v.Default.Enact(p)
|
msg, err = v.Default.Enact(p)
|
||||||
}
|
}
|
||||||
return msg, err
|
return msg, err
|
||||||
@ -394,8 +398,47 @@ func (f *FuncPolicy) Is(p Policy) bool {
|
|||||||
return ok && (f == fp)
|
return ok && (f == fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A DisabledPolicy is never enabled.
|
||||||
|
type DisabledPolicy struct {
|
||||||
|
Msg cardsim.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DisabledPolicy) OptionText(p *Player) (cardsim.Message, error) {
|
||||||
|
return d.Msg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DisabledPolicy) Enact(*Player) (cardsim.Message, error) {
|
||||||
|
return nil, ErrOptionNotEnabled
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DisabledPolicy) Enabled(*Player) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DisabledPolicy) Unenact(*Player) error {
|
||||||
|
return ErrPolicyNotEnacted
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DisabledPolicy) LastEnacted(int, Policy) {}
|
||||||
|
|
||||||
|
func (d *DisabledPolicy) Is(p Policy) bool {
|
||||||
|
dp, ok := p.(*DisabledPolicy)
|
||||||
|
return ok && (dp == d)
|
||||||
|
}
|
||||||
|
|
||||||
// ShuffleIntoBottomHalf is a common "what to do with the card after?" behavior.
|
// ShuffleIntoBottomHalf is a common "what to do with the card after?" behavior.
|
||||||
func ShuffleIntoBottomHalf(c Card, p *Player, _ CardOption) error {
|
func ShuffleIntoBottomHalf(c Card, p *Player, _ CardOption) error {
|
||||||
p.Deck.InsertRandomBottom(0.5, c)
|
p.Deck.InsertRandomBottom(0.5, c)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OverrideDefaultMsg returns a closure that returns the provided message and
|
||||||
|
// ErrKeepMessage. This can be used in a FuncPolicy to tell a VerbosePolicy
|
||||||
|
// to use its Default but keep the message written here, to avoid writing
|
||||||
|
// repetitive Enact funcs (and, for that matter, OptionText funcs, even though
|
||||||
|
// the underlying Default call should be unnecessary).
|
||||||
|
func OverrideMsg(m cardsim.Message) func(*Player) (cardsim.Message, error) {
|
||||||
|
return func(p *Player) (cardsim.Message, error) {
|
||||||
|
return m, ErrKeepMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user