Merge pull request #3893 from myk002/myk_tailor

[tailor] reuse existing orders if possible
develop
Myk 2023-10-16 09:43:51 -07:00 committed by GitHub
commit 06944ee0bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 16 deletions

@ -81,6 +81,7 @@ Template for new versions:
- `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 - `buildingplan`: show how many items you need to make when planning buildings
- `tailor`: now adds to existing orders if possilbe instead of creating new ones
## 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

@ -425,7 +425,6 @@ public:
int size = world->raws.creatures.all[race]->adultsize; int size = world->raws.creatures.all[race]->adultsize;
auto tt = jobTypeMap.find(o->job_type); auto tt = jobTypeMap.find(o->job_type);
if (tt == jobTypeMap.end()) if (tt == jobTypeMap.end())
{ {
@ -441,6 +440,21 @@ public:
} }
static df::manager_order * get_existing_order(df::job_type ty, int16_t sub, int32_t hfid, df::job_material_category mcat) {
for (auto order : world->manager_orders) {
if (order->job_type == ty &&
order->item_type == df::item_type::NONE &&
order->item_subtype == sub &&
order->mat_type == -1 &&
order->mat_index == -1 &&
order->hist_figure_id == hfid &&
order->material_category.whole == mcat.whole &&
order->frequency == df::manager_order::T_frequency::OneTime)
return order;
}
return NULL;
}
int place_orders() int place_orders()
{ {
int ordered = 0; int ordered = 0;
@ -532,21 +546,29 @@ public:
} }
supply[m] -= c; supply[m] -= c;
auto order = new df::manager_order; auto order = get_existing_order(ty, sub, sizes[size], m.job_material);
order->job_type = ty; if (order) {
order->item_type = df::item_type::NONE; if (order->amount_total > 0) {
order->item_subtype = sub; order->amount_left += c;
order->mat_type = -1; order->amount_total += c;
order->mat_index = -1; }
order->amount_left = c; } else {
order->amount_total = c; order = new df::manager_order;
order->status.bits.validated = false; order->job_type = ty;
order->status.bits.active = false; order->item_type = df::item_type::NONE;
order->id = world->manager_order_next_id++; order->item_subtype = sub;
order->hist_figure_id = sizes[size]; order->mat_type = -1;
order->material_category = m.job_material; order->mat_index = -1;
order->amount_left = c;
world->manager_orders.push_back(order); order->amount_total = c;
order->status.bits.validated = false;
order->status.bits.active = false;
order->id = world->manager_order_next_id++;
order->hist_figure_id = sizes[size];
order->material_category = m.job_material;
world->manager_orders.push_back(order);
}
INFO(cycle).print("tailor: added order #%d for %d %s %s, sized for %s\n", INFO(cycle).print("tailor: added order #%d for %d %s %s, sized for %s\n",
order->id, order->id,