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::EGG:
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");
return CR_FAILURE;
@ -328,7 +333,15 @@ command_result df_createitem (color_ostream &out, vector <string> & parameters)
}
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;
}
}