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

Function init_state

plugins/autolabor/labormanager.cpp:336–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334}
335
336static 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
382static df::job_skill labor_to_skill[ENUM_LAST_ITEM(unit_labor) + 1];
383

Callers 3

enable_pluginFunction · 0.70

Calls 11

ivalMethod · 0.80
c_strMethod · 0.80
mark_assignedMethod · 0.80
isOptionEnabledFunction · 0.70
reset_laborFunction · 0.70
isValidMethod · 0.45
resizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected