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

Function moveToInventory

plugins/forceequip.cpp:72–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72static bool moveToInventory(df::item *item, df::unit *unit, df::body_part_raw * targetBodyPart, bool ignoreRestrictions, int multiEquipLimit, bool verbose)
73{
74 // Step 1: Check for anti-requisite conditions
75 df::unit * itemOwner = Items::getOwner(item);
76 if (ignoreRestrictions)
77 {
78 // If the ignoreRestrictions cmdline switch was specified, then skip all of the normal preventative rules
79 if (verbose) { DEBUG(log).print("Skipping integrity checks...\n"); }
80 }
81 else if(!item->isClothing() && !item->isArmorNotClothing())
82 {
83 if (verbose) { WARN(log).print("Item {} is not clothing or armor; it cannot be equipped. Please choose a different item (or use the Ignore option if you really want to equip an inappropriate item).\n", item->id); }
84 return false;
85 }
86 else if (item->getType() != df::enums::item_type::GLOVES &&
87 item->getType() != df::enums::item_type::HELM &&
88 item->getType() != df::enums::item_type::ARMOR &&
89 item->getType() != df::enums::item_type::PANTS &&
90 item->getType() != df::enums::item_type::SHOES &&
91 !targetBodyPart)
92 {
93 if (verbose) { WARN(log).print("Item {} is of an unrecognized type; it cannot be equipped (because the module wouldn't know where to put it).\n", item->id); }
94 return false;
95 }
96 else if (itemOwner && itemOwner->id != unit->id)
97 {
98 if (verbose) { WARN(log).print("Item {} is owned by someone else. Equipping it on this unit is not recommended. Please use DFHack's Confiscate plugin, choose a different item, or use the Ignore option to proceed in spite of this warning.\n", item->id); }
99 return false;
100 }
101 else if (item->flags.bits.in_inventory)
102 {
103 if (verbose) { WARN(log).print("Item {} is already in a unit's inventory. Direct inventory transfers are not recommended; please move the item to the ground first (or use the Ignore option).\n", item->id); }
104 return false;
105 }
106 else if (item->flags.bits.in_job)
107 {
108 if (verbose) { WARN(log).print("Item {} is reserved for use in a queued job. Equipping it is not recommended, as this might interfere with the completion of vital jobs. Use the Ignore option to ignore this warning.\n", item->id); }
109 return false;
110 }
111
112 // ASSERT: anti-requisite conditions have been satisfied (or disregarded)
113
114
115 // Step 2: Try to find a bodypart which is eligible to receive equipment AND which is appropriate for the specified item
116 df::body_part_raw * confirmedBodyPart = NULL;
117 size_t bpIndex;
118 for(bpIndex = 0; bpIndex < unit->body.body_plan->body_parts.size(); bpIndex++)
119 {
120 df::body_part_raw * currPart = unit->body.body_plan->body_parts[bpIndex];
121
122 // Short-circuit the search process if a BP was specified in the function call
123 // Note: this causes a bit of inefficient busy-looping, but the search space is tiny (<100) and we NEED to get the correct bpIndex value in order to perform inventory manipulations
124 if (!targetBodyPart)
125 {
126 // The function call did not specify any particular body part; proceed with normal iteration and evaluation of BP eligibility
127 }
128 else if (currPart == targetBodyPart)
129 {

Callers 3

items_moveToInventoryFunction · 0.85
df_forceequipFunction · 0.85
assignJobFunction · 0.85

Calls 4

getTypeMethod · 0.80
is_setMethod · 0.80
printMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected