Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Template for new versions:
## Fixes

## Misc Improvements
- `autoclothing`: added a ``clear`` option to unset previously set orders

## Documentation

Expand Down
4 changes: 4 additions & 0 deletions docs/plugins/autoclothing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Usage
autoclothing
autoclothing <material> <item>
autoclothing <material> <item> <quantity>
autoclothing clear <material> <item>

``<material>`` can be "cloth", "silk", "yarn", or "leather". The ``<item>`` can
be anything your civilization can produce, such as "dress" or "mitten".
Expand All @@ -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?
----------------------------------------------
Expand Down
36 changes: 29 additions & 7 deletions plugins/autoclothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ struct ClothingRequirement {

bool SetFromParameters(color_ostream &out, vector<string> &parameters)
{
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)) {
Expand Down Expand Up @@ -442,14 +455,20 @@ command_result autoclothing(color_ostream &out, vector<string> &parameters)
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;) {
Expand All @@ -459,7 +478,10 @@ command_result autoclothing(color_ostream &out, vector<string> &parameters)
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;
Expand Down