When called with game_ui = true, this is equivalent to Bay12's itemst::meltable() (i.e., returning true if and only if the item has a "designate for melting" button in game)
| 1987 | /// When called with game_ui = true, this is equivalent to Bay12's itemst::meltable() |
| 1988 | /// (i.e., returning true if and only if the item has a "designate for melting" button in game) |
| 1989 | bool Items::canMelt(df::item *item, bool game_ui) { |
| 1990 | CHECK_NULL_POINTER(item); |
| 1991 | MaterialInfo mat(item); |
| 1992 | if (mat.getCraftClass() != craft_material_class::Metal) |
| 1993 | return false; |
| 1994 | |
| 1995 | if (!usesStandardMaterial(item->getType())) |
| 1996 | return false; |
| 1997 | |
| 1998 | if (item->flags.bits.artifact) |
| 1999 | return false; |
| 2000 | // Ignore checks below when asked to behave like itemst::meltable() |
| 2001 | if (game_ui) |
| 2002 | return true; |
| 2003 | |
| 2004 | if (item->getType() == item_type::BAR) |
| 2005 | return false; |
| 2006 | |
| 2007 | // Do not melt nonempty containers and items in unit inventories |
| 2008 | for (auto gref : item->general_refs) { |
| 2009 | switch (gref->getType()) |
| 2010 | { using namespace df::enums::general_ref_type; |
| 2011 | case CONTAINS_ITEM: |
| 2012 | case UNIT_HOLDER: |
| 2013 | case CONTAINS_UNIT: |
| 2014 | return false; |
| 2015 | case CONTAINED_IN_ITEM: |
| 2016 | if (auto cont = gref->getItem(); getGeneralRef(cont, UNIT_HOLDER)) |
| 2017 | return false; |
| 2018 | break; |
| 2019 | default: |
| 2020 | break; |
| 2021 | } |
| 2022 | } |
| 2023 | return true; |
| 2024 | } |
| 2025 | |
| 2026 | bool Items::markForMelting(df::item *item) { |
| 2027 | CHECK_NULL_POINTER(item); |
nothing calls this directly
no test coverage detected