Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TileManager.cxx
Go to the documentation of this file.
1 #include "TileManager.hxx"
2 
3 #include "LOG.hxx"
4 #include "Exception.hxx"
5 #include "basics/Settings.hxx"
6 #include "ResourcesManager.hxx"
7 #include "Filesystem.hxx"
8 #include "tileData.hxx"
9 #include "../services/Randomizer.hxx"
10 
11 #include <bitset>
12 
14 
16 
17 SDL_Texture *TileManager::getTexture(const std::string &tileID) const
18 {
20 }
21 
23 {
24  if (m_tileData.count(id))
25  return &m_tileData[id];
26  return nullptr;
27 }
28 
29 std::vector<std::string> TileManager::getAllTileIDsForZone(ZoneType zone, ZoneDensity zoneDensity, TileSize tileSize)
30 {
31  std::vector<std::string> results;
32  for (auto &tileData : m_tileData)
33  {
34  if (std::find(tileData.second.zoneTypes.begin(), tileData.second.zoneTypes.end(), +zone) != tileData.second.zoneTypes.end() &&
35  (zone == +ZoneType::AGRICULTURAL || std::find(tileData.second.zoneDensity.begin(), tileData.second.zoneDensity.end(),
36  +zoneDensity) != tileData.second.zoneDensity.end()) &&
37  tileData.second.RequiredTiles.height == tileSize.height && tileData.second.RequiredTiles.width == tileSize.width &&
38  tileData.second.tileType != +TileType::ZONE)
39  {
40  results.push_back(tileData.first);
41  }
42  }
43  return results;
44 }
45 
46 std::vector<Point> TileManager::getTargetCoordsOfTileID(const Point &targetCoordinates, const std::string &tileID)
47 {
48  std::vector<Point> occupiedCoords;
49  TileData *tileData = getTileData(tileID);
50 
51  if (!tileData)
52  {
53  return occupiedCoords;
54  }
55 
56  for (int i = 0; i < tileData->RequiredTiles.width; i++)
57  {
58  for (int j = 0; j < tileData->RequiredTiles.height; j++)
59  {
60  Point coords = {targetCoordinates.x - i, targetCoordinates.y + j};
61  if (!coords.isWithinMapBoundaries())
62  { // boundary check
63  occupiedCoords.clear();
64  return occupiedCoords;
65  }
66  occupiedCoords.emplace_back(coords);
67  }
68  }
69  return occupiedCoords;
70 }
71 
72 std::optional<std::string> TileManager::getRandomTileIDForZoneWithRandomSize(ZoneType zone, ZoneDensity zoneDensity,
73  TileSize maxTileSize)
74 
75 {
76  std::vector<TileSize> elligibleTileSizes;
77 
78  // filter out the tilesizes that are below the maximum from all available tilesizes
79  for (auto tileSize : m_tileSizeCombinations)
80  {
81  // for now only pick square buildings. non square buildings don't work yet.
82  if (tileSize.height <= maxTileSize.height && tileSize.width <= maxTileSize.width && tileSize.height == tileSize.width)
83  {
84  elligibleTileSizes.push_back(tileSize);
85  }
86  }
87 
88  // pick a random tilesize from the new set of elligible tilesizes
89  auto &randomizer = Randomizer::instance();
90  TileSize randomTileSize = *randomizer.choose(elligibleTileSizes.begin(), elligibleTileSizes.end());
91 
92  // get all tile IDs for the according zone and tilesize
93  const auto &tileIDsForThisZone = getAllTileIDsForZone(zone, zoneDensity, randomTileSize);
94 
95  if (tileIDsForThisZone.empty())
96  {
97  return std::nullopt;
98  }
99 
100  // return a random tileID
101  return *randomizer.choose(tileIDsForThisZone.begin(), tileIDsForThisZone.end());
102 }
103 
105 {
106  Layer layer = Layer::TERRAIN;
107  TileData *tileData = TileManager::instance().getTileData(tileID);
108  if (tileData)
109  {
110  switch (tileData->tileType)
111  {
112  case TileType::TERRAIN:
113  layer = Layer::TERRAIN;
114  break;
115  case TileType::BLUEPRINT:
116  layer = Layer::BLUEPRINT;
117  break;
118  case TileType::WATER:
119  layer = Layer::WATER;
120  break;
122  layer = Layer::UNDERGROUND;
123  break;
124  case TileType::GROUNDDECORATION:
125  layer = Layer::GROUND_DECORATION;
126  break;
127  case TileType::ZONE:
128  layer = Layer::ZONE;
129  break;
130  case TileType::ROAD:
131  layer = Layer::ROAD;
132  break;
133  case TileType::POWERLINE:
134  layer = Layer::POWERLINES;
135  break;
136  case TileType::FLORA:
137  layer = Layer::FLORA;
138  break;
139  default:
140  layer = Layer::BUILDINGS;
141  break;
142  }
143  }
144  return layer;
145 }
146 
147 size_t TileManager::calculateSlopeOrientation(unsigned char bitMaskElevation)
148 {
149  // initialize with DEFAULT_ORIENTATION which elevationMask.none()
150  size_t orientation = TileSlopes::DEFAULT_ORIENTATION;
151  const std::bitset<8> elevationMask(bitMaskElevation);
152 
153  // Bits:
154  // 0 = 2^0 = 1 = TOP
155  // 1 = 2^1 = 2 = BOTTOM
156  // 2 = 2^2 = 4 = LEFT
157  // 3 = 2^3 = 8 = RIGHT
158  // 4 = 2^4 = 16 = TOP LEFT
159  // 5 = 2^5 = 32 = TOP RIGHT
160  // 6 = 2^6 = 64 = BOTTOM LEFT
161  // 7 = 2^7 = 128 = BOTTOM RIGHT
162 
163  // check for all combinations
164  if (elevationMask.test(3) && elevationMask.test(6))
165  { // BOTTOM_RIGHT
166  orientation = TileSlopes::S_AND_E;
167  }
168  else if (elevationMask.test(2) && elevationMask.test(5))
169  { // BOTTOM_RIGHT
170  orientation = TileSlopes::N_AND_W;
171  }
172  else if (elevationMask.test(3) && elevationMask.test(4))
173  { // BOTTOM_RIGHT
174  orientation = TileSlopes::N_AND_E;
175  }
176  else if (elevationMask.test(2) && elevationMask.test(7))
177  { // BOTTOM_RIGHT
178  orientation = TileSlopes::S_AND_W;
179  }
180 
181  else if (elevationMask.test(0) && elevationMask.test(6))
182  { // BOTTOM_RIGHT
183  orientation = TileSlopes::N_AND_W;
184  }
185  else if (elevationMask.test(1) && elevationMask.test(5))
186  { // BOTTOM_RIGHT
187  orientation = TileSlopes::S_AND_E;
188  }
189  else if (elevationMask.test(0) && elevationMask.test(7))
190  { // BOTTOM_RIGHT
191  orientation = TileSlopes::N_AND_E;
192  }
193  else if (elevationMask.test(1) && elevationMask.test(4))
194  { // BOTTOM_RIGHT
195  orientation = TileSlopes::S_AND_W;
196  }
197 
198  // diagonal combinations
199  else if (elevationMask.test(0) && elevationMask.test(2))
200  { // TOP && RIGHT
201  orientation = TileSlopes::N_AND_W;
202  }
203  else if (elevationMask.test(0) && elevationMask.test(3))
204  { // TOP && LEFT
205  orientation = TileSlopes::N_AND_E;
206  }
207  else if (elevationMask.test(1) && elevationMask.test(2))
208  { // BOTTOM && RIGHT
209  orientation = TileSlopes::S_AND_W;
210  }
211  else if (elevationMask.test(1) && elevationMask.test(3))
212  { // BOTTOM && LEFT
213  orientation = TileSlopes::S_AND_E;
214  }
215 
216  // default directions
217  else if (elevationMask.test(0))
218  { // TOP
219  orientation = TileSlopes::N;
220  }
221  else if (elevationMask.test(1))
222  { // BOTTOM
223  orientation = TileSlopes::S;
224  }
225  else if (elevationMask.test(2))
226  { // LEFT
227  orientation = TileSlopes::W;
228  }
229  else if (elevationMask.test(3))
230  { // RIGHT
231  orientation = TileSlopes::E;
232  }
233  else if ((elevationMask.test(4) && elevationMask.test(7)) || (elevationMask.test(5) && elevationMask.test(6)))
234  { // BOTTOM_RIGHT
235  orientation = TileSlopes::BETWEEN;
236  }
237  else if (elevationMask.test(4))
238  { // TOP_LEFT
239  orientation = TileSlopes::NW;
240  }
241  else if (elevationMask.test(5))
242  { // TOP_RIGHT
243  orientation = TileSlopes::NE;
244  }
245  else if (elevationMask.test(6))
246  { // BOTTOM_LEFT
247  orientation = TileSlopes::SW;
248  }
249  else if (elevationMask.test(7))
250  { // BOTTOM_RIGHT
251  orientation = TileSlopes::SE;
252  }
253 
254  return orientation;
255 }
256 
258 {
259  TileOrientation orientation;
260  const std::bitset<8> elevationMask(bitMaskElevation);
261 
262  // Bits:
263  // 0 = 2^0 = 1 = TOP
264  // 1 = 2^1 = 2 = BOTTOM
265  // 2 = 2^2 = 4 = LEFT
266  // 3 = 2^3 = 8 = RIGHT
267  // 4 = 2^4 = 16 = TOP LEFT
268  // 5 = 2^5 = 32 = TOP RIGHT
269  // 6 = 2^6 = 64 = BOTTOM LEFT
270  // 7 = 2^7 = 128 = BOTTOM RIGHT
271 
272  // check for all combinations
273  if (elevationMask.none())
274  { // NONE
276  }
277  // special cases
278  else if (elevationMask.test(0) && elevationMask.test(1) && elevationMask.test(2) && elevationMask.test(3))
279  { // BOTTOM_RIGHT
281  }
282  else if (elevationMask.test(0) && elevationMask.test(2) && elevationMask.test(3))
283  { // BOTTOM_RIGHT
285  }
286  else if (elevationMask.test(0) && elevationMask.test(1) && elevationMask.test(3))
287  { // BOTTOM_RIGHT
289  }
290  else if (elevationMask.test(0) && elevationMask.test(1) && elevationMask.test(2))
291  { // BOTTOM_RIGHT
293  }
294  else if (elevationMask.test(1) && elevationMask.test(2) && elevationMask.test(3))
295  { // BOTTOM_RIGHT
297  }
298  else if (elevationMask.test(2) && elevationMask.test(3))
299  { // BOTTOM_RIGHT
300  orientation = TileOrientation::TILE_E_AND_W;
301  }
302  else if (elevationMask.test(0) && elevationMask.test(1))
303  { // BOTTOM_RIGHT
304  orientation = TileOrientation::TILE_N_AND_S;
305  }
306 
307  // diagonal combinations
308  else if (elevationMask.test(0) && elevationMask.test(2))
309  { // TOP && RIGHT
310  orientation = TileOrientation::TILE_N_AND_W;
311  }
312  else if (elevationMask.test(0) && elevationMask.test(3))
313  { // TOP && LEFT
314  orientation = TileOrientation::TILE_N_AND_E;
315  }
316  else if (elevationMask.test(1) && elevationMask.test(2))
317  { // BOTTOM && RIGHT
318  orientation = TileOrientation::TILE_S_AND_W;
319  }
320  else if (elevationMask.test(1) && elevationMask.test(3))
321  { // BOTTOM && LEFT
322  orientation = TileOrientation::TILE_S_AND_E;
323  }
324 
325  // default directions
326  else if (elevationMask.test(0))
327  { // TOP
328  orientation = TileOrientation::TILE_N;
329  }
330  else if (elevationMask.test(1))
331  { // BOTTOM
332  orientation = TileOrientation::TILE_S;
333  }
334  else if (elevationMask.test(2))
335  { // LEFT
336  orientation = TileOrientation::TILE_W;
337  }
338  else if (elevationMask.test(3))
339  { // RIGHT
340  orientation = TileOrientation::TILE_E;
341  }
342 
343  else
344  {
345  orientation = TILE_DEFAULT_ORIENTATION;
346  }
347  return orientation;
348 }
349 
351 {
352  std::string jsonFile = fs::readFileAsString(Settings::instance().tileDataJSONFile.get());
353  const json tileDataJSON = json::parse(jsonFile, nullptr, false);
354 
355  // check if json file can be parsed
356  if (tileDataJSON.is_discarded())
357  throw ConfigurationError(TRACE_INFO "Error parsing JSON File " + Settings::instance().tileDataJSONFile.get());
358 
359  std::string key;
360 
361  size_t idx = 0;
362 
363  for (const auto &element : tileDataJSON.items())
364  {
365  std::string id;
366  id = element.value().value("id", "");
367  addJSONObjectToTileData(tileDataJSON, idx, id);
368  idx++;
369  }
370 }
371 
372 void TileManager::addJSONObjectToTileData(const nlohmann::json &tileDataJSON, size_t idx, const std::string &id)
373 {
374  m_tileData[id].author = tileDataJSON[idx].value("author", "");
375  m_tileData[id].title = tileDataJSON[idx].value("title", "");
376  m_tileData[id].description = tileDataJSON[idx].value("description", "");
377  m_tileData[id].category = tileDataJSON[idx].value("category", "");
378  m_tileData[id].subCategory = tileDataJSON[idx].value("subCategory", "");
379  m_tileData[id].price = tileDataJSON[idx].value("price", 0);
380  m_tileData[id].power = tileDataJSON[idx].value("power", 0);
381  m_tileData[id].water = tileDataJSON[idx].value("water", 0);
382  m_tileData[id].upkeepCost = tileDataJSON[idx].value("upkeepCost", 0);
383  m_tileData[id].isOverPlacable = tileDataJSON[idx].value("isOverPlacable", false);
384  m_tileData[id].placeOnWater = tileDataJSON[idx].value("placeOnWater", false);
385  m_tileData[id].inhabitants = tileDataJSON[idx].value("inhabitants", 0);
386  m_tileData[id].happiness = tileDataJSON[idx].value("happiness", 0);
387  m_tileData[id].fireHazardLevel = tileDataJSON[idx].value("fireHazardLevel", 0);
388  m_tileData[id].educationLevel = tileDataJSON[idx].value("educationLevel", 0);
389  m_tileData[id].crimeLevel = tileDataJSON[idx].value("crimeLevel", 0);
390  m_tileData[id].pollutionLevel = tileDataJSON[idx].value("pollutionLevel", 0);
391 
392  std::string tileTypeStr = tileDataJSON[idx].value("tileType", "default");
393 
394  if (TileType::_is_valid_nocase(tileTypeStr.c_str()))
395  {
396  m_tileData[id].tileType = TileType::_from_string_nocase(tileTypeStr.c_str());
397  }
398  else
399  {
400  throw ConfigurationError(TRACE_INFO "In TileData.json in field with ID " + id +
401  " the field tileType uses the unsupported value " + tileTypeStr);
402  }
403 
404  if (tileDataJSON[idx].find("zoneDensity") != tileDataJSON[idx].end())
405  {
406  for (auto zoneDensity : tileDataJSON[idx].at("zoneDensity").items())
407  {
408  if (ZoneDensity::_is_valid_nocase(zoneDensity.value().get<std::string>().c_str()))
409  {
410  m_tileData[id].zoneDensity.push_back(ZoneDensity::_from_string_nocase(zoneDensity.value().get<std::string>().c_str()));
411  }
412  else
413  {
414  throw ConfigurationError(TRACE_INFO "In TileData.json in field with ID " + id +
415  " the field zoneDensity uses the unsupported value " + zoneDensity.value().get<std::string>());
416  }
417  }
418  }
419 
420  if (tileDataJSON[idx].find("zoneType") != tileDataJSON[idx].end())
421  {
422  for (auto zoneType : tileDataJSON[idx].at("zoneType").items())
423  {
424  if (ZoneType::_is_valid_nocase(zoneType.value().get<std::string>().c_str()))
425  {
426  m_tileData[id].zoneTypes.push_back(ZoneType::_from_string_nocase(zoneType.value().get<std::string>().c_str()));
427  }
428  else
429  {
430  throw ConfigurationError(TRACE_INFO "In TileData.json in field with ID " + id +
431  " the field zone uses the unsupported value " + zoneType.value().get<std::string>());
432  }
433  }
434  }
435 
436  if (tileDataJSON[idx].find("style") != tileDataJSON[idx].end())
437  {
438  for (auto style : tileDataJSON[idx].at("style").items())
439  {
440  if (Style::_is_valid_nocase(style.value().get<std::string>().c_str()))
441  {
442  m_tileData[id].style.push_back(Style::_from_string_nocase(style.value().get<std::string>().c_str()));
443  }
444  else
445  {
446  throw ConfigurationError(TRACE_INFO "In TileData.json in field with ID " + id +
447  " the field style uses the unsupported value " + style.value().get<std::string>());
448  }
449  }
450  }
451 
452  if (tileDataJSON[idx].find("biomes") != tileDataJSON[idx].end())
453  {
454  for (auto biome : tileDataJSON[idx].at("biomes").items())
455  {
456  m_tileData[id].biomes.push_back(biome.value().get<std::string>());
457  }
458  }
459 
460  if (tileDataJSON[idx].find("groundDecoration") != tileDataJSON[idx].end())
461  {
462  for (auto groundDecoration : tileDataJSON[idx].at("groundDecoration").items())
463  {
464  m_tileData[id].groundDecoration.push_back(groundDecoration.value().get<std::string>());
465  }
466  }
467 
468  if (tileDataJSON[idx].find("RequiredTiles") != tileDataJSON[idx].end())
469  {
470  m_tileData[id].RequiredTiles.width = tileDataJSON[idx]["RequiredTiles"].value("width", 1);
471  m_tileData[id].RequiredTiles.height = tileDataJSON[idx]["RequiredTiles"].value("height", 1);
472  }
473  else
474  {
475  m_tileData[id].RequiredTiles.width = 1;
476  m_tileData[id].RequiredTiles.height = 1;
477  }
478 
479  m_tileSizeCombinations.insert(m_tileData[id].RequiredTiles);
480 
481  m_tileData[id].tiles.fileName = tileDataJSON[idx]["tiles"].value("fileName", "");
482  m_tileData[id].tiles.clippingHeight = tileDataJSON[idx]["tiles"].value("clip_height", 0);
483  m_tileData[id].tiles.clippingWidth = tileDataJSON[idx]["tiles"].value("clip_width", 0);
484 
485  // offset value can be negative in the json, for the tiledata editor, but never in Cytopia
486  int offset = tileDataJSON[idx]["tiles"].value("offset", 0);
487  if (offset < 0)
488  {
489  offset = 0;
490  }
491  m_tileData[id].tiles.offset = offset;
492  m_tileData[id].tiles.count = tileDataJSON[idx]["tiles"].value("count", 1);
493  m_tileData[id].tiles.pickRandomTile = tileDataJSON[idx]["tiles"].value("pickRandomTile", true);
494 
495  if (!m_tileData[id].tiles.fileName.empty())
496  {
497  ResourcesManager::instance().loadTexture(id, m_tileData[id].tiles.fileName);
498  }
499 
500  if (tileDataJSON[idx].find("shoreLine") != tileDataJSON[idx].end())
501  {
502  m_tileData[id].shoreTiles.fileName = tileDataJSON[idx]["shoreLine"].value("fileName", "");
503  m_tileData[id].shoreTiles.count = tileDataJSON[idx]["shoreLine"].value("count", 1);
504  m_tileData[id].shoreTiles.clippingWidth = tileDataJSON[idx]["shoreLine"].value("clip_width", 0);
505  m_tileData[id].shoreTiles.clippingHeight = tileDataJSON[idx]["shoreLine"].value("clip_height", 0);
506 
507  // offset value can be negative in the json, for the tiledata editor, but never in Cytopia
508  int offset = tileDataJSON[idx]["shoreLine"].value("offset", 0);
509  if (offset < 0)
510  {
511  offset = 0;
512  }
513  m_tileData[id].shoreTiles.offset = offset;
514 
515  if (!m_tileData[id].shoreTiles.fileName.empty())
516  {
517  ResourcesManager::instance().loadTexture(id + "_shore", m_tileData[id].shoreTiles.fileName);
518  }
519  }
520 
521  if (tileDataJSON[idx].find("slopeTiles") != tileDataJSON[idx].end())
522  {
523 
524  m_tileData[id].slopeTiles.fileName = tileDataJSON[idx]["slopeTiles"].value("fileName", "");
525  m_tileData[id].slopeTiles.count = tileDataJSON[idx]["slopeTiles"].value("count", 1);
526  m_tileData[id].slopeTiles.clippingWidth = tileDataJSON[idx]["slopeTiles"].value("clip_width", 0);
527  m_tileData[id].slopeTiles.clippingHeight = tileDataJSON[idx]["slopeTiles"].value("clip_height", 0);
528 
529  // offset value can be negative in the json, for the tiledata editor, but never in Cytopia
530  int offset = tileDataJSON[idx]["slopeTiles"].value("offset", 0);
531  if (offset < 0)
532  {
533  offset = 0;
534  }
535  m_tileData[id].slopeTiles.offset = offset;
536 
537  if (!m_tileData[id].slopeTiles.fileName.empty())
538  {
539  ResourcesManager::instance().loadTexture(id, m_tileData[id].slopeTiles.fileName);
540  }
541  }
542 }
543 
545 {
546  TileData *tileData = getTileData(tileID);
547  if (tileData)
548  switch (tileData->tileType)
549  {
550  case +TileType::ROAD:
551  case +TileType::AUTOTILE:
552  case +TileType::UNDERGROUND:
553  case +TileType::POWERLINE:
554  return true;
555  default:
556  return false;
557  }
558 
559  return false;
560 }
TRACE_INFO
#define TRACE_INFO
Definition: Exception.hxx:12
ConfigurationError
A configuration error.
Definition: Exception.hxx:36
tileData.hxx
TileSize::height
unsigned int height
Definition: tileData.hxx:89
TileManager::calculateTileOrientation
TileOrientation calculateTileOrientation(unsigned char bitMaskElevation)
Calculates the TileOrientation for elevated tiles to pick the correct Sprite.
Definition: TileManager.cxx:257
WATER
@ WATER
6- Water tiles
Definition: enums.hxx:17
TileData::tileType
TileType tileType
Definition: tileData.hxx:149
TILE_S
@ TILE_S
Definition: TileManager.hxx:51
TileManager::getAllTileIDsForZone
std::vector< std::string > getAllTileIDsForZone(ZoneType zone, ZoneDensity zoneDensity, TileSize tileSize={1, 1})
Get the All Tile IDs for a zone with a certain tileSize.
Definition: TileManager.cxx:29
TILE_N_AND_W
@ TILE_N_AND_W
Definition: TileManager.hxx:49
TileManager.hxx
TILE_ALL_DIRECTIONS
@ TILE_ALL_DIRECTIONS
Definition: TileManager.hxx:58
ResourcesManager::getTileTexture
SDL_Texture * getTileTexture(const std::string &id)
Definition: ResourcesManager.cxx:59
TileManager::getTargetCoordsOfTileID
std::vector< Point > getTargetCoordsOfTileID(const Point &targetCoordinates, const std::string &tileID)
Return a vector of Points on a target node (origin corner) that would be occupied by a given tileID i...
Definition: TileManager.cxx:46
TILE_N
@ TILE_N
Definition: TileManager.hxx:45
json
nlohmann::json json
Definition: TileManager.cxx:13
LOG.hxx
POWERLINES
@ POWERLINES
9- Powerlines
Definition: enums.hxx:20
TileManager::TileManager
TileManager()
Definition: TileManager.cxx:15
TILE_S_AND_E_AND_W
@ TILE_S_AND_E_AND_W
Definition: TileManager.hxx:56
BETWEEN
@ BETWEEN
Definition: TileManager.hxx:37
SW
@ SW
Definition: TileManager.hxx:31
TileSize
How many tiles are occupied by a building.
Definition: tileData.hxx:86
TileManager::calculateSlopeOrientation
size_t calculateSlopeOrientation(unsigned char bitMaskElevation)
Calculates the slope orientation for elevated tiles to pick the correct slope Sprite.
Definition: TileManager.cxx:147
W
@ W
Definition: TileManager.hxx:26
TILE_E
@ TILE_E
Definition: TileManager.hxx:44
TILE_N_AND_E
@ TILE_N_AND_E
Definition: TileManager.hxx:46
TILE_E_AND_W
@ TILE_E_AND_W
Definition: TileManager.hxx:48
Point::y
int y
The y coordinate.
Definition: Point.hxx:20
Point::x
int x
The x coordinate.
Definition: Point.hxx:14
TileManager::getRandomTileIDForZoneWithRandomSize
std::optional< std::string > getRandomTileIDForZoneWithRandomSize(ZoneType zone, ZoneDensity zoneDensity, TileSize maxTileSize={1, 1})
Pick a single random tileID for a zone with a random tilesize within the supplied max Size.
Definition: TileManager.cxx:72
readFileAsString
std::string readFileAsString(const std::string &fileName, bool binaryMode)
Read contents from a file as string.
Definition: Filesystem.cxx:12
S_AND_W
@ S_AND_W
Definition: TileManager.hxx:35
TileManager::m_tileData
std::unordered_map< std::string, TileData > m_tileData
Definition: TileManager.hxx:153
ZONE
@ ZONE
4- Optional layer, zones(Industrial/Residential/Commercial).
Definition: enums.hxx:15
BLUEPRINT
@ BLUEPRINT
1- Optional layer - Map Blueprint
Definition: enums.hxx:12
N_AND_W
@ N_AND_W
Definition: TileManager.hxx:33
BUILDINGS
@ BUILDINGS
8- Buildings, Streets and everything that goes on the terrain
Definition: enums.hxx:19
TileManager::getTileLayer
Layer getTileLayer(const std::string &tileID) const
Get the Layer that is associated with a tileID. The Tile will be placed on this layer.
Definition: TileManager.cxx:104
TILE_S_AND_E
@ TILE_S_AND_E
Definition: TileManager.hxx:52
TILE_N_AND_S_AND_W
@ TILE_N_AND_S_AND_W
Definition: TileManager.hxx:57
Point::isWithinMapBoundaries
bool isWithinMapBoundaries() const
Definition: Point.hxx:37
DEFAULT_ORIENTATION
@ DEFAULT_ORIENTATION
Definition: TileManager.hxx:38
NE
@ NE
Definition: TileManager.hxx:30
ResourcesManager.hxx
TileManager::m_tileSizeCombinations
std::unordered_set< TileSize > m_tileSizeCombinations
Definition: TileManager.hxx:154
Filesystem.hxx
TileManager::getTexture
SDL_Texture * getTexture(const std::string &tileID) const
Get the Texture for the tileID.
Definition: TileManager.cxx:17
E
@ E
Definition: TileManager.hxx:27
Settings.hxx
TileManager::init
void init()
Parse the tileData JSON and set up the tileManager.
Definition: TileManager.cxx:350
TileData::RequiredTiles
TileSize RequiredTiles
How many tiles this building uses.
Definition: tileData.hxx:173
FLORA
@ FLORA
10- Trees and other flora/Fauna tiles
Definition: enums.hxx:21
TileManager::getTileData
TileData * getTileData(const std::string &id) noexcept
Get the TileData struct for this tileID and all information associated with it.
Definition: TileManager.cxx:22
N_AND_E
@ N_AND_E
Definition: TileManager.hxx:34
TERRAIN
@ TERRAIN
3- Terrain tiles, decorations, ... - must always be a "full" tile
Definition: enums.hxx:14
TileOrientation
TileOrientation
Definition: TileManager.hxx:41
TILE_S_AND_W
@ TILE_S_AND_W
Definition: TileManager.hxx:55
TILE_W
@ TILE_W
Definition: TileManager.hxx:47
ROAD
@ ROAD
5- Optional layer, roads.
Definition: enums.hxx:16
SE
@ SE
Definition: TileManager.hxx:32
TILE_N_AND_S
@ TILE_N_AND_S
Definition: TileManager.hxx:53
ResourcesManager::loadTexture
void loadTexture(const std::string &id, const std::string &fileName)
Definition: ResourcesManager.cxx:20
Point
Definition: Point.hxx:7
TileManager::isTileIDAutoTile
bool isTileIDAutoTile(const std::string &tileID)
check if given TileID can autotile (meaning there are textures that look differently according to the...
Definition: TileManager.cxx:544
GROUND_DECORATION
@ GROUND_DECORATION
13- Decoration to place beneath buildings. Like concrete or grass
Definition: enums.hxx:24
NW
@ NW
Definition: TileManager.hxx:29
Singleton< ResourcesManager >::instance
static ResourcesManager & instance(void)
Get an instance of the singleton.
Definition: Singleton.hxx:15
Exception.hxx
S
@ S
Definition: TileManager.hxx:28
N
@ N
Definition: TileManager.hxx:25
TileManager::addJSONObjectToTileData
void addJSONObjectToTileData(const nlohmann::json &tileDataJSON, size_t idx, const std::string &id)
Definition: TileManager.cxx:372
Layer
Layer
All Layers we have.
Definition: enums.hxx:9
S_AND_E
@ S_AND_E
Definition: TileManager.hxx:36
json
nlohmann::json json
Definition: Settings.hxx:12
string
std::string string
Definition: AudioConfig.hxx:14
UNDERGROUND
@ UNDERGROUND
2- Optional layer - Pipes, Subway-pipes and so onn
Definition: enums.hxx:13
TILE_DEFAULT_ORIENTATION
@ TILE_DEFAULT_ORIENTATION
Definition: TileManager.hxx:43
TILE_N_AND_E_AND_S
@ TILE_N_AND_E_AND_S
Definition: TileManager.hxx:54
TILE_N_AND_E_AND_W
@ TILE_N_AND_E_AND_W
Definition: TileManager.hxx:50
TileData
Holds all releavted information to this specific tile.
Definition: tileData.hxx:135
TileSize::width
unsigned int width
Definition: tileData.hxx:88