1package gen 2 3import ( 4 "fmt" 5 "math/rand/v2" 6 7 "tinyadventure/internal/model" 8 "tinyadventure/internal/rng" 9 "tinyadventure/internal/world" 10) 11 12var spawnKinds = []struct{ kind, hint string }{ 13 {"shrine", "A roadside shrine, its offering bowl full of fresh ash. A pilgrim's note points toward %s."}, 14 {"burned inn", "The burned inn still smells of smoke. A survivor mutters that the trouble began near %s."}, 15 {"crossroads", "A weathered signpost has one arm scratched over in blood: %s."}, 16 {"watchpost", "An abandoned watchpost. The last log entry reads: all eyes on %s."}, 17 {"wagon", "A broken merchant wagon. A torn map is marked at %s."}, 18} 19 20func buildSpawns(r *rand.Rand, m *model.Map, main map[[2]int]bool) []model.SpawnPoint { 21 kinds := rng.Shuffled(r, spawnKinds) 22 west := func(open bool) func(c [2]int) bool { 23 return func(c [2]int) bool { 24 h := m.Hex(c[0], c[1]) 25 return main[c] && c[0] >= 3 && c[0] <= mapW/5 && c[1] >= 5 && c[1] < mapH-5 && (!open || h[0] == model.ShapePlain && h[3]&model.FlagForest == 0) 26 } 27 } 28 sites := hexes(m, west(true)) 29 if len(sites) < 2 { 30 sites = hexes(m, west(false)) 31 } 32 a := rng.Pick(r, sites) 33 b := a 34 for _, c := range rng.Shuffled(r, sites) { 35 if d := world.Distance(a[0], a[1], c[0], c[1]); d >= 6 && d <= 14 { 36 b = c 37 break 38 } 39 } 40 out := []model.SpawnPoint{ 41 {ID: "sp1", Kind: kinds[0].kind, X: a[0], Y: a[1], Hint: kinds[0].hint}, 42 {ID: "sp2", Kind: kinds[1].kind, X: b[0], Y: b[1], Hint: kinds[1].hint}, 43 } 44 for _, s := range out { 45 m.Hex(s.X, s.Y)[3] &^= model.FlagForest 46 } 47 return out 48} 49 50func hintSpawns(spawns []model.SpawnPoint, first model.POI) { 51 for i := range spawns { 52 spawns[i].Hint = fmt.Sprintf(spawns[i].Hint, first.Name) 53 } 54}