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

Function NewReportEvent

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

Source from the content-addressed store, hash-verified

305 }
306
307 void NewReportEvent(color_ostream &out, void* r) {
308 int32_t tick = world->frame_counter;
309 auto report_id = (int32_t)(intptr_t(r));
310 df::report* report = df::report::find(report_id);
311 if (!report) {
312 WARN(plugin).print("Error: NewReportEvent() received an invalid report_id - a report* cannot be found\n");
313 return;
314 }
315 switch (report->type) {
316 case announcement_type::CANCEL_JOB:
317 if (config.insta_dig) {
318 if (report->text.find("cancels Dig") != std::string::npos ||
319 report->text.find("path") != std::string::npos) {
320
321 dignow_queue.emplace(report->pos);
322 }
323 DEBUG(plugin).print("{}, pos: {} , pos2: {}\n{}\n", report_id, report->pos,
324 report->pos2, report->text.c_str());
325 }
326 break;
327 case announcement_type::CAVE_COLLAPSE:
328 if (config.resurrect) {
329 DEBUG(plugin).print("CAVE IN\n{}, pos: {} , pos2: {}\n{}\n", report_id, report->pos,
330 report->pos2, report->text.c_str());
331
332 df::coord below = report->pos;
333 below.z -= 1;
334 below = simulate_area_fall(below);
335 df::coord areaMin{report->pos};
336 df::coord areaMax{areaMin};
337 areaMin.x -= 15;
338 areaMin.y -= 15;
339 areaMax.x += 15;
340 areaMax.y += 15;
341 areaMin.z = below.z;
342 areaMax.z += 1;
343 std::vector<df::unit*> units;
344 Units::getUnitsInBox(units, COORDARGS(areaMin), COORDARGS(areaMax));
345 for (auto unit: units) {
346 endangered_units[unit] = tick;
347 DEBUG(plugin).print(" [id {}] was near a cave in.\n", unit->id);
348 }
349 for (auto unit : world->units.all) {
350 if (last_safe.count(unit->id)) {
351 endangered_units[unit] = tick;
352 DEBUG(plugin).print(" [id {}] is/was a worker, we'll track them too.\n", unit->id);
353 }
354 }
355 }
356 break;
357 default:
358 break;
359 }
360 }
361
362 void OnUpdate(color_ostream &out) {
363 if (World::ReadPauseState())

Callers

nothing calls this directly

Calls 7

simulate_area_fallFunction · 0.85
getUnitsInBoxFunction · 0.85
c_strMethod · 0.80
findFunction · 0.50
printMethod · 0.45
findMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected