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

Function autoclothing

plugins/autoclothing.cpp:421–532  ·  view source on GitHub ↗

A command! It sits around and looks pretty. And it's nice and friendly.

Source from the content-addressed store, hash-verified

419
420// A command! It sits around and looks pretty. And it's nice and friendly.
421command_result autoclothing(color_ostream &out, vector<string> &parameters)
422{
423 if (!Core::getInstance().isMapLoaded() || !World::isFortressMode()) {
424 out.printerr("Cannot run {} without a loaded fort.\n", plugin_name);
425 return CR_FAILURE;
426 }
427
428 // It's nice to print a help message you get invalid options
429 // from the user instead of just acting strange.
430 // This can be achieved by adding the extended help string to the
431 // PluginCommand registration as show above, and then returning
432 // CR_WRONG_USAGE from the function. The same string will also
433 // be used by 'help your-command'.
434 if (parameters.empty())
435 {
436 out << "Automatic clothing management is currently " << (is_enabled ? "enabled" : "disabled") << "." << endl;
437 out << "Currently set " << clothingOrders.size() << " automatic clothing orders" << endl;
438 for (auto &order : clothingOrders)
439 out << order.ToReadableLabel() << endl;
440 generate_control(out);
441 return CR_OK;
442 }
443 /* TODO: Disabled until I have time to fully implement it.
444 else if (parameters[0] == "strictness") {
445 if (parameters.size() != 2) {
446 out << "Wrong number of arguments." << endl;
447 return CR_WRONG_USAGE;
448 }
449 else if (parameters[1] == "permissive")
450 strictnessSetting = STRICT_PERMISSIVE;
451 else if (parameters[1] == "type")
452 strictnessSetting = STRICT_TYPE;
453 else if (parameters[1] == "material")
454 strictnessSetting = STRICT_MATERIAL;
455 }*/
456 else if (parameters.size() < 2 || parameters.size() > 3) {
457 out << "Wrong number of arguments." << endl;
458 return CR_WRONG_USAGE;
459 }
460
461 // Create a new requirement from the available parameters.
462 auto newRequirementOpt = ClothingRequirement::createFromParameters(out, parameters);
463 if (!newRequirementOpt)
464 return CR_WRONG_USAGE;
465
466 auto& newRequirement = *newRequirementOpt;
467
468 // All checks are passed. Now we either show or set the amount.
469 bool settingSize = false;
470
471 if (parameters.size() > 2) {
472 if (parameters[0] == "clear") {
473 newRequirement.needed_per_citizen = 0;
474 settingSize = true;
475 }
476 else {
477 try {
478 newRequirement.needed_per_citizen = std::stoi(parameters[2]);

Callers

nothing calls this directly

Calls 9

generate_controlFunction · 0.85
do_autoclothingFunction · 0.85
ToReadableLabelMethod · 0.80
findFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected