| 307 | } |
| 308 | |
| 309 | static void init_state() |
| 310 | { |
| 311 | config = World::GetPersistentSiteData("autolabor/config"); |
| 312 | if (config.isValid() && config.ival(0) == -1) |
| 313 | config.ival(0) = 0; |
| 314 | |
| 315 | enable_autolabor = isOptionEnabled(CF_ENABLED); |
| 316 | |
| 317 | if (!enable_autolabor) |
| 318 | return; |
| 319 | |
| 320 | // bypass DF's work detail system |
| 321 | game->external_flag.bits.automatic_professions_disabled = true; |
| 322 | |
| 323 | auto cfg_haulpct = World::GetPersistentSiteData("autolabor/haulpct"); |
| 324 | if (cfg_haulpct.isValid()) |
| 325 | { |
| 326 | hauler_pct = cfg_haulpct.ival(0); |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | hauler_pct = 33; |
| 331 | } |
| 332 | |
| 333 | // Load labors from save |
| 334 | labor_infos.resize(ARRAY_COUNT(default_labor_infos)); |
| 335 | |
| 336 | std::vector<PersistentDataItem> items; |
| 337 | World::GetPersistentSiteData(&items, "autolabor/labors/", true); |
| 338 | |
| 339 | for (auto& p : items) |
| 340 | { |
| 341 | std::string key = p.key(); |
| 342 | df::unit_labor labor = (df::unit_labor) atoi(key.substr(strlen("autolabor/labors/")).c_str()); |
| 343 | if (labor >= 0 && size_t(labor) < labor_infos.size()) |
| 344 | { |
| 345 | labor_infos[labor].config = p; |
| 346 | labor_infos[labor].is_exclusive = default_labor_infos[labor].is_exclusive; |
| 347 | labor_infos[labor].active_dwarfs = 0; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | // Add default labors for those not in save |
| 352 | for (size_t i = 0; i < ARRAY_COUNT(default_labor_infos); i++) { |
| 353 | if (labor_infos[i].config.isValid()) |
| 354 | continue; |
| 355 | |
| 356 | std::stringstream name; |
| 357 | name << "autolabor/labors/" << i; |
| 358 | |
| 359 | labor_infos[i].config = World::AddPersistentSiteData(name.str()); |
| 360 | |
| 361 | labor_infos[i].is_exclusive = default_labor_infos[i].is_exclusive; |
| 362 | labor_infos[i].active_dwarfs = 0; |
| 363 | reset_labor((df::unit_labor) i); |
| 364 | } |
| 365 | |
| 366 | generate_labor_to_skill_map(); |
no test coverage detected