Skip to content

Commit b294eab

Browse files
authored
preserve inventory order in AHuman::EquipNamedDevice too
1 parent 0f5f56a commit b294eab

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Source/Entities/AHuman.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,16 +800,19 @@ bool AHuman::EquipNamedDevice(const std::string& moduleName, const std::string&
800800
// Found proper device to equip, so make the switch!
801801
if (pDevice && (moduleName.empty() || pDevice->GetModuleName() == moduleName) && pDevice->GetPresetName() == presetName) {
802802
if (doEquip) {
803-
// Erase the inventory entry containing the device we now have switched to
804-
*itr = 0;
805-
m_Inventory.erase(itr);
806-
807803
// Put back into the inventory what we had in our hands, if anything
808804
if (HeldDevice* heldDevice = m_pFGArm->GetHeldDevice()) {
809805
heldDevice->Deactivate();
810806
AddToInventoryBack(m_pFGArm->RemoveAttachable(heldDevice));
811807
}
812808

809+
// We want to preserve inventory order in case the player expects it to be some way.
810+
std::rotate(m_Inventory.begin(), itr, m_Inventory.end());
811+
812+
// Erase the inventory entry containing the device we now have switched to
813+
*m_Inventory.begin() = 0;
814+
m_Inventory.pop_front();
815+
813816
// Now put the device we were looking for and found into the hand
814817
m_pFGArm->SetHeldDevice(pDevice);
815818
// Move the hand to a poisition so it looks like the new device was drawn from inventory

0 commit comments

Comments
 (0)