xonecas.ioDon't click! Sean Caetano Martin Sign in

tiny-adventure / commits / 69776d0

Add roaming bands, guarded chests, hazards, landmarks and gear traits

Bands roam and intercept the party, chests can be guarded, trapped or mimics, harsh terrain wears heroes down, and lookouts, shrines and caches reward exploring. Items and enemies carry traits, weaknesses and resistances, the threat card shows them, and Prepare opens the inventory with live odds in place of Equip best. Verified with scripts/verify.sh (0 failures at 6 resolutions) and a seed 7 playthrough (victory in 9 battles, no console errors).

Co-Authored-By: Claude Opus 5.5

sacenox2 days ago69776d036c1878865ba1bef875f6720ae6cf79d4parent 4d3527674 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

README.md+4-3
@@ -36,11 +36,12 @@ Beating the boss ends the campaign with a stats screen.
3636
3737 ## Playing
3838
39-- Click a tile to walk there. Right-drag or Q/E rotates, the wheel zooms.
39+- Click a hex to walk there. Roads are fast, hills, shallows and forest are slow. Right-drag or Q/E rotates, the wheel zooms.
4040 - The next main objective is always marked with a light beam and labelled with its level (`Lv N`), even in the fog. J opens the journal, which marks the next step.
4141 - Walking toward a place that is still held stops you next to it and shows its defenders, your chance to win, and how much health the fight should cost. Fight (Enter) or back off (Esc).
42-- Wounds carry from fight to fight. Camps are the two spawns plus every cleared camp or village. At a camp (C), rest to heal the party, buy potions and gear, and sell loot. P drinks a potion on the selected hero.
43-- Walking over loot picks it up. In the inventory (I), `Equip best` gears every hero with the best items in the pack.
42+- Wounds carry from fight to fight. Shallows, mountains and harsh biomes wear the party down as it walks. Rest (C) at a spawn or any place you cleared. Spawns, camps and villages also trade potions and gear. P drinks a potion on the selected hero.
43+- Roaming bands chase a party that comes near. Some chests are guarded, trapped, or mimics. Lookouts reveal the land, shrines heal, and old caches grant XP.
44+- Walking over loot picks it up. Items may carry a trait, such as fire, lifesteal or taunt, paid for with a lower stat. Enemies show their traits, weaknesses and resistances on the threat card. Prepare (G) opens the inventory with live odds, so you can gear for the fight in front of you.
4445 - A lost fight carries the party back to the nearest camp, patched up, and costs a quarter of its gold. Heroes still earn half XP, more when they fought above their level.
4546 - M toggles sound.
4647
docs/api.md+49-10
@@ -31,16 +31,18 @@ Every endpoint except `/api/seed` and `/api/combat/log` returns a full `GameStat
3131 "map": {
3232 "width": 1,
3333 "height": 1,
34- "tiles": [[{"terrain": "grass", "walkable": true}]],
34+ "hexes": "AgQFAQ==",
3535 "pois": [{"id": "poi1", "kind": "mine", "name": "Dark Mine", "x": 0, "y": 0, "faction": "f1", "level": 1, "cleared": false}],
3636 "spawns": [{"id": "sp1", "kind": "inn", "x": 0, "y": 0, "hint": "Ask the innkeeper"}],
37- "loot": [{"id": "l1", "x": 0, "y": 0, "item": {"id": "i1", "name": "Rusty Sword", "slot": "weapon", "rarity": "common", "bonus": {"hp": 0, "maxHp": 0, "attack": 2, "defense": 0, "magic": 0, "speed": 0, "crit": 0}}, "collected": false}]
37+ "loot": [{"id": "chest1", "x": 0, "y": 0, "item": {"id": "i1", "name": "Rusty Sword", "slot": "weapon", "rarity": "common", "bonus": {"hp": 0, "maxHp": 0, "attack": 2, "defense": 0, "magic": 0, "speed": 0, "crit": 0}, "trait": "fire"}, "collected": false, "trap": true}],
38+ "bands": [{"id": "band1", "kind": "roam", "name": "Raiders", "faction": "f1", "level": 2, "x": 0, "y": 0, "homeX": 0, "homeY": 0, "cleared": false}],
39+ "landmarks": [{"id": "lm1", "kind": "lookout", "x": 0, "y": 0, "used": false}]
3840 },
3941 "party": {
4042 "playerId": "local",
4143 "units": [
4244 {
43- "id": "u1", "name": "Ayla", "class": "fighter", "level": 1, "xp": 0,
45+ "id": "u1", "name": "Ayla", "class": "fighter", "race": "dwarf", "level": 1, "xp": 0,
4446 "stats": {"hp": 10, "maxHp": 10, "attack": 3, "defense": 1, "magic": 0, "speed": 4, "crit": 5},
4547 "abilities": [{"id": "a1", "name": "Slash", "kind": "damage", "power": 1.2, "cooldown": 2, "target": "enemy"}],
4648 "gear": {}
@@ -67,6 +69,39 @@ Each POI has a `level`, the enemy level of its fight. The boss is one level high
6769
6870 Item slots: `weapon`, `armor`, `helm`, `trinket`. `gear` maps slot to `Item`.
6971
72+## Map
73+
74+The map is a board of pointy-top hexes in offset coordinates: odd rows sit half a hex to the right. `hexes` is base64, four bytes per hex in row-major order: shape, biome, height, flags.
75+
76+- Shapes: 0 deep water, 1 shallow, 2 plain, 3 hill, 4 mountain, 5 peak. Deep water and peaks are not walkable.
77+- Biomes: 0 to 8, named in `model.Biomes`.
78+- Flags: bit 1 forest, bit 2 road.
79+
80+Walking costs 1 on a road, 2 on a plain, 3 on shallows and hills, and 4 on mountains, plus 1 in forest. The server walks the cheapest path.
81+
82+`bands` are enemies on the board:
83+
84+- `roam` bands wander near home and chase a party within 5 hexes.
85+- `guard` bands sit on a chest.
86+- `mimic` bands are chests that bite.
87+
88+A cleared band stays `cleared`. A band that wins goes back home.
89+
90+`landmarks` fire once, when the party steps on them:
91+
92+- `lookout` reveals the land around it.
93+- `shrine` heals the party.
94+- `cache` grants XP.
95+
96+`loot[].trap` chests wound the party on pickup unless a rogue or ranger disarms them.
97+
98+Units carry `race`. Enemies also carry `traits`, `weak` and `resist`. Items may carry one `trait`, paid for with a lower stat. Traits:
99+
100+- `lifesteal`, `first`, `cleave`, `pierce`, `thorns`, `taunt`, `ward`, `armored`, `swarm`, `shadow`.
101+- The elements `fire`, `frost` and `holy`.
102+
103+`trail` lists the hexes the party walked in the latest move. `notes` lists what the walk caused, such as hazard damage, a trap, a shrine or a lookout. Shallows, mountains and three harsh biomes cost 2% of each hero's health per hex walked, never below 1 hp. A hero with `ward` is immune.
104+
70105 ## GET /api/state
71106
72107 Returns the current `GameState`.
@@ -89,13 +124,17 @@ Response: `GameState` with a fresh campaign.
89124
90125 ## POST /api/move
91126
92-Moves the party toward tile `x,y`. The server paths over walkable tiles and returns the new state. The route avoids other uncleared POI tiles unless they block the only way. The party never walks onto an uncleared POI: it stops on the tile before it, and `threat` describes the fight:
127+Moves the party toward hex `x,y`. The server paths over walkable hexes and returns the new state. The route avoids uncleared POIs and bands unless they block the only way. The party never walks onto an uncleared POI or band. It stops on the hex before it, and `threat` describes the fight. Every second step, roaming bands move. A band that ends next to the party stops the walk with a `threat`:
93128
94129 ```json
95130 {"poi": "poi1", "enemies": [], "odds": 82, "wounds": 35, "barred": false}
96131 ```
97132
98-`odds` is the percent of 40 simulated fights the party wins as it stands now. `wounds` is the average percent of the party's current health lost in those fights. `barred` is true for the boss until every other main step is done. Start the fight with `POST /api/interact` on the POI id. Any other action clears `threat`. Loot on any tile the party walks over is picked up automatically and listed in `found`; key items on a POI tile are picked up when the POI is cleared. Rejected with 400 for an unre …
133+```json
134+{"band": "band1", "enemies": [], "odds": 64, "wounds": 50}
135+```
136+
137+`odds` is the percent of 40 simulated fights the party wins as it stands now. `wounds` is the average percent of the party's current health lost in those fights. `barred` is true for the boss until every other main step is done. Start the fight with `POST /api/interact` on the POI or band id. Any other action clears `threat`. Loot on any tile the party walks over is picked up automatically and listed in `found`; key items on a POI tile are picked up when the POI is cleared. Rejected with 400 for …
99138
100139 ```json
101140 {"x": 12, "y": 7}
@@ -105,10 +144,10 @@ Response: `GameState` with updated `party.x`, `party.y`, and possibly `threat`.
105144
106145 ## POST /api/interact
107146
108-Interacts with a POI, loot node, or spawn structure by id (`poi1`, `l1`, `sp1`). Collects loot, advances mission steps, or starts the POI encounter. Moving already collects loot on the path, so this is only needed for loot the party stands on and has not collected, and it fails with 400 for loot already collected.
147+Interacts with a POI, band, loot node, or spawn structure by id (`poi1`, `band1`, `chest1`, `sp1`). Collects loot, advances mission steps, or starts the POI or band encounter. Moving already collects loot on the path, so this is only needed for loot the party stands on and has not collected, and it fails with 400 for loot already collected.
109148
110149 ```json
111-{"id": "l1"}
150+{"id": "chest1"}
112151 ```
113152
114153 Response: `GameState`. Collected loot appears in `party.inventory` and `map.loot[].collected` becomes `true`.
@@ -139,13 +178,13 @@ Response: `GameState` with updated `party.units[].abilities`.
139178
140179 ## Camps
141180
142-Camps are the spawns and every cleared POI of kind `camp` or `village`. While the party stands on one, `camp` is set:
181+Camps are the spawns and every cleared POI. While the party stands on one, `camp` is set. Spawns and cleared POIs of kind `camp` or `village` also trade:
143182
144183 ```json
145-{"id": "sp1", "name": "shrine", "stock": [], "potionPrice": 15}
184+{"id": "sp1", "name": "shrine", "trade": true, "stock": [], "potionPrice": 15}
146185 ```
147186
148-`stock` holds three items rolled from the seed for that camp, one tier above its level. The rest of this section's endpoints fail with 400 away from a camp.
187+`stock` holds three items rolled from the seed for that camp, one tier above its level. The rest of this section's endpoints fail with 400 away from a camp. Buy and sell also fail where `trade` is false.
149188
150189 ### POST /api/rest
151190
docs/verification.md+4-3
@@ -12,7 +12,7 @@ Needs `go`, `node`, `ffmpeg` (for the recording), `python3`, and `agent-browser`
1212
1313 1. Builds and starts the server on a free port with `--seed`.
1414 2. Opens a headed Chrome on `DISPLAY` (default `:0`) with software WebGL flags, so a window appears on the desktop. Do not touch the desktop while it runs.
15-3. For each of 1280x720, 1920x1080, 2560x1440, 1366x768, 800x600 and 390x844, resets the campaign to the seed and plays through input only: clicks Begin, clicks a ground tile, presses I, J and Escape, then for each main-quest POI in order clicks it, waits for the threat card and clicks Fight. When a hero is below half health it first walks to the nearest camp, which opens the camp panel, and clicks Rest and Potion. The end screen is reached by fast-forwarding through the API.
15+3. For each of 1280x720, 1920x1080, 2560x1440, 1366x768, 800x600 and 390x844, resets the campaign to the seed and plays through input only: clicks Begin, clicks a ground tile, presses I, J and Escape, then for each main-quest POI in order clicks it, waits for the threat card and clicks Fight. On the first card it clicks Prepare, checks the inventory opens with odds, and clicks back. A band that intercepts the walk is fought instead. When a hero is below half health it first walks to the nearest …
1616 4. Exits non-zero if any assertion failed.
1717
1818 `VERIFY_ONLY=1280x720,390x844` limits the resolutions. `VERIFY_ATTEMPTS=n` caps POI clicks (default 14).
@@ -23,7 +23,7 @@ Needs `go`, `node`, `ffmpeg` (for the recording), `python3`, and `agent-browser`
2323 scripts/playthrough.sh <outdir> <seed> [width height name]
2424 ```
2525
26-Plays one full campaign on `<seed>` through input only: clicks Begin, opens the journal, then clicks the next main POI and Fight on its threat card until the end screen shows, opening the inventory and pressing `Equip best` before each leg. When a hero is below half health it rests at the nearest camp first. After two defeats at one POI it walks to a lower level POI first. It records `<name>.webm`, saves screenshots and `<name>.md`/`<name>.json`, and exits non-zero on any failed step, layout pro …
26+Plays one full campaign on `<seed>` through input only: clicks Begin, opens the journal, then clicks the next main POI and Fight on its threat card until the end screen shows. Before each fight it clicks Prepare and clicks pack items that beat the equipped ones. Bands that intercept the walk are fought. When a hero is below half health it rests at the nearest camp first. After two defeats at one POI it walks to a lower level POI first. It records `<name>.webm`, saves screenshots and `<name>.md`/ …
2727
2828 ## Output
2929
@@ -48,13 +48,14 @@ Defined in `web/js/debug.js`, installed after boot.
4848
4949 | Member | Meaning |
5050 | --- | --- |
51-| `mode` | `loading`, `title`, `explore`, `threat`, `combat`, `end` |
51+| `mode` | `loading`, `title`, `explore`, `threat`, `prepare`, `combat`, `end` |
5252 | `busy` | true while a move, walk or fight animation runs |
5353 | `state()` | phase, seed, party x/y/gold/potions/inventory/unit levels and hp, threat, camp, summary, winner |
5454 | `rects()` | `[{name, x, y, w, h, essential}]` in CSS pixels |
5555 | `setRects(fn)` | replace the rect provider (use when the UI is drawn in Three.js) |
5656 | `tileScreen(x, y)` | screen position of a tile, for real clicks |
5757 | `focusTile(x, y)` | move the camera to a tile; `focusTile(null)` releases it |
58+| `pickAt(x, y)` | the hex under a screen point, so clicks can avoid hexes hidden behind hills |
5859
5960 ## Rules
6061
internal/gen/bands.go+19-0
@@ -0,0 +1,19 @@
1+package gen
2+
3+import (
4+ "tinyadventure/internal/model"
5+)
6+
7+var bandNames = []string{"Patrol", "Warband", "Raiders", "Hunters"}
8+
9+func placeBands(p *placer, maxDist int, byPower []model.Faction) []model.Band {
10+ var out []model.Band
11+ for _, c := range p.take(between(p.r, 7, 10), 6, func([2]int) bool { return true }) {
12+ f := factionAt(byPower, p.progress(c, maxDist), p.r.Float64())
13+ out = append(out, model.Band{
14+ Kind: "roam", Name: pick(p.r, bandNames), Faction: f.ID,
15+ Level: levelAt(p.origin, maxDist, c[0], c[1]), X: c[0], Y: c[1], HomeX: c[0], HomeY: c[1],
16+ })
17+ }
18+ return out
19+}
internal/gen/encounters.go+39-6
@@ -3,6 +3,7 @@ package gen
33 import (
44 "fmt"
55 "math/rand"
6+ "slices"
67
78 "tinyadventure/internal/model"
89 )
@@ -15,10 +16,12 @@ func bossName(r *rand.Rand, f model.Faction) string {
1516 return fmt.Sprintf("%s %s %s", pick(r, d.titles), pick(r, bossNames), pick(r, bossEpithets))
1617 }
1718
18-func enemy(r *rand.Rand, id, name string, f model.Faction, level int, hpMult, atkMult float64) model.Unit {
19+func enemy(r *rand.Rand, id string, l look, f model.Faction, level int, hpMult, atkMult float64) model.Unit {
1920 hp := int(float64(hpBase+level*hpGrow+r.Intn(5)) * hpMult)
21+ n := natures[defOf(f).name]
2022 return model.Unit{
21- ID: id, Name: name, Class: "monster", Faction: f.ID, Level: level,
23+ Traits: slices.DeleteFunc(slices.Clone(n.traits), func(t string) bool { return t == "swarm" }), Weak: n.weak, Resist: n.resist,
24+ ID: id, Name: l.name, Race: l.race, Class: l.class, Faction: f.ID, Level: level,
2225 Stats: model.Stats{
2326 HP: hp, MaxHP: hp, Attack: int(float64(atkBase+level*atkGrow/2) * atkMult), Defense: 1 + level/2,
2427 Magic: level, Speed: between(r, 3, 7), Crit: 5,
@@ -28,8 +31,9 @@ func enemy(r *rand.Rand, id, name string, f model.Faction, level int, hpMult, at
2831 }
2932
3033 const (
31- hpBase, hpGrow, atkBase, atkGrow = 18, 8, 7, 4
32- bossHP, bossAtk = 2.0, 1.2
34+ hpBase, hpGrow, atkBase, atkGrow = 22, 9, 9, 4
35+ bossHP, bossAtk = 1.7, 1.1
36+ swarmHP, swarmAtk = 0.65, 0.8
3337 )
3438
3539 func buildEncounter(r *rand.Rand, poi model.POI, f model.Faction, level int, boss string) model.Encounter {
@@ -37,11 +41,40 @@ func buildEncounter(r *rand.Rand, poi model.POI, f model.Faction, level int, bos
3741 e := model.Encounter{ID: "enc-" + poi.ID, POI: poi.ID}
3842 if boss != "" {
3943 e.Boss = true
40- e.Enemies = append(e.Enemies, enemy(r, e.ID+"-boss", boss, f, level+1, bossHP, bossAtk))
44+ e.Enemies = append(e.Enemies, enemy(r, e.ID+"-boss", look{boss, d.boss.race, d.boss.class}, f, level+1, bossHP, bossAtk))
4145 }
4246 count := between(r, 2, 2+min(2, level/3))
47+ if boss != "" {
48+ count = 2
49+ }
50+ hpMult, atkMult := 1.0, 1.0
51+ if slices.Contains(natures[d.name].traits, "swarm") {
52+ count++
53+ hpMult, atkMult = swarmHP, swarmAtk
54+ }
4355 for i := 0; i < count; i++ {
44- e.Enemies = append(e.Enemies, enemy(r, fmt.Sprintf("%s-e%d", e.ID, i+1), pick(r, d.minions), f, level, 1, 1))
56+ e.Enemies = append(e.Enemies, enemy(r, fmt.Sprintf("%s-e%d", e.ID, i+1), pick(r, d.minions), f, level, hpMult, atkMult))
57+ }
58+ return e
59+}
60+
61+const mimicHP, mimicAtk = 1.8, 1.3
62+
63+func buildBandEncounter(r *rand.Rand, b model.Band, f model.Faction) model.Encounter {
64+ e := model.Encounter{ID: "enc-" + b.ID, POI: b.ID}
65+ if b.Kind == "mimic" {
66+ m := enemy(r, e.ID+"-m", look{"Mimic", "beast", "mimic"}, f, b.Level, mimicHP, mimicAtk)
67+ m.Traits = []string{"first"}
68+ e.Enemies = []model.Unit{m}
69+ return e
70+ }
71+ d := defOf(f)
72+ count, hpMult, atkMult := 2, 1.0, 1.0
73+ if slices.Contains(natures[d.name].traits, "swarm") {
74+ count, hpMult, atkMult = 3, swarmHP, swarmAtk
75+ }
76+ for i := range count {
77+ e.Enemies = append(e.Enemies, enemy(r, fmt.Sprintf("%s-e%d", e.ID, i+1), pick(r, d.minions), f, b.Level, hpMult, atkMult))
4578 }
4679 return e
4780 }
internal/gen/factions.go+27-10
@@ -7,25 +7,42 @@ import (
77 "tinyadventure/internal/model"
88 )
99
10+type look struct{ name, race, class string }
11+
1012 type factionDef struct {
1113 name string
1214 theme string
13- minions []string
15+ minions []look
16+ boss look
1417 titles []string
1518 }
1619
20+type nature struct{ traits, weak, resist []string }
21+
22+var natures = map[string]nature{
23+ "Vampires": {[]string{"lifesteal", "shadow"}, []string{"holy", "fire"}, []string{"frost", "shadow"}},
24+ "Lizardfolk": {[]string{"thorns"}, []string{"frost"}, []string{"fire"}},
25+ "Bandits": {[]string{"first"}, nil, nil},
26+ "Undead": {[]string{"armored", "frost"}, []string{"holy", "fire"}, []string{"frost", "shadow"}},
27+ "Cultists": {[]string{"fire"}, []string{"frost"}, []string{"fire", "shadow"}},
28+ "Goblins": {[]string{"swarm", "first"}, []string{"fire"}, nil},
29+ "Beastkin": {[]string{"swarm", "thorns"}, []string{"fire"}, []string{"frost"}},
30+ "Witches": {[]string{"shadow", "ward"}, []string{"holy"}, []string{"shadow", "frost"}},
31+ "Wildlings": {[]string{"swarm"}, []string{"fire"}, nil},
32+}
33+
1734 var factionPool = []factionDef{
18- {"Vampires", "blood", []string{"Thrall", "Bloodbat", "Vampire Spawn"}, []string{"Count", "Countess", "Lord"}},
19- {"Lizardfolk", "reptile", []string{"Scaleguard", "Lizard Skirmisher", "Marsh Spitter"}, []string{"Warlord", "High Shaman", "Scale-King"}},
20- {"Bandits", "outlaw", []string{"Cutpurse", "Brigand", "Bandit Archer"}, []string{"Captain", "Highwayman", "Boss"}},
21- {"Undead", "grave", []string{"Skeleton", "Zombie", "Wight"}, []string{"Lich", "Death Knight", "Revenant"}},
22- {"Cultists", "occult", []string{"Acolyte", "Zealot", "Hollow Priest"}, []string{"Prophet", "Archon", "Hierophant"}},
23- {"Goblins", "greenskin", []string{"Goblin", "Hobgoblin", "Goblin Sneak"}, []string{"Chieftain", "Warboss", "King"}},
24- {"Beastkin", "wild", []string{"Dire Wolf", "Gnoll", "Boar Raider"}, []string{"Packlord", "Alpha", "Horned King"}},
25- {"Witches", "hex", []string{"Hedge Witch", "Crow Familiar", "Bog Hag"}, []string{"Coven Mother", "Grand Hag", "Queen"}},
35+ {"Vampires", "blood", []look{{"Thrall", "human", "thrall"}, {"Bloodbat", "beast", "bat"}, {"Vampire Spawn", "vampire", "rogue"}}, look{"", "vampire", "lord"}, []string{"Count", "Countess", "Lord"}},
36+ {"Lizardfolk", "reptile", []look{{"Scaleguard", "lizard", "fighter"}, {"Lizard Skirmisher", "lizard", "rogue"}, {"Marsh Spitter", "lizard", "shaman"}}, look{"", "lizard", "chief"}, []string{"Warlord", "High Shaman", "Scale-King"}},
37+ {"Bandits", "outlaw", []look{{"Cutpurse", "bandit", "rogue"}, {"Brigand", "bandit", "fighter"}, {"Bandit Archer", "bandit", "archer"}}, look{"", "bandit", "captain"}, []string{"Captain", "Highwayman", "Boss"}},
38+ {"Undead", "grave", []look{{"Skeleton", "skeleton", "fighter"}, {"Zombie", "zombie", "brute"}, {"Wight", "skeleton", "knight"}}, look{"", "skeleton", "lich"}, []string{"Lich", "Death Knight", "Revenant"}},
39+ {"Cultists", "occult", []look{{"Acolyte", "human", "cultist"}, {"Zealot", "human", "zealot"}, {"Hollow Priest", "hollow", "priest"}}, look{"", "hollow", "prophet"}, []string{"Prophet", "Archon", "Hierophant"}},
40+ {"Goblins", "greenskin", []look{{"Goblin", "goblin", "rogue"}, {"Hobgoblin", "orc", "fighter"}, {"Goblin Sneak", "goblin", "sneak"}}, look{"", "orc", "warboss"}, []string{"Chieftain", "Warboss", "King"}},
41+ {"Beastkin", "wild", []look{{"Dire Wolf", "beast", "wolf"}, {"Gnoll", "gnoll", "fighter"}, {"Boar Raider", "beast", "boar"}}, look{"", "beast", "owlbear"}, []string{"Packlord", "Alpha", "Horned King"}},
42+ {"Witches", "hex", []look{{"Hedge Witch", "human", "witch"}, {"Crow Familiar", "beast", "crow"}, {"Bog Hag", "hag", "witch"}}, look{"", "hag", "coven"}, []string{"Coven Mother", "Grand Hag", "Queen"}},
2643 }
2744
28-var wildFaction = factionDef{"Wildlings", "wild", []string{"Wolf", "Giant Spider", "Wild Boar"}, []string{"Alpha", "Elder", "Terror"}}
45+var wildFaction = factionDef{"Wildlings", "wild", []look{{"Wolf", "beast", "wolf"}, {"Giant Spider", "beast", "spider"}, {"Wild Boar", "beast", "boar"}}, look{"", "beast", "troll"}, []string{"Alpha", "Elder", "Terror"}}
2946
3047 func rollFactions(r *rand.Rand, on bool) []model.Faction {
3148 if !on {
internal/gen/gen.go+39-5
@@ -1,7 +1,11 @@
11 package gen
22
33 import (
4+ "fmt"
5+ "slices"
6+
47 "tinyadventure/internal/model"
8+ "tinyadventure/internal/world"
59 )
610
711 type World struct {
@@ -25,10 +29,15 @@ func Generate(seed model.Seed) World {
2529 if sys.SideQuest {
2630 nSide = between(lr, 2, 4)
2731 }
28- spawns := buildSpawns(lr)
29- pois := layoutPOIs(lr, sys, factions, spawns, nMain, nSide)
32+ byPower := append([]model.Faction(nil), factions...)
33+ slices.SortStableFunc(byPower, func(a, b model.Faction) int { return a.Power - b.Power })
34+ toward := themeClimate[byPower[len(byPower)-1].Theme]
35+ m := buildMap(seed, toward)
36+ main := mainland(&m)
37+ spawns := buildSpawns(lr, &m, main)
38+ pois := layoutPOIs(&layout{r: lr, sys: sys, m: &m, main: main, spawns: spawns, byPower: byPower, harsh: harshest(toward)}, nMain, nSide)
3039 boss := pois[nMain-1]
31- maxDist := abs(boss.X-spawns[0].X) + abs(boss.Y-spawns[0].Y)
40+ maxDist := world.Distance(boss.X, boss.Y, spawns[0].X, spawns[0].Y)
3241
3342 qr := sub(seed, "quests")
3443 q := &questBuilder{r: qr, sys: sys, factions: byID, names: rollKeyNames(qr)}
@@ -42,7 +51,17 @@ func Generate(seed model.Seed) World {
4251 }
4352 hintSpawns(spawns, pois[0])
4453
45- m := buildMap(sub(seed, "terrain"), sys, spawns, pois)
54+ m.Spawns, m.POIs = spawns, pois
55+ roads := [][2]int{}
56+ for _, sp := range spawns {
57+ roads = append(roads, [2]int{sp.X, sp.Y})
58+ }
59+ for _, p := range pois {
60+ if p.Kind == "village" || p.Kind == "camp" {
61+ roads = append(roads, [2]int{p.X, p.Y})
62+ }
63+ }
64+ layRoads(&m, roads)
4665 for _, k := range q.keys {
4766 for _, mission := range append([]model.Mission{camp.Main}, camp.SideQuests...) {
4867 for _, s := range mission.Steps {
@@ -53,7 +72,16 @@ func Generate(seed model.Seed) World {
5372 }
5473 }
5574 }
56- placeLoot(sub(seed, "loot"), &m, spawns[0], maxDist)
75+ pl := newPlacer(sub(seed, "loot"), &m, spawns[0], 4)
76+ bands := placeLoot(pl, maxDist, byPower)
77+ pl.far = 9
78+ bands = append(bands, placeBands(pl, maxDist, byPower)...)
79+ pl.far = 3
80+ m.Landmarks = placeLandmarks(pl)
81+ for i := range bands {
82+ bands[i].ID = fmt.Sprintf("band%d", i+1)
83+ }
84+ m.Bands = bands
5785
5886 er := sub(seed, "encounters")
5987 var encs []model.Encounter
@@ -63,9 +91,15 @@ func Generate(seed model.Seed) World {
6391 b = name
6492 }
6593 lv := levelAt(spawns[0], maxDist, p.X, p.Y)
94+ if i < nMain {
95+ lv = 1 + i*4/(nMain-1)
96+ }
6697 m.POIs[i].Level = lv
6798 encs = append(encs, buildEncounter(er, p, byID[p.Faction], lv, b))
6899 }
100+ for _, b := range m.Bands {
101+ encs = append(encs, buildBandEncounter(er, b, byID[b.Faction]))
102+ }
69103 return World{Campaign: camp, Map: m, Party: rollParty(sub(seed, "party"), spawns[0]), Encounters: encs}
70104 }
71105
internal/gen/gen_test.go+2-1
@@ -7,6 +7,7 @@ import (
77 "testing"
88
99 "tinyadventure/internal/model"
10+ "tinyadventure/internal/world"
1011 )
1112
1213 func TestDeterministic(t *testing.T) {
@@ -18,7 +19,7 @@ func TestDeterministic(t *testing.T) {
1819 }
1920
2021 func bfs(m model.Map, sx, sy int) map[[2]int]bool {
21- return reachable(&m, sx, sy)
22+ return world.Reach(&m, [2]int{sx, sy})
2223 }
2324
2425 func TestSolvable(t *testing.T) {
internal/gen/items.go+2-0
@@ -5,6 +5,7 @@ import (
55 "math/rand"
66
77 "tinyadventure/internal/model"
8+ "tinyadventure/internal/sim"
89 )
910
1011 var rarities = []string{"common", "uncommon", "rare", "epic", "legendary"}
@@ -49,6 +50,7 @@ func makeItem(r *rand.Rand, id string, level int) model.Item {
4950 it.Bonus = model.Stats{Speed: 1 + tier, Magic: pow, Crit: r.Intn(tier + 2)}
5051 }
5152 it.Value = model.Price(it)
53+ sim.Imbue(r.Intn, &it)
5254 return it
5355 }
5456
internal/gen/landmarks.go+29-0
@@ -0,0 +1,29 @@
1+package gen
2+
3+import (
4+ "fmt"
5+ "slices"
6+
7+ "tinyadventure/internal/model"
8+ "tinyadventure/internal/world"
9+)
10+
11+func hilltop(m *model.Map, c [2]int) bool {
12+ h := m.Hex(c[0], c[1])
13+ return h[0] == model.ShapeHill && !slices.ContainsFunc(world.Neighbours(c[0], c[1]), func(n [2]int) bool {
14+ return m.In(n[0], n[1]) && m.Hex(n[0], n[1])[2] > h[2]
15+ })
16+}
17+
18+func placeLandmarks(p *placer) []model.Landmark {
19+ var out []model.Landmark
20+ add := func(kind string, cs [][2]int) {
21+ for _, c := range cs {
22+ out = append(out, model.Landmark{ID: fmt.Sprintf("lm%d", len(out)+1), Kind: kind, X: c[0], Y: c[1]})
23+ }
24+ }
25+ add("lookout", p.take(5, 8, func(c [2]int) bool { return hilltop(p.m, c) }))
26+ add("shrine", p.take(3, 10, func([2]int) bool { return true }))
27+ add("cache", p.take(5, 6, func([2]int) bool { return true }))
28+ return out
29+}
internal/gen/loot.go+29-51
@@ -2,64 +2,42 @@ package gen
22
33 import (
44 "fmt"
5- "math/rand"
65
76 "tinyadventure/internal/model"
87 )
98
10-var lootKinds = []string{"chest", "corpse", "cache"}
9+const (
10+ guardChance = 40
11+ mimicChance = 15
12+ trapChance = 25
13+)
1114
12-func reachable(m *model.Map, sx, sy int) map[[2]int]bool {
13- seen := map[[2]int]bool{{sx, sy}: true}
14- queue := [][2]int{{sx, sy}}
15- for len(queue) > 0 {
16- c := queue[0]
17- queue = queue[1:]
18- for _, d := range [][2]int{{1, 0}, {-1, 0}, {0, 1}, {0, -1}} {
19- n := [2]int{c[0] + d[0], c[1] + d[1]}
20- if n[0] < 0 || n[1] < 0 || n[0] >= m.Width || n[1] >= m.Height || seen[n] || !m.Tiles[n[1]][n[0]].Walkable {
21- continue
22- }
23- seen[n] = true
24- queue = append(queue, n)
15+func placeLoot(p *placer, maxDist int, byPower []model.Faction) []model.Band {
16+ var bands []model.Band
17+ for _, c := range p.take(between(p.r, 10, 14), 4, func([2]int) bool { return true }) {
18+ lv := levelAt(p.origin, maxDist, c[0], c[1])
19+ id := fmt.Sprintf("chest%d", len(p.m.Loot)+1)
20+ roll := p.r.Intn(100)
21+ bonus := 0
22+ node := model.LootNode{ID: id, X: c[0], Y: c[1]}
23+ switch {
24+ case roll < guardChance:
25+ bonus = 1
26+ f := factionAt(byPower, p.progress(c, maxDist), p.r.Float64())
27+ bands = append(bands, model.Band{Kind: "guard", Name: "Guards", Faction: f.ID, Level: lv, X: c[0], Y: c[1], HomeX: c[0], HomeY: c[1]})
28+ case roll < guardChance+mimicChance:
29+ bonus = 2
30+ bands = append(bands, model.Band{Kind: "mimic", Name: "Mimic", Level: lv, X: c[0], Y: c[1], HomeX: c[0], HomeY: c[1]})
31+ case roll < guardChance+mimicChance+trapChance:
32+ bonus = 1
33+ node.Trap = true
2534 }
35+ node.Item = makeItem(p.r, fmt.Sprintf("item%d", len(p.m.Loot)+1), lv+2*bonus)
36+ p.m.Loot = append(p.m.Loot, node)
2637 }
27- return seen
38+ return bands
2839 }
2940
30-func placeLoot(r *rand.Rand, m *model.Map, origin model.SpawnPoint, maxDist int) {
31- used := map[[2]int]bool{}
32- for _, p := range m.POIs {
33- used[[2]int{p.X, p.Y}] = true
34- }
35- for _, s := range m.Spawns {
36- used[[2]int{s.X, s.Y}] = true
37- }
38- for _, l := range m.Loot {
39- used[[2]int{l.X, l.Y}] = true
40- }
41- var open [][2]int
42- for y := 0; y < m.Height; y++ {
43- for x := 0; x < m.Width; x++ {
44- c := [2]int{x, y}
45- if m.Tiles[y][x].Walkable && !used[c] {
46- open = append(open, c)
47- }
48- }
49- }
50- reach := reachable(m, origin.X, origin.Y)
51- open = shuffled(r, open)
52- n := between(r, 16, 24)
53- for _, c := range open {
54- if n == 0 {
55- break
56- }
57- if !reach[c] {
58- continue
59- }
60- id := fmt.Sprintf("%s%d", pick(r, lootKinds), len(m.Loot)+1)
61- it := makeItem(r, fmt.Sprintf("item%d", len(m.Loot)+1), levelAt(origin, maxDist, c[0], c[1]))
62- m.Loot = append(m.Loot, model.LootNode{ID: id, X: c[0], Y: c[1], Item: it})
63- n--
64- }
41+func factionAt(byPower []model.Faction, prog, jitter float64) model.Faction {
42+ return byPower[min(len(byPower)-1, int(prog*float64(len(byPower))+jitter*0.8))]
6543 }
internal/gen/party.go+26-11
@@ -5,21 +5,35 @@ import (
55 "math/rand"
66
77 "tinyadventure/internal/model"
8+ "tinyadventure/internal/sim"
89 )
910
1011 type classDef struct {
1112 name string
1213 hp, atk int
1314 def, mag int
14- abilities []model.Ability
15+ abilities []string
1516 }
1617
1718 var classes = []classDef{
18- {"fighter", 30, 6, 4, 1, []model.Ability{{ID: "cleave", Name: "Cleave", Kind: "damage", Power: 1.3, Cooldown: 2, Target: "enemy"}, {ID: "shield-bash", Name: "Shield Bash", Kind: "damage", Power: 0.9, Cooldown: 3, Target: "enemy"}}},
19- {"rogue", 22, 7, 2, 1, []model.Ability{{ID: "backstab", Name: "Backstab", Kind: "damage", Power: 1.6, Cooldown: 3, Target: "enemy"}, {ID: "poison-dart", Name: "Poison Dart", Kind: "damage", Power: 1.1, Cooldown: 2, Target: "enemy"}}},
20- {"mage", 18, 2, 1, 8, []model.Ability{{ID: "firebolt", Name: "Firebolt", Kind: "damage", Power: 1.5, Cooldown: 2, Target: "enemy"}, {ID: "frost-nova", Name: "Frost Nova", Kind: "damage", Power: 1.0, Cooldown: 3, Target: "all-enemies"}}},
21- {"cleric", 24, 3, 3, 6, []model.Ability{{ID: "heal", Name: "Heal", Kind: "heal", Power: 1.4, Cooldown: 2, Target: "ally"}, {ID: "smite", Name: "Smite", Kind: "damage", Power: 1.2, Cooldown: 2, Target: "enemy"}}},
22- {"ranger", 22, 6, 2, 2, []model.Ability{{ID: "piercing-shot", Name: "Piercing Shot", Kind: "damage", Power: 1.4, Cooldown: 2, Target: "enemy"}, {ID: "volley", Name: "Volley", Kind: "damage", Power: 0.8, Cooldown: 3, Target: "all-enemies"}}},
19+ {"fighter", 30, 6, 4, 1, []string{"cleave", "shield-bash"}},
20+ {"rogue", 22, 7, 2, 1, []string{"backstab", "poison-dart"}},
21+ {"mage", 18, 2, 1, 8, []string{"firebolt", "frost-nova"}},
22+ {"cleric", 24, 3, 3, 6, []string{"heal", "smite"}},
23+ {"ranger", 22, 6, 2, 2, []string{"piercing-shot", "volley"}},
24+}
25+
26+type raceDef struct {
27+ name string
28+ hp, atk, def int
29+ mag, speed, crit int
30+}
31+
32+var races = []raceDef{
33+ {"human", 0, 0, 0, 0, 0, 3},
34+ {"elf", 0, 0, 0, 1, 2, 0},
35+ {"dwarf", 4, 0, 1, 0, 0, 0},
36+ {"orc", 0, 2, 0, 0, 0, 0},
2337 }
2438
2539 var heroNames = []string{"Ayla", "Brom", "Cael", "Dara", "Edrin", "Fenna", "Garrick", "Hilde", "Isolde", "Joren", "Kestrel", "Lysa", "Mordo", "Nyx", "Orin", "Perrin"}
@@ -29,14 +43,15 @@ func rollParty(r *rand.Rand, spawn model.SpawnPoint) model.Party {
2943 names := shuffled(r, heroNames)
3044 p := model.Party{X: spawn.X, Y: spawn.Y, Gold: between(r, 10, 40)}
3145 for i, c := range cs {
32- hp := c.hp + r.Intn(7)
46+ rc := pick(r, races)
47+ hp := c.hp + rc.hp + r.Intn(7)
3348 u := model.Unit{
34- ID: fmt.Sprintf("u%d", i+1), Name: names[i], Class: c.name, Level: 1,
49+ ID: fmt.Sprintf("u%d", i+1), Name: names[i], Class: c.name, Race: rc.name, Level: 1,
3550 Stats: model.Stats{
36- HP: hp, MaxHP: hp, Attack: c.atk + r.Intn(3), Defense: c.def + r.Intn(2),
37- Magic: c.mag + r.Intn(3), Speed: between(r, 3, 8), Crit: between(r, 3, 10),
51+ HP: hp, MaxHP: hp, Attack: c.atk + rc.atk + r.Intn(3), Defense: c.def + rc.def + r.Intn(2),
52+ Magic: c.mag + rc.mag + r.Intn(3), Speed: between(r, 3, 8) + rc.speed, Crit: between(r, 3, 10) + rc.crit,
3853 },
39- Abilities: append([]model.Ability(nil), c.abilities...),
54+ Abilities: sim.Abilities(c.abilities...),
4055 Gear: model.Gear{},
4156 }
4257 for _, s := range shuffled(r, slots)[:between(r, 2, 3)] {
internal/gen/place.go+66-0
@@ -0,0 +1,66 @@
1+package gen
2+
3+import (
4+ "math/rand"
5+
6+ "tinyadventure/internal/model"
7+ "tinyadventure/internal/world"
8+)
9+
10+type placer struct {
11+ r *rand.Rand
12+ m *model.Map
13+ reach map[[2]int]bool
14+ used map[[2]int]bool
15+ origin model.SpawnPoint
16+ far int
17+}
18+
19+func newPlacer(r *rand.Rand, m *model.Map, origin model.SpawnPoint, far int) *placer {
20+ p := &placer{r: r, m: m, reach: world.Reach(m, [2]int{origin.X, origin.Y}), used: map[[2]int]bool{}, origin: origin, far: far}
21+ for _, q := range m.POIs {
22+ p.used[[2]int{q.X, q.Y}] = true
23+ }
24+ for _, l := range m.Loot {
25+ p.used[[2]int{l.X, l.Y}] = true
26+ }
27+ return p
28+}
29+
30+func (p *placer) take(n, gap int, fits func(c [2]int) bool) [][2]int {
31+ var out [][2]int
32+ for _, c := range shuffled(p.r, hexes(p.m, func(c [2]int) bool { return p.reach[c] && open(p.m, c) && !p.used[c] && fits(c) })) {
33+ if len(out) == n {
34+ break
35+ }
36+ if p.near(c, gap) {
37+ continue
38+ }
39+ p.used[c] = true
40+ out = append(out, c)
41+ }
42+ return out
43+}
44+
45+func (p *placer) near(c [2]int, gap int) bool {
46+ for _, s := range p.m.Spawns {
47+ if world.Distance(s.X, s.Y, c[0], c[1]) < p.far {
48+ return true
49+ }
50+ }
51+ for u := range p.used {
52+ if world.Distance(u[0], u[1], c[0], c[1]) < gap {
53+ return true
54+ }
55+ }
56+ return false
57+}
58+
59+func (p *placer) progress(c [2]int, maxDist int) float64 {
60+ return min(1, float64(world.Distance(c[0], c[1], p.origin.X, p.origin.Y))/float64(max(1, maxDist)))
61+}
62+
63+func open(m *model.Map, c [2]int) bool {
64+ s := m.Hex(c[0], c[1])[0]
65+ return s == model.ShapePlain || s == model.ShapeHill
66+}
internal/gen/pois.go+100-46
@@ -3,15 +3,14 @@ package gen
33 import (
44 "fmt"
55 "math/rand"
6+ "slices"
67 "sort"
78
89 "tinyadventure/internal/model"
10+ "tinyadventure/internal/world"
911 )
1012
11-const (
12- mapW = 48
13- mapH = 32
14-)
13+const poiGap = 5
1514
1615 var poiAdjectives = []string{"Gloomhollow", "Ashen", "Whispering", "Forsaken", "Crimson", "Thornwood", "Sunken", "Hollow", "Iron", "Mournful", "Weeping", "Pale"}
1716
@@ -19,62 +18,115 @@ var poiTitles = map[string]string{
1918 "mine": "Mine", "beach": "Shore", "ruins": "Ruins", "crypt": "Crypt", "village": "Hamlet", "tower": "Tower", "camp": "Camp",
2019 }
2120
22-func abs(a int) int {
23- if a < 0 {
24- return -a
21+var poiFits = map[string]func(m *model.Map, c [2]int) bool{
22+ "mine": func(m *model.Map, c [2]int) bool {
23+ s := m.Hex(c[0], c[1])[0]
24+ return s == model.ShapeHill || s == model.ShapeMountain
25+ },
26+ "beach": func(m *model.Map, c [2]int) bool {
27+ return m.Hex(c[0], c[1])[0] == model.ShapePlain && slices.ContainsFunc(world.Neighbours(c[0], c[1]), func(n [2]int) bool {
28+ return m.In(n[0], n[1]) && m.Hex(n[0], n[1])[0] <= model.ShapeShallow
29+ })
30+ },
31+ "crypt": func(m *model.Map, c [2]int) bool { return m.Hex(c[0], c[1])[1]%3 == 2 },
32+ "village": func(m *model.Map, c [2]int) bool {
33+ h := m.Hex(c[0], c[1])
34+ return h[0] == model.ShapePlain && h[3]&model.FlagForest == 0
35+ },
36+ "tower": func(m *model.Map, c [2]int) bool {
37+ h := m.Hex(c[0], c[1])
38+ return h[0] >= model.ShapeHill && !slices.ContainsFunc(world.Neighbours(c[0], c[1]), func(n [2]int) bool {
39+ return m.In(n[0], n[1]) && m.Hex(n[0], n[1])[2] > h[2]
40+ })
41+ },
42+ "camp": func(m *model.Map, c [2]int) bool { return m.Hex(c[0], c[1])[3]&model.FlagForest != 0 },
43+ "ruins": func(m *model.Map, c [2]int) bool { return true },
44+}
45+
46+func filter(cs [][2]int, keep func(c [2]int) bool) [][2]int {
47+ var out [][2]int
48+ for _, c := range cs {
49+ if keep(c) {
50+ out = append(out, c)
51+ }
2552 }
26- return a
53+ return out
2754 }
2855
29-func taken(pts []model.POI, spawns []model.SpawnPoint, x, y int) bool {
30- for _, p := range pts {
31- if abs(p.X-x)+abs(p.Y-y) < 4 {
32- return true
56+type layout struct {
57+ r *rand.Rand
58+ sys Systems
59+ m *model.Map
60+ main map[[2]int]bool
61+ spawns []model.SpawnPoint
62+ byPower []model.Faction
63+ harsh byte
64+ pois []model.POI
65+}
66+
67+func (l *layout) free(c [2]int) bool {
68+ if !l.main[c] || !land(l.m, c) {
69+ return false
70+ }
71+ for _, s := range l.spawns {
72+ if world.Distance(s.X, s.Y, c[0], c[1]) < poiGap {
73+ return false
3374 }
3475 }
35- for _, s := range spawns {
36- if abs(s.X-x)+abs(s.Y-y) < 4 {
37- return true
76+ for _, p := range l.pois {
77+ if world.Distance(p.X, p.Y, c[0], c[1]) < poiGap {
78+ return false
3879 }
3980 }
40- return false
81+ return true
4182 }
4283
43-func layoutPOIs(r *rand.Rand, sys Systems, factions []model.Faction, spawns []model.SpawnPoint, nMain, nSide int) []model.POI {
44- byPower := append([]model.Faction(nil), factions...)
45- sort.Slice(byPower, func(i, j int) bool { return byPower[i].Power < byPower[j].Power })
46- var pois []model.POI
47- place := func(i, x int, prog float64, boss bool) {
48- lo, hi := 2, mapH-3
49- if i == 0 {
50- lo, hi = spawns[0].Y-3, spawns[0].Y+3
51- }
52- y := between(r, lo, hi)
53- for a := 0; a < 80 && taken(pois, spawns, x, y); a++ {
54- y = between(r, lo, hi)
55- if a > 40 {
56- x += r.Intn(3) - 1
57- }
84+func (l *layout) place(cx int, near *model.SpawnPoint, prog float64, boss bool) {
85+ var band [][2]int
86+ for w := 2; len(band) == 0 && w < mapW*2; w += 2 {
87+ band = hexes(l.m, func(c [2]int) bool {
88+ return abs(c[0]-cx) <= w && (near == nil || world.Distance(c[0], c[1], near.X, near.Y) <= 6+w) && l.free(c)
89+ })
90+ }
91+ if boss {
92+ if hb := filter(band, func(c [2]int) bool { return l.m.Hex(c[0], c[1])[1] == l.harsh }); len(hb) > 0 {
93+ band = hb
5894 }
59- kind := pick(r, sys.POIKinds)
60- f := byPower[len(byPower)-1]
61- if !boss {
62- f = byPower[min(len(byPower)-1, int(prog*float64(len(byPower))+r.Float64()*0.8))]
95+ }
96+ kinds := shuffled(l.r, l.sys.POIKinds)
97+ kind, at := kinds[0], pick(l.r, band)
98+ for _, k := range kinds {
99+ if fit := filter(band, func(c [2]int) bool { return poiFits[k](l.m, c) }); len(fit) > 0 {
100+ kind, at = k, pick(l.r, fit)
101+ break
63102 }
64- pois = append(pois, model.POI{
65- ID: fmt.Sprintf("poi%d", i+1), Kind: kind, X: x, Y: y, Faction: f.ID,
66- Name: uniqueName(r, pois, kind),
67- })
68103 }
69- x0 := spawns[0].X
70- for i := 0; i < nMain; i++ {
104+ f := l.byPower[len(l.byPower)-1]
105+ if !boss {
106+ f = l.byPower[min(len(l.byPower)-1, int(prog*float64(len(l.byPower))+l.r.Float64()*0.8))]
107+ }
108+ l.m.Hex(at[0], at[1])[3] &^= model.FlagForest
109+ l.pois = append(l.pois, model.POI{
110+ ID: fmt.Sprintf("poi%d", len(l.pois)+1), Kind: kind, X: at[0], Y: at[1], Faction: f.ID,
111+ Name: uniqueName(l.r, l.pois, kind),
112+ })
113+}
114+
115+func layoutPOIs(l *layout, nMain, nSide int) []model.POI {
116+ sort.Slice(l.byPower, func(i, j int) bool { return l.byPower[i].Power < l.byPower[j].Power })
117+ x0 := l.spawns[0].X
118+ for i := range nMain {
71119 prog := float64(i) / float64(nMain-1)
72- place(i, x0+4+int(prog*float64(mapW-x0-10)), prog, i == nMain-1)
120+ var near *model.SpawnPoint
121+ if i == 0 {
122+ near = &l.spawns[0]
123+ }
124+ l.place(x0+5+int(prog*float64(mapW-x0-10)), near, prog, i == nMain-1)
73125 }
74- for i := 0; i < nSide; i++ {
75- place(nMain+i, between(r, x0+6, mapW-12), r.Float64(), false)
126+ for range nSide {
127+ l.place(between(l.r, x0+6, mapW-12), nil, l.r.Float64(), false)
76128 }
77- return pois
129+ return l.pois
78130 }
79131
80132 func uniqueName(r *rand.Rand, pois []model.POI, kind string) string {
@@ -90,6 +142,8 @@ func uniqueName(r *rand.Rand, pois []model.POI, kind string) string {
90142 }
91143 }
92144
145+func abs(a int) int { return max(a, -a) }
146+
93147 func levelAt(origin model.SpawnPoint, maxDist, x, y int) int {
94- return 1 + (abs(x-origin.X)+abs(y-origin.Y))*4/max(1, maxDist)
148+ return 1 + world.Distance(x, y, origin.X, origin.Y)*4/max(1, maxDist)
95149 }
internal/gen/spawn.go+27-5
@@ -5,6 +5,7 @@ import (
55 "math/rand"
66
77 "tinyadventure/internal/model"
8+ "tinyadventure/internal/world"
89 )
910
1011 var spawnKinds = []struct{ kind, hint string }{
@@ -15,13 +16,34 @@ var spawnKinds = []struct{ kind, hint string }{
1516 {"wagon", "A broken merchant wagon. A torn map is marked at %s."},
1617 }
1718
18-func buildSpawns(r *rand.Rand) []model.SpawnPoint {
19+func buildSpawns(r *rand.Rand, m *model.Map, main map[[2]int]bool) []model.SpawnPoint {
1920 kinds := shuffled(r, spawnKinds)
20- cy := mapH / 2
21- return []model.SpawnPoint{
22- {ID: "sp1", Kind: kinds[0].kind, X: 3, Y: cy - between(r, 0, 3), Hint: kinds[0].hint},
23- {ID: "sp2", Kind: kinds[1].kind, X: 3, Y: cy + between(r, 4, 7), Hint: kinds[1].hint},
21+ west := func(open bool) func(c [2]int) bool {
22+ return func(c [2]int) bool {
23+ h := m.Hex(c[0], c[1])
24+ 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)
25+ }
2426 }
27+ sites := hexes(m, west(true))
28+ if len(sites) < 2 {
29+ sites = hexes(m, west(false))
30+ }
31+ a := pick(r, sites)
32+ b := a
33+ for _, c := range shuffled(r, sites) {
34+ if d := world.Distance(a[0], a[1], c[0], c[1]); d >= 6 && d <= 14 {
35+ b = c
36+ break
37+ }
38+ }
39+ out := []model.SpawnPoint{
40+ {ID: "sp1", Kind: kinds[0].kind, X: a[0], Y: a[1], Hint: kinds[0].hint},
41+ {ID: "sp2", Kind: kinds[1].kind, X: b[0], Y: b[1], Hint: kinds[1].hint},
42+ }
43+ for _, s := range out {
44+ m.Hex(s.X, s.Y)[3] &^= model.FlagForest
45+ }
46+ return out
2547 }
2648
2749 func hintSpawns(spawns []model.SpawnPoint, first model.POI) {
internal/gen/terrain.go+62-64
@@ -1,90 +1,88 @@
11 package gen
22
33 import (
4- "math/rand"
4+ "sort"
55
66 "tinyadventure/internal/model"
7+ "tinyadventure/internal/world"
78 )
89
9-var poiTerrain = map[string]string{
10- "mine": "rock", "beach": "sand", "ruins": "ruin", "crypt": "grave", "village": "farm", "tower": "stone", "camp": "dirt",
10+const (
11+ mapW = 68
12+ mapH = 46
13+)
14+
15+var themeClimate = map[string]world.Climate{
16+ "blood": {Temp: -0.6, Moist: 1}, "reptile": {Temp: 1, Moist: 1}, "outlaw": {Temp: 1, Moist: -1}, "grave": {Temp: -1, Moist: -1},
17+ "occult": {Temp: 1, Moist: 0}, "greenskin": {Temp: 0.6, Moist: -0.6}, "wild": {Temp: 0, Moist: 0.8}, "hex": {Temp: -0.2, Moist: 1},
18+}
19+
20+func band(v float64) int {
21+ return min(2, max(0, int(v+1.5)))
1122 }
1223
13-var blocked = map[string]bool{"water": true, "mountain": true}
24+func harshest(c world.Climate) byte { return byte(3*band(c.Temp) + band(c.Moist)) }
25+
26+func buildMap(seed model.Seed, toward world.Climate) model.Map {
27+ return model.Map{Width: mapW, Height: mapH, Hexes: world.New(uint64(seed), mapW, mapH, toward).Map()}
28+}
1429
15-func stamp(m *model.Map, cx, cy, rad int, terrain string, force bool) {
16- for y := cy - rad; y <= cy+rad; y++ {
17- for x := cx - rad; x <= cx+rad; x++ {
18- if x < 0 || y < 0 || x >= m.Width || y >= m.Height || (x-cx)*(x-cx)+(y-cy)*(y-cy) > rad*rad+1 {
30+func land(m *model.Map, c [2]int) bool {
31+ return m.Walkable(c[0], c[1]) && m.Hex(c[0], c[1])[0] >= model.ShapePlain
32+}
33+
34+func mainland(m *model.Map) map[[2]int]bool {
35+ var best map[[2]int]bool
36+ seen := map[[2]int]bool{}
37+ for y := range m.Height {
38+ for x := range m.Width {
39+ c := [2]int{x, y}
40+ if seen[c] || !land(m, c) {
1941 continue
2042 }
21- if force || m.Tiles[y][x].Terrain == "grass" {
22- m.Tiles[y][x] = model.Tile{Terrain: terrain, Walkable: !blocked[terrain]}
43+ r := world.Reach(m, c)
44+ for k := range r {
45+ seen[k] = true
46+ }
47+ if len(r) > len(best) {
48+ best = r
2349 }
2450 }
2551 }
52+ return best
2653 }
2754
28-func carve(m *model.Map, x0, y0, x1, y1 int) {
29- open := func(x, y int) {
30- if !m.Tiles[y][x].Walkable {
31- m.Tiles[y][x] = model.Tile{Terrain: "road", Walkable: true}
32- }
33- }
34- x, y := x0, y0
35- for x != x1 {
36- open(x, y)
37- if x < x1 {
38- x++
39- } else {
40- x--
41- }
42- }
43- for y != y1 {
44- open(x, y)

Cut short: this commit's diff is over 1000 lines.

internal/model/camp.go+1-0

Cut short: this commit's diff is over 1000 lines.

internal/model/combat.go+2-1

Cut short: this commit's diff is over 1000 lines.

internal/model/item.go+6-1

Cut short: this commit's diff is over 1000 lines.

internal/model/state.go+2-0

Cut short: this commit's diff is over 1000 lines.

internal/model/state_test.go+1-1

Cut short: this commit's diff is over 1000 lines.

internal/model/unit.go+4-0

Cut short: this commit's diff is over 1000 lines.

internal/model/worldmap.go+74-10

Cut short: this commit's diff is over 1000 lines.

internal/server/bands.go+76-0

Cut short: this commit's diff is over 1000 lines.

internal/server/camp.go+26-20

Cut short: this commit's diff is over 1000 lines.

internal/server/danger_test.go+85-0

Cut short: this commit's diff is over 1000 lines.

internal/server/game.go+11-5

Cut short: this commit's diff is over 1000 lines.

internal/server/hazards.go+55-0

Cut short: this commit's diff is over 1000 lines.

internal/server/interact.go+10-3

Cut short: this commit's diff is over 1000 lines.

internal/server/landmarks.go+53-0

Cut short: this commit's diff is over 1000 lines.

internal/server/move.go+35-36

Cut short: this commit's diff is over 1000 lines.

internal/server/play_test.go+30-22

Cut short: this commit's diff is over 1000 lines.

internal/server/server_test.go+20-1

Cut short: this commit's diff is over 1000 lines.

internal/server/threat.go+9-4

Cut short: this commit's diff is over 1000 lines.

internal/sim/abilities.go+6-1

Cut short: this commit's diff is over 1000 lines.

internal/sim/classes.go+1-1

Cut short: this commit's diff is over 1000 lines.

internal/sim/combat.go+92-16

Cut short: this commit's diff is over 1000 lines.

internal/sim/enemies.go+2-2

Cut short: this commit's diff is over 1000 lines.

internal/sim/gear.go+1-0

Cut short: this commit's diff is over 1000 lines.

internal/sim/traits.go+80-0

Cut short: this commit's diff is over 1000 lines.

internal/sim/traits_test.go+66-0

Cut short: this commit's diff is over 1000 lines.

internal/world/hex.go+38-0

Cut short: this commit's diff is over 1000 lines.

internal/world/noise.go+49-0

Cut short: this commit's diff is over 1000 lines.

internal/world/path.go+75-0

Cut short: this commit's diff is over 1000 lines.

internal/world/terrain.go+105-0

Cut short: this commit's diff is over 1000 lines.

internal/world/world_test.go+71-0

Cut short: this commit's diff is over 1000 lines.

scripts/driver.mjs+57-8

Cut short: this commit's diff is over 1000 lines.

scripts/playthrough.mjs+34-14

Cut short: this commit's diff is over 1000 lines.

scripts/verify.mjs+23-6

Cut short: this commit's diff is over 1000 lines.

web/gallery.html+13-0

Cut short: this commit's diff is over 1000 lines.

web/js/autogear.js+0-20

Cut short: this commit's diff is over 1000 lines.

web/js/beasts.js+111-0

Cut short: this commit's diff is over 1000 lines.

web/js/board.js+189-0

Cut short: this commit's diff is over 1000 lines.

web/js/camp.js+7-2

Cut short: this commit's diff is over 1000 lines.

web/js/combat.js+11-7

Cut short: this commit's diff is over 1000 lines.

web/js/compass.js+8-6

Cut short: this commit's diff is over 1000 lines.

web/js/debug.js+3-0

Cut short: this commit's diff is over 1000 lines.

web/js/figures.js+206-0

Cut short: this commit's diff is over 1000 lines.

web/js/flora.js+94-0

Cut short: this commit's diff is over 1000 lines.

web/js/gallery.js+95-0

Cut short: this commit's diff is over 1000 lines.

web/js/hex.js+27-0

Cut short: this commit's diff is over 1000 lines.

web/js/hud.js+9-1

Cut short: this commit's diff is over 1000 lines.

web/js/inventory.js+22-9

Cut short: this commit's diff is over 1000 lines.

web/js/layout.js+2-1

Cut short: this commit's diff is over 1000 lines.

web/js/looks.js+56-0

Cut short: this commit's diff is over 1000 lines.

web/js/main.js+32-15

Cut short: this commit's diff is over 1000 lines.

web/js/minis.js+32-0

Cut short: this commit's diff is over 1000 lines.

web/js/paint.js+16-18

Cut short: this commit's diff is over 1000 lines.

web/js/party.js+14-13

Cut short: this commit's diff is over 1000 lines.

web/js/props.js+35-24

Cut short: this commit's diff is over 1000 lines.

web/js/threat.js+21-5

Cut short: this commit's diff is over 1000 lines.

web/js/traits.js+57-0

Cut short: this commit's diff is over 1000 lines.

web/js/ui.js+22-2

Cut short: this commit's diff is over 1000 lines.

web/js/world.js+79-108

Cut short: this commit's diff is over 1000 lines.