diff --git a/docs/changelog.txt b/docs/changelog.txt index 98f6f7e487..750670a79e 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -58,6 +58,7 @@ Template for new versions: ## Fixes ## Misc Improvements +- `autoclothing`: added a ``clear`` option to unset previously set orders ## Documentation diff --git a/docs/plugins/autoclothing.rst b/docs/plugins/autoclothing.rst index 1ea1a9094f..02d13c83a7 100644 --- a/docs/plugins/autoclothing.rst +++ b/docs/plugins/autoclothing.rst @@ -22,6 +22,7 @@ Usage autoclothing autoclothing autoclothing + autoclothing clear ```` can be "cloth", "silk", "yarn", or "leather". The ```` can be anything your civilization can produce, such as "dress" or "mitten". @@ -43,6 +44,9 @@ Examples long as there is cloth available to make them out of). ``autoclothing cloth dress`` Displays the currently set number of cloth dresses chosen per citizen. +``autoclothing clear cloth "short skirt"`` + Unsets cloth short skirts from being made if previously enabled such as + in the first example Which should I enable: autoclothing or tailor? ---------------------------------------------- diff --git a/plugins/autoclothing.cpp b/plugins/autoclothing.cpp index fac721a5c5..a4516f4dce 100644 --- a/plugins/autoclothing.cpp +++ b/plugins/autoclothing.cpp @@ -129,6 +129,19 @@ struct ClothingRequirement { bool SetFromParameters(color_ostream &out, vector ¶meters) { + if (parameters[0] == "clear") { // handle the clear case + if (!set_bitfield_field(&material_category, parameters[1], 1)) + out << "Unrecognized material type: " << parameters[1] << endl; + if (!setItem(parameters[2], this)) { + out << "Unrecognized item name or token: " << parameters[2] << endl; + return false; + } + else if (!validateMaterialCategory(this)) { + out << parameters[1] << " is not a valid material category for " << parameters[2] << endl; + return false; + } + return true; + } if (!set_bitfield_field(&material_category, parameters[0], 1)) out << "Unrecognized material type: " << parameters[0] << endl; if (!setItem(parameters[1], this)) { @@ -442,14 +455,20 @@ command_result autoclothing(color_ostream &out, vector ¶meters) bool settingSize = false; bool matchedExisting = false; if (parameters.size() > 2) { - try { - newRequirement.needed_per_citizen = std::stoi(parameters[2]); + if (parameters[0] == "clear") { + newRequirement.needed_per_citizen = 0; + settingSize = true; } - catch (const std::exception&) { - out << parameters[2] << " is not a valid number." << endl; - return CR_WRONG_USAGE; + else { + try { + newRequirement.needed_per_citizen = std::stoi(parameters[2]); + } + catch (const std::exception&) { + out << parameters[2] << " is not a valid number." << endl; + return CR_WRONG_USAGE; + } + settingSize = true; } - settingSize = true; } for (size_t i = clothingOrders.size(); i-- > 0;) { @@ -459,7 +478,10 @@ command_result autoclothing(color_ostream &out, vector ¶meters) if (settingSize) { if (newRequirement.needed_per_citizen == 0) { clothingOrders.erase(clothingOrders.begin() + i); - out << "Unset " << parameters[0] << " " << parameters[1] << endl; + if (parameters[0] == "clear") + out << "Unset " << parameters[1] << " " << parameters[2] << endl; + else + out << "Unset " << parameters[0] << " " << parameters[1] << endl; } else { clothingOrders[i] = newRequirement;