Skip to content

Commit

Permalink
Merge pull request #5085 from myk002/myk_orders_sort
Browse files Browse the repository at this point in the history
[orders] sort workshop-tied orders first
  • Loading branch information
myk002 authored Dec 7, 2024
2 parents 5b744e7 + af24837 commit 74d316f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Template for new versions:
- `preserve-rooms`: automatically release room reservations for captured squad members. we were kidding ourselves with our optimistic kept reservations. they're unlikely to come back : ((
- `buildingplan`: add value info to item selection dialog (effectively ungrouping items with different values) and add sorting by value
- `timestream`: reduce CPU utilization
- `fix/occupancy`: additionally handle the case where tile occupancy doesn't reflect the actual existence of a building
- `fix/occupancy`: additionally handle the case where tile building occupancy needs to be set instead of cleared
- `orders`: make ``orders sort`` sort orders that are tied to a specific workshop first

## Documentation
- Dreamfort: add link to Dreamfort tutorial youtube series: https://www.youtube.com/playlist?list=PLzXx9JcB9oXxmrtkO1y8ZXzBCFEZrKxve
Expand Down
10 changes: 7 additions & 3 deletions plugins/orders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,12 @@ static command_result orders_clear_command(color_ostream & out)
return CR_OK;
}

static bool compare_freq(df::manager_order *a, df::manager_order *b)
static bool orders_compare(df::manager_order *a, df::manager_order *b)
{
if (a->workshop_id != b->workshop_id) {
return a->workshop_id >= 0;
}

if (a->frequency == df::manager_order::T_frequency::OneTime
|| b->frequency == df::manager_order::T_frequency::OneTime)
return a->frequency < b->frequency;
Expand All @@ -1025,11 +1029,11 @@ static command_result orders_sort_command(color_ostream & out)

if (!std::is_sorted(world->manager_orders.all.begin(),
world->manager_orders.all.end(),
compare_freq))
orders_compare))
{
std::stable_sort(world->manager_orders.all.begin(),
world->manager_orders.all.end(),
compare_freq);
orders_compare);
out << "Fixed priority of manager orders." << std::endl;
}

Expand Down

0 comments on commit 74d316f

Please sign in to comment.