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

Function finalizeBuilding

plugins/buildingplan/buildingplan_cycle.cpp:210–246  ·  view source on GitHub ↗

this function does not remove the job_items since their quantity fields are now all at 0, so there is no risk of having extra items attached. we don't remove them to keep the "finalize with buildingplan active" path as similar as possible to the "finalize with buildingplan disabled" path.

Source from the content-addressed store, hash-verified

208// remove them to keep the "finalize with buildingplan active" path as similar
209// as possible to the "finalize with buildingplan disabled" path.
210void finalizeBuilding(color_ostream &out, df::building *bld, bool unsuspend_on_finalize) {
211 DEBUG(cycle,out).print("finalizing building {}\n", bld->id);
212 auto job = bld->jobs[0];
213
214 // sort the items so they get added to the structure in the correct order
215 std::sort(job->items.begin(), job->items.end(), job_item_idx_lt);
216
217 // derive the material properties of the building and job from the first
218 // applicable item. if any boulders are involved, it makes the whole
219 // structure "rough".
220 bool rough = false;
221 for (auto attached_item : job->items) {
222 df::item *item = attached_item->item;
223 rough = rough || item->getType() == df::item_type::BOULDER;
224 if (bld->mat_type == -1) {
225 bld->mat_type = item->getMaterial();
226 job->mat_type = bld->mat_type;
227 }
228 if (bld->mat_index == -1) {
229 bld->mat_index = item->getMaterialIndex();
230 job->mat_index = bld->mat_index;
231 }
232 }
233
234 if (bld->needsDesign()) {
235 auto act = (df::building_actual *)bld;
236 if (!act->design)
237 act->design = new df::building_design();
238 act->design->flags.bits.rough = rough;
239 }
240
241 // we're good to go!
242 if (unsuspend_on_finalize) {
243 job->flags.bits.suspend = false;
244 Job::checkBuildingsNow();
245 }
246}
247
248static df::building * popInvalidTasks(color_ostream &out, Bucket &task_queue,
249 unordered_map<int32_t, PlannedBuilding> &planned_buildings) {

Callers 2

registerPlannedBuildingFunction · 0.85
doVectorFunction · 0.85

Calls 5

sortFunction · 0.85
getTypeMethod · 0.80
printMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected