| 51 | } |
| 52 | |
| 53 | bool makeItem(df::unit *unit, df::item_type type, int16_t subtype, int16_t mat_type, int32_t mat_index, int32_t count, |
| 54 | bool move_to_cursor = false, bool second_item = false) |
| 55 | { // Special logic for making Gloves and Shoes in pairs |
| 56 | bool is_gloves = (type == item_type::GLOVES); |
| 57 | bool is_shoes = (type == item_type::SHOES); |
| 58 | |
| 59 | df::item *container = NULL; |
| 60 | df::building *building = NULL; |
| 61 | if (dest_container != -1) |
| 62 | container = df::item::find(dest_container); |
| 63 | if (dest_building != -1) |
| 64 | building = df::building::find(dest_building); |
| 65 | |
| 66 | bool on_floor = (container == NULL) && (building == NULL) && !move_to_cursor; |
| 67 | |
| 68 | vector<df::item *> out_items; |
| 69 | if (!Items::createItem(out_items, unit, type, subtype, mat_type, mat_index, !on_floor, count)) |
| 70 | return false; |
| 71 | |
| 72 | for (size_t i = 0; i < out_items.size(); i++) { |
| 73 | if (container) |
| 74 | { |
| 75 | out_items[i]->flags.bits.removed = 1; |
| 76 | if (!Items::moveToContainer(out_items[i], container)) |
| 77 | out_items[i]->moveToGround(container->pos.x, container->pos.y, container->pos.z); |
| 78 | } |
| 79 | else if (building) |
| 80 | { |
| 81 | out_items[i]->flags.bits.removed = 1; |
| 82 | if (!Items::moveToBuilding(out_items[i], (df::building_actual *)building, df::building_item_role_type::TEMP)) |
| 83 | out_items[i]->moveToGround(building->centerx, building->centery, building->z); |
| 84 | } |
| 85 | else if (move_to_cursor) |
| 86 | { |
| 87 | auto pos = Gui::getCursorPos(); |
| 88 | out_items[i]->moveToGround(pos.x, pos.y, pos.z); |
| 89 | } |
| 90 | // else createItem() already put it on the floor at the unit's feet, so we're good |
| 91 | |
| 92 | // Special logic for creating proper gloves in pairs |
| 93 | if (is_gloves) |
| 94 | { // If the gloves have non-zero handedness, then disable special pair-making logic |
| 95 | // ("reaction-gloves" tweak is active, or Toady fixed glove-making reactions) |
| 96 | // Otherwise, set them to be either Left or Right-handed |
| 97 | if (out_items[i]->getGloveHandedness() > 0) |
| 98 | is_gloves = false; |
| 99 | else |
| 100 | out_items[i]->setGloveHandedness(second_item ? 2 : 1); |
| 101 | } |
| 102 | } |
| 103 | // If we asked to make a Shoe and we got more than one, then disable special pair-making logic |
| 104 | if (is_shoes && out_items.size() > 1) |
| 105 | is_shoes = false; |
| 106 | // If we asked for gloves/shoes and only got one (and we're making the first one), make another |
| 107 | if ((is_gloves || is_shoes) && !second_item) |
| 108 | return makeItem(unit, type, subtype, mat_type, mat_index, count, move_to_cursor, true); |
| 109 | return true; |
| 110 | } |
no test coverage detected