xoreos  0.0.5
game.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <cassert>
26 
27 #include <algorithm>
28 
29 #include "src/common/error.h"
30 #include "src/common/configman.h"
31 #include "src/common/filepath.h"
32 #include "src/common/filelist.h"
33 
35 
36 #include "src/events/events.h"
37 
44 
46 
48 
49 namespace Engines {
50 
51 namespace Witcher {
52 
53 Game::Game(WitcherEngine &engine, ::Engines::Console &console) : _engine(&engine), _console(&console) {
54  _functions.reset(new Functions(*this));
55  _bindings.reset(new LuaBindings());
56 }
57 
59 }
60 
62  assert(_campaign);
63 
64  return *_campaign;
65 }
66 
68  assert(_campaign);
69 
70  return _campaign->getModule();
71 }
72 
73 void Game::run() {
74  _campaign.reset(new Campaign(*_console));
75 
76  // Don't know what are this file for. Seems to be some internal scripts.
77  // They are absent in game resources.
78  LuaScriptMan.addIgnoredFile("global_local");
79  LuaScriptMan.addIgnoredFile("startup_local");
80 
81  // This needs a bit more research, so ignore them for now.
82  LuaScriptMan.addIgnoredFile("combatsystem");
83  LuaScriptMan.addIgnoredFile("gui_defs_sum_v2");
84 
85  // This are the only files that need to be called manually, I guess.
86  // Other script files are called from Lua scripts.
87  LuaScriptMan.executeFile("global");
88  LuaScriptMan.executeFile("startup");
89 
90  while (!EventMan.quitRequested()) {
91  runCampaign();
92  }
93 
94  _campaign.reset();
95 }
96 
98  _campaign->load("thewitcher");
99  _campaign->usePC("wiedzmin");
100 
101  if (EventMan.quitRequested() || !_campaign->isLoaded()) {
102  _campaign->clear();
103  return;
104  }
105 
106  _campaign->enter();
107  EventMan.enableKeyRepeat(true);
108 
109  while (!EventMan.quitRequested() && _campaign->isRunning()) {
110  Events::Event event;
111  while (EventMan.pollEvent(event))
112  _campaign->addEvent(event);
113 
114  _campaign->processEventQueue();
115  EventMan.delay(10);
116  }
117 
118  EventMan.enableKeyRepeat(false);
119  _campaign->leave();
120 
121  _campaign->clear();
122 }
123 
124 void Game::playMusic(const Common::UString &music) {
125  if (!_campaign || !_campaign->getModule().isRunning())
126  return;
127 
128  Area *area = _campaign->getModule().getCurrentArea();
129  if (!area)
130  return;
131 
132  area->playAmbientMusic(music);
133 }
134 
136  if (!_campaign || !_campaign->getModule().isRunning())
137  return;
138 
139  Area *area = _campaign->getModule().getCurrentArea();
140  if (!area)
141  return;
142 
143  area->stopAmbientMusic();
144 }
145 
147  if (!_campaign)
148  return;
149 
150  _campaign->refreshLocalized();
151 }
152 
153 void Game::getCampaigns(std::vector<Common::UString> &campaigns) {
154  campaigns.clear();
155 
156  const Common::FileList mmdFiles(ConfigMan.getString("WITCHER_moduleDir"), -1);
157 
158  for (Common::FileList::const_iterator c = mmdFiles.begin(); c != mmdFiles.end(); ++c) {
160  continue;
161 
163  if (mmd.empty())
164  continue;
165 
166  campaigns.push_back(mmd);
167  }
168 
169  std::sort(campaigns.begin(), campaigns.end(), Common::UString::iless());
170 }
171 
172 void Game::getModules(std::vector<Common::UString> &modules) {
173  modules.clear();
174 
175  const Common::FileList modFiles(ConfigMan.getString("WITCHER_moduleDir"), -1);
176 
177  for (Common::FileList::const_iterator c = modFiles.begin(); c != modFiles.end(); ++c) {
180  continue;
181 
183  if (mod.empty())
184  continue;
185 
186  modules.push_back(mod);
187  }
188 
189  std::sort(modules.begin(), modules.end(), Common::UString::iless());
190 }
191 
192 } // End of namespace Witcher
193 
194 } // End of namespace Engines
The context holding a The Witcher campaign.
An area in The Witcher, holding all objects and area geometry within, as well as general area propert...
Definition: area.h:63
A class holding an UTF-8 string.
Definition: ustring.h:48
Common::ScopedPtr< Functions > _functions
Definition: game.h:80
static UString getExtension(const UString &p)
Return a file name&#39;s extension.
Definition: filepath.cpp:93
The global config manager.
void playAmbientMusic(Common::UString music="")
Play the specified music (or the area&#39;s default) as ambient music.
Definition: area.cpp:155
bool equalsIgnoreCase(const UString &str) const
Definition: ustring.cpp:218
std::list< UString >::const_iterator const_iterator
Definition: filelist.h:37
static void getCampaigns(std::vector< Common::UString > &campaigns)
Return a list of all campaigns.
Definition: game.cpp:153
Module & getModule()
Return the module context.
Definition: game.cpp:67
The Witcher (debug) console.
SDL_Event Event
Definition: types.h:42
void refreshLocalized()
Refresh all localized strings.
Definition: game.cpp:146
Basic exceptions to throw.
static void getModules(std::vector< Common::UString > &modules)
Return a list of all modules.
Definition: game.cpp:172
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
The global events manager.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
Common::ScopedPtr< LuaBindings > _bindings
Definition: game.h:81
void stopAmbientMusic()
Stop the ambient music.
Definition: area.cpp:151
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
void stopMusic()
Force all currently playing music stopped.
Definition: game.cpp:135
static UString getStem(const UString &p)
Return a file name&#39;s stem.
Definition: filepath.cpp:87
A list of files.
Definition: filelist.h:35
The context needed to run a The Witcher module.
The Witcher engine functions.
Lua script manager.
The context holding a The Witcher area.
Game(WitcherEngine &engine, ::Engines::Console &console)
Definition: game.cpp:53
Campaign & getCampaign()
Return the campaign context.
Definition: game.cpp:61
A list of files.
Engine class handling The Witcher.
The context handling the gameplay in The Witcher.
#define LuaScriptMan
Shortcut for accessing the script engine.
Definition: scriptman.h:157
::Engines::Console * _console
Definition: game.h:83
The Lua bindings for The Witcher.
void playMusic(const Common::UString &music="")
Overwrite all currently playing music.
Definition: game.cpp:124
Utility class for manipulating file paths.
Common::ScopedPtr< Campaign > _campaign
Definition: game.h:78