Skip to content
36 changes: 36 additions & 0 deletions library/include/MiscUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,42 @@ inline bool static_add_to_map(CT *pmap, typename CT::key_type key, typename CT::
/*
* MISC
*/
template<
std::ranges::input_range Range,
std::invocable<std::ostream&, std::ranges::range_reference_t<Range>> Callable>
void print_range(
std::ostream &out,
const Range &elements,
Callable&& print_element,
const std::string &prefix = "[",
const std::string &separator = ", ",
const std::string &suffix = "]"
){
out << prefix;
auto it = std::ranges::begin(elements);
auto end = std::ranges::end(elements);

if (it != end) {
print_element(out, *it);
for (++it; it != end; ++it) {
out << separator;
print_element(out, *it);
}
}
out << suffix;
}

template<std::ranges::input_range Range>
void print_range(
std::ostream &out,
const Range& elements,
const std::string &prefix = "[",
const std::string &separator = ", ",
const std::string &suffix = "]"
){
auto print_element = [](std::ostream &out, auto& e) { out << e; };
print_range(out, elements, print_element, prefix, separator, suffix);
}

DFHACK_EXPORT bool split_string(std::vector<std::string> *out,
const std::string &str, const std::string &separator,
Expand Down
2 changes: 1 addition & 1 deletion library/include/df/custom/coord2d.methods.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
coord2d(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
coord2d(int16_t _x, int16_t _y) : x(_x), y(_y) {}

bool isValid() const { return x >= 0; }
void clear() { x = y = -30000; }
Expand Down
9 changes: 9 additions & 0 deletions library/include/modules/Maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ distribution.
#include "df/flow_type.h"
#include "df/tile_dig_designation.h"
#include "df/tiletype.h"
#include "df/world_site.h"

namespace df {
struct block_square_event;
Expand Down Expand Up @@ -402,6 +403,14 @@ DFHACK_EXPORT bool removeTileAquifer(int32_t x, int32_t y, int32_t z);
inline bool removeTileAquifer(df::coord pos) { return removeTileAquifer(pos.x, pos.y, pos.z); }
DFHACK_EXPORT int removeAreaAquifer(df::coord pos1, df::coord pos2,
std::function<bool(df::coord, df::map_block *)> filter = [](df::coord pos, df::map_block *block) { return true; });


/**
* A single function does not merit a "Sites" module, hence we collect site functions here in the meantime.
*/

// Get the classification string (e.g. "town", "hillocs", "tower", etc.) for a site
DFHACK_EXPORT const char* getSiteTypeName(df::world_site *site);
}
}
#endif
86 changes: 86 additions & 0 deletions library/modules/Maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,3 +1274,89 @@ int Maps::removeAreaAquifer(df::coord pos1, df::coord pos2, std::function<bool(d

return totalAffectedCount;
}

#include "df/world_site.h"
#include "df/world_site_type.h"
#include "df/site_map_infost.h"

// reverse engineered from DF 50.13 (FUN_140d82ca0, likely sitest::get_site_type_name)
const char* Maps::getSiteTypeName(df::world_site *site) {
using wst = df::enums::world_site_type::world_site_type;
switch (site->type) {
case wst::PlayerFortress:
case wst::MountainHalls:
if (site->min_depth == 0 && (0 < site->max_depth)){
return "fortress";
}
if (site->min_depth > 0) {
return "mountain halls";
}
return "hillocks";

case wst::DarkFortress: {
bool has_market = site->flag.is_set(df::enums::site_flag_type::HAS_MARKET);
return has_market ? "fortress" : "pits";
}

case wst::Cave:
return "cave";

case wst::ForestRetreat:
return "forest retreat";

case wst::Town: {
bool has_market = site->flag.is_set(df::enums::site_flag_type::HAS_MARKET);
return has_market ? "town" : "hamlet";
}

case wst::ImportantLocation:
return "important location";

case wst::LairShrine:
if (site->subtype_info) {
switch (site->subtype_info->lair_type) {
case df::enums::lair_type::LABYRINTH:
return "labyrinth";
case df::enums::lair_type::SHRINE:
return "shrine";
default:
break;
}
}
return "lair";

case wst::Fortress:
if (site->subtype_info) {
switch (site->subtype_info->fortress_type) {
case df::enums::fortress_type::TOWER:
return "tower";
case df::enums::fortress_type::MONASTERY:
return "monastery";
case df::enums::fortress_type::FORT:
return "fort";
default:
return "castle";
}
}
return "fortress";

case wst::Camp:
return "camp";

case wst::Monument:
if (site->subtype_info) {
switch (site->subtype_info->monument_type) {
case df::enums::monument_type::TOMB:
return "tomb";
case df::enums::monument_type::VAULT:
return "vault";
default:
break;
}
}
return "monument";

default:
return "site";
}
}
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ if(BUILD_SUPPORTED)
#dfhack_plugin(dwarfmonitor dwarfmonitor.cpp LINK_LIBRARIES lua)
#add_subdirectory(embark-assistant)
dfhack_plugin(eventful eventful.cpp LINK_LIBRARIES lua)
dfhack_plugin(export-map export-map.cpp COMPILE_FLAGS_GCC -fno-gnu-unique)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is requiring -fno-gnu-unique?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably a STL template; it can be hard to figure out which one because you have to pore over the libc++ implementation and that's very timeconsuming.

-fno-gnu-unique should always be safe for DFHack plugins, as long as they don't crossload another another plug-in module

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is actually requiring this. Is what a (failed) attempt to make the plugin unload. I will have to check whether it unloads, now that I have removed the GDAL dependency. Keeping this there and the conversation open in the meantime.

dfhack_plugin(fastdwarf fastdwarf.cpp)
dfhack_plugin(filltraffic filltraffic.cpp)
dfhack_plugin(fix-occupancy fix-occupancy.cpp LINK_LIBRARIES lua)
Expand Down
Loading