Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Template for new versions:
- ``Random`` module: added ``SplitmixRNG`` class, implements the Splitmix64 RNG used by Dwarf Fortress for "simple" randomness
- ``Items::getDescription``: fixed display of quality levels, now displays ALL item designations (in correct order) and obeys vanilla SHOW_IMP_QUALITY setting
- ``cuboid::forCoord``, ``Maps::forCoord``: take additional parameter to control whether iteration goes in column major or row major order
- ``SC_NEW_MAP_AVAILABLE`` introduced to allow callbacks when moving between map tiles in adventure mode
- ``World::GetCurrentSiteIdsWithExtraRange`` added to check for valid sites with added range when in adventure mode

## Lua
- ``script-manager``: new ``get_active_mods()`` function for getting information on active mods
Expand Down
10 changes: 9 additions & 1 deletion library/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ static void sc_event_map_init() {
insert(SC_VIEWSCREEN_CHANGED);
insert(SC_PAUSED);
insert(SC_UNPAUSED);
insert(SC_NEW_MAP_AVAILABLE);
#undef insert
}
}
Expand Down Expand Up @@ -2044,8 +2045,11 @@ void Core::doUpdate(color_ostream &out)
onStateChange(out, SC_MAP_UNLOADED);
// and if the world is appearing, we report map change after that
onStateChange(out, new_wdata ? SC_WORLD_LOADED : SC_WORLD_UNLOADED);
if(isMapLoaded())
if (isMapLoaded())
{
onStateChange(out, SC_MAP_LOADED);
onStateChange(out, SC_NEW_MAP_AVAILABLE);
}
}
// otherwise just check for map change...
else if (new_mapdata != last_local_map_ptr)
Expand All @@ -2057,6 +2061,10 @@ void Core::doUpdate(color_ostream &out)
{
onStateChange(out, new_mapdata ? SC_MAP_LOADED : SC_MAP_UNLOADED);
}
if (isMapLoaded())
{
onStateChange(out, SC_NEW_MAP_AVAILABLE);
}
}

if (vs_changed)
Expand Down
3 changes: 2 additions & 1 deletion library/include/CoreDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace DFHack
SC_CORE_INITIALIZED = 5,
SC_BEGIN_UNLOAD = 6,
SC_PAUSED = 7,
SC_UNPAUSED = 8
SC_UNPAUSED = 8,
SC_NEW_MAP_AVAILABLE = 9
};

}
1 change: 1 addition & 0 deletions library/include/modules/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace DFHack
DFHACK_EXPORT df::unit * getAdventurer();

DFHACK_EXPORT int32_t GetCurrentSiteId();
DFHACK_EXPORT void GetCurrentSiteIdsWithExtraRange(std::vector<int32_t>& ids, const int32_t x_range = 0, const int32_t y_range = 0, const uint32_t max = UINT_MAX);
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be documented in docs/dev/Lua API.rst

DFHACK_EXPORT bool IsSiteLoaded();

// Store DFHack tool data in the game save directory.
Expand Down
29 changes: 29 additions & 0 deletions library/modules/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,35 @@ int32_t World::GetCurrentSiteId() {
return -1;
}

void World::GetCurrentSiteIdsWithExtraRange(std::vector<int32_t>& ids, const int32_t x_range, const int32_t y_range, const uint32_t max)
{
ids.clear();
if (!plotinfo || max < 1)
{
return;
}
if (isFortressMode())
{
ids.push_back(plotinfo->site_id);
}
if (auto adv = getAdventurer(); adv && world->world_data) {
auto& world_map = world->map;
auto adv_pos = Units::getPosition(adv);
df::coord2d rgn_pos(world_map.region_x + adv_pos.x / 48, world_map.region_y + adv_pos.y / 48);
for (auto site : world->world_data->sites) {
if (rgn_pos.x + x_range >= site->global_min_x && rgn_pos.x - x_range <= site->global_max_x
&& rgn_pos.y + y_range >= site->global_min_y && rgn_pos.y - y_range <= site->global_max_y)
{
ids.push_back(site->id);
if (ids.size() >= max)
{
return;
}
}
}
}
}

bool World::IsSiteLoaded() {
return GetCurrentSiteId() != -1;
}
Expand Down