| 157 | } |
| 158 | |
| 159 | static inline bool select_plant_growth(color_ostream &out, vector<string> &tokens, df::item_type &item_type, |
| 160 | int16_t &item_subtype, int16_t &mat_type, int32_t &mat_index, const string &material_str) |
| 161 | { |
| 162 | split_string(&tokens, material_str, ":"); |
| 163 | if (tokens.size() == 1) |
| 164 | { // Default to empty to display a list of valid growths later |
| 165 | tokens.push_back(""); |
| 166 | } |
| 167 | else if (tokens.size() == 3 && tokens[0] == "PLANT") |
| 168 | tokens.erase(tokens.begin()); |
| 169 | else if (tokens.size() != 2) { |
| 170 | out.printerr("You must specify a plant and growth ID for this item type!\n"); |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | for (size_t i = 0; i < world->raws.plants.all.size(); i++) |
| 175 | { |
| 176 | string growths = ""; |
| 177 | auto plant = world->raws.plants.all[i]; |
| 178 | if (plant->id != tokens[0]) |
| 179 | continue; |
| 180 | |
| 181 | for (size_t j = 0; j < plant->growths.size(); j++) |
| 182 | { |
| 183 | auto growth = plant->growths[j]; |
| 184 | growths += " " + growth->id; |
| 185 | if (growth->id != tokens[1]) |
| 186 | continue; |
| 187 | |
| 188 | // Plant growths specify the actual item type/subtype |
| 189 | // so that certain growths can drop as SEEDS items |
| 190 | item_type = growth->item_type; |
| 191 | item_subtype = growth->item_subtype; |
| 192 | mat_type = growth->mat_type; |
| 193 | mat_index = growth->mat_index; |
| 194 | break; |
| 195 | } |
| 196 | if (mat_type == -1) { |
| 197 | if (tokens[1].empty()) |
| 198 | out.printerr("You must also specify a growth ID.\n"); |
| 199 | else |
| 200 | out.printerr("The plant you specified has no such growth!\n"); |
| 201 | out.printerr("Valid growths:{}\n", growths); |
| 202 | return false; |
| 203 | } |
| 204 | } |
| 205 | if (mat_type == -1) { |
| 206 | out.printerr("Unrecognized plant ID!\n"); |
| 207 | return false; |
| 208 | } |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | command_result df_createitem (color_ostream &out, vector<string> ¶meters) { |
| 213 | string item_str, material_str; |
no test coverage detected