| 253 | } |
| 254 | |
| 255 | command_result changeitem_execute( |
| 256 | color_ostream &out, df::item * item, |
| 257 | bool info, bool force, |
| 258 | bool change_material, string new_material, |
| 259 | bool change_quality, int new_quality, |
| 260 | bool change_subtype, string new_subtype ) |
| 261 | { |
| 262 | MaterialInfo mat_new; |
| 263 | MaterialInfo mat_old; |
| 264 | |
| 265 | ItemTypeInfo sub_old; |
| 266 | ItemTypeInfo sub_new; |
| 267 | int new_subtype_id = -1; |
| 268 | |
| 269 | if(change_material) |
| 270 | mat_new.find(new_material); |
| 271 | if(change_material || info) |
| 272 | mat_old.decode(item); |
| 273 | |
| 274 | if(change_subtype || info) |
| 275 | sub_old.decode(item); |
| 276 | if(change_subtype) |
| 277 | { |
| 278 | string new_type = ENUM_KEY_STR(item_type, item->getType()) + ":" + new_subtype; |
| 279 | if (new_subtype == "NONE") |
| 280 | new_subtype_id = -1; |
| 281 | else if (sub_new.find(new_type)) |
| 282 | new_subtype_id = sub_new.subtype; |
| 283 | else |
| 284 | { |
| 285 | // out.printerr("Invalid subtype for selected item, skipping\n"); |
| 286 | return CR_FAILURE; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // print some info, don't change stuff |
| 291 | if(info) |
| 292 | { |
| 293 | out << "Item info: " << endl; |
| 294 | out << " type: " << ENUM_KEY_STR(item_type, item->getType()) << endl; |
| 295 | out << " subtype: " << (sub_old.custom ? sub_old.custom->id : "NONE") << endl; |
| 296 | out << " quality: " << describeQuality(item->getQuality()) << endl; |
| 297 | //if(item->isImproved()) |
| 298 | // out << " imp.quality: " << describeQuality(item->getImprovementQuality()) << endl; |
| 299 | out << " material: " << mat_old.getToken() << endl; |
| 300 | return CR_OK; |
| 301 | } |
| 302 | |
| 303 | if(change_quality) |
| 304 | { |
| 305 | item->setQuality(new_quality); |
| 306 | // it would be nice to be able to change the improved quality, too |
| 307 | // (only allowed if the item is already improved) |
| 308 | // but there is no method in item.h which supports that |
| 309 | // ok: hints from _Q/angavrilov: improvent is a vector, an item can have more than one improvement |
| 310 | // -> virtual_cast to item_constructedst |
| 311 | } |
| 312 |
no test coverage detected