Implements plugin: channel-safely v0.3.1

develop
Josh Cooper 2022-11-06 12:09:38 -08:00
parent b7ee01108e
commit a8dcfeead9
1 changed files with 51 additions and 53 deletions

@ -146,65 +146,63 @@ namespace CSP {
} }
void JobStartedEvent(color_ostream &out, void* p) { void JobStartedEvent(color_ostream &out, void* p) {
if (config.monitor_active) { if (enabled && World::isFortressMode() && Maps::IsValid()) {
if (enabled && World::isFortressMode() && Maps::IsValid()) { INFO(monitor).print("JobStartedEvent()\n");
INFO(monitor).print("JobStartedEvent()\n"); auto job = (df::job*) p;
auto job = (df::job*) p; // validate job type
// validate job type if (is_dig_job(job)) {
if (is_dig_job(job)) { DEBUG(monitor).print(" valid channel job:\n");
DEBUG(monitor).print(" valid channel job:\n"); df::unit* worker = Job::getWorker(job);
df::unit* worker = Job::getWorker(job); // there is a valid worker (living citizen) on the job? right..
// there is a valid worker (living citizen) on the job? right.. if (worker && Units::isAlive(worker) && Units::isCitizen(worker)) {
if (worker && Units::isAlive(worker) && Units::isCitizen(worker)) { DEBUG(monitor).print(" valid worker:\n");
DEBUG(monitor).print(" valid worker:\n"); df::coord local(job->pos);
df::coord local(job->pos); local.x = local.x % 16;
local.x = local.x % 16; local.y = local.y % 16;
local.y = local.y % 16; // check pathing exists to job
// check pathing exists to job if (Maps::canWalkBetween(worker->pos, job->pos)) {
if (Maps::canWalkBetween(worker->pos, job->pos)) { DEBUG(monitor).print(" can path from (" COORD ") to (" COORD ")\n",
DEBUG(monitor).print(" can path from (" COORD ") to (" COORD ")\n", COORDARGS(worker->pos), COORDARGS(job->pos));
COORDARGS(worker->pos), COORDARGS(job->pos)); // track workers on jobs
// track workers on jobs active_workers.emplace(job->id, Units::findIndexById(Job::getWorker(job)->id));
active_workers.emplace(job->id, Units::findIndexById(Job::getWorker(job)->id)); // set tile to restricted
// set tile to restricted TRACE(monitor).print(" setting job tile to restricted\n");
TRACE(monitor).print(" setting job tile to restricted\n"); Maps::getTileDesignation(job->pos)->bits.traffic = df::tile_traffic::Restricted;
Maps::getTileDesignation(job->pos)->bits.traffic = df::tile_traffic::Restricted; } else {
} else { DEBUG(monitor).print(" no path exists to job:\n");
DEBUG(monitor).print(" no path exists to job:\n"); // if we can't get there, then we should remove the worker and cancel the job (restore tile designation)
// if we can't get there, then we should remove the worker and cancel the job (restore tile designation) Job::removeWorker(job);
Job::removeWorker(job); cancel_job(job);
cancel_job(job); if (!config.insta_dig) {
if (!config.insta_dig) { TRACE(monitor).print(" setting marker mode for (" COORD ")\n", COORDARGS(job->pos));
TRACE(monitor).print(" setting marker mode for (" COORD ")\n", COORDARGS(job->pos)); // set to marker mode
// set to marker mode auto occupancy = Maps::getTileOccupancy(job->pos);
auto occupancy = Maps::getTileOccupancy(job->pos); if (!occupancy) {
if (!occupancy) { WARN(monitor).print(" <X> Could not acquire tile occupancy*\n");
WARN(monitor).print(" <X> Could not acquire tile occupancy*\n"); return;
return; }
} occupancy->bits.dig_marked = true;
occupancy->bits.dig_marked = true; // prevent algorithm from re-enabling designation
// prevent algorithm from re-enabling designation df::map_block* block = Maps::getTileBlock(job->pos);
df::map_block* block = Maps::getTileBlock(job->pos); if (!block) {
if (!block) { WARN(monitor).print(" <X> Could not acquire block*\n");
WARN(monitor).print(" <X> Could not acquire block*\n"); return;
return; }
} for (auto &be: block->block_events) { ;
for (auto &be: block->block_events) { ; if (auto bsedp = virtual_cast<df::block_square_event_designation_priorityst>(be)) {
if (auto bsedp = virtual_cast<df::block_square_event_designation_priorityst>(be)) { TRACE(monitor).print(" re-setting priority\n");
TRACE(monitor).print(" re-setting priority\n"); bsedp->priority[Coord(local)] = config.ignore_threshold * 1000 + 1;
bsedp->priority[Coord(local)] = config.ignore_threshold * 1000 + 1;
}
} }
} else {
TRACE(monitor).print(" deleting job, and queuing insta-dig)\n");
// queue digging the job instantly
dignow_queue.emplace(job->pos);
} }
} else {
TRACE(monitor).print(" deleting job, and queuing insta-dig)\n");
// queue digging the job instantly
dignow_queue.emplace(job->pos);
} }
} }
} }
INFO(monitor).print(" <- JobStartedEvent() exits normally\n");
} }
INFO(monitor).print(" <- JobStartedEvent() exits normally\n");
} }
} }