1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program 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 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program 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 this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 //
24 // Game initialization
25 //
26
27 #include "ags/shared/ac/common.h"
28 #include "ags/shared/ac/character_info.h"
29 #include "ags/engine/ac/game.h"
30 #include "ags/shared/ac/game_setup_struct.h"
31 #include "ags/engine/ac/game_state.h"
32 #include "ags/engine/ac/global_game.h"
33 #include "ags/engine/ac/mouse.h"
34 #include "ags/engine/ac/room.h"
35 #include "ags/engine/ac/screen.h"
36 #include "ags/engine/ac/timer.h"
37 #include "ags/engine/debugging/debug_log.h"
38 #include "ags/engine/debugging/debugger.h"
39 #include "ags/shared/debugging/out.h"
40 #include "ags/engine/device/mouse_w32.h"
41 #include "ags/engine/main/game_run.h"
42 #include "ags/engine/main/game_start.h"
43 #include "ags/engine/media/audio/audio_system.h"
44 #include "ags/engine/script/script_runtime.h"
45 #include "ags/engine/script/script.h"
46 #include "ags/ags.h"
47 #include "ags/globals.h"
48
49 namespace AGS3 {
50
51 using namespace AGS::Shared;
52 using namespace AGS::Engine;
53
start_game_init_editor_debugging()54 void start_game_init_editor_debugging() {
55 if (_G(editor_debugging_enabled)) {
56 SetMultitasking(1);
57 if (init_editor_debugging()) {
58 auto waitUntil = AGS_Clock::now() + std::chrono::milliseconds(500);
59 while (waitUntil > AGS_Clock::now()) {
60 // pick up any breakpoints in game_start
61 check_for_messages_from_editor();
62 }
63
64 ccSetDebugHook(scriptDebugHook);
65 }
66 }
67 }
68
start_game_load_savegame_on_startup()69 void start_game_load_savegame_on_startup() {
70 if (_G(loadSaveGameOnStartup) != -1) {
71 current_fade_out_effect();
72 try_restore_save(_G(loadSaveGameOnStartup));
73 }
74 }
75
start_game()76 void start_game() {
77 set_cursor_mode(MODE_WALK);
78 _GP(mouse).SetPosition(Point(160, 100));
79 newmusic(0);
80
81 _G(our_eip) = -42;
82
83 // skip ticks to account for initialisation or a restored _GP(game).
84 skipMissedTicks();
85
86 for (int kk = 0; kk < _G(numScriptModules); kk++)
87 RunTextScript(_GP(moduleInst)[kk], "game_start");
88
89 RunTextScript(_G(gameinst), "game_start");
90
91 _G(our_eip) = -43;
92
93 SetRestartPoint();
94
95 _G(our_eip) = -3;
96
97 if (_G(displayed_room) < 0) {
98 current_fade_out_effect();
99 load_new_room(_G(playerchar)->room, _G(playerchar));
100 // load_new_room updates it, but it should be -1 in the first room
101 _G(playerchar)->prevroom = -1;
102 }
103
104 first_room_initialization();
105 }
106
initialize_start_and_play_game(int override_start_room,int loadSaveGameOnStartup)107 void initialize_start_and_play_game(int override_start_room, int loadSaveGameOnStartup) {
108 //try { // BEGIN try for ALI3DEXception
109
110 set_cursor_mode(MODE_WALK);
111
112 ::AGS::g_vm->setRandomNumberSeed(_GP(play).randseed);
113 if (override_start_room)
114 _G(playerchar)->room = override_start_room;
115
116 Debug::Printf(kDbgMsg_Info, "Engine initialization complete");
117 Debug::Printf(kDbgMsg_Info, "Starting game");
118
119 start_game_init_editor_debugging();
120
121 start_game_load_savegame_on_startup();
122
123 // only start if not restored a save
124 if (_G(displayed_room) < 0)
125 start_game();
126
127 RunGameUntilAborted();
128
129 /*} catch (Ali3DException gfxException) {
130 quit((char *)gfxException._message);
131 }*/
132 }
133
134 } // namespace AGS3
135