createitem: Improve error handling when no caste is specified

Extension of #1463
develop
lethosor 2019-11-01 23:46:42 -04:00
parent 5e1fc0700b
commit 5190257864
1 changed files with 16 additions and 3 deletions

@ -303,7 +303,12 @@ command_result df_createitem (color_ostream &out, vector <string> & parameters)
case item_type::PET: case item_type::PET:
case item_type::EGG: case item_type::EGG:
split_string(&tokens, material_str, ":"); split_string(&tokens, material_str, ":");
if (tokens.size() != 2) if (tokens.size() == 1)
{
// default to empty caste to display a list of valid castes later
tokens.push_back("");
}
else if (tokens.size() != 2)
{ {
out.printerr("You must specify a creature ID and caste for this item type!\n"); out.printerr("You must specify a creature ID and caste for this item type!\n");
return CR_FAILURE; return CR_FAILURE;
@ -318,7 +323,7 @@ command_result df_createitem (color_ostream &out, vector <string> & parameters)
for (size_t j = 0; j < creature->caste.size(); j++) for (size_t j = 0; j < creature->caste.size(); j++)
{ {
df::caste_raw *caste = creature->caste[j]; df::caste_raw *caste = creature->caste[j];
castes += " "+creature->caste[j]->caste_id; castes += " " + creature->caste[j]->caste_id;
if (creature->caste[j]->caste_id == tokens[1]) if (creature->caste[j]->caste_id == tokens[1])
{ {
mat_type = i; mat_type = i;
@ -328,7 +333,15 @@ command_result df_createitem (color_ostream &out, vector <string> & parameters)
} }
if (mat_type == -1) if (mat_type == -1)
{ {
out.printerr("The creature you specified has no such caste!\nValid castes:%s\n", castes.c_str()); if (tokens[1].empty())
{
out.printerr("You must also specify a caste.\n");
}
else
{
out.printerr("The creature you specified has no such caste!\n");
}
out.printerr("Valid castes:%s\n", castes.c_str());
return CR_FAILURE; return CR_FAILURE;
} }
} }