1 /*
2 * This file is part of EasyRPG Player.
3 *
4 * EasyRPG Player is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * EasyRPG Player is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef EP_PLAYER_H
19 #define EP_PLAYER_H
20
21 // Headers
22 #include "fileext_guesser.h"
23 #include "meta.h"
24 #include "translation.h"
25 #include "game_clock.h"
26 #include "game_config.h"
27 #include <vector>
28 #include <memory>
29
30 /**
31 * Player namespace.
32 */
33 namespace Player {
34 /** Bitmask for type of emulated engine */
35 enum EngineType {
36 EngineNone = 0,
37 /** All versions of RPG Maker 2000 */
38 EngineRpg2k = 1,
39 /** All versions of RPG Maker 2003 */
40 EngineRpg2k3 = 2,
41 /** RPG Maker 2000 v1.50 or newer, 2003 v1.05 or newer */
42 EngineMajorUpdated = 4,
43 /** Official English translation (RPG Maker 2003 v1.10 or newer,
44 * or RPG Maker 2000 v.1.61 or newer) */
45 EngineEnglish = 8
46 };
47
48 /** Bitmask for activated patches */
49 enum PatchType {
50 PatchNone = 0,
51 /** DynRPG */
52 PatchDynRpg = 1,
53 /** ManiacPatch */
54 PatchManiac = 1 << 1,
55 /** Patches specified on command line, no autodetect */
56 PatchOverride = 1 << 16
57 };
58
59 /**
60 * Initializes EasyRPG Player.
61 */
62 void Init(int argc, char *argv[]);
63
64 /**
65 * Runs the game engine.
66 */
67 void Run();
68
69 /**
70 * Runs the game loop.
71 */
72 void MainLoop();
73
74 /**
75 * Pauses the game engine.
76 */
77 void Pause();
78
79 /**
80 * Resumes the game engine.
81 */
82 void Resume();
83
84 /**
85 * Updates EasyRPG Player.
86 *
87 * @param update_scene Whether to update the current scene.
88 */
89 void Update(bool update_scene = true);
90
91 /**
92 * Process input events
93 */
94 void UpdateInput();
95
96 /**
97 * Renders EasyRPG Player state to the screen
98 */
99 void Draw();
100
101 /**
102 * Returns executed game frames since player start.
103 * Should be 60 fps when game ran fast enough.
104 *
105 * @return Update frames since player start
106 */
107 int GetFrames();
108
109 /**
110 * Increment the frame counters.
111 */
112 void IncFrame();
113
114 /**
115 * Exits EasyRPG Player.
116 */
117 void Exit();
118
119 /**
120 * Parses the command line arguments.
121 */
122 Game_Config ParseCommandLine(int argc, char *argv[]);
123
124 /**
125 * Initializes all game objects
126 */
127 void CreateGameObjects();
128
129 /**
130 * Resets all game objects. Faster then CreateGameObjects because
131 * the database is not reparsed.
132 */
133 void ResetGameObjects();
134
135 /**
136 * Determine if the LDB and LMT files are not present, and if so, guess
137 * if they may have been renamed. Populates fileext_map.
138 */
139 void GuessNonStandardExtensions();
140
141 /**
142 * Loads all databases.
143 */
144 void LoadDatabase();
145
146 /**
147 * Loads savegame data.
148 *
149 * @param save_file Savegame file to load
150 * @param save_id ID of the savegame to load
151 */
152 void LoadSavegame(const std::string& save_file, int save_id = 0);
153
154 /**
155 * Starts a new game
156 */
157 void SetupNewGame();
158
159 /**
160 * Starts a new game
161 */
162 void SetupBattleTest();
163
164 /**
165 * Moves the player to the start map.
166 */
167 void SetupPlayerSpawn();
168
169 /**
170 * Gets current codepage.
171 *
172 * @return current codepage
173 */
174 std::string GetEncoding();
175
176 /** @return If engine is any version of RPG2k */
177 bool IsRPG2k();
178
179 /** @return If engine is any version of RPG2k3 */
180 bool IsRPG2k3();
181
182 /** @return If engine is RPG2k <= 1.10 */
183 bool IsRPG2kLegacy();
184
185 /** @return If engine is RPG2k3 <= v1.04 */
186 bool IsRPG2k3Legacy();
187
188 /** @return If engine is RPG2k >= 1.50 */
189 bool IsRPG2kUpdated();
190
191 /** @return If engine is RPG2k3 >= 1.05 */
192 bool IsRPG2k3Updated();
193
194 /**
195 * @return If engine is the official English RM2k release v.1.61 or newer.
196 * False if engine is RM2k3, Japanese, unofficial or v.1.60.
197 */
198 bool IsRPG2kE();
199
200 /** @return If engine is the official English RM2k3 release (v1.10) or newer. */
201 bool IsRPG2k3E();
202
203 /** @return If engine is RPG2kLegacy() or RPG2k3Legacy() */
204 bool IsLegacy();
205
206 /** @return If engine is RPG2kUpdated() or RPG2k3Updated() */
207 bool IsMajorUpdatedVersion();
208
209 /**
210 * @return If engine is the official English release (and not RM2k v.1.60,
211 * which is hard to detect).
212 */
213 bool IsEnglish();
214
215 /**
216 * @return true if encoding is CP932 (Shift-JIS, used for Japanese),
217 * false if not
218 */
219 bool IsCP932();
220
221 /**
222 * @return true if encoding is CP949 (used for Korean), false if
223 * not
224 */
225 bool IsCP949();
226
227 /**
228 * @return true if encoding is Big5 (CP950, used for Traditional
229 * Chinese), false if not
230 */
231 bool IsBig5();
232
233 /**
234 * @return true if encoding is CP936 (used for Simplified Chinese)
235 * or false if not
236 */
237 bool IsCP936();
238
239 /**
240 * @return true if game is in Chinese, Japanese, or Korean
241 * (based on the encoding), false otherwise
242 */
243 bool IsCJK();
244
245 /**
246 * @return true if encoding is CP1251 (used for languages written in
247 * Cyrillic script) or false if not
248 */
249 bool IsCP1251();
250
251 /**
252 * @return True when the DynRPG patch is active
253 */
254 bool IsPatchDynRpg();
255
256 /**
257 * @return True when the Maniac Patch is active
258 */
259 bool IsPatchManiac();
260
261 /**
262 * @return Running engine version. 2000 for RPG2k and 2003 for RPG2k3
263 */
264 int EngineVersion();
265 std::string GetEngineVersion();
266
267 /** Output program version on stdout */
268 void PrintVersion();
269
270 /** Output program usage information on stdout */
271 void PrintUsage();
272
273 /** Set the desired rendering frames per second */
274 void SetTargetFps(int fps);
275
276 /** Exit flag, if true will exit application on next Player::Update. */
277 extern bool exit_flag;
278
279 /** Reset flag, if true will restart game on next Player::Update. */
280 extern bool reset_flag;
281
282 /** Debug flag, if true will run game in debug mode. */
283 extern bool debug_flag;
284
285 /** Hide Title flag, if true title scene will run without image and music. */
286 extern bool hide_title_flag;
287
288 /** Mouse flag, if true enables mouse click and scroll wheel */
289 extern bool mouse_flag;
290
291 /** Touch flag, if true enables finger taps */
292 extern bool touch_flag;
293
294 /** Overwrite party x position */
295 extern int party_x_position;
296
297 /** Overwrite party y position */
298 extern int party_y_position;
299
300 /** Overwrite starting party members */
301 extern std::vector<int> party_members;
302
303 /** Overwrite start map */
304 extern int start_map_id;
305
306 /** New game flag, if true a new game starts directly. */
307 extern bool new_game_flag;
308
309 /** If set, savegame is loaded directly */
310 extern int load_game_id;
311
312 /** Prevent adding of RTP paths to the file finder */
313 extern bool no_rtp_flag;
314
315 /** Mutes audio playback */
316 extern bool no_audio_flag;
317
318 /** Is this project using EasyRPG files, or the RPG_RT format? */
319 extern bool is_easyrpg_project;
320
321 /** Encoding used */
322 extern std::string encoding;
323
324 /** Backslash recoded to utf8 string */
325 extern std::string escape_symbol;
326
327 /** Backslash recoded to character */
328 extern uint32_t escape_char;
329
330 /** Currently interpreted engine. */
331 extern int engine;
332
333 /** Path to replay input log from */
334 extern std::string replay_input_path;
335
336 /** Path to record input log to */
337 extern std::string record_input_path;
338
339 /** The concatenated command line */
340 extern std::string command_line;
341
342 /** Game title. */
343 extern std::string game_title;
344
345 /** Currently enabled engine patches */
346 extern int patch;
347
348 /** Meta class containing additional external data for this game. */
349 extern std::shared_ptr<Meta> meta;
350
351 /** File extension rewriter, for non-standard extensions. */
352 extern FileExtGuesser::RPG2KFileExtRemap fileext_map;
353
354 /** Translation manager, including list of languages and current translation. */
355 extern Translation translation;
356
357 /**
358 * The default speed modifier applied when the speed up button is pressed
359 * Only used for configuring the speedup, don't read this var directly use
360 * GetSpeedModifier() instead.
361 */
362 extern int speed_modifier;
363
364 /**
365 * The game logic configuration
366 */
367 extern Game_ConfigPlayer player_config;
368
369 #ifdef EMSCRIPTEN
370 /** Name of game emscripten uses */
371 extern std::string emscripten_game_name;
372 #endif
373
374 #ifdef _3DS
375 /** Is executed from a .3dsx (otherwise .cia) */
376 extern bool is_3dsx;
377 #endif
378 }
379
IsRPG2k()380 inline bool Player::IsRPG2k() {
381 return (engine & EngineRpg2k) == EngineRpg2k;
382 }
383
IsRPG2k3()384 inline bool Player::IsRPG2k3() {
385 return (engine & EngineRpg2k3) == EngineRpg2k3;
386 }
387
IsRPG2kLegacy()388 inline bool Player::IsRPG2kLegacy() {
389 return engine == EngineRpg2k;
390 }
391
IsRPG2k3Legacy()392 inline bool Player::IsRPG2k3Legacy() {
393 return engine == EngineRpg2k3;
394 }
395
IsLegacy()396 inline bool Player::IsLegacy() {
397 return IsRPG2kLegacy() || IsRPG2k3Legacy();
398 }
399
IsMajorUpdatedVersion()400 inline bool Player::IsMajorUpdatedVersion() {
401 return (engine & EngineMajorUpdated) == EngineMajorUpdated;
402 }
403
IsEnglish()404 inline bool Player::IsEnglish() {
405 return (engine & EngineEnglish) == EngineEnglish;
406 }
407
IsRPG2kUpdated()408 inline bool Player::IsRPG2kUpdated() {
409 return (IsRPG2k() && IsMajorUpdatedVersion());
410 }
411
IsRPG2k3Updated()412 inline bool Player::IsRPG2k3Updated() {
413 return (IsRPG2k3() && IsMajorUpdatedVersion());
414 }
415
IsRPG2kE()416 inline bool Player::IsRPG2kE() {
417 return (IsRPG2k() && IsEnglish());
418 }
419
IsRPG2k3E()420 inline bool Player::IsRPG2k3E() {
421 return (IsRPG2k3() && IsEnglish());
422 }
423
IsPatchDynRpg()424 inline bool Player::IsPatchDynRpg() {
425 return (patch & PatchDynRpg) == PatchDynRpg;
426 }
427
IsPatchManiac()428 inline bool Player::IsPatchManiac() {
429 return (patch & PatchManiac) == PatchManiac;
430 }
431
432 #endif
433