xoreos  0.0.5
dragonage2.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 "src/common/util.h"
28 #include "src/common/filelist.h"
29 #include "src/common/filepath.h"
30 #include "src/common/configman.h"
31 
32 #include "src/aurora/resman.h"
33 #include "src/aurora/language.h"
34 
36 
37 #include "src/events/events.h"
38 
43 
48 
49 namespace Engines {
50 
51 namespace DragonAge2 {
52 
54  _console.reset(new Console(*this));
55 }
56 
58 }
59 
61  switch (language) {
63  return "en-us";
65  return "fr-fr";
67  return "de-de";
69  return "it-it";
71  return "es-es";
73  return "pl-pl";
75  return "cs-cz";
77  return "hu-hu";
79  return "ru-ru";
81  return "ko-ko";
83  return "ja-ja";
84  default:
85  break;
86  }
87 
88  return "";
89 }
90 
92  Aurora::Platform UNUSED(platform),
93  std::vector<Aurora::Language> &languages) const {
94  try {
95  Common::UString tlkDir =
96  Common::FilePath::findSubDirectory(target, "packages/core/data/talktables", true);
97 
98  if (tlkDir.empty())
99  return true;
100 
101  Common::FileList tlks;
102  if (!tlks.addDirectory(tlkDir))
103  return true;
104 
105  for (size_t i = 0; i < Aurora::kLanguageMAX; i++) {
107  if (langStr.empty())
108  continue;
109 
110  if (!tlks.contains("core_" + langStr + ".tlk", true))
111  continue;
112 
113  languages.push_back((Aurora::Language) i);
114  }
115 
116  } catch (...) {
117  }
118 
119  return true;
120 }
121 
123  language = _language;
124  return true;
125 }
126 
128  Aurora::Language language;
129  if (!evaluateLanguage(false, language) || (_language != language))
130  return false;
131 
132  return true;
133 }
134 
136  assert(_game);
137 
138  return *_game;
139 }
140 
142  init();
143  if (EventMan.quitRequested())
144  return;
145 
146  CursorMan.hideCursor();
147  CursorMan.set();
148 
149  playIntroVideos();
150  if (EventMan.quitRequested())
151  return;
152 
153  CursorMan.showCursor();
154 
155  _game.reset(new Game(*this, *_console));
156  _game->run();
157 
158  deinit();
159 }
160 
162  LoadProgress progress(11);
163 
164  progress.step("Declare languages");
166 
167  if (evaluateLanguage(true, _language))
168  status("Setting the language to %s", LangMan.getLanguageName(_language).c_str());
169  else
170  warning("Failed to detect this game's language");
171 
172  LangMan.setCurrentLanguage(_language);
173 
174  progress.step("Loading user game config");
175  initConfig();
176 
177  initResources(progress);
178  if (EventMan.quitRequested())
179  return;
180 
181  progress.step("Loading game cursors");
182  initCursors();
183  if (EventMan.quitRequested())
184  return;
185 
186  progress.step("Initializing internal game config");
187  initGameConfig();
188 
189  progress.step("Successfully initialized the engine");
190 }
191 
193  static const Aurora::LanguageManager::Declaration kLanguageDeclarations[] = {
205  };
206 
207  LangMan.addLanguages(kLanguageDeclarations, ARRAYSIZE(kLanguageDeclarations));
208 }
209 
211  ResMan.setRIMsAreERFs(true);
212  ResMan.setHashAlgo(Common::kHashFNV64);
213 
214  progress.step("Setting base directory");
215  ResMan.registerDataBase(_target);
216 
217  progress.step("Adding core archive directories");
218 
219  progress.step("Indexing core resources files");
220  Game::loadResources ("/packages/core", 0, _resources, _language);
221  Game::loadTalkTables("/packages/core", 0, _languageTLK, _language);
222 
223  progress.step("Indexing extra core resources files");
224  indexMandatoryArchive("/packages/core/data/2da.rim", 450, _resources);
225  indexMandatoryArchive("/packages/core/data/chargen.gpu.rim", 451, _resources);
226  indexMandatoryArchive("/packages/core/data/chargen.rim", 452, _resources);
227  indexMandatoryArchive("/packages/core/data/designerresources.rim", 453, _resources);
228  indexMandatoryArchive("/packages/core/data/designerscripts.rim", 454, _resources);
229  indexMandatoryArchive("/packages/core/data/global-uncompressed.rim", 455, _resources);
230  indexMandatoryArchive("/packages/core/data/global.rim", 456, _resources);
231  indexMandatoryArchive("/packages/core/data/globalani-core.rim", 457, _resources);
232  indexMandatoryArchive("/packages/core/data/globalchargen-core.rim", 458, _resources);
233  indexMandatoryArchive("/packages/core/data/globalchargendds-core.gpu.rim", 459, _resources);
234  indexMandatoryArchive("/packages/core/data/globaldds-core.gpu.rim", 460, _resources);
235  indexMandatoryArchive("/packages/core/data/globalmao-core.rim", 461, _resources);
236  indexMandatoryArchive("/packages/core/data/globalvfx-core.rim", 462, _resources);
237  indexMandatoryArchive("/packages/core/data/materialobjects.rim", 463, _resources);
238  indexMandatoryArchive("/packages/core/data/pathfindingpatches.rim", 464, _resources);
239  indexMandatoryArchive("/packages/core/data/summonwardog.gpu.rim", 465, _resources);
240  indexMandatoryArchive("/packages/core/data/summonwardog.rim", 466, _resources);
241  indexMandatoryArchive("/packages/core/data/tints.rim", 467, _resources);
242 
243  progress.step("Indexing single-player campaign resources files");
244  Game::loadResources ("/modules/campaign_base", 500, _resources, _language);
245  Game::loadTalkTables("/modules/campaign_base", 500, _languageTLK, _language);
246 
247  progress.step("Registering file formats");
249 }
250 
252  CursorMan.add("area_transition" , "area_transition" , "up" );
253  CursorMan.add("area_transition_pressed" , "area_transition" , "down" );
254  CursorMan.add("attack" , "attack" , "up" );
255  CursorMan.add("attack_pressed" , "attack" , "down" );
256  CursorMan.add("chest" , "chest" , "up" );
257  CursorMan.add("chest_pressed" , "chest" , "down" );
258  CursorMan.add("close" , "close" , "up" );
259  CursorMan.add("close_pressed" , "close" , "down" );
260  CursorMan.add("converse" , "converse" , "up" );
261  CursorMan.add("converse_pressed" , "converse" , "down" );
262  CursorMan.add("destroy" , "destroy" , "up" );
263  CursorMan.add("destroy_pressed" , "destroy" , "down" );
264  CursorMan.add("dialog" , "dialog" , "up" );
265  CursorMan.add("dialog_pressed" , "dialog" , "down" );
266  CursorMan.add("disabled_disarm" , "disabled_disarm" , "up" );
267  CursorMan.add("disabled_disarm_pressed" , "disabled_disarm" , "down" );
268  CursorMan.add("disabled_unlock" , "disabled_unlock" , "up" );
269  CursorMan.add("disabled_unlock_pressed" , "disabled_unlock" , "down" );
270  CursorMan.add("disarm" , "disarm" , "up" );
271  CursorMan.add("disarm_pressed" , "disarm" , "down" );
272  CursorMan.add("door" , "door" , "up" );
273  CursorMan.add("door_pressed" , "door" , "down" );
274  CursorMan.add("dragging" , "dragging" , "" );
275  CursorMan.add("examine" , "examine" , "up" );
276  CursorMan.add("examine_pressed" , "examine" , "down" );
277  CursorMan.add("flip_cover" , "flip_cover" , "up" );
278  CursorMan.add("flip_cover_pressed" , "flip_cover" , "down" );
279  CursorMan.add("hand" , "hand" , "up" );
280  CursorMan.add("hand2" , "hand" , "down" );
281  CursorMan.add("hidden_cursor" , "hidden_cursor" , "" );
282  CursorMan.add("ibeam" , "ibeam" , "up" );
283  CursorMan.add("ibeam_pressed" , "ibeam" , "down" );
284  CursorMan.add("invalid" , "invalid" , "up" );
285  CursorMan.add("invalid_pressed" , "invalid" , "down" );
286  CursorMan.add("invalid_move" , "invalid_move" , "" );
287  CursorMan.add("open" , "open" , "up" );
288  CursorMan.add("open_pressed" , "open" , "down" );
289  CursorMan.add("open_inventory" , "open_inventory" , "up" );
290  CursorMan.add("open_inventory_pressed" , "open_inventory" , "down" );
291  CursorMan.add("panning" , "panning" , "down" );
292  CursorMan.add("panning1" , "panning" , "up" );
293  CursorMan.add("panning1_h" , "panning_h" , "up" );
294  CursorMan.add("panning1_v" , "panning_v" , "up" );
295  CursorMan.add("panning_h" , "panning_h" , "down" );
296  CursorMan.add("panning_v" , "panning_v" , "down" );
297  CursorMan.add("party_member" , "party_member" , "" );
298  CursorMan.add("standard" , "standard" , "up" );
299  CursorMan.add("standard_pressed" , "standard" , "down" );
300  CursorMan.add("standard_targeting" , "standard_targeting" , "up" );
301  CursorMan.add("standard_targeting_pressed" , "standard_targeting" , "down" );
302  CursorMan.add("target" , "target" , "up" );
303  CursorMan.add("target_pressed" , "target" , "down" );
304  CursorMan.add("target_inactive" , "target" , "inactive");
305  CursorMan.add("target_circle" , "target_circle" , "up" );
306  CursorMan.add("target_circle_pressed" , "target_circle" , "down" );
307  CursorMan.add("target_circle_invalid" , "target_circle" , "invalid" );
308  CursorMan.add("target_cone" , "target_cone" , "up" );
309  CursorMan.add("target_cone_pressed" , "target_cone" , "down" );
310  CursorMan.add("target_cone_invalid" , "target_cone" , "invalid" );
311  CursorMan.add("target_creature" , "target_creature" , "up" );
312  CursorMan.add("target_creature_pressed" , "target_creature" , "down" );
313  CursorMan.add("target_creature_invalid" , "target_creature" , "invalid" );
314  CursorMan.add("target_creaturelock" , "target_creaturelock", "up" );
315  CursorMan.add("target_creaturelock_pressed", "target_creaturelock", "down" );
316  CursorMan.add("topple" , "topple" , "up" );
317  CursorMan.add("topple_pressed" , "topple" , "down" );
318  CursorMan.add("trigger_trap" , "trigger_trap" , "up" );
319  CursorMan.add("trigger_trap_pressed" , "trigger_trap" , "down" );
320  CursorMan.add("unlock" , "unlock" , "up" );
321  CursorMan.add("unlock_pressed" , "unlock" , "down" );
322  CursorMan.add("use" , "use" , "up" );
323  CursorMan.add("use_pressed" , "use" , "down" );
324 
325  CursorMan.setDefault("standard", "up");
326 }
327 
329 }
330 
332 }
333 
337 
338  _game.reset();
339 }
340 
342  playVideo("dragon_age_ea_logo");
343 }
344 
345 } // End of namespace DragonAge2
346 
347 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
void playVideo(const Common::UString &video)
Play this video resource.
Definition: util.cpp:54
GameID
Definition: types.h:393
Generic Aurora engines resource utility functions.
static void unloadTalkTables(ChangeList &changes)
Unload this set of talk tables.
Definition: game.cpp:220
A class holding an UTF-8 string.
Definition: ustring.h:48
64bit Fowler-Noll-Vo hash by Glenn Fowler, Landon Curt Noll and Phong Vo.
Definition: hash.h:41
The global config manager.
static Common::UString getLanguageString(Aurora::Language language)
Return the string Dragon Age II uses to representing this language.
Definition: dragonage2.cpp:60
Common::ScopedPtr< Console > _console
Definition: engine.h:87
bool getLanguage(Aurora::Language &language) const
Return the game&#39;s current language.
Definition: dragonage2.cpp:122
bool evaluateLanguage(bool find, Aurora::Language &language) const
Definition: engine.cpp:198
Engine class handling Dragon Age II.
UTF-16 LE (little endian).
Definition: encoding.h:44
The context handling the gameplay in Dragon Age II.
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
Language
Definition: language.h:46
void deindexResources(Common::ChangeID &changeID)
Remove previously added resources from the ResourceManager.
Definition: resources.cpp:164
void indexMandatoryArchive(const Common::UString &file, uint32 priority, const std::vector< byte > &password, Common::ChangeID *changeID)
Definition: resources.cpp:36
void initResources(LoadProgress &progress)
Definition: dragonage2.cpp:210
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
bool changeLanguage()
Change the game&#39;s current language.
Definition: dragonage2.cpp:127
The global events manager.
Common::ScopedPtr< Game > _game
Definition: dragonage2.h:73
Types and functions related to language.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
Game & getGame()
Return the context running the actual game.
Definition: dragonage2.cpp:135
void warning(const char *s,...)
Definition: util.cpp:33
#define CursorMan
Shortcut for accessing the cursor manager.
Definition: cursorman.h:129
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
The Aurora cursor manager.
Displaying the progress in loading a game.
bool detectLanguages(Aurora::GameID game, const Common::UString &target, Aurora::Platform platform, std::vector< Aurora::Language > &languages) const
Detect which languages this game instance supports.
Definition: dragonage2.cpp:91
Common::UString _target
Definition: engine.h:85
void registerModelLoader(ModelLoader *loader)
Definition: model.cpp:37
#define LangMan
Shortcut for accessing the language manager.
Definition: language.h:275
Windows codepage 932 (Japanese, extended Shift-JIS).
Definition: encoding.h:53
A list of files.
Definition: filelist.h:35
void step(const Common::UString &description)
Take a step in advancing the progress.
void status(const char *s,...)
Definition: util.cpp:52
Windows codepage 1250 (Eastern European, Latin alphabet).
Definition: encoding.h:49
bool addDirectory(const UString &directory, int recurseDepth=0)
Add a directory to the list.
Definition: filelist.cpp:102
Generic Aurora engines utility functions.
A list of files.
Windows codepage 1251 (Eastern European, Cyrillic alphabet).
Definition: encoding.h:50
Windows codepage 1252 (Western European, Latin alphabet).
Definition: encoding.h:51
Dragon Age II model loader.
Windows codepage 949 (Korean, similar to EUC-KR).
Definition: encoding.h:55
void loadTalkTables(const Common::UString &dir, uint32 priority, ChangeList &res)
Load all talk tables in the current language found in this directory.
Definition: game.cpp:157
Platform
Definition: types.h:429
Dragon Age II (debug) console.
The global resource manager for Aurora resources.
Utility class for manipulating file paths.
static UString findSubDirectory(const UString &directory, const UString &subDirectory, bool caseInsensitive=false)
Find a directory&#39;s subdirectory.
Definition: filepath.cpp:318
bool contains(const UString &str, bool caseInsensitive) const
Does the list contain at least one file ending with the given string?
Definition: filelist.cpp:185
void loadResources(const Common::UString &dir, uint32 priority, ChangeList &res)
Load all game resource archives in the current language found in this directory.
Definition: game.cpp:150
Generic Aurora engines model functions.