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

Function registerPlannedBuilding

plugins/buildingplan/buildingplan.cpp:457–505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

455}
456
457static bool registerPlannedBuilding(color_ostream &out, PlannedBuilding & pb, bool unsuspend_on_finalize) {
458 df::building * bld = pb.getBuildingIfValidOrRemoveIfNot(out);
459 if (!bld)
460 return false;
461
462 if (bld->jobs.size() != 1) {
463 DEBUG(control,out).print("unexpected number of jobs: want 1, got {}\n", bld->jobs.size());
464 return false;
465 }
466
467 // suspend jobs
468 for (auto job : bld->jobs)
469 job->flags.bits.suspend = true;
470
471 auto job_items = bld->jobs[0]->job_items.elements;
472 if (isJobReady(out, job_items)) {
473 // all items are already attached
474 finalizeBuilding(out, bld, unsuspend_on_finalize);
475 pb.remove(out);
476 return true;
477 }
478
479 int num_job_items = (int)job_items.size();
480 int32_t id = bld->id;
481 for (int job_item_idx = 0; job_item_idx < num_job_items; ++job_item_idx) {
482 int rev_jitem_index = num_job_items - (job_item_idx+1);
483 auto job_item = job_items[rev_jitem_index];
484 auto bucket = getBucket(*job_item, pb, job_item_idx);
485
486 // if there are multiple vector_ids, schedule duplicate tasks. after
487 // the correct number of items are matched, the extras will get popped
488 // as invalid
489 for (auto vector_id : pb.vector_ids[job_item_idx]) {
490 for (int item_num = 0; item_num < job_item->quantity; ++item_num) {
491 tasks[vector_id][bucket].emplace_back(id, rev_jitem_index);
492 DEBUG(control,out).print("added task: {}/{}/{}, {}; "
493 "{} vector(s), {} filter bucket(s), {} task(s) in bucket\n",
494 ENUM_KEY_STR(job_item_vector_id, vector_id),
495 bucket, id, rev_jitem_index, tasks.size(),
496 tasks[vector_id].size(), tasks[vector_id][bucket].size());
497 }
498 }
499 }
500
501 // add the planned buildings to our register
502 planned_buildings.emplace(bld->id, pb);
503
504 return true;
505}
506
507static string get_desc_string(color_ostream &out, df::job_item *jitem,
508 const vector<df::job_item_vector_id> &vec_ids) {

Callers 2

addPlannedBuildingFunction · 0.85

Calls 7

isJobReadyFunction · 0.85
finalizeBuildingFunction · 0.85
getBucketFunction · 0.85
sizeMethod · 0.45
printMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected