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

Function countAvailableItems

plugins/buildingplan/buildingplan.cpp:757–785  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

755}
756
757static int countAvailableItems(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) {
758 DEBUG(control,out).print(
759 "entering countAvailableItems building_type={} subtype={} custom={} index={}\n",
760 ENUM_AS_STR(type), subtype, custom, index);
761 int count = scanAvailableItems(out, type, subtype, custom, index, false, false);
762 if (count)
763 return count;
764
765 // nothing in stock; return how many are waiting in line as a negative
766 BuildingTypeKey key(type, subtype, custom);
767 auto &job_items = get_job_items(out, key);
768 if (index < 0 || job_items.size() <= (size_t)index)
769 return 0;
770 auto &jitem = job_items[index];
771
772 for (auto &entry : planned_buildings) {
773 auto &pb = entry.second;
774 // don't actually remove bad buildings from the list while we're
775 // actively iterating through that list
776 auto bld = pb.getBuildingIfValidOrRemoveIfNot(out, true);
777 if (!bld || bld->jobs.size() != 1)
778 continue;
779 for (auto pb_jitem : bld->jobs[0]->job_items.elements) {
780 if (pb_jitem->item_type == jitem->item_type && pb_jitem->item_subtype == jitem->item_subtype)
781 count -= pb_jitem->quantity;
782 }
783 }
784 return count;
785}
786
787static bool hasFilter(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) {
788 TRACE(control,out).print("entering hasFilter\n");

Callers

nothing calls this directly

Calls 4

scanAvailableItemsFunction · 0.85
printMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected