9 #include "../services/Randomizer.hxx"
24 if (m_tileData.count(
id))
25 return &m_tileData[id];
31 std::vector<std::string> results;
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 &&
40 results.push_back(tileData.first);
48 std::vector<Point> occupiedCoords;
53 return occupiedCoords;
60 Point coords = {targetCoordinates.
x - i, targetCoordinates.
y + j};
63 occupiedCoords.clear();
64 return occupiedCoords;
66 occupiedCoords.emplace_back(coords);
69 return occupiedCoords;
76 std::vector<TileSize> elligibleTileSizes;
82 if (tileSize.height <= maxTileSize.
height && tileSize.width <= maxTileSize.
width && tileSize.height == tileSize.width)
84 elligibleTileSizes.push_back(tileSize);
90 TileSize randomTileSize = *randomizer.choose(elligibleTileSizes.begin(), elligibleTileSizes.end());
95 if (tileIDsForThisZone.empty())
101 return *randomizer.choose(tileIDsForThisZone.begin(), tileIDsForThisZone.end());
124 case TileType::GROUNDDECORATION:
133 case TileType::POWERLINE:
151 const std::bitset<8> elevationMask(bitMaskElevation);
164 if (elevationMask.test(3) && elevationMask.test(6))
168 else if (elevationMask.test(2) && elevationMask.test(5))
172 else if (elevationMask.test(3) && elevationMask.test(4))
176 else if (elevationMask.test(2) && elevationMask.test(7))
181 else if (elevationMask.test(0) && elevationMask.test(6))
185 else if (elevationMask.test(1) && elevationMask.test(5))
189 else if (elevationMask.test(0) && elevationMask.test(7))
193 else if (elevationMask.test(1) && elevationMask.test(4))
199 else if (elevationMask.test(0) && elevationMask.test(2))
203 else if (elevationMask.test(0) && elevationMask.test(3))
207 else if (elevationMask.test(1) && elevationMask.test(2))
211 else if (elevationMask.test(1) && elevationMask.test(3))
217 else if (elevationMask.test(0))
221 else if (elevationMask.test(1))
225 else if (elevationMask.test(2))
229 else if (elevationMask.test(3))
233 else if ((elevationMask.test(4) && elevationMask.test(7)) || (elevationMask.test(5) && elevationMask.test(6)))
237 else if (elevationMask.test(4))
241 else if (elevationMask.test(5))
245 else if (elevationMask.test(6))
249 else if (elevationMask.test(7))
260 const std::bitset<8> elevationMask(bitMaskElevation);
273 if (elevationMask.none())
278 else if (elevationMask.test(0) && elevationMask.test(1) && elevationMask.test(2) && elevationMask.test(3))
282 else if (elevationMask.test(0) && elevationMask.test(2) && elevationMask.test(3))
286 else if (elevationMask.test(0) && elevationMask.test(1) && elevationMask.test(3))
290 else if (elevationMask.test(0) && elevationMask.test(1) && elevationMask.test(2))
294 else if (elevationMask.test(1) && elevationMask.test(2) && elevationMask.test(3))
298 else if (elevationMask.test(2) && elevationMask.test(3))
302 else if (elevationMask.test(0) && elevationMask.test(1))
308 else if (elevationMask.test(0) && elevationMask.test(2))
312 else if (elevationMask.test(0) && elevationMask.test(3))
316 else if (elevationMask.test(1) && elevationMask.test(2))
320 else if (elevationMask.test(1) && elevationMask.test(3))
326 else if (elevationMask.test(0))
330 else if (elevationMask.test(1))
334 else if (elevationMask.test(2))
338 else if (elevationMask.test(3))
353 const json tileDataJSON = json::parse(jsonFile,
nullptr,
false);
356 if (tileDataJSON.is_discarded())
363 for (
const auto &element : tileDataJSON.items())
366 id = element.value().value(
"id",
"");
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);
392 std::string tileTypeStr = tileDataJSON[idx].value(
"tileType",
"default");
394 if (TileType::_is_valid_nocase(tileTypeStr.c_str()))
396 m_tileData[id].tileType = TileType::_from_string_nocase(tileTypeStr.c_str());
401 " the field tileType uses the unsupported value " + tileTypeStr);
404 if (tileDataJSON[idx].find(
"zoneDensity") != tileDataJSON[idx].end())
406 for (
auto zoneDensity : tileDataJSON[idx].at(
"zoneDensity").items())
408 if (ZoneDensity::_is_valid_nocase(zoneDensity.value().get<
std::string>().c_str()))
410 m_tileData[id].zoneDensity.push_back(ZoneDensity::_from_string_nocase(zoneDensity.value().get<
std::string>().c_str()));
415 " the field zoneDensity uses the unsupported value " + zoneDensity.value().get<
std::string>());
420 if (tileDataJSON[idx].find(
"zoneType") != tileDataJSON[idx].end())
422 for (
auto zoneType : tileDataJSON[idx].at(
"zoneType").items())
424 if (ZoneType::_is_valid_nocase(zoneType.value().get<
std::string>().c_str()))
426 m_tileData[id].zoneTypes.push_back(ZoneType::_from_string_nocase(zoneType.value().get<
std::string>().c_str()));
431 " the field zone uses the unsupported value " + zoneType.value().get<
std::string>());
436 if (tileDataJSON[idx].find(
"style") != tileDataJSON[idx].end())
438 for (
auto style : tileDataJSON[idx].at(
"style").items())
440 if (Style::_is_valid_nocase(style.value().get<
std::string>().c_str()))
442 m_tileData[id].style.push_back(Style::_from_string_nocase(style.value().get<
std::string>().c_str()));
447 " the field style uses the unsupported value " + style.value().get<
std::string>());
452 if (tileDataJSON[idx].find(
"biomes") != tileDataJSON[idx].end())
454 for (
auto biome : tileDataJSON[idx].at(
"biomes").items())
460 if (tileDataJSON[idx].find(
"groundDecoration") != tileDataJSON[idx].end())
462 for (
auto groundDecoration : tileDataJSON[idx].at(
"groundDecoration").items())
468 if (tileDataJSON[idx].find(
"RequiredTiles") != tileDataJSON[idx].end())
470 m_tileData[id].RequiredTiles.width = tileDataJSON[idx][
"RequiredTiles"].value(
"width", 1);
471 m_tileData[id].RequiredTiles.height = tileDataJSON[idx][
"RequiredTiles"].value(
"height", 1);
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);
486 int offset = tileDataJSON[idx][
"tiles"].value(
"offset", 0);
492 m_tileData[id].tiles.count = tileDataJSON[idx][
"tiles"].value(
"count", 1);
493 m_tileData[id].tiles.pickRandomTile = tileDataJSON[idx][
"tiles"].value(
"pickRandomTile",
true);
500 if (tileDataJSON[idx].find(
"shoreLine") != tileDataJSON[idx].end())
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);
508 int offset = tileDataJSON[idx][
"shoreLine"].value(
"offset", 0);
515 if (!
m_tileData[
id].shoreTiles.fileName.empty())
521 if (tileDataJSON[idx].find(
"slopeTiles") != tileDataJSON[idx].end())
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);
530 int offset = tileDataJSON[idx][
"slopeTiles"].value(
"offset", 0);
537 if (!
m_tileData[
id].slopeTiles.fileName.empty())
551 case +TileType::AUTOTILE:
553 case +TileType::POWERLINE: