| 315 | } |
| 316 | |
| 317 | static 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 | |
| 348 | static void autonestbox_cycle(color_ostream &out) { |
| 349 | // mark that we have recently run |
no test coverage detected