show how many items you need to make when planning

develop
Myk Taylor 2023-10-15 23:20:31 -07:00
parent d38545032c
commit 287ed440ce
No known key found for this signature in database
3 changed files with 31 additions and 4 deletions

@ -78,6 +78,7 @@ Template for new versions:
- `sort`: added help button for squad assignment search/filter/sort
- `zone`: animals trained for war or hunting are now labeled as such in animal assignment screens
- `buildingplan`: support filtering cages by whether they are occupied
- `buildingplan`: show how many items you need to make when planning buildings
## Documentation
- unavailable tools are no longer listed in the tag indices in the online docs

@ -677,7 +677,7 @@ static int scanAvailableItems(color_ostream &out, df::building_type type, int16_
int32_t custom, int index, bool ignore_filters, vector<int> *item_ids = NULL,
map<MaterialInfo, int32_t> *counts = NULL) {
DEBUG(status,out).print(
"entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
"entering scanAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
type, subtype, custom, index);
BuildingTypeKey key(type, subtype, custom);
HeatSafety heat = get_heat_safety_filter(key);
@ -755,7 +755,30 @@ static int countAvailableItems(color_ostream &out, df::building_type type, int16
DEBUG(status,out).print(
"entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
type, subtype, custom, index);
return scanAvailableItems(out, type, subtype, custom, index, false);
int count = scanAvailableItems(out, type, subtype, custom, index, false);
if (count)
return count;
// nothing in stock; return how many are waiting in line as a negative
BuildingTypeKey key(type, subtype, custom);
auto &job_items = get_job_items(out, key);
if (index < 0 || job_items.size() <= (size_t)index)
return 0;
auto &jitem = job_items[index];
for (auto &entry : planned_buildings) {
auto &pb = entry.second;
// don't actually remove bad buildings from the list while we're
// actively iterating through that list
auto bld = pb.getBuildingIfValidOrRemoveIfNot(out, true);
if (!bld || bld->jobs.size() != 1)
continue;
for (auto pb_jitem : bld->jobs[0]->job_items) {
if (pb_jitem->item_type == jitem->item_type && pb_jitem->item_subtype == jitem->item_subtype)
count -= pb_jitem->quantity;
}
}
return count;
}
static bool hasFilter(color_ostream &out, df::building_type type, int16_t subtype, int32_t custom, int index) {

@ -295,9 +295,12 @@ function ItemLine:get_item_line_text()
if self.available >= quantity then
self.note_pen = COLOR_GREEN
self.note = ' Available now'
elseif self.available >= 0 then
self.note_pen = COLOR_BROWN
self.note = (' Will link next (need to make %d)'):format(quantity - self.available)
else
self.note_pen = COLOR_BROWN
self.note = ' Will link later'
self.note = (' Will link later (need to make %d)'):format(-self.available + quantity)
end
self.note = string.char(192) .. self.note -- character 192 is "└"
@ -318,7 +321,7 @@ function ItemLine:reduce_quantity(used_quantity)
if not self.available then return end
local filter = get_cur_filters()[self.idx]
used_quantity = used_quantity or get_quantity(filter, self.is_hollow_fn())
self.available = math.max(0, self.available - used_quantity)
self.available = self.available - used_quantity
end
local function get_placement_errors()