MCPcopy Create free account
hub / github.com/DFHack/dfhack / populatePreferencesColumn

Method populatePreferencesColumn

plugins/dwarfmonitor.cpp:1304–1375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1302 }
1303
1304 void populatePreferencesColumn()
1305 {
1306 selected_column = 0;
1307
1308 auto last_selected_index = preferences_column.highlighted_index;
1309 preferences_column.clear();
1310 preference_totals.clear();
1311
1312 for (auto iter = world->units.active.begin(); iter != world->units.active.end(); iter++)
1313 {
1314 df::unit* unit = *iter;
1315 if (!Units::isCitizen(unit))
1316 continue;
1317
1318 if (!DFHack::Units::isActive(unit))
1319 continue;
1320
1321 if (!unit->status.current_soul)
1322 continue;
1323
1324 for (auto it = unit->status.current_soul->preferences.begin();
1325 it != unit->status.current_soul->preferences.end();
1326 it++)
1327 {
1328 auto pref = *it;
1329 if (!pref->active)
1330 continue;
1331 bool foundInStore = false;
1332 for (size_t pref_index = 0; pref_index < preferences_store.size(); pref_index++)
1333 {
1334 if (isMatchingPreference(preferences_store[pref_index].pref, *pref))
1335 {
1336 foundInStore = true;
1337 preferences_store[pref_index].dwarves.push_back(unit);
1338 }
1339 }
1340
1341 if (!foundInStore)
1342 {
1343 size_t pref_index = preferences_store.size();
1344 preferences_store.resize(pref_index + 1);
1345 preferences_store[pref_index].pref = *pref;
1346 preferences_store[pref_index].dwarves.push_back(unit);
1347 }
1348 }
1349 }
1350
1351 for (size_t i = 0; i < preferences_store.size(); i++)
1352 {
1353 preference_totals[i] = preferences_store[i].dwarves.size();
1354 }
1355
1356 vector<pair<size_t, size_t>> rev_vec(preference_totals.begin(), preference_totals.end());
1357 sort(rev_vec.begin(), rev_vec.end(), less_second<size_t, size_t>());
1358
1359 for (auto rev_it = rev_vec.begin(); rev_it != rev_vec.end(); rev_it++)
1360 {
1361 auto pref_index = rev_it->first;

Callers

nothing calls this directly

Calls 13

sortFunction · 0.85
pad_stringFunction · 0.85
int_to_stringFunction · 0.85
makeLabelMethod · 0.80
fixWidthMethod · 0.80
filterDisplayMethod · 0.80
setHighlightMethod · 0.80
clearMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected