-
Notifications
You must be signed in to change notification settings - Fork 1
/
properties.go
323 lines (293 loc) · 7.81 KB
/
properties.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
package bio
import (
"fmt"
"strings"
)
// SpeciesProperties defines the properties of a species.
type SpeciesProperties struct {
Kingdom SpeciesKingdom // General type of the species.
Family SpeciesFamily // Subtype of the species.
Digestion DigestiveSystem // What kind of food the species can eat.
Size SpeciesSize // Size of the species.
Locomotion Locomotion // How the species moves. (TODO: Primary locomotion)
}
// CompetitorHash returns a hash that can be used to compare two species and
// determine if they are competitors.
// This will be helpful when spreading the species and avoiding competing species.
func (s *SpeciesProperties) CompetitorHash() int64 {
return int64(s.Size) | (int64(s.Locomotion) << 8) | (int64(s.Digestion) << 16)
}
func (s *SpeciesProperties) String() string {
return fmt.Sprintf("%s %s %s %s %s", s.Kingdom, s.Family, s.Digestion, s.Size, s.Locomotion)
}
type SpeciesKingdom string
const (
SpeciesKingdomFlora SpeciesKingdom = "flora"
SpeciesKingdomFauna SpeciesKingdom = "fauna" // Maybe split this up into different types of fauna?
SpeciesKingdomFunga SpeciesKingdom = "funga"
)
func (s SpeciesKingdom) String() string {
return string(s)
}
func (s SpeciesKingdom) DigestiveSystems() []DigestiveSystem {
switch s {
case SpeciesKingdomFlora:
return []DigestiveSystem{
// TODO: Allow weighted selection. Some plants can eat other plants or animals.
DigestivePhotosynthetic,
}
case SpeciesKingdomFauna:
return []DigestiveSystem{
DigestiveSystemCarnivore,
DigestiveSystemHerbivore,
DigestiveSystemOmnivore,
}
case SpeciesKingdomFunga:
return []DigestiveSystem{
DigestivePhotosynthetic,
DigestiveDecomposer,
DigestiveSystemCarnivore, // rare
}
}
return nil
}
var SpeciesKingdoms = []SpeciesKingdom{
SpeciesKingdomFauna,
SpeciesKingdomFlora,
SpeciesKingdomFunga,
}
type SpeciesFamily string
const (
SpeciesFamilyNone SpeciesFamily = "None"
SpeciesFamilyTree SpeciesFamily = "Tree"
SpeciesFamilyShrub SpeciesFamily = "Shrub"
SpeciesFamilyGrass SpeciesFamily = "Grass"
SpeciesFamilyReed SpeciesFamily = "Reed"
SpeciesFamilyHerb SpeciesFamily = "Herb"
SpeciesFamilyFlower SpeciesFamily = "Flower"
SpeciesFamilyFern SpeciesFamily = "Fern"
SpeciesFamilyMoss SpeciesFamily = "Moss"
SpeciesFamilyVine SpeciesFamily = "Vine"
SpeciesFamilyCactus SpeciesFamily = "Cactus"
SpeciesFamilySucculent SpeciesFamily = "Succulent"
SpeciesFamilyInsect SpeciesFamily = "Insect"
SpeciesFamilyArachnid SpeciesFamily = "Arachnid"
SpeciesFamilyMammal SpeciesFamily = "Mammal"
SpeciesFamilyBird SpeciesFamily = "Bird"
SpeciesFamilyFish SpeciesFamily = "Fish"
SpeciesFamilyCrustacean SpeciesFamily = "Crustacean"
SpeciesFamilyMollusk SpeciesFamily = "Mollusk"
SpeciesFamilyMolluskClam SpeciesFamily = "Clam"
SpeciesFamilyMolluskSnail SpeciesFamily = "Snail"
SpeciesFamilyAmphibian SpeciesFamily = "Amphibian"
SpeciesFamilyReptileSerpent SpeciesFamily = "Serpent"
SpeciesFamilyReptileLizard SpeciesFamily = "Lizard"
SpeciesFamilyRodent SpeciesFamily = "Rodent"
SpeciesFamilyWorm SpeciesFamily = "Worm"
SpeciesFamilyMushroom SpeciesFamily = "Mushroom"
SpeciesFamilyMold SpeciesFamily = "Mold"
)
func (s SpeciesFamily) String() string {
return string(s)
}
func (s SpeciesFamily) Locomotion() Locomotion {
switch s {
case SpeciesFamilyInsect:
return LocomotionWalk
case SpeciesFamilyArachnid:
return LocomotionWalk
case SpeciesFamilyMammal:
return LocomotionWalk
case SpeciesFamilyBird:
return LocomotionFly
case SpeciesFamilyFish:
return LocomotionSwim
case SpeciesFamilyCrustacean:
return LocomotionSwim
case SpeciesFamilyMollusk:
return LocomotionSwim | LocomotionWalk
case SpeciesFamilyMolluskSnail:
return LocomotionSlither | LocomotionClimb
case SpeciesFamilyAmphibian:
return LocomotionWalk | LocomotionSwim
case SpeciesFamilyReptileSerpent:
return LocomotionSlither
case SpeciesFamilyReptileLizard:
return LocomotionWalk | LocomotionClimb
case SpeciesFamilyRodent:
return LocomotionWalk | LocomotionClimb | LocomotionBurrow
case SpeciesFamilyWorm:
return LocomotionSlither | LocomotionBurrow
}
return LocomotionNone
}
var speciesKingdomToFamiliesLand = map[SpeciesKingdom][]SpeciesFamily{
SpeciesKingdomFlora: {
SpeciesFamilyTree,
SpeciesFamilyShrub,
SpeciesFamilyGrass,
SpeciesFamilyReed,
SpeciesFamilyHerb,
SpeciesFamilyFlower,
SpeciesFamilyFern,
SpeciesFamilyMoss,
SpeciesFamilyVine,
SpeciesFamilyCactus,
SpeciesFamilySucculent,
},
SpeciesKingdomFauna: {
SpeciesFamilyInsect,
SpeciesFamilyArachnid,
SpeciesFamilyMammal,
SpeciesFamilyBird,
SpeciesFamilyAmphibian,
SpeciesFamilyReptileSerpent,
SpeciesFamilyReptileLizard,
SpeciesFamilyMolluskSnail,
SpeciesFamilyRodent,
SpeciesFamilyMollusk,
},
SpeciesKingdomFunga: {
SpeciesFamilyMushroom,
SpeciesFamilyMold,
},
}
var speciesKingdomToFamiliesWater = map[SpeciesKingdom][]SpeciesFamily{
SpeciesKingdomFlora: {
SpeciesFamilyGrass,
SpeciesFamilyHerb,
},
SpeciesKingdomFauna: {
SpeciesFamilyFish,
SpeciesFamilyCrustacean,
SpeciesFamilyMollusk,
SpeciesFamilyMolluskClam,
SpeciesFamilyReptileSerpent,
},
SpeciesKingdomFunga: {
SpeciesFamilyMushroom,
},
}
type SpeciesSize byte
const (
SpeciesSizeDefault SpeciesSize = iota
SpeciesSizeTiny
SpeciesSizeSmall
SpeciesSizeMedium
SpeciesSizeLarge
SpeciesSizeHuge
)
func (s SpeciesSize) String() string {
switch s {
case SpeciesSizeDefault:
return "default"
case SpeciesSizeTiny:
return "tiny"
case SpeciesSizeSmall:
return "small"
case SpeciesSizeMedium:
return "medium"
case SpeciesSizeLarge:
return "large"
case SpeciesSizeHuge:
return "huge"
}
return "unknown"
}
var SpeciesSizes = []SpeciesSize{
SpeciesSizeTiny,
SpeciesSizeSmall,
SpeciesSizeMedium,
SpeciesSizeLarge,
SpeciesSizeHuge,
}
type DigestiveSystem byte
const (
DigestiveSystemCarnivore DigestiveSystem = iota
DigestiveSystemHerbivore
DigestiveSystemOmnivore
DigestivePhotosynthetic
DigestiveDecomposer
DigestiveParasitic
)
func (d DigestiveSystem) String() string {
switch d {
case DigestiveSystemCarnivore:
return "carnivore"
case DigestiveSystemHerbivore:
return "herbivore"
case DigestiveSystemOmnivore:
return "omnivore"
case DigestivePhotosynthetic:
return "photosynthetic"
case DigestiveDecomposer:
return "decomposer"
case DigestiveParasitic:
return "parasitic"
}
return "unknown"
}
var DigestiveSystems = []DigestiveSystem{
DigestiveSystemCarnivore,
DigestiveSystemHerbivore,
DigestiveSystemOmnivore,
DigestivePhotosynthetic,
DigestiveDecomposer,
DigestiveParasitic,
}
type Locomotion byte
func (l Locomotion) isSet(b Locomotion) bool {
return l&b != 0
}
const (
LocomotionNone Locomotion = 0
LocomotionFly Locomotion = 1 << iota
LocomotionBurrow
LocomotionWalk
LocomotionSwim
LocomotionClimb
LocomotionSlither
)
func (l Locomotion) String() string {
var strs []string
if l.isSet(LocomotionFly) {
strs = append(strs, "fly")
}
if l.isSet(LocomotionBurrow) {
strs = append(strs, "burrow")
}
if l.isSet(LocomotionWalk) {
strs = append(strs, "walk")
}
if l.isSet(LocomotionSwim) {
strs = append(strs, "swim")
}
if l.isSet(LocomotionClimb) {
strs = append(strs, "climb")
}
if l.isSet(LocomotionSlither) {
strs = append(strs, "slither")
}
return strings.Join(strs, ", ")
}
var LocomotionTypes = []Locomotion{
LocomotionFly,
LocomotionBurrow,
LocomotionWalk,
LocomotionSwim,
LocomotionClimb,
LocomotionSlither,
}
var LocomotionTypesLand = []Locomotion{
LocomotionFly,
LocomotionBurrow,
LocomotionWalk,
LocomotionClimb,
LocomotionSlither,
}
var LocomotionTypesWater = []Locomotion{
LocomotionBurrow,
LocomotionSwim,
LocomotionClimb,
LocomotionSlither,
}