xoreos  0.0.5
console.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 <algorithm>
26 
27 #include <boost/bind.hpp>
28 
29 #include "src/common/ustring.h"
30 #include "src/common/util.h"
31 #include "src/common/configman.h"
32 
33 #include "src/aurora/resman.h"
34 #include "src/aurora/talkman.h"
35 
37 
39 
41 #include "src/engines/nwn/nwn.h"
42 #include "src/engines/nwn/game.h"
43 #include "src/engines/nwn/module.h"
44 #include "src/engines/nwn/area.h"
45 
46 static const uint32 kCampaignNames[] = {
47  10314 , 5557 , 5558 , 5559, 5560,
48  40041 , 40042 , 40043 ,
49  100777, 100778, 100779
50 };
51 
52 static const char * const kCampaignModules[] = {
53  "Prelude" , "Chapter1" , "Chapter2" , "Chapter3", "Chapter4",
54  "XP1-Chapter 1", "XP1-Interlude", "XP1-Chapter 2",
55  "XP2_Chapter1" , "XP2_Chapter2" , "XP2_Chapter3"
56 };
57 
58 namespace Engines {
59 
60 namespace NWN {
61 
63  ::Engines::Console(engine, Graphics::Aurora::kSystemFontMono, 13),
64  _engine(&engine), _maxSizeMusic(0) {
65 
66  registerCommand("exitmodule" , boost::bind(&Console::cmdExitModule , this, _1),
67  "Usage: exitmodule\nExit the module, returning to the main menu");
68  registerCommand("listcampaigns", boost::bind(&Console::cmdListCampaigns, this, _1),
69  "Usage: listcampaigns\nList all original campaign modules");
70  registerCommand("loadcampaign" , boost::bind(&Console::cmdLoadCampaign , this, _1),
71  "Usage: loadcampaign\nLoad a original campaign modules, "
72  "replacing the currently running module");
73  registerCommand("listmodules" , boost::bind(&Console::cmdListModules , this, _1),
74  "Usage: listmodules\nList all modules");
75  registerCommand("loadmodule" , boost::bind(&Console::cmdLoadModule , this, _1),
76  "Usage: loadmodule <module>\nLoads a module, "
77  "replacing the currently running one");
78  registerCommand("listareas" , boost::bind(&Console::cmdListAreas , this, _1),
79  "Usage: listareas\nList all areas in the current module");
80  registerCommand("gotoarea" , boost::bind(&Console::cmdGotoArea , this, _1),
81  "Usage: gotoarea <area>\nMove to a specific area");
82  registerCommand("listmusic" , boost::bind(&Console::cmdListMusic , this, _1),
83  "Usage: listmusic\nList all available music resources");
84  registerCommand("stopmusic" , boost::bind(&Console::cmdStopMusic , this, _1),
85  "Usage: stopmusic\nStop the currently playing music resource");
86  registerCommand("playmusic" , boost::bind(&Console::cmdPlayMusic , this, _1),
87  "Usage: playmusic [<music>]\nPlay the specified music resource. "
88  "If none was specified, play the default area music.");
89 }
90 
92 }
93 
96 
98  updateModules();
99  updateAreas();
100  updateMusic();
101 }
102 
104  _campaigns.clear();
105  _campaignModules.clear();
106 
108 
109  // Base game
110  for (int i = 0; i < 5; i++) {
111  Common::UString name = TalkMan.getString(kCampaignNames[i]);
112  name.truncate(name.findFirst('\n'));
113  name.trim();
114 
115  _campaigns.push_back(name);
116  _campaignModules.insert(std::make_pair(name, i));
117  }
118 
119  // XP1
120  if (ConfigMan.getBool("NWN_hasXP1")) {
121  for (int i = 5; i < 8; i++) {
122  Common::UString name = "XP1: " + TalkMan.getString(kCampaignNames[i]);
123  name.truncate(name.findFirst('\n'));
124  name.trim();
125 
126  _campaigns.push_back(name);
127  _campaignModules.insert(std::make_pair(name, i));
128  }
129  }
130 
131  // XP2
132  if (ConfigMan.getBool("NWN_hasXP2")) {
133  for (int i = 8; i < 11; i++) {
134  Common::UString name = "XP2: " + TalkMan.getString(kCampaignNames[i]);
135  name.truncate(name.findFirst('\n'));
136  name.trim();
137 
138  _campaigns.push_back(name);
139  _campaignModules.insert(std::make_pair(name, i));
140  }
141  }
142 
143  setArguments("loadcampaign", _campaigns);
144 }
145 
148 
149  setArguments("loadmodule", _modules);
150 }
151 
153  setArguments("gotoarea", _engine->getGame().getModule().getIFO().getAreas());
154 }
155 
157  _music.clear();
158  _maxSizeMusic = 0;
159 
160  std::list<Aurora::ResourceManager::ResourceID> music;
161  ResMan.getAvailableResources(Aurora::kFileTypeBMU, music);
162 
163  for (std::list<Aurora::ResourceManager::ResourceID>::const_iterator m = music.begin();
164  m != music.end(); ++m) {
165 
166  _music.push_back(m->name);
167 
168  _maxSizeMusic = MAX(_maxSizeMusic, _music.back().size());
169  }
170 
171  std::sort(_music.begin(), _music.end(), Common::UString::iless());
172  setArguments("playmusic", _music);
173 }
174 
176  hide();
177 
178  _engine->getGame().getModule().exit();
179 }
180 
182  updateCampaigns();
183  for (std::vector<Common::UString>::iterator c = _campaigns.begin(); c != _campaigns.end(); ++c)
184  print(*c);
185 }
186 
188  if (cl.args.empty()) {
189  printCommandHelp(cl.cmd);
190  return;
191  }
192 
193  CampaignMap::const_iterator c = _campaignModules.find(cl.args);
194  if (c == _campaignModules.end()) {
195  printf("No such campaign module \"%s\"", cl.args.c_str());
196  return;
197  }
198 
199  hide();
200 
201  Common::UString mod = Common::UString(kCampaignModules[c->second]) + ".nwm";
202  _engine->getGame().getModule().load(mod);
203 }
204 
206  updateModules();
208 }
209 
211  if (cl.args.empty()) {
212  printCommandHelp(cl.cmd);
213  return;
214  }
215 
216  for (std::vector<Common::UString>::iterator m = _modules.begin(); m != _modules.end(); ++m) {
217  if (m->equalsIgnoreCase(cl.args)) {
218  hide();
219 
220  _engine->getGame().getModule().load(cl.args + ".mod");
221  return;
222  }
223  }
224 
225  printf("No such module \"%s\"", cl.args.c_str());
226 }
227 
229  updateAreas();
230 
231  const std::vector<Common::UString> &areas = _engine->getGame().getModule().getIFO().getAreas();
232  for (std::vector<Common::UString>::const_iterator a = areas.begin(); a != areas.end(); ++a)
233  printf("%s (\"%s\")", a->c_str(), Area::getName(*a).c_str());
234 }
235 
237  if (cl.args.empty()) {
238  printCommandHelp(cl.cmd);
239  return;
240  }
241 
242  Module &module = _engine->getGame().getModule();
243 
244  const std::vector<Common::UString> &areas = module.getIFO().getAreas();
245  for (std::vector<Common::UString>::const_iterator a = areas.begin(); a != areas.end(); ++a)
246  if (a->equalsIgnoreCase(cl.args)) {
247  hide();
248  module.movePC(*a);
249  return;
250  }
251 
252  printf("Area \"%s\" does not exist", cl.args.c_str());
253 }
254 
256  updateMusic();
258 }
259 
262 }
263 
265  _engine->getGame().playMusic(cl.args);
266 }
267 
268 } // End of namespace NWN
269 
270 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
std::vector< Common::UString > _campaigns
All known campaigns modules.
Definition: console.h:55
Common::UString args
Definition: console.h:218
void cmdListMusic(const CommandLine &cl)
Definition: console.cpp:255
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
Engine class handling Neverwinter Nights.
A class holding an UTF-8 string.
Definition: ustring.h:48
void cmdLoadModule(const CommandLine &cl)
Definition: console.cpp:210
The global config manager.
static void getModules(std::vector< Common::UString > &modules)
Return a list of all modules.
Definition: game.cpp:210
void cmdPlayMusic(const CommandLine &cl)
Definition: console.cpp:264
void truncate(const iterator &it)
Definition: ustring.cpp:343
Game & getGame()
Return the context running the actual game.
Definition: nwn.cpp:110
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
void movePC(const Common::UString &area)
Move the player character to this area.
Definition: module.cpp:689
void exit()
Exit the currently running module.
Definition: module.cpp:440
void cmdListCampaigns(const CommandLine &cl)
Definition: console.cpp:181
void playMusic(const Common::UString &music="")
Overwrite all currently playing music.
Definition: game.cpp:128
iterator findFirst(uint32 c) const
Definition: ustring.cpp:261
static const char *const kCampaignModules[]
Definition: console.cpp:52
The context needed to run a Neverwinter Nights module.
void load(const Common::UString &module)
Load a module.
Definition: module.cpp:127
The context holding a Neverwinter Nights area.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Neverwinter Nights (debug) console.
void cmdListAreas(const CommandLine &cl)
Definition: console.cpp:228
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
#define UNUSED(x)
Definition: system.h:170
Basic Aurora graphics types.
Utility templates and functions.
void cmdExitModule(const CommandLine &cl)
Definition: console.cpp:175
const Aurora::IFOFile & getIFO() const
Return the IFO of the currently loaded module.
Definition: module.cpp:748
std::vector< Common::UString > _music
All known music resources.
Definition: console.h:57
const char * kSystemFontMono
Identifier used for the monospaced system font.
Definition: fontman.cpp:41
void cmdLoadCampaign(const CommandLine &cl)
Definition: console.cpp:187
const std::vector< Common::UString > & getAreas() const
Return the list of areas in the module.
Definition: ifofile.cpp:311
void printList(const std::vector< Common::UString > &list, size_t maxSize=0)
Definition: console.cpp:1479
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
void cmdStopMusic(const CommandLine &cl)
Definition: console.cpp:260
Unicode string handling.
CampaignMap _campaignModules
Mapping campaign module file -> campaign module name.
Definition: console.h:59
static const uint32 kCampaignNames[]
Definition: console.cpp:46
uint32_t uint32
Definition: types.h:204
The global talk manager for Aurora strings.
void cmdListModules(const CommandLine &cl)
Definition: console.cpp:205
void printf(const char *s,...) GCC_PRINTF(2
Definition: console.cpp:1093
void print(const Common::UString &line)
Definition: console.cpp:1089
Generic Aurora engines utility functions.
NWNEngine * _engine
Definition: console.h:52
virtual void updateCaches()
Definition: console.cpp:1122
void printCommandHelp(const Common::UString &cmd)
Definition: console.cpp:1391
The context handling the gameplay in Neverwinter Nights.
Console(NWNEngine &engine)
Definition: console.cpp:62
T MAX(T a, T b)
Definition: util.h:71
void setArguments(const Common::UString &cmd, const std::vector< Common::UString > &args)
Definition: console.cpp:1565
size_t _maxSizeMusic
Definition: console.h:61
void stopMusic()
Force all currently playing music stopped.
Definition: game.cpp:140
void cmdGotoArea(const CommandLine &cl)
Definition: console.cpp:236
Module & getModule()
Return the module context.
Definition: game.cpp:70
bool registerCommand(const Common::UString &cmd, const CommandCallback &callback, const Common::UString &help)
Definition: console.cpp:1576
std::vector< Common::UString > _modules
All known modules.
Definition: console.h:56
The global resource manager for Aurora resources.
const Common::UString & getName()
Return the area&#39;s localized name.
Definition: area.cpp:124
Audio, MP3 with extra header.
Definition: types.h:65