Merge pull request #2844 from cppcooper/channel-safely

Implements plugin: channel-safely v1.2.3
develop
Myk 2023-02-08 12:37:41 -08:00 committed by GitHub
commit 44428bc06c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

@ -39,6 +39,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- ``Units::isFortControlled``: Account for agitated wildlife - ``Units::isFortControlled``: Account for agitated wildlife
- Fix right click sometimes closing both a DFHack window and a vanilla panel - Fix right click sometimes closing both a DFHack window and a vanilla panel
- Fixed issue with scrollable lists having some data off-screen if they were scrolled before being made visible - Fixed issue with scrollable lists having some data off-screen if they were scrolled before being made visible
- `channel-safely`: fixed bug resulting in marker mode never being set for any designation
## Misc Improvements ## Misc Improvements
- `automelt`: is now more resistent to savegame corruption - `automelt`: is now more resistent to savegame corruption

@ -5,7 +5,17 @@
#include <modules/EventManager.h> //hash function for df::coord #include <modules/EventManager.h> //hash function for df::coord
#include <df/block_square_event_designation_priorityst.h> #include <df/block_square_event_designation_priorityst.h>
#define NUMARGS(...) std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value
#define d_assert(condition, ...) \
static_assert(NUMARGS(__VA_ARGS__) >= 1, "d_assert(condition, format, ...) requires at least up to format as arguments"); \
if (!condition) { \
DFHack::Core::getInstance().getConsole().printerr(__VA_ARGS__); \
assert(0); \
}
df::unit* find_dwarf(const df::coord &map_pos) { df::unit* find_dwarf(const df::coord &map_pos) {
df::unit* nearest = nullptr; df::unit* nearest = nullptr;
uint32_t distance; uint32_t distance;
for (auto unit : df::global::world->units.active) { for (auto unit : df::global::world->units.active) {
@ -57,6 +67,7 @@ void ChannelManager::manage_group(const Group &group, bool set_marker_mode, bool
// cavein prevention // cavein prevention
bool cavein_possible = false; bool cavein_possible = false;
uint8_t least_access = 100; uint8_t least_access = 100;
std::unordered_map<df::coord, uint8_t> cavein_candidates; std::unordered_map<df::coord, uint8_t> cavein_candidates;
if (!marker_mode) { if (!marker_mode) {
/* To prevent cave-ins we're looking at accessibility of tiles with open space below them /* To prevent cave-ins we're looking at accessibility of tiles with open space below them
@ -111,7 +122,7 @@ void ChannelManager::manage_group(const Group &group, bool set_marker_mode, bool
// if no cave-in is possible [or we don't check for], we'll just execute normally and move on // if no cave-in is possible [or we don't check for], we'll just execute normally and move on
if (!cavein_possible) { if (!cavein_possible) {
TRACE(manager).print("cave-in evaluated false\n"); TRACE(manager).print("cave-in evaluated false\n");
assert(manage_one(pos, true, marker_mode)); d_assert(manage_one(pos, true, marker_mode), "manage_one() is failing under !cavein");
continue; continue;
} }
// cavein is only possible if marker_mode is false // cavein is only possible if marker_mode is false
@ -136,16 +147,16 @@ void ChannelManager::manage_group(const Group &group, bool set_marker_mode, bool
evT->priority[Coord(local)] = v; evT->priority[Coord(local)] = v;
} }
} }
assert(manage_one(pos, true, false)); d_assert(manage_one(pos, true, false), "manage_one() is failing for cavein ");
continue; continue;
} }
// cavein possible, but we failed to meet the criteria for activation // cavein possible, but we failed to meet the criteria for activation
if (cavein_candidates.count(pos)) { if (cavein_candidates.count(pos)) {
DEBUG(manager).print("cave-in evaluated true and no dignow and (%d > %d)\n", cavein_candidates[pos], least_access+OFFSET); DEBUG(manager).print("cave-in evaluated true and the cavein candidate's accessibility check was made as (%d <= %d)\n", cavein_candidates[pos], least_access+OFFSET);
} else { } else {
DEBUG(manager).print("cave-in evaluated true and no dignow and pos is not a candidate\n"); DEBUG(manager).print("cave-in evaluated true and the position was not a candidate, nor was it set for dignow\n");
} }
assert(manage_one(pos, true, true)); d_assert(manage_one(pos, true, true), "manage_one() is failing to set a cave-in causing designation to marker mode");
} }
INFO(manager).print("manage_group() is done\n"); INFO(manager).print("manage_group() is done\n");
} }