1package model 2 3const ( 4 ShapeDeep byte = iota 5 ShapeShallow 6 ShapePlain 7 ShapeHill 8 ShapeMountain 9 ShapePeak 10) 11 12const ( 13 FlagForest byte = 1 << iota 14 FlagRoad 15) 16 17const HexBytes = 4 18 19var Biomes = []string{"Frost steppe", "Frostwood", "Rime fen", "Fey meadows", "Enchanted forest", "Mistbog", "Ember badlands", "Ashwood", "Jungle of vines"} 20 21type POI struct { 22 ID string `json:"id"` 23 Kind string `json:"kind"` 24 Name string `json:"name"` 25 X int `json:"x"` 26 Y int `json:"y"` 27 Faction string `json:"faction,omitempty"` 28 Level int `json:"level"` 29 Cleared bool `json:"cleared"` 30} 31 32type SpawnPoint struct { 33 ID string `json:"id"` 34 Kind string `json:"kind"` 35 X int `json:"x"` 36 Y int `json:"y"` 37 Hint string `json:"hint"` 38} 39 40type LootNode struct { 41 ID string `json:"id"` 42 X int `json:"x"` 43 Y int `json:"y"` 44 Item Item `json:"item"` 45 Collected bool `json:"collected"` 46 Trap bool `json:"trap,omitempty"` 47} 48 49type Band struct { 50 ID string `json:"id"` 51 Kind string `json:"kind"` 52 Name string `json:"name"` 53 Faction string `json:"faction"` 54 Level int `json:"level"` 55 X int `json:"x"` 56 Y int `json:"y"` 57 HomeX int `json:"homeX"` 58 HomeY int `json:"homeY"` 59 Cleared bool `json:"cleared,omitempty"` 60 Calm int `json:"calm,omitempty"` 61} 62 63type Landmark struct { 64 ID string `json:"id"` 65 Kind string `json:"kind"` 66 X int `json:"x"` 67 Y int `json:"y"` 68 Used bool `json:"used,omitempty"` 69} 70 71type Map struct { 72 Width int `json:"width"` 73 Height int `json:"height"` 74 Hexes []byte `json:"hexes"` 75 POIs []POI `json:"pois"` 76 Spawns []SpawnPoint `json:"spawns"` 77 Loot []LootNode `json:"loot"` 78 Bands []Band `json:"bands"` 79 Landmarks []Landmark `json:"landmarks"` 80} 81 82func (m *Map) In(x, y int) bool { return x >= 0 && y >= 0 && x < m.Width && y < m.Height } 83 84func (m *Map) Hex(x, y int) []byte { 85 i := (y*m.Width + x) * HexBytes 86 return m.Hexes[i : i+HexBytes] 87} 88 89func (m *Map) Walkable(x, y int) bool { 90 if !m.In(x, y) { 91 return false 92 } 93 s := m.Hex(x, y)[0] 94 return s != ShapeDeep && s != ShapePeak 95} 96 97func (m *Map) Cost(x, y int) int { 98 h := m.Hex(x, y) 99 if h[3]&FlagRoad != 0 { 100 return 1 101 } 102 c := [...]int{0, 3, 2, 3, 4, 0}[h[0]] 103 if h[3]&FlagForest != 0 { 104 c++ 105 } 106 return c 107}