| 334 | } |
| 335 | |
| 336 | static void init_state() |
| 337 | { |
| 338 | config = World::GetPersistentData("labormanager/2.0/config"); |
| 339 | if (config.isValid() && config.ival(0) == -1) |
| 340 | config.ival(0) = 0; |
| 341 | |
| 342 | enable_labormanager = isOptionEnabled(CF_ENABLED); |
| 343 | |
| 344 | if (!enable_labormanager) |
| 345 | return; |
| 346 | |
| 347 | // Load labors from save |
| 348 | labor_infos.resize(ARRAY_COUNT(default_labor_infos)); |
| 349 | |
| 350 | std::vector<PersistentDataItem> items; |
| 351 | World::GetPersistentData(&items, "labormanager/2.0/labors/", true); |
| 352 | |
| 353 | for (auto p = items.begin(); p != items.end(); p++) |
| 354 | { |
| 355 | string key = p->key(); |
| 356 | df::unit_labor labor = (df::unit_labor) atoi(key.substr(strlen("labormanager/2.0/labors/")).c_str()); |
| 357 | if (labor >= 0 && size_t(labor) < labor_infos.size()) |
| 358 | { |
| 359 | labor_infos[labor].config = *p; |
| 360 | labor_infos[labor].active_dwarfs = 0; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | // Add default labors for those not in save |
| 365 | for (size_t i = 0; i < ARRAY_COUNT(default_labor_infos); i++) { |
| 366 | if (labor_infos[i].config.isValid()) |
| 367 | continue; |
| 368 | |
| 369 | std::stringstream name; |
| 370 | name << "labormanager/2.0/labors/" << i; |
| 371 | |
| 372 | labor_infos[i].config = World::AddPersistentData(name.str()); |
| 373 | labor_infos[i].mark_assigned(); |
| 374 | labor_infos[i].active_dwarfs = 0; |
| 375 | reset_labor((df::unit_labor) i); |
| 376 | } |
| 377 | |
| 378 | initialized = true; |
| 379 | |
| 380 | } |
| 381 | |
| 382 | static df::job_skill labor_to_skill[ENUM_LAST_ITEM(unit_labor) + 1]; |
| 383 |
no test coverage detected