Skip to content

Commit 51173fb

Browse files
committed
Removed material and job type sortings.
1 parent de5b88c commit 51173fb

3 files changed

Lines changed: 6 additions & 180 deletions

File tree

docs/plugins/orders.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ Usage
2828
Sorts current manager orders by repeat frequency so repeating orders don't
2929
prevent one-time orders from ever being completed. The sorting order is:
3030
one-time orders first, then yearly, seasonally, monthly, and finally, daily.
31-
``orders sort_type``
32-
Sorts current manager orders by job type, making it easier to locate orders
33-
that produce similar items. The sorting is done by reaction name, job type
34-
and item subtype. If orders are equal by these fields the sorting falls back
35-
to sort by frequency.
36-
``orders sort_material``
37-
Sorts current manager orders by material, making it easier to locate orders
38-
that produce items of the same material. The sorting is done by material type
39-
and material category. If orders are equal by these fields the sorting falls back
40-
to sort by job type.
4131

4232
You can keep your orders automatically sorted by adding the following command to
4333
your ``dfhack-config/init/onMapLoad.init`` file::

plugins/lua/orders.lua

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ OrdersOverlay.ATTRS{
7979
default_pos={x=53,y=-6},
8080
default_enabled=true,
8181
viewscreens='dwarfmode/Info/WORK_ORDERS/Default',
82-
frame={w=73, h=4},
82+
frame={w=46, h=4},
8383
}
8484

8585
function OrdersOverlay:init()
@@ -114,31 +114,17 @@ function OrdersOverlay:init()
114114
},
115115
widgets.HotkeyLabel{
116116
frame={t=1, l=15},
117-
label='clear',
118-
key='CUSTOM_CTRL_C',
119-
auto_width=true,
120-
on_activate=do_clear,
121-
},
122-
widgets.HotkeyLabel{
123-
frame={t=0, l=30},
124-
label='sort by freq',
117+
label='sort',
125118
key='CUSTOM_CTRL_O',
126119
auto_width=true,
127120
on_activate=do_sort,
128121
},
129122
widgets.HotkeyLabel{
130-
frame={t=1, l=30},
131-
label='sort by type',
132-
key='CUSTOM_CTRL_J',
133-
auto_width=true,
134-
on_activate=do_sort_type,
135-
},
136-
widgets.HotkeyLabel{
137-
frame={t=0, l=52},
138-
label='sort by mat',
139-
key='CUSTOM_CTRL_T',
123+
frame={t=0, l=31},
124+
label='clear',
125+
key='CUSTOM_CTRL_C',
140126
auto_width=true,
141-
on_activate=do_sort_mat,
127+
on_activate=do_clear,
142128
},
143129
},
144130
}

plugins/orders.cpp

Lines changed: 0 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ static command_result orders_export_command(color_ostream & out, const std::stri
6767
static command_result orders_import_command(color_ostream & out, const std::string & name);
6868
static command_result orders_clear_command(color_ostream & out);
6969
static command_result orders_sort_command(color_ostream & out);
70-
static command_result orders_sort_type_command(color_ostream & out);
71-
static command_result orders_sort_material_command(color_ostream & out);
7270
static command_result orders_recheck_command(color_ostream & out);
7371
static command_result orders_recheck_current_command(color_ostream & out);
7472

@@ -118,16 +116,6 @@ static command_result orders_command(color_ostream & out, std::vector<std::strin
118116
return orders_sort_command(out);
119117
}
120118

121-
if (parameters[0] == "sort_type" && parameters.size() == 1)
122-
{
123-
return orders_sort_type_command(out);
124-
}
125-
126-
if (parameters[0] == "sort_material" && parameters.size() == 1)
127-
{
128-
return orders_sort_material_command(out);
129-
}
130-
131119
if (parameters[0] == "recheck" && parameters.size() == 1)
132120
{
133121
return orders_recheck_command(out);
@@ -1046,144 +1034,6 @@ static command_result orders_sort_command(color_ostream & out)
10461034
return CR_OK;
10471035
}
10481036

1049-
static bool compare_type(df::manager_order *a, df::manager_order *b)
1050-
{
1051-
// Goal: Sort orders to easily find them in the list and to see dupclicated orders.
1052-
// Sorting by job types
1053-
1054-
// Divide orders by frequency first
1055-
if (a->frequency != b->frequency)
1056-
{
1057-
return compare_freq(a, b);
1058-
}
1059-
1060-
// Determine if only one order has reaction_name
1061-
bool a_has_reaction_name = !a->reaction_name.empty();
1062-
bool b_has_reaction_name = !b->reaction_name.empty();
1063-
1064-
if (a_has_reaction_name != b_has_reaction_name)
1065-
{
1066-
return a_has_reaction_name;
1067-
}
1068-
else if (a_has_reaction_name && b_has_reaction_name)
1069-
{
1070-
if (a->reaction_name != b->reaction_name)
1071-
{
1072-
return a->reaction_name < b->reaction_name;
1073-
}
1074-
}
1075-
1076-
// Compare job_type
1077-
if (enum_item_key(a->job_type) != enum_item_key(b->job_type))
1078-
{
1079-
return enum_item_key(a->job_type) < enum_item_key(b->job_type);
1080-
}
1081-
1082-
// Compare item subtype
1083-
bool a_has_item_subtype = (a->item_subtype != -1);
1084-
bool b_has_item_subtype = (b->item_subtype != -1);
1085-
1086-
if (a_has_item_subtype != b_has_item_subtype)
1087-
{
1088-
return a_has_item_subtype;
1089-
}
1090-
else if (a_has_item_subtype && b_has_item_subtype)
1091-
{
1092-
if (a->item_subtype != b->item_subtype)
1093-
{
1094-
return a->item_subtype < b->item_subtype;
1095-
}
1096-
}
1097-
1098-
// By default orders are the same
1099-
return false;
1100-
}
1101-
1102-
static command_result orders_sort_type_command(color_ostream & out)
1103-
{
1104-
CoreSuspender suspend;
1105-
if (!std::is_sorted(world->manager_orders.begin(),
1106-
world->manager_orders.end(),
1107-
compare_type))
1108-
{
1109-
std::stable_sort(world->manager_orders.begin(),
1110-
world->manager_orders.end(),
1111-
compare_type);
1112-
out << "Manager orders are sorted by job type." << std::endl;
1113-
}
1114-
1115-
return CR_OK;
1116-
}
1117-
1118-
static bool compare_material(df::manager_order *a, df::manager_order *b)
1119-
{
1120-
// Goal: Sort orders to easily find them in the list and to see dupclicated orders.
1121-
// Sorting by materials
1122-
1123-
// Divide orders by frequency first
1124-
if (a->frequency != b->frequency)
1125-
{
1126-
return compare_freq(a, b);
1127-
}
1128-
1129-
// Determine if only one of the orders has mat_type
1130-
bool a_has_material = (a->mat_type != -1 || a->mat_index != -1);
1131-
bool b_has_material = (b->mat_type != -1 || b->mat_index != -1);
1132-
1133-
if (a_has_material != b_has_material)
1134-
{
1135-
return a_has_material;
1136-
}
1137-
else if (a_has_material && b_has_material)
1138-
{
1139-
// Compare mat_type using MaterialInfo
1140-
if (MaterialInfo(a).getToken() != MaterialInfo(b).getToken())
1141-
{
1142-
return MaterialInfo(a).getToken() < MaterialInfo(b).getToken();
1143-
}
1144-
}
1145-
1146-
// Determine if only one order has material_category
1147-
bool a_has_material_category = (a->material_category.whole != 0);
1148-
bool b_has_material_category = (b->material_category.whole != 0);
1149-
1150-
if (a_has_material_category != b_has_material_category)
1151-
{
1152-
return a_has_material_category;
1153-
}
1154-
else if (a_has_material_category && b_has_material_category)
1155-
{
1156-
std::vector<std::string> a_mats, b_mats;
1157-
bitfield_to_string(&a_mats, a->material_category);
1158-
bitfield_to_string(&b_mats, b->material_category);
1159-
1160-
// Checking that mats are not empty just in case
1161-
if (!a_mats.empty() && !b_mats.empty() && a_mats[0] != b_mats[0])
1162-
{
1163-
return a_mats[0] < b_mats[0];
1164-
}
1165-
}
1166-
1167-
// Fall back to material sort
1168-
return compare_type(a, b);
1169-
}
1170-
1171-
static command_result orders_sort_material_command(color_ostream & out)
1172-
{
1173-
CoreSuspender suspend;
1174-
if (!std::is_sorted(world->manager_orders.begin(),
1175-
world->manager_orders.end(),
1176-
compare_material))
1177-
{
1178-
std::stable_sort(world->manager_orders.begin(),
1179-
world->manager_orders.end(),
1180-
compare_material);
1181-
out << "Manager orders are sorted by material." << std::endl;
1182-
}
1183-
1184-
return CR_OK;
1185-
}
1186-
11871037
static command_result orders_recheck_command(color_ostream & out)
11881038
{
11891039
for (auto it : world->manager_orders)

0 commit comments

Comments
 (0)