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 <boost/bind.hpp>
26 
27 #include "src/common/ustring.h"
28 #include "src/common/strutil.h"
29 
30 #include "src/aurora/gdafile.h"
31 #include "src/aurora/2dareg.h"
32 #include "src/aurora/gff4file.h"
33 #include "src/aurora/talkman.h"
34 
36 
39 #include "src/engines/sonic/game.h"
41 
42 namespace Engines {
43 
44 namespace Sonic {
45 
47  ::Engines::Console(engine, Graphics::Aurora::kSystemFontMono, 10),
48  _engine(&engine) {
49 
50  registerCommand("listareas", boost::bind(&Console::cmdListAreas, this, _1),
51  "Usage: listareas\nList all areas");
52  registerCommand("gotoarea" , boost::bind(&Console::cmdGotoArea , this, _1),
53  "Usage: gotoarea <area>\nMove to a specific area");
54 }
55 
57 }
58 
61 
62  updateAreas();
63 }
64 
66  _areas.clear();
67  setArguments("gotoarea");
68 
69  const Aurora::GDAFile &areas = TwoDAReg.getGDA("areas");
70 
71  std::vector<Common::UString> areaIDs;
72  for (size_t i = 0; i < areas.getRowCount(); i++) {
73  if (areas.getInt(i, "Name") > 0) {
74  _areas.insert(i);
75 
76  areaIDs.push_back(Common::UString::format("%u", (uint)i));
77  }
78  }
79 
80  setArguments("gotoarea", areaIDs);
81 }
82 
84  updateAreas();
85 
86  const Aurora::GDAFile &areas = TwoDAReg.getGDA("areas");
87 
88  for (std::set<int32>::const_iterator a = _areas.begin(); a != _areas.end(); ++a)
89  printf("%d (\"%s\")", *a, TalkMan.getString(areas.getInt(*a, "Name")).c_str());
90 }
91 
93  if (cl.args.empty()) {
95  return;
96  }
97 
98  int32 areaID = -1;
99  try {
100  Common::parseString(cl.args, areaID);
101  } catch (...) {
102  printCommandHelp(cl.cmd);
103  return;
104  }
105 
106  std::set<int32>::const_iterator area = _areas.find(areaID);
107  if (area == _areas.end()) {
108  printf("No such area %d", areaID);
109  return;
110  }
111 
112  _engine->getGame().getModule().movePC(areaID);
113 }
114 
115 } // End of namespace Sonic
116 
117 } // End of namespace Engines
Common::UString args
Definition: console.h:218
Handling BioWare&#39;s GDAs (2DAs, two-dimensional array, within V4.0 GFFs).
int32 getInt(size_t row, uint32 columnHash, int32 def=0) const
Definition: gdafile.cpp:184
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
Console(SonicEngine &engine)
Definition: console.cpp:46
void cmdGotoArea(const CommandLine &cl)
Definition: console.cpp:92
SonicEngine * _engine
Definition: console.h:47
std::set< int32 > _areas
All known areas.
Definition: console.h:50
The context handling the gameplay in Sonic Chronicles: The Dark Brotherhood.
Engine class handling Sonic Chronicles: The Dark Brotherhood.
void cmdListAreas(const CommandLine &cl)
Definition: console.cpp:83
Utility templates and functions for working with strings and streams.
Handling version V4.0/V4.1 of BioWare&#39;s GFFs (generic file format).
Sonic Chronicles: The Dark Brotherhood (debug) console.
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
#define UNUSED(x)
Definition: system.h:170
Basic Aurora graphics types.
Game & getGame()
Return the context running the actual game.
Definition: sonic.cpp:164
const char * kSystemFontMono
Identifier used for the monospaced system font.
Definition: fontman.cpp:41
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
#define TwoDAReg
Shortcut for accessing the 2da registry.
Definition: 2dareg.h:101
The global 2DA registry.
size_t getRowCount() const
Return the number of rows in the array.
Definition: gdafile.cpp:61
Unicode string handling.
The context needed to run a Sonic Chronicles: The Dark Brotherhood module.
void movePC(int32 area)
Move the player character to this area.
Definition: module.cpp:203
The global talk manager for Aurora strings.
void printf(const char *s,...) GCC_PRINTF(2
Definition: console.cpp:1093
virtual void updateCaches()
Definition: console.cpp:1122
void printCommandHelp(const Common::UString &cmd)
Definition: console.cpp:1391
void setArguments(const Common::UString &cmd, const std::vector< Common::UString > &args)
Definition: console.cpp:1565
Module & getModule()
Return the module context.
Definition: game.cpp:65
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
Class to hold the GFF&#39;d two-dimensional array of a GDA file.
Definition: gdafile.h:62
unsigned int uint
Definition: types.h:211
int32_t int32
Definition: types.h:203