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

Function saveWorkshopProfile

plugins/siege-engine.cpp:715–759  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

713}
714
715static df::workshop_profile *saveWorkshopProfile(df::building_siegeenginest *bld)
716{
717 CHECK_NULL_POINTER(bld);
718 CHECK_INVALID_ARGUMENT(is_build_complete(bld));
719
720 if (!enable_plugin())
721 return NULL;
722
723 // Save skill limits
724 auto key = stl_sprintf("siege-engine/profiles/%d", bld->id);
725 auto entry = World::GetPersistentData(key, NULL);
726 if (!entry.isValid())
727 return NULL;
728
729 auto engine = find_engine(bld, true);
730
731 entry.ival(0) = engine->id;
732 entry.ival(1) = engine->profile.min_level;
733 entry.ival(2) = engine->profile.max_level;
734
735 // Save worker list
736 std::vector<PersistentDataItem> vec;
737 auto &workers = engine->profile.permitted_workers;
738
739 key = stl_sprintf("siege-engine/profile-workers/%d", bld->id);
740 World::GetPersistentData(&vec, key, true);
741
742 for (auto it = vec.begin(); it != vec.end(); ++it)
743 {
744 if (linear_index(workers, it->ival(1)) < 0)
745 World::DeletePersistentData(*it);
746 }
747
748 for (size_t i = 0; i < workers.size(); i++)
749 {
750 key = stl_sprintf("siege-engine/profile-workers/%d/%d", bld->id, workers[i]);
751 entry = World::GetPersistentData(key, NULL);
752 if (!entry.isValid())
753 continue;
754 entry.ival(0) = engine->id;
755 entry.ival(1) = workers[i];
756 }
757
758 return &engine->profile;
759}
760
761static df::unit *getOperatorUnit(df::building_siegeenginest *bld, bool force = false)
762{

Callers

nothing calls this directly

Calls 10

is_build_completeFunction · 0.85
stl_sprintfFunction · 0.85
find_engineFunction · 0.85
ivalMethod · 0.80
enable_pluginFunction · 0.70
linear_indexFunction · 0.50
isValidMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected