summaryrefslogtreecommitdiff
path: root/plugins/autolabor.cpp
diff options
context:
space:
mode:
authorPetr Mrázek2012-03-29 20:00:26 +0200
committerPetr Mrázek2012-03-29 20:00:26 +0200
commit69b1bbe59ea1a3969a2623ba2d32b9455762307a (patch)
tree44c2b710db0e6463f4ebb32d2470305c6a4963e5 /plugins/autolabor.cpp
parentb847a026e3d3069e677872aa62bcd71ce0f6dd42 (diff)
downloaddfhack-69b1bbe59ea1a3969a2623ba2d32b9455762307a.tar.gz
dfhack-69b1bbe59ea1a3969a2623ba2d32b9455762307a.tar.bz2
dfhack-69b1bbe59ea1a3969a2623ba2d32b9455762307a.tar.xz
Turn sorting lambdas into functors in autolabor.
Diffstat (limited to 'plugins/autolabor.cpp')
-rw-r--r--plugins/autolabor.cpp56
1 files changed, 42 insertions, 14 deletions
diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp
index 26c4cb8b..eee10e3e 100644
--- a/plugins/autolabor.cpp
+++ b/plugins/autolabor.cpp
@@ -384,7 +384,7 @@ static const df::job_skill noble_skills[] = {
df::enums::job_skill::RECORD_KEEPING,
};
-struct dwarf_info
+struct dwarf_info_t
{
int highest_skill;
int total_skill;
@@ -432,6 +432,38 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out )
return CR_OK;
}
+// sorting objects
+struct dwarfinfo_sorter
+{
+ dwarfinfo_sorter(std::vector <dwarf_info_t> & info):dwarf_info(info){};
+ bool operator() (int i,int j)
+ {
+ if (dwarf_info[i].state == IDLE && dwarf_info[j].state != IDLE)
+ return true;
+ if (dwarf_info[i].state != IDLE && dwarf_info[j].state == IDLE)
+ return false;
+ return dwarf_info[i].mastery_penalty > dwarf_info[j].mastery_penalty;
+ };
+ std::vector <dwarf_info_t> & dwarf_info;
+};
+struct laborinfo_sorter
+{
+ bool operator() (int i,int j)
+ {
+ return labor_infos[i].mode < labor_infos[j].mode;
+ };
+};
+
+struct values_sorter
+{
+ values_sorter(std::vector <int> & values):values(values){};
+ bool operator() (int i,int j)
+ {
+ return values[i] > values[j];
+ };
+ std::vector<int> & values;
+};
+
DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{
static int step_count = 0;
@@ -478,7 +510,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
if (n_dwarfs == 0)
return CR_OK;
- std::vector<dwarf_info> dwarf_info(n_dwarfs);
+ std::vector<dwarf_info_t> dwarf_info(n_dwarfs);
std::vector<int> best_noble(ARRAY_COUNT(noble_skills));
std::vector<int> highest_noble_skill(ARRAY_COUNT(noble_skills));
@@ -643,8 +675,8 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
labors.push_back(labor);
}
-
- std::sort(labors.begin(), labors.end(), [] (int i, int j) { return labor_infos[i].mode < labor_infos[j].mode; });
+ laborinfo_sorter lasorter;
+ std::sort(labors.begin(), labors.end(), lasorter);
// Handle all skills except those marked HAULERS
@@ -734,7 +766,10 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
}
if (labor_infos[labor].mode != EVERYONE)
- std::sort(candidates.begin(), candidates.end(), [&values] (int i, int j) { return values[i] > values[j]; });
+ {
+ values_sorter ivs(values);
+ std::sort(candidates.begin(), candidates.end(), ivs);
+ }
for (int dwarf = 0; dwarf < n_dwarfs; dwarf++)
{
@@ -815,16 +850,9 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
if (dwarf_info[dwarf].state == IDLE || dwarf_info[dwarf].state == BUSY)
hauler_ids.push_back(dwarf);
}
-
+ dwarfinfo_sorter sorter(dwarf_info);
// Idle dwarves come first, then we sort from least-skilled to most-skilled.
- std::sort(hauler_ids.begin(), hauler_ids.end(), [&dwarf_info] (int i, int j) -> bool
- {
- if (dwarf_info[i].state == IDLE && dwarf_info[j].state != IDLE)
- return true;
- if (dwarf_info[i].state != IDLE && dwarf_info[j].state == IDLE)
- return false;
- return dwarf_info[i].mastery_penalty > dwarf_info[j].mastery_penalty;
- });
+ std::sort(hauler_ids.begin(), hauler_ids.end(), sorter);
// don't set any haulers if everyone is off drinking or something
if (hauler_ids.size() == 0) {