| 1474 | } |
| 1475 | |
| 1476 | static void releaseTiredWorker(EngineInfo *engine, df::job *job, df::unit *worker) |
| 1477 | { |
| 1478 | // If not in siege |
| 1479 | auto &sieges = plotinfo->invasions.list; |
| 1480 | |
| 1481 | for (size_t i = 0; i < sieges.size(); i++) |
| 1482 | if (sieges[i]->flags.bits.active) |
| 1483 | return; |
| 1484 | |
| 1485 | // And there is a free replacement |
| 1486 | auto &others = world->units.active; |
| 1487 | |
| 1488 | for (size_t i = 0; i < others.size(); i++) |
| 1489 | { |
| 1490 | auto unit = others[i]; |
| 1491 | |
| 1492 | if (unit == worker || |
| 1493 | unit->job.current_job || !unit->status.labors[unit_labor::SIEGEOPERATE] || |
| 1494 | !Units::isCitizen(unit) || Units::getMiscTrait(unit, misc_trait_type::Migrant) || |
| 1495 | isTired(unit) || !Maps::canWalkBetween(job->pos, unit->pos)) |
| 1496 | continue; |
| 1497 | |
| 1498 | int skill2 = Units::getEffectiveSkill(unit, job_skill::SIEGEOPERATE); |
| 1499 | |
| 1500 | if (skill2 >= engine->profile.min_level && skill2 <= engine->profile.max_level) |
| 1501 | { |
| 1502 | // Remove the worker and request a recheck |
| 1503 | if (Job::removeWorker(job)) |
| 1504 | { |
| 1505 | color_ostream_proxy out(Core::getInstance().getConsole()); |
| 1506 | out.print("Released tired operator {} from siege engine.\n", worker->id); |
| 1507 | |
| 1508 | if (process_jobs) |
| 1509 | *process_jobs = true; |
| 1510 | } |
| 1511 | |
| 1512 | return; |
| 1513 | } |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | /* |
| 1518 | * Projectile hook |
no test coverage detected