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 
30 
37 
38 namespace Engines {
39 
40 namespace DragonAge {
41 
43  ::Engines::Console(engine, Graphics::Aurora::kSystemFontMono, 13),
44  _engine(&engine) {
45 
46  registerCommand("listareas" , boost::bind(&Console::cmdListAreas , this, _1),
47  "Usage: listareas\nList all areas in the current campaign");
48  registerCommand("loadarea" , boost::bind(&Console::cmdLoadArea , this, _1),
49  "Usage: loadarea <name>\nLoad and show a specific area in the current campaign");
50  registerCommand("listcampaigns", boost::bind(&Console::cmdListCampaigns, this, _1),
51  "Usage: listcampaigns\nList all playable campaigns");
52  registerCommand("loadcampaign" , boost::bind(&Console::cmdLoadCampaign , this, _1),
53  "Usage: loadcampaign <name>\nLoad and run a specific campaign");
54 }
55 
57 }
58 
61 
62  updateAreas();
64 }
65 
67  setArguments("loadarea");
68 
69  const Campaign *campaign = _engine->getGame().getCampaigns().getCurrentCampaign();
70  if (!campaign)
71  return;
72 
73  setArguments("loadarea", campaign->getAreas());
74 }
75 
77  setArguments("loadcampaign");
78 
79  const Campaigns &campaignsCtx = _engine->getGame().getCampaigns();
80 
81  std::vector<Common::UString> campaignTags;
82 
83  const Campaigns::PlayableCampaigns &campaigns = campaignsCtx.getCampaigns();
84  for (Campaigns::PlayableCampaigns::const_iterator c = campaigns.begin(); c != campaigns.end(); ++c)
85  campaignTags.push_back((*c)->getUID());
86 
87  std::sort(campaignTags.begin(), campaignTags.end(), Common::UString::iless());
88  setArguments("loadcampaign", campaignTags);
89 }
90 
92  const Campaign *campaign = _engine->getGame().getCampaigns().getCurrentCampaign();
93  if (!campaign)
94  return;
95 
96  const std::vector<Common::UString> &areas = campaign->getAreas();
97 
98  for (std::vector<Common::UString>::const_iterator a = areas.begin(); a != areas.end(); ++a) {
99  const Common::UString &rim = campaign->getAreaRIM(*a);
100 
101  printf("%s (\"%s\")", a->c_str(), Area::getName(*a, rim).c_str());
102  }
103 }
104 
106  if (cl.args.empty()) {
107  printCommandHelp(cl.cmd);
108  return;
109  }
110 
112  if (!campaign)
113  return;
114 
115  const std::vector<Common::UString> &areas = campaign->getAreas();
116 
117  for (std::vector<Common::UString>::const_iterator a = areas.begin(); a != areas.end(); ++a) {
118  if (a->equalsIgnoreCase(cl.args)) {
119  hide();
120  campaign->movePC(*a);
121  return;
122  }
123  }
124 
125  printf("No such area \"%s\"", cl.args.c_str());
126 }
127 
129  const Campaigns &campaignsCtx = _engine->getGame().getCampaigns();
130 
131  const Campaigns::PlayableCampaigns &campaigns = campaignsCtx.getCampaigns();
132 
133  for (Campaigns::PlayableCampaigns::const_iterator c = campaigns.begin(); c != campaigns.end(); ++c)
134  printf("%s (\"%s\")", (*c)->getUID().c_str(), (*c)->getName().getString().c_str());
135 }
136 
138  if (cl.args.empty()) {
139  printCommandHelp(cl.cmd);
140  return;
141  }
142 
143  Campaigns &campaignsCtx = _engine->getGame().getCampaigns();
144 
145  const Campaigns::PlayableCampaigns &campaigns = campaignsCtx.getCampaigns();
146  for (Campaigns::PlayableCampaigns::const_iterator c = campaigns.begin(); c != campaigns.end(); ++c) {
147  if ((*c)->getUID().equalsIgnoreCase(cl.args)) {
148  hide();
149  campaignsCtx.load(**c);
150  return;
151  }
152  }
153 
154  printf("No such campaign \"%s\"", cl.args.c_str());
155 }
156 
157 } // End of namespace DragonAge
158 
159 } // End of namespace Engines
Common::UString args
Definition: console.h:218
const Aurora::LocString & getName() const
Definition: area.cpp:94
A class holding an UTF-8 string.
Definition: ustring.h:48
Engine class handling Dragon Age: Origins.
The context holding a Dragon Age: Origins campaign.
Campaigns & getCampaigns()
Return the campaigns context.
Definition: game.cpp:57
Dragon Age: Origins (debug) console.
const PlayableCampaigns & getCampaigns() const
Return all playable campaigns.
Definition: campaigns.cpp:65
const std::vector< Common::UString > & getAreas() const
Definition: campaign.cpp:287
Console(DragonAgeEngine &engine)
Definition: console.cpp:42
void cmdLoadCampaign(const CommandLine &cl)
Definition: console.cpp:137
The context holding a Dragon Age: Origins area.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
The context handling the gameplay in Dragon Age: Origins.
#define UNUSED(x)
Definition: system.h:170
void load(const Campaign &campaign)
Load a campaign.
Definition: campaigns.cpp:175
Basic Aurora graphics types.
void cmdListCampaigns(const CommandLine &cl)
Definition: console.cpp:128
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
void cmdListAreas(const CommandLine &cl)
Definition: console.cpp:91
const Common::UString & getAreaRIM(const Common::UString &area) const
Return the RIM file containing this area.
Definition: campaign.cpp:277
DragonAgeEngine * _engine
Definition: console.h:42
Campaign * getCurrentCampaign() const
Return the currently running campaign.
Definition: campaigns.cpp:311
void movePC(const Common::UString &area)
Move the player character to this area.
Definition: campaign.cpp:507
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
The context managing and running the Dragon Age: Origins campaigns.
void setArguments(const Common::UString &cmd, const std::vector< Common::UString > &args)
Definition: console.cpp:1565
void cmdLoadArea(const CommandLine &cl)
Definition: console.cpp:105
bool registerCommand(const Common::UString &cmd, const CommandCallback &callback, const Common::UString &help)
Definition: console.cpp:1576
Game & getGame()
Return the context running the actual game.
Definition: dragonage.cpp:135