Repository navigation
Expand file tree
/
Copy pathBiome.cpp
More file actions
112 lines (86 loc) · 2.3 KB
/
Copy pathBiome.cpp
File metadata and controls
112 lines (86 loc) · 2.3 KB
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
#include "Biome.h"
//#define DEBUG
Biome::Biome()
{
_x = 0;
_y = 0;
_id = 0;
_temperature = 0;
_moisture = 0;
}
Biome::Biome(int x, int y, int ID)
{
_x = x;
_y = y;
_id = ID;
}
Biome::~Biome()
{
}
bool Biome::setResources(BiomeInfo b) // ERROR HANDLE HERE
{
_resources = b;
return true;
}
bool Biome::setBiomeType(int type) // FIGURE OUT A BETTER WAY TO HANDLE THIS!
{
if (type <= HEAVYSNOWFOREST)
{
_biomeType = type;
return true;
}
else return false;
}
int Biome::FindTileID() // to be later determined!
{
//BARREN,TEMPDECFOREST,PRARIE,BOREALFOREST,TUNDRA,POLAR,WARMDESERT,TROPGRASSLAND,COLDDESERT,SAVANNA,TROPDECFOREST,TROPRAINFOREST,HEAVYSNOWFOREST
return _biomeType;
}
WaterBiome::WaterBiome()
{
_moisture = 100.00f;
}
WaterBiome::WaterBiome(int x, int y)
{
_x = x;
_y = y;
_moisture = 100.0f;
}
WaterBiome::~WaterBiome()
{
//
}
bool Biome::SaveBiome(std::fstream& biomeFile) // add safety checks later
{
int strSize = 0;
short idTemp = 0;
strSize = _name.size();
idTemp = _id;
biomeFile.write((char*)&idTemp, sizeof(short));
biomeFile.write((char*)&strSize, sizeof(int));
biomeFile.write(_name.c_str(), strSize);
strSize = _biomeType;
biomeFile.write((char*)&strSize, sizeof(int));
strSize = _x;
biomeFile.write((char*)&strSize, sizeof(int));
strSize = _y;
biomeFile.write((char*)&strSize, sizeof(int));
float tempFloat = _temperature;
biomeFile.write((char*)&tempFloat, sizeof(float));
tempFloat = _moisture;
biomeFile.write((char*)&tempFloat, sizeof(float));
//biome resource write
strSize = _resources.type.size();
biomeFile.write((char*)&strSize, sizeof(int));
biomeFile.write(_resources.type.c_str(), strSize); // string and size of string
for (int re = 0; re < 5; re++) // each of the 5 contained resources
{
strSize = _resources.sources[re].name.size();
biomeFile.write((char*)&strSize, sizeof(int));
biomeFile.write(_resources.sources[re].name.c_str(), _resources.sources[re].name.size());
biomeFile.write((char *)&_resources.sources[re].currentCount, sizeof(int));
biomeFile.write((char *)&_resources.sources[re].replenishRate, sizeof(float));
biomeFile.write((char *)&_resources.sources[re].max, sizeof(int));
}
return true;
}