1package gen 2 3import ( 4 "math/rand/v2" 5 6 "tinyadventure/internal/rng" 7) 8 9var allPOIKinds = []string{"mine", "beach", "ruins", "crypt", "village", "tower", "camp"} 10 11type Systems struct { 12 Factions bool 13 SideQuest bool 14 Hazards bool 15 POIKinds []string 16} 17 18func rollSystems(r *rand.Rand) Systems { 19 kinds := rng.Shuffled(r, allPOIKinds)[:rng.Between(r, 4, len(allPOIKinds))] 20 return Systems{ 21 Factions: r.IntN(4) != 0, 22 SideQuest: r.IntN(4) != 0, 23 Hazards: r.IntN(2) == 0, 24 POIKinds: kinds, 25 } 26} 27 28func (s Systems) List() []string { 29 var out []string 30 for name, on := range map[string]bool{"factions": s.Factions, "sidequests": s.SideQuest, "hazards": s.Hazards} { 31 if on { 32 out = append(out, name) 33 } 34 } 35 sortStrings(out) 36 for _, k := range s.POIKinds { 37 out = append(out, "poi:"+k) 38 } 39 return out 40} 41 42func sortStrings(s []string) { 43 for i := 1; i < len(s); i++ { 44 for j := i; j > 0 && s[j] < s[j-1]; j-- { 45 s[j], s[j-1] = s[j-1], s[j] 46 } 47 } 48}