Пример #1
0
    bool Player::readRecord (ESM::ESMReader& reader, uint32_t type)
    {
        if (type==ESM::REC_PLAY)
        {
            ESM::Player player;
            player.load (reader);

            if (!mPlayer.checkState (player.mObject))
            {
                // this is the one object we can not silently drop.
                throw std::runtime_error ("invalid player state record (object state)");
            }

            mPlayer.load (player.mObject);

            for (int i=0; i<ESM::Attribute::Length; ++i)
                mSaveAttributes[i].readState(player.mSaveAttributes[i]);
            for (int i=0; i<ESM::Skill::Length; ++i)
                mSaveSkills[i].readState(player.mSaveSkills[i]);

            if (player.mObject.mNpcStats.mWerewolfDeprecatedData && player.mObject.mNpcStats.mIsWerewolf)
            {
                saveSkillsAttributes();
                setWerewolfSkillsAttributes();
            }

            getPlayer().getClass().getCreatureStats(getPlayer()).getAiSequence().clear();

            MWBase::World& world = *MWBase::Environment::get().getWorld();

            try
            {
                mCellStore = world.getCell (player.mCellId);
            }
            catch (...)
            {
                std::cerr << "Player cell '" << player.mCellId.mWorldspace << "' no longer exists" << std::endl;
                // Cell no longer exists. The loader will have to choose a default cell.
                mCellStore = NULL;
            }

            if (!player.mBirthsign.empty())
            {
                const ESM::BirthSign* sign = world.getStore().get<ESM::BirthSign>().search (player.mBirthsign);
                if (!sign)
                    throw std::runtime_error ("invalid player state record (birthsign does not exist)");

                // To handle the case where a birth sign was edited in between play sessions (does not yet handle removing the old spells)
                // Also needed for ess-imported savegames which do not specify the birtsign spells in the player's spell list.
                for (std::vector<std::string>::const_iterator iter (sign->mPowers.mList.begin());
                    iter!=sign->mPowers.mList.end(); ++iter)
                {
                    getPlayer().getClass().getCreatureStats(getPlayer()).getSpells().add (*iter);
                }
            }

            mCurrentCrimeId = player.mCurrentCrimeId;
            mPaidCrimeId = player.mPaidCrimeId;

            mSign = player.mBirthsign;

            mLastKnownExteriorPosition.x() = player.mLastKnownExteriorPosition[0];
            mLastKnownExteriorPosition.y() = player.mLastKnownExteriorPosition[1];
            mLastKnownExteriorPosition.z() = player.mLastKnownExteriorPosition[2];

            if (player.mHasMark && !player.mMarkedCell.mPaged)
            {
                // interior cell -> need to check if it exists (exterior cell will be
                // generated on the fly)

                if (!world.getStore().get<ESM::Cell>().search (player.mMarkedCell.mWorldspace))
                    player.mHasMark = false; // drop mark silently
            }

            if (player.mHasMark)
            {
                mMarkedPosition = player.mMarkedPosition;
                mMarkedCell = world.getCell (player.mMarkedCell);
            }
            else
            {
                mMarkedCell = 0;
            }

            mAutoMove = player.mAutoMove!=0;

            mForwardBackward = 0;
            mTeleported = false;

            return true;
        }

        return false;
    }
Пример #2
0
    bool Player::readRecord (ESM::ESMReader& reader, int32_t type)
    {
        if (type==ESM::REC_PLAY)
        {
            ESM::Player player;
            player.load (reader);

            if (!mPlayer.checkState (player.mObject))
            {
                // this is the one object we can not silently drop.
                throw std::runtime_error ("invalid player state record (object state)");
            }

            mPlayer.load (player.mObject);

            getPlayer().getClass().getCreatureStats(getPlayer()).getAiSequence().clear();

            MWBase::World& world = *MWBase::Environment::get().getWorld();

            try
            {
                mCellStore = world.getCell (player.mCellId);
            }
            catch (...)
            {
                // Cell no longer exists. Place the player in a default cell.
                ESM::Position pos = mPlayer.mData.getPosition();
                MWBase::Environment::get().getWorld()->indexToPosition(0, 0, pos.pos[0], pos.pos[1], true);
                pos.pos[2] = 0;
                mPlayer.mData.setPosition(pos);
                mCellStore = world.getExterior(0,0);
            }

            if (!player.mBirthsign.empty() &&
                !world.getStore().get<ESM::BirthSign>().search (player.mBirthsign))
                throw std::runtime_error ("invalid player state record (birthsign)");

            mCurrentCrimeId = player.mCurrentCrimeId;
            mPaidCrimeId = player.mPaidCrimeId;

            mSign = player.mBirthsign;

            mLastKnownExteriorPosition.x = player.mLastKnownExteriorPosition[0];
            mLastKnownExteriorPosition.y = player.mLastKnownExteriorPosition[1];
            mLastKnownExteriorPosition.z = player.mLastKnownExteriorPosition[2];

            if (player.mHasMark && !player.mMarkedCell.mPaged)
            {
                // interior cell -> need to check if it exists (exterior cell will be
                // generated on the fly)

                if (!world.getStore().get<ESM::Cell>().search (player.mMarkedCell.mWorldspace))
                    player.mHasMark = false; // drop mark silently
            }

            if (player.mHasMark)
            {
                mMarkedPosition = player.mMarkedPosition;
                mMarkedCell = world.getCell (player.mMarkedCell);
            }
            else
            {
                mMarkedCell = 0;
            }

            mAutoMove = player.mAutoMove!=0;

            mForwardBackward = 0;
            mTeleported = false;

            return true;
        }

        return false;
    }
Пример #3
0
    bool Player::readRecord (ESM::ESMReader& reader, int32_t type)
    {
        if (type==ESM::REC_PLAY)
        {
            ESM::Player player;
            player.load (reader);

            if (!mPlayer.checkState (player.mObject))
            {
                // this is the one object we can not silently drop.
                throw std::runtime_error ("invalid player state record (object state)");
            }

            mPlayer.load (player.mObject);

            MWBase::World& world = *MWBase::Environment::get().getWorld();

            mCellStore = world.getCell (player.mCellId);

            if (!player.mBirthsign.empty() &&
                !world.getStore().get<ESM::BirthSign>().search (player.mBirthsign))
                throw std::runtime_error ("invalid player state record (birthsign)");

            mCurrentCrimeId = player.mCurrentCrimeId;
            mPayedCrimeId = player.mPayedCrimeId;

            mSign = player.mBirthsign;

            mLastKnownExteriorPosition.x = player.mLastKnownExteriorPosition[0];
            mLastKnownExteriorPosition.y = player.mLastKnownExteriorPosition[1];
            mLastKnownExteriorPosition.z = player.mLastKnownExteriorPosition[2];

            if (player.mHasMark && !player.mMarkedCell.mPaged)
            {
                // interior cell -> need to check if it exists (exterior cell will be
                // generated on the fly)

                if (!world.getStore().get<ESM::Cell>().search (player.mMarkedCell.mWorldspace))
                    player.mHasMark = false; // drop mark silently
            }

            if (player.mHasMark)
            {
                mMarkedPosition = player.mMarkedPosition;
                mMarkedCell = world.getCell (player.mMarkedCell);
            }
            else
            {
                mMarkedCell = 0;
            }

            mAutoMove = player.mAutoMove!=0;

            mForwardBackward = 0;
            mTeleported = false;

            return true;
        }

        return false;
    }