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/filepath.h"
32 #include "src/common/filelist.h"
33 #include "src/common/configman.h"
34 #include "src/common/strutil.h"
35 
36 #include "src/aurora/resman.h"
37 
39 
42 #include "src/engines/kotor/game.h"
44 #include "src/engines/kotor/room.h"
45 #include "src/engines/kotor/area.h"
46 
47 namespace Engines {
48 
49 namespace KotOR {
50 
52  ::Engines::Console(engine, Graphics::Aurora::kSystemFontMono, 13),
53  _engine(&engine), _maxSizeMusic(0) {
54 
55  registerCommand("exitmodule" , boost::bind(&Console::cmdExitModule , this, _1),
56  "Usage: exitmodule\nExit the module, returning to the main menu");
57  registerCommand("listmodules" , boost::bind(&Console::cmdListModules , this, _1),
58  "Usage: listmodules\nList all modules");
59  registerCommand("loadmodule" , boost::bind(&Console::cmdLoadModule , this, _1),
60  "Usage: loadmodule <module>\nLoad and enter the specified module");
61  registerCommand("listmusic" , boost::bind(&Console::cmdListMusic , this, _1),
62  "Usage: listmusic\nList all available music resources");
63  registerCommand("stopmusic" , boost::bind(&Console::cmdStopMusic , this, _1),
64  "Usage: stopmusic\nStop the currently playing music resource");
65  registerCommand("playmusic" , boost::bind(&Console::cmdPlayMusic , this, _1),
66  "Usage: playmusic [<music>]\nPlay the specified music resource. "
67  "If none was specified, play the default area music.");
68  registerCommand("flycam" , boost::bind(&Console::cmdFlyCam , this, _1),
69  "Usage: flycam\nToggle free roam camera mode");
70  registerCommand("showwalkmesh" , boost::bind(&Console::cmdShowWalkmesh , this, _1),
71  "Usage: showwalkmesh\nToggle walkmesh display");
72  registerCommand("showtriggers" , boost::bind(&Console::cmdShowTriggers , this, _1),
73  "Usage: showtriggers\nToggle triggers display");
74  registerCommand("getpcroom" , boost::bind(&Console::cmdGetPCRoom , this, _1),
75  "Usage: getpcroom\nGet a room PC is in");
76  registerCommand("listroomsvisiblefrom", boost::bind(&Console::cmdListRoomsVisibleFrom, this, _1),
77  "Usage: listroomsvisiblefrom <room>\nList rooms that are visible from the specified room");
78  registerCommand("playanim" , boost::bind(&Console::cmdPlayAnim , this, _1),
79  "Usage: playanim <base> [<head>]\nPlay the specified animations on the active object");
80  registerCommand("additem" , boost::bind(&Console::cmdAddItem , this, _1),
81  "Usage: additem <item> [<count>]\nAdd the specified item to the active object");
82 
83 }
84 
86 }
87 
90 
91  updateModules();
92  updateMusic();
93 }
94 
97 
98  setArguments("loadmodule", _modules);
99 }
100 
102  _music.clear();
103  _maxSizeMusic = 0;
104 
105  const Common::FileList music(Common::FilePath::findSubDirectory(ResMan.getDataBase(), "streammusic", true));
106 
107  for (Common::FileList::const_iterator m = music.begin(); m != music.end(); ++m) {
109  continue;
110 
111  _music.push_back(Common::FilePath::getStem(*m));
112 
113  _maxSizeMusic = MAX(_maxSizeMusic, _music.back().size());
114  }
115 
116  std::sort(_music.begin(), _music.end(), Common::UString::iless());
117  setArguments("playmusic", _music);
118 }
119 
121  hide();
122  _engine->getGame().getModule().exit();
123 }
124 
126  updateModules();
127 
128  for (std::vector<Common::UString>::iterator m = _modules.begin(); m != _modules.end(); ++m)
129  printf("%s (\"%s\")", m->c_str(), Module::getName(*m).c_str());
130 }
131 
133  if (cl.args.empty()) {
134  printCommandHelp(cl.cmd);
135  return;
136  }
137 
138  for (std::vector<Common::UString>::iterator m = _modules.begin(); m != _modules.end(); ++m) {
139  if (m->equalsIgnoreCase(cl.args)) {
140  hide();
141  _engine->getGame().getModule().load(cl.args);
142  return;
143  }
144  }
145 
146  printf("No such module \"%s\"", cl.args.c_str());
147 }
148 
150  updateMusic();
152 }
153 
156 }
157 
159  _engine->getGame().playMusic(cl.args);
160 }
161 
164 }
165 
168 }
169 
172 }
173 
175  const Room *room = _engine->getGame().getModule().getPC()->getRoom();
176  printf("%s", room->getResRef().c_str());
177 }
178 
180  if (cl.args.empty()) {
181  printCommandHelp(cl.cmd);
182  return;
183  }
184 
185  const std::vector<Common::UString> &rooms = _engine->getGame().getModule().getCurrentArea()->getRoomsVisibleFrom(cl.args);
186  for (std::vector<Common::UString>::const_iterator r = rooms.begin();
187  r != rooms.end(); ++r) {
188  printf("%s", r->c_str());
189  }
190 }
191 
193  if (cl.args.empty()) {
194  printCommandHelp(cl.cmd);
195  return;
196  }
197  std::vector<Common::UString> anims;
198  Common::UString::split(cl.args, ' ', anims);
199  size_t animCount = anims.size();
201  animCount >= 2 ? anims[1] : "");
202 }
203 
205  if (cl.args.empty()) {
206  printCommandHelp(cl.cmd);
207  return;
208  }
209 
210  std::vector<Common::UString> args;
211  Common::UString::split(cl.args, ' ', args);
212  int count = 1;
213  if (args.size() >= 2)
214  Common::parseString(args[1], count);
215 
216  _engine->getGame().getModule().addItemToActiveObject(args[0], count);
217 }
218 
219 } // End of namespace KotOR
220 
221 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
const std::vector< Common::UString > & getRoomsVisibleFrom(const Common::UString &room) const
Definition: area.cpp:720
Common::UString args
Definition: console.h:218
Game & getGame()
Return the context running the actual game.
Definition: kotor.cpp:107
void cmdLoadModule(const CommandLine &cl)
Definition: console.cpp:132
void cmdExitModule(const CommandLine &cl)
Definition: console.cpp:120
static UString getExtension(const UString &p)
Return a file name&#39;s extension.
Definition: filepath.cpp:93
void cmdStopMusic(const CommandLine &cl)
Definition: console.cpp:154
The global config manager.
void addItemToActiveObject(const Common::UString &item, int count)
Definition: module.cpp:1031
void cmdPlayAnim(const CommandLine &cl)
Definition: console.cpp:192
A room within a Star Wars: Knights of the Old Republic area.
void playMusic(const Common::UString &music="")
Overwrite all currently playing music.
Definition: game.cpp:119
std::vector< Common::UString > _modules
All known modules.
Definition: console.h:48
Console(KotOREngine &engine)
Definition: console.cpp:51
void cmdGetPCRoom(const CommandLine &cl)
Definition: console.cpp:174
void cmdPlayMusic(const CommandLine &cl)
Definition: console.cpp:158
bool equalsIgnoreCase(const UString &str) const
Definition: ustring.cpp:218
std::list< UString >::const_iterator const_iterator
Definition: filelist.h:37
void load(const Common::UString &module, const Common::UString &entryLocation="", ObjectType entryLocationType=kObjectTypeAll)
Load a module.
Definition: module.cpp:110
KotOREngine * _engine
Definition: console.h:45
Utility templates and functions for working with strings and streams.
void stopMusic()
Force all currently playing music stopped.
Definition: game.cpp:131
void cmdListModules(const CommandLine &cl)
Definition: console.cpp:125
void cmdShowWalkmesh(const CommandLine &cl)
Definition: console.cpp:166
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
Star Wars: Knights of the Old Republic (debug) console.
void toggleFreeRoamCamera()
Definition: module.cpp:963
#define UNUSED(x)
Definition: system.h:170
Basic Aurora graphics types.
The context handling the gameplay in Star Wars: Knights of the Old Republic.
Utility templates and functions.
Engine class handling Star Wars: Knights of the Old Republic.
Room * getRoom()
Get a room the object is in.
Definition: object.cpp:175
Common::UString getResRef() const
Definition: room.cpp:60
const char * kSystemFontMono
Identifier used for the monospaced system font.
Definition: fontman.cpp:41
const Common::UString & getName() const
Return the module&#39;s name.
Definition: module.cpp:903
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
The context holding a Star Wars: Knights of the Old Republic area.
Unicode string handling.
static void getModules(std::vector< Common::UString > &modules)
Return a list of all modules.
Definition: game.cpp:159
void cmdListRoomsVisibleFrom(const CommandLine &cl)
Definition: console.cpp:179
std::vector< Common::UString > _music
All known music resources.
Definition: console.h:49
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
void cmdFlyCam(const CommandLine &cl)
Definition: console.cpp:162
Module & getModule()
Return the module context.
Definition: game.cpp:65
void cmdShowTriggers(const CommandLine &cl)
Definition: console.cpp:170
void playAnimationOnActiveObject(const Common::UString &baseAnim, const Common::UString &headAnim)
Definition: module.cpp:1014
void printf(const char *s,...) GCC_PRINTF(2
Definition: console.cpp:1093
const_iterator begin() const
Return a const_iterator pointing to the beginning of the list.
Definition: filelist.cpp:94
A list of files.
virtual void updateCaches()
Definition: console.cpp:1122
void printCommandHelp(const Common::UString &cmd)
Definition: console.cpp:1391
void split(iterator splitPoint, UString &left, UString &right, bool remove=false) const
Definition: ustring.cpp:621
The context needed to run a Star Wars: Knights of the Old Republic module.
Area * getCurrentArea()
Return the area the PC is currently in.
Definition: module.cpp:907
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
void parseString(const UString &str, T &value, bool allowEmpty)
Parse a string into any POD integer, float/double or bool type.
Definition: strutil.cpp:215
bool registerCommand(const Common::UString &cmd, const CommandCallback &callback, const Common::UString &help)
Definition: console.cpp:1576
The global resource manager for Aurora resources.
Utility class for manipulating file paths.
void cmdAddItem(const CommandLine &cl)
Definition: console.cpp:204
const_iterator end() const
Return a const_iterator pointing past the end of the list.
Definition: filelist.cpp:98
static UString findSubDirectory(const UString &directory, const UString &subDirectory, bool caseInsensitive=false)
Find a directory&#39;s subdirectory.
Definition: filepath.cpp:318
void exit()
Exit the currently running module.
Definition: module.cpp:197
void cmdListMusic(const CommandLine &cl)
Definition: console.cpp:149
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:181