Esempio n. 1
0
void MWState::StateManager::loadGame(const std::string& filepath)
{
    for (CharacterIterator it = mCharacterManager.begin(); it != mCharacterManager.end(); ++it)
    {
        const MWState::Character& character = *it;
        for (MWState::Character::SlotIterator slotIt = character.begin(); slotIt != character.end(); ++slotIt)
        {
            const MWState::Slot& slot = *slotIt;
            if (slot.mPath == boost::filesystem::path(filepath))
            {
                loadGame(&character, slot.mPath.string());
                return;
            }
        }
    }

    // have to peek into the save file to get the player name
    ESM::ESMReader reader;
    reader.open (filepath);
    if (reader.getRecName()!=ESM::REC_SAVE)
        return; // invalid save file -> ignore
    reader.getRecHeader();
    ESM::SavedGame profile;
    profile.load (reader);
    reader.close();

    MWState::Character* character = mCharacterManager.getCurrentCharacter(true, profile.mPlayerName);
    loadGame(character, filepath);
    mTimePlayed = profile.mTimePlayed;
}