MCPcopy Create free account
hub / github.com/DFHack/dfhack / canMelt

Method canMelt

library/modules/Items.cpp:1989–2024  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)
1989bool 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
2026bool Items::markForMelting(df::item *item) {
2027 CHECK_NULL_POINTER(item);

Callers

nothing calls this directly

Calls 2

getCraftClassMethod · 0.80
getTypeMethod · 0.80

Tested by

no test coverage detected