Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

LevelLoading.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "LevelLoading.h"
00010 
00011 #include "RoomAccess.h"
00012 #include "Room.h"
00013 #include "LoadException.h"
00014 #include "minmax.h"
00015 
00016 //-----------------------------------------------------------------
00017 LevelLoading::LevelLoading(RoomAccess *access)
00018 {
00019     m_access = access;
00020     reset();
00021 }
00022 //-----------------------------------------------------------------
00023     void
00024 LevelLoading::reset()
00025 {
00026     m_paused = false;
00027     m_replayMode = false;
00028     m_loadSpeed = 1;
00029     m_loadedMoves = "";
00030 }
00031 //-----------------------------------------------------------------
00032 bool
00033 LevelLoading::isLoading() const
00034 {
00035     return !m_loadedMoves.empty() || m_replayMode;
00036 }
00037 //-----------------------------------------------------------------
00038 /**
00039  * Start loading mode.
00040  * @param moves saved moves to load
00041  */
00042     void
00043 LevelLoading::loadGame(const std::string &moves)
00044 {
00045     m_loadedMoves = moves;
00046     m_loadSpeed = min(50, max(5, m_loadedMoves.size() / 150));
00047 }
00048 //-----------------------------------------------------------------
00049 /**
00050  * Start replay mode.
00051  * @param moves saved moves to load
00052  */
00053     void
00054 LevelLoading::loadReplay(const std::string &moves)
00055 {
00056     m_loadedMoves = moves;
00057     m_loadSpeed = 1;
00058     m_replayMode = true;
00059 }
00060 //-----------------------------------------------------------------
00061 /**
00062  * Load a few moves.
00063  * @throws LoadException for bad load
00064  */
00065     void
00066 LevelLoading::nextLoadAction()
00067 {
00068     if (m_paused) {
00069         return;
00070     }
00071 
00072     if (m_loadedMoves.empty()) {
00073         m_access->room()->beginFall(false);
00074         m_access->room()->finishRound(false);
00075     }
00076     else {
00077         for (int i = 0; i < m_loadSpeed
00078                 && !m_loadedMoves.empty(); ++i)
00079         {
00080             try {
00081                 char symbol = m_loadedMoves[0];
00082                 m_loadedMoves.erase(0, 1);
00083 
00084                 m_access->room()->loadMove(symbol);
00085             }
00086             catch (LoadException &e) {
00087                 throw LoadException(ExInfo(e.info())
00088                         .addInfo("remain", m_loadedMoves));
00089             }
00090         }
00091     }
00092 }
00093 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2