Esempio n. 1
0
File: cells.cpp Progetto: 4DA/openmw
MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, Ptr::CellStore& cell)
{
    if (cell.mState==Ptr::CellStore::State_Unloaded)
        cell.preload (mStore, mReader);

    if (cell.mState==Ptr::CellStore::State_Preloaded)
    {
        std::string lowerCase = Misc::StringUtils::lowerCase(name);

        if (std::binary_search (cell.mIds.begin(), cell.mIds.end(), lowerCase))
        {
            cell.load (mStore, mReader);
            fillContainers (cell);
        }
        else
            return Ptr();
    }

    MWWorld::Ptr ptr;

    if (MWWorld::LiveCellRef<ESM::Activator> *ref = cell.mActivators.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Potion> *ref = cell.mPotions.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Apparatus> *ref = cell.mAppas.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Armor> *ref = cell.mArmors.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Book> *ref = cell.mBooks.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Clothing> *ref = cell.mClothes.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Container> *ref = cell.mContainers.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Creature> *ref = cell.mCreatures.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Door> *ref = cell.mDoors.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Ingredient> *ref = cell.mIngreds.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::CreatureLevList> *ref = cell.mCreatureLists.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::ItemLevList> *ref = cell.mItemLists.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Light> *ref = cell.mLights.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Lockpick> *ref = cell.mLockpicks.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = cell.mMiscItems.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::NPC> *ref = cell.mNpcs.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Probe> *ref = cell.mProbes.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Repair> *ref = cell.mRepairs.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Static> *ref = cell.mStatics.find (name))
        ptr = Ptr (ref, &cell);

    if (MWWorld::LiveCellRef<ESM::Weapon> *ref = cell.mWeapons.find (name))
        ptr = Ptr (ref, &cell);

    if (!ptr.isEmpty() && ptr.getRefData().getCount() > 0) {
        return ptr;
    }
    return Ptr();
}
Esempio n. 2
0
MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, Ptr::CellStore& cell)
{
    if (cell.mState==Ptr::CellStore::State_Unloaded)
        cell.preload (mStore, mReader);

    if (cell.mState==Ptr::CellStore::State_Preloaded)
    {
        std::string lowerCase;

        std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
            (int(*)(int)) std::tolower);

        if (std::binary_search (cell.mIds.begin(), cell.mIds.end(), lowerCase))
            cell.load (mStore, mReader);
        else
            return Ptr();
    }

    if (ESMS::LiveCellRef<ESM::Activator, RefData> *ref = cell.activators.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Potion, RefData> *ref = cell.potions.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Apparatus, RefData> *ref = cell.appas.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Armor, RefData> *ref = cell.armors.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Book, RefData> *ref = cell.books.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Clothing, RefData> *ref = cell.clothes.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Container, RefData> *ref = cell.containers.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Creature, RefData> *ref = cell.creatures.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Door, RefData> *ref = cell.doors.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Ingredient, RefData> *ref = cell.ingreds.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::CreatureLevList, RefData> *ref = cell.creatureLists.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::ItemLevList, RefData> *ref = cell.itemLists.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Light, RefData> *ref = cell.lights.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Tool, RefData> *ref = cell.lockpicks.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Miscellaneous, RefData> *ref = cell.miscItems.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::NPC, RefData> *ref = cell.npcs.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Probe, RefData> *ref = cell.probes.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Repair, RefData> *ref = cell.repairs.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Static, RefData> *ref = cell.statics.find (name))
        return Ptr (ref, &cell);

    if (ESMS::LiveCellRef<ESM::Weapon, RefData> *ref = cell.weapons.find (name))
        return Ptr (ref, &cell);

    return Ptr();
}