| 1783 | } |
| 1784 | |
| 1785 | bool Items::createItem(vector<df::item *> &out_items, df::unit *unit, df::item_type item_type, |
| 1786 | int16_t item_subtype, int16_t mat_type, int32_t mat_index, bool no_floor, int32_t count) |
| 1787 | { // Based on Quietust's plugins/createitem.cpp |
| 1788 | CHECK_NULL_POINTER(unit); |
| 1789 | auto pos = Units::getPosition(unit); |
| 1790 | auto block = Maps::getTileBlock(pos); |
| 1791 | CHECK_NULL_POINTER(block); |
| 1792 | |
| 1793 | auto prod = df::allocate<df::reaction_product_itemst>(); |
| 1794 | prod->item_type = item_type; |
| 1795 | prod->item_subtype = item_subtype; |
| 1796 | prod->mat_type = mat_type; |
| 1797 | prod->mat_index = mat_index; |
| 1798 | prod->probability = 100; |
| 1799 | prod->count = count; |
| 1800 | |
| 1801 | switch(item_type) |
| 1802 | { using namespace df::enums::item_type; |
| 1803 | case BAR: |
| 1804 | case POWDER_MISC: |
| 1805 | case LIQUID_MISC: |
| 1806 | case DRINK: |
| 1807 | prod->product_dimension = 150; |
| 1808 | break; |
| 1809 | case THREAD: |
| 1810 | prod->product_dimension = 15000; |
| 1811 | break; |
| 1812 | case CLOTH: |
| 1813 | prod->product_dimension = 10000; |
| 1814 | break; |
| 1815 | default: |
| 1816 | prod->product_dimension = 1; |
| 1817 | } |
| 1818 | |
| 1819 | // makeItem |
| 1820 | vector<df::reaction_product *> out_products; |
| 1821 | vector<df::reaction_reagent *> in_reag; |
| 1822 | vector<df::item *> in_items; |
| 1823 | |
| 1824 | out_items.clear(); |
| 1825 | prod->produce(unit, &out_products, &out_items, &in_reag, &in_items, 1, job_skill::NONE, |
| 1826 | 0, df::historical_entity::find(unit->civ_id), |
| 1827 | World::isFortressMode() ? df::world_site::find(World::GetCurrentSiteId()) : NULL, NULL); |
| 1828 | delete prod; |
| 1829 | |
| 1830 | DEBUG(items).print("produced {} items\n", out_items.size()); |
| 1831 | |
| 1832 | for (auto out_item : out_items) |
| 1833 | { // Plant growths need a valid "growth print", otherwise they behave oddly |
| 1834 | if (auto growth = virtual_cast<df::item_plant_growthst>(out_item)) |
| 1835 | growth->growth_print = pickGrowthPrint(growth->subtype, growth->mat_type, growth->mat_index); |
| 1836 | if (!no_floor) |
| 1837 | out_item->moveToGround(pos.x, pos.y, pos.z); |
| 1838 | } |
| 1839 | return !out_items.empty(); |
| 1840 | } |
| 1841 | |
| 1842 | /* |
nothing calls this directly
no test coverage detected