00001
00002
00003
00004
00005
00006
00007
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
00040
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
00051
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
00063
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