forked from jasonbot/mud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterrain.go
103 lines (87 loc) · 3.81 KB
/
terrain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package mud
import (
"encoding/json"
"io/ioutil"
"log"
)
// DefaultBiomeType yes
const DefaultBiomeType = "open-grass"
// BiomeData contains information about biome types
type BiomeData struct {
ID string
Name string `json:""`
Algorithm string `json:""` // Need strategies to make land
AlgorithmParameters map[string]string `json:""` // Helpers for terrain generator algorithm
Transitions []string `json:""` // Other biome types this can transition into when generating
GetRandomTransition func() string // What to transition to
}
// DefaultCellType is the seed land type when spawning a character.
const DefaultCellType string = "clearing"
// CellTerrain stores rules about different cell's terrain types.
// For 256 color colors check https://jonasjacek.github.io/colors/
type CellTerrain struct {
ID string `json:""`
Permeable bool `json:""` // Things like paths, rivers, etc. should be permeable so biomes don't suddenly stop geneating through them.
Blocking bool `json:""` // Some terrain types are impassable; e.g. walls
Name string `json:",omitempty"` // Formatstring to modify place name
Algorithm string `json:""` // Should have algos for e.g. town grid building etc.
AlgorithmParameters map[string]string `json:""` // Helpers for terrain generator algorithm
CreatureSpawns []CreatureSpawn `json:""` // List of monster types and probabilities of them appearing in each terrain type
ItemDrops []ItemDrop `json:""` // List of items and probabilities of them appearing in each terrain type
FGcolor byte `json:""` // SSH-display specific: the 256 color xterm color for FG
BGcolor byte `json:""` // SSH-display specific: the 256 color xterm color for BG
Bold bool `json:""` // SSH-display specific: bold the cell FG?
Animated bool `json:""` // SSH-display specific: Fake an animation effect?
Representations []rune `json:""` // SSH-display specific: unicode chars to use to represent this cell on-screen
}
// CellTypes is the list of cell types
var CellTypes map[string]CellTerrain
// BiomeTypes is the list of cell types
var BiomeTypes map[string]BiomeData
// NORTHBIT North for bitmasks
// EASTBIT East for bitmasks
// SOUTHBIT South for bitmasks
// WESTBIT West for bitmasks
const (
NORTHBIT = 1
EASTBIT = 2
SOUTHBIT = 4
WESTBIT = 8
)
// CellInfo holds more information on the cell: exits, items available, etc.
type CellInfo struct {
TerrainID string `json:""`
TerrainData CellTerrain `json:"-"`
BiomeID string `json:""`
BiomeData BiomeData `json:"-"`
ExitBlocks byte `json:""`
RegionNameID uint64 `json:""`
RegionName string `json:"-"`
}
func loadTerrainTypes(terrainInfoFile string) {
data, err := ioutil.ReadFile(terrainInfoFile)
var terrainFileData struct {
CellTypes map[string]CellTerrain `json:"cells"`
BiomeTypes map[string]BiomeData `json:"biomes"`
}
if err == nil {
err = json.Unmarshal(data, &terrainFileData)
BiomeTypes = make(map[string]BiomeData)
for k, val := range terrainFileData.BiomeTypes {
val.ID = k
val.GetRandomTransition, val.Transitions = MakeTransitionFunction(val.ID, val.Transitions)
BiomeTypes[k] = val
}
CellTypes = make(map[string]CellTerrain)
for k, val := range terrainFileData.CellTypes {
val.ID = k
CellTypes[k] = val
}
}
if err != nil {
log.Printf("Error parsing %s: %v", terrainInfoFile, err)
}
}
func init() {
CellTypes = make(map[string]CellTerrain)
}