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

Function assign_nestboxes

plugins/autonestbox.cpp:317–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315}
316
317static size_t assign_nestboxes(color_ostream &out) {
318 rate_limit_complaining();
319
320 vector<df::building_civzonest *> free_zones;
321 size_t assigned = getFreeNestboxZones(out, free_zones);
322 vector<df::unit *> free_units = getFreeEggLayers(out);
323
324 const size_t max_idx = std::min(free_zones.size(), free_units.size());
325 for (size_t idx = 0; idx < max_idx; ++idx) {
326 if (!assignUnitToZone(out, free_units[idx], free_zones[idx])) {
327 DEBUG(cycle,out).print("Failed to assign unit to building.\n");
328 return assigned;
329 }
330 DEBUG(cycle,out).print("assigned unit {} to zone {}\n",
331 free_units[idx]->id, free_zones[idx]->id);
332 ++assigned;
333 }
334
335 if (free_zones.size() < free_units.size() && !did_complain) {
336 size_t num_needed = free_units.size() - free_zones.size();
337 std::stringstream ss;
338 ss << "Not enough free nestbox zones! You need to make " << num_needed <<
339 " more 1x1 pasture" << (num_needed == 1 ? " and build a nestbox in it." : "s and build nestboxes in them.");
340 string announce = ss.str();
341 out << announce << std::endl;
342 Gui::showAnnouncement("[DFHack autonestbox] " + announce, COLOR_BROWN, true);
343 did_complain = true;
344 }
345 return assigned;
346}
347
348static void autonestbox_cycle(color_ostream &out) {
349 // mark that we have recently run

Callers 1

autonestbox_cycleFunction · 0.85

Calls 7

rate_limit_complainingFunction · 0.85
getFreeNestboxZonesFunction · 0.85
getFreeEggLayersFunction · 0.85
assignUnitToZoneFunction · 0.85
sizeMethod · 0.45
printMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected