Implements plugin: channel-safely v0.3

develop
Josh Cooper 2022-11-06 12:04:01 -08:00
parent 3a6205d19e
commit b7ee01108e
1 changed files with 23 additions and 26 deletions

@ -209,33 +209,30 @@ namespace CSP {
} }
void JobCompletedEvent(color_ostream &out, void* job_ptr) { void JobCompletedEvent(color_ostream &out, void* job_ptr) {
if (config.monitor_active) { if (enabled && World::isFortressMode() && Maps::IsValid()) {
INFO(monitor).print("JobCompletedEvent()\n"); INFO(monitor).print("JobCompletedEvent()\n");
if (enabled && World::isFortressMode() && Maps::IsValid()) { auto job = (df::job*) job_ptr;
auto job = (df::job*) job_ptr; // we only care if the job is a channeling one
// we only care if the job is a channeling one if (is_dig_job(job)) {
if (is_dig_job(job)) { // untrack job/worker
// untrack job/worker active_workers.erase(job->id);
active_workers.erase(job->id); // check job outcome
// check job outcome df::coord local(job->pos);
df::coord local(job->pos); auto block = Maps::getTileBlock(local);
auto block = Maps::getTileBlock(local); local.x = local.x % 16;
local.x = local.x % 16; local.y = local.y % 16;
local.y = local.y % 16; // verify completion
// verify completion if (isOpenTerrain(block->tiletype[local.x][local.y])
if (isOpenTerrain(block->tiletype[local.x][local.y]) || block->designation[local.x][local.y].bits.dig != df::enums::tile_dig_designation::Channel) {
|| block->designation[local.x][local.y].bits.dig != df::enums::tile_dig_designation::Channel) { // the job can be considered done
// the job can be considered done df::coord below(job->pos);
df::coord below(job->pos); below.z--;
below.z--; WARN(monitor).print(" -> Marking tile done and managing the group below.\n");
WARN(monitor).print(" -> Marking tile done and managing the group below.\n"); // mark done and manage below
// mark done and manage below Maps::getTileDesignation(job->pos)->bits.traffic = df::tile_traffic::Normal;
Maps::getTileDesignation(job->pos)->bits.traffic = df::tile_traffic::Normal; ChannelManager::Get().mark_done(job->pos);
ChannelManager::Get().mark_done(job->pos); ChannelManager::Get().manage_group(below);
ChannelManager::Get().manage_group(below); ChannelManager::Get().debug();
ChannelManager::Get().debug();
Job::removeJob(job);
}
} }
} }
INFO(monitor).print("JobCompletedEvent() exits\n"); INFO(monitor).print("JobCompletedEvent() exits\n");