Porting more ContainerStoreIterator usage to const version #4

removed const_cast revision
0.6.1
Rafael Moura 8 years ago
parent 7fa2703715
commit 6c2ce2b2a1

@ -765,8 +765,8 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
if (!mSoundsDisabled)
{
MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ContainerStoreIterator csi = inv.getSlot(group < 0 ? MWWorld::InventoryStore::Slot_Helmet : group);
const MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ConstContainerStoreIterator csi = inv.getSlot(group < 0 ? MWWorld::InventoryStore::Slot_Helmet : group);
if (csi != inv.end())
{
mSoundIds[type] = csi->getClass().getSound(*csi);
@ -899,8 +899,8 @@ void NpcAnimation::showWeapons(bool showWeapon)
mShowWeapons = showWeapon;
if(showWeapon)
{
MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
const MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ConstContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if(weapon != inv.end())
{
osg::Vec4f glowColor = getEnchantmentColor(*weapon);
@ -912,7 +912,7 @@ void NpcAnimation::showWeapons(bool showWeapon)
if (weapon->getTypeName() == typeid(ESM::Weapon).name() &&
weapon->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::MarksmanCrossbow)
{
MWWorld::ContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition);
MWWorld::ConstContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition);
if (ammo != inv.end() && ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Bolt)
attachArrow();
else
@ -931,8 +931,8 @@ void NpcAnimation::showWeapons(bool showWeapon)
void NpcAnimation::showCarriedLeft(bool show)
{
mShowCarriedLeft = show;
MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ContainerStoreIterator iter = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
const MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
MWWorld::ConstContainerStoreIterator iter = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
if(show && iter != inv.end())
{
osg::Vec4f glowColor = getEnchantmentColor(*iter);

@ -56,8 +56,8 @@ WeaponAnimation::~WeaponAnimation()
void WeaponAnimation::attachArrow(MWWorld::Ptr actor)
{
MWWorld::InventoryStore& inv = actor.getClass().getInventoryStore(actor);
MWWorld::ContainerStoreIterator weaponSlot = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
const MWWorld::InventoryStore& inv = actor.getClass().getInventoryStore(actor);
MWWorld::ConstContainerStoreIterator weaponSlot = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if (weaponSlot == inv.end())
return;
if (weaponSlot->getTypeName() != typeid(ESM::Weapon).name())
@ -79,7 +79,7 @@ void WeaponAnimation::attachArrow(MWWorld::Ptr actor)
if (!parent)
return;
MWWorld::ContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition);
MWWorld::ConstContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition);
if (ammo == inv.end())
return;
std::string model = ammo->getClass().getModel(*ammo);

@ -256,9 +256,9 @@ namespace MWScript
throw std::runtime_error ("armor index out of range");
}
MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
MWWorld::ContainerStoreIterator it = invStore.getSlot (slot);
const MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
MWWorld::ConstContainerStoreIterator it = invStore.getSlot (slot);
if (it == invStore.end() || it->getTypeName () != typeid(ESM::Armor).name())
{
runtime.push(-1);
@ -289,10 +289,10 @@ namespace MWScript
std::string item = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
const MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot)
{
MWWorld::ContainerStoreIterator it = invStore.getSlot (slot);
MWWorld::ConstContainerStoreIterator it = invStore.getSlot (slot);
if (it != invStore.end() && ::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item))
{
runtime.push(1);
@ -336,8 +336,8 @@ namespace MWScript
{
MWWorld::Ptr ptr = R()(runtime);
MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
MWWorld::ContainerStoreIterator it = invStore.getSlot (MWWorld::InventoryStore::Slot_CarriedRight);
const MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
MWWorld::ConstContainerStoreIterator it = invStore.getSlot (MWWorld::InventoryStore::Slot_CarriedRight);
if (it == invStore.end() || it->getTypeName () != typeid(ESM::Weapon).name())
{
runtime.push(-1);

@ -519,7 +519,7 @@ namespace MWScript
int numNotEquipped = invStorePtr->count(item);
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot)
{
MWWorld::ContainerStoreIterator it = invStorePtr->getSlot (slot);
MWWorld::ConstContainerStoreIterator it = invStorePtr->getSlot (slot);
if (it != invStorePtr->end() && ::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item))
{
numNotEquipped -= it->getRefData().getCount();

@ -199,25 +199,12 @@ void MWWorld::InventoryStore::unequipAll(const MWWorld::Ptr& actor)
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
{
if (slot<0 || slot>=static_cast<int> (mSlots.size()))
throw std::runtime_error ("slot number out of range");
if (mSlots[slot]==end())
return end();
if (mSlots[slot]->getRefData().getCount()<1)
{
// Object has been deleted
// This should no longer happen, since the new remove function will unequip first
throw std::runtime_error("Invalid slot, make sure you are not calling RefData::setCount for a container object");
}
return mSlots[slot];
return findSlot (slot);
}
MWWorld::ConstContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot) const
{
return const_cast<InventoryStore*>(this)->getSlot (slot);
return findSlot (slot);
}
bool MWWorld::InventoryStore::canActorAutoEquip(const MWWorld::Ptr& actor, const MWWorld::Ptr& item)
@ -240,6 +227,24 @@ bool MWWorld::InventoryStore::canActorAutoEquip(const MWWorld::Ptr& actor, const
return true;
}
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::findSlot (int slot) const
{
if (slot<0 || slot>=static_cast<int> (mSlots.size()))
throw std::runtime_error ("slot number out of range");
if (mSlots[slot]==end())
return mSlots[slot];
if (mSlots[slot]->getRefData().getCount()<1)
{
// Object has been deleted
// This should no longer happen, since the new remove function will unequip first
throw std::runtime_error("Invalid slot, make sure you are not calling RefData::setCount for a container object");
}
return mSlots[slot];
}
void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor)
{
const MWBase::World *world = MWBase::Environment::get().getWorld();

@ -116,6 +116,7 @@ namespace MWWorld
virtual void readEquipmentState (const MWWorld::ContainerStoreIterator& iter, int index, const ESM::InventoryState& inventory);
bool canActorAutoEquip(const MWWorld::Ptr& actor, const MWWorld::Ptr& item);
ContainerStoreIterator findSlot (int slot) const;
public:

Loading…
Cancel
Save