MCPcopy Create free account
hub / github.com/DFHack/dfhack / JobStartedEvent

Function JobStartedEvent

plugins/channel-safely/channel-safely-plugin.cpp:224–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222 }
223
224 void JobStartedEvent(color_ostream &out, void* j) {
225 if (enabled && World::isFortressMode() && Maps::IsValid()) {
226 TRACE(jobs).print("JobStartedEvent()\n");
227 auto job = (df::job*) j;
228 // validate job type
229 if (ChannelManager::Get().exists(job->pos)) {
230 DEBUG(jobs).print(" valid channel job:\n");
231 df::unit* worker = Job::getWorker(job);
232 // there is a valid worker (living citizen) on the job? right..
233 if (worker && Units::isAlive(worker) && Units::isCitizen(worker)) {
234 ChannelManager::Get().jobs.mark_active(job->pos);
235 if (config.riskaverse) {
236 if (ChannelManager::Get().jobs.possible_cavein(job->pos)) {
237 cancel_job(job);
238 ChannelManager::Get().manage_one(job->pos, true, true);
239 } else {
240 ChannelManager::Get().manage_group(job->pos, true, false);
241 }
242 }
243 DEBUG(jobs).print(" valid worker:\n");
244 // track workers on jobs
245 df::coord &pos = job->pos;
246 TRACE(jobs).print(" -> Starting job at (" COORD ")\n", COORDARGS(pos));
247 if (config.monitoring || config.resurrect) {
248 job_id_map.emplace(job, job->id);
249 active_jobs.emplace(job->id, job);
250 active_workers[job->id] = worker;
251 if (config.resurrect) {
252 // this is the only place we can be 100% sure of "safety"
253 // (excluding deadly enemies that will have arrived)
254 last_safe[worker->id] = worker->pos;
255 }
256 }
257 // set tile to restricted
258 TRACE(jobs).print(" setting job tile to restricted\n");
259 Maps::getTileDesignation(job->pos)->bits.traffic = df::tile_traffic::Restricted;
260 }
261 }
262 TRACE(jobs).print(" <- JobStartedEvent() exits normally\n");
263 }
264 }
265
266 void JobCompletedEvent(color_ostream &out, void* j) {
267 if (enabled && World::isFortressMode() && Maps::IsValid()) {

Callers

nothing calls this directly

Calls 8

cancel_jobFunction · 0.85
getTileDesignationFunction · 0.85
mark_activeMethod · 0.80
possible_caveinMethod · 0.80
manage_oneMethod · 0.80
manage_groupMethod · 0.80
printMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected