Cuberite
A lightweight, fast and extensible game server for Minecraft
BiomeDef.cpp
Go to the documentation of this file.
1 
2 // BiomeDef.cpp
3 
4 // Implements biome helper functions
5 
6 
7 #include "Globals.h"
8 #include "BiomeDef.h"
9 
10 
11 
12 
13 // The "map" used for biome <-> string conversions:
14 static struct
15 {
17  const char * m_String;
18 } g_BiomeMap[] =
19 {
20  {biOcean, "Ocean"},
21  {biPlains, "Plains"},
22  {biDesert, "Desert"},
23  {biExtremeHills, "ExtremeHills"},
24  {biForest, "Forest"},
25  {biTaiga, "Taiga"},
26  {biSwampland, "Swampland"},
27  {biRiver, "River"},
28  {biNether, "Hell"},
29  {biNether, "Nether"},
30  {biEnd, "Sky"},
31  {biEnd, "End"},
32  {biFrozenOcean, "FrozenOcean"},
33  {biFrozenRiver, "FrozenRiver"},
34  {biIcePlains, "IcePlains"},
35  {biIcePlains, "Tundra"},
36  {biIceMountains, "IceMountains"},
37  {biMushroomIsland, "MushroomIsland"},
38  {biMushroomShore, "MushroomShore"},
39  {biBeach, "Beach"},
40  {biDesertHills, "DesertHills"},
41  {biForestHills, "ForestHills"},
42  {biTaigaHills, "TaigaHills"},
43  {biExtremeHillsEdge, "ExtremeHillsEdge"},
44  {biJungle, "Jungle"},
45  {biJungleHills, "JungleHills"},
46 
47  // Release 1.7 biomes:
48  {biJungleEdge, "JungleEdge"},
49  {biDeepOcean, "DeepOcean"},
50  {biStoneBeach, "StoneBeach"},
51  {biColdBeach, "ColdBeach"},
52  {biBirchForest, "BirchForest"},
53  {biBirchForestHills, "BirchForestHills"},
54  {biRoofedForest, "RoofedForest"},
55  {biColdTaiga, "ColdTaiga"},
56  {biColdTaigaHills, "ColdTaigaHills"},
57  {biMegaTaiga, "MegaTaiga"},
58  {biMegaTaigaHills, "MegaTaigaHills"},
59  {biExtremeHillsPlus, "ExtremeHillsPlus"},
60  {biSavanna, "Savanna"},
61  {biSavannaPlateau, "SavannaPlateau"},
62  {biMesa, "Mesa"},
63  {biMesaPlateauF, "MesaPlateauF"},
64  {biMesaPlateau, "MesaPlateau"},
65 
66  // Release 1.7 variants:
67  {biSunflowerPlains, "SunflowerPlains"},
68  {biDesertM, "DesertM"},
69  {biExtremeHillsM, "ExtremeHillsM"},
70  {biFlowerForest, "FlowerForest"},
71  {biTaigaM, "TaigaM"},
72  {biSwamplandM, "SwamplandM"},
73  {biIcePlainsSpikes, "IcePlainsSpikes"},
74  {biJungleM, "JungleM"},
75  {biJungleEdgeM, "JungleEdgeM"},
76  {biBirchForestM, "BirchForestM"},
77  {biBirchForestHillsM, "BirchForestHillsM"},
78  {biRoofedForestM, "RoofedForestM"},
79  {biColdTaigaM, "ColdTaigaM"},
80  {biMegaSpruceTaiga, "MegaSpruceTaiga"},
81  {biMegaSpruceTaigaHills, "MegaSpruceTaigaHills"},
82  {biExtremeHillsPlusM, "ExtremeHillsPlusM"},
83  {biSavannaM, "SavannaM"},
84  {biSavannaPlateauM, "SavannaPlateauM"},
85  {biMesaBryce, "MesaBryce"},
86  {biMesaPlateauFM, "MesaPlateauFM"},
87  {biMesaPlateauM, "MesaPlateauM"},
88 } ;
89 
90 
91 
92 
93 
94 EMCSBiome StringToBiome(const AString & a_BiomeString)
95 {
96  // If it is a number, return it:
97  int res = atoi(a_BiomeString.c_str());
98  if ((res != 0) || (a_BiomeString.compare("0") == 0))
99  {
100  if ((res >= biFirstBiome) && (res < biNumBiomes))
101  {
102  return static_cast<EMCSBiome>(res);
103  }
104  else if ((res >= biFirstVariantBiome) && (res < biNumVariantBiomes))
105  {
106  return static_cast<EMCSBiome>(res);
107  }
108  // It was an invalid number
109  return biInvalidBiome;
110  }
111 
112  for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++)
113  {
114  if (NoCaseCompare(g_BiomeMap[i].m_String, a_BiomeString) == 0)
115  {
116  return g_BiomeMap[i].m_Biome;
117  }
118  } // for i - BiomeMap[]
119  return biInvalidBiome;
120 }
121 
122 
123 
124 
125 
126 AString BiomeToString(int a_Biome)
127 {
128  for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++)
129  {
130  if (g_BiomeMap[i].m_Biome == a_Biome)
131  {
132  return g_BiomeMap[i].m_String;
133  }
134  }
135  return AString();
136 }
137 
138 
139 
140 
141 
143 {
144  switch (a_Biome)
145  {
146  case biDesert:
147  case biDesertHills:
148  case biDesertM:
149  case biSavanna:
150  case biSavannaM:
151  case biSavannaPlateau:
152  case biSavannaPlateauM:
153  case biNether:
154  case biEnd:
155  {
156  return true;
157  }
158  default:
159  {
160  return false;
161  }
162  }
163 }
164 
165 
166 
167 
168 
170 {
171  switch (a_Biome)
172  {
173  case biFrozenOcean:
174  case biFrozenRiver:
175  case biIcePlains:
176  case biIceMountains:
177  case biColdBeach:
178  case biColdTaiga:
179  case biColdTaigaHills:
180  case biIcePlainsSpikes:
181  case biColdTaigaM:
182  {
183  return true;
184  }
185  default:
186  {
187  return false;
188  }
189  }
190 }
191 
192 
193 
194 
195 
196 bool IsBiomeCold(EMCSBiome a_Biome)
197 {
198  switch (a_Biome)
199  {
200  case biExtremeHills:
201  case biTaiga:
202  case biTaigaHills:
203  case biExtremeHillsEdge:
204  case biStoneBeach:
205  case biMegaTaiga:
206  case biMegaTaigaHills:
207  case biExtremeHillsPlus:
208  case biExtremeHillsM:
209  case biTaigaM:
210  case biColdTaigaM:
211  case biMegaSpruceTaiga:
213  case biExtremeHillsPlusM:
214  {
215  return true;
216  }
217  default:
218  {
219  return false;
220  }
221  }
222 }
223 
224 
225 
226 
227 
229 {
230  switch (a_Biome)
231  {
232  case biExtremeHills:
233  case biExtremeHillsEdge:
234  case biExtremeHillsM:
235  case biExtremeHillsPlus:
236  case biExtremeHillsPlusM:
237  {
238  return true;
239  }
240  default:
241  {
242  return false;
243  }
244  }
245 }
246 
247 
248 
249 
250 
251 bool IsBiomeMesa(EMCSBiome a_Biome)
252 {
253  switch (a_Biome)
254  {
255  case biMesa:
256  case biMesaPlateauF:
257  case biMesaPlateau:
258  case biMesaBryce:
259  case biMesaPlateauFM:
260  case biMesaPlateauM:
261  {
262  return true;
263  }
264  default:
265  {
266  return false;
267  }
268  }
269 }
270 
271 
272 
273 
274 
276 {
277  switch (a_Biome)
278  {
279  case biIcePlainsSpikes:
280  case biIcePlains:
281  case biIceMountains:
282  case biFrozenRiver:
283  case biColdBeach:
284  case biColdTaiga:
285  case biColdTaigaHills:
286  case biColdTaigaM:
287  {
288  // Always snow
289  return 0;
290  }
291 
292  case biExtremeHills:
293  case biExtremeHillsM:
294  case biExtremeHillsPlus:
295  case biExtremeHillsPlusM:
296  case biStoneBeach:
297  {
298  // Starts snowing at 96
299  return 96;
300  }
301 
302  case biTaiga:
303  case biTaigaHills:
304  case biTaigaM:
305  {
306  // Start snowing at 130
307  return 130;
308  }
309 
310  case biMegaTaiga:
311  case biMegaSpruceTaiga:
312  case biMegaTaigaHills:
314  {
315  // Start snowing at 160
316  return 160;
317  }
318 
319  case biRiver:
320  case biOcean:
321  case biDeepOcean:
322  {
323  // Starts snowing at 280
324  return 280;
325  }
326 
327  case biBirchForest:
328  case biBirchForestHills:
329  case biBirchForestM:
330  case biBirchForestHillsM:
331  {
332  // Starts snowing at 335
333  return 335;
334  }
335 
336  case biForest:
337  case biForestHills:
338  case biFlowerForest:
339  case biRoofedForest:
340  case biRoofedForestM:
341  {
342  // Starts snowing at 400
343  return 400;
344  }
345 
346  case biPlains:
347  case biSunflowerPlains:
348  case biSwampland:
349  case biSwamplandM:
350  case biBeach:
351  {
352  // Starts snowing at 460
353  return 460;
354  }
355 
356  case biMushroomIsland:
357  case biMushroomShore:
358  {
359  // Starts snowing at 520
360  return 520;
361  }
362 
363  case biJungle:
364  case biJungleHills:
365  case biJungleM:
366  case biJungleEdge:
367  case biJungleEdgeM:
368  {
369  // Starts snowing at 550
370  return 550;
371  }
372 
373  case biDesert:
374  case biDesertHills:
375  case biDesertM:
376  case biSavanna:
377  case biSavannaM:
378  case biSavannaPlateau:
379  case biSavannaPlateauM:
380  case biMesa:
381  case biMesaBryce:
382  case biMesaPlateau:
383  case biMesaPlateauF:
384  case biMesaPlateauFM:
385  case biMesaPlateauM:
386  {
387  // These biomes don't actualy have any downfall.
388  return 1000;
389  }
390 
391  case biNether:
392  case biEnd:
393  {
394  // These shouldn't get any snow at all.
395  return 9999;
396  }
397 
398  default:
399  {
400  return 0;
401  }
402  }
403 }
404 
405 
406 
407 
int GetSnowStartHeight(EMCSBiome a_Biome)
Returns the height when a biome when a biome starts snowing.
Definition: BiomeDef.cpp:275
const char * m_String
Definition: BiomeDef.cpp:17
bool IsBiomeNoDownfall(EMCSBiome a_Biome)
Returns true if the biome has no downfall - deserts and savannas.
Definition: BiomeDef.cpp:142
bool IsBiomeVeryCold(EMCSBiome a_Biome)
Returns true if the biome is very cold (has snow on ground everywhere, turns top water to ice,...
Definition: BiomeDef.cpp:169
bool IsBiomeMountain(EMCSBiome a_Biome)
Returns true if the biome is mountainous (mutations of the extreme hills biome)
Definition: BiomeDef.cpp:228
EMCSBiome StringToBiome(const AString &a_BiomeString)
Translates a biome string to biome enum.
Definition: BiomeDef.cpp:94
static struct @0 g_BiomeMap[]
AString BiomeToString(int a_Biome)
Translates biome enum into biome string.
Definition: BiomeDef.cpp:126
bool IsBiomeMesa(EMCSBiome a_Biome)
Returns true if the biome is Mesa or one of its mutations.
Definition: BiomeDef.cpp:251
bool IsBiomeCold(EMCSBiome a_Biome)
Returns true if the biome is cold (has snow and snowfall at higher elevations but not at regular heig...
Definition: BiomeDef.cpp:196
EMCSBiome m_Biome
Definition: BiomeDef.cpp:16
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:18
@ biJungleEdge
Definition: BiomeDef.h:50
@ biIceMountains
Definition: BiomeDef.h:38
@ biMesa
Definition: BiomeDef.h:64
@ biMesaPlateau
Definition: BiomeDef.h:66
@ biExtremeHillsM
Definition: BiomeDef.h:79
@ biForestHills
Definition: BiomeDef.h:43
@ biNether
Definition: BiomeDef.h:31
@ biBirchForest
Definition: BiomeDef.h:54
@ biBirchForestM
Definition: BiomeDef.h:86
@ biDesert
Definition: BiomeDef.h:24
@ biMesaPlateauF
Definition: BiomeDef.h:65
@ biSunflowerPlains
Definition: BiomeDef.h:77
@ biExtremeHillsPlusM
Definition: BiomeDef.h:92
@ biColdTaigaHills
Definition: BiomeDef.h:58
@ biFlowerForest
Definition: BiomeDef.h:80
@ biInvalidBiome
Definition: BiomeDef.h:19
@ biMegaSpruceTaiga
Definition: BiomeDef.h:90
@ biStoneBeach
Definition: BiomeDef.h:52
@ biMushroomShore
Definition: BiomeDef.h:40
@ biSavanna
Definition: BiomeDef.h:62
@ biTaigaHills
Definition: BiomeDef.h:44
@ biExtremeHillsPlus
Definition: BiomeDef.h:61
@ biJungle
Definition: BiomeDef.h:46
@ biMegaTaiga
Definition: BiomeDef.h:59
@ biJungleHills
Definition: BiomeDef.h:47
@ biOcean
Definition: BiomeDef.h:22
@ biFirstVariantBiome
Definition: BiomeDef.h:76
@ biDesertHills
Definition: BiomeDef.h:42
@ biBeach
Definition: BiomeDef.h:41
@ biForest
Definition: BiomeDef.h:26
@ biJungleEdgeM
Definition: BiomeDef.h:85
@ biTaigaM
Definition: BiomeDef.h:81
@ biBirchForestHillsM
Definition: BiomeDef.h:87
@ biJungleM
Definition: BiomeDef.h:84
@ biExtremeHillsEdge
Definition: BiomeDef.h:45
@ biNumVariantBiomes
Definition: BiomeDef.h:99
@ biFrozenRiver
Definition: BiomeDef.h:35
@ biRiver
Definition: BiomeDef.h:29
@ biMesaPlateauFM
Definition: BiomeDef.h:96
@ biMushroomIsland
Definition: BiomeDef.h:39
@ biDeepOcean
Definition: BiomeDef.h:51
@ biSavannaPlateauM
Definition: BiomeDef.h:94
@ biMesaBryce
Definition: BiomeDef.h:95
@ biPlains
Definition: BiomeDef.h:23
@ biRoofedForestM
Definition: BiomeDef.h:88
@ biBirchForestHills
Definition: BiomeDef.h:55
@ biColdBeach
Definition: BiomeDef.h:53
@ biMegaSpruceTaigaHills
Definition: BiomeDef.h:91
@ biSavannaM
Definition: BiomeDef.h:93
@ biSwamplandM
Definition: BiomeDef.h:82
@ biEnd
Definition: BiomeDef.h:33
@ biIcePlainsSpikes
Definition: BiomeDef.h:83
@ biFrozenOcean
Definition: BiomeDef.h:34
@ biExtremeHills
Definition: BiomeDef.h:25
@ biColdTaiga
Definition: BiomeDef.h:57
@ biFirstBiome
Definition: BiomeDef.h:21
@ biMegaTaigaHills
Definition: BiomeDef.h:60
@ biNumBiomes
Definition: BiomeDef.h:69
@ biRoofedForest
Definition: BiomeDef.h:56
@ biIcePlains
Definition: BiomeDef.h:36
@ biTaiga
Definition: BiomeDef.h:27
@ biDesertM
Definition: BiomeDef.h:78
@ biSavannaPlateau
Definition: BiomeDef.h:63
@ biMesaPlateauM
Definition: BiomeDef.h:97
@ biColdTaigaM
Definition: BiomeDef.h:89
@ biSwampland
Definition: BiomeDef.h:28
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
Definition: Globals.h:231
int NoCaseCompare(const AString &s1, const AString &s2)
Case-insensitive string comparison.
std::string AString
Definition: StringUtils.h:11