Merge pull request #3891 from myk002/myk_buildingplan_count

[buildingplan] show how many items you need to make when planning
develop
Myk 2023-10-15 23:31:18 -07:00 committed by GitHub
commit dbab35f8a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 - `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 - `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`: support filtering cages by whether they are occupied
- `buildingplan`: show how many items you need to make when planning buildings
## Documentation ## Documentation
- unavailable tools are no longer listed in the tag indices in the online docs - 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, int32_t custom, int index, bool ignore_filters, vector<int> *item_ids = NULL,
map<MaterialInfo, int32_t> *counts = NULL) { map<MaterialInfo, int32_t> *counts = NULL) {
DEBUG(status,out).print( 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); type, subtype, custom, index);
BuildingTypeKey key(type, subtype, custom); BuildingTypeKey key(type, subtype, custom);
HeatSafety heat = get_heat_safety_filter(key); 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( DEBUG(status,out).print(
"entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n", "entering countAvailableItems building_type=%d subtype=%d custom=%d index=%d\n",
type, subtype, custom, index); 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) { 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 if self.available >= quantity then
self.note_pen = COLOR_GREEN self.note_pen = COLOR_GREEN
self.note = ' Available now' 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 else
self.note_pen = COLOR_BROWN self.note_pen = COLOR_BROWN
self.note = ' Will link later' self.note = (' Will link later (need to make %d)'):format(-self.available + quantity)
end end
self.note = string.char(192) .. self.note -- character 192 is "└" 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 if not self.available then return end
local filter = get_cur_filters()[self.idx] local filter = get_cur_filters()[self.idx]
used_quantity = used_quantity or get_quantity(filter, self.is_hollow_fn()) 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 end
local function get_placement_errors() local function get_placement_errors()