@@ -654,7 +654,7 @@ bool AHuman::EquipFirearm(bool doEquip) {
654654 AddToInventoryBack (m_pFGArm->RemoveAttachable (heldDevice));
655655 }
656656
657- // We want to preserve inventory order, so rotate it to the device in question.
657+ // We want to preserve inventory order, so rotate to the device in question.
658658 std::rotate (m_Inventory.begin (), itr, m_Inventory.end ());
659659
660660 // Erase the inventory entry containing the device we now have switched to
@@ -673,7 +673,6 @@ bool AHuman::EquipFirearm(bool doEquip) {
673673 if (m_DeviceSwitchSound) {
674674 m_DeviceSwitchSound->Play (m_Pos);
675675 }
676-
677676 }
678677
679678 return true ;
@@ -698,10 +697,6 @@ bool AHuman::EquipDeviceInGroup(std::string group, bool doEquip) {
698697 // Found proper device to equip, so make the switch!
699698 if (pDevice && pDevice->IsInGroup (group)) {
700699 if (doEquip) {
701- // Erase the inventory entry containing the device we now have switched to
702- *itr = 0 ;
703- m_Inventory.erase (itr);
704-
705700 // Put back into the inventory what we had in our hands, if anything
706701 if (HeldDevice* heldDevice = m_pFGArm->GetHeldDevice ()) {
707702 heldDevice->Deactivate ();
@@ -717,6 +712,12 @@ bool AHuman::EquipDeviceInGroup(std::string group, bool doEquip) {
717712 }
718713 }
719714
715+ // We want to preserve inventory order, so rotate it to the device in question.
716+ std::rotate (m_Inventory.begin (), itr, m_Inventory.end ());
717+
718+ // Erase the inventory entry containing the device we now have switched to
719+ *m_Inventory.begin () = 0 ;
720+
720721 // Now put the device we were looking for and found into the hand
721722 m_pFGArm->SetHeldDevice (pDevice);
722723 // Move the hand to a poisition so it looks like the new device was drawn from inventory
@@ -753,16 +754,18 @@ bool AHuman::EquipLoadedFirearmInGroup(std::string group, std::string excludeGro
753754 // Found proper device to equip, so make the switch!
754755 if (pFirearm && !pFirearm->NeedsReloading () && pFirearm->IsInGroup (group) && !pFirearm->IsInGroup (excludeGroup)) {
755756 if (doEquip) {
756- // Erase the inventory entry containing the device we now have switched to
757- *itr = 0 ;
758- m_Inventory.erase (itr);
759-
760757 // Put back into the inventory what we had in our hands, if anything
761758 if (HeldDevice* heldDevice = m_pFGArm->GetHeldDevice ()) {
762759 m_pFGArm->GetHeldDevice ()->Deactivate ();
763760 AddToInventoryBack (m_pFGArm->RemoveAttachable (heldDevice));
764761 }
765762
763+ // We want to preserve inventory order, so rotate it to the device in question.
764+ std::rotate (m_Inventory.begin (), itr, m_Inventory.end ());
765+
766+ // Erase the inventory entry containing the device we now have switched to
767+ *m_Inventory.begin () = 0 ;
768+
766769 // Now put the device we were looking for and found into the hand
767770 m_pFGArm->SetHeldDevice (pFirearm);
768771 // Move the hand to a poisition so it looks like the new device was drawn from inventory
@@ -806,7 +809,7 @@ bool AHuman::EquipNamedDevice(const std::string& moduleName, const std::string&
806809 AddToInventoryBack (m_pFGArm->RemoveAttachable (heldDevice));
807810 }
808811
809- // We want to preserve inventory order in case the player expects it to be some way .
812+ // We want to preserve inventory order, so rotate to the device in question .
810813 std::rotate (m_Inventory.begin (), itr, m_Inventory.end ());
811814
812815 // Erase the inventory entry containing the device we now have switched to
@@ -851,16 +854,19 @@ bool AHuman::EquipThrowable(bool doEquip) {
851854 if (pThrown) // && pThrown->IsWeapon())
852855 {
853856 if (doEquip) {
854- // Erase the inventory entry containing the device we now have switched to
855- *itr = 0 ;
856- m_Inventory.erase (itr);
857857
858858 // Put back into the inventory what we had in our hands, if anything
859859 if (HeldDevice* heldDevice = m_pFGArm->GetHeldDevice ()) {
860860 heldDevice->Deactivate ();
861861 AddToInventoryBack (m_pFGArm->RemoveAttachable (heldDevice));
862862 }
863863
864+ // We want to preserve inventory order, so rotate it to the device in question.
865+ std::rotate (m_Inventory.begin (), itr, m_Inventory.end ());
866+
867+ // Erase the inventory entry containing the device we now have switched to
868+ *m_Inventory.begin () = 0 ;
869+
864870 // Now put the device we were looking for and found into the hand
865871 m_pFGArm->SetHeldDevice (pThrown);
866872 // Move the hand to a poisition so it looks like the new device was drawn from inventory
@@ -975,16 +981,19 @@ bool AHuman::EquipShield() {
975981 HeldDevice* pShield = dynamic_cast <HeldDevice*>(*itr);
976982 // Found proper device to equip, so make the switch!
977983 if (pShield && pShield->IsShield ()) {
978- // Erase the inventory entry containing the device we now have switched to
979- *itr = 0 ;
980- m_Inventory.erase (itr);
981984
982985 // Put back into the inventory what we had in our hands, if anything
983986 if (HeldDevice* heldDevice = m_pFGArm->GetHeldDevice ()) {
984987 heldDevice->Deactivate ();
985988 AddToInventoryBack (m_pFGArm->RemoveAttachable (heldDevice));
986989 }
987990
991+ // We want to preserve inventory order, so rotate it to the device in question.
992+ std::rotate (m_Inventory.begin (), itr, m_Inventory.end ());
993+
994+ // Erase the inventory entry containing the device we now have switched to
995+ *m_Inventory.begin () = 0 ;
996+
988997 // Now put the device we were looking for and found into the hand
989998 m_pFGArm->SetHeldDevice (pShield);
990999 // Move the hand to a poisition so it looks like the new device was drawn from inventory
@@ -1034,10 +1043,6 @@ bool AHuman::EquipShieldInBGArm(bool depositToFront) {
10341043 HeldDevice* pShield = dynamic_cast <HeldDevice*>(*itr);
10351044 // Found proper device to equip, so make the switch!
10361045 if (pShield && (pShield->IsShield () || pShield->IsDualWieldable ())) {
1037- // Erase the inventory entry containing the device we now have switched to
1038- *itr = 0 ;
1039- m_Inventory.erase (itr);
1040-
10411046 // Put back into the inventory what we had in our hands, if anything
10421047 if (HeldDevice* heldDevice = m_pBGArm->GetHeldDevice ()) {
10431048 heldDevice->Deactivate ();
@@ -1048,6 +1053,12 @@ bool AHuman::EquipShieldInBGArm(bool depositToFront) {
10481053 }
10491054 }
10501055
1056+ // We want to preserve inventory order, so rotate it to the device in question.
1057+ std::rotate (m_Inventory.begin (), itr, m_Inventory.end ());
1058+
1059+ // Erase the inventory entry containing the device we now have switched to
1060+ *m_Inventory.begin () = 0 ;
1061+
10511062 // Now put the device we were looking for and found into the hand
10521063 m_pBGArm->SetHeldDevice (pShield);
10531064 // Move the hand to a poisition so it looks like the new device was drawn from inventory
0 commit comments