summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2014-10-19 16:18:36 +0200
committerkrzys-h <krzys_h@interia.pl>2014-10-19 16:18:36 +0200
commit0245fdc6c328edf65b4fd9f45be4f440ef92b6eb (patch)
treed8237bdeacdee273c2eabaefc14f21637c1f489a
parentd7ef0a1a5f7cee44eb8faaafefb7bb78e69be1f6 (diff)
parent83abb8ca8e74176d64944e9681d74aa11ef6cdf9 (diff)
downloadcolobot-0245fdc6c328edf65b4fd9f45be4f440ef92b6eb.tar.gz
colobot-0245fdc6c328edf65b4fd9f45be4f440ef92b6eb.tar.bz2
colobot-0245fdc6c328edf65b4fd9f45be4f440ef92b6eb.zip
Merge branch 'dev-physfs' into dev
Conflicts: src/app/app.cpp
-rw-r--r--.gitignore2
-rw-r--r--.travis.yml2
-rw-r--r--CMakeLists.txt1
-rw-r--r--cmake/FindPhysFS.cmake36
m---------data0
-rw-r--r--desktop/.gitignore3
-rw-r--r--lib/localename/.gitignore1
-rw-r--r--src/CMakeLists.txt13
-rw-r--r--src/app/app.cpp120
-rw-r--r--src/app/app.h16
-rw-r--r--src/app/gamedata.cpp139
-rw-r--r--src/app/gamedata.h69
-rw-r--r--src/app/main.cpp2
-rw-r--r--src/app/pausemanager.cpp18
-rw-r--r--src/app/system.cpp10
-rw-r--r--src/app/system.h7
-rw-r--r--src/app/system_linux.cpp34
-rw-r--r--src/app/system_linux.h3
-rw-r--r--src/app/system_macosx.cpp14
-rw-r--r--src/app/system_macosx.h3
-rw-r--r--src/app/system_windows.cpp25
-rw-r--r--src/app/system_windows.h3
-rw-r--r--src/common/image.cpp14
-rw-r--r--src/common/profile.cpp58
-rw-r--r--src/common/profile.h3
-rw-r--r--src/common/resources/inputstream.cpp61
-rw-r--r--src/common/resources/inputstream.h37
-rw-r--r--src/common/resources/inputstreambuffer.cpp132
-rw-r--r--src/common/resources/inputstreambuffer.h51
-rw-r--r--src/common/resources/outputstream.cpp55
-rw-r--r--src/common/resources/outputstream.h36
-rw-r--r--src/common/resources/outputstreambuffer.cpp89
-rw-r--r--src/common/resources/outputstreambuffer.h46
-rw-r--r--src/common/resources/resourcemanager.cpp280
-rw-r--r--src/common/resources/resourcemanager.h63
-rw-r--r--src/common/resources/sndfile.cpp133
-rw-r--r--src/common/resources/sndfile.h49
-rw-r--r--src/graphics/engine/cloud.cpp6
-rw-r--r--src/graphics/engine/engine.cpp49
-rw-r--r--src/graphics/engine/lightning.cpp2
-rw-r--r--src/graphics/engine/modelfile.cpp20
-rw-r--r--src/graphics/engine/modelmanager.cpp7
-rw-r--r--src/graphics/engine/particle.cpp8
-rw-r--r--src/graphics/engine/planet.cpp4
-rw-r--r--src/graphics/engine/pyro.cpp4
-rw-r--r--src/graphics/engine/terrain.cpp19
-rw-r--r--src/graphics/engine/text.cpp22
-rw-r--r--src/graphics/engine/water.cpp6
-rw-r--r--src/object/auto/autobase.cpp4
-rw-r--r--src/object/level/parser.cpp244
-rw-r--r--src/object/level/parser.h69
-rw-r--r--src/object/level/parserexceptions.cpp45
-rw-r--r--src/object/level/parserexceptions.h55
-rw-r--r--src/object/level/parserline.cpp90
-rw-r--r--src/object/level/parserline.h62
-rw-r--r--src/object/level/parserparam.cpp940
-rw-r--r--src/object/level/parserparam.h137
-rw-r--r--src/object/robotmain.cpp1371
-rw-r--r--src/object/robotmain.h12
-rw-r--r--src/script/cmdtoken.cpp2
-rw-r--r--src/script/script.cpp52
-rw-r--r--src/sound/oalsound/alsound.cpp23
-rw-r--r--src/sound/oalsound/alsound.h67
-rw-r--r--src/sound/oalsound/buffer.cpp33
-rw-r--r--src/sound/sound.cpp2
-rw-r--r--src/ui/button.cpp2
-rw-r--r--src/ui/check.cpp2
-rw-r--r--src/ui/color.cpp2
-rw-r--r--src/ui/compass.cpp2
-rw-r--r--src/ui/control.cpp14
-rw-r--r--src/ui/displayinfo.cpp282
-rw-r--r--src/ui/displayinfo.h1
-rw-r--r--src/ui/edit.cpp83
-rw-r--r--src/ui/gauge.cpp2
-rw-r--r--src/ui/group.cpp60
-rw-r--r--src/ui/image.cpp8
-rw-r--r--src/ui/key.cpp2
-rw-r--r--src/ui/list.cpp10
-rw-r--r--src/ui/maindialog.cpp265
-rw-r--r--src/ui/maindialog.h7
-rw-r--r--src/ui/map.cpp34
-rw-r--r--src/ui/scroll.cpp8
-rw-r--r--src/ui/shortcut.cpp6
-rw-r--r--src/ui/slider.cpp6
-rw-r--r--src/ui/studio.cpp1
-rw-r--r--src/ui/window.cpp38
-rw-r--r--test/envs/CMakeLists.txt3
-rw-r--r--test/unit/common/profile_test.cpp1
-rwxr-xr-xtools/check-levels.sh18
89 files changed, 3933 insertions, 1907 deletions
diff --git a/.gitignore b/.gitignore
index 6a031c6..3dae3d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,8 @@ Makefile
/install_manifest.txt
/Testing
/CTestTestfile.cmake
+/CPackConfig.cmake
+/CPackSourceConfig.cmake
# Ignore the generated documentation
/doc
diff --git a/.travis.yml b/.travis.yml
index 1abfb51..e1ed6ab 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,6 @@ before_install:
- git submodule update --init --recursive
- sudo add-apt-repository ppa:mapnik/boost -y
- sudo apt-get update -qq
- - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libglew-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin libsndfile-dev libopenal-dev
+ - sudo apt-get install -qq --no-install-recommends libgl1-mesa-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev libpng12-dev libglew-dev libboost-dev libboost-system-dev libboost-filesystem-dev libboost-regex-dev google-mock libgtest-dev doxygen graphviz po4a librsvg2-bin libsndfile-dev libopenal-dev libphysfs-dev
notifications:
email: false
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0d1416..b69586e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -209,6 +209,7 @@ find_package(SDL_image 1.2 REQUIRED)
find_package(SDL_ttf 2.0 REQUIRED)
find_package(PNG 1.2 REQUIRED)
find_package(Gettext REQUIRED)
+find_package(PhysFS REQUIRED)
set(Boost_USE_STATIC_LIBS ${BOOST_STATIC})
set(Boost_USE_MULTITHREADED ON)
diff --git a/cmake/FindPhysFS.cmake b/cmake/FindPhysFS.cmake
new file mode 100644
index 0000000..fae8378
--- /dev/null
+++ b/cmake/FindPhysFS.cmake
@@ -0,0 +1,36 @@
+# PHYSFS_FOUND
+# PHYSFS_INCLUDE_PATH
+# PHYSFS_LIBRARY
+#
+
+IF (WIN32)
+ FIND_PATH( PHYSFS_INCLUDE_PATH physfs.h
+ DOC "The directory where physfs.h resides")
+ FIND_LIBRARY( PHYSFS_LIBRARY
+ NAMES physfs
+ PATHS /mingw/lib
+ DOC "The PhysFS library")
+ELSE (WIN32)
+ FIND_PATH( PHYSFS_INCLUDE_PATH physfs.h
+ /usr/include
+ /usr/local/include
+ /opt/local/include
+ DOC "The directory where physfs.h resides")
+ FIND_LIBRARY( PHYSFS_LIBRARY
+ NAMES physfs
+ PATHS
+ /usr/lib64
+ /usr/lib
+ /usr/local/lib64
+ /usr/local/lib
+ /opt/local/lib
+ DOC "The PhysFS library")
+ENDIF (WIN32)
+
+IF (PHYSFS_INCLUDE_PATH)
+ SET( PHYSFS_FOUND 1 CACHE STRING "Set to 1 if PhysFS is found, 0 otherwise")
+ELSE (GLEW_INCLUDE_PATH)
+ SET( PHYSFS_FOUND 0 CACHE STRING "Set to 1 if PhysFS is found, 0 otherwise")
+ENDIF (PHYSFS_INCLUDE_PATH)
+
+MARK_AS_ADVANCED( PHYSFS_FOUND )
diff --git a/data b/data
-Subproject 89158ea0b4876e3c75209df2ee1679076ffca7b
+Subproject e19711d1909b43d269e4a725d5a20d916180acf
diff --git a/desktop/.gitignore b/desktop/.gitignore
index e6649e0..b3d4193 100644
--- a/desktop/.gitignore
+++ b/desktop/.gitignore
@@ -3,5 +3,8 @@ fr/
16/
32/
48/
+128/
+256/
+512/
colobot.6
colobot.desktop
diff --git a/lib/localename/.gitignore b/lib/localename/.gitignore
new file mode 100644
index 0000000..c42756f
--- /dev/null
+++ b/lib/localename/.gitignore
@@ -0,0 +1 @@
+liblocalename.a
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fbbaa37..869f0cb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -61,7 +61,6 @@ endif()
# Source files
set(BASE_SOURCES
app/app.cpp
- app/gamedata.cpp
app/pausemanager.cpp
app/system.cpp
app/${SYSTEM_CPP_MODULE}
@@ -74,6 +73,12 @@ set(BASE_SOURCES
common/profile.cpp
common/restext.cpp
common/stringutils.cpp
+ common/resources/resourcemanager.cpp
+ common/resources/inputstreambuffer.cpp
+ common/resources/outputstreambuffer.cpp
+ common/resources/inputstream.cpp
+ common/resources/outputstream.cpp
+ common/resources/sndfile.cpp
graphics/core/color.cpp
graphics/engine/camera.cpp
graphics/engine/cloud.cpp
@@ -116,6 +121,10 @@ set(BASE_SOURCES
object/auto/autostation.cpp
object/auto/autotower.cpp
object/brain.cpp
+ object/level/parser.cpp
+ object/level/parserline.cpp
+ object/level/parserparam.cpp
+ object/level/parserexceptions.cpp
object/mainmovie.cpp
object/motion/motion.cpp
object/motion/motionant.cpp
@@ -206,6 +215,7 @@ set(LIBS
${LIBSNDFILE_LIBRARY}
${OPTIONAL_LIBS}
${PLATFORM_LIBS}
+${PHYSFS_LIBRARY}
)
set(COLOBOT_LIBS ${LIBS} PARENT_SCOPE)
@@ -229,6 +239,7 @@ set(SYSTEM_INCLUDES
${LOCALENAME_INCLUDE_DIR}
${OPTIONAL_INCLUDE_DIRS}
${CLIPBOARD_INCLUDE_DIR}
+${PHYSFS_INCLUDE_PATH}
)
set(COLOBOT_LOCAL_INCLUDES ${LOCAL_INCLUDES} PARENT_SCOPE)
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 77930ed..06e3f01 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -21,7 +21,6 @@
#include "app/app.h"
-#include "app/gamedata.h"
#include "app/system.h"
#include "common/logger.h"
@@ -29,6 +28,7 @@
#include "common/image.h"
#include "common/key.h"
#include "common/stringutils.h"
+#include "common/resources/resourcemanager.h"
#include "graphics/engine/modelmanager.h"
#include "graphics/opengl/gldevice.h"
@@ -103,7 +103,6 @@ CApplication::CApplication()
m_objMan = new CObjectManager();
m_eventQueue = new CEventQueue();
m_profile = new CProfile();
- m_gameData = new CGameData();
m_engine = nullptr;
m_device = nullptr;
@@ -114,7 +113,6 @@ CApplication::CApplication()
m_exitCode = 0;
m_active = false;
m_debugModes = 0;
- m_customDataPath = false;
m_windowTitle = "COLOBOT: Gold Edition";
@@ -157,11 +155,17 @@ CApplication::CApplication()
#else
m_dataPath = GetSystemUtils()->GetDataPath();
m_langPath = GetSystemUtils()->GetLangPath();
+ #endif
+
+ #ifdef DEV_BUILD
+ m_savePath = "./saves";
+ #else
+ m_savePath = GetSystemUtils()->GetSaveDir();
#endif
m_runSceneName = "";
m_runSceneRank = 0;
-
+
m_sceneTest = false;
m_language = LANGUAGE_ENV;
@@ -187,9 +191,6 @@ CApplication::~CApplication()
delete m_iMan;
m_iMan = nullptr;
-
- delete m_gameData;
- m_gameData = nullptr;
GetSystemUtils()->DestroyTimeStamp(m_baseTimeStamp);
GetSystemUtils()->DestroyTimeStamp(m_curTimeStamp);
@@ -222,9 +223,10 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
OPT_SCENETEST,
OPT_LOGLEVEL,
OPT_LANGUAGE,
+ OPT_LANGDIR,
OPT_DATADIR,
+ OPT_SAVEDIR,
OPT_MOD,
- OPT_LANGDIR,
OPT_VBO
};
@@ -236,9 +238,10 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
{ "scenetest", no_argument, nullptr, OPT_SCENETEST },
{ "loglevel", required_argument, nullptr, OPT_LOGLEVEL },
{ "language", required_argument, nullptr, OPT_LANGUAGE },
+ { "langdir", required_argument, nullptr, OPT_LANGDIR },
{ "datadir", required_argument, nullptr, OPT_DATADIR },
+ { "savedir", required_argument, nullptr, OPT_SAVEDIR },
{ "mod", required_argument, nullptr, OPT_MOD },
- { "langdir", required_argument, nullptr, OPT_LANGDIR },
{ "vbo", required_argument, nullptr, OPT_VBO },
{ nullptr, 0, nullptr, 0}
};
@@ -276,9 +279,10 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
GetLogger()->Message(" -scenetest win every mission right after it's loaded\n");
GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n");
GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl, ru)\n");
- GetLogger()->Message(" -datadir path set custom data directory path\n");
- GetLogger()->Message(" -mod path run mod\n");
GetLogger()->Message(" -langdir path set custom language directory path\n");
+ GetLogger()->Message(" -datadir path set custom data directory path\n");
+ GetLogger()->Message(" -savedir path set custom save directory path (must be writable)\n");
+ GetLogger()->Message(" -mod path load datadir mod from given path\n");
GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n");
return PARSE_ARGS_HELP;
}
@@ -341,25 +345,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
m_language = language;
break;
}
- case OPT_DATADIR:
- {
- m_dataPath = optarg;
- m_customDataPath = true;
- GetLogger()->Info("Using datadir: '%s'\n", optarg);
- break;
- }
- case OPT_MOD:
- {
- m_gameData->AddMod(std::string(optarg));
- GetLogger()->Info("Running mod from path: '%s'\n", optarg);
- break;
- }
- case OPT_LANGDIR:
- {
- m_langPath = optarg;
- GetLogger()->Info("Using language dir: '%s'\n", m_langPath.c_str());
- break;
- }
case OPT_VBO:
{
std::string vbo;
@@ -378,6 +363,30 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
break;
}
+ case OPT_DATADIR:
+ {
+ m_dataPath = optarg;
+ GetLogger()->Info("Using data dir: '%s'\n", optarg);
+ break;
+ }
+ case OPT_LANGDIR:
+ {
+ m_langPath = optarg;
+ GetLogger()->Info("Using language dir: '%s'\n", optarg);
+ break;
+ }
+ case OPT_SAVEDIR:
+ {
+ m_savePath = optarg;
+ GetLogger()->Info("Using save dir: '%s'\n", optarg);
+ break;
+ }
+ case OPT_MOD:
+ {
+ GetLogger()->Info("Loading mod: '%s'\n", optarg);
+ CResourceManager::AddLocation(optarg, true);
+ break;
+ }
default:
assert(false); // should never get here
}
@@ -393,30 +402,32 @@ bool CApplication::Create()
GetLogger()->Info("Creating CApplication\n");
- if (!GetProfile().Init())
- {
- GetLogger()->Warn("Config not found. Default values will be used!\n");
- defaultValues = true;
- }
- else
- {
- if (!m_customDataPath && GetProfile().GetStringProperty("Resources", "Data", path))
- m_dataPath = path;
- }
-
boost::filesystem::path dataPath(m_dataPath);
if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) )
{
GetLogger()->Error("Data directory '%s' doesn't exist or is not a directory\n", m_dataPath.c_str());
m_errorMessage = std::string("Could not read from data directory:\n") +
- std::string("'") + m_dataPath + std::string("'\n") +
- std::string("Please check your installation, or supply a valid data directory by -datadir option.");
+ std::string("'") + m_dataPath + std::string("'\n") +
+ std::string("Please check your installation, or supply a valid data directory by -datadir option.");
m_exitCode = 1;
return false;
}
-
- m_gameData->SetDataDir(std::string(m_dataPath));
- m_gameData->Init();
+
+ boost::filesystem::create_directories(m_savePath);
+ boost::filesystem::create_directories(m_savePath+"/mods");
+
+ LoadModsFromDir(m_dataPath+"/mods");
+ LoadModsFromDir(m_savePath+"/mods");
+
+ CResourceManager::AddLocation(m_dataPath, false);
+ CResourceManager::SetSaveLocation(m_savePath);
+ CResourceManager::AddLocation(m_savePath, true);
+
+ if (!GetProfile().Init())
+ {
+ GetLogger()->Warn("Config not found. Default values will be used!\n");
+ defaultValues = true;
+ }
if (GetProfile().GetStringProperty("Language", "Lang", path)) {
Language language;
@@ -601,6 +612,23 @@ bool CApplication::CreateVideoSurface()
return true;
}
+void CApplication::LoadModsFromDir(const std::string &dir)
+{
+ try {
+ boost::filesystem::directory_iterator iterator(dir);
+ for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
+ {
+ std::string fn = iterator->path().string();
+ CLogger::GetInstancePointer()->Info("Loading mod: '%s'\n", fn.c_str());
+ CResourceManager::AddLocation(fn, false);
+ }
+ }
+ catch(std::exception &e)
+ {
+ CLogger::GetInstancePointer()->Warn("Unable to load mods from directory '%s': %s\n", dir.c_str(), e.what());
+ }
+}
+
void CApplication::Destroy()
{
m_joystickEnabled = false;
diff --git a/src/app/app.h b/src/app/app.h
index 21ece4c..c73cb53 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -44,7 +44,6 @@ class CInstanceManager;
class CEventQueue;
class CRobotMain;
class CSoundInterface;
-class CGameData;
namespace Gfx {
class CModelManager;
@@ -357,6 +356,9 @@ public:
protected:
//! Creates the window's SDL_Surface
bool CreateVideoSurface();
+
+ //! Loads all mods from given directory
+ void LoadModsFromDir(const std::string &dir);
//! Processes the captured SDL event to Event struct
Event ProcessSystemEvent();
@@ -404,8 +406,6 @@ protected:
CRobotMain* m_robotMain;
//! Profile (INI) reader/writer
CProfile* m_profile;
- //! Game data
- CGameData* m_gameData;
//! Code to return at exit
int m_exitCode;
@@ -469,16 +469,16 @@ protected:
std::vector<int> m_joyAxeState;
//! Current state of joystick buttons; may be updated from another thread
std::vector<bool> m_joyButtonState;
-
+
//! Path to directory with data files
std::string m_dataPath;
-
- //! True if datadir was passed in command line
- bool m_customDataPath;
-
+
//! Path to directory with language files
std::string m_langPath;
+ //! Path to directory with save files
+ std::string m_savePath;
+
//@{
//! Scene to run on startup
std::string m_runSceneName;
diff --git a/src/app/gamedata.cpp b/src/app/gamedata.cpp
deleted file mode 100644
index f758716..0000000
--- a/src/app/gamedata.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * This file is part of the Colobot: Gold Edition source code
- * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
- * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://gnu.org/licenses
- */
-
-#include "app/gamedata.h"
-
-
-#include "app/app.h"
-
-#include <boost/filesystem.hpp>
-
-template<> CGameData* CSingleton<CGameData>::m_instance = nullptr;
-
-CGameData::CGameData()
-{
- m_dataDirSet = false;
-
- for (int i = 0; i < DIR_MAX; ++i)
- m_standardDataDirs[i] = nullptr;
-
- m_standardDataDirs[DIR_AI] = "ai";
- m_standardDataDirs[DIR_FONT] = "fonts";
- m_standardDataDirs[DIR_HELP] = "help";
- m_standardDataDirs[DIR_ICON] = "icons";
- m_standardDataDirs[DIR_LEVEL] = "levels";
- m_standardDataDirs[DIR_MODEL] = "models";
- m_standardDataDirs[DIR_MUSIC] = "music";
- m_standardDataDirs[DIR_SOUND] = "sounds";
- m_standardDataDirs[DIR_TEXTURE] = "textures";
-}
-
-CGameData::~CGameData()
-{
-}
-
-void CGameData::SetDataDir(std::string path)
-{
- assert(!m_dataDirSet);
- m_dataDirSet = true;
-
- m_dataDirs.insert(m_dataDirs.begin(), path);
-}
-
-void CGameData::AddMod(std::string path)
-{
- m_dataDirs.push_back(path);
-}
-
-void CGameData::Init()
-{
- std::string out = "Using datadirs: ";
- bool first = true;
- for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) {
- if(!first) out += ", ";
- first = false;
- out += *rit;
- }
- out += "\n";
- CLogger::GetInstancePointer()->Info(out.c_str());
-}
-
-std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath)
-{
- int index = static_cast<int>(dir);
- assert(index >= 0 && index < DIR_MAX);
-
- for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) {
- std::stringstream str;
-
- if ( subpath.find("save") == std::string::npos ){ // if its NOT a path to a savefile screenshot
- str << *rit;
- str << "/";
- str << m_standardDataDirs[index];
-
- if (dir == DIR_HELP)
- {
- str << "/";
- str << CApplication::GetInstancePointer()->GetLanguageChar();
- }
- str << "/";
- }
-
- str << subpath;
-
- boost::filesystem::path path(str.str());
- if(boost::filesystem::exists(path))
- {
- return str.str();
- }
- }
-
- if(m_dataDirs.size() > 0) {
- std::stringstream str;
- if ( subpath.find("save") == std::string::npos ){ // if its NOT a path to a savefile screenshot
- str << m_dataDirs[0];
- str << "/";
- str << m_standardDataDirs[index];
-
- if (dir == DIR_HELP)
- {
- str << "/";
- str << CApplication::GetInstancePointer()->GetLanguageChar();
- }
- str << "/";
- }
- str << subpath;
- return str.str();
- }
-
- return subpath;
-}
-
-std::string CGameData::GetDataPath(const std::string &subpath)
-{
- for(std::vector<std::string>::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) {
- std::string path = *rit + "/" + subpath;
- boost::filesystem::path boostPath(path);
- if(boost::filesystem::exists(boostPath))
- {
- return path;
- }
- }
- return m_dataDirs[0] + "/" + subpath;
-}
diff --git a/src/app/gamedata.h b/src/app/gamedata.h
deleted file mode 100644
index 1164d60..0000000
--- a/src/app/gamedata.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * This file is part of the Colobot: Gold Edition source code
- * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
- * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://gnu.org/licenses
- */
-
-/**
- * \file app/gamedata.h
- * \brief Game data
- */
-
-#pragma once
-
-#include "common/singleton.h"
-
-#include <string>
-#include <vector>
-
-/**
- * \enum DataDir
- * \brief Directories in data directory
- */
-enum DataDir
-{
- DIR_AI, //! < ai scripts
- DIR_FONT, //! < fonts
- DIR_HELP, //! < help files
- DIR_ICON, //! < icons & images
- DIR_LEVEL, //! < levels
- DIR_MODEL, //! < models
- DIR_MUSIC, //! < music
- DIR_SOUND, //! < sounds
- DIR_TEXTURE, //! < textures
-
- DIR_MAX //! < number of dirs
-};
-
-class CGameData : public CSingleton<CGameData>
-{
-public:
- CGameData();
- ~CGameData();
-
- void Init();
- void SetDataDir(std::string path);
- void AddMod(std::string path);
-
- std::string GetFilePath(DataDir dir, const std::string &subpath);
- std::string GetDataPath(const std::string &subpath);
-
-private:
- bool m_dataDirSet;
- std::vector<std::string> m_dataDirs;
- const char* m_standardDataDirs[DIR_MAX];
-};
-
diff --git a/src/app/main.cpp b/src/app/main.cpp
index 27952db..e30a83d 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -71,6 +71,7 @@ The current layout is the following:
- src/script - link with the CBot library
*/
+#include "common/resources/resourcemanager.h"
//! Entry point to the program
extern "C"
@@ -79,6 +80,7 @@ extern "C"
int SDL_MAIN_FUNC(int argc, char *argv[])
{
CLogger logger; // single istance of logger
+ CResourceManager manager(argv[0]);
// Initialize static string arrays
InitializeRestext();
diff --git a/src/app/pausemanager.cpp b/src/app/pausemanager.cpp
index 3376ae4..b28565f 100644
--- a/src/app/pausemanager.cpp
+++ b/src/app/pausemanager.cpp
@@ -31,7 +31,7 @@ template<> CPauseManager* CSingleton<CPauseManager>::m_instance = nullptr;
CPauseManager::CPauseManager()
{
m_sound = CApplication::GetInstancePointer()->GetSound();
-
+
m_pause = PAUSE_NONE;
}
@@ -42,24 +42,28 @@ CPauseManager::~CPauseManager()
void CPauseManager::SetPause(PauseType pause)
{
- if(pause != PAUSE_NONE) {
- if(m_pause != pause) {
+ if (pause != PAUSE_NONE)
+ {
+ if (m_pause != pause)
+ {
CLogger::GetInstancePointer()->Info("Game paused - %s\n", GetPauseName(pause).c_str());
CRobotMain::GetInstancePointer()->StartPauseMusic(pause);
}
-
+
m_pause = pause;
- } else
+ }
+ else
ClearPause();
}
void CPauseManager::ClearPause()
{
- if(m_pause != PAUSE_NONE) {
+ if(m_pause != PAUSE_NONE)
+ {
CLogger::GetInstancePointer()->Info("Game resumed\n");
m_sound->StopPauseMusic();
}
-
+
m_pause = PAUSE_NONE;
}
diff --git a/src/app/system.cpp b/src/app/system.cpp
index 118bc80..2ceea6a 100644
--- a/src/app/system.cpp
+++ b/src/app/system.cpp
@@ -204,13 +204,7 @@ std::string CSystemUtils::GetLangPath()
return COLOBOT_I18N_DIR;
}
-std::string CSystemUtils::GetProfileFileLocation()
+std::string CSystemUtils::GetSaveDir()
{
- return std::string("colobot.ini");
+ return std::string("save");
}
-
-std::string CSystemUtils::GetSavegameDirectoryLocation()
-{
- return std::string("savegame");
-}
-
diff --git a/src/app/system.h b/src/app/system.h
index 36e558a..d52020b 100644
--- a/src/app/system.h
+++ b/src/app/system.h
@@ -138,11 +138,8 @@ public:
//! Returns the translations path
virtual std::string GetLangPath();
- //! Returns the profile (colobot.ini) file location
- virtual std::string GetProfileFileLocation();
-
- //! Returns the savegame directory location
- virtual std::string GetSavegameDirectoryLocation();
+ //! Returns the save dir location
+ virtual std::string GetSaveDir();
};
//! Global function to get CSystemUtils instance
diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp
index a10e371..6fbfb05 100644
--- a/src/app/system_linux.cpp
+++ b/src/app/system_linux.cpp
@@ -27,7 +27,7 @@
void CSystemUtilsLinux::Init()
{
m_zenityAvailable = true;
- if (system("zenity --version") != 0)
+ if (system("zenity --version 1> /dev/null 2> /dev/null") != 0)
{
m_zenityAvailable = false;
GetLogger()->Warn("Zenity not available, will fallback to console users dialogs.\n");
@@ -97,34 +97,7 @@ long long CSystemUtilsLinux::TimeStampExactDiff(SystemTimeStamp *before, SystemT
(after->clockTime.tv_sec - before->clockTime.tv_sec) * 1000000000ll;
}
-std::string CSystemUtilsLinux::GetProfileFileLocation()
-{
- std::string profileFile;
-
- // Determine profileFile according to XDG Base Directory Specification
- char* envXDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
- if (envXDG_CONFIG_HOME == NULL)
- {
- char *envHOME = getenv("HOME");
- if (envHOME == NULL)
- {
- profileFile = "colobot.ini";
- }
- else
- {
- profileFile = std::string(envHOME) + "/.config/colobot.ini";
- }
- }
- else
- {
- profileFile = std::string(envXDG_CONFIG_HOME) + "/colobot.ini";
- }
- GetLogger()->Trace("Profile configuration is %s\n", profileFile.c_str());
-
- return profileFile;
-}
-
-std::string CSystemUtilsLinux::GetSavegameDirectoryLocation()
+std::string CSystemUtilsLinux::GetSaveDir()
{
std::string savegameDir;
@@ -135,7 +108,7 @@ std::string CSystemUtilsLinux::GetSavegameDirectoryLocation()
char *envHOME = getenv("HOME");
if (envHOME == NULL)
{
- savegameDir = "/tmp/colobot-savegame";
+ savegameDir = "/tmp/colobot-save";
}
else
{
@@ -150,4 +123,3 @@ std::string CSystemUtilsLinux::GetSavegameDirectoryLocation()
return savegameDir;
}
-
diff --git a/src/app/system_linux.h b/src/app/system_linux.h
index 2b32660..5f4fcc3 100644
--- a/src/app/system_linux.h
+++ b/src/app/system_linux.h
@@ -48,8 +48,7 @@ public:
virtual long long GetTimeStampExactResolution() override;
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override;
- virtual std::string GetProfileFileLocation() override;
- virtual std::string GetSavegameDirectoryLocation() override;
+ virtual std::string GetSaveDir() override;
private:
bool m_zenityAvailable;
diff --git a/src/app/system_macosx.cpp b/src/app/system_macosx.cpp
index c44831f..208b4a7 100644
--- a/src/app/system_macosx.cpp
+++ b/src/app/system_macosx.cpp
@@ -99,20 +99,10 @@ std::string CSystemUtilsMacOSX::GetLangPath()
return m_dataPath + "/i18n";
}
-std::string CSystemUtilsMacOSX::GetProfileFileLocation()
+std::string CSystemUtilsMacOSX::GetSaveDir()
{
- std::string profileFile = m_ASPath + "/colobot.ini";
-
- GetLogger()->Trace("Profile file is %s\n", profileFile.c_str());
- return profileFile;
-}
-
-std::string CSystemUtilsMacOSX::GetSavegameDirectoryLocation()
-{
- std::string savegameDir = m_ASPath + "/savegame";
- boost::filesystem::create_directories(savegameDir.c_str());
+ std::string savegameDir = m_ASPath;
GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
return savegameDir;
}
-
diff --git a/src/app/system_macosx.h b/src/app/system_macosx.h
index 39c5702..9063aab 100644
--- a/src/app/system_macosx.h
+++ b/src/app/system_macosx.h
@@ -32,8 +32,7 @@ public:
virtual std::string GetDataPath() override;
virtual std::string GetLangPath() override;
- virtual std::string GetProfileFileLocation() override;
- virtual std::string GetSavegameDirectoryLocation() override;
+ virtual std::string GetSaveDir() override;
private:
std::string m_ASPath;
std::string m_dataPath;
diff --git a/src/app/system_windows.cpp b/src/app/system_windows.cpp
index 9f4cd2c..a2ea18f 100644
--- a/src/app/system_windows.cpp
+++ b/src/app/system_windows.cpp
@@ -113,39 +113,20 @@ std::wstring CSystemUtilsWindows::UTF8_Decode(const std::string& str)
}
-std::string CSystemUtilsWindows::GetProfileFileLocation()
-{
- std::string profileFile;
-
- char* envUSERPROFILE = getenv("USERPROFILE");
- if (envUSERPROFILE == NULL)
- {
- profileFile = "colobot.ini";
- }
- else
- {
- profileFile = std::string(envUSERPROFILE) + "\\colobot\\colobot.ini";
- }
- GetLogger()->Trace("Profile configuration is %s\n", profileFile.c_str());
-
- return profileFile;
-}
-
-std::string CSystemUtilsWindows::GetSavegameDirectoryLocation()
+std::string CSystemUtilsWindows::GetSaveDir()
{
std::string savegameDir;
char* envUSERPROFILE = getenv("USERPROFILE");
if (envUSERPROFILE == NULL)
{
- savegameDir = "savegame";
+ savegameDir = "save";
}
else
{
- savegameDir = std::string(envUSERPROFILE) + "\\colobot\\savegame";
+ savegameDir = std::string(envUSERPROFILE) + "\\colobot";
}
GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
return savegameDir;
}
-
diff --git a/src/app/system_windows.h b/src/app/system_windows.h
index 2d8e146..9175a44 100644
--- a/src/app/system_windows.h
+++ b/src/app/system_windows.h
@@ -46,8 +46,7 @@ public:
virtual long long GetTimeStampExactResolution() override;
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override;
- virtual std::string GetProfileFileLocation() override;
- virtual std::string GetSavegameDirectoryLocation() override;
+ virtual std::string GetSaveDir() override;
private:
std::string UTF8_Encode(const std::wstring &wstr);
diff --git a/src/common/image.cpp b/src/common/image.cpp
index e9cf422..f241f83 100644
--- a/src/common/image.cpp
+++ b/src/common/image.cpp
@@ -21,6 +21,7 @@
#include "common/image.h"
#include "math/func.h"
+#include "common/resources/resourcemanager.h"
#include <stdlib.h>
#include <stdio.h>
@@ -384,7 +385,16 @@ bool CImage::Load(const std::string& fileName)
m_error = "";
- m_data->surface = IMG_Load(fileName.c_str());
+ SDL_RWops* pointer = CResourceManager::GetSDLFileHandler(fileName.c_str());
+ if (pointer == nullptr)
+ {
+ delete m_data;
+ m_data = nullptr;
+
+ m_error = "Unable to open file";
+ return false;
+ }
+ m_data->surface = IMG_Load_RW(pointer, 1);
if (m_data->surface == nullptr)
{
delete m_data;
@@ -461,4 +471,4 @@ void CImage::flipVertically(){
SDL_FreeSurface(m_data->surface);
m_data->surface = result;
-} \ No newline at end of file
+}
diff --git a/src/common/profile.cpp b/src/common/profile.cpp
index fa7aa26..92fc1d6 100644
--- a/src/common/profile.cpp
+++ b/src/common/profile.cpp
@@ -20,10 +20,13 @@
#include "common/profile.h"
+#include "common/resources/inputstream.h"
+#include "common/resources/outputstream.h"
#include "app/system.h"
#include "common/logger.h"
+#include <memory>
#include <utility>
#include <cstring>
#include <boost/property_tree/ini_parser.hpp>
@@ -51,16 +54,34 @@ void CProfile::SetUseCurrentDirectory(bool useCurrentDirectory)
m_useCurrentDirectory = useCurrentDirectory;
}
-std::string CProfile::GetIniFileLocation()
-{
- return m_useCurrentDirectory ? "colobot.ini" : GetSystemUtils()->GetProfileFileLocation();
-}
-
bool CProfile::Init()
{
try
{
- bp::ini_parser::read_ini(GetIniFileLocation(), m_propertyTree);
+ std::unique_ptr<std::istream> stream;
+ bool good;
+ if (m_useCurrentDirectory)
+ {
+ std::ifstream* inputStream = new std::ifstream("./colobot.ini");
+ stream = std::unique_ptr<std::istream>(inputStream);
+ good = inputStream->good();
+ }
+ else
+ {
+ CInputStream* inputStream = new CInputStream("colobot.ini");
+ stream = std::unique_ptr<std::istream>(inputStream);
+ good = inputStream->is_open();
+ }
+
+ if (good)
+ {
+ bp::ini_parser::read_ini(*stream, m_propertyTree);
+ }
+ else
+ {
+ GetLogger()->Error("Error on parsing profile: failed to open file\n");
+ return false;
+ }
}
catch (std::exception & e)
{
@@ -76,7 +97,30 @@ bool CProfile::Save()
{
try
{
- bp::ini_parser::write_ini(GetIniFileLocation(), m_propertyTree);
+ std::unique_ptr<std::ostream> stream;
+ bool good;
+ if (m_useCurrentDirectory)
+ {
+ std::ofstream* outputStream = new std::ofstream("./colobot.ini");
+ stream = std::unique_ptr<std::ostream>(outputStream);
+ good = outputStream->good();
+ }
+ else
+ {
+ COutputStream* outputStream = new COutputStream("colobot.ini");
+ stream = std::unique_ptr<std::ostream>(outputStream);
+ good = outputStream->is_open();
+ }
+
+ if (good)
+ {
+ bp::ini_parser::write_ini(*stream, m_propertyTree);
+ }
+ else
+ {
+ GetLogger()->Error("Error on storing profile: failed to open file\n");
+ return false;
+ }
}
catch (std::exception & e)
{
diff --git a/src/common/profile.h b/src/common/profile.h
index c53c2f6..444975c 100644
--- a/src/common/profile.h
+++ b/src/common/profile.h
@@ -136,9 +136,6 @@ public:
bool CopyFileToTemp(std::string filename);
private:
- std::string GetIniFileLocation();
-
-private:
boost::property_tree::ptree m_propertyTree;
bool m_profileNeedSave;
std::string m_userDirectory;
diff --git a/src/common/resources/inputstream.cpp b/src/common/resources/inputstream.cpp
new file mode 100644
index 0000000..57d1305
--- /dev/null
+++ b/src/common/resources/inputstream.cpp
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "common/resources/inputstream.h"
+#include "common/resources/inputstreambuffer.h"
+
+
+CInputStream::CInputStream() : std::istream(new CInputStreamBuffer())
+{
+}
+
+CInputStream::CInputStream(const std::string& filename) : std::istream(new CInputStreamBuffer())
+{
+ open(filename);
+}
+
+
+CInputStream::~CInputStream()
+{
+ delete rdbuf();
+}
+
+
+void CInputStream::open(const std::string& filename)
+{
+ static_cast<CInputStreamBuffer *>(rdbuf())->open(filename);
+}
+
+
+void CInputStream::close()
+{
+ static_cast<CInputStreamBuffer *>(rdbuf())->close();
+}
+
+
+bool CInputStream::is_open()
+{
+ return static_cast<CInputStreamBuffer *>(rdbuf())->is_open();
+}
+
+
+size_t CInputStream::size()
+{
+ return static_cast<CInputStreamBuffer *>(rdbuf())->size();
+}
diff --git a/src/common/resources/inputstream.h b/src/common/resources/inputstream.h
new file mode 100644
index 0000000..74e17b2
--- /dev/null
+++ b/src/common/resources/inputstream.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#pragma once
+
+#include <istream>
+#include <string>
+
+
+class CInputStream : public std::istream
+{
+public:
+ CInputStream();
+ CInputStream(const std::string& filename);
+ virtual ~CInputStream();
+
+ void open(const std::string& filename);
+ void close();
+ bool is_open();
+ size_t size();
+};
diff --git a/src/common/resources/inputstreambuffer.cpp b/src/common/resources/inputstreambuffer.cpp
new file mode 100644
index 0000000..7059d60
--- /dev/null
+++ b/src/common/resources/inputstreambuffer.cpp
@@ -0,0 +1,132 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "common/resources/inputstreambuffer.h"
+
+#include <stdexcept>
+#include <sstream>
+
+CInputStreamBuffer::CInputStreamBuffer(size_t buffer_size) : m_buffer_size(buffer_size)
+{
+ if (buffer_size <= 0)
+ {
+ throw std::runtime_error("File buffer must be larger then 0 bytes");
+ }
+
+ m_buffer = new char[buffer_size];
+ m_file = nullptr;
+}
+
+
+CInputStreamBuffer::~CInputStreamBuffer()
+{
+ close();
+ delete m_buffer;
+}
+
+
+void CInputStreamBuffer::open(const std::string &filename)
+{
+ if (PHYSFS_isInit())
+ m_file = PHYSFS_openRead(filename.c_str());
+}
+
+
+void CInputStreamBuffer::close()
+{
+ if (is_open())
+ PHYSFS_close(m_file);
+}
+
+
+bool CInputStreamBuffer::is_open()
+{
+ return m_file;
+}
+
+
+size_t CInputStreamBuffer::size()
+{
+ return PHYSFS_fileLength(m_file);
+}
+
+
+std::streambuf::int_type CInputStreamBuffer::underflow()
+{
+ if (gptr() < egptr())
+ return traits_type::to_int_type(*gptr());
+
+ if (PHYSFS_eof(m_file))
+ return traits_type::eof();
+
+ PHYSFS_sint64 read_count = PHYSFS_read(m_file, m_buffer, sizeof(char), m_buffer_size);
+ if (read_count <= 0)
+ return traits_type::eof();
+
+ setg(m_buffer, m_buffer, m_buffer + read_count);
+
+ return traits_type::to_int_type(*gptr());
+}
+
+
+std::streampos CInputStreamBuffer::seekpos(std::streampos sp, std::ios_base::openmode which)
+{
+ return seekoff(off_type(sp), std::ios_base::beg, which);
+}
+
+
+std::streampos CInputStreamBuffer::seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which)
+{
+ /* A bit of explanation:
+ We are reading file by m_buffer_size parts so our 3 internal pointers will be
+ * eback (not used here) - start of block
+ * gptr - position of read cursor in block
+ * egtpr - end of block
+ off argument is relative to way */
+
+ std::streamoff new_position;
+
+ switch (way)
+ {
+ case std::ios_base::beg:
+ new_position = off;
+ break;
+
+ case std::ios_base::cur:
+ // tell will give cursor at begining of block so we have to add where in block we currently are
+ new_position = off + static_cast<off_type>(PHYSFS_tell(m_file)) - static_cast<off_type> (egptr() - gptr());
+ break;
+
+ case std::ios_base::end:
+ new_position = off + static_cast<off_type>(PHYSFS_fileLength(m_file));
+ break;
+
+ default:
+ break;
+ }
+
+ if (PHYSFS_seek(m_file, new_position))
+ {
+ setg(m_buffer, m_buffer, m_buffer); // reset buffer
+
+ return pos_type(new_position);
+ }
+
+ return pos_type(off_type(-1));
+}
diff --git a/src/common/resources/inputstreambuffer.h b/src/common/resources/inputstreambuffer.h
new file mode 100644
index 0000000..8c45c22
--- /dev/null
+++ b/src/common/resources/inputstreambuffer.h
@@ -0,0 +1,51 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#pragma once
+
+#include <streambuf>
+#include <string>
+#include <physfs.h>
+
+class CInputStreamBuffer : public std::streambuf
+{
+public:
+ CInputStreamBuffer(size_t buffer_size = 512);
+ virtual ~CInputStreamBuffer();
+
+ void open(const std::string &filename);
+ void close();
+ bool is_open();
+ size_t size();
+
+private:
+ int_type underflow();
+
+ std::streampos seekpos(std::streampos sp, std::ios_base::openmode which);
+ std::streampos seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which);
+
+ // copy ctor and assignment not implemented;
+ // copying not allowed
+ CInputStreamBuffer(const CInputStreamBuffer &);
+ CInputStreamBuffer &operator= (const CInputStreamBuffer &);
+
+ PHYSFS_File *m_file;
+ char *m_buffer;
+ size_t m_buffer_size;
+};
diff --git a/src/common/resources/outputstream.cpp b/src/common/resources/outputstream.cpp
new file mode 100644
index 0000000..e88520e
--- /dev/null
+++ b/src/common/resources/outputstream.cpp
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "common/resources/outputstream.h"
+#include "common/resources/outputstreambuffer.h"
+
+
+COutputStream::COutputStream() : std::ostream(new COutputStreamBuffer())
+{
+}
+
+COutputStream::COutputStream(const std::string& filename) : std::ostream(new COutputStreamBuffer())
+{
+ open(filename);
+}
+
+
+COutputStream::~COutputStream()
+{
+ delete rdbuf();
+}
+
+
+void COutputStream::open(const std::string& filename)
+{
+ static_cast<COutputStreamBuffer *>(rdbuf())->open(filename);
+}
+
+
+void COutputStream::close()
+{
+ static_cast<COutputStreamBuffer *>(rdbuf())->close();
+}
+
+
+bool COutputStream::is_open()
+{
+ return static_cast<COutputStreamBuffer *>(rdbuf())->is_open();
+}
diff --git a/src/common/resources/outputstream.h b/src/common/resources/outputstream.h
new file mode 100644
index 0000000..30b9429
--- /dev/null
+++ b/src/common/resources/outputstream.h
@@ -0,0 +1,36 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#pragma once
+
+#include <ostream>
+#include <string>
+
+
+class COutputStream : public std::ostream
+{
+public:
+ COutputStream();
+ COutputStream(const std::string& filename);
+ virtual ~COutputStream();
+
+ void open(const std::string& filename);
+ void close();
+ bool is_open();
+};
diff --git a/src/common/resources/outputstreambuffer.cpp b/src/common/resources/outputstreambuffer.cpp
new file mode 100644
index 0000000..f8b4100
--- /dev/null
+++ b/src/common/resources/outputstreambuffer.cpp
@@ -0,0 +1,89 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "common/resources/outputstreambuffer.h"
+
+#include <stdexcept>
+#include <sstream>
+
+COutputStreamBuffer::COutputStreamBuffer(size_t buffer_size) : m_buffer_size(buffer_size)
+{
+ m_file = nullptr;
+ m_buffer = new char[buffer_size];
+ setp(m_buffer, m_buffer + buffer_size);
+}
+
+
+COutputStreamBuffer::~COutputStreamBuffer()
+{
+ close();
+ delete m_buffer;
+}
+
+
+void COutputStreamBuffer::open(const std::string &filename)
+{
+ if (PHYSFS_isInit())
+ m_file = PHYSFS_openWrite(filename.c_str());
+}
+
+
+void COutputStreamBuffer::close()
+{
+ sync();
+ if (is_open())
+ PHYSFS_close(m_file);
+}
+
+
+bool COutputStreamBuffer::is_open()
+{
+ return m_file;
+}
+
+
+std::streambuf::int_type COutputStreamBuffer::overflow(std::streambuf::int_type ch)
+{
+ /* This function should be called when pptr() == epptr(). We use it also in sync()
+ so we also have to write data if buffer is not full. */
+
+ if (pbase() == pptr()) // no data to write, sync() called with empty buffer
+ return 0;
+
+ // save buffer
+ PHYSFS_sint64 bytes_written = PHYSFS_write(m_file, pbase(), 1, pptr() - pbase());
+ if (bytes_written <= 0)
+ return traits_type::eof();
+
+ pbump(-bytes_written);
+ // write final char
+ if (ch != traits_type::eof()) {
+ bytes_written = PHYSFS_write(m_file, &ch, 1, 1);
+ if (bytes_written <= 0)
+ return traits_type::eof();
+ }
+
+ return ch;
+}
+
+
+int COutputStreamBuffer::sync()
+{
+ return overflow(traits_type::eof());
+}
diff --git a/src/common/resources/outputstreambuffer.h b/src/common/resources/outputstreambuffer.h
new file mode 100644
index 0000000..758c4df
--- /dev/null
+++ b/src/common/resources/outputstreambuffer.h
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#pragma once
+
+#include <streambuf>
+#include <string>
+#include <physfs.h>
+
+class COutputStreamBuffer : public std::streambuf
+{
+public:
+ COutputStreamBuffer(size_t buffer_size = 512);
+ virtual ~COutputStreamBuffer();
+ void open(const std::string &filename);
+ void close();
+ bool is_open();
+
+private:
+ int_type overflow(int_type ch);
+ int sync();
+
+ // copy ctor and assignment not implemented;
+ // copying not allowed
+ COutputStreamBuffer(const COutputStreamBuffer &);
+ COutputStreamBuffer &operator= (const COutputStreamBuffer &);
+ PHYSFS_File *m_file;
+ char *m_buffer;
+ size_t m_buffer_size;
+};
diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp
new file mode 100644
index 0000000..21aceec
--- /dev/null
+++ b/src/common/resources/resourcemanager.cpp
@@ -0,0 +1,280 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+
+#include "common/resources/resourcemanager.h"
+
+#include "common/config.h"
+#include "common/logger.h"
+
+#include <physfs.h>
+
+#include <boost/filesystem.hpp>
+
+namespace fs = boost::filesystem;
+
+namespace
+{
+ const Uint32 PHYSFS_RWOPS_TYPE = 0xc010b04f;
+}
+
+
+CResourceManager::CResourceManager(const char *argv0)
+{
+ if (!PHYSFS_init(argv0))
+ {
+ CLogger::GetInstancePointer()->Error("Error while initializing physfs\n");
+ }
+}
+
+
+CResourceManager::~CResourceManager()
+{
+ if (PHYSFS_isInit())
+ {
+ if (!PHYSFS_deinit())
+ {
+ CLogger::GetInstancePointer()->Error("Error while deinitializing physfs\n");
+ }
+ }
+}
+
+
+bool CResourceManager::AddLocation(const std::string &location, bool prepend)
+{
+ if (PHYSFS_isInit())
+ {
+ if (!PHYSFS_mount(location.c_str(), nullptr, prepend ? 0 : 1))
+ {
+ CLogger::GetInstancePointer()->Error("Error while mounting \"%s\"\n", location.c_str());
+ }
+ }
+
+ return false;
+}
+
+
+bool CResourceManager::RemoveLocation(const std::string &location)
+{
+ if (PHYSFS_isInit())
+ {
+ if (!PHYSFS_removeFromSearchPath(location.c_str()))
+ {
+ CLogger::GetInstancePointer()->Error("Error while unmounting \"%s\"\n", location.c_str());
+ }
+ }
+
+ return false;
+}
+
+
+bool CResourceManager::SetSaveLocation(const std::string &location)
+{
+ if (PHYSFS_isInit())
+ {
+ if (!PHYSFS_setWriteDir(location.c_str()))
+ {
+ CLogger::GetInstancePointer()->Error("Error while setting save location to \"%s\"\n", location.c_str());
+ }
+ }
+
+ return false;
+}
+
+
+SDL_RWops* CResourceManager::GetSDLFileHandler(const std::string &filename)
+{
+ SDL_RWops *handler = SDL_AllocRW();
+ if (!handler)
+ {
+ CLogger::GetInstancePointer()->Error("Unable to allocate SDL_RWops for \"%s\"\n", filename.c_str());
+ return nullptr;
+ }
+
+ if (!PHYSFS_isInit())
+ {
+ SDL_FreeRW(handler);
+ return nullptr;
+ }
+
+ PHYSFS_File *file = PHYSFS_openRead(filename.c_str());
+ if (!file)
+ {
+ SDL_FreeRW(handler);
+ return nullptr;
+ }
+
+ handler->seek = SDLSeek;
+ handler->read = SDLRead;
+ handler->write = SDLWrite;
+ handler->close = SDLClose;
+ handler->type = PHYSFS_RWOPS_TYPE;
+ handler->hidden.unknown.data1 = file;
+
+ return handler;
+}
+
+
+CSNDFile* CResourceManager::GetSNDFileHandler(const std::string &filename)
+{
+ return new CSNDFile(filename);
+}
+
+
+bool CResourceManager::Exists(const std::string &filename)
+{
+ return PHYSFS_exists(filename.c_str());
+}
+
+bool CResourceManager::DirectoryExists(const std::string& directory)
+{
+ return PHYSFS_exists(directory.c_str()) && PHYSFS_isDirectory(directory.c_str());
+}
+
+bool CResourceManager::CreateDirectory(const std::string& directory)
+{
+ return PHYSFS_mkdir(directory.c_str());
+}
+
+bool CResourceManager::RemoveDirectory(const std::string& directory)
+{
+ bool success = true;
+ std::string writeDir = PHYSFS_getWriteDir();
+ try
+ {
+ fs::remove_all(writeDir + "/" + directory);
+ }
+ catch (std::exception & e)
+ {
+ success = false;
+ }
+ return success;
+}
+
+std::vector<std::string> CResourceManager::ListFiles(const std::string &directory)
+{
+ std::vector<std::string> result;
+
+ char **files = PHYSFS_enumerateFiles(directory.c_str());
+
+ for (char **i = files; *i != nullptr; i++)
+ {
+ result.push_back(*i);
+ }
+
+ PHYSFS_freeList(files);
+
+ return result;
+}
+
+std::vector<std::string> CResourceManager::ListDirectories(const std::string &directory)
+{
+ std::vector<std::string> result;
+
+ char **files = PHYSFS_enumerateFiles(directory.c_str());
+
+ for (char **i = files; *i != nullptr; i++)
+ {
+ std::string path = directory + "/" + (*i);
+ if (PHYSFS_isDirectory(path.c_str()))
+ {
+ result.push_back(*i);
+ }
+ }
+
+ PHYSFS_freeList(files);
+
+ return result;
+}
+
+
+int CResourceManager::SDLClose(SDL_RWops *context)
+{
+ if (CheckSDLContext(context))
+ {
+ PHYSFS_close(static_cast<PHYSFS_File *>(context->hidden.unknown.data1));
+ SDL_FreeRW(context);
+
+ return 0;
+ }
+
+ return 1;
+}
+
+
+int CResourceManager::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum)
+{
+ if (CheckSDLContext(context))
+ {
+ PHYSFS_File *file = static_cast<PHYSFS_File *>(context->hidden.unknown.data1);
+ SDL_memset(ptr, 0, size * maxnum);
+
+ return PHYSFS_read(file, ptr, size, maxnum);
+ }
+
+ return 0;
+}
+
+
+int CResourceManager::SDLWrite(SDL_RWops *context, const void *ptr, int size, int num)
+{
+ return 0;
+}
+
+
+int CResourceManager::SDLSeek(SDL_RWops *context, int offset, int whence)
+{
+ if (CheckSDLContext(context))
+ {
+ PHYSFS_File *file = static_cast<PHYSFS_File *>(context->hidden.unknown.data1);
+ int position, result;
+
+ switch (whence)
+ {
+ default:
+ case RW_SEEK_SET:
+ result = PHYSFS_seek(file, offset);
+ return result > 0 ? offset : -1;
+
+ case RW_SEEK_CUR:
+ position = offset + PHYSFS_tell(file);
+ result = PHYSFS_seek(file, position);
+ return result > 0 ? position : -1;
+
+ case RW_SEEK_END:
+ position = PHYSFS_fileLength(file) - offset;
+ result = PHYSFS_seek(file, position);
+ return result > 0 ? position : -1;
+ }
+ }
+
+ return -1;
+}
+
+
+bool CResourceManager::CheckSDLContext(SDL_RWops *context)
+{
+ if (context->type != PHYSFS_RWOPS_TYPE)
+ {
+ SDL_SetError("Wrong kind of RWops");
+ return false;
+ }
+
+ return true;
+}
diff --git a/src/common/resources/resourcemanager.h b/src/common/resources/resourcemanager.h
new file mode 100644
index 0000000..e949746
--- /dev/null
+++ b/src/common/resources/resourcemanager.h
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#pragma once
+
+#include <vector>
+#include <string>
+#include <SDL.h>
+
+#include "common/resources/sndfile.h"
+
+class CResourceManager
+{
+public:
+ CResourceManager(const char *argv0);
+ ~CResourceManager();
+
+ static bool AddLocation(const std::string &location, bool prepend = true);
+ static bool RemoveLocation(const std::string &location);
+
+ static bool SetSaveLocation(const std::string &location);
+
+ static SDL_RWops* GetSDLFileHandler(const std::string &filename);
+ static CSNDFile* GetSNDFileHandler(const std::string &filename);
+
+ //! Check if file exists
+ static bool Exists(const std::string &filename);
+ //! Check if file exists and is a directory
+ static bool DirectoryExists(const std::string& directory);
+
+ //! Create directory in write directory
+ static bool CreateDirectory(const std::string& directory);
+ //! Remove directory in write directory, recursively
+ static bool RemoveDirectory(const std::string& directory);
+
+ //! List files contained in directory
+ static std::vector<std::string> ListFiles(const std::string &directory);
+ //! List directories contained in directory
+ static std::vector<std::string> ListDirectories(const std::string &directory);
+
+private:
+ static int SDLSeek(SDL_RWops *context, int offset, int whence);
+ static int SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum);
+ static int SDLWrite(SDL_RWops *context, const void *ptr, int size, int num);
+ static int SDLClose(SDL_RWops *context);
+ static bool CheckSDLContext(SDL_RWops *context);
+};
diff --git a/src/common/resources/sndfile.cpp b/src/common/resources/sndfile.cpp
new file mode 100644
index 0000000..d2330e1
--- /dev/null
+++ b/src/common/resources/sndfile.cpp
@@ -0,0 +1,133 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "common/resources/sndfile.h"
+
+#include <cstring>
+
+
+CSNDFile::CSNDFile(const std::string& filename)
+ : m_file_info{}
+ , m_snd_file{nullptr}
+ , m_file{nullptr}
+ , m_last_error{}
+ , m_snd_callbacks{SNDLength, SNDSeek, SNDRead, SNDWrite, SNDTell}
+{
+ if (PHYSFS_isInit())
+ {
+ m_file = PHYSFS_openRead(filename.c_str());
+ }
+ else
+ {
+ m_last_error = "Resource system not started!";
+ }
+ if (m_file)
+ {
+ m_snd_file = sf_open_virtual(&m_snd_callbacks, SFM_READ, &m_file_info, m_file);
+ if (!m_snd_file)
+ {
+ m_last_error = "Could not load file";
+ }
+ }
+ else
+ {
+ m_last_error = std::string(PHYSFS_getLastError());
+ }
+}
+
+
+CSNDFile::~CSNDFile()
+{
+ if (m_file)
+ {
+ PHYSFS_close(m_file);
+ if (m_snd_file)
+ {
+ sf_close(m_snd_file);
+ }
+ }
+}
+
+
+bool CSNDFile::IsOpen()
+{
+ return m_file && m_snd_file;
+}
+
+
+SF_INFO &CSNDFile::GetFileInfo()
+{
+ return m_file_info;
+}
+
+
+std::string& CSNDFile::GetLastError()
+{
+ return m_last_error;
+}
+
+
+sf_count_t CSNDFile::Read(short int *ptr, sf_count_t items)
+{
+ return sf_read_short(m_snd_file, ptr, items);
+}
+
+
+sf_count_t CSNDFile::SNDLength(void *data)
+{
+ return PHYSFS_fileLength(static_cast<PHYSFS_File *>(data));
+}
+
+
+sf_count_t CSNDFile::SNDRead(void *ptr, sf_count_t count, void *data)
+{
+ return PHYSFS_read(static_cast<PHYSFS_File *>(data), ptr, 1, count);
+}
+
+
+sf_count_t CSNDFile::SNDSeek(sf_count_t offset, int whence, void *data)
+{
+ PHYSFS_File *file = static_cast<PHYSFS_File *>(data);
+ switch(whence)
+ {
+ case SEEK_CUR:
+ PHYSFS_seek(file, PHYSFS_tell(file) + offset);
+ break;
+ case SEEK_SET:
+ PHYSFS_seek(file, offset);
+ break;
+ case SEEK_END:
+ PHYSFS_seek(file, PHYSFS_fileLength(file) + offset);
+ break;
+ }
+
+ return PHYSFS_tell(file);
+}
+
+
+sf_count_t CSNDFile::SNDTell(void *data)
+{
+ return PHYSFS_tell(static_cast<PHYSFS_File *>(data));
+}
+
+
+sf_count_t CSNDFile::SNDWrite(const void *ptr, sf_count_t count, void *data)
+{
+ return PHYSFS_write(static_cast<PHYSFS_File *>(data), ptr, 1, count);
+}
diff --git a/src/common/resources/sndfile.h b/src/common/resources/sndfile.h
new file mode 100644
index 0000000..f083666
--- /dev/null
+++ b/src/common/resources/sndfile.h
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#pragma once
+
+#include <string>
+#include <physfs.h>
+#include <sndfile.h>
+
+
+class CSNDFile
+{
+public:
+ CSNDFile(const std::string &filename);
+ virtual ~CSNDFile();
+
+ SF_INFO &GetFileInfo();
+ bool IsOpen();
+ std::string &GetLastError();
+ sf_count_t Read(short int *ptr, sf_count_t items);
+
+private:
+ static sf_count_t SNDLength(void *data);
+ static sf_count_t SNDSeek(sf_count_t offset, int whence, void *data);
+ static sf_count_t SNDRead(void *ptr, sf_count_t count, void *data);
+ static sf_count_t SNDWrite(const void *ptr, sf_count_t count, void *data);
+ static sf_count_t SNDTell(void *data);
+ SF_INFO m_file_info;
+ SNDFILE *m_snd_file;
+ PHYSFS_File *m_file;
+ std::string m_last_error;
+ SF_VIRTUAL_IO m_snd_callbacks;
+};
diff --git a/src/graphics/engine/cloud.cpp b/src/graphics/engine/cloud.cpp
index d3e40cf..7ec0d9e 100644
--- a/src/graphics/engine/cloud.cpp
+++ b/src/graphics/engine/cloud.cpp
@@ -127,8 +127,8 @@ void CCloud::Draw()
material.ambient = m_ambient;
m_engine->SetMaterial(material);
- m_engine->SetTexture(m_fileName, 0);
- m_engine->SetTexture(m_fileName, 1);
+ m_engine->SetTexture("textures/"+m_fileName, 0);
+ m_engine->SetTexture("textures/"+m_fileName, 1);
m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_FOG | ENG_RSTATE_WRAP);
@@ -220,7 +220,7 @@ void CCloud::Create(const std::string& fileName,
m_fileName = fileName;
if (! m_fileName.empty())
- m_engine->LoadTexture(m_fileName);
+ m_engine->LoadTexture("textures/"+m_fileName);
if (m_terrain == nullptr)
m_terrain = CRobotMain::GetInstancePointer()->GetTerrain();
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 6766a27..2c412ec 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -21,7 +21,6 @@
#include "graphics/engine/engine.h"
#include "app/app.h"
-#include "app/gamedata.h"
#include "common/image.h"
#include "common/key.h"
@@ -285,7 +284,7 @@ bool CEngine::Create()
params.minFilter = TEX_MIN_FILTER_NEAREST;
params.magFilter = TEX_MAG_FILTER_NEAREST;
params.mipmap = false;
- m_miceTexture = LoadTexture("mouse.png", params);
+ m_miceTexture = LoadTexture("textures/interface/mouse.png", params);
GetSystemUtils()->GetCurrentTimeStamp(m_currentFrameTime);
GetSystemUtils()->GetCurrentTimeStamp(m_lastFrameTime);
@@ -1126,10 +1125,10 @@ void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name)
p1.next[l2].next.clear();
if (!newP2.tex1.Valid())
- newP2.tex1 = LoadTexture(newP2.tex1Name);
+ newP2.tex1 = LoadTexture("textures/"+newP2.tex1Name);
if (!newP2.tex2.Valid())
- newP2.tex2 = LoadTexture(newP2.tex2Name);
+ newP2.tex2 = LoadTexture("textures/"+newP2.tex2Name);
}
}
@@ -2260,7 +2259,7 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa
if (image == nullptr)
{
- if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName)))
+ if (!img.Load(texName))
{
std::string error = img.GetError();
GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str());
@@ -2311,27 +2310,27 @@ Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams&
bool CEngine::LoadAllTextures()
{
- LoadTexture("text.png");
- m_miceTexture = LoadTexture("mouse.png");
- LoadTexture("button1.png");
- LoadTexture("button2.png");
- LoadTexture("button3.png");
- LoadTexture("effect00.png");
- LoadTexture("effect01.png");
- LoadTexture("effect02.png");
- LoadTexture("map.png");
+ LoadTexture("textures/interface/text.png");
+ m_miceTexture = LoadTexture("textures/interface/mouse.png");
+ LoadTexture("textures/interface/button1.png");
+ LoadTexture("textures/interface/button2.png");
+ LoadTexture("textures/interface/button3.png");
+ LoadTexture("textures/effect00.png");
+ LoadTexture("textures/effect01.png");
+ LoadTexture("textures/effect02.png");
+ LoadTexture("textures/interface/map.png");
if (! m_backgroundName.empty())
{
TextureCreateParams params = m_defaultTexParams;
params.padToNearestPowerOfTwo = true;
- m_backgroundTex = LoadTexture(m_backgroundName, params);
+ m_backgroundTex = LoadTexture("textures/"+m_backgroundName, params);
}
else
m_backgroundTex.SetInvalid();
if (! m_foregroundName.empty())
- m_foregroundTex = LoadTexture(m_foregroundName);
+ m_foregroundTex = LoadTexture("textures/"+m_foregroundName);
else
m_foregroundTex.SetInvalid();
@@ -2365,9 +2364,9 @@ bool CEngine::LoadAllTextures()
if (! p2.tex1Name.empty())
{
if (terrain)
- p2.tex1 = LoadTexture(p2.tex1Name, m_terrainTexParams);
+ p2.tex1 = LoadTexture("textures/"+p2.tex1Name, m_terrainTexParams);
else
- p2.tex1 = LoadTexture(p2.tex1Name);
+ p2.tex1 = LoadTexture("textures/"+p2.tex1Name);
if (! p2.tex1.Valid())
ok = false;
@@ -2376,9 +2375,9 @@ bool CEngine::LoadAllTextures()
if (! p2.tex2Name.empty())
{
if (terrain)
- p2.tex2 = LoadTexture(p2.tex2Name, m_terrainTexParams);
+ p2.tex2 = LoadTexture("textures/"+p2.tex2Name, m_terrainTexParams);
else
- p2.tex2 = LoadTexture(p2.tex2Name);
+ p2.tex2 = LoadTexture("textures/"+p2.tex2Name);
if (! p2.tex2.Valid())
ok = false;
@@ -2428,7 +2427,7 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
CImage img;
- if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName)))
+ if (!img.Load(texName))
{
std::string error = img.GetError();
GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str());
@@ -2773,7 +2772,7 @@ void CEngine::SetBackground(const std::string& name, Color up, Color down,
{
TextureCreateParams params = m_defaultTexParams;
params.padToNearestPowerOfTwo = true;
- m_backgroundTex = LoadTexture(m_backgroundName, params);
+ m_backgroundTex = LoadTexture("textures/"+m_backgroundName, params);
}
}
@@ -2799,7 +2798,7 @@ void CEngine::SetForegroundName(const std::string& name)
m_foregroundName = name;
if (! m_foregroundName.empty())
- m_foregroundTex = LoadTexture(m_foregroundName);
+ m_foregroundTex = LoadTexture("textures/"+m_foregroundName);
}
void CEngine::SetOverFront(bool front)
@@ -3738,7 +3737,7 @@ void CEngine::UpdateGroundSpotTextures()
}
std::stringstream str;
- str << "shadow" << std::setfill('0') << std::setw(2) << s << ".png";
+ str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png";
std::string texName = str.str();
DeleteTexture(texName);
@@ -3787,7 +3786,7 @@ void CEngine::DrawShadow()
SetMaterial(material);
// TODO: create a separate texture
- SetTexture("text.png");
+ SetTexture("textures/interface/text.png");
Math::Point ts, ti;
diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp
index 373a35c..be76b2f 100644
--- a/src/graphics/engine/lightning.cpp
+++ b/src/graphics/engine/lightning.cpp
@@ -237,7 +237,7 @@ void CLightning::Draw()
mat.LoadIdentity();
device->SetTransform(TRANSFORM_WORLD, mat);
- m_engine->SetTexture("effect00.png");
+ m_engine->SetTexture("textures/effect00.png");
m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK);
Math::Point texInf;
diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp
index ba7c1d6..09c7bbd 100644
--- a/src/graphics/engine/modelfile.cpp
+++ b/src/graphics/engine/modelfile.cpp
@@ -24,6 +24,8 @@
#include "common/logger.h"
#include "common/stringutils.h"
+#include "common/resources/inputstream.h"
+
#include "graphics/engine/engine.h"
#include "math/geometry.h"
@@ -434,9 +436,9 @@ bool CModelFile::ReadModel(const std::string& fileName)
{
m_triangles.clear();
- std::ifstream stream;
- stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary);
- if (!stream.good())
+ CInputStream stream;
+ stream.open(fileName.c_str());
+ if (!stream.is_open())
{
GetLogger()->Error("Could not open file '%s'\n", fileName.c_str());
return false;
@@ -825,9 +827,9 @@ struct NewModelTriangle1
bool CModelFile::ReadTextModel(const std::string& fileName)
{
- std::ifstream stream;
- stream.open(fileName.c_str(), std::ios_base::in);
- if (!stream.good())
+ CInputStream stream;
+ stream.open(fileName.c_str());
+ if (!stream.is_open())
{
GetLogger()->Error("Could not open file '%s'\n", fileName.c_str());
return false;
@@ -1022,9 +1024,9 @@ bool CModelFile::WriteTextModel(std::ostream& stream)
bool CModelFile::ReadBinaryModel(const std::string& fileName)
{
- std::ifstream stream;
- stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary);
- if (!stream.good())
+ CInputStream stream;
+ stream.open(fileName.c_str());
+ if (!stream.is_open())
{
GetLogger()->Error("Could not open file '%s'\n", fileName.c_str());
return false;
diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp
index 25f6d35..ec104d0 100644
--- a/src/graphics/engine/modelmanager.cpp
+++ b/src/graphics/engine/modelmanager.cpp
@@ -20,7 +20,6 @@
#include "graphics/engine/modelmanager.h"
#include "app/app.h"
-#include "app/gamedata.h"
#include "common/logger.h"
@@ -50,11 +49,9 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored)
if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS))
modelFile.SetPrintDebugInfo(true);
- std::string filePath = CGameData::GetInstancePointer()->GetFilePath(DIR_MODEL, fileName);
-
- if (!modelFile.ReadModel(filePath))
+ if (!modelFile.ReadModel("models/" + fileName))
{
- GetLogger()->Error("Loading model '%s' failed\n", filePath.c_str());
+ GetLogger()->Error("Loading model '%s' failed\n", fileName.c_str());
return false;
}
diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp
index beb4a02..d038322 100644
--- a/src/graphics/engine/particle.cpp
+++ b/src/graphics/engine/particle.cpp
@@ -203,7 +203,7 @@ void NameParticle(std::string &name, int num)
if (num == 1) name = "effect00.png";
else if (num == 2) name = "effect01.png";
else if (num == 3) name = "effect02.png";
- else if (num == 4) name = "text.png";
+ else if (num == 4) name = "interface/text.png";
else name = "";
}
@@ -3534,7 +3534,7 @@ void CParticle::DrawParticle(int sheet)
if (m_particle[i].sheet != sheet) continue;
if (m_particle[i].type == PARTIPART) continue;
- m_engine->SetTexture(m_triangle[i].tex1Name);
+ m_engine->SetTexture("textures/"+m_triangle[i].tex1Name);
m_engine->SetMaterial(m_triangle[i].material);
m_engine->SetState(m_triangle[i].state);
DrawParticleTriangle(i);
@@ -3553,7 +3553,7 @@ void CParticle::DrawParticle(int sheet)
// Draw tire marks.
if (m_wheelTraceTotal > 0 && sheet == SH_WORLD)
{
- m_engine->SetTexture("text.png");
+ m_engine->SetTexture("textures/interface/text.png");
m_engine->SetState(ENG_RSTATE_TTEXTURE_WHITE);
Math::Matrix matrix;
matrix.LoadIdentity();
@@ -3584,7 +3584,7 @@ void CParticle::DrawParticle(int sheet)
{
std::string name;
NameParticle(name, t);
- m_engine->SetTexture(name);
+ m_engine->SetTexture("textures/"+name);
loadTexture = true;
}
diff --git a/src/graphics/engine/planet.cpp b/src/graphics/engine/planet.cpp
index 66eecca..df34fbc 100644
--- a/src/graphics/engine/planet.cpp
+++ b/src/graphics/engine/planet.cpp
@@ -88,7 +88,7 @@ void CPlanet::LoadTexture()
{
for (int i = 0; i < static_cast<int>( m_planet[j].size() ); i++)
{
- m_engine->LoadTexture(m_planet[j][i].name);
+ m_engine->LoadTexture("textures/"+m_planet[j][i].name);
}
}
}
@@ -104,7 +104,7 @@ void CPlanet::Draw()
for (int i = 0; i < static_cast<int>( m_planet[m_mode].size() ); i++)
{
- m_engine->SetTexture(m_planet[m_mode][i].name);
+ m_engine->SetTexture("textures/"+m_planet[m_mode][i].name);
if (m_planet[m_mode][i].transparent)
m_engine->SetState(ENG_RSTATE_WRAP | ENG_RSTATE_ALPHA);
diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp
index 9dfc5a4..42f0e84 100644
--- a/src/graphics/engine/pyro.cpp
+++ b/src/graphics/engine/pyro.cpp
@@ -1596,7 +1596,7 @@ void CPyro::ExploStart()
if (channel != -1)
m_object->SetMasterParticle(i, channel);
}
- m_engine->LoadTexture("dirty04.png");
+ m_engine->LoadTexture("textures/dirty04.png");
DeleteObject(false, true); // destroys the object transported + the battery
}
@@ -1639,7 +1639,7 @@ void CPyro::BurnStart()
m_engine->ChangeSecondTexture(objRank, "dirty04.png");
}
}
- m_engine->LoadTexture("dirty04.png");
+ m_engine->LoadTexture("textures/dirty04.png");
m_burnPartTotal = 0;
diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp
index 6dc8708..21d7446 100644
--- a/src/graphics/engine/terrain.cpp
+++ b/src/graphics/engine/terrain.cpp
@@ -21,7 +21,6 @@
#include "graphics/engine/terrain.h"
#include "app/app.h"
-#include "app/gamedata.h"
#include "common/image.h"
#include "common/logger.h"
@@ -192,10 +191,10 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point
bool CTerrain::LoadResources(const std::string& fileName)
{
CImage img;
- std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName);
- if (! img.Load(path))
+
+ if (! img.Load(fileName))
{
- GetLogger()->Error("Cannot load resource file: '%s'\n", path.c_str());
+ GetLogger()->Error("Cannot load resource file: '%s'\n", fileName.c_str());
return false;
}
@@ -289,10 +288,10 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief,
m_scaleRelief = scaleRelief;
CImage img;
- std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName);
- if (! img.Load(path))
+
+ if (! img.Load(fileName))
{
- GetLogger()->Error("Could not load relief file: '%s'!\n", path.c_str());
+ GetLogger()->Error("Could not load relief file: '%s'!\n", fileName.c_str());
return false;
}
@@ -368,17 +367,11 @@ bool CTerrain::RandomizeRelief()
double xi, yi, a, b;
a = modf(x * (rozmiar_oktawy-1), &xi);
b = modf(y * (rozmiar_oktawy-1), &yi);
- /*int xi = floor(x * (rozmiar_oktawy-1));
- int yi = floor(y * (rozmiar_oktawy-1));
- float a = (x * (rozmiar_oktawy-1)) - xi;
- float b = (y * (rozmiar_oktawy-1)) - yi;*/
- //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", xi, yi, a, b);
float lg = oktawy[i][static_cast<int>(yi * rozmiar_oktawy + xi)];
float pg = oktawy[i][static_cast<int>(yi * rozmiar_oktawy + xi + 1)];
float ld = oktawy[i][static_cast<int>((yi+1) * rozmiar_oktawy + xi)];
float pd = oktawy[i][static_cast<int>((yi+1) * rozmiar_oktawy + xi + 1)];
- //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", lg, pg, ld, pd);
float g = pg * a + lg * (1-a);
float d = pd * a + ld * (1-a);
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index ea7fd14..bebf30c 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -21,11 +21,11 @@
#include "graphics/engine/text.h"
#include "app/app.h"
-#include "app/gamedata.h"
#include "common/image.h"
#include "common/logger.h"
#include "common/stringutils.h"
+#include "common/resources/resourcemanager.h"
#include "math/func.h"
@@ -80,12 +80,12 @@ bool CText::Create()
return false;
}
- m_fonts[FONT_COLOBOT] = new MultisizeFont("dvu_sans.ttf");
- m_fonts[FONT_COLOBOT_BOLD] = new MultisizeFont("dvu_sans_bold.ttf");
- m_fonts[FONT_COLOBOT_ITALIC] = new MultisizeFont("dvu_sans_italic.ttf");
+ m_fonts[FONT_COLOBOT] = new MultisizeFont("fonts/dvu_sans.ttf");
+ m_fonts[FONT_COLOBOT_BOLD] = new MultisizeFont("fonts/dvu_sans_bold.ttf");
+ m_fonts[FONT_COLOBOT_ITALIC] = new MultisizeFont("fonts/dvu_sans_italic.ttf");
- m_fonts[FONT_COURIER] = new MultisizeFont("dvu_sans_mono.ttf");
- m_fonts[FONT_COURIER_BOLD] = new MultisizeFont("dvu_sans_mono_bold.ttf");
+ m_fonts[FONT_COURIER] = new MultisizeFont("fonts/dvu_sans_mono.ttf");
+ m_fonts[FONT_COURIER_BOLD] = new MultisizeFont("fonts/dvu_sans_mono_bold.ttf");
for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it)
{
@@ -868,10 +868,14 @@ CachedFont* CText::GetOrOpenFont(FontType font, float size)
return m_lastCachedFont;
}
- std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_FONT, mf->fileName);
-
m_lastCachedFont = new CachedFont();
- m_lastCachedFont->font = TTF_OpenFont(path.c_str(), pointSize);
+ SDL_RWops* file = CResourceManager::GetSDLFileHandler(mf->fileName);
+ if(file == nullptr)
+ {
+ m_error = std::string("Unable to open file");
+ return nullptr;
+ }
+ m_lastCachedFont->font = TTF_OpenFontRW(file, 1, pointSize);
if (m_lastCachedFont->font == nullptr)
m_error = std::string("TTF_OpenFont error ") + std::string(TTF_GetError());
diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp
index d4c7d11..8a396a8 100644
--- a/src/graphics/engine/water.cpp
+++ b/src/graphics/engine/water.cpp
@@ -350,8 +350,8 @@ void CWater::DrawSurf()
material.ambient = m_ambient;
m_engine->SetMaterial(material);
- m_engine->SetTexture(m_fileName, 0);
- m_engine->SetTexture(m_fileName, 1);
+ m_engine->SetTexture("textures/"+m_fileName, 0);
+ m_engine->SetTexture("textures/"+m_fileName, 1);
if (m_type[rankview] == WATER_TT)
m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_DUAL_WHITE | ENG_RSTATE_WRAP, m_color);
@@ -494,7 +494,7 @@ void CWater::Create(WaterType type1, WaterType type2, const std::string& fileNam
VaporFlush();
if (! m_fileName.empty())
- m_engine->LoadTexture(m_fileName);
+ m_engine->LoadTexture("textures/"+m_fileName);
if (m_terrain == nullptr)
m_terrain = CRobotMain::GetInstancePointer()->GetTerrain();
diff --git a/src/object/auto/autobase.cpp b/src/object/auto/autobase.cpp
index 7cae9c8..611730d 100644
--- a/src/object/auto/autobase.cpp
+++ b/src/object/auto/autobase.cpp
@@ -1374,7 +1374,7 @@ void CAutoBase::BeginTransit()
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f));
- m_engine->LoadTexture(m_bgBack);
+ m_engine->LoadTexture("textures/"+m_bgBack);
m_cloud->SetEnabled(false); // cache clouds
m_planet->SetMode(1);
@@ -1391,7 +1391,7 @@ void CAutoBase::EndTransit()
m_engine->DeleteTexture(m_bgBack);
m_engine->SetBackground(m_bgName, m_bgUp, m_bgDown, m_bgCloudUp, m_bgCloudDown);
- m_engine->LoadTexture(m_bgName);
+ m_engine->LoadTexture("textures/"+m_bgName);
m_cloud->SetEnabled(true); // gives the clouds
m_planet->SetMode(0);
diff --git a/src/object/level/parser.cpp b/src/object/level/parser.cpp
new file mode 100644
index 0000000..ab3e6bc
--- /dev/null
+++ b/src/object/level/parser.cpp
@@ -0,0 +1,244 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "object/level/parser.h"
+
+
+#include "app/app.h"
+
+#include "common/resources/inputstream.h"
+
+#include "object/level/parserexceptions.h"
+
+#include "object/robotmain.h"
+
+#include <string>
+#include <exception>
+#include <sstream>
+#include <iomanip>
+
+#include <boost/algorithm/string/trim.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/lexical_cast.hpp>
+
+CLevelParser::CLevelParser()
+{
+ m_filename = "";
+}
+
+CLevelParser::CLevelParser(std::string filename)
+{
+ m_filename = filename;
+}
+
+CLevelParser::CLevelParser(std::string category, int chapter, int rank)
+{
+ m_filename = BuildSceneName(category, chapter, rank);
+}
+
+CLevelParser::~CLevelParser()
+{
+ for(auto line : m_lines)
+ {
+ delete line;
+ }
+}
+
+std::string CLevelParser::BuildSceneName(std::string category, int chapter, int rank, bool sceneFile)
+{
+ std::ostringstream outstream;
+ if(category == "custom")
+ {
+ outstream << "levels/custom/";
+ outstream << CRobotMain::GetInstancePointer()->GetUserLevelName(chapter);
+ if(rank == 000)
+ {
+ if(sceneFile)
+ {
+ outstream << "/chaptertitle.txt";
+ }
+ }
+ else
+ {
+ outstream << "/level" << std::setfill('0') << std::setw(3) << rank;
+ if(sceneFile)
+ {
+ outstream << "/scene.txt";
+ }
+ }
+ }
+ else if(category == "perso")
+ {
+ outstream << "levels/other/perso.txt";
+ }
+ else if(category == "win" || category == "lost")
+ {
+ outstream << "levels/other/";
+ outstream << category << std::setfill('0') << std::setw(3) << chapter*100+rank << ".txt";
+ }
+ else
+ {
+ outstream << "levels/" << category << "/";
+ outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter;
+ if(rank == 000)
+ {
+ if(sceneFile)
+ {
+ outstream << "/chaptertitle.txt";
+ }
+ }
+ else
+ {
+ outstream << "/level" << std::setfill('0') << std::setw(3) << rank;
+ if(sceneFile)
+ {
+ outstream << "/scene.txt";
+ }
+ }
+ }
+ return outstream.str();
+}
+
+void CLevelParser::Load()
+{
+ CInputStream file;
+ file.open(m_filename);
+ if(!file.is_open())
+ throw CLevelParserException("Failed to open file: "+m_filename);
+
+ char lang = CApplication::GetInstancePointer()->GetLanguageChar();
+
+ std::string line;
+ int lineNumber = 0;
+ std::map<std::string, CLevelParserLine*> translatableLines;
+ while(getline(file,line))
+ {
+ lineNumber++;
+
+ boost::replace_all(line, "\t", " "); // replace tab by space
+
+ // ignore comments
+ std::size_t comment = line.find("//");
+ if(comment != std::string::npos)
+ line = line.substr(0, comment);
+
+ boost::algorithm::trim(line);
+
+ std::size_t pos = line.find_first_of(" \t\n");
+ std::string command = line.substr(0, pos);
+ if(pos != std::string::npos) {
+ line = line.substr(pos+1);
+ boost::algorithm::trim(line);
+ } else {
+ line = "";
+ }
+ if(command.empty()) continue;
+
+ CLevelParserLine* parserLine = new CLevelParserLine(lineNumber, command);
+
+ std::string baseCommand = command;
+ if(command[command.length()-2] == '.') {
+ baseCommand = command.substr(0, command.length()-2);
+ if(command[command.length()-1] == 'E' && translatableLines[baseCommand] == nullptr) {
+ parserLine->SetCommand(baseCommand);
+ translatableLines[baseCommand] = parserLine;
+ } else if(command[command.length()-1] == lang) {
+ if(translatableLines[baseCommand] != nullptr) {
+ m_lines.erase(std::remove(m_lines.begin(), m_lines.end(), translatableLines[baseCommand]), m_lines.end());
+ delete translatableLines[baseCommand];
+ }
+ parserLine->SetCommand(baseCommand);
+ translatableLines[baseCommand] = parserLine;
+ } else {
+ delete parserLine;
+ continue;
+ }
+ }
+
+ while(!line.empty()) {
+ pos = line.find_first_of("=");
+ std::string paramName = line.substr(0, pos);
+ boost::algorithm::trim(paramName);
+ line = line.substr(pos+1);
+ boost::algorithm::trim(line);
+
+ if(line[0] == '\"') {
+ pos = line.find_first_of("\"", 1);
+ if(pos == std::string::npos)
+ throw CLevelParserException("Unclosed \" in "+m_filename+":"+boost::lexical_cast<std::string>(lineNumber));
+ } else if(line[0] == '\'') {
+ pos = line.find_first_of("'", 1);
+ if(pos == std::string::npos)
+ throw CLevelParserException("Unclosed ' in "+m_filename+":"+boost::lexical_cast<std::string>(lineNumber));
+ } else {
+ pos = line.find_first_of("=");
+ if(pos != std::string::npos) {
+ std::size_t pos2 = line.find_last_of(" \t\n", line.find_last_not_of(" \t\n", pos-1));
+ if(pos2 != std::string::npos)
+ pos = pos2;
+ } else {
+ pos = line.length()-1;
+ }
+ }
+ std::string paramValue = line.substr(0, pos+1);
+ boost::algorithm::trim(paramValue);
+
+ parserLine->AddParam(paramName, new CLevelParserParam(paramName, paramValue));
+
+ if(pos == std::string::npos)
+ break;
+ line = line.substr(pos+1);
+ boost::algorithm::trim(line);
+ }
+
+ AddLine(parserLine);
+ }
+
+ file.close();
+}
+
+void CLevelParser::Save(std::string filename)
+{
+ assert(false); //TODO
+}
+
+const std::string& CLevelParser::GetFilename()
+{
+ return m_filename;
+}
+
+std::vector<CLevelParserLine*> CLevelParser::GetLines()
+{
+ return m_lines;
+}
+
+void CLevelParser::AddLine(CLevelParserLine* line)
+{
+ line->SetLevel(this);
+ m_lines.push_back(line);
+}
+
+CLevelParserLine* CLevelParser::Get(std::string command)
+{
+ for(auto& line : m_lines) {
+ if(line->GetCommand() == command)
+ return line;
+ }
+ throw CLevelParserException("Command not found: "+command);
+}
diff --git a/src/object/level/parser.h b/src/object/level/parser.h
new file mode 100644
index 0000000..7e87e2d
--- /dev/null
+++ b/src/object/level/parser.h
@@ -0,0 +1,69 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+/**
+ * \file object/level/parser.h
+ * \brief Parser for level files
+ */
+
+#pragma once
+
+#include "object/level/parserline.h"
+#include "object/level/parserparam.h"
+#include "object/level/parserexceptions.h"
+
+#include <string>
+#include <vector>
+
+class CLevelParser
+{
+public:
+ //! Create an empty level file
+ CLevelParser();
+ //! Load level from file
+ CLevelParser(std::string filename);
+ //! Load given level
+ CLevelParser(std::string category, int chapter, int rank);
+
+ ~CLevelParser();
+
+ //! Build level filename
+ static std::string BuildSceneName(std::string category, int chapter, int rank, bool sceneFile = true);
+
+ //! Load file
+ void Load();
+ //! Save file
+ void Save(std::string filename);
+
+ //! Get filename
+ const std::string& GetFilename();
+
+ //! Get all lines from file
+ std::vector<CLevelParserLine*> GetLines();
+ //! Insert new line to file
+ void AddLine(CLevelParserLine* line);
+
+ //! Find first line with given command
+ CLevelParserLine* Get(std::string command);
+
+private:
+
+ std::string m_filename;
+ std::vector<CLevelParserLine*> m_lines;
+}; \ No newline at end of file
diff --git a/src/object/level/parserexceptions.cpp b/src/object/level/parserexceptions.cpp
new file mode 100644
index 0000000..8f74078
--- /dev/null
+++ b/src/object/level/parserexceptions.cpp
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "object/level/parserexceptions.h"
+
+
+#include "object/level/parser.h"
+
+#include <boost/lexical_cast.hpp>
+
+CLevelParserException::CLevelParserException(std::string message) noexcept
+{
+ m_message = message;
+}
+
+const char* CLevelParserException::what() const noexcept
+{
+ return m_message.c_str();
+}
+
+CLevelParserExceptionMissingParam::CLevelParserExceptionMissingParam(CLevelParserParam* thisParam) noexcept
+: CLevelParserException("Missing required param "+thisParam->GetName()+" (in "+thisParam->GetLine()->GetLevel()->GetFilename()+":"+boost::lexical_cast<std::string>(thisParam->GetLine()->GetLineNumber())+")")
+{
+}
+
+CLevelParserExceptionBadParam::CLevelParserExceptionBadParam(CLevelParserParam* thisParam, std::string requestedType) noexcept
+: CLevelParserException("Unable to parse '"+thisParam->GetValue()+"' as "+requestedType+" (param '"+thisParam->GetName()+"' in "+thisParam->GetLine()->GetLevel()->GetFilename()+":"+boost::lexical_cast<std::string>(thisParam->GetLine()->GetLineNumber())+")")
+{
+}
diff --git a/src/object/level/parserexceptions.h b/src/object/level/parserexceptions.h
new file mode 100644
index 0000000..7265d8b
--- /dev/null
+++ b/src/object/level/parserexceptions.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+/**
+ * \file object/level/parserexceptions.h
+ * \brief Exceptions that could be thrown in level parser
+ */
+
+#pragma once
+
+#include <exception>
+#include <string>
+
+class CLevelParserParam;
+
+class CLevelParserException : public std::exception
+{
+public:
+ CLevelParserException(std::string message) noexcept;
+ virtual ~CLevelParserException() noexcept {}
+ const char* what() const noexcept;
+
+protected:
+ std::string m_message;
+};
+
+class CLevelParserExceptionMissingParam : public CLevelParserException
+{
+public:
+ CLevelParserExceptionMissingParam(CLevelParserParam* thisParam) noexcept;
+ virtual ~CLevelParserExceptionMissingParam() noexcept {}
+};
+
+class CLevelParserExceptionBadParam : public CLevelParserException
+{
+public:
+ CLevelParserExceptionBadParam(CLevelParserParam* thisParam, std::string requestedType) noexcept;
+ virtual ~CLevelParserExceptionBadParam() noexcept {}
+}; \ No newline at end of file
diff --git a/src/object/level/parserline.cpp b/src/object/level/parserline.cpp
new file mode 100644
index 0000000..e0e8097
--- /dev/null
+++ b/src/object/level/parserline.cpp
@@ -0,0 +1,90 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "object/level/parserline.h"
+
+
+#include "object/level/parser.h"
+#include "common/logger.h"
+
+CLevelParserLine::CLevelParserLine(std::string command)
+{
+ m_command = command;
+ m_lineNumber = 0;
+}
+
+CLevelParserLine::CLevelParserLine(int lineNumber, std::string command)
+{
+ m_command = command;
+ m_lineNumber = lineNumber;
+}
+
+CLevelParserLine::~CLevelParserLine()
+{
+ for(auto param : m_params)
+ {
+ delete param.second;
+ }
+}
+
+std::string CLevelParserLine::GetLine()
+{
+ assert(false); //TODO
+}
+
+int CLevelParserLine::GetLineNumber()
+{
+ return m_lineNumber;
+}
+
+CLevelParser* CLevelParserLine::GetLevel()
+{
+ return m_level;
+}
+
+void CLevelParserLine::SetLevel(CLevelParser* level)
+{
+ m_level = level;
+}
+
+std::string CLevelParserLine::GetCommand()
+{
+ return m_command;
+}
+
+void CLevelParserLine::SetCommand(std::string command)
+{
+ m_command = command;
+}
+
+CLevelParserParam* CLevelParserLine::GetParam(std::string name)
+{
+ if(m_params[name] == nullptr) {
+ CLevelParserParam* param = new CLevelParserParam(name, true);
+ param->SetLine(this);
+ m_params[name] = param;
+ }
+ return m_params[name];
+}
+
+void CLevelParserLine::AddParam(std::string name, CLevelParserParam* value)
+{
+ value->SetLine(this);
+ m_params[name] = value;
+} \ No newline at end of file
diff --git a/src/object/level/parserline.h b/src/object/level/parserline.h
new file mode 100644
index 0000000..9881ac7
--- /dev/null
+++ b/src/object/level/parserline.h
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+/**
+ * \file object/level/parserline.h
+ * \brief Class for one line from level file
+ */
+
+#pragma once
+
+#include <string>
+#include <map>
+
+class CLevelParser;
+class CLevelParserParam;
+
+class CLevelParserLine
+{
+public:
+ CLevelParserLine(int lineNumber, std::string command);
+ CLevelParserLine(std::string command);
+ ~CLevelParserLine();
+
+ //! Get line to be saved in level file
+ std::string GetLine();
+
+ //! Get line number
+ int GetLineNumber();
+
+ //! Get CLevelParser this line is part of
+ CLevelParser* GetLevel();
+ //! Set CLevelParser this line is part of
+ void SetLevel(CLevelParser* level);
+
+ std::string GetCommand();
+ void SetCommand(std::string command);
+
+ CLevelParserParam* GetParam(std::string name);
+ void AddParam(std::string name, CLevelParserParam* value);
+
+private:
+ CLevelParser* m_level;
+ int m_lineNumber;
+ std::string m_command;
+ std::map<std::string, CLevelParserParam*> m_params;
+}; \ No newline at end of file
diff --git a/src/object/level/parserparam.cpp b/src/object/level/parserparam.cpp
new file mode 100644
index 0000000..aa5a963
--- /dev/null
+++ b/src/object/level/parserparam.cpp
@@ -0,0 +1,940 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "object/level/parserline.h"
+
+
+#include "app/app.h"
+#include "common/logger.h"
+#include "object/level/parser.h"
+#include "object/robotmain.h"
+
+#include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string.hpp>
+
+CLevelParserParam::CLevelParserParam(std::string name, std::string value)
+{
+ m_name = name;
+ m_value = value;
+ m_empty = false;
+}
+
+CLevelParserParam::CLevelParserParam(std::string name, bool empty)
+{
+ assert(empty == true); // we need a second argument because we don't want to create param with value "name"
+ m_name = name;
+ m_value = "";
+ m_empty = true;
+}
+
+CLevelParserParam::~CLevelParserParam()
+{
+ for(auto& a : m_array)
+ delete a;
+}
+
+void CLevelParserParam::SetLine(CLevelParserLine* line)
+{
+ m_line = line;
+}
+
+CLevelParserLine* CLevelParserParam::GetLine()
+{
+ return m_line;
+}
+
+std::string CLevelParserParam::GetName()
+{
+ return m_name;
+}
+
+std::string CLevelParserParam::GetValue()
+{
+ return m_value;
+}
+
+bool CLevelParserParam::IsDefined()
+{
+ return !m_empty;
+}
+
+template<typename T>
+T CLevelParserParam::Cast(std::string value, std::string requestedType)
+{
+ try {
+ return boost::lexical_cast<T>(value);
+ }
+ catch(...)
+ {
+ throw CLevelParserExceptionBadParam(this, requestedType);
+ }
+}
+
+template<typename T>
+T CLevelParserParam::Cast(std::string requestedType)
+{
+ return Cast<T>(m_value, requestedType);
+}
+
+
+int CLevelParserParam::AsInt()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return Cast<int>("int");
+}
+
+
+int CLevelParserParam::AsInt(int def)
+{
+ if(m_empty)
+ return def;
+ return AsInt();
+}
+
+
+float CLevelParserParam::AsFloat()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return Cast<float>("float");
+}
+
+float CLevelParserParam::AsFloat(float def)
+{
+ if(m_empty)
+ return def;
+ return AsFloat();
+}
+
+
+std::string CLevelParserParam::AsString()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ if((m_value[0] == '\"' && m_value[m_value.length()-1] == '\"') || (m_value[0] == '\'' && m_value[m_value.length()-1] == '\''))
+ {
+ return m_value.substr(1, m_value.length()-2);
+ } else {
+ throw CLevelParserExceptionBadParam(this, "string");
+ }
+}
+
+std::string CLevelParserParam::AsString(std::string def)
+{
+ if(m_empty)
+ return def;
+ return AsString();
+}
+
+
+bool CLevelParserParam::AsBool()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ std::string value = m_value;
+ boost::to_lower(value);
+ if(value == "true") return true;
+ if(value == "false") return false;
+ return Cast<bool>("bool");
+}
+
+bool CLevelParserParam::AsBool(bool def)
+{
+ if(m_empty)
+ return def;
+ return AsBool();
+}
+
+
+std::string CLevelParserParam::InjectLevelDir(std::string path, const std::string defaultDir)
+{
+ std::string newPath = path;
+ std::string lvlDir = CLevelParser::BuildSceneName(CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank()/100, CRobotMain::GetInstancePointer()->GetSceneRank()%100, false);
+ boost::replace_all(newPath, "%lvl%", lvlDir);
+ std::string chapDir = CLevelParser::BuildSceneName(CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank()/100, 0, false);
+ boost::replace_all(newPath, "%chap%", chapDir);
+ if(newPath == path)
+ {
+ newPath = defaultDir + (!defaultDir.empty() ? "/" : "") + newPath;
+ }
+ //TODO: Fallback to English
+ std::string langStr(1, CApplication::GetInstancePointer()->GetLanguageChar());
+ boost::replace_all(newPath, "%lng%", langStr);
+ return newPath;
+}
+
+std::string CLevelParserParam::ToPath(std::string path, const std::string defaultDir)
+{
+ if(defaultDir == "" && path.find("%lvl%") != std::string::npos)
+ throw CLevelParserException("TODO: Param "+m_name+" does not yet support %lvl%! :(");
+
+ return InjectLevelDir(path, defaultDir);
+}
+
+std::string CLevelParserParam::AsPath(const std::string defaultDir)
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+
+ return ToPath(AsString(), defaultDir);
+}
+
+std::string CLevelParserParam::AsPath(const std::string defaultDir, std::string def)
+{
+ if(m_empty)
+ return InjectLevelDir(def, defaultDir);
+
+ return ToPath(AsString(def), defaultDir);
+}
+
+
+Gfx::Color CLevelParserParam::AsColor()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+
+ ParseArray();
+
+ if(m_array.size() == 3) { //RGB
+ return Gfx::Color(m_array[0]->AsFloat(), m_array[1]->AsFloat(), m_array[2]->AsFloat());
+ } else if(m_array.size() == 4) { //RGBA
+ return Gfx::Color(m_array[0]->AsFloat(), m_array[1]->AsFloat(), m_array[2]->AsFloat(), m_array[3]->AsFloat());
+ } else {
+ throw CLevelParserExceptionBadParam(this, "color");
+ }
+}
+
+Gfx::Color CLevelParserParam::AsColor(Gfx::Color def)
+{
+ if(m_empty)
+ return def;
+ return AsColor();
+}
+
+
+Math::Vector CLevelParserParam::AsPoint()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+
+ ParseArray();
+
+ if(m_array.size() == 2) { //XZ
+ return Math::Vector(m_array[0]->AsFloat(), 0.0f, m_array[1]->AsFloat());
+ } else if(m_array.size() == 3) { //XYZ
+ return Math::Vector(m_array[0]->AsFloat(), m_array[1]->AsFloat(), m_array[2]->AsFloat());
+ } else {
+ throw CLevelParserExceptionBadParam(this, "point");
+ }
+}
+
+Math::Vector CLevelParserParam::AsPoint(Math::Vector def)
+{
+ if(m_empty)
+ return def;
+ return AsPoint();
+}
+
+
+ObjectType CLevelParserParam::ToObjectType(std::string value)
+{
+ if(value == "All" ) return OBJECT_NULL;
+ if(value == "Portico" ) return OBJECT_PORTICO;
+ if(value == "SpaceShip" ) return OBJECT_BASE;
+ if(value == "PracticeBot" ) return OBJECT_MOBILEwt;
+ if(value == "WingedGrabber" ) return OBJECT_MOBILEfa;
+ if(value == "TrackedGrabber" ) return OBJECT_MOBILEta;
+ if(value == "WheeledGrabber" ) return OBJECT_MOBILEwa;
+ if(value == "LeggedGrabber" ) return OBJECT_MOBILEia;
+ if(value == "WingedShooter" ) return OBJECT_MOBILEfc;
+ if(value == "TrackedShooter" ) return OBJECT_MOBILEtc;
+ if(value == "WheeledShooter" ) return OBJECT_MOBILEwc;
+ if(value == "LeggedShooter" ) return OBJECT_MOBILEic;
+ if(value == "WingedOrgaShooter" ) return OBJECT_MOBILEfi;
+ if(value == "TrackedOrgaShooter") return OBJECT_MOBILEti;
+ if(value == "WheeledOrgaShooter") return OBJECT_MOBILEwi;
+ if(value == "LeggedOrgaShooter" ) return OBJECT_MOBILEii;
+ if(value == "WingedSniffer" ) return OBJECT_MOBILEfs;
+ if(value == "TrackedSniffer" ) return OBJECT_MOBILEts;
+ if(value == "WheeledSniffer" ) return OBJECT_MOBILEws;
+ if(value == "LeggedSniffer" ) return OBJECT_MOBILEis;
+ if(value == "Thumper" ) return OBJECT_MOBILErt;
+ if(value == "PhazerShooter" ) return OBJECT_MOBILErc;
+ if(value == "Recycler" ) return OBJECT_MOBILErr;
+ if(value == "Shielder" ) return OBJECT_MOBILErs;
+ if(value == "Subber" ) return OBJECT_MOBILEsa;
+ if(value == "TargetBot" ) return OBJECT_MOBILEtg;
+ if(value == "Scribbler" ) return OBJECT_MOBILEdr;
+ if(value == "PowerSpot" ) return OBJECT_MARKPOWER;
+ if(value == "TitaniumSpot" ) return OBJECT_MARKSTONE;
+ if(value == "UraniumSpot" ) return OBJECT_MARKURANIUM;
+ if(value == "PlatinumSpot" ) return OBJECT_MARKURANIUM;
+ if(value == "KeyASpot" ) return OBJECT_MARKKEYa;
+ if(value == "KeyBSpot" ) return OBJECT_MARKKEYb;
+ if(value == "KeyCSpot" ) return OBJECT_MARKKEYc;
+ if(value == "KeyDSpot" ) return OBJECT_MARKKEYd;
+ if(value == "WayPoint" ) return OBJECT_WAYPOINT;
+ if(value == "BlueFlag" ) return OBJECT_FLAGb;
+ if(value == "RedFlag" ) return OBJECT_FLAGr;
+ if(value == "GreenFlag" ) return OBJECT_FLAGg;
+ if(value == "YellowFlag" ) return OBJECT_FLAGy;
+ if(value == "VioletFlag" ) return OBJECT_FLAGv;
+ if(value == "PowerCell" ) return OBJECT_POWER;
+ if(value == "FuelCellPlant" ) return OBJECT_NUCLEAR;
+ if(value == "FuelCell" ) return OBJECT_ATOMIC;
+ if(value == "NuclearCell" ) return OBJECT_ATOMIC;
+ if(value == "TitaniumOre" ) return OBJECT_STONE;
+ if(value == "UraniumOre" ) return OBJECT_URANIUM;
+ if(value == "PlatinumOre" ) return OBJECT_URANIUM;
+ if(value == "Titanium" ) return OBJECT_METAL;
+ if(value == "OrgaMatter" ) return OBJECT_BULLET;
+ if(value == "BlackBox" ) return OBJECT_BBOX;
+ if(value == "KeyA" ) return OBJECT_KEYa;
+ if(value == "KeyB" ) return OBJECT_KEYb;
+ if(value == "KeyC" ) return OBJECT_KEYc;
+ if(value == "KeyD" ) return OBJECT_KEYd;
+ if(value == "TNT" ) return OBJECT_TNT;
+ if(value == "Scrap1" ) return OBJECT_SCRAP1;
+ if(value == "Scrap2" ) return OBJECT_SCRAP2;
+ if(value == "Scrap3" ) return OBJECT_SCRAP3;
+ if(value == "Scrap4" ) return OBJECT_SCRAP4;
+ if(value == "Scrap5" ) return OBJECT_SCRAP5;
+ if(value == "Mine" ) return OBJECT_BOMB;
+ if(value == "Firework" ) return OBJECT_WINFIRE;
+ if(value == "Bag" ) return OBJECT_BAG;
+ if(value == "Greenery0" ) return OBJECT_PLANT0;
+ if(value == "Greenery1" ) return OBJECT_PLANT1;
+ if(value == "Greenery2" ) return OBJECT_PLANT2;
+ if(value == "Greenery3" ) return OBJECT_PLANT3;
+ if(value == "Greenery4" ) return OBJECT_PLANT4;
+ if(value == "Greenery5" ) return OBJECT_PLANT5;
+ if(value == "Greenery6" ) return OBJECT_PLANT6;
+ if(value == "Greenery7" ) return OBJECT_PLANT7;
+ if(value == "Greenery8" ) return OBJECT_PLANT8;
+ if(value == "Greenery9" ) return OBJECT_PLANT9;
+ if(value == "Greenery10" ) return OBJECT_PLANT10;
+ if(value == "Greenery11" ) return OBJECT_PLANT11;
+ if(value == "Greenery12" ) return OBJECT_PLANT12;
+ if(value == "Greenery13" ) return OBJECT_PLANT13;
+ if(value == "Greenery14" ) return OBJECT_PLANT14;
+ if(value == "Greenery15" ) return OBJECT_PLANT15;
+ if(value == "Greenery16" ) return OBJECT_PLANT16;
+ if(value == "Greenery17" ) return OBJECT_PLANT17;
+ if(value == "Greenery18" ) return OBJECT_PLANT18;
+ if(value == "Greenery19" ) return OBJECT_PLANT19;
+ if(value == "Tree0" ) return OBJECT_TREE0;
+ if(value == "Tree1" ) return OBJECT_TREE1;
+ if(value == "Tree2" ) return OBJECT_TREE2;
+ if(value == "Tree3" ) return OBJECT_TREE3;
+ if(value == "Tree4" ) return OBJECT_TREE4;
+ if(value == "Tree5" ) return OBJECT_TREE5;
+ if(value == "Mushroom1" ) return OBJECT_MUSHROOM1;
+ if(value == "Mushroom2" ) return OBJECT_MUSHROOM2;
+ if(value == "Home" ) return OBJECT_HOME1;
+ if(value == "Derrick" ) return OBJECT_DERRICK;
+ if(value == "BotFactory" ) return OBJECT_FACTORY;
+ if(value == "PowerStation" ) return OBJECT_STATION;
+ if(value == "Converter" ) return OBJECT_CONVERT;
+ if(value == "RepairCenter" ) return OBJECT_REPAIR;
+ if(value == "Destroyer" ) return OBJECT_DESTROYER;
+ if(value == "DefenseTower" ) return OBJECT_TOWER;
+ if(value == "AlienNest" ) return OBJECT_NEST;
+ if(value == "ResearchCenter" ) return OBJECT_RESEARCH;
+ if(value == "RadarStation" ) return OBJECT_RADAR;
+ if(value == "ExchangePost" ) return OBJECT_INFO;
+ if(value == "PowerPlant" ) return OBJECT_ENERGY;
+ if(value == "AutoLab" ) return OBJECT_LABO;
+ if(value == "NuclearPlant" ) return OBJECT_NUCLEAR;
+ if(value == "PowerCaptor" ) return OBJECT_PARA;
+ if(value == "Vault" ) return OBJECT_SAFE;
+ if(value == "Houston" ) return OBJECT_HUSTON;
+ if(value == "Target1" ) return OBJECT_TARGET1;
+ if(value == "Target2" ) return OBJECT_TARGET2;
+ if(value == "StartArea" ) return OBJECT_START;
+ if(value == "GoalArea" ) return OBJECT_END;
+ if(value == "AlienQueen" ) return OBJECT_MOTHER;
+ if(value == "AlienEgg" ) return OBJECT_EGG;
+ if(value == "AlienAnt" ) return OBJECT_ANT;
+ if(value == "AlienSpider" ) return OBJECT_SPIDER;
+ if(value == "AlienWasp" ) return OBJECT_BEE;
+ if(value == "AlienWorm" ) return OBJECT_WORM;
+ if(value == "WreckBotw1" ) return OBJECT_RUINmobilew1;
+ if(value == "WreckBotw2" ) return OBJECT_RUINmobilew2;
+ if(value == "WreckBott1" ) return OBJECT_RUINmobilet1;
+ if(value == "WreckBott2" ) return OBJECT_RUINmobilet2;
+ if(value == "WreckBotr1" ) return OBJECT_RUINmobiler1;
+ if(value == "WreckBotr2" ) return OBJECT_RUINmobiler2;
+ if(value == "RuinBotFactory" ) return OBJECT_RUINfactory;
+ if(value == "RuinDoor" ) return OBJECT_RUINdoor;
+ if(value == "RuinSupport" ) return OBJECT_RUINsupport;
+ if(value == "RuinRadar" ) return OBJECT_RUINradar;
+ if(value == "RuinConvert" ) return OBJECT_RUINconvert;
+ if(value == "RuinBaseCamp" ) return OBJECT_RUINbase;
+ if(value == "RuinHeadCamp" ) return OBJECT_RUINhead;
+ if(value == "Barrier0" ) return OBJECT_BARRIER0;
+ if(value == "Barrier1" ) return OBJECT_BARRIER1;
+ if(value == "Barrier2" ) return OBJECT_BARRIER2;
+ if(value == "Barrier3" ) return OBJECT_BARRIER3;
+ if(value == "Teen0" ) return OBJECT_TEEN0;
+ if(value == "Teen1" ) return OBJECT_TEEN1;
+ if(value == "Teen2" ) return OBJECT_TEEN2;
+ if(value == "Teen3" ) return OBJECT_TEEN3;
+ if(value == "Teen4" ) return OBJECT_TEEN4;
+ if(value == "Teen5" ) return OBJECT_TEEN5;
+ if(value == "Teen6" ) return OBJECT_TEEN6;
+ if(value == "Teen7" ) return OBJECT_TEEN7;
+ if(value == "Teen8" ) return OBJECT_TEEN8;
+ if(value == "Teen9" ) return OBJECT_TEEN9;
+ if(value == "Teen10" ) return OBJECT_TEEN10;
+ if(value == "Teen11" ) return OBJECT_TEEN11;
+ if(value == "Teen12" ) return OBJECT_TEEN12;
+ if(value == "Teen13" ) return OBJECT_TEEN13;
+ if(value == "Teen14" ) return OBJECT_TEEN14;
+ if(value == "Teen15" ) return OBJECT_TEEN15;
+ if(value == "Teen16" ) return OBJECT_TEEN16;
+ if(value == "Teen17" ) return OBJECT_TEEN17;
+ if(value == "Teen18" ) return OBJECT_TEEN18;
+ if(value == "Teen19" ) return OBJECT_TEEN19;
+ if(value == "Teen20" ) return OBJECT_TEEN20;
+ if(value == "Teen21" ) return OBJECT_TEEN21;
+ if(value == "Teen22" ) return OBJECT_TEEN22;
+ if(value == "Teen23" ) return OBJECT_TEEN23;
+ if(value == "Teen24" ) return OBJECT_TEEN24;
+ if(value == "Teen25" ) return OBJECT_TEEN25;
+ if(value == "Teen26" ) return OBJECT_TEEN26;
+ if(value == "Teen27" ) return OBJECT_TEEN27;
+ if(value == "Teen28" ) return OBJECT_TEEN28;
+ if(value == "Teen29" ) return OBJECT_TEEN29;
+ if(value == "Teen30" ) return OBJECT_TEEN30;
+ if(value == "Teen31" ) return OBJECT_TEEN31;
+ if(value == "Teen32" ) return OBJECT_TEEN32;
+ if(value == "Teen33" ) return OBJECT_TEEN33;
+ if(value == "Stone" ) return OBJECT_TEEN34;
+ if(value == "Teen35" ) return OBJECT_TEEN35;
+ if(value == "Teen36" ) return OBJECT_TEEN36;
+ if(value == "Teen37" ) return OBJECT_TEEN37;
+ if(value == "Teen38" ) return OBJECT_TEEN38;
+ if(value == "Teen39" ) return OBJECT_TEEN39;
+ if(value == "Teen40" ) return OBJECT_TEEN40;
+ if(value == "Teen41" ) return OBJECT_TEEN41;
+ if(value == "Teen42" ) return OBJECT_TEEN42;
+ if(value == "Teen43" ) return OBJECT_TEEN43;
+ if(value == "Teen44" ) return OBJECT_TEEN44;
+ if(value == "Quartz0" ) return OBJECT_QUARTZ0;
+ if(value == "Quartz1" ) return OBJECT_QUARTZ1;
+ if(value == "Quartz2" ) return OBJECT_QUARTZ2;
+ if(value == "Quartz3" ) return OBJECT_QUARTZ3;
+ if(value == "MegaStalk0" ) return OBJECT_ROOT0;
+ if(value == "MegaStalk1" ) return OBJECT_ROOT1;
+ if(value == "MegaStalk2" ) return OBJECT_ROOT2;
+ if(value == "MegaStalk3" ) return OBJECT_ROOT3;
+ if(value == "MegaStalk4" ) return OBJECT_ROOT4;
+ if(value == "MegaStalk5" ) return OBJECT_ROOT5;
+ if(value == "ApolloLEM" ) return OBJECT_APOLLO1;
+ if(value == "ApolloJeep" ) return OBJECT_APOLLO2;
+ if(value == "ApolloFlag" ) return OBJECT_APOLLO3;
+ if(value == "ApolloModule" ) return OBJECT_APOLLO4;
+ if(value == "ApolloAntenna" ) return OBJECT_APOLLO5;
+ if(value == "Me" ) return OBJECT_HUMAN;
+ if(value == "Tech" ) return OBJECT_TECH;
+ if(value == "MissionController" ) return OBJECT_CONTROLLER;
+ return static_cast<ObjectType>(Cast<int>(value, "object"));
+}
+
+const std::string CLevelParserParam::FromObjectType(ObjectType value)
+{
+ if(value == OBJECT_PORTICO ) return "Portico";
+ if(value == OBJECT_BASE ) return "SpaceShip";
+ if(value == OBJECT_MOBILEwt ) return "PracticeBot";
+ if(value == OBJECT_MOBILEfa ) return "WingedGrabber";
+ if(value == OBJECT_MOBILEta ) return "TrackedGrabber";
+ if(value == OBJECT_MOBILEwa ) return "WheeledGrabber";
+ if(value == OBJECT_MOBILEia ) return "LeggedGrabber";
+ if(value == OBJECT_MOBILEfc ) return "WingedShooter";
+ if(value == OBJECT_MOBILEtc ) return "TrackedShooter";
+ if(value == OBJECT_MOBILEwc ) return "WheeledShooter";
+ if(value == OBJECT_MOBILEic ) return "LeggedShooter";
+ if(value == OBJECT_MOBILEfi ) return "WingedOrgaShooter";
+ if(value == OBJECT_MOBILEti ) return "TrackedOrgaShooter";
+ if(value == OBJECT_MOBILEwi ) return "WheeledOrgaShooter";
+ if(value == OBJECT_MOBILEii ) return "LeggedOrgaShooter";
+ if(value == OBJECT_MOBILEfs ) return "WingedSniffer";
+ if(value == OBJECT_MOBILEts ) return "TrackedSniffer";
+ if(value == OBJECT_MOBILEws ) return "WheeledSniffer";
+ if(value == OBJECT_MOBILEis ) return "LeggedSniffer";
+ if(value == OBJECT_MOBILErt ) return "Thumper";
+ if(value == OBJECT_MOBILErc ) return "PhazerShooter";
+ if(value == OBJECT_MOBILErr ) return "Recycler";
+ if(value == OBJECT_MOBILErs ) return "Shielder";
+ if(value == OBJECT_MOBILEsa ) return "Subber";
+ if(value == OBJECT_MOBILEtg ) return "TargetBot";
+ if(value == OBJECT_MOBILEdr ) return "Scribbler";
+ if(value == OBJECT_MARKPOWER ) return "PowerSpot";
+ if(value == OBJECT_MARKSTONE ) return "TitaniumSpot";
+ if(value == OBJECT_MARKURANIUM ) return "UraniumSpot";
+ if(value == OBJECT_MARKKEYa ) return "KeyASpot";
+ if(value == OBJECT_MARKKEYb ) return "KeyBSpot";
+ if(value == OBJECT_MARKKEYc ) return "KeyCSpot";
+ if(value == OBJECT_MARKKEYd ) return "KeyDSpot";
+ if(value == OBJECT_WAYPOINT ) return "WayPoint";
+ if(value == OBJECT_FLAGb ) return "BlueFlag";
+ if(value == OBJECT_FLAGr ) return "RedFlag";
+ if(value == OBJECT_FLAGg ) return "GreenFlag";
+ if(value == OBJECT_FLAGy ) return "YellowFlag";
+ if(value == OBJECT_FLAGv ) return "VioletFlag";
+ if(value == OBJECT_POWER ) return "PowerCell";
+ if(value == OBJECT_ATOMIC ) return "NuclearCell";
+ if(value == OBJECT_STONE ) return "TitaniumOre";
+ if(value == OBJECT_URANIUM ) return "UraniumOre";
+ if(value == OBJECT_METAL ) return "Titanium";
+ if(value == OBJECT_BULLET ) return "OrgaMatter";
+ if(value == OBJECT_BBOX ) return "BlackBox";
+ if(value == OBJECT_KEYa ) return "KeyA";
+ if(value == OBJECT_KEYb ) return "KeyB";
+ if(value == OBJECT_KEYc ) return "KeyC";
+ if(value == OBJECT_KEYd ) return "KeyD";
+ if(value == OBJECT_TNT ) return "TNT";
+ if(value == OBJECT_SCRAP1 ) return "Scrap1";
+ if(value == OBJECT_SCRAP2 ) return "Scrap2";
+ if(value == OBJECT_SCRAP3 ) return "Scrap3";
+ if(value == OBJECT_SCRAP4 ) return "Scrap4";
+ if(value == OBJECT_SCRAP5 ) return "Scrap5";
+ if(value == OBJECT_BOMB ) return "Mine";
+ if(value == OBJECT_WINFIRE ) return "Firework";
+ if(value == OBJECT_BAG ) return "Bag";
+ if(value == OBJECT_PLANT0 ) return "Greenery0";
+ if(value == OBJECT_PLANT1 ) return "Greenery1";
+ if(value == OBJECT_PLANT2 ) return "Greenery2";
+ if(value == OBJECT_PLANT3 ) return "Greenery3";
+ if(value == OBJECT_PLANT4 ) return "Greenery4";
+ if(value == OBJECT_PLANT5 ) return "Greenery5";
+ if(value == OBJECT_PLANT6 ) return "Greenery6";
+ if(value == OBJECT_PLANT7 ) return "Greenery7";
+ if(value == OBJECT_PLANT8 ) return "Greenery8";
+ if(value == OBJECT_PLANT9 ) return "Greenery9";
+ if(value == OBJECT_PLANT10 ) return "Greenery10";
+ if(value == OBJECT_PLANT11 ) return "Greenery11";
+ if(value == OBJECT_PLANT12 ) return "Greenery12";
+ if(value == OBJECT_PLANT13 ) return "Greenery13";
+ if(value == OBJECT_PLANT14 ) return "Greenery14";
+ if(value == OBJECT_PLANT15 ) return "Greenery15";
+ if(value == OBJECT_PLANT16 ) return "Greenery16";
+ if(value == OBJECT_PLANT17 ) return "Greenery17";
+ if(value == OBJECT_PLANT18 ) return "Greenery18";
+ if(value == OBJECT_PLANT19 ) return "Greenery19";
+ if(value == OBJECT_TREE0 ) return "Tree0";
+ if(value == OBJECT_TREE1 ) return "Tree1";
+ if(value == OBJECT_TREE2 ) return "Tree2";
+ if(value == OBJECT_TREE3 ) return "Tree3";
+ if(value == OBJECT_TREE4 ) return "Tree4";
+ if(value == OBJECT_TREE5 ) return "Tree5";
+ if(value == OBJECT_MUSHROOM1 ) return "Mushroom1";
+ if(value == OBJECT_MUSHROOM2 ) return "Mushroom2";
+ if(value == OBJECT_HOME1 ) return "Home";
+ if(value == OBJECT_DERRICK ) return "Derrick";
+ if(value == OBJECT_FACTORY ) return "BotFactory";
+ if(value == OBJECT_STATION ) return "PowerStation";
+ if(value == OBJECT_CONVERT ) return "Converter";
+ if(value == OBJECT_REPAIR ) return "RepairCenter";
+ if(value == OBJECT_DESTROYER ) return "Destroyer";
+ if(value == OBJECT_TOWER ) return "DefenseTower";
+ if(value == OBJECT_NEST ) return "AlienNest";
+ if(value == OBJECT_RESEARCH ) return "ResearchCenter";
+ if(value == OBJECT_RADAR ) return "RadarStation";
+ if(value == OBJECT_INFO ) return "ExchangePost";
+ if(value == OBJECT_ENERGY ) return "PowerPlant";
+ if(value == OBJECT_LABO ) return "AutoLab";
+ if(value == OBJECT_NUCLEAR ) return "NuclearPlant";
+ if(value == OBJECT_PARA ) return "PowerCaptor";
+ if(value == OBJECT_SAFE ) return "Vault";
+ if(value == OBJECT_HUSTON ) return "Houston";
+ if(value == OBJECT_TARGET1 ) return "Target1";
+ if(value == OBJECT_TARGET2 ) return "Target2";
+ if(value == OBJECT_START ) return "StartArea";
+ if(value == OBJECT_END ) return "GoalArea";
+ if(value == OBJECT_MOTHER ) return "AlienQueen";
+ if(value == OBJECT_EGG ) return "AlienEgg";
+ if(value == OBJECT_ANT ) return "AlienAnt";
+ if(value == OBJECT_SPIDER ) return "AlienSpider";
+ if(value == OBJECT_BEE ) return "AlienWasp";
+ if(value == OBJECT_WORM ) return "AlienWorm";
+ if(value == OBJECT_RUINmobilew1) return "WreckBotw1";
+ if(value == OBJECT_RUINmobilew2) return "WreckBotw2";
+ if(value == OBJECT_RUINmobilet1) return "WreckBott1";
+ if(value == OBJECT_RUINmobilet2) return "WreckBott2";
+ if(value == OBJECT_RUINmobiler1) return "WreckBotr1";
+ if(value == OBJECT_RUINmobiler2) return "WreckBotr2";
+ if(value == OBJECT_RUINfactory ) return "RuinBotFactory";
+ if(value == OBJECT_RUINdoor ) return "RuinDoor";
+ if(value == OBJECT_RUINsupport ) return "RuinSupport";
+ if(value == OBJECT_RUINradar ) return "RuinRadar";
+ if(value == OBJECT_RUINconvert ) return "RuinConvert";
+ if(value == OBJECT_RUINbase ) return "RuinBaseCamp";
+ if(value == OBJECT_RUINhead ) return "RuinHeadCamp";
+ if(value == OBJECT_BARRIER0 ) return "Barrier0";
+ if(value == OBJECT_BARRIER1 ) return "Barrier1";
+ if(value == OBJECT_BARRIER2 ) return "Barrier2";
+ if(value == OBJECT_BARRIER3 ) return "Barrier3";
+ if(value == OBJECT_TEEN0 ) return "Teen0";
+ if(value == OBJECT_TEEN1 ) return "Teen1";
+ if(value == OBJECT_TEEN2 ) return "Teen2";
+ if(value == OBJECT_TEEN3 ) return "Teen3";
+ if(value == OBJECT_TEEN4 ) return "Teen4";
+ if(value == OBJECT_TEEN5 ) return "Teen5";
+ if(value == OBJECT_TEEN6 ) return "Teen6";
+ if(value == OBJECT_TEEN7 ) return "Teen7";
+ if(value == OBJECT_TEEN8 ) return "Teen8";
+ if(value == OBJECT_TEEN9 ) return "Teen9";
+ if(value == OBJECT_TEEN10 ) return "Teen10";
+ if(value == OBJECT_TEEN11 ) return "Teen11";
+ if(value == OBJECT_TEEN12 ) return "Teen12";
+ if(value == OBJECT_TEEN13 ) return "Teen13";
+ if(value == OBJECT_TEEN14 ) return "Teen14";
+ if(value == OBJECT_TEEN15 ) return "Teen15";
+ if(value == OBJECT_TEEN16 ) return "Teen16";
+ if(value == OBJECT_TEEN17 ) return "Teen17";
+ if(value == OBJECT_TEEN18 ) return "Teen18";
+ if(value == OBJECT_TEEN19 ) return "Teen19";
+ if(value == OBJECT_TEEN20 ) return "Teen20";
+ if(value == OBJECT_TEEN21 ) return "Teen21";
+ if(value == OBJECT_TEEN22 ) return "Teen22";
+ if(value == OBJECT_TEEN23 ) return "Teen23";
+ if(value == OBJECT_TEEN24 ) return "Teen24";
+ if(value == OBJECT_TEEN25 ) return "Teen25";
+ if(value == OBJECT_TEEN26 ) return "Teen26";
+ if(value == OBJECT_TEEN27 ) return "Teen27";
+ if(value == OBJECT_TEEN28 ) return "Teen28";
+ if(value == OBJECT_TEEN29 ) return "Teen29";
+ if(value == OBJECT_TEEN30 ) return "Teen30";
+ if(value == OBJECT_TEEN31 ) return "Teen31";
+ if(value == OBJECT_TEEN32 ) return "Teen32";
+ if(value == OBJECT_TEEN33 ) return "Teen33";
+ if(value == OBJECT_TEEN34 ) return "Stone";
+ if(value == OBJECT_TEEN35 ) return "Teen35";
+ if(value == OBJECT_TEEN36 ) return "Teen36";
+ if(value == OBJECT_TEEN37 ) return "Teen37";
+ if(value == OBJECT_TEEN38 ) return "Teen38";
+ if(value == OBJECT_TEEN39 ) return "Teen39";
+ if(value == OBJECT_TEEN40 ) return "Teen40";
+ if(value == OBJECT_TEEN41 ) return "Teen41";
+ if(value == OBJECT_TEEN42 ) return "Teen42";
+ if(value == OBJECT_TEEN43 ) return "Teen43";
+ if(value == OBJECT_TEEN44 ) return "Teen44";
+ if(value == OBJECT_QUARTZ0 ) return "Quartz0";
+ if(value == OBJECT_QUARTZ1 ) return "Quartz1";
+ if(value == OBJECT_QUARTZ2 ) return "Quartz2";
+ if(value == OBJECT_QUARTZ3 ) return "Quartz3";
+ if(value == OBJECT_ROOT0 ) return "MegaStalk0";
+ if(value == OBJECT_ROOT1 ) return "MegaStalk1";
+ if(value == OBJECT_ROOT2 ) return "MegaStalk2";
+ if(value == OBJECT_ROOT3 ) return "MegaStalk3";
+ if(value == OBJECT_ROOT4 ) return "MegaStalk4";
+ if(value == OBJECT_ROOT5 ) return "MegaStalk5";
+ if(value == OBJECT_APOLLO1 ) return "ApolloLEM";
+ if(value == OBJECT_APOLLO2 ) return "ApolloJeep";
+ if(value == OBJECT_APOLLO3 ) return "ApolloFlag";
+ if(value == OBJECT_APOLLO4 ) return "ApolloModule";
+ if(value == OBJECT_APOLLO5 ) return "ApolloAntenna";
+ if(value == OBJECT_HUMAN ) return "Me";
+ if(value == OBJECT_TECH ) return "Tech";
+ if(value == OBJECT_CONTROLLER ) return "MissionController";
+ return boost::lexical_cast<std::string>(static_cast<int>(value));
+}
+
+ObjectType CLevelParserParam::AsObjectType()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return ToObjectType(m_value);
+}
+
+ObjectType CLevelParserParam::AsObjectType(ObjectType def)
+{
+ if(m_empty)
+ return def;
+ return AsObjectType();
+}
+
+
+DriveType CLevelParserParam::ToDriveType(std::string value)
+{
+ if(value == "Wheeled") return DRIVE_WHEELED;
+ if(value == "Tracked") return DRIVE_TRACKED;
+ if(value == "Winged" ) return DRIVE_WINGED;
+ if(value == "Legged" ) return DRIVE_LEGGED;
+ if(value == "Other" ) return DRIVE_OTHER;
+ return static_cast<DriveType>(Cast<int>(value, "drive"));
+}
+
+DriveType CLevelParserParam::AsDriveType()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return ToDriveType(m_value);
+}
+
+DriveType CLevelParserParam::AsDriveType(DriveType def)
+{
+ if(m_empty)
+ return def;
+ return AsDriveType();
+}
+
+
+ToolType CLevelParserParam::ToToolType(std::string value)
+{
+ if(value == "Grabber" ) return TOOL_GRABBER;
+ if(value == "Shiffer" ) return TOOL_SNIFFER;
+ if(value == "Shooter" ) return TOOL_SHOOTER;
+ if(value == "OrgaShooter") return TOOL_ORGASHOOTER;
+ if(value == "Other" ) return TOOL_OTHER;
+ return static_cast<ToolType>(Cast<int>(value, "tool"));
+}
+
+ToolType CLevelParserParam::AsToolType()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return ToToolType(m_value);
+}
+
+ToolType CLevelParserParam::AsToolType(ToolType def)
+{
+ if(m_empty)
+ return def;
+ return AsToolType();
+}
+
+
+Gfx::WaterType CLevelParserParam::ToWaterType(std::string value)
+{
+ if(value == "NULL") return Gfx::WATER_NULL;
+ if(value == "TT" ) return Gfx::WATER_TT;
+ if(value == "TO" ) return Gfx::WATER_TO;
+ if(value == "CT" ) return Gfx::WATER_CT;
+ if(value == "CO" ) return Gfx::WATER_CO;
+ return static_cast<Gfx::WaterType>(Cast<int>(value, "watertype"));
+}
+
+Gfx::WaterType CLevelParserParam::AsWaterType()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return ToWaterType(m_value);
+}
+
+Gfx::WaterType CLevelParserParam::AsWaterType(Gfx::WaterType def)
+{
+ if(m_empty)
+ return def;
+ return AsWaterType();
+}
+
+
+Gfx::EngineObjectType CLevelParserParam::ToTerrainType(std::string value)
+{
+ if(value == "Terrain") return Gfx::ENG_OBJTYPE_TERRAIN;
+ if(value == "Object" ) return Gfx::ENG_OBJTYPE_FIX;
+ if(value == "Quartz" ) return Gfx::ENG_OBJTYPE_QUARTZ;
+ if(value == "Metal" ) return Gfx::ENG_OBJTYPE_METAL;
+ return static_cast<Gfx::EngineObjectType>(Cast<int>(value, "terraintype"));
+}
+
+Gfx::EngineObjectType CLevelParserParam::AsTerrainType()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return ToTerrainType(m_value);
+}
+
+Gfx::EngineObjectType CLevelParserParam::AsTerrainType(Gfx::EngineObjectType def)
+{
+ if(m_empty)
+ return def;
+ return AsTerrainType();
+}
+
+
+int CLevelParserParam::ToBuildFlag(std::string value)
+{
+ if(value == "BotFactory" ) return BUILD_FACTORY;
+ if(value == "Derrick" ) return BUILD_DERRICK;
+ if(value == "Converter" ) return BUILD_CONVERT;
+ if(value == "RadarStation" ) return BUILD_RADAR;
+ if(value == "PowerPlant" ) return BUILD_ENERGY;
+ if(value == "NuclearPlant" ) return BUILD_NUCLEAR;
+ if(value == "FuelCellPlant" ) return BUILD_NUCLEAR;
+ if(value == "PowerStation" ) return BUILD_STATION;
+ if(value == "RepairCenter" ) return BUILD_REPAIR;
+ if(value == "DefenseTower" ) return BUILD_TOWER;
+ if(value == "ResearchCenter") return BUILD_RESEARCH;
+ if(value == "AutoLab" ) return BUILD_LABO;
+ if(value == "PowerCaptor" ) return BUILD_PARA;
+ if(value == "ExchangePost" ) return BUILD_INFO;
+ if(value == "Destroyer" ) return BUILD_DESTROYER;
+ if(value == "FlatGround" ) return BUILD_GFLAT;
+ if(value == "Flag" ) return BUILD_FLAG;
+ return Cast<int>(value, "buildflag");
+}
+
+int CLevelParserParam::AsBuildFlag()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return ToBuildFlag(m_value);
+}
+
+int CLevelParserParam::AsBuildFlag(int def)
+{
+ if(m_empty)
+ return def;
+ return AsBuildFlag();
+}
+
+
+int CLevelParserParam::ToResearchFlag(std::string value)
+{
+ if(value == "TRACKER" ) return RESEARCH_TANK;
+ if(value == "WINGER" ) return RESEARCH_FLY;
+ if(value == "THUMPER" ) return RESEARCH_THUMP;
+ if(value == "SHOOTER" ) return RESEARCH_CANON;
+ if(value == "TOWER" ) return RESEARCH_TOWER;
+ if(value == "PHAZER" ) return RESEARCH_PHAZER;
+ if(value == "SHIELDER") return RESEARCH_SHIELD;
+ if(value == "ATOMIC" ) return RESEARCH_ATOMIC;
+ if(value == "iPAW" ) return RESEARCH_iPAW;
+ if(value == "iGUN" ) return RESEARCH_iGUN;
+ if(value == "RECYCLER") return RESEARCH_RECYCLER;
+ if(value == "SUBBER" ) return RESEARCH_SUBM;
+ if(value == "SNIFFER" ) return RESEARCH_SNIFFER;
+ return Cast<int>(value, "researchflag");
+}
+
+int CLevelParserParam::AsResearchFlag()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return ToResearchFlag(m_value);
+}
+
+int CLevelParserParam::AsResearchFlag(int def)
+{
+ if(m_empty)
+ return def;
+ return AsResearchFlag();
+}
+
+
+Gfx::PyroType CLevelParserParam::ToPyroType(std::string value)
+{
+ if(value == "FRAGt" ) return Gfx::PT_FRAGT;
+ if(value == "FRAGo" ) return Gfx::PT_FRAGO;
+ if(value == "FRAGw" ) return Gfx::PT_FRAGW;
+ if(value == "EXPLOt") return Gfx::PT_EXPLOT;
+ if(value == "EXPLOo") return Gfx::PT_EXPLOO;
+ if(value == "EXPLOw") return Gfx::PT_EXPLOW;
+ if(value == "SHOTt" ) return Gfx::PT_SHOTT;
+ if(value == "SHOTh" ) return Gfx::PT_SHOTH;
+ if(value == "SHOTm" ) return Gfx::PT_SHOTM;
+ if(value == "SHOTw" ) return Gfx::PT_SHOTW;
+ if(value == "EGG" ) return Gfx::PT_EGG;
+ if(value == "BURNt" ) return Gfx::PT_BURNT;
+ if(value == "BURNo" ) return Gfx::PT_BURNO;
+ if(value == "SPIDER") return Gfx::PT_SPIDER;
+ if(value == "FALL" ) return Gfx::PT_FALL;
+ if(value == "RESET" ) return Gfx::PT_RESET;
+ if(value == "WIN" ) return Gfx::PT_WIN;
+ if(value == "LOST" ) return Gfx::PT_LOST;
+ return static_cast<Gfx::PyroType>(Cast<int>(value, "pyrotype"));
+}
+
+Gfx::PyroType CLevelParserParam::AsPyroType()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return ToPyroType(m_value);
+}
+
+Gfx::PyroType CLevelParserParam::AsPyroType(Gfx::PyroType def)
+{
+ if(m_empty)
+ return def;
+ return AsPyroType();
+}
+
+
+Gfx::CameraType CLevelParserParam::ToCameraType(std::string value)
+{
+ if(value == "BACK" ) return Gfx::CAM_TYPE_BACK;
+ if(value == "PLANE" ) return Gfx::CAM_TYPE_PLANE;
+ if(value == "ONBOARD") return Gfx::CAM_TYPE_ONBOARD;
+ if(value == "FIX" ) return Gfx::CAM_TYPE_FIX;
+ return static_cast<Gfx::CameraType>(Cast<int>(value, "camera"));
+}
+
+const std::string CLevelParserParam::FromCameraType(Gfx::CameraType value)
+{
+ if(value == Gfx::CAM_TYPE_ONBOARD) return "ONBOARD";
+ if(value == Gfx::CAM_TYPE_FIX ) return "FIX";
+ return boost::lexical_cast<std::string>(static_cast<int>(value));
+}
+
+Gfx::CameraType CLevelParserParam::AsCameraType()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+ return ToCameraType(m_value);
+}
+
+Gfx::CameraType CLevelParserParam::AsCameraType(Gfx::CameraType def)
+{
+ if(m_empty)
+ return def;
+ return AsCameraType();
+}
+
+
+void CLevelParserParam::ParseArray()
+{
+ if(m_array.size() != 0)
+ return;
+
+ std::vector<std::string> values;
+ boost::split(values, m_value, boost::is_any_of(";"));
+ int i = 0;
+ for(auto& value : values) {
+ boost::algorithm::trim(value);
+ if(value.empty()) continue;
+ CLevelParserParam* param = new CLevelParserParam(m_name+"["+boost::lexical_cast<std::string>(i)+"]", value);
+ param->SetLine(m_line);
+ m_array.push_back(param);
+ i++;
+ }
+}
+
+const std::vector<CLevelParserParam*>& CLevelParserParam::AsArray()
+{
+ if(m_empty)
+ throw CLevelParserExceptionMissingParam(this);
+
+ ParseArray();
+
+ return m_array;
+} \ No newline at end of file
diff --git a/src/object/level/parserparam.h b/src/object/level/parserparam.h
new file mode 100644
index 0000000..f59b40f
--- /dev/null
+++ b/src/object/level/parserparam.h
@@ -0,0 +1,137 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+/**
+ * \file object/level/parserparam.h
+ * \brief Value of command argument in level file
+ */
+
+#pragma once
+
+#include <object/object.h>
+#include <graphics/core/color.h>
+#include <graphics/engine/water.h>
+#include <graphics/engine/pyro.h>
+#include <math/point.h>
+
+#include <string>
+
+class CLevelParserLine;
+
+class CLevelParserParam
+{
+public:
+ //! Create param with given value
+ //@{
+ CLevelParserParam(int value);
+ CLevelParserParam(float value);
+ CLevelParserParam(std::string value);
+ CLevelParserParam(bool value);
+ CLevelParserParam(Gfx::Color value);
+ CLevelParserParam(Math::Point value);
+ CLevelParserParam(ObjectType value);
+ CLevelParserParam(Gfx::CameraType value);
+ CLevelParserParam(const std::vector<CLevelParserParam*>& value);
+ //@}
+ //! Create param from string
+ CLevelParserParam(std::string name, std::string value);
+ //! Create empty parser param
+ CLevelParserParam(std::string name, bool empty);
+
+ ~CLevelParserParam();
+
+ //! Get value (throws exception if not found or unable to process)
+ //@{
+ int AsInt();
+ float AsFloat();
+ std::string AsString();
+ bool AsBool();
+ std::string AsPath(const std::string defaultDir);
+ Gfx::Color AsColor();
+ Math::Vector AsPoint();
+ ObjectType AsObjectType();
+ DriveType AsDriveType();
+ ToolType AsToolType();
+ Gfx::WaterType AsWaterType();
+ Gfx::EngineObjectType AsTerrainType();
+ int AsBuildFlag();
+ int AsResearchFlag();
+ Gfx::PyroType AsPyroType();
+ Gfx::CameraType AsCameraType();
+ const std::vector<CLevelParserParam*>& AsArray();
+ //@}
+
+ //! Get value (returns default if not found, throws exception if unable to process)
+ //@{
+ int AsInt(int def);
+ float AsFloat(float def);
+ std::string AsString(std::string def);
+ bool AsBool(bool def);
+ std::string AsPath(const std::string defaultDir, std::string def);
+ Gfx::Color AsColor(Gfx::Color def);
+ Math::Vector AsPoint(Math::Vector def);
+ ObjectType AsObjectType(ObjectType def);
+ DriveType AsDriveType(DriveType def);
+ ToolType AsToolType(ToolType def);
+ Gfx::WaterType AsWaterType(Gfx::WaterType def);
+ Gfx::EngineObjectType AsTerrainType(Gfx::EngineObjectType def);
+ int AsBuildFlag(int def);
+ int AsResearchFlag(int def);
+ Gfx::PyroType AsPyroType(Gfx::PyroType def);
+ Gfx::CameraType AsCameraType(Gfx::CameraType def);
+ //@}
+
+ //! Set line this param is part of
+ void SetLine(CLevelParserLine* line);
+ //! Get line this param is part of
+ CLevelParserLine* GetLine();
+
+ std::string GetName();
+ std::string GetValue();
+ bool IsDefined();
+
+ static std::string InjectLevelDir(std::string path, const std::string defaultDir);
+
+private:
+ void ParseArray();
+
+ template<typename T> T Cast(std::string value, std::string requestedType);
+ template<typename T> T Cast(std::string requestedType);
+
+ std::string ToPath(std::string path, const std::string defaultDir);
+ ObjectType ToObjectType(std::string value);
+ DriveType ToDriveType(std::string value);
+ ToolType ToToolType(std::string value);
+ Gfx::WaterType ToWaterType(std::string value);
+ Gfx::EngineObjectType ToTerrainType(std::string value);
+ int ToBuildFlag(std::string value);
+ int ToResearchFlag(std::string value);
+ Gfx::PyroType ToPyroType(std::string value);
+ Gfx::CameraType ToCameraType(std::string value);
+
+ const std::string FromObjectType(ObjectType value);
+ const std::string FromCameraType(Gfx::CameraType value);
+
+private:
+ CLevelParserLine* m_line;
+ bool m_empty;
+ std::string m_name;
+ std::string m_value;
+ std::vector<CLevelParserParam*> m_array;
+}; \ No newline at end of file
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 2ca2409..91e2d61 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -23,7 +23,6 @@
#include "CBot/CBotDll.h"
#include "app/app.h"
-#include "app/gamedata.h"
#include "common/event.h"
#include "common/global.h"
@@ -33,6 +32,8 @@
#include "common/profile.h"
#include "common/restext.h"
+#include "common/resources/inputstream.h"
+
#include "graphics/engine/camera.h"
#include "graphics/engine/cloud.h"
#include "graphics/engine/engine.h"
@@ -60,6 +61,7 @@
#include "object/task/task.h"
#include "object/task/taskbuild.h"
#include "object/task/taskmanip.h"
+#include "object/level/parser.h"
#include "physics/physics.h"
@@ -85,7 +87,7 @@
#include <iomanip>
-#include <boost/regex.hpp>
+#include <boost/lexical_cast.hpp>
template<> CRobotMain* CSingleton<CRobotMain>::m_instance = nullptr;
@@ -659,12 +661,6 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
m_selectObject = 0;
m_infoUsed = 0;
- m_beginObject = false;
- m_terrainGenerate = false;
- m_terrainInit = false;
- m_terrainInitTextures = false;
- m_terrainCreate = false;
-
m_version = 1;
m_controller = nullptr;
m_retroStyle = false;
@@ -1210,18 +1206,27 @@ void CRobotMain::ChangePhase(Phase phase)
bool loading = (m_dialog->GetSceneRead()[0] != 0);
m_map->CreateMap();
- CreateScene(m_dialog->GetSceneSoluce(), false, false); // interactive scene
- if (m_mapImage)
- m_map->SetFixImage(m_mapFilename);
+
+ try {
+ CreateScene(m_dialog->GetSceneSoluce(), false, false); // interactive scene
+ if (m_mapImage)
+ m_map->SetFixImage(m_mapFilename);
- m_app->ResetTimeAfterLoading();
+ m_app->ResetTimeAfterLoading();
- if (m_immediatSatCom && !loading &&
- m_infoFilename[SATCOM_HUSTON][0] != 0)
- StartDisplayInfo(SATCOM_HUSTON, false); // shows the instructions
+ if (m_immediatSatCom && !loading &&
+ m_infoFilename[SATCOM_HUSTON][0] != 0)
+ StartDisplayInfo(SATCOM_HUSTON, false); // shows the instructions
- m_sound->StopMusic(0.0f);
- if (!m_base || loading) StartMusic();
+ m_sound->StopMusic(0.0f);
+ if (!m_base || loading) StartMusic();
+ }
+ catch(const CLevelParserException& e)
+ {
+ CLogger::GetInstancePointer()->Error("An error occured while trying to load a level\n");
+ CLogger::GetInstancePointer()->Error("%s\n", e.what());
+ ChangePhase(PHASE_INIT);
+ }
}
if (m_phase == PHASE_WIN)
@@ -1237,29 +1242,37 @@ void CRobotMain::ChangePhase(Phase phase)
m_dialog->SetSceneName("win");
m_dialog->SetSceneRank(m_endingWinRank);
- CreateScene(false, true, false); // sets scene
+ try {
+ CreateScene(false, true, false); // sets scene
- pos.x = ox+sx*1; pos.y = oy+sy*1;
- Math::Point ddim;
- ddim.x = dim.x*2; ddim.y = dim.y*2;
- m_interface->CreateButton(pos, ddim, 16, EVENT_BUTTON_OK);
+ pos.x = ox+sx*1; pos.y = oy+sy*1;
+ Math::Point ddim;
+ ddim.x = dim.x*2; ddim.y = dim.y*2;
+ m_interface->CreateButton(pos, ddim, 16, EVENT_BUTTON_OK);
- if (m_winTerminate)
- {
- pos.x = ox+sx*3; pos.y = oy+sy*0.2f;
- ddim.x = dim.x*15; ddim.y = dim.y*3.0f;
- pe = m_interface->CreateEdit(pos, ddim, 0, EVENT_EDIT0);
- pe->SetGenericMode(true);
- pe->SetFontType(Gfx::FONT_COLOBOT);
- pe->SetEditCap(false);
- pe->SetHighlightCap(false);
- pe->ReadText(std::string("help/") + m_app->GetLanguageChar() + std::string("/win.txt"));
+ if (m_winTerminate)
+ {
+ pos.x = ox+sx*3; pos.y = oy+sy*0.2f;
+ ddim.x = dim.x*15; ddim.y = dim.y*3.0f;
+ pe = m_interface->CreateEdit(pos, ddim, 0, EVENT_EDIT0);
+ pe->SetGenericMode(true);
+ pe->SetFontType(Gfx::FONT_COLOBOT);
+ pe->SetEditCap(false);
+ pe->SetHighlightCap(false);
+ pe->ReadText(std::string("help/") + m_app->GetLanguageChar() + std::string("/win.txt"));
+ }
+ else
+ {
+ m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f);
+ }
+ StartMusic();
}
- else
+ catch(const CLevelParserException& e)
{
- m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f);
+ CLogger::GetInstancePointer()->Error("An error occured while trying to load win scene\n");
+ CLogger::GetInstancePointer()->Error("%s\n", e.what());
+ ChangePhase(PHASE_TERM);
}
- StartMusic();
}
}
@@ -1275,15 +1288,23 @@ void CRobotMain::ChangePhase(Phase phase)
m_winTerminate = false;
m_dialog->SetSceneName("lost");
m_dialog->SetSceneRank(m_endingLostRank);
- CreateScene(false, true, false); // sets scene
+ try {
+ CreateScene(false, true, false); // sets scene
- pos.x = ox+sx*1; pos.y = oy+sy*1;
- Math::Point ddim;
- ddim.x = dim.x*2; ddim.y = dim.y*2;
- m_interface->CreateButton(pos, ddim, 16, EVENT_BUTTON_OK);
- m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f);
+ pos.x = ox+sx*1; pos.y = oy+sy*1;
+ Math::Point ddim;
+ ddim.x = dim.x*2; ddim.y = dim.y*2;
+ m_interface->CreateButton(pos, ddim, 16, EVENT_BUTTON_OK);
+ m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f);
- StartMusic();
+ StartMusic();
+ }
+ catch(const CLevelParserException& e)
+ {
+ CLogger::GetInstancePointer()->Error("An error occured while trying to load lost scene\n");
+ CLogger::GetInstancePointer()->Error("%s\n", e.what());
+ ChangePhase(PHASE_TERM);
+ }
}
}
@@ -3628,7 +3649,14 @@ void CRobotMain::ScenePerso()
m_dialog->SetSceneName("perso");
m_dialog->SetSceneRank(0);
- CreateScene(false, true, false); // sets scene
+ try {
+ CreateScene(false, true, false); // sets scene
+ }
+ catch(const CLevelParserException& e)
+ {
+ CLogger::GetInstancePointer()->Error("An error occured while trying to load apperance scene\n");
+ CLogger::GetInstancePointer()->Error("%s\n", e.what());
+ }
m_engine->SetDrawWorld(false); // does not draw anything on the interface
m_engine->SetDrawFront(true); // draws on the human interface
@@ -3650,12 +3678,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
int rank = m_dialog->GetSceneRank();
const char* read = m_dialog->GetSceneRead().c_str();
const char* stack = m_dialog->GetStackRead().c_str();
- m_dialog->SetUserDir(base, rank);
-
- /*
- * TODO: original code relying on UserDir() was removed.
- * A new way of providing custom data file paths will need to be devised.
- */
m_fixScene = fixScene;
@@ -3727,35 +3749,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
strcpy(m_scriptName, scriptNameStr.c_str());
m_scriptFile[0] = 0;
- m_beginObject = false;
- m_terrainGenerate = false;
- m_terrainInit = false;
- m_terrainInitTextures = false;
- m_terrainCreate = false;
-
m_version = 1;
m_retroStyle = false;
m_missionResult = ERR_MISSION_NOTERM;
}
-
- char line[500];
- char name[200];
- char dir[100];
- char op[100];
- char filename[500];
- int lineNum = 0;
-
- memset(line, 0, 500);
- memset(name, 0, 200);
- memset(dir, 0, 100);
- memset(op, 0, 100);
- memset(filename, 0, 500);
- std::string tempLine;
- m_dialog->BuildSceneName(tempLine, base, rank);
- strcpy(filename, tempLine.c_str());
- FILE* file = fopen(filename, "r");
- if (file == NULL) return;
+
+ CLevelParser* level = new CLevelParser(base, rank/100, rank%100);
+ level->Load();
int rankObj = 0;
int rankGadget = 0;
@@ -3768,579 +3769,445 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
* may speed up loading
*/
- while (fgets(line, 500, file) != NULL)
+ for(auto& line : level->GetLines())
{
- lineNum++;
- for (int i = 0; i < 500; i++)
+ if (line->GetCommand() == "MissionFile" && !resetObject)
{
- if (line[i] == '\t' ) line[i] = ' '; // replace tab by space
- if (line[i] == '/' && line[i+1] == '/')
- {
- line[i] = 0;
- break;
- }
- }
-
- if (Cmd(line, "MissionFile") && !resetObject) {
- m_version = OpInt(line, "version", 1);
- continue;
+ m_version = line->GetParam("version")->AsInt(1);
+ continue;
}
-
- // TODO: Fallback to an non-localized entry
- sprintf(op, "Title.%c", m_app->GetLanguageChar());
- if (Cmd(line, op) && !resetObject)
+
+ if(line->GetCommand() == "Title" && !resetObject)
{
- OpString(line, "text", m_title);
+ strcpy(m_title, line->GetParam("text")->AsString().c_str());
continue;
}
-
- sprintf(op, "Resume.%c", m_app->GetLanguageChar());
- if (Cmd(line, op) && !resetObject)
+
+ if(line->GetCommand() == "Resume" && !resetObject)
{
- OpString(line, "text", m_resume);
+ strcpy(m_resume, line->GetParam("text")->AsString().c_str());
continue;
}
-
- sprintf(op, "ScriptName.%c", m_app->GetLanguageChar());
- if (Cmd(line, op) && !resetObject)
+
+ if(line->GetCommand() == "ScriptName" && !resetObject)
{
- OpString(line, "text", m_scriptName);
+ strcpy(m_scriptName, line->GetParam("text")->AsString().c_str());
continue;
}
-
- static const boost::regex titleCmdRe("Title\\.[A-Z]");
- static const boost::regex resumeCmdRe("Resume\\.[A-Z]");
- static const boost::regex scriptNameCmdRe("ScriptName\\.[A-Z]");
-
- if (boost::regex_match(GetCmd(line), titleCmdRe)) continue; // Ignore
- if (boost::regex_match(GetCmd(line), resumeCmdRe)) continue; // Ignore
- if (boost::regex_match(GetCmd(line), scriptNameCmdRe)) continue; // Ignore
-
-
- if (Cmd(line, "ScriptFile") && !resetObject)
+
+ if (line->GetCommand() == "ScriptFile" && !resetObject)
{
- OpString(line, "name", m_scriptFile);
+ strcpy(m_scriptFile, line->GetParam("name")->AsString().c_str());
continue;
}
-
- if (Cmd(line, "Instructions") && !resetObject)
+
+ if (line->GetCommand() == "Instructions" && !resetObject)
{
- OpString(line, "name", name);
- std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name);
- strcpy(m_infoFilename[SATCOM_HUSTON], path.c_str());
-
- m_immediatSatCom = OpInt(line, "immediat", 0);
- if (m_version >= 2) m_beginSatCom = m_lockedSatCom = OpInt(line, "lock", 0);
+ strcpy(m_infoFilename[SATCOM_HUSTON], line->GetParam("name")->AsPath("help/%lng%").c_str());
+
+ m_immediatSatCom = line->GetParam("immediat")->AsBool(false);
+ if (m_version >= 2) m_beginSatCom = m_lockedSatCom = line->GetParam("lock")->AsBool(false);
if (m_app->GetSceneTestMode()) m_immediatSatCom = false;
continue;
}
-
- if (Cmd(line, "Satellite") && !resetObject)
+
+ if (line->GetCommand() == "Satellite" && !resetObject)
{
- OpString(line, "name", name);
- std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name);
- strcpy(m_infoFilename[SATCOM_SAT], path.c_str());
+ strcpy(m_infoFilename[SATCOM_SAT], line->GetParam("name")->AsPath("help/%lng%").c_str());
continue;
}
-
- if (Cmd(line, "Loading") && !resetObject)
+
+ if (line->GetCommand() == "Loading" && !resetObject)
{
- OpString(line, "name", name);
- std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name);
- strcpy(m_infoFilename[SATCOM_LOADING], path.c_str());
+ strcpy(m_infoFilename[SATCOM_LOADING], line->GetParam("name")->AsPath("help/%lng%").c_str());
continue;
}
-
- if (Cmd(line, "HelpFile") && !resetObject)
+
+ if (line->GetCommand() == "HelpFile" && !resetObject)
{
- OpString(line, "name", name);
- std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name);
- strcpy(m_infoFilename[SATCOM_PROG], path.c_str());
+ strcpy(m_infoFilename[SATCOM_PROG], line->GetParam("name")->AsPath("help/%lng%").c_str());
continue;
}
- if (Cmd(line, "SoluceFile") && !resetObject)
+ if (line->GetCommand() == "SoluceFile" && !resetObject)
{
- OpString(line, "name", name);
- std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name);
- strcpy(m_infoFilename[SATCOM_SOLUCE], path.c_str());
+ strcpy(m_infoFilename[SATCOM_SOLUCE], line->GetParam("name")->AsPath("help/%lng%").c_str());
continue;
}
-
- if (Cmd(line, "EndingFile") && !resetObject)
+
+ if (line->GetCommand() == "EndingFile" && !resetObject)
{
- m_endingWinRank = OpInt(line, "win", 0);
- m_endingLostRank = OpInt(line, "lost", 0);
+ // NOTE: The old default was 0, but I think -1 is more correct - 0 means "ending file 000", while -1 means "no ending file"
+ m_endingWinRank = line->GetParam("win")->AsInt(-1);
+ m_endingLostRank = line->GetParam("lost")->AsInt(-1);
continue;
}
-
- if (Cmd(line, "MessageDelay") && !resetObject)
+
+ if (line->GetCommand() == "MessageDelay" && !resetObject)
{
- m_displayText->SetDelay(OpFloat(line, "factor", 1.0f));
+ m_displayText->SetDelay(line->GetParam("factor")->AsFloat());
continue;
}
-
- if (Cmd(line, "CacheAudio") && !resetObject && m_version >= 2)
+
+ if (line->GetCommand() == "CacheAudio" && !resetObject && m_version >= 2)
{
- OpString(line, "filename", name);
- m_sound->CacheMusic(name);
+ m_sound->CacheMusic(line->GetParam("filename")->AsPath("").c_str()); //TODO: don't make this relative to music/
continue;
}
-
- if (Cmd(line, "AudioChange") && !resetObject && m_version >= 2 && m_controller == nullptr)
+
+ if (line->GetCommand() == "AudioChange" && !resetObject && m_version >= 2 && m_controller == nullptr)
{
int i = m_audioChangeTotal;
if (i < 10)
{
- m_audioChange[i].pos = OpPos(line, "pos")*g_unit;
- m_audioChange[i].dist = OpFloat(line, "dist", 1000.0f)*g_unit;
- m_audioChange[i].type = OpTypeObject(line, "type", OBJECT_NULL);
- m_audioChange[i].min = OpInt(line, "min", 1);
- m_audioChange[i].max = OpInt(line, "max", 9999);
- m_audioChange[i].powermin = OpFloat(line, "powermin", -1);
- m_audioChange[i].powermax = OpFloat(line, "powermax", 100);
- m_audioChange[i].tool = OpTool(line, "tool");
- m_audioChange[i].drive = OpDrive(line, "drive");
- OpString(line, "filename", m_audioChange[i].music);
- m_audioChange[i].repeat = OpInt(line, "repeat", 1);
+ m_audioChange[i].pos = line->GetParam("pos")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit;
+ m_audioChange[i].dist = line->GetParam("dist")->AsFloat(1000.0f)*g_unit;
+ m_audioChange[i].type = line->GetParam("type")->AsObjectType(OBJECT_NULL);
+ m_audioChange[i].min = line->GetParam("min")->AsInt(1);
+ m_audioChange[i].max = line->GetParam("max")->AsInt(9999);
+ m_audioChange[i].powermin = line->GetParam("powermin")->AsFloat(-1);
+ m_audioChange[i].powermax = line->GetParam("powermax")->AsFloat(100);
+ m_audioChange[i].tool = line->GetParam("tool")->AsToolType(TOOL_OTHER);
+ m_audioChange[i].drive = line->GetParam("drive")->AsDriveType(DRIVE_OTHER);
+ strcpy(m_audioChange[i].music, line->GetParam("filename")->AsPath("").c_str()); //TODO: don't make this relative to music/
+ m_audioChange[i].repeat = line->GetParam("repeat")->AsBool(true);
m_audioChange[i].changed = false;
m_sound->CacheMusic(m_audioChange[i].music);
m_audioChangeTotal ++;
}
continue;
}
-
- if (Cmd(line, "Audio") && !resetObject && m_controller == nullptr)
+
+ if (line->GetCommand() == "Audio" && !resetObject && m_controller == nullptr)
{
if (m_version < 2)
{
- int trackid = OpInt(line, "track", 0);
+ int trackid = line->GetParam("track")->AsInt();
if (trackid != 0)
{
std::stringstream filenameStr;
filenameStr << "music" << std::setfill('0') << std::setw(3) << trackid << ".ogg";
m_audioTrack = filenameStr.str();
}
- m_audioRepeat = OpInt(line, "repeat", 1);
+ m_audioRepeat = line->GetParam("repeat")->AsBool(true);
}
else
{
- char trackname[100];
-
- OpString(line, "main", trackname);
- m_audioTrack = trackname;
- m_audioRepeat = OpInt(line, "mainRepeat", 1);
+ m_audioTrack = line->GetParam("main")->AsPath("", ""); //TODO: don't make this relative to music/
+ m_audioRepeat = line->GetParam("mainRepeat")->AsBool(true);
- OpString(line, "satcom", trackname);
- m_satcomTrack = trackname;
- m_satcomRepeat = OpInt(line, "satcomRepeat", 1);
+ m_satcomTrack = line->GetParam("satcom")->AsPath("", ""); //TODO: don't make this relative to music/
+ m_satcomRepeat = line->GetParam("satcomRepeat")->AsBool(true);
- OpString(line, "editor", trackname);
- m_editorTrack = trackname;
- m_editorRepeat = OpInt(line, "editorRepeat", 1);
+ m_editorTrack = line->GetParam("editor")->AsPath("", ""); //TODO: don't make this relative to music/
+ m_editorRepeat = line->GetParam("editorRepeat")->AsBool(true);
}
if (m_audioTrack != "") m_sound->CacheMusic(m_audioTrack);
if (m_satcomTrack != "") m_sound->CacheMusic(m_satcomTrack);
if (m_editorTrack != "") m_sound->CacheMusic(m_editorTrack);
continue;
}
-
- if (Cmd(line, "AmbientColor") && !resetObject)
+
+ if (line->GetCommand() == "AmbientColor" && !resetObject)
{
- m_engine->SetAmbientColor(OpColor(line, "air", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0);
- m_engine->SetAmbientColor(OpColor(line, "water", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 1);
+ m_engine->SetAmbientColor(line->GetParam("air")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0);
+ m_engine->SetAmbientColor(line->GetParam("water")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 1);
continue;
}
-
- if (Cmd(line, "FogColor") && !resetObject)
+
+ if (line->GetCommand() == "FogColor" && !resetObject)
{
- m_engine->SetFogColor(OpColor(line, "air", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0);
- m_engine->SetFogColor(OpColor(line, "water", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 1);
+ m_engine->SetFogColor(line->GetParam("air")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 0);
+ m_engine->SetFogColor(line->GetParam("water")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)), 1);
continue;
}
-
- if (Cmd(line, "VehicleColor") && !resetObject)
+
+ if (line->GetCommand() == "VehicleColor" && !resetObject)
{
- m_colorNewBot = OpColor(line, "color", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f));
+ m_colorNewBot = line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f));
continue;
}
-
- if (Cmd(line, "InsectColor") && !resetObject)
+
+ if (line->GetCommand() == "InsectColor" && !resetObject)
{
- m_colorNewAlien = OpColor(line, "color", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f));
+ m_colorNewAlien = line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f));
continue;
}
-
- if (Cmd(line, "GreeneryColor") && !resetObject)
+
+ if (line->GetCommand() == "GreeneryColor" && !resetObject)
{
- m_colorNewGreen = OpColor(line, "color", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f));
+ m_colorNewGreen = line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f));
continue;
}
-
- if (Cmd(line, "DeepView") && !resetObject)
+
+ if (line->GetCommand() == "DeepView" && !resetObject)
{
- m_engine->SetDeepView(OpFloat(line, "air", 500.0f)*g_unit, 0, true);
- m_engine->SetDeepView(OpFloat(line, "water", 100.0f)*g_unit, 1, true);
+ m_engine->SetDeepView(line->GetParam("air")->AsFloat(500.0f)*g_unit, 0, true);
+ m_engine->SetDeepView(line->GetParam("water")->AsFloat(100.0f)*g_unit, 1, true);
continue;
}
-
- if (Cmd(line, "FogStart") && !resetObject)
+
+ if (line->GetCommand() == "FogStart" && !resetObject)
{
- m_engine->SetFogStart(OpFloat(line, "air", 0.5f), 0);
- m_engine->SetFogStart(OpFloat(line, "water", 0.5f), 1);
+ m_engine->SetFogStart(line->GetParam("air")->AsFloat(0.5f), 0);
+ m_engine->SetFogStart(line->GetParam("water")->AsFloat(0.5f), 1);
continue;
}
-
- if (Cmd(line, "SecondTexture") && !resetObject)
+
+ if (line->GetCommand() == "SecondTexture" && !resetObject)
{
- m_engine->SetSecondTexture(OpInt(line, "rank", 1));
+ m_engine->SetSecondTexture(line->GetParam("rank")->AsInt());
continue;
}
-
- if (Cmd(line, "Background") && !resetObject)
- {
- OpString(line, "image", name);
- m_engine->SetBackground(name,
- OpColor(line, "up", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
- OpColor(line, "down", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
- OpColor(line, "cloudUp", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
- OpColor(line, "cloudDown", Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
- OpInt(line, "full", 0));
+
+ if (line->GetCommand() == "Background" && !resetObject)
+ {
+ m_engine->SetBackground(line->GetParam("image")->AsPath("", "").c_str(), //TODO: don't make this relative to textures/
+ line->GetParam("up")->AsColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
+ line->GetParam("down")->AsColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
+ line->GetParam("cloudUp")->AsColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
+ line->GetParam("cloudDown")->AsColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)),
+ line->GetParam("full")->AsBool(false));
continue;
}
-
- if (Cmd(line, "Planet") && !resetObject)
+
+ if (line->GetCommand() == "Planet" && !resetObject)
{
Math::Vector ppos, uv1, uv2;
-
- ppos = OpPos(line, "pos");
- uv1 = OpPos(line, "uv1");
- uv2 = OpPos(line, "uv2");
- OpString(line, "image", name);
- m_planet->Create(OpInt(line, "mode", 0),
+
+ ppos = line->GetParam("pos")->AsPoint();
+ uv1 = line->GetParam("uv1")->AsPoint();
+ uv2 = line->GetParam("uv2")->AsPoint();
+ m_planet->Create(line->GetParam("mode")->AsInt(0),
Math::Point(ppos.x, ppos.z),
- OpFloat(line, "dim", 0.2f),
- OpFloat(line, "speed", 0.0f),
- OpFloat(line, "dir", 0.0f),
- name,
+ line->GetParam("dim")->AsFloat(0.2f),
+ line->GetParam("speed")->AsFloat(0.0f),
+ line->GetParam("dir")->AsFloat(0.0f),
+ line->GetParam("image")->AsPath(""), //TODO: don't make this relative to textures/
Math::Point(uv1.x, uv1.z),
Math::Point(uv2.x, uv2.z),
- strstr(name, "planet") != nullptr // TODO: add transparent op or modify textures
- );
+ line->GetParam("image")->AsPath("").find("planet") != std::string::npos // TODO: add transparent op or modify textures
+ );
continue;
}
-
- if (Cmd(line, "ForegroundName") && !resetObject)
+
+ if (line->GetCommand() == "ForegroundName" && !resetObject)
{
- OpString(line, "image", name);
- m_engine->SetForegroundName(name);
+ m_engine->SetForegroundName(line->GetParam("image")->AsPath("")); //TODO: don't make this relative to textures/
continue;
}
-
- if (((m_version == 1 && Cmd(line, "Global")) || (m_version >= 2 && Cmd(line, "Mission"))) && !resetObject)
+
+ if (((line->GetCommand() == "Global") || (m_version >= 2 && line->GetCommand() == "Mission")) && !resetObject)
{
- g_unit = OpFloat(line, "unitScale", 4.0f);
- m_engine->SetTracePrecision(OpFloat(line, "traceQuality", 1.0f));
- m_shortCut = OpInt(line, "shortcut", 1);
+ g_unit = line->GetParam("unitScale")->AsFloat(4.0f);
+ m_engine->SetTracePrecision(line->GetParam("traceQuality")->AsFloat(1.0f));
+ m_shortCut = line->GetParam("shortcut")->AsBool(true);
if (m_version >= 2)
{
- m_retroStyle = OpInt(line, "retro", 0);
+ m_retroStyle = line->GetParam("retro")->AsBool(false);
if (m_retroStyle) GetLogger()->Info("Retro mode enabled.\n");
}
continue;
}
-
- if (Cmd(line, "TerrainGenerate") && !resetObject)
- {
- if (m_terrainCreate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainGenerate after TerrainCreate\n", filename, lineNum);
- continue;
- }
-
- if (m_terrainInit)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainGenerate after TerrainInit\n", filename, lineNum);
- continue;
- }
-
- m_terrain->Generate(OpInt(line, "mosaic", 20),
- OpInt(line, "brick", 3),
- OpFloat(line, "size", 20.0f),
- OpFloat(line, "vision", 500.0f)*g_unit,
- OpInt(line, "depth", 2),
- OpFloat(line, "hard", 0.5f));
-
- m_terrainGenerate = true;
+
+ if (line->GetCommand() == "TerrainGenerate" && !resetObject)
+ {
+ m_terrain->Generate(line->GetParam("mosaic")->AsInt(20),
+ line->GetParam("brick")->AsInt(3),
+ line->GetParam("size")->AsFloat(20.0f),
+ line->GetParam("vision")->AsFloat(500.0f)*g_unit,
+ line->GetParam("depth")->AsInt(2),
+ line->GetParam("hard")->AsFloat(0.5f));
continue;
}
-
- if (Cmd(line, "TerrainWind") && !resetObject)
+
+ if (line->GetCommand() == "TerrainWind" && !resetObject)
{
- if (m_terrainCreate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainWind after TerrainCreate\n", filename, lineNum);
- continue;
- }
-
- if (m_terrainInit)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainWind after TerrainInit\n", filename, lineNum);
- continue;
- }
-
- if (!m_terrainGenerate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainWind before TerrainGenerate\n", filename, lineNum);
- continue;
- }
-
- m_terrain->SetWind(OpPos(line, "speed"));
+ m_terrain->SetWind(line->GetParam("speed")->AsPoint());
continue;
}
-
- if (Cmd(line, "TerrainRelief") && !resetObject)
+
+ if (line->GetCommand() == "TerrainRelief" && !resetObject)
{
- if (m_terrainCreate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainRelief after TerrainCreate\n", filename, lineNum);
- continue;
- }
-
- if (m_terrainInit)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainRelief after TerrainInit\n", filename, lineNum);
- continue;
- }
-
- if (!m_terrainGenerate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainRelief before TerrainGenerate\n", filename, lineNum);
- continue;
- }
-
- OpString(line, "image", name);
- m_terrain->LoadRelief(name, OpFloat(line, "factor", 1.0f), OpInt(line, "border", 1));
+ m_terrain->LoadRelief(
+ line->GetParam("image")->AsPath("textures"),
+ line->GetParam("factor")->AsFloat(1.0f),
+ line->GetParam("border")->AsBool(true));
continue;
}
- if (Cmd(line, "TerrainRandomRelief") && !resetObject)
+ if (line->GetCommand() == "TerrainRandomRelief" && !resetObject)
{
m_terrain->RandomizeRelief();
continue;
}
-
- if (Cmd(line, "TerrainResource") && !resetObject)
+
+ if (line->GetCommand() == "TerrainResource" && !resetObject)
{
- if (m_terrainCreate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainResource after TerrainCreate\n", filename, lineNum);
- continue;
- }
-
- if (m_terrainInit)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainResource after TerrainInit\n", filename, lineNum);
- continue;
- }
-
- if (!m_terrainGenerate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainResource before TerrainGenerate\n", filename, lineNum);
- continue;
- }
-
- OpString(line, "image", name);
- m_terrain->LoadResources(name);
+ m_terrain->LoadResources(line->GetParam("image")->AsPath("textures"));
continue;
}
-
- if (Cmd(line, "TerrainWater") && !resetObject)
+
+ if (line->GetCommand() == "TerrainWater" && !resetObject)
{
- OpString(line, "image", name);
Math::Vector pos;
- pos.x = OpFloat(line, "moveX", 0.0f);
- pos.y = OpFloat(line, "moveY", 0.0f);
+ pos.x = line->GetParam("moxeX")->AsFloat(0.0f);
+ pos.y = line->GetParam("moxeY")->AsFloat(0.0f);
pos.z = pos.x;
- m_water->Create(OpTypeWater(line, "air", Gfx::WATER_TT),
- OpTypeWater(line, "water", Gfx::WATER_TT),
- name,
- OpColor(line, "diffuse", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
- OpColor(line, "ambient", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
- OpFloat(line, "level", 100.0f)*g_unit,
- OpFloat(line, "glint", 1.0f),
+ m_water->Create(line->GetParam("air")->AsWaterType(Gfx::WATER_TT),
+ line->GetParam("water")->AsWaterType(Gfx::WATER_TT),
+ line->GetParam("image")->AsPath(""), //TODO: don't make this relative to textures/
+ line->GetParam("diffuse")->AsColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
+ line->GetParam("ambient")->AsColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
+ line->GetParam("level")->AsFloat(100.0f)*g_unit,
+ line->GetParam("glint")->AsFloat(1.0f),
pos);
- m_colorNewWater = OpColor(line, "color", m_colorRefWater);
- m_colorShiftWater = OpFloat(line, "brightness", 0.0f);
+ m_colorNewWater = line->GetParam("color")->AsColor(m_colorRefWater);
+ m_colorShiftWater = line->GetParam("brightness")->AsFloat(0.0f);
continue;
}
-
- if (Cmd(line, "TerrainLava") && !resetObject)
+
+ if (line->GetCommand() == "TerrainLava" && !resetObject)
{
- m_water->SetLava(OpInt(line, "mode", 0));
+ m_water->SetLava(line->GetParam("mode")->AsBool());
continue;
}
-
- if (Cmd(line, "TerrainCloud") && !resetObject)
+
+ if (line->GetCommand() == "TerrainCloud" && !resetObject)
{
- OpString(line, "image", name);
- m_cloud->Create(name,
- OpColor(line, "diffuse", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
- OpColor(line, "ambient", Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
- OpFloat(line, "level", 500.0f) * g_unit);
+ m_cloud->Create(line->GetParam("image")->AsPath("", ""), //TODO: don't make this relative to textures/
+ line->GetParam("diffuse")->AsColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
+ line->GetParam("ambient")->AsColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)),
+ line->GetParam("level")->AsFloat(500.0f)*g_unit);
continue;
}
-
- if (Cmd(line, "TerrainBlitz") && !resetObject)
+
+ if (line->GetCommand() == "TerrainBlitz" && !resetObject)
{
- m_lightning->Create(OpFloat(line, "sleep", 0.0f),
- OpFloat(line, "delay", 3.0f),
- OpFloat(line, "magnetic", 50.0f) * g_unit);
+ m_lightning->Create(line->GetParam("sleep")->AsFloat(0.0f),
+ line->GetParam("delay")->AsFloat(3.0f),
+ line->GetParam("magnetic")->AsFloat(50.0f)*g_unit);
continue;
}
-
- if (Cmd(line, "TerrainInitTextures") && !resetObject)
+
+ if (line->GetCommand() == "TerrainInitTextures" && !resetObject)
{
- if (m_terrainInit)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainInitTextures and TerrainInit at same time\n", filename, lineNum);
- continue;
+ std::string name = line->GetParam("image")->AsPath(""); //TODO: don't make this relative to textures/
+ if(name.find(".") == std::string::npos)
+ name += ".png";
+ unsigned int dx = line->GetParam("dx")->AsInt(1);
+ unsigned int dy = line->GetParam("dy")->AsInt(1);
+
+ int tt[100]; //TODO: I have no idea how TerrainInitTextures works, but maybe we shuld remove the limit to 100?
+ if(dx*dy > 100)
+ throw CLevelParserException("In TerrainInitTextures: dx*dy must be <100");
+ if(line->GetParam("table")->IsDefined()) {
+ const std::vector<CLevelParserParam*>& table = line->GetParam("table")->AsArray();
+
+ if(table.size() > dx*dy)
+ throw CLevelParserException("In TerrainInitTextures: table size must be dx*dy");
+
+ for (unsigned int i = 0; i < dx*dy; i++)
+ {
+ if(i >= table.size())
+ {
+ tt[i] = 0;
+ } else {
+ tt[i] = table[i]->AsInt();
+ }
+ }
+ } else {
+ for (unsigned int i = 0; i < dx*dy; i++)
+ {
+ tt[i] = 0;
+ }
}
-
- OpString(line, "image", name);
- AddExt(name, ".png");
- int dx = OpInt(line, "dx", 1);
- int dy = OpInt(line, "dy", 1);
- char* opTable = SearchOp(line, "table");
- int tt[100];
- for (int i = 0; i < dx*dy; i++)
- tt[i] = GetInt(opTable, i, 0);
-
+
+ /*TODO: ???
if (strstr(name, "%user%") != 0)
CopyFileListToTemp(name, tt, dx*dy);
-
- m_terrain->InitTextures(name, tt, dx, dy);
-
- m_terrainInitTextures = true;
+ */
+
+ m_terrain->InitTextures(name.c_str(), tt, dx, dy);
continue;
}
-
- if (Cmd(line, "TerrainInit") && !resetObject)
+
+ if (line->GetCommand() == "TerrainInit" && !resetObject)
{
- if (m_terrainInitTextures)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainInit and TerrainInitTextures at same time\n", filename, lineNum);
- continue;
- }
-
- m_terrain->InitMaterials(OpInt(line, "id", 1));
- m_terrainInit = true;
+ m_terrain->InitMaterials(line->GetParam("id")->AsInt(1));
continue;
}
-
- if (Cmd(line, "TerrainMaterial") && !resetObject)
+
+ if (line->GetCommand() == "TerrainMaterial" && !resetObject)
{
- if (m_terrainCreate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainMaterial after TerrainCreate\n", filename, lineNum);
- continue;
- }
-
- if (m_terrainInit)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainMaterial after TerrainInit\n", filename, lineNum);
- continue;
- }
-
- if (m_terrainInitTextures)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainMaterial and TerrainInitTextures at same time\n", filename, lineNum);
- continue;
- }
-
- OpString(line, "image", name);
- AddExt(name, ".png");
+ std::string name = line->GetParam("image")->AsPath(""); //TODO: don't make this relative to textures/
+ if(name.find(".") == std::string::npos)
+ name += ".png";
+ /*TODO: ???
if (strstr(name, "%user%") != 0)
{
GetProfile().CopyFileToTemp(std::string(name));
}
-
- m_terrain->AddMaterial(OpInt(line, "id", 0),
- name,
- Math::Point(OpFloat(line, "u", 0.0f),
- OpFloat(line, "v", 0.0f)),
- OpInt(line, "up", 1),
- OpInt(line, "right", 1),
- OpInt(line, "down", 1),
- OpInt(line, "left", 1),
- OpFloat(line, "hard", 0.5f));
+ */
+
+ m_terrain->AddMaterial(line->GetParam("id")->AsInt(0),
+ name.c_str(),
+ Math::Point(line->GetParam("u")->AsFloat(),
+ line->GetParam("v")->AsFloat()),
+ line->GetParam("up")->AsInt(),
+ line->GetParam("right")->AsInt(),
+ line->GetParam("down")->AsInt(),
+ line->GetParam("left")->AsInt(),
+ line->GetParam("hard")->AsFloat(0.5f));
continue;
}
-
- if (Cmd(line, "TerrainLevel") && !resetObject)
+
+ if (line->GetCommand() == "TerrainLevel" && !resetObject)
{
- if (m_terrainCreate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel after TerrainCreate\n", filename, lineNum);
- continue;
- }
-
- if (!m_terrainInit)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel before TerrainInit\n", filename, lineNum);
- continue;
- }
-
- if (m_terrainInitTextures)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel and TerrainInitTextures at same time\n", filename, lineNum);
- continue;
- }
-
- if (!m_terrainGenerate)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): TerrainLevel before TerrainGenerate\n", filename, lineNum);
- continue;
- }
-
- char* opId = SearchOp(line, "id");
- int id[50];
- int i = 0;
- while (i < 50)
- {
- id[i] = GetInt(opId, i, 0);
- if (id[i++] == 0) break;
+ int id[50]; //TODO: I have no idea how TerrainLevel works, but maybe we should remove the limit to 50?
+ if(line->GetParam("id")->IsDefined()) {
+ const std::vector<CLevelParserParam*>& id_array = line->GetParam("id")->AsArray();
+
+ if(id_array.size() > 50)
+ throw CLevelParserException("In TerrainLevel: id array size must be < 50");
+
+ unsigned int i = 0;
+ while (i < 50)
+ {
+ id[i] = id_array[i]->AsInt();
+ i++;
+ if(i >= id_array.size()) break;
+ }
+ id[i] = 0;
}
-
+
m_terrain->GenerateMaterials(id,
- OpFloat(line, "min", 0.0f)*g_unit,
- OpFloat(line, "max", 100.0f)*g_unit,
- OpFloat(line, "slope", 5.0f),
- OpFloat(line, "freq", 100.0f),
- OpPos(line, "center")*g_unit,
- OpFloat(line, "radius", 0.0f)*g_unit);
+ line->GetParam("min")->AsFloat(0.0f)*g_unit,
+ line->GetParam("max")->AsFloat(100.0f)*g_unit,
+ line->GetParam("slope")->AsFloat(5.0f),
+ line->GetParam("freq")->AsFloat(100.0f),
+ line->GetParam("center")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit,
+ line->GetParam("radius")->AsFloat(0.0f)*g_unit);
continue;
}
-
- if (Cmd(line, "TerrainCreate") && !resetObject)
+
+ if (line->GetCommand() == "TerrainCreate" && !resetObject)
{
m_terrain->CreateObjects();
- m_terrainCreate = true;
continue;
}
-
- if (Cmd(line, "BeginObject"))
+
+ if (line->GetCommand() == "BeginObject")
{
InitEye();
SetMovieLock(false);
-
+
if (read[0] != 0) // loading file ?
sel = IOReadScene(read, stack);
-
- m_beginObject = true;
+
continue;
}
-
- if (Cmd(line, "MissionController") && read[0] == 0 && m_version >= 2)
+
+ if (line->GetCommand() == "MissionController" && read[0] == 0 && m_version >= 2)
{
m_controller = CObjectManager::GetInstancePointer()->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER, 100.0f);
m_controller->SetMagnifyDamage(100.0f);
@@ -4348,48 +4215,42 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
CBrain* brain = m_controller->GetBrain();
if (brain != nullptr)
{
- OpString(line, "script", name);
- if (name[0] != 0)
- brain->SetScriptName(0, name);
+ std::string name = line->GetParam("script")->AsPath(""); //TODO: Don't make this relative to ai/
+ if (!name.empty())
+ brain->SetScriptName(0, const_cast<char*>(name.c_str()));
brain->SetScriptRun(0);
}
continue;
}
-
- if (Cmd(line, "CreateObject") && read[0] == 0)
+
+ if (line->GetCommand() == "CreateObject" && read[0] == 0)
{
- if (!m_beginObject)
- {
- GetLogger()->Error("Syntax error in file '%s' (line %d): CreateObject before BeginObject\n", filename, lineNum);
- continue;
- }
-
- ObjectType type = OpTypeObject(line, "type", OBJECT_NULL);
-
- int gadget = OpInt(line, "gadget", -1);
+ ObjectType type = line->GetParam("type")->AsObjectType();
+
+ int gadget = line->GetParam("gadget")->AsInt(-1);
if ( gadget == -1 )
{
gadget = 0;
if ( type == OBJECT_TECH ||
- (type >= OBJECT_PLANT0 &&
- type <= OBJECT_PLANT19 ) ||
- (type >= OBJECT_TREE0 &&
- type <= OBJECT_TREE5 ) ||
- (type >= OBJECT_TEEN0 &&
- type <= OBJECT_TEEN44 ) ||
- (type >= OBJECT_QUARTZ0 &&
- type <= OBJECT_QUARTZ3 ) ||
- (type >= OBJECT_ROOT0 &&
- type <= OBJECT_ROOT4 ) ) // not ROOT5!
+ (type >= OBJECT_PLANT0 &&
+ type <= OBJECT_PLANT19 ) ||
+ (type >= OBJECT_TREE0 &&
+ type <= OBJECT_TREE5 ) ||
+ (type >= OBJECT_TEEN0 &&
+ type <= OBJECT_TEEN44 ) ||
+ (type >= OBJECT_QUARTZ0 &&
+ type <= OBJECT_QUARTZ3 ) ||
+ (type >= OBJECT_ROOT0 &&
+ type <= OBJECT_ROOT4 ) ) // not ROOT5!
{
if ( type != OBJECT_TEEN11 && // lamp?
- type != OBJECT_TEEN12 && // coke?
- type != OBJECT_TEEN20 && // wall?
- type != OBJECT_TEEN21 && // wall?
- type != OBJECT_TEEN22 && // wall?
- type != OBJECT_TEEN26 && // lamp?
- type != OBJECT_TEEN28 && // bottle?
- type != OBJECT_TEEN34 ) // stone?
+ type != OBJECT_TEEN12 && // coke?
+ type != OBJECT_TEEN20 && // wall?
+ type != OBJECT_TEEN21 && // wall?
+ type != OBJECT_TEEN22 && // wall?
+ type != OBJECT_TEEN26 && // lamp?
+ type != OBJECT_TEEN28 && // bottle?
+ type != OBJECT_TEEN34 ) // stone?
{
gadget = 1;
}
@@ -4399,19 +4260,20 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
{
if (!TestGadgetQuantity(rankGadget++)) continue;
}
-
- Math::Vector pos = OpPos(line, "pos")*g_unit;
- float dirAngle = OpFloat(line, "dir", 0.0f)*Math::PI;
+
+ Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit;
+ float dirAngle = line->GetParam("dir")->AsFloat(0.0f)*Math::PI;
bool trainer;
CObject* obj = CObjectManager::GetInstancePointer()->CreateObject(
- pos, dirAngle,
- type,
- OpFloat(line, "power", 1.0f),
- OpFloat(line, "z", 1.0f),
- OpFloat(line, "h", 0.0f),
- trainer = OpInt(line, "trainer", 0),
- OpInt(line, "toy", 0),
- OpInt(line, "option", 0));
+ pos, dirAngle,
+ type,
+ line->GetParam("power")->AsFloat(1.0f),
+ line->GetParam("z")->AsFloat(1.0f),
+ line->GetParam("h")->AsFloat(0.0f),
+ trainer = line->GetParam("trainer")->AsBool(false),
+ line->GetParam("toy")->AsBool(false),
+ line->GetParam("option")->AsInt(0)
+ );
if (m_fixScene && type == OBJECT_HUMAN)
{
@@ -4419,108 +4281,111 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (m_phase == PHASE_WIN ) motion->SetAction(MHS_WIN, 0.4f);
if (m_phase == PHASE_LOST) motion->SetAction(MHS_LOST, 0.5f);
}
-
+
if (obj != nullptr)
{
obj->SetDefRank(rankObj);
-
+
if (type == OBJECT_BASE) m_base = true;
-
- Gfx::CameraType cType = OpCamera(line, "camera");
+
+ Gfx::CameraType cType = line->GetParam("camera")->AsCameraType(Gfx::CAM_TYPE_NULL);
if (cType != Gfx::CAM_TYPE_NULL)
obj->SetCameraType(cType);
-
- obj->SetCameraDist(OpFloat(line, "cameraDist", 50.0f));
- obj->SetCameraLock(OpInt(line, "cameraLock", 0));
-
- Gfx::PyroType pType = OpPyro(line, "pyro");
+
+ obj->SetCameraDist(line->GetParam("cameraDist")->AsFloat(50.0f));
+ obj->SetCameraLock(line->GetParam("cameraLock")->AsBool(false));
+
+ Gfx::PyroType pType = line->GetParam("pyro")->AsPyroType(Gfx::PT_NULL);
if (pType != Gfx::PT_NULL)
{
Gfx::CPyro* pyro = new Gfx::CPyro();
pyro->Create(pType, obj);
}
-
+
// Puts information in terminal (OBJECT_INFO).
for (int i = 0; i < OBJECTMAXINFO; i++)
{
- sprintf(op, "info%d", i+1);
- char text[100];
- OpString(line, op, text);
- if (text[0] == 0) break;
- char* p = strchr(text, '=');
- if (p == 0) break;
- *p = 0;
+ std::string op = "info"+boost::lexical_cast<std::string>(i+1);
+ if(!line->GetParam(op)->IsDefined()) break;
+ std::string text = line->GetParam(op)->AsString();
+ std::size_t p = text.find_first_of("=");
+ if(p == std::string::npos)
+ throw CLevelParserExceptionBadParam(line->GetParam(op), "info");
Info info;
- strcpy(info.name, text);
- sscanf(p+1, "%f", &info.value);
+ strcpy(info.name, text.substr(0, p).c_str());
+ try {
+ info.value = boost::lexical_cast<float>(text.substr(p+1).c_str());
+ }
+ catch(...)
+ {
+ throw CLevelParserExceptionBadParam(line->GetParam(op), "info.value (float)");
+ }
obj->SetInfo(i, info);
}
-
+
// Sets the parameters of the command line.
- char* p = SearchOp(line, "cmdline");
- for (int i = 0; i < OBJECTMAXCMDLINE; i++)
- {
- float value = GetFloat(p, i, NAN);
- if (value == NAN) break;
- obj->SetCmdLine(i, value);
+ if(line->GetParam("cmdline")->IsDefined()) {
+ const std::vector<CLevelParserParam*>& cmdline = line->GetParam("cmdline")->AsArray();
+ for (unsigned int i = 0; i < OBJECTMAXCMDLINE && i < cmdline.size(); i++) //TODO: get rid of the limit
+ {
+ obj->SetCmdLine(i, cmdline[i]->AsFloat());
+ }
}
-
- if (OpInt(line, "select", 0) == 1)
+
+ if (line->GetParam("select")->AsBool(false))
{
sel = obj;
}
-
- bool selectable = OpInt(line, "selectable", 1);
+
+ bool selectable = line->GetParam("selectable")->AsBool(true);
obj->SetSelectable(selectable);
- obj->SetIgnoreBuildCheck(OpInt(line, "ignoreBuildCheck", 0));
- obj->SetEnable(OpInt(line, "enable", 1));
- obj->SetProxyActivate(OpInt(line, "proxyActivate", 0));
- obj->SetProxyDistance(OpFloat(line, "proxyDistance", 15.0f)*g_unit);
- obj->SetRange(OpFloat(line, "range", 30.0f));
- obj->SetShield(OpFloat(line, "shield", 1.0f));
- obj->SetMagnifyDamage(OpFloat(line, "magnifyDamage", 1.0f));
- obj->SetClip(OpInt(line, "clip", 1));
- obj->SetCheckToken(m_version >= 2 ? trainer || !selectable : OpInt(line, "checkToken", 1));
+ obj->SetIgnoreBuildCheck(line->GetParam("ignoreBuildCheck")->AsBool(false));
+ obj->SetEnable(line->GetParam("enable")->AsBool(true));
+ obj->SetProxyActivate(line->GetParam("proxyActivate")->AsBool(false));
+ obj->SetProxyDistance(line->GetParam("proxyDistance")->AsFloat(15.0f)*g_unit);
+ obj->SetRange(line->GetParam("range")->AsFloat(30.0f));
+ obj->SetShield(line->GetParam("shield")->AsFloat(1.0f));
+ obj->SetMagnifyDamage(line->GetParam("magnifyDamage")->AsFloat(1.0f));
+ obj->SetClip(line->GetParam("clip")->AsBool(true));
+ obj->SetCheckToken(m_version >= 2 ? trainer || !selectable : line->GetParam("checkToken")->AsBool(true));
// SetManual will affect bot speed
if (type == OBJECT_MOBILEdr)
{
- obj->SetManual(m_version >= 2 ? !trainer : OpInt(line, "manual", 0));
+ obj->SetManual(m_version >= 2 ? !trainer : line->GetParam("manual")->AsBool(false));
}
-
+
if (m_version >= 2)
{
- Math::Vector zoom = OpDir(line, "zoom");
+ Math::Vector zoom = line->GetParam("zoom")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f));
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
obj->SetZoom(0, zoom);
}
-
+
+ //TODO: I don't remember what this is used for
CMotion* motion = obj->GetMotion();
- if (motion != nullptr)
+ if (motion != nullptr && line->GetParam("param")->IsDefined())
{
- p = SearchOp(line, "param");
- for (int i = 0; i < 10; i++)
+ const std::vector<CLevelParserParam*>& p = line->GetParam("param")->AsArray();
+ for (unsigned int i = 0; i < 10 && i < p.size(); i++)
{
- float value;
- value = GetFloat(p, i, NAN);
- if (value == NAN) break;
- motion->SetParam(i, value);
+ motion->SetParam(i, p[i]->AsFloat());
}
}
-
+
int run = -1;
CBrain* brain = obj->GetBrain();
if (brain != nullptr)
{
for (int i = 0; i < 10; i++)
{
- sprintf(op, "script%d", i+1); // script1..script10
- OpString(line, op, name);
- if (name[0] != 0)
- brain->SetScriptName(i, name);
-
+ std::string op = "script"+boost::lexical_cast<std::string>(i+1); // script1..script10
+ if(line->GetParam(op)->IsDefined()) {
+ brain->SetScriptName(i, const_cast<char*>(line->GetParam(op)->AsPath("").c_str())); //TODO: don't make this relative to ai/
+ }
+
}
-
- int i = OpInt(line, "run", 0);
+
+ int i = line->GetParam("run")->AsInt(0);
if (i != 0)
{
run = i-1;
@@ -4530,17 +4395,16 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
CAuto* automat = obj->GetAuto();
if (automat != nullptr)
{
- type = OpTypeObject(line, "autoType", OBJECT_NULL);
+ type = line->GetParam("autoType")->AsObjectType(OBJECT_NULL);
automat->SetType(type);
for (int i = 0; i < 5; i++)
{
- sprintf(op, "autoValue%d", i+1); // autoValue1..autoValue5
- automat->SetValue(i, OpFloat(line, op, 0.0f));
+ std::string op = "autoValue"+boost::lexical_cast<std::string>(i+1); // autoValue1..autoValue5
+ automat->SetValue(i, line->GetParam(op)->AsFloat(0.0f));
}
- OpString(line, "autoString", name);
- automat->SetString(name);
-
- int i = OpInt(line, "run", -1);
+ automat->SetString(const_cast<char*>(line->GetParam("autoString")->AsString("").c_str()));
+
+ int i = line->GetParam("run")->AsInt(-1);
if (i != -1)
{
if (i != PARAM_FIXSCENE &&
@@ -4548,30 +4412,29 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
automat->Start(i); // starts the film
}
}
-
- OpString(line, "soluce", name);
- if (soluce && brain != 0 && name[0] != 0)
- brain->SetSoluceName(name);
-
+
+ if (soluce && brain != nullptr && line->GetParam("soluce")->IsDefined())
+ brain->SetSoluceName(const_cast<char*>(line->GetParam("soluce")->AsString().c_str()));
+
obj->SetResetPosition(obj->GetPosition(0));
obj->SetResetAngle(obj->GetAngle(0));
obj->SetResetRun(run);
-
- if (OpInt(line, "reset", 0) == 1)
+
+ if (line->GetParam("reset")->AsBool(false))
obj->SetResetCap(RESET_MOVE);
}
-
+
rankObj ++;
continue;
}
-
- if (Cmd(line, "CreateFog") && !resetObject)
+
+ if (line->GetCommand() == "CreateFog" && !resetObject)
{
- Gfx::ParticleType type = static_cast<Gfx::ParticleType>((Gfx::PARTIFOG0+OpInt(line, "type", 0)));
- Math::Vector pos = OpPos(line, "pos")*g_unit;
- float height = OpFloat(line, "height", 1.0f)*g_unit;
- float ddim = OpFloat(line, "dim", 50.0f)*g_unit;
- float delay = OpFloat(line, "delay", 2.0f);
+ Gfx::ParticleType type = static_cast<Gfx::ParticleType>(Gfx::PARTIFOG0+(line->GetParam("type")->AsInt()));
+ Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit;
+ float height = line->GetParam("height")->AsFloat(1.0f)*g_unit;
+ float ddim = line->GetParam("dim")->AsFloat(50.0f)*g_unit;
+ float delay = line->GetParam("delay")->AsFloat(2.0f);
m_terrain->AdjustToFloor(pos);
pos.y += height;
Math::Point dim;
@@ -4580,149 +4443,150 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, type, delay, 0.0f, 0.0f);
continue;
}
-
- if (Cmd(line, "CreateLight") && !resetObject)
+
+ if (line->GetCommand() == "CreateLight" && !resetObject)
{
Gfx::EngineObjectType type;
-
- int lightRank = CreateLight(OpDir(line, "dir"),
- OpColor(line, "color", Gfx::Color(0.5f, 0.5f, 0.5f, 1.0f)));
-
- type = OpTypeTerrain(line, "type", Gfx::ENG_OBJTYPE_NULL);
+
+ int lightRank = CreateLight(line->GetParam("dir")->AsPoint(),
+ line->GetParam("color")->AsColor(Gfx::Color(0.5f, 0.5f, 0.5f, 1.0f)));
+
+ type = line->GetParam("type")->AsTerrainType(Gfx::ENG_OBJTYPE_NULL);
+
if (type == Gfx::ENG_OBJTYPE_TERRAIN)
{
m_lightMan->SetLightPriority(lightRank, Gfx::LIGHT_PRI_HIGHEST);
m_lightMan->SetLightIncludeType(lightRank, Gfx::ENG_OBJTYPE_TERRAIN);
}
-
+
if (type == Gfx::ENG_OBJTYPE_QUARTZ)
m_lightMan->SetLightIncludeType(lightRank, Gfx::ENG_OBJTYPE_QUARTZ);
-
+
if (type == Gfx::ENG_OBJTYPE_METAL)
m_lightMan->SetLightIncludeType(lightRank, Gfx::ENG_OBJTYPE_METAL);
-
+
if (type == Gfx::ENG_OBJTYPE_FIX)
m_lightMan->SetLightExcludeType(lightRank, Gfx::ENG_OBJTYPE_TERRAIN);
-
+
continue;
}
- if (Cmd(line, "CreateSpot") && !resetObject)
+ if (line->GetCommand() == "CreateSpot" && !resetObject)
{
Gfx::EngineObjectType type;
-
- int rankLight = CreateSpot(OpDir(line, "pos")*g_unit,
- OpColor(line, "color", Gfx::Color(0.5f, 0.5f, 0.5f, 1.0f)));
-
- type = OpTypeTerrain(line, "type", Gfx::ENG_OBJTYPE_NULL);
+
+ int rankLight = CreateSpot(line->GetParam("pos")->AsPoint()*g_unit,
+ line->GetParam("color")->AsColor(Gfx::Color(0.5f, 0.5f, 0.5f, 1.0f)));
+
+ type = line->GetParam("type")->AsTerrainType(Gfx::ENG_OBJTYPE_NULL);
if (type == Gfx::ENG_OBJTYPE_TERRAIN)
m_lightMan->SetLightIncludeType(rankLight, Gfx::ENG_OBJTYPE_TERRAIN);
-
+
if (type == Gfx::ENG_OBJTYPE_QUARTZ)
m_lightMan->SetLightIncludeType(rankLight, Gfx::ENG_OBJTYPE_QUARTZ);
-
+
if (type == Gfx::ENG_OBJTYPE_METAL)
m_lightMan->SetLightIncludeType(rankLight, Gfx::ENG_OBJTYPE_METAL);
-
+
if (type == Gfx::ENG_OBJTYPE_FIX)
m_lightMan->SetLightExcludeType(rankLight, Gfx::ENG_OBJTYPE_TERRAIN);
-
+
continue;
}
-
- if (Cmd(line, "GroundSpot") && !resetObject)
+
+ if (line->GetCommand() == "GroundSpot" && !resetObject)
{
rank = m_engine->CreateGroundSpot();
if (rank != -1)
{
- m_engine->SetObjectGroundSpotPos(rank, OpPos(line, "pos")*g_unit);
- m_engine->SetObjectGroundSpotRadius(rank, OpFloat(line, "radius", 10.0f)*g_unit);
- m_engine->SetObjectGroundSpotColor(rank, OpColor(line, "color", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)));
- m_engine->SetObjectGroundSpotSmooth(rank, OpFloat(line, "smooth", 1.0f));
- m_engine->SetObjectGroundSpotMinMax(rank, OpFloat(line, "min", 0.0f)*g_unit,
- OpFloat(line, "max", 0.0f)*g_unit);
+ m_engine->SetObjectGroundSpotPos(rank, line->GetParam("pos")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit);
+ m_engine->SetObjectGroundSpotRadius(rank, line->GetParam("radius")->AsFloat(10.0f)*g_unit);
+ m_engine->SetObjectGroundSpotColor(rank, line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)));
+ m_engine->SetObjectGroundSpotSmooth(rank, line->GetParam("smooth")->AsFloat(1.0f));
+ m_engine->SetObjectGroundSpotMinMax(rank, line->GetParam("min")->AsFloat(0.0f)*g_unit,
+ line->GetParam("max")->AsFloat(0.0f)*g_unit);
}
continue;
}
-
- if (Cmd(line, "WaterColor") && !resetObject)
+
+ if (line->GetCommand() == "WaterColor" && !resetObject)
{
- m_engine->SetWaterAddColor(OpColor(line, "color", Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f)));
+ m_engine->SetWaterAddColor(line->GetParam("color")->AsColor());
continue;
}
-
- if (Cmd(line, "MapColor") && !resetObject)
+
+ if (line->GetCommand() == "MapColor" && !resetObject)
{
- m_map->FloorColorMap(OpColor(line, "floor", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)),
- OpColor(line, "water", Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)));
- m_mapShow = OpInt(line, "show", 1);
+ m_map->FloorColorMap(line->GetParam("floor")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)),
+ line->GetParam("water")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)));
+ m_mapShow = line->GetParam("show")->AsBool(true);
m_map->ShowMap(m_mapShow);
- m_map->SetToy(OpInt(line, "toyIcon", 0));
- m_mapImage = OpInt(line, "image", 0);
+ m_map->SetToy(line->GetParam("toyIcon")->AsBool(false));
+ m_mapImage = line->GetParam("image")->AsBool(false);
if (m_mapImage)
{
- Math::Vector offset;
- OpString(line, "filename", m_mapFilename);
- offset = OpPos(line, "offset");
- m_map->SetFixParam(OpFloat(line, "zoom", 1.0f),
+ Math::Vector offset;
+ strcpy(m_mapFilename, line->GetParam("filename")->AsPath("").c_str()); //TODO: don't make this relative to textures/
+ offset = line->GetParam("offset")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f));
+ m_map->SetFixParam(line->GetParam("zoom")->AsFloat(1.0f),
offset.x, offset.z,
- OpFloat(line, "angle", 0.0f)*Math::PI/180.0f,
- OpInt(line, "mode", 0),
- OpInt(line, "debug", 0));
+ line->GetParam("angle")->AsFloat(0.0f)*Math::PI/180.0f,
+ line->GetParam("mode")->AsInt(0),
+ line->GetParam("debug")->AsBool(false));
}
continue;
}
-
- if (Cmd(line, "MapZoom") && !resetObject)
+
+ if (line->GetCommand() == "MapZoom" && !resetObject)
{
- m_map->ZoomMap(OpFloat(line, "factor", 2.0f));
- m_map->MapEnable(OpInt(line, "enable", 1));
+ m_map->ZoomMap(line->GetParam("factor")->AsFloat(2.0f));
+ m_map->MapEnable(line->GetParam("enable")->AsBool(true));
continue;
}
-
- if (Cmd(line, "MaxFlyingHeight") && !resetObject)
+
+ if (line->GetCommand() == "MaxFlyingHeight" && !resetObject)
{
- m_terrain->SetFlyingMaxHeight(OpFloat(line, "max", 280.0f)*g_unit);
+ m_terrain->SetFlyingMaxHeight(line->GetParam("max")->AsFloat(280.0f)*g_unit);
continue;
}
-
- if (Cmd(line, "AddFlyingHeight") && !resetObject)
+
+ if (line->GetCommand() == "AddFlyingHeight" && !resetObject)
{
- m_terrain->AddFlyingLimit(OpPos(line, "center")*g_unit,
- OpFloat(line, "extRadius", 20.0f)*g_unit,
- OpFloat(line, "intRadius", 10.0f)*g_unit,
- OpFloat(line, "maxHeight", 200.0f));
+ m_terrain->AddFlyingLimit(line->GetParam("center")->AsPoint()*g_unit,
+ line->GetParam("extRadius")->AsFloat(20.0f)*g_unit,
+ line->GetParam("intRadius")->AsFloat(10.0f)*g_unit,
+ line->GetParam("maxHeight")->AsFloat(200.0f));
continue;
}
-
- if (Cmd(line, "Camera"))
+
+ if (line->GetCommand() == "Camera")
{
- m_camera->Init(OpDir(line, "eye")*g_unit,
- OpDir(line, "lookat")*g_unit,
- resetObject?0.0f:OpFloat(line, "delay", 0.0f));
-
- if (OpInt(line, "fadeIn", 0) == 1)
+ m_camera->Init(line->GetParam("eye")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit,
+ line->GetParam("lookat")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit,
+ resetObject ? 0.0f : line->GetParam("delay")->AsFloat(0.0f));
+
+ if (line->GetParam("fadeIn")->AsBool(false))
m_camera->StartOver(Gfx::CAM_OVER_EFFECT_FADEIN_WHITE, Math::Vector(0.0f, 0.0f, 0.0f), 1.0f);
-
- m_camera->SetFixDirection(OpFloat(line, "fixDirection", 0.25f)*Math::PI);
+
+ m_camera->SetFixDirection(line->GetParam("fixDirection")->AsFloat(0.25f)*Math::PI);
continue;
}
-
- if (Cmd(line, "EndMissionTake") && !resetObject && m_controller == nullptr)
+
+ if (line->GetCommand() == "EndMissionTake" && !resetObject && m_controller == nullptr)
{
int i = m_endTakeTotal;
if (i < 10)
{
- m_endTake[i].pos = OpPos(line, "pos")*g_unit;
- m_endTake[i].dist = OpFloat(line, "dist", (m_version < 2 ? 8.0f : 100.0f))*g_unit;
- m_endTake[i].type = OpTypeObject(line, "type", OBJECT_NULL);
- m_endTake[i].min = OpInt(line, "min", 1);
- m_endTake[i].max = OpInt(line, "max", 9999);
+ m_endTake[i].pos = line->GetParam("pos")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit;
+ m_endTake[i].dist = line->GetParam("dist")->AsFloat(m_version < 2 ? 8.0f : 100.0f)*g_unit;
+ m_endTake[i].type = line->GetParam("type")->AsObjectType(OBJECT_NULL);
+ m_endTake[i].min = line->GetParam("min")->AsInt(1);
+ m_endTake[i].max = line->GetParam("max")->AsInt(9999);
if (m_version >= 2)
{
- m_endTake[i].powermin = OpFloat(line, "powermin", -1);
- m_endTake[i].powermax = OpFloat(line, "powermax", 100);
- m_endTake[i].tool = OpTool(line, "tool");
- m_endTake[i].drive = OpDrive(line, "drive");
+ m_endTake[i].powermin = line->GetParam("powermin")->AsFloat(-1);
+ m_endTake[i].powermax = line->GetParam("powermax")->AsFloat(100);
+ m_endTake[i].tool = line->GetParam("tool")->AsToolType(TOOL_OTHER);
+ m_endTake[i].drive = line->GetParam("drive")->AsDriveType(DRIVE_OTHER);
}
else
{
@@ -4731,93 +4595,91 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_endTake[i].tool = TOOL_OTHER;
m_endTake[i].drive = DRIVE_OTHER;
}
- m_endTake[i].lost = OpInt(line, "lost", -1);
- m_endTake[i].immediat = OpInt(line, "immediat", 0);
- OpString(line, "message", m_endTake[i].message);
+ m_endTake[i].lost = line->GetParam("lost")->AsInt(-1);
+ m_endTake[i].immediat = line->GetParam("immediat")->AsBool(false);
+ strcpy(m_endTake[i].message, line->GetParam("message")->AsString("").c_str()); //TODO: Really, ending mission on message()? Is this used anywhere? Do we need that?
m_endTakeTotal ++;
}
continue;
}
- if (Cmd(line, "EndMissionDelay") && !resetObject && m_controller == nullptr)
+ if (line->GetCommand() == "EndMissionDelay" && !resetObject && m_controller == nullptr)
{
- m_endTakeWinDelay = OpFloat(line, "win", 2.0f);
- m_endTakeLostDelay = OpFloat(line, "lost", 2.0f);
+ m_endTakeWinDelay = line->GetParam("win")->AsFloat(2.0f);
+ m_endTakeLostDelay = line->GetParam("lost")->AsFloat(2.0f);
continue;
}
- if (Cmd(line, "EndMissionResearch") && !resetObject && m_controller == nullptr)
+ if (line->GetCommand() == "EndMissionResearch" && !resetObject && m_controller == nullptr) //TODO: Is this used anywhere?
{
- m_endTakeResearch |= OpResearch(line, "type");
+ m_endTakeResearch |= line->GetParam("type")->AsResearchFlag();
continue;
}
- if (Cmd(line, "EndMissionNever") && !resetObject && m_controller == nullptr)
+ if (line->GetCommand() == "EndMissionNever" && !resetObject && m_controller == nullptr)
{
m_endTakeNever = true;
continue;
}
-
- if (Cmd(line, "ObligatoryToken") && !resetObject)
+
+ if (line->GetCommand() == "ObligatoryToken" && !resetObject) //NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises?
{
int i = m_obligatoryTotal;
- if (i < 100)
+ if (i < 100) //TODO: remove the limit
{
- OpString(line, "text", m_obligatoryToken[i]);
+ strcpy(m_obligatoryToken[i], line->GetParam("text")->AsString().c_str());
m_obligatoryTotal ++;
}
continue;
}
-
- if (Cmd(line, "ProhibitedToken") && !resetObject)
+
+ if (line->GetCommand() == "ProhibitedToken" && !resetObject) //NOTE: This was used only in CeeBot, maybe we should add this to some Colobot exercises?
{
int i = m_prohibitedTotal;
- if (i < 100)
+ if (i < 100) //TODO: remove the limit
{
- OpString(line, "text", m_prohibitedToken[i]);
+ strcpy(m_prohibitedToken[i], line->GetParam("text")->AsString().c_str());
m_prohibitedTotal ++;
}
continue;
}
-
- if (Cmd(line, "EnableBuild") && !resetObject)
+
+ if (line->GetCommand() == "EnableBuild" && !resetObject)
{
- g_build |= OpBuild(line, "type");
+ g_build |= line->GetParam("type")->AsBuildFlag();
continue;
}
-
- if (Cmd(line, "EnableResearch") && !resetObject)
+
+ if (line->GetCommand() == "EnableResearch" && !resetObject)
{
- g_researchEnable |= OpResearch(line, "type");
+ g_researchEnable |= line->GetParam("type")->AsResearchFlag();
continue;
}
-
- if (Cmd(line, "DoneResearch") && read[0] == 0 && !resetObject) // not loading file?
+
+ if (line->GetCommand() == "DoneResearch" && read[0] == 0 && !resetObject) // not loading file?
{
- g_researchDone |= OpResearch(line, "type");
+ g_researchDone |= line->GetParam("type")->AsResearchFlag();
continue;
}
-
- if (Cmd(line, "NewScript") && !resetObject)
+
+ if (line->GetCommand() == "NewScript" && !resetObject)
{
- OpString(line, "name", name);
- AddNewScriptName(OpTypeObject(line, "type", OBJECT_NULL), name);
+ char name[200];
+ strcpy(name, line->GetParam("name")->AsPath("").c_str()); //TODO: don't make this relative to ai/
+ AddNewScriptName(line->GetParam("type")->AsObjectType(OBJECT_NULL), name);
continue;
}
-
- if (line[0] == '\n') continue; // Ignore empty lines
- if (line[0] == '\0') continue; // Ignore empty lines
- if (read[0] != 0) continue; // Ignore when loading saved game
-
- GetLogger()->Error("Syntax error in file '%s' (line %d): Unknown command: %s", filename, lineNum, line); // Don't add \n at the end of log message - it's included in line variable
+
+ if(read[0] != 0) continue; // ignore errors when loading saevd game (TODO: don't report ones that are just not loaded when loading saved game)
+ if(resetObject) continue; // ignore when reseting just objects (TODO: see above)
+
+ throw CLevelParserException("Unknown command: '"+line->GetCommand()+"' in "+line->GetLevel()->GetFilename()+":"+boost::lexical_cast<std::string>(line->GetLineNumber()));
}
- fclose(file);
-
if (read[0] == 0)
CompileScript(soluce); // compiles all scripts
- if (strcmp(base, "scene") == 0 && !resetObject) // mission?
+ if (strcmp(base, "missions") == 0 && !resetObject) // mission?
WriteFreeParam();
- if (strcmp(base, "free") == 0 && !resetObject) // free play?
+ if (strcmp(base, "freemissions") == 0 && !resetObject) // free play?
{
g_researchDone = m_freeResearch;
@@ -4959,7 +4821,7 @@ void CRobotMain::ChangeColor()
exclu[3] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // SatCom screen
exclu[4] = Math::Point(0.0f, 0.0f);
exclu[5] = Math::Point(0.0f, 0.0f); // terminator
- m_engine->ChangeTextureColor("human.png", colorRef1, colorNew1, colorRef2, colorNew2, 0.30f, 0.01f, ts, ti, exclu);
+ m_engine->ChangeTextureColor("textures/human.png", colorRef1, colorNew1, colorRef2, colorNew2, 0.30f, 0.01f, ts, ti, exclu);
float tolerance;
@@ -5001,7 +4863,7 @@ void CRobotMain::ChangeColor()
colorNew2.b = 0.0f;
char name[100];
- sprintf(name, "face%.2d.png", face+1);
+ sprintf(name, "textures/face%.2d.png", face+1);
exclu[0] = Math::Point(105.0f/256.0f, 47.0f/166.0f);
exclu[1] = Math::Point(153.0f/256.0f, 79.0f/166.0f); // blue canister
exclu[2] = Math::Point(0.0f, 0.0f);
@@ -5015,19 +4877,19 @@ void CRobotMain::ChangeColor()
colorNew2.g = 0.0f;
colorNew2.b = 0.0f;
- m_engine->ChangeTextureColor("base1.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
- m_engine->ChangeTextureColor("convert.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
- m_engine->ChangeTextureColor("derrick.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
- m_engine->ChangeTextureColor("factory.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
- m_engine->ChangeTextureColor("lemt.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
- m_engine->ChangeTextureColor("roller.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
- m_engine->ChangeTextureColor("search.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
+ m_engine->ChangeTextureColor("textures/base1.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
+ m_engine->ChangeTextureColor("textures/convert.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
+ m_engine->ChangeTextureColor("textures/derrick.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
+ m_engine->ChangeTextureColor("textures/factory.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
+ m_engine->ChangeTextureColor("textures/lemt.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
+ m_engine->ChangeTextureColor("textures/roller.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
+ m_engine->ChangeTextureColor("textures/search.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true);
exclu[0] = Math::Point( 0.0f/256.0f, 160.0f/256.0f);
exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // pencils
exclu[2] = Math::Point(0.0f, 0.0f);
exclu[3] = Math::Point(0.0f, 0.0f); // terminator
- m_engine->ChangeTextureColor("drawer.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true);
+ m_engine->ChangeTextureColor("textures/drawer.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true);
exclu[0] = Math::Point(237.0f/256.0f, 176.0f/256.0f);
exclu[1] = Math::Point(256.0f/256.0f, 220.0f/256.0f); // blue canister
@@ -5035,26 +4897,26 @@ void CRobotMain::ChangeColor()
exclu[3] = Math::Point(130.0f/256.0f, 214.0f/256.0f); // safe location
exclu[4] = Math::Point(0.0f, 0.0f);
exclu[5] = Math::Point(0.0f, 0.0f); // terminator
- m_engine->ChangeTextureColor("subm.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true);
+ m_engine->ChangeTextureColor("textures/subm.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true);
exclu[0] = Math::Point(128.0f/256.0f, 160.0f/256.0f);
exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // SatCom
exclu[2] = Math::Point(0.0f, 0.0f);
exclu[3] = Math::Point(0.0f, 0.0f); // terminator
- m_engine->ChangeTextureColor("ant.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti, exclu);
- m_engine->ChangeTextureColor("mother.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti);
+ m_engine->ChangeTextureColor("textures/ant.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti, exclu);
+ m_engine->ChangeTextureColor("textures/mother.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti);
- m_engine->ChangeTextureColor("plant.png", m_colorRefGreen, m_colorNewGreen, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti);
+ m_engine->ChangeTextureColor("textures/plant.png", m_colorRefGreen, m_colorNewGreen, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti);
// PARTIPLOUF0 and PARTIDROP :
ts = Math::Point(0.500f, 0.500f);
ti = Math::Point(0.875f, 0.750f);
- m_engine->ChangeTextureColor("effect00.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true);
+ m_engine->ChangeTextureColor("textures/effect00.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true);
// PARTIFLIC :
ts = Math::Point(0.00f, 0.75f);
ti = Math::Point(0.25f, 1.00f);
- m_engine->ChangeTextureColor("effect02.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true);
+ m_engine->ChangeTextureColor("textures/effect02.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true);
}
//! Updates the number of unnecessary objects
@@ -5488,11 +5350,12 @@ void CRobotMain::CompileScript(bool soluce)
{
if (brain->GetCompile(j)) continue;
- char* name = brain->GetScriptName(j);
+ std::string name = brain->GetScriptName(j);
+ name = "ai/"+name;
if (name[0] != 0)
{
- if(! brain->ReadProgram(j, name)) {
- CLogger::GetInstancePointer()->Error("Unable to read script from file \"%s\"\n", name);
+ if(! brain->ReadProgram(j, const_cast<char*>(name.c_str()))) {
+ CLogger::GetInstancePointer()->Error("Unable to read script from file \"%s\"\n", name.c_str());
}
if (!brain->GetCompile(j)) nbError++;
}
@@ -6346,20 +6209,28 @@ void CRobotMain::ResetCreate()
m_camera->SetType(Gfx::CAM_TYPE_DIALOG);
- CreateScene(m_dialog->GetSceneSoluce(), false, true);
+ try {
+ CreateScene(m_dialog->GetSceneSoluce(), false, true);
- if (!GetNiceReset()) return;
+ if (!GetNiceReset()) return;
- for (int i = 0; i < 1000000; i++)
- {
- CObject* obj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
- if (obj == nullptr) break;
+ for (int i = 0; i < 1000000; i++)
+ {
+ CObject* obj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
+ if (obj == nullptr) break;
- ResetCap cap = obj->GetResetCap();
- if (cap == RESET_NONE) continue;
+ ResetCap cap = obj->GetResetCap();
+ if (cap == RESET_NONE) continue;
- Gfx::CPyro* pyro = new Gfx::CPyro();
- pyro->Create(Gfx::PT_RESET, obj);
+ Gfx::CPyro* pyro = new Gfx::CPyro();
+ pyro->Create(Gfx::PT_RESET, obj);
+ }
+ }
+ catch(const CLevelParserException& e)
+ {
+ CLogger::GetInstancePointer()->Error("An error occured while trying to reset scene\n");
+ CLogger::GetInstancePointer()->Error("%s\n", e.what());
+ ChangePhase(PHASE_TERM);
}
}
@@ -6811,6 +6682,21 @@ float CRobotMain::GetPersoAngle()
return m_dialog->GetPersoAngle();
}
+char* CRobotMain::GetSceneName()
+{
+ return m_dialog->GetSceneName();
+}
+
+int CRobotMain::GetSceneRank()
+{
+ return m_dialog->GetSceneRank();
+}
+
+void CRobotMain::BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile)
+{
+ m_dialog->BuildSceneName(filename, base, rank, sceneFile);
+}
+
//! Changes on the pause mode
void CRobotMain::ChangePause(PauseType pause)
@@ -7046,3 +6932,8 @@ void CRobotMain::DisplayError(Error err, Math::Vector goal, float height, float
{
m_displayText->DisplayError(err, goal, height, dist, time);
}
+
+std::string& CRobotMain::GetUserLevelName(int id)
+{
+ return m_dialog->GetUserLevelName(id);
+}
diff --git a/src/object/robotmain.h b/src/object/robotmain.h
index 2db7bfe..882265c 100644
--- a/src/object/robotmain.h
+++ b/src/object/robotmain.h
@@ -340,6 +340,9 @@ public:
int GetGamerGlasses();
bool GetGamerOnlyHead();
float GetPersoAngle();
+ char* GetSceneName();
+ int GetSceneRank();
+ void BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile = true);
void StartMusic();
void StartPauseMusic(PauseType pause);
@@ -389,6 +392,8 @@ public:
void DisplayError(Error err, CObject* pObj, float time=10.0f);
void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f);
+
+ std::string& GetUserLevelName(int id);
protected:
bool EventFrame(const Event &event);
@@ -488,13 +493,6 @@ protected:
CObject* m_controller;
- // Level Checker flags
- bool m_beginObject;
- bool m_terrainGenerate;
- bool m_terrainInitTextures;
- bool m_terrainInit;
- bool m_terrainCreate;
-
int m_version; // Mission file version
bool m_retroStyle; // Retro
bool m_immediatSatCom; // SatCom immediately?
diff --git a/src/script/cmdtoken.cpp b/src/script/cmdtoken.cpp
index d40be82..317e881 100644
--- a/src/script/cmdtoken.cpp
+++ b/src/script/cmdtoken.cpp
@@ -26,6 +26,8 @@
#include <cstdio>
+// TODO: Remove these functions
+
// Skips spaces.
diff --git a/src/script/script.cpp b/src/script/script.cpp
index ae640d4..abb2a8b 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -21,13 +21,15 @@
#include "script/script.h"
#include "app/app.h"
-#include "app/gamedata.h"
#include "common/global.h"
#include "common/iman.h"
#include "common/restext.h"
#include "common/stringutils.h"
+#include "common/resources/inputstream.h"
+#include "common/resources/resourcemanager.h"
+
#include "graphics/engine/terrain.h"
#include "graphics/engine/water.h"
#include "graphics/engine/text.h"
@@ -4369,7 +4371,6 @@ void CScript::GetError(std::string& error)
void CScript::New(Ui::CEdit* edit, const char* name)
{
- FILE *file = NULL;
char res[100];
char text[100];
char script[500];
@@ -4412,18 +4413,18 @@ void CScript::New(Ui::CEdit* edit, const char* name)
sf = m_main->GetScriptFile();
if ( sf[0] != 0 ) // Load an empty program specific?
{
- std::string filename = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, sf);
- file = fopen(filename.c_str(), "rb");
- if ( file != NULL )
+ std::string filename = sf;
+ CInputStream stream;
+ stream.open(filename);
+
+ if (stream.is_open())
{
- fseek(file, 0, SEEK_END);
- len = ftell(file);
- fseek(file, 0, SEEK_SET);
+ len = stream.size();
if ( len > 500-1 ) len = 500-1;
- fread(buffer, 1, len, file);
+ stream.read(buffer, len);
buffer[len] = 0;
- fclose(file);
+ stream.close();
cursor1 = 0;
i = 0;
@@ -4500,24 +4501,9 @@ bool CScript::SendScript(const char* text)
bool CScript::ReadScript(const char* filename)
{
- FILE* file;
Ui::CEdit* edit;
- std::string name;
-
- if ( strchr(filename, '/') == 0 ) //we're reading non user script
- {
- name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename);
- }
- else
- {
- name = filename;
- //TODO: is this needed?
- // UserDir(name, filename, "");
- }
- file = fopen(name.c_str(), "rb");
- if ( file == NULL ) return false;
- fclose(file);
+ if (!CResourceManager::Exists(filename)) return false;
delete[] m_script;
m_script = nullptr;
@@ -4525,7 +4511,7 @@ bool CScript::ReadScript(const char* filename)
edit = m_interface->CreateEdit(Math::Point(0.0f, 0.0f), Math::Point(0.0f, 0.0f), 0, EVENT_EDIT9);
edit->SetMaxChar(Ui::EDITSTUDIOMAX);
edit->SetAutoIndent(m_engine->GetEditIndentMode());
- edit->ReadText(name.c_str());
+ edit->ReadText(filename);
GetScript(edit);
m_interface->DeleteControl(EVENT_EDIT9);
return true;
@@ -4536,16 +4522,6 @@ bool CScript::ReadScript(const char* filename)
bool CScript::WriteScript(const char* filename)
{
Ui::CEdit* edit;
- std::string name;
-
- if ( strchr(filename, '/') == 0 ) //we're writing non user script
- {
- name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename);
- }
- else
- {
- name = filename;
- }
if ( m_script == nullptr )
{
@@ -4557,7 +4533,7 @@ bool CScript::WriteScript(const char* filename)
edit->SetMaxChar(Ui::EDITSTUDIOMAX);
edit->SetAutoIndent(m_engine->GetEditIndentMode());
edit->SetText(m_script);
- edit->WriteText(name);
+ edit->WriteText(filename);
m_interface->DeleteControl(EVENT_EDIT9);
return true;
}
diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp
index 960faac..0d8fe74 100644
--- a/src/sound/oalsound/alsound.cpp
+++ b/src/sound/oalsound/alsound.cpp
@@ -20,8 +20,6 @@
#include "sound/oalsound/alsound.h"
-#include "app/gamedata.h"
-
#include <algorithm>
#include <iomanip>
@@ -161,7 +159,7 @@ int ALSound::GetMusicVolume()
bool ALSound::Cache(Sound sound, const std::string &filename)
{
Buffer *buffer = new Buffer();
- if (buffer->LoadFromFile(CGameData::GetInstancePointer()->GetFilePath(DIR_SOUND, filename), sound))
+ if (buffer->LoadFromFile(filename, sound))
{
m_sounds[sound] = buffer;
return true;
@@ -171,12 +169,12 @@ bool ALSound::Cache(Sound sound, const std::string &filename)
bool ALSound::CacheMusic(const std::string &filename)
{
- if (m_music.find(filename) == m_music.end())
+ if (m_music.find("music/"+filename) == m_music.end())
{
Buffer *buffer = new Buffer();
- if (buffer->LoadFromFile(CGameData::GetInstancePointer()->GetFilePath(DIR_MUSIC, filename), static_cast<Sound>(-1)))
+ if (buffer->LoadFromFile("music/"+filename, static_cast<Sound>(-1)))
{
- m_music[filename] = buffer;
+ m_music["music/"+filename] = buffer;
return true;
}
}
@@ -632,30 +630,29 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim
return false;
}
- std::string file = CGameData::GetInstancePointer()->GetFilePath(DIR_MUSIC, filename);
Buffer *buffer;
// check if we have music in cache
- if (m_music.find(filename) == m_music.end())
+ if (m_music.find("music/"+filename) == m_music.end())
{
GetLogger()->Debug("Music %s was not cached!\n", filename.c_str());
- if (!boost::filesystem::exists(file))
+ /* TODO: if (!boost::filesystem::exists("music/"+filename))
{
GetLogger()->Debug("Requested music %s was not found.\n", filename.c_str());
return false;
- }
+ } */
buffer = new Buffer();
- if (!buffer->LoadFromFile(file, static_cast<Sound>(-1)))
+ if (!buffer->LoadFromFile("music/"+filename, static_cast<Sound>(-1)))
{
return false;
}
- m_music[filename] = buffer;
+ m_music["music/"+filename] = buffer;
}
else
{
GetLogger()->Debug("Music loaded from cache\n");
- buffer = m_music[filename];
+ buffer = m_music["music/"+filename];
}
if (m_currentMusic)
diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h
index 25ef3d6..08caac3 100644
--- a/src/sound/oalsound/alsound.h
+++ b/src/sound/oalsound/alsound.h
@@ -50,45 +50,44 @@ public:
ALSound();
~ALSound();
- bool Create();
- bool Cache(Sound, const std::string &);
- bool CacheMusic(const std::string &);
-
- bool GetEnable();
-
- void SetAudioVolume(int volume);
- int GetAudioVolume();
- void SetMusicVolume(int volume);
- int GetMusicVolume();
-
- void SetListener(const Math::Vector &eye, const Math::Vector &lookat);
- void FrameMove(float rTime);
-
- int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
- int Play(Sound sound, const Math::Vector &pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
- bool FlushEnvelope(int channel);
- bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper);
- bool Position(int channel, const Math::Vector &pos);
- bool Frequency(int channel, float frequency);
- bool Stop(int channel);
- bool StopAll();
- bool MuteAll(bool bMute);
-
- bool PlayMusic(int rank, bool bRepeat, float fadeTime=2.0f);
- bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=2.0f);
- bool RestartMusic();
- void SuspendMusic();
- void StopMusic(float fadeTime=2.0f);
- bool IsPlayingMusic();
- bool PlayPauseMusic(const std::string &filename, bool repeat);
- void StopPauseMusic();
-
- bool CheckChannel(int &channel);
+ bool Create() override;
+ bool Cache(Sound, const std::string &) override;
+ bool CacheMusic(const std::string &) override;
+
+ bool GetEnable() override;
+
+ void SetAudioVolume(int volume) override;
+ int GetAudioVolume() override;
+ void SetMusicVolume(int volume) override;
+ int GetMusicVolume() override;
+
+ void SetListener(const Math::Vector &eye, const Math::Vector &lookat) override;
+ void FrameMove(float rTime) override;
+
+ int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) override;
+ int Play(Sound sound, const Math::Vector &pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false) override;
+ bool FlushEnvelope(int channel) override;
+ bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper) override;
+ bool Position(int channel, const Math::Vector &pos) override;
+ bool Frequency(int channel, float frequency) override;
+ bool Stop(int channel) override;
+ bool StopAll() override;
+ bool MuteAll(bool bMute) override;
+
+ bool PlayMusic(int rank, bool bRepeat, float fadeTime=2.0f) override;
+ bool PlayMusic(const std::string &filename, bool bRepeat, float fadeTime=2.0f) override;
+ bool RestartMusic() override;
+ void SuspendMusic() override;
+ void StopMusic(float fadeTime=2.0f) override;
+ bool IsPlayingMusic() override;
+ bool PlayPauseMusic(const std::string &filename, bool repeat) override;
+ void StopPauseMusic() override;
private:
void CleanUp();
int GetPriority(Sound);
bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded);
+ bool CheckChannel(int &channel);
bool m_enabled;
float m_audioVolume;
diff --git a/src/sound/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp
index 5a46566..7584767 100644
--- a/src/sound/oalsound/buffer.cpp
+++ b/src/sound/oalsound/buffer.cpp
@@ -20,7 +20,10 @@
#include "sound/oalsound/buffer.h"
-#include <cstring>
+#include <memory>
+
+#include "common/resources/resourcemanager.h"
+
Buffer::Buffer()
{
@@ -45,19 +48,17 @@ bool Buffer::LoadFromFile(std::string filename, Sound sound)
m_sound = sound;
GetLogger()->Debug("Loading audio file: %s\n", filename.c_str());
- SF_INFO fileInfo;
- memset(&fileInfo, 0, sizeof(SF_INFO));
- SNDFILE *file = sf_open(filename.c_str(), SFM_READ, &fileInfo);
+ std::unique_ptr<CSNDFile> file = std::unique_ptr<CSNDFile>(CResourceManager::GetSNDFileHandler(filename));
- GetLogger()->Trace(" channels %d\n", fileInfo.channels);
- GetLogger()->Trace(" format %d\n", fileInfo.format);
- GetLogger()->Trace(" frames %d\n", fileInfo.frames);
- GetLogger()->Trace(" samplerate %d\n", fileInfo.samplerate);
- GetLogger()->Trace(" sections %d\n", fileInfo.sections);
+ GetLogger()->Trace(" channels %d\n", file->GetFileInfo().channels);
+ GetLogger()->Trace(" format %d\n", file->GetFileInfo().format);
+ GetLogger()->Trace(" frames %d\n", file->GetFileInfo().frames);
+ GetLogger()->Trace(" samplerate %d\n", file->GetFileInfo().samplerate);
+ GetLogger()->Trace(" sections %d\n", file->GetFileInfo().sections);
- if (!file)
+ if (!file->IsOpen())
{
- GetLogger()->Warn("Could not load file. Reason: %s\n", sf_strerror(file));
+ GetLogger()->Warn("Could not load file. Reason: %s\n", file->GetLastError().c_str());
m_loaded = false;
return false;
}
@@ -67,23 +68,21 @@ bool Buffer::LoadFromFile(std::string filename, Sound sound)
{
GetLogger()->Warn("Could not create audio buffer\n");
m_loaded = false;
- sf_close(file);
return false;
}
// read chunks of 4096 samples
std::vector<uint16_t> data;
std::array<int16_t, 4096> buffer;
- data.reserve(fileInfo.frames);
+ data.reserve(file->GetFileInfo().frames);
size_t read = 0;
- while ((read = sf_read_short(file, buffer.data(), buffer.size())) != 0)
+ while ((read = file->Read(buffer.data(), buffer.size())) != 0)
{
data.insert(data.end(), buffer.begin(), buffer.begin() + read);
}
- sf_close(file);
- alBufferData(m_buffer, fileInfo.channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, &data.front(), data.size() * sizeof(uint16_t), fileInfo.samplerate);
- m_duration = static_cast<float>(fileInfo.frames) / fileInfo.samplerate;
+ alBufferData(m_buffer, file->GetFileInfo().channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, &data.front(), data.size() * sizeof(uint16_t), file->GetFileInfo().samplerate);
+ m_duration = static_cast<float>(file->GetFileInfo().frames) / file->GetFileInfo().samplerate;
m_loaded = true;
return true;
}
diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp
index da60dbc..abc18f6 100644
--- a/src/sound/sound.cpp
+++ b/src/sound/sound.cpp
@@ -48,7 +48,7 @@ void CSoundInterface::CacheAll()
for ( int i = 1; i < SOUND_MAX; i++ )
{
std::stringstream filename;
- filename << "sound" << std::setfill('0') << std::setw(3) << i << ".wav";
+ filename << "sounds/sound" << std::setfill('0') << std::setw(3) << i << ".wav";
if ( !Cache(static_cast<Sound>(i), filename.str()) )
GetLogger()->Warn("Unable to load audio: %s\n", filename.str().c_str());
}
diff --git a/src/ui/button.cpp b/src/ui/button.cpp
index 3cb7d25..0a10379 100644
--- a/src/ui/button.cpp
+++ b/src/ui/button.cpp
@@ -178,7 +178,7 @@ void CButton::Draw()
(m_state & STATE_CARD ) == 0 &&
(m_state & STATE_SIMPLY) == 0 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
dp = 0.5f / 256.0f;
diff --git a/src/ui/check.cpp b/src/ui/check.cpp
index 2e6f8ff..e590309 100644
--- a/src/ui/check.cpp
+++ b/src/ui/check.cpp
@@ -104,7 +104,7 @@ void CCheck::Draw()
DrawShadow(m_pos, m_dim);
}
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
zoomExt = 1.00f;
diff --git a/src/ui/color.cpp b/src/ui/color.cpp
index 0ffdc72..ddf7629 100644
--- a/src/ui/color.cpp
+++ b/src/ui/color.cpp
@@ -140,7 +140,7 @@ void CColor::Draw()
DrawShadow(m_pos, m_dim);
}
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
CControl::Draw();
diff --git a/src/ui/compass.cpp b/src/ui/compass.cpp
index e49302a..45977c5 100644
--- a/src/ui/compass.cpp
+++ b/src/ui/compass.cpp
@@ -90,7 +90,7 @@ void CCompass::Draw()
device = m_engine->GetDevice();
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
p1.x = m_pos.x;
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 22f863b..a4cdbfc 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -439,7 +439,7 @@ void CControl::Draw()
if ( (m_state & STATE_VISIBLE) == 0 ) return;
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
zoomExt = 1.00f;
@@ -493,7 +493,7 @@ void CControl::Draw()
if ( m_state & STATE_OKAY )
{
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
icon = 3; // yellow with green point pressed
}
@@ -508,19 +508,19 @@ void CControl::Draw()
if ( icon >= 192 )
{
icon -= 192;
- m_engine->SetTexture("text.png");
+ m_engine->SetTexture("textures/interface/text.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
}
else if ( icon >= 128 )
{
icon -= 128;
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
}
else if ( icon >= 64 )
{
icon -= 64;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
}
else
@@ -753,7 +753,7 @@ void CControl::DrawWarning(Math::Point pos, Math::Point dim)
dp = 0.5f / 256.0f;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f;
@@ -797,7 +797,7 @@ void CControl::DrawShadow(Math::Point pos, Math::Point dim, float deep)
dp = 0.5f/256.0f;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState( Gfx::ENG_RSTATE_TTEXTURE_WHITE);
pos.x += deep * 0.010f * 0.75f;
diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp
index 891c1ab..aceb5b0 100644
--- a/src/ui/displayinfo.cpp
+++ b/src/ui/displayinfo.cpp
@@ -344,8 +344,6 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc
m_index = index;
m_bSoluce = bSoluce;
-//? CreateObjectsFile();
-
m_bEditLock = m_main->GetEditLock();
if ( m_bEditLock ) // edition running program?
{
@@ -937,284 +935,4 @@ CObject* CDisplayInfo::SearchToto()
return 0;
}
-
-// Creating the list of objects.
-
-struct ObjectList
-{
- int total;
- ObjectType type;
-};
-
-void ObjectAdd(ObjectList list[], ObjectType type)
-{
- int i;
-
- for ( i=0 ; i<200 ; i++ )
- {
- if ( list[i].total == 0 )
- {
- list[i].total ++;
- list[i].type = type;
- list[i+1].total = 0;
- return;
- }
- if ( list[i].type == type )
- {
- list[i].total ++;
- return;
- }
- }
-}
-
-void ObjectWrite(FILE* file, ObjectList list[], int i)
-{
- std::string line;
-
- if ( list[i].total < 10 )
- {
- line = StrUtils::Format("\\c; %dx \\n;\\l;", list[i].total);
- }
- else
- {
- line = StrUtils::Format("\\c;%dx \\n;\\l;", list[i].total);
- }
-
- std::string res;
- GetResource(RES_OBJECT, list[i].type, res);
- if (res.empty())
- return;
-
- line += res;
-
- line += "\\u ";
-
- std::string helpFilename = GetHelpFilename(list[i].type);
- if (helpFilename.empty())
- return;
-
- line += helpFilename.substr(7); // skip "help\?\"
-
- auto pos = line.find(".txt");
- if (pos != std::string::npos)
- {
- line = line.substr(0, pos);
- }
-
- line += ";\n";
-
- fputs(line.c_str(), file);
-}
-
-// Creates the file containing the list of objects.
-
-void CDisplayInfo::CreateObjectsFile()
-{
- FILE* file;
- CObject* pObj;
- ObjectType type;
- ObjectList list[200];
- std::string line;
- int i;
- bool bRadar, bAtLeast;
-
- CInstanceManager* iMan = CInstanceManager::GetInstancePointer();
-
- file = fopen((std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("objects.txt")).c_str(), "w");
- if ( file == 0 ) return;
-
- list[0].total = 0; // empty list
- bRadar = false;
- for ( i=0 ; i<1000000 ; i++ )
- {
- pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
- if ( pObj == 0 ) break;
-
- if ( !pObj->GetActif() ) continue;
- if ( !pObj->GetSelectable() ) continue;
- if ( pObj->GetProxyActivate() ) continue;
-
- type = pObj->GetType();
- if ( type == OBJECT_NULL ) continue;
- if ( type == OBJECT_FIX ) continue;
-
- ObjectAdd(list, type);
-
- if ( type == OBJECT_RADAR ) bRadar = true;
- }
-
- if ( bRadar )
- {
- GetResource(RES_TEXT, RT_SATCOM_LIST, line);
- fputs(line.c_str(), file);
- bAtLeast = false;
- for ( i=0 ; i<200 ; i++ )
- {
- if ( list[i].total == 0 ) break; // end of the list?
-
- if ( list[i].type == OBJECT_BASE ||
- list[i].type == OBJECT_HUMAN )
- {
- ObjectWrite(file, list, i);
- bAtLeast = true;
- }
- }
- if ( !bAtLeast )
- {
- GetResource(RES_TEXT, RT_SATCOM_NULL, line);
- fputs(line.c_str(), file);
- }
-
- fputs("\n", file);
- GetResource(RES_TEXT, RT_SATCOM_BOT, line);
- fputs(line.c_str(), file);
- bAtLeast = false;
- for ( i=0 ; i<200 ; i++ )
- {
- if ( list[i].total == 0 ) break; // end of the list?
-
- if ( list[i].type == OBJECT_MOBILEwt ||
- list[i].type == OBJECT_MOBILEtt ||
- list[i].type == OBJECT_MOBILEft ||
- list[i].type == OBJECT_MOBILEit ||
- list[i].type == OBJECT_MOBILEwa ||
- list[i].type == OBJECT_MOBILEta ||
- list[i].type == OBJECT_MOBILEfa ||
- list[i].type == OBJECT_MOBILEia ||
- list[i].type == OBJECT_MOBILEwc ||
- list[i].type == OBJECT_MOBILEtc ||
- list[i].type == OBJECT_MOBILEfc ||
- list[i].type == OBJECT_MOBILEic ||
- list[i].type == OBJECT_MOBILEwi ||
- list[i].type == OBJECT_MOBILEti ||
- list[i].type == OBJECT_MOBILEfi ||
- list[i].type == OBJECT_MOBILEii ||
- list[i].type == OBJECT_MOBILEws ||
- list[i].type == OBJECT_MOBILEts ||
- list[i].type == OBJECT_MOBILEfs ||
- list[i].type == OBJECT_MOBILEis ||
- list[i].type == OBJECT_MOBILErt ||
- list[i].type == OBJECT_MOBILErc ||
- list[i].type == OBJECT_MOBILErr ||
- list[i].type == OBJECT_MOBILErs ||
- list[i].type == OBJECT_MOBILEsa ||
- list[i].type == OBJECT_MOBILEtg ||
- list[i].type == OBJECT_MOBILEdr )
- {
- ObjectWrite(file, list, i);
- bAtLeast = true;
- }
- }
- if ( !bAtLeast )
- {
- GetResource(RES_TEXT, RT_SATCOM_NULL, line);
- fputs(line.c_str(), file);
- }
-
- fputs("\n", file);
- GetResource(RES_TEXT, RT_SATCOM_BUILDING, line);
- fputs(line.c_str(), file);
- bAtLeast = false;
- for ( i=0 ; i<200 ; i++ )
- {
- if ( list[i].total == 0 ) break; // end of the list?
-
- if ( list[i].type == OBJECT_DERRICK ||
- list[i].type == OBJECT_FACTORY ||
- list[i].type == OBJECT_STATION ||
- list[i].type == OBJECT_CONVERT ||
- list[i].type == OBJECT_REPAIR ||
- list[i].type == OBJECT_DESTROYER||
- list[i].type == OBJECT_TOWER ||
- list[i].type == OBJECT_NEST ||
- list[i].type == OBJECT_RESEARCH ||
- list[i].type == OBJECT_RADAR ||
- list[i].type == OBJECT_ENERGY ||
- list[i].type == OBJECT_LABO ||
- list[i].type == OBJECT_NUCLEAR ||
- list[i].type == OBJECT_START ||
- list[i].type == OBJECT_END ||
- list[i].type == OBJECT_INFO ||
- list[i].type == OBJECT_PARA ||
- list[i].type == OBJECT_TARGET1 ||
- list[i].type == OBJECT_TARGET2 ||
- list[i].type == OBJECT_SAFE ||
- list[i].type == OBJECT_HUSTON )
- {
- ObjectWrite(file, list, i);
- bAtLeast = true;
- }
- }
- if ( !bAtLeast )
- {
- GetResource(RES_TEXT, RT_SATCOM_NULL, line);
- fputs(line.c_str(), file);
- }
-
- fputs("\n", file);
- GetResource(RES_TEXT, RT_SATCOM_FRET, line);
- fputs(line.c_str(), file);
- bAtLeast = false;
- for ( i=0 ; i<200 ; i++ )
- {
- if ( list[i].total == 0 ) break; // end of the list?
-
- if ( list[i].type == OBJECT_STONE ||
- list[i].type == OBJECT_URANIUM ||
- list[i].type == OBJECT_METAL ||
- list[i].type == OBJECT_POWER ||
- list[i].type == OBJECT_ATOMIC ||
- list[i].type == OBJECT_BULLET ||
- list[i].type == OBJECT_BBOX ||
- list[i].type == OBJECT_TNT )
- {
- ObjectWrite(file, list, i);
- bAtLeast = true;
- }
- }
- if ( !bAtLeast )
- {
- GetResource(RES_TEXT, RT_SATCOM_NULL, line);
- fputs(line.c_str(), file);
- }
-
- fputs("\n", file);
- GetResource(RES_TEXT, RT_SATCOM_ALIEN, line);
- fputs(line.c_str(), file);
- bAtLeast = false;
- for ( i=0 ; i<200 ; i++ )
- {
- if ( list[i].total == 0 ) break; // end of the list?
-
- if ( list[i].type == OBJECT_MOTHER ||
- list[i].type == OBJECT_ANT ||
- list[i].type == OBJECT_BEE ||
- list[i].type == OBJECT_WORM ||
- list[i].type == OBJECT_SPIDER )
- {
- ObjectWrite(file, list, i);
- bAtLeast = true;
- }
- }
- if ( !bAtLeast )
- {
- GetResource(RES_TEXT, RT_SATCOM_NULL, line);
- fputs(line.c_str(), file);
- }
- }
- else
- {
- GetResource(RES_TEXT, RT_SATCOM_ERROR1, line);
- fputs(line.c_str(), file);
- GetResource(RES_TEXT, RT_SATCOM_ERROR2, line);
- fputs(line.c_str(), file);
- }
-
- fputs("\n", file);
-
- fclose(file);
-}
-
-
}
-
diff --git a/src/ui/displayinfo.h b/src/ui/displayinfo.h
index 47bdec9..f820cd6 100644
--- a/src/ui/displayinfo.h
+++ b/src/ui/displayinfo.h
@@ -68,7 +68,6 @@ protected:
void UpdateCopyButton();
void ViewDisplayInfo();
CObject* SearchToto();
- void CreateObjectsFile();
protected:
Gfx::CEngine* m_engine;
diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp
index 36bfd5a..b6e6bbf 100644
--- a/src/ui/edit.cpp
+++ b/src/ui/edit.cpp
@@ -21,11 +21,18 @@
#include "ui/edit.h"
#include "app/app.h"
-#include "app/gamedata.h"
#include "clipboard/clipboard.h"
+#include "object/robotmain.h"
+
+#include "object/level/parserparam.h"
+
+#include "common/resources/inputstream.h"
+#include "common/resources/outputstream.h"
+
#include <string.h>
+#include <boost/algorithm/string.hpp>
namespace Ui {
@@ -779,16 +786,9 @@ void CEdit::HyperJump(std::string name, std::string marker)
sMarker = marker;
-//? sprintf(filename, "help\\%s.txt", name);
-
- if ( name[0] == '%' )
- {
- filename = GetProfile().GetUserBasedPath(name, "") + ".txt";
- }
- else
- {
- filename = std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + "/" + name + std::string(".txt");
- }
+ filename = name + std::string(".txt");
+ filename = CLevelParserParam::InjectLevelDir(filename, "help/%lng%");
+ boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
if ( ReadText(filename) )
{
@@ -1142,7 +1142,9 @@ void CEdit::DrawImage(Math::Point pos, std::string name, float width,
float dp;
std::string filename;
- filename = GetProfile().GetUserBasedPath(name, "../icons") + ".png";
+ filename = name + ".png";
+ filename = CLevelParserParam::InjectLevelDir(filename, "icons");
+ boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
m_engine->SetTexture(filename);
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
@@ -1172,7 +1174,7 @@ void CEdit::DrawBack(Math::Point pos, Math::Point dim)
if ( m_bGeneric ) return;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
if ( m_bMulti )
@@ -1222,7 +1224,7 @@ void CEdit::DrawPart(Math::Point pos, Math::Point dim, int icon)
Math::Point uv1, uv2;
float dp;
- m_engine->SetTexture("text.png");
+ m_engine->SetTexture("textures/interface/text.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = (16.0f/256.0f)*(icon%16);
@@ -1420,7 +1422,7 @@ void CEdit::FreeImage()
for (int i = 0 ; i < m_imageTotal; i++ )
{
- filename = GetProfile().GetUserBasedPath(m_image[i].name, "../icons") + ".png";
+ filename = m_image[i].name + ".png";
m_engine->DeleteTexture(filename);
}
}
@@ -1430,7 +1432,9 @@ void CEdit::FreeImage()
void CEdit::LoadImage(std::string name)
{
std::string filename;
- filename = GetProfile().GetUserBasedPath(name, "../icons") + ".png";
+ filename = name + ".png";
+ filename = CLevelParserParam::InjectLevelDir(filename, "icons");
+ boost::replace_all(filename, "\\", "/"); //TODO: Fix this in files
m_engine->LoadTexture(filename);
}
@@ -1438,7 +1442,6 @@ void CEdit::LoadImage(std::string name)
bool CEdit::ReadText(std::string filename, int addSize)
{
- FILE *file = NULL;
char *buffer;
int len, i, j, n, font, iIndex, iLines, iCount, iLink, res;
char iName[50];
@@ -1447,27 +1450,18 @@ bool CEdit::ReadText(std::string filename, int addSize)
InputSlot slot;
bool bInSoluce, bBOL;
- if ( filename[0] == 0 ) return false;
-
- boost::replace_all(filename, "\\", "/");
-
- /* This is ugly but doesn't require many changes in code. If file doesn't
- exists it's posible filename is absolute not full path */
- std::string path = filename;
- if (!fs::exists(path))
+ if ( filename == "" ) return false;
+
+ CInputStream stream;
+ stream.open(filename);
+
+ if (!stream.is_open())
{
- path = CGameData::GetInstancePointer()->GetDataPath(filename);
- }
-
- file = fopen(fs::path(path).make_preferred().string().c_str(), "rb");
- if ( file == NULL ) {
- CLogger::GetInstancePointer()->Error("Unable to read text from file \"%s\"\n", path.c_str());
+ CLogger::GetInstancePointer()->Error("Failed to load text file %s\n", filename.c_str());
return false;
}
- fseek(file, 0, SEEK_END);
- len = ftell(file);
- fseek(file, 0, SEEK_SET);
+ len = stream.size();
m_maxChar = len+addSize+100;
m_len = len;
@@ -1484,7 +1478,7 @@ bool CEdit::ReadText(std::string filename, int addSize)
buffer = new char[m_maxChar+1];
memset(buffer, 0, m_maxChar+1);
- fread(buffer, 1, len, file);
+ stream.read(buffer, len);
m_format.clear();
m_format.reserve(m_maxChar+1);
@@ -1493,7 +1487,7 @@ bool CEdit::ReadText(std::string filename, int addSize)
m_format.push_back(0);
}
- fclose(file);
+ stream.close();
bInSoluce = false;
font = m_fontType;
@@ -1887,14 +1881,19 @@ bool CEdit::ReadText(std::string filename, int addSize)
bool CEdit::WriteText(std::string filename)
{
- FILE* file;
char buffer[1000+20];
int i, j, k, n;
float iDim = 0.0f;
if ( filename[0] == 0 ) return false;
- file = fopen(filename.c_str(), "wb");
- if ( file == NULL ) return false;
+
+ COutputStream stream;
+ stream.open(filename);
+
+ if (!stream.is_open())
+ {
+ return false;
+ }
if ( m_bAutoIndent )
{
@@ -1925,7 +1924,7 @@ bool CEdit::WriteText(std::string filename)
if ( j >= 1000-1 )
{
- fwrite(buffer, 1, j, file);
+ stream.write(buffer, j);
j = 0;
}
@@ -1933,10 +1932,10 @@ bool CEdit::WriteText(std::string filename)
}
if ( j > 0 )
{
- fwrite(buffer, 1, j, file);
+ stream.write(buffer, j);
}
- fclose(file);
+ stream.close();
if ( m_bAutoIndent )
{
diff --git a/src/ui/gauge.cpp b/src/ui/gauge.cpp
index 4bc9d7d..92f4d7c 100644
--- a/src/ui/gauge.cpp
+++ b/src/ui/gauge.cpp
@@ -77,7 +77,7 @@ void CGauge::Draw()
if ( (m_state & STATE_VISIBLE) == 0 ) return;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
dp = 0.5f/256.0f;
diff --git a/src/ui/group.cpp b/src/ui/group.cpp
index 6ca6067..e924ea6 100644
--- a/src/ui/group.cpp
+++ b/src/ui/group.cpp
@@ -90,7 +90,7 @@ void CGroup::Draw()
if ( m_icon == 0 ) // hollow frame?
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 160.0f / 256.0f;
uv1.y = 192.0f / 256.0f; // u-v texture
@@ -106,7 +106,7 @@ void CGroup::Draw()
}
if ( m_icon == 1 ) // orange solid opaque?
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 104.0f / 256.0f;
uv1.y = 48.0f / 256.0f;
@@ -120,7 +120,7 @@ void CGroup::Draw()
}
if ( m_icon == 2 ) // orange degrade -> transparent?
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 112.0f / 256.0f;
uv1.y = 48.0f / 256.0f;
@@ -134,7 +134,7 @@ void CGroup::Draw()
}
if ( m_icon == 3 ) // transparent gradient -> gray?
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 120.0f / 256.0f;
uv1.y = 48.0f / 256.0f;
@@ -148,7 +148,7 @@ void CGroup::Draw()
}
if ( m_icon == 4 ) // degrade blue corner?
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 192.0f / 256.0f;
uv1.y = 128.0f / 256.0f;
@@ -162,7 +162,7 @@ void CGroup::Draw()
}
if ( m_icon == 5 ) // degrade orange corner?
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 224.0f / 256.0f;
uv1.y = 128.0f / 256.0f;
@@ -176,7 +176,7 @@ void CGroup::Draw()
}
if ( m_icon == 6 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 0.0f / 256.0f; // brown transparent
uv1.y = 75.0f / 256.0f;
@@ -192,7 +192,7 @@ void CGroup::Draw()
}
if ( m_icon == 7 )
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f;
uv1.y = 0.0f / 256.0f;
@@ -206,7 +206,7 @@ void CGroup::Draw()
}
if ( m_icon == 8 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f / 256.0f; // green transparent
uv1.y = 160.0f / 256.0f;
@@ -220,7 +220,7 @@ void CGroup::Draw()
}
if ( m_icon == 9 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f / 256.0f; // red transparent
uv1.y = 176.0f/256.0f;
@@ -234,7 +234,7 @@ void CGroup::Draw()
}
if ( m_icon == 10 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f / 256.0f; // blue transparent
uv1.y = 192.0f / 256.0f;
@@ -248,7 +248,7 @@ void CGroup::Draw()
}
if ( m_icon == 11 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f / 256.0f; // yellow transparent
uv1.y = 224.0f / 256.0f;
@@ -265,7 +265,7 @@ void CGroup::Draw()
dim.x = m_dim.x / 2.0f;
dim.y = m_dim.y / 2.0f;
- m_engine->SetTexture("mouse.png");
+ m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/300.0f;
pos.y = m_pos.y+m_dim.y/300.0f+dim.y;
@@ -304,7 +304,7 @@ void CGroup::Draw()
}
if ( m_icon == 13 ) // corner upper / left?
{
- m_engine->SetTexture("mouse.png");
+ m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f;
@@ -325,7 +325,7 @@ void CGroup::Draw()
}
if ( m_icon == 14 ) // corner upper / right?
{
- m_engine->SetTexture("mouse.png");
+ m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f;
@@ -346,7 +346,7 @@ void CGroup::Draw()
}
if ( m_icon == 15 ) // corner lower / left?
{
- m_engine->SetTexture("mouse.png");
+ m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f;
@@ -367,7 +367,7 @@ void CGroup::Draw()
}
if ( m_icon == 16 ) // corner lower / left?
{
- m_engine->SetTexture("mouse.png");
+ m_engine->SetTexture("textures/interface/mouse.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
pos.x = m_pos.x-m_dim.x/150.0f;
pos.y = m_pos.y+m_dim.y/150.0f;
@@ -388,7 +388,7 @@ void CGroup::Draw()
}
if ( m_icon == 17 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f / 256.0f; // blue frame
uv1.y = 75.0f / 256.0f;
@@ -404,7 +404,7 @@ void CGroup::Draw()
}
if ( m_icon == 18 ) // arrow> for SatCom?
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 0.0f / 256.0f; // >
uv1.y = 192.0f / 256.0f;
@@ -418,7 +418,7 @@ void CGroup::Draw()
}
if ( m_icon == 19 ) // SatCom symbol?
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 224.0f / 256.0f; // SatCom symbol
uv1.y = 224.0f / 256.0f;
@@ -432,7 +432,7 @@ void CGroup::Draw()
}
if ( m_icon == 20 ) // solid blue background?
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 224.0f / 256.0f;
uv1.y = 32.0f / 256.0f;
@@ -446,7 +446,7 @@ void CGroup::Draw()
}
if ( m_icon == 21 ) // stand-by symbol?
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 160.0f / 256.0f;
uv1.y = 32.0f / 256.0f;
@@ -460,7 +460,7 @@ void CGroup::Draw()
}
if ( m_icon == 22 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f; // opaque yellow
uv1.y = 224.0f / 256.0f;
@@ -477,7 +477,7 @@ void CGroup::Draw()
if ( m_icon == 23 )
{
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f; // yellow
uv1.y = 192.0f / 256.0f;
@@ -493,7 +493,7 @@ void CGroup::Draw()
}
if ( m_icon == 24 )
{
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 80.0f / 256.0f; // orange
uv1.y = 192.0f / 256.0f;
@@ -509,7 +509,7 @@ void CGroup::Draw()
}
if ( m_icon == 25 )
{
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f; // orange
uv1.y = 208.0f / 256.0f;
@@ -525,7 +525,7 @@ void CGroup::Draw()
}
if ( m_icon == 26 )
{
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 80.0f / 256.0f; // red
uv1.y = 208.0f / 256.0f;
@@ -541,7 +541,7 @@ void CGroup::Draw()
}
if ( m_icon == 27 )
{
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 32.0f / 256.0f;
uv1.y = 0.0f / 256.0f;
@@ -559,7 +559,7 @@ void CGroup::Draw()
pos = m_pos;
dim = m_dim;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 32.0f / 256.0f;
uv1.y = 32.0f / 256.0f;
@@ -571,7 +571,7 @@ void CGroup::Draw()
uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2);
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
pos.x += 8.0f / 640.0f;
pos.y += 8.0f / 480.0f;
diff --git a/src/ui/image.cpp b/src/ui/image.cpp
index b4c19f8..89e1fd2 100644
--- a/src/ui/image.cpp
+++ b/src/ui/image.cpp
@@ -112,7 +112,7 @@ void CImage::Draw()
if ( m_icon == 0 ) // hollow frame?
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 160.0f / 256.0f;
uv1.y = 192.0f / 256.0f; // u-v texture
@@ -129,8 +129,10 @@ void CImage::Draw()
if ( m_filename[0] != 0 ) // displays an image?
{
- m_engine->LoadTexture(m_filename);
- m_engine->SetTexture(m_filename);
+ std::string texFilename = m_filename;
+ texFilename = "textures/"+texFilename;
+ m_engine->LoadTexture(texFilename.c_str());
+ m_engine->SetTexture(texFilename);
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
pos = m_pos;
dim = m_dim;
diff --git a/src/ui/key.cpp b/src/ui/key.cpp
index ecc000c..fd9a77f 100644
--- a/src/ui/key.cpp
+++ b/src/ui/key.cpp
@@ -138,7 +138,7 @@ void CKey::Draw()
DrawShadow(m_pos, m_dim);
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); // was D3DSTATENORMAL
float zoomExt = 1.00f;
diff --git a/src/ui/list.cpp b/src/ui/list.cpp
index 16f0457..9611533 100644
--- a/src/ui/list.cpp
+++ b/src/ui/list.cpp
@@ -388,7 +388,7 @@ void CList::Draw()
if (m_icon == 0)
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f / 256.0f;
@@ -398,7 +398,7 @@ void CList::Draw()
}
else
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 132.0f / 256.0f;
@@ -434,7 +434,7 @@ void CList::Draw()
dim.y *= 0.4f;
pos.y -= dim.y;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw
uv1.x = 120.0f / 256.0f;
uv1.y = 64.0f / 256.0f;
@@ -509,7 +509,7 @@ void CList::Draw()
if ( m_check[i + m_firstLine] )
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f;
uv1.y = 0.0f / 256.0f;
@@ -534,7 +534,7 @@ void CList::Draw()
}
else
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw
if ( i + m_firstLine == m_selectLine )
{
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index c0656a6..dec4586 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -21,7 +21,6 @@
#include "ui/maindialog.h"
#include "app/app.h"
-#include "app/gamedata.h"
#include "app/system.h"
#include "common/config.h"
@@ -33,6 +32,12 @@
#include "common/restext.h"
#include "common/stringutils.h"
+#include "common/resources/resourcemanager.h"
+#include "common/resources/inputstream.h"
+#include "common/resources/outputstream.h"
+
+#include "object/level/parser.h"
+
#include "object/robotmain.h"
#include "script/cmdtoken.h"
@@ -176,17 +181,8 @@ CMainDialog::CMainDialog()
m_partiTime[i] = 0.0f;
}
-
- m_sceneDir = "levels";
-
- #if DEV_BUILD
m_savegameDir = "savegame";
- #else
- m_savegameDir = GetSystemUtils()->GetSavegameDirectoryLocation();
- #endif
-
m_publicDir = "program";
- m_userDir = "user";
m_filesDir = m_savegameDir;
m_setupFull = m_app->GetVideoConfig().fullScreen;
@@ -318,7 +314,6 @@ void CMainDialog::ChangePhase(Phase phase)
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_QUIT);
pb->SetState(STATE_SHADOW);
- #if DEV_BUILD
if ( m_accessEnable && m_accessUser )
{
pos.x = 447.0f/640.0f;
@@ -327,7 +322,6 @@ void CMainDialog::ChangePhase(Phase phase)
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_USER);
pb->SetState(STATE_SHADOW);
}
- #endif
/*pos.x = 139.0f/640.0f;
pos.y = 313.0f/480.0f;
@@ -346,7 +340,7 @@ void CMainDialog::ChangePhase(Phase phase)
pl->SetFontType(Gfx::FONT_COURIER);
pl->SetFontSize(Gfx::FONT_SIZE_SMALL);
- m_engine->SetBackground("interface.png",
+ m_engine->SetBackground("interface/interface.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -453,7 +447,7 @@ void CMainDialog::ChangePhase(Phase phase)
UpdateNameControl();
UpdateNameFace();
- m_engine->SetBackground("interface.png",
+ m_engine->SetBackground("interface/interface.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -716,16 +710,16 @@ void CMainDialog::ChangePhase(Phase phase)
if ( m_phase == PHASE_FREE )
{
- strcpy(m_sceneName, "scene");
+ strcpy(m_sceneName, "missions");
ReadGamerInfo();
m_accessChap = GetChapPassed();
}
- if ( m_phase == PHASE_TRAINER ) strcpy(m_sceneName, "train");
- if ( m_phase == PHASE_DEFI ) strcpy(m_sceneName, "defi" );
- if ( m_phase == PHASE_MISSION ) strcpy(m_sceneName, "scene");
- if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "free");
- if ( m_phase == PHASE_USER ) strcpy(m_sceneName, "user");
+ if ( m_phase == PHASE_TRAINER ) strcpy(m_sceneName, "exercises");
+ if ( m_phase == PHASE_DEFI ) strcpy(m_sceneName, "challenges" );
+ if ( m_phase == PHASE_MISSION ) strcpy(m_sceneName, "missions");
+ if ( m_phase == PHASE_FREE ) strcpy(m_sceneName, "freemissions");
+ if ( m_phase == PHASE_USER ) strcpy(m_sceneName, "custom");
ReadGamerInfo();
@@ -878,7 +872,7 @@ void CMainDialog::ChangePhase(Phase phase)
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_BACK);
pb->SetState(STATE_SHADOW);
- m_engine->SetBackground("interface.png",
+ m_engine->SetBackground("interface/interface.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -1003,7 +997,7 @@ void CMainDialog::ChangePhase(Phase phase)
if ( !m_bSimulSetup )
{
- m_engine->SetBackground("interface.png",
+ m_engine->SetBackground("interface/interface.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -1492,7 +1486,7 @@ void CMainDialog::ChangePhase(Phase phase)
if ( m_phase == PHASE_READ )
{
- m_engine->SetBackground("interface.png",
+ m_engine->SetBackground("interface/interface.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -1539,7 +1533,7 @@ void CMainDialog::ChangePhase(Phase phase)
pl->SetFontSize(12.0f);
pl->SetTextAlign(Gfx::TEXT_ALIGN_CENTER);
- m_engine->SetBackground("interface.png",
+ m_engine->SetBackground("interface/interface.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -1561,7 +1555,7 @@ void CMainDialog::ChangePhase(Phase phase)
m_engine->SetOverColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f), Gfx::ENG_RSTATE_TCOLOR_BLACK); // TODO: color ok?
m_engine->SetOverFront(true);
- m_engine->SetBackground("ppc.png",
+ m_engine->SetBackground("interface/ppc.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -1580,7 +1574,7 @@ void CMainDialog::ChangePhase(Phase phase)
m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); // TODO: color ok?
m_engine->SetOverFront(true);
- m_engine->SetBackground("colobot.png",
+ m_engine->SetBackground("interface/colobot.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -1599,7 +1593,7 @@ void CMainDialog::ChangePhase(Phase phase)
m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); // TODO: color ok?
m_engine->SetOverFront(true);
- m_engine->SetBackground("epsitec.png",
+ m_engine->SetBackground("interface/epsitec.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -1665,7 +1659,7 @@ void CMainDialog::ChangePhase(Phase phase)
pb = pw->CreateButton(pos, ddim, 49, EVENT_INTERFACE_ABORT);
pb->SetState(STATE_SHADOW);
- m_engine->SetBackground("generico.png",
+ m_engine->SetBackground("interface/generico.png",
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
@@ -3271,40 +3265,15 @@ void CMainDialog::NiceParticle(Math::Point mouse, bool bPress)
-// Specifies the special user folder if needed.
-
-void CMainDialog::SetUserDir(char *base, int rank)
-{
- std::string dir;
-
- if ( strcmp(base, "user") == 0 && rank >= 100 )
- {
- dir = m_userDir + "/" + m_userList.at(rank/100-1);
- GetProfile().SetUserDir(dir);
- }
- else
- {
- GetProfile().SetUserDir("");
- }
-}
-
// Builds the file name of a mission.
-void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank)
+void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile)
{
- std::ostringstream rankStream;
- if ( strcmp(base, "user") == 0 )
- {
- //TODO: Change this to point user dir according to operating system
- rankStream << std::setfill('0') << std::setw(2) << rank%100;
- filename = m_userDir + "/" + m_userList[rank/100-1] + "/" + rankStream.str() + ".txt";
- }
- else
- {
- rankStream << std::setfill('0') << std::setw(3) << rank;
- filename = base + rankStream.str() + ".txt";
- filename = CGameData::GetInstancePointer()->GetFilePath(DIR_LEVEL, filename);
- }
+ //TODO: Support for more than 9 chapters
+ int chapter = rank/100;
+ int new_rank = rank%100;
+
+ filename = CLevelParser::BuildSceneName(std::string(base), chapter, new_rank, sceneFile);
}
// Built the default descriptive name of a mission.
@@ -3556,7 +3525,7 @@ void CMainDialog::NameCreate()
char c;
int len, i, j;
- GetLogger()->Debug("Creating new player\n");
+ GetLogger()->Info("Creating new player\n");
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
@@ -3593,13 +3562,16 @@ void CMainDialog::NameCreate()
return;
}
- // TODO: _mkdir(m_savegameDir); // if does not exist yet!
-
+ if(!CResourceManager::DirectoryExists(m_savegameDir))
+ CResourceManager::CreateDirectory(m_savegameDir);
+
dir = m_savegameDir + "/" + name;
if (!fs::exists(dir))
{
fs::create_directories(dir);
+ if(!CResourceManager::DirectoryExists(dir))
+ CResourceManager::CreateDirectory(dir);
}
else
{
@@ -3998,7 +3970,6 @@ bool CMainDialog::IsIOReadScene()
void CMainDialog::IOReadName()
{
- FILE* file;
CWindow* pw;
CEdit* pe;
std::string filename;
@@ -4020,10 +3991,12 @@ void CMainDialog::IOReadName()
sprintf(op, "Title.E");
sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar() );
- file = fopen(filename.c_str(), "r");
- if ( file != NULL )
+ CInputStream stream;
+ stream.open(filename);
+
+ if (stream.is_open())
{
- while ( fgets(line, 500, file) != NULL )
+ while (stream.getline(line, 500))
{
for ( i=0 ; i<500 ; i++ )
{
@@ -4045,7 +4018,7 @@ void CMainDialog::IOReadName()
break;
}
}
- fclose(file);
+ stream.close();
}
time(&now);
@@ -4390,10 +4363,9 @@ void CMainDialog::AllMissionUpdate()
void CMainDialog::UpdateSceneChap(int &chap)
{
- FILE* file = NULL;
CWindow* pw;
CList* pl;
- //struct _finddata_t fileBuffer;
+
std::string fileName;
char op[100];
char op_i18n[100];
@@ -4417,60 +4389,25 @@ void CMainDialog::UpdateSceneChap(int &chap)
if ( m_phase == PHASE_USER )
{
j = 0;
- fs::directory_iterator dirIt(m_savegameDir), dirEndIt;
- m_userList.clear();
-
- for (; dirIt != dirEndIt; ++dirIt)
- {
- const fs::path& p = *dirIt;
- if (fs::is_directory(p))
- {
- m_userList.push_back(p.leaf().string());
- }
- }
+ auto userLevelDirs = CResourceManager::ListDirectories("levels/custom/");
+ std::sort(userLevelDirs.begin(), userLevelDirs.end());
+ m_userList = userLevelDirs;
m_userTotal = m_userList.size();
for ( j=0 ; j<m_userTotal ; j++ )
{
- BuildSceneName(fileName, m_sceneName, (j+1)*100);
- file = fopen(fileName.c_str(), "r");
- if ( file == NULL )
- {
- strcpy(name, m_userList[j].c_str());
+ try {
+ CLevelParser* level = new CLevelParser("custom", j+1, 0);
+ level->Load();
+ pl->SetItemName(j, level->Get("Title")->GetParam("text")->AsString().c_str());
+ pl->SetEnable(j, true);
+ delete level;
}
- else
+ catch(CLevelParserException& e)
{
- BuildResumeName(name, m_sceneName, j+1); // default name
- sprintf(op, "Title.E");
- sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar());
-
- while ( fgets(line, 500, file) != NULL )
- {
- for ( i=0 ; i<500 ; i++ )
- {
- if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space
- if ( line[i] == '/' && line[i+1] == '/' )
- {
- line[i] = 0;
- break;
- }
- }
-
- if ( Cmd(line, op) )
- {
- OpString(line, "text", name);
- }
- if ( Cmd(line, op_i18n) )
- {
- OpString(line, "text", name);
- break;
- }
- }
- fclose(file);
+ pl->SetItemName(j, (std::string("[ERROR]: ")+e.what()).c_str());
+ pl->SetEnable(j, false);
}
-
- pl->SetItemName(j, name);
- pl->SetEnable(j, true);
}
}
else
@@ -4478,14 +4415,15 @@ void CMainDialog::UpdateSceneChap(int &chap)
for ( j=0 ; j<9 ; j++ )
{
BuildSceneName(fileName, m_sceneName, (j+1)*100);
- file = fopen(fileName.c_str(), "r");
- if ( file == NULL ) break;
+ CInputStream stream;
+ stream.open(fileName);
+ if (!stream.is_open()) break;
BuildResumeName(name, m_sceneName, j+1); // default name
sprintf(op, "Title.E");
sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar());
- while ( fgets(line, 500, file) != NULL )
+ while (stream.getline(line, 500))
{
for ( i=0 ; i<500 ; i++ )
{
@@ -4507,7 +4445,7 @@ void CMainDialog::UpdateSceneChap(int &chap)
break;
}
}
- fclose(file);
+ stream.close();
bPassed = GetGamerInfoPassed((j+1)*100);
sprintf(line, "%d: %s", j+1, name);
@@ -4539,7 +4477,6 @@ void CMainDialog::UpdateSceneChap(int &chap)
void CMainDialog::UpdateSceneList(int chap, int &sel)
{
- FILE* file = NULL;
CWindow* pw;
CList* pl;
std::string fileName;
@@ -4561,18 +4498,22 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
if ( pl == 0 ) return;
pl->Flush();
+
+ if(chap < 0) return;
for ( j=0 ; j<99 ; j++ )
{
BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1));
- file = fopen(fileName.c_str(), "r");
- if ( file == NULL ) break;
+
+ CInputStream stream;
+ stream.open(fileName);
+ if (!stream.is_open()) break;
BuildResumeName(name, m_sceneName, j+1); // default name
sprintf(op, "Title.E");
sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar());
- while ( fgets(line, 500, file) != NULL )
+ while (stream.getline(line, 500))
{
for ( i=0 ; i<500 ; i++ )
{
@@ -4594,7 +4535,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
break;
}
}
- fclose(file);
+ stream.close();
bPassed = GetGamerInfoPassed((chap+1)*100+(j+1));
sprintf(line, "%d: %s", j+1, name);
@@ -4609,6 +4550,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
}
}
+ /* TODO: ?????
BuildSceneName(fileName, m_sceneName, (chap+1)*100+(j+1));
file = fopen(fileName.c_str(), "r");
if ( file == NULL )
@@ -4619,7 +4561,8 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
{
m_maxList = j+1; // this is not the last!
fclose(file);
- }
+ }*/
+ m_maxList = j;
if ( sel > j-1 ) sel = j-1;
@@ -4669,16 +4612,11 @@ void CMainDialog::ShowSoluceUpdate()
void CMainDialog::UpdateSceneResume(int rank)
{
- FILE* file = NULL;
CWindow* pw;
CEdit* pe;
CCheck* pc;
std::string fileName;
- char op[100];
- char op_i18n[100];
- char line[500];
- char name[500];
- int i, numTry;
+ int numTry;
bool bPassed, bVisible;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
@@ -4704,43 +4642,18 @@ void CMainDialog::UpdateSceneResume(int rank)
m_bSceneSoluce = false;
}
}
-
- BuildSceneName(fileName, m_sceneName, rank);
- sprintf(op, "Resume.E");
- sprintf(op_i18n, "Resume.%c", m_app->GetLanguageChar());
-
- file = fopen(fileName.c_str(), "r");
- if ( file == NULL ) return;
-
- name[0] = 0;
- while ( fgets(line, 500, file) != NULL )
+
+ if(rank<100) return;
+
+ try {
+ CLevelParser* level = new CLevelParser(m_sceneName, rank/100, rank%100);
+ level->Load();
+ pe->SetText(level->Get("Resume")->GetParam("text")->AsString().c_str());
+ }
+ catch(CLevelParserException& e)
{
- for ( i=0 ; i<500 ; i++ )
- {
- if (line[i] == 0)
- break;
-
- if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space
- if ( line[i] == '/' && line[i+1] == '/' )
- {
- line[i] = 0;
- break;
- }
- }
-
- if ( Cmd(line, op) )
- {
- OpString(line, "text", name);
- }
- if ( Cmd(line, op_i18n) )
- {
- OpString(line, "text", name);
- break;
- }
+ pe->SetText((std::string("[ERROR]: ")+e.what()).c_str());
}
- fclose(file);
-
- pe->SetText(name);
}
// Updates the list of modes.
@@ -5121,10 +5034,8 @@ void CMainDialog::ChangeSetupButtons()
void CMainDialog::SetupMemorize()
{
- GetProfile().SetStringProperty("Directory", "scene", m_sceneDir);
GetProfile().SetStringProperty("Directory", "savegame", m_savegameDir);
GetProfile().SetStringProperty("Directory", "public", m_publicDir);
- GetProfile().SetStringProperty("Directory", "user", m_userDir);
GetProfile().SetStringProperty("Directory", "files", m_filesDir);
GetProfile().SetIntProperty("Setup", "Tooltips", m_bTooltip);
GetProfile().SetIntProperty("Setup", "InterfaceGlint", m_bGlint);
@@ -5200,11 +5111,6 @@ void CMainDialog::SetupRecall()
int iValue;
std::string key;
- if ( GetProfile().GetStringProperty("Directory", "scene", key) )
- {
- m_sceneDir = key;
- }
-
if ( GetProfile().GetStringProperty("Directory", "savegame", key) )
{
m_savegameDir = key;
@@ -5215,11 +5121,6 @@ void CMainDialog::SetupRecall()
m_publicDir = key;
}
- if ( GetProfile().GetStringProperty("Directory", "user", key) )
- {
- m_userDir = key;
- }
-
if ( GetProfile().GetStringProperty("Directory", "files", key) )
{
m_filesDir = key;
@@ -5944,7 +5845,6 @@ void CMainDialog::FrameDialog(float rTime)
void CMainDialog::StopDialog()
{
CWindow* pw;
- CButton* pb;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw != 0 ) pw->SetState(STATE_ENABLE);
@@ -6414,6 +6314,11 @@ bool CMainDialog::NextMission()
return true;
}
+std::string& CMainDialog::GetUserLevelName(int id)
+{
+ return m_userList[id-1];
+}
+
} // namespace Ui
diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h
index 0cf8db4..390aa31 100644
--- a/src/ui/maindialog.h
+++ b/src/ui/maindialog.h
@@ -101,8 +101,7 @@ public:
bool GetNiceReset();
bool GetHimselfDamage();
- void SetUserDir(char *base, int rank);
- void BuildSceneName(std::string &filename, char *base, int rank);
+ void BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile = true);
void BuildResumeName(char *filename, char *base, int rank);
std::string & GetFilesDir();
@@ -143,6 +142,8 @@ public:
void AllMissionUpdate();
void ShowSoluceUpdate();
+
+ std::string& GetUserLevelName(int id);
protected:
void GlintMove();
@@ -202,10 +203,8 @@ protected:
int m_persoTab; // perso: tab selected
float m_persoAngle; // perso: angle of presentation
- std::string m_sceneDir; // scene folder
std::string m_savegameDir; // savegame folder
std::string m_publicDir; // program folder
- std::string m_userDir; // user folder
std::string m_filesDir; // case files
int m_index; // 0..4
diff --git a/src/ui/map.cpp b/src/ui/map.cpp
index 89c3397..f3f569a 100644
--- a/src/ui/map.cpp
+++ b/src/ui/map.cpp
@@ -324,7 +324,7 @@ void CMap::Draw()
m_offset = AdjustOffset(m_map[MAPMAXOBJECT - 1].pos);
if ( m_fixImage[0] == 0 ) { // drawing of the relief?
- m_engine->SetTexture("map.png");
+ m_engine->SetTexture("textures/interface/map.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.5f + (m_offset.x - (m_half / m_zoom)) / (m_half * 2.0f);
uv1.y = 0.5f - (m_offset.y + (m_half / m_zoom)) / (m_half * 2.0f);
@@ -332,8 +332,10 @@ void CMap::Draw()
uv2.y = 0.5f - (m_offset.y - (m_half / m_zoom)) / (m_half * 2.0f);
DrawVertex(uv1, uv2, 0.97f); // drawing the map
} else { // still image?
- m_engine->LoadTexture(m_fixImage);
- m_engine->SetTexture(m_fixImage);
+ std::string texFilename = m_fixImage;
+ texFilename = "textures/"+texFilename;
+ m_engine->LoadTexture(texFilename.c_str());
+ m_engine->SetTexture(texFilename.c_str());
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f;
uv1.y = 0.0f;
@@ -471,7 +473,7 @@ void CMap::DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color
uv2.x = 126.0f/256.0f;
uv2.y = 255.0f/256.0f;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
bEnding = false;
@@ -531,7 +533,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
return; // flashes
}
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
if ( bUp )
{
@@ -674,7 +676,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
{
if ( bSelect )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
if ( m_bToy )
{
@@ -700,7 +702,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
{
if ( m_bRadar )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 64.5f/256.0f; // blue triangle
uv1.y = 240.5f/256.0f;
@@ -720,7 +722,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
if ( color == MAPCOLOR_WAYPOINTb )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 192.5f/256.0f; // blue cross
uv1.y = 240.5f/256.0f;
@@ -730,7 +732,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
}
if ( color == MAPCOLOR_WAYPOINTr )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 208.5f/256.0f; // red cross
uv1.y = 240.5f/256.0f;
@@ -740,7 +742,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
}
if ( color == MAPCOLOR_WAYPOINTg )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 224.5f/256.0f; // green cross
uv1.y = 240.5f/256.0f;
@@ -750,7 +752,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
}
if ( color == MAPCOLOR_WAYPOINTy )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 240.5f/256.0f; // yellow cross
uv1.y = 240.5f/256.0f;
@@ -760,7 +762,7 @@ void CMap::DrawObject(Math::Point pos, float dir, ObjectType type, MapColor colo
}
if ( color == MAPCOLOR_WAYPOINTv )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 192.5f/256.0f; // violet cross
uv1.y = 224.5f/256.0f;
@@ -781,7 +783,7 @@ void CMap::DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color,
dp = 0.5f/256.0f;
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
if ( color == MAPCOLOR_MOVE )
{
@@ -896,7 +898,7 @@ void CMap::DrawHighlight(Math::Point pos)
dim.x *= 2.0f+cosf(m_time*8.0f)*0.5f;
dim.y *= 2.0f+cosf(m_time*8.0f)*0.5f;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 160.5f/256.0f; // hilite
uv1.y = 224.5f/256.0f;
@@ -1054,8 +1056,8 @@ void CMap::UpdateTerrain()
}
}
- m_engine->DeleteTexture("map.png");
- m_engine->LoadTexture("map.png", &img);
+ m_engine->DeleteTexture("interface/map.png");
+ m_engine->LoadTexture("textures/interface/map.png", &img);
}
// Updates the field in the map.
diff --git a/src/ui/scroll.cpp b/src/ui/scroll.cpp
index de2f26b..32c5818 100644
--- a/src/ui/scroll.cpp
+++ b/src/ui/scroll.cpp
@@ -381,7 +381,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon)
if ( icon == 0 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f/256.0f; // yellow rectangle
uv1.y = 32.0f/256.0f;
@@ -391,7 +391,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 1 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // gray rectangle
uv1.y = 32.0f/256.0f;
@@ -401,7 +401,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 2 )
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f/256.0f; // blue rectangle
uv1.y = 0.0f/256.0f;
@@ -411,7 +411,7 @@ void CScroll::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 104.0f/256.0f; // blue line -
uv1.y = 32.0f/256.0f;
diff --git a/src/ui/shortcut.cpp b/src/ui/shortcut.cpp
index 5164a10..81495a7 100644
--- a/src/ui/shortcut.cpp
+++ b/src/ui/shortcut.cpp
@@ -116,7 +116,7 @@ void CShortcut::Draw()
zoom = 1.0f;
}
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
if ( icon != -1 )
{
@@ -132,7 +132,7 @@ void CShortcut::Draw()
Math::Point p1, p2, c, uv1, uv2;
float dp;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
zoom = 0.9f+sinf(m_time*8.0f)*0.1f;
@@ -172,7 +172,7 @@ void CShortcut::Draw()
Math::Point uv1, uv2;
float dp;
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 160.0f/256.0f;
diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp
index 7752441..58fcc26 100644
--- a/src/ui/slider.cpp
+++ b/src/ui/slider.cpp
@@ -500,7 +500,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon)
if ( icon == 0 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f/256.0f; // yellow rectangle
uv1.y = 32.0f/256.0f;
@@ -512,7 +512,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 1 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // gray rectangle
uv1.y = 32.0f/256.0f;
@@ -524,7 +524,7 @@ void CSlider::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 224.0f/256.0f; // cursor
uv1.y = 32.0f/256.0f;
diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp
index 5400265..abe4e5c 100644
--- a/src/ui/studio.cpp
+++ b/src/ui/studio.cpp
@@ -852,7 +852,6 @@ bool CStudio::StopEditScript(bool bCancel)
{
CWindow* pw;
CEdit* edit;
- CButton* button;
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3));
if ( pw == nullptr ) return false;
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index 20a9e69..7b57a2f 100644
--- a/src/ui/window.cpp
+++ b/src/ui/window.cpp
@@ -1153,7 +1153,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
if ( icon == 0 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 64.0f/256.0f; // dark blue transparent
uv1.y = 64.0f/256.0f;
@@ -1169,7 +1169,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 1 )
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // white tooltip
uv1.y = 0.0f/256.0f;
@@ -1183,7 +1183,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 2 )
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // yellow
uv1.y = 16.0f/256.0f;
@@ -1197,7 +1197,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 3 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 0.0f/256.0f; // transparent blue bar with yellow upper
uv1.y = 64.0f/256.0f;
@@ -1216,7 +1216,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
dim.x += 100.0f/640.0f;
dim.y += 60.0f/480.0f;
- m_engine->SetTexture("human.png");
+ m_engine->SetTexture("textures/human.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 140.0f/256.0f;
uv1.y = 32.0f/256.0f;
@@ -1233,7 +1233,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
dim.x -= 20.0f/640.0f;
dim.y += 0.0f/480.0f;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
uv1.x = 192.0f/256.0f;
uv1.y = 32.0f/256.0f;
@@ -1252,7 +1252,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
dim.x -= 20.0f/640.0f;
dim.y -= 20.0f/480.0f;
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f/256.0f;
uv1.y = 0.0f/256.0f;
@@ -1288,7 +1288,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
dim.x -= 20.0f/640.0f;
dim.y -= 20.0f/480.0f;
- m_engine->SetTexture("button3.png");
+ m_engine->SetTexture("textures/interface/button3.png");
uv1.x = 0.0f/256.0f;
uv1.y = 224.0f/256.0f;
uv2.x = 32.0f/256.0f;
@@ -1299,7 +1299,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2); // dark blue background
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
uv1.x = 224.0f/256.0f;
uv1.y = 224.0f/256.0f;
uv2.x = 249.0f/256.0f;
@@ -1371,7 +1371,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 5 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f/256.0f; // transparent green
uv1.y = 160.0f/256.0f;
@@ -1385,7 +1385,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 6 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f/256.0f; // transparent red
uv1.y = 176.0f/256.0f;
@@ -1399,7 +1399,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 7 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f/256.0f; // transparent blue
uv1.y = 192.0f/256.0f;
@@ -1413,7 +1413,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 8 )
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 0.0f/256.0f; // opaque orange
uv1.y = 0.0f/256.0f;
@@ -1429,7 +1429,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 9 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 32.0f/256.0f; // opaque gray
uv1.y = 32.0f/256.0f;
@@ -1449,7 +1449,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 11 )
{
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK);
uv1.x = 64.0f/256.0f; // transparent yellow
uv1.y = 224.0f/256.0f;
@@ -1463,7 +1463,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 12 )
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 128.0f/256.0f; // dirty opaque gray
uv1.y = 128.0f/256.0f;
@@ -1479,7 +1479,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 13 )
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 192.0f/256.0f; // dirty opaque blue
uv1.y = 128.0f/256.0f;
@@ -1495,7 +1495,7 @@ void CWindow::DrawVertex(Math::Point pos, Math::Point dim, int icon)
}
else if ( icon == 14 )
{
- m_engine->SetTexture("button1.png");
+ m_engine->SetTexture("textures/interface/button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 160.0f/256.0f; // dirty opaque red
uv1.y = 128.0f/256.0f;
@@ -1521,7 +1521,7 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim)
dp = 0.5f/256.0f;
- m_engine->SetTexture("button2.png");
+ m_engine->SetTexture("textures/interface/button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f/256.0f; // hatching
uv1.y = 208.0f/256.0f;
diff --git a/test/envs/CMakeLists.txt b/test/envs/CMakeLists.txt
index 374c39f..3d535f3 100644
--- a/test/envs/CMakeLists.txt
+++ b/test/envs/CMakeLists.txt
@@ -1,2 +1,3 @@
# OpenGL tests
-add_subdirectory(opengl)
+# TODO: fix dependency on resource manager and re-enable
+#add_subdirectory(opengl)
diff --git a/test/unit/common/profile_test.cpp b/test/unit/common/profile_test.cpp
index 714b2c2..d85017b 100644
--- a/test/unit/common/profile_test.cpp
+++ b/test/unit/common/profile_test.cpp
@@ -30,7 +30,6 @@ class CProfileTest : public testing::Test
{
protected:
CProfile m_profile;
-
};
TEST_F(CProfileTest, ReadTest)
diff --git a/tools/check-levels.sh b/tools/check-levels.sh
index 22544fb..127375f 100755
--- a/tools/check-levels.sh
+++ b/tools/check-levels.sh
@@ -2,8 +2,18 @@
# Runs every level in scenetest mode
-levels=`ls /usr/local/share/games/colobot/levels | cut -d "." -f 1`
-for level in $levels; do
- echo $level
- colobot -runscene $level -scenetest -loglevel warn
+categories=`ls /usr/local/share/games/colobot/levels`
+for category in $categories; do
+ if [ "$category" = "other" ]; then continue; fi
+ chapters=`ls /usr/local/share/games/colobot/levels/$category`
+ for chapter in $chapters; do
+ chapter=`echo -n $chapter | tail -c 1`
+ levels=`ls /usr/local/share/games/colobot/levels/$category/chapter00$chapter`
+ for level in $levels; do
+ if [ ! -d /usr/local/share/games/colobot/levels/$category/chapter00$chapter/$level ]; then continue; fi
+ level=`echo -n $level | cut -d . -f 1 | tail -c 3`
+ echo $category$chapter$level
+ colobot -runscene $category$chapter$level -scenetest -loglevel warn
+ done
+ done
done