mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 21:56:41 +00:00 
			
		
		
		
	Code cleanup for Class::canBeEquipped
This commit is contained in:
		
							parent
							
								
									79a440e94a
								
							
						
					
					
						commit
						b8ac37347c
					
				
					 3 changed files with 45 additions and 72 deletions
				
			
		|  | @ -294,41 +294,30 @@ namespace MWClass | ||||||
|         // slots that this item can be equipped in
 |         // slots that this item can be equipped in
 | ||||||
|         std::pair<std::vector<int>, bool> slots_ = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); |         std::pair<std::vector<int>, bool> slots_ = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); | ||||||
| 
 | 
 | ||||||
|  |         if (slots_.first.empty()) | ||||||
|  |             return std::make_pair(0, ""); | ||||||
|  | 
 | ||||||
|         std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace; |         std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace; | ||||||
| 
 | 
 | ||||||
|  |         // Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
 | ||||||
|  |         const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace); | ||||||
|  |         if(race->mData.mFlags & ESM::Race::Beast) | ||||||
|  |         { | ||||||
|  |             std::vector<ESM::PartReference> parts = ptr.get<ESM::Armor>()->mBase->mParts.mParts; | ||||||
|  | 
 | ||||||
|  |             for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr) | ||||||
|  |             { | ||||||
|  |                 if((*itr).mPart == ESM::PRT_Head) | ||||||
|  |                     return std::make_pair(0, "#{sNotifyMessage13}"); | ||||||
|  |                 if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot) | ||||||
|  |                     return std::make_pair(0, "#{sNotifyMessage14}"); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         for (std::vector<int>::const_iterator slot=slots_.first.begin(); |         for (std::vector<int>::const_iterator slot=slots_.first.begin(); | ||||||
|             slot!=slots_.first.end(); ++slot) |             slot!=slots_.first.end(); ++slot) | ||||||
|         { |         { | ||||||
| 
 |             // If equipping a shield, check if there's a twohanded weapon conflicting with it
 | ||||||
|             // Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
 |  | ||||||
|             const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace); |  | ||||||
|             if(race->mData.mFlags & ESM::Race::Beast) |  | ||||||
|             { |  | ||||||
|                 std::vector<ESM::PartReference> parts = ptr.get<ESM::Armor>()->mBase->mParts.mParts; |  | ||||||
| 
 |  | ||||||
|                 if(*slot == MWWorld::InventoryStore::Slot_Helmet) |  | ||||||
|                 { |  | ||||||
|                     for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr) |  | ||||||
|                     { |  | ||||||
|                         if((*itr).mPart == ESM::PRT_Head) |  | ||||||
|                         { |  | ||||||
|                             return std::make_pair(0, "#{sNotifyMessage13}"); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 if (*slot == MWWorld::InventoryStore::Slot_Boots) |  | ||||||
|                 { |  | ||||||
|                     for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr) |  | ||||||
|                     { |  | ||||||
|                         if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot) |  | ||||||
|                         { |  | ||||||
|                             return std::make_pair(0, "#{sNotifyMessage14}"); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             if(*slot == MWWorld::InventoryStore::Slot_CarriedLeft) |             if(*slot == MWWorld::InventoryStore::Slot_CarriedLeft) | ||||||
|             { |             { | ||||||
|                 MWWorld::ContainerStoreIterator weapon = invStore.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); |                 MWWorld::ContainerStoreIterator weapon = invStore.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); | ||||||
|  |  | ||||||
|  | @ -235,37 +235,26 @@ namespace MWClass | ||||||
|         // slots that this item can be equipped in
 |         // slots that this item can be equipped in
 | ||||||
|         std::pair<std::vector<int>, bool> slots_ = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); |         std::pair<std::vector<int>, bool> slots_ = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); | ||||||
| 
 | 
 | ||||||
|  |         if (slots_.first.empty()) | ||||||
|  |             return std::make_pair(0, ""); | ||||||
|  | 
 | ||||||
|         std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace; |         std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace; | ||||||
| 
 | 
 | ||||||
|         for (std::vector<int>::const_iterator slot=slots_.first.begin(); |         // Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
 | ||||||
|             slot!=slots_.first.end(); ++slot) |         const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace); | ||||||
|  |         if(race->mData.mFlags & ESM::Race::Beast) | ||||||
|         { |         { | ||||||
|  |             std::vector<ESM::PartReference> parts = ptr.get<ESM::Clothing>()->mBase->mParts.mParts; | ||||||
| 
 | 
 | ||||||
|             // Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
 |             for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr) | ||||||
|             const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace); |  | ||||||
|             if(race->mData.mFlags & ESM::Race::Beast) |  | ||||||
|             { |             { | ||||||
|                 std::vector<ESM::PartReference> parts = ptr.get<ESM::Clothing>()->mBase->mParts.mParts; |                 if((*itr).mPart == ESM::PRT_Head) | ||||||
| 
 |                     return std::make_pair(0, "#{sNotifyMessage13}"); | ||||||
|                 if(*slot == MWWorld::InventoryStore::Slot_Helmet) |                 if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot) | ||||||
|                 { |                     return std::make_pair(0, "#{sNotifyMessage15}"); | ||||||
|                     for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr) |  | ||||||
|                     { |  | ||||||
|                         if((*itr).mPart == ESM::PRT_Head) |  | ||||||
|                             return std::make_pair(0, "#{sNotifyMessage13}"); |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 if (*slot == MWWorld::InventoryStore::Slot_Boots) |  | ||||||
|                 { |  | ||||||
|                     for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr) |  | ||||||
|                     { |  | ||||||
|                         if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot) |  | ||||||
|                             return std::make_pair(0, "#{sNotifyMessage15}"); |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|         return std::make_pair (1, ""); |         return std::make_pair (1, ""); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -390,26 +390,21 @@ namespace MWClass | ||||||
|     { |     { | ||||||
|         std::pair<std::vector<int>, bool> slots_ = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); |         std::pair<std::vector<int>, bool> slots_ = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); | ||||||
| 
 | 
 | ||||||
|         // equip the item in the first free slot
 |         if (slots_.first.empty()) | ||||||
|         for (std::vector<int>::const_iterator slot=slots_.first.begin(); |             return std::make_pair (0, ""); | ||||||
|             slot!=slots_.first.end(); ++slot) | 
 | ||||||
|  |         if(ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand || | ||||||
|  |         ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoClose || | ||||||
|  |         ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoWide || | ||||||
|  |         ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::SpearTwoWide || | ||||||
|  |         ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::AxeTwoHand || | ||||||
|  |         ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow || | ||||||
|  |         ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow) | ||||||
|         { |         { | ||||||
|             if(*slot == MWWorld::InventoryStore::Slot_CarriedRight) |             return std::make_pair (2, ""); | ||||||
|             { |  | ||||||
|                 if(ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::LongBladeTwoHand || |  | ||||||
|                 ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoClose ||  |  | ||||||
|                 ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::BluntTwoWide ||  |  | ||||||
|                 ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::SpearTwoWide || |  | ||||||
|                 ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::AxeTwoHand ||  |  | ||||||
|                 ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanBow ||  |  | ||||||
|                 ptr.get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow) |  | ||||||
|                 { |  | ||||||
|                     return std::make_pair (2, ""); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             return std::make_pair(1, ""); |  | ||||||
|         } |         } | ||||||
|         return std::make_pair (0, ""); | 
 | ||||||
|  |         return std::make_pair(1, ""); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     boost::shared_ptr<MWWorld::Action> Weapon::use (const MWWorld::Ptr& ptr) const |     boost::shared_ptr<MWWorld::Action> Weapon::use (const MWWorld::Ptr& ptr) const | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue