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 #include "ags/engine/ac/global_dialog.h"
24 #include "ags/shared/ac/common.h"
25 #include "ags/engine/ac/dialog.h"
26 #include "ags/shared/ac/dialog_topic.h"
27 #include "ags/shared/ac/game_setup_struct.h"
28 #include "ags/engine/ac/game_state.h"
29 #include "ags/engine/debugging/debug_log.h"
30 #include "ags/engine/debugging/debugger.h"
31 #include "ags/shared/debugging/out.h"
32 #include "ags/engine/script/script.h"
33 #include "ags/globals.h"
34
35 namespace AGS3 {
36
37 using namespace AGS::Shared;
38
RunDialog(int tum)39 void RunDialog(int tum) {
40 if ((tum < 0) | (tum >= _GP(game).numdialog))
41 quit("!RunDialog: invalid topic number specified");
42
43 can_run_delayed_command();
44
45 if (_GP(play).stop_dialog_at_end != DIALOG_NONE) {
46 if (_GP(play).stop_dialog_at_end == DIALOG_RUNNING)
47 _GP(play).stop_dialog_at_end = DIALOG_NEWTOPIC + tum;
48 else
49 quitprintf("!RunDialog: two NewRoom/RunDialog/StopDialog requests within dialog; last was called in \"%s\", line %d",
50 _GP(last_in_dialog_request_script_pos).Section.GetCStr(), _GP(last_in_dialog_request_script_pos).Line);
51 return;
52 }
53
54 get_script_position(_GP(last_in_dialog_request_script_pos));
55
56 if (_G(inside_script))
57 _G(curscript)->queue_action(ePSARunDialog, tum, "RunDialog");
58 else
59 do_conversation(tum);
60 }
61
62
StopDialog()63 void StopDialog() {
64 if (_GP(play).stop_dialog_at_end == DIALOG_NONE) {
65 debug_script_warn("StopDialog called, but was not in a dialog");
66 debug_script_log("StopDialog called but no dialog");
67 return;
68 }
69 get_script_position(_GP(last_in_dialog_request_script_pos));
70 _GP(play).stop_dialog_at_end = DIALOG_STOP;
71 }
72
SetDialogOption(int dlg,int opt,int onoroff,bool dlg_script)73 void SetDialogOption(int dlg, int opt, int onoroff, bool dlg_script) {
74 if ((dlg < 0) | (dlg >= _GP(game).numdialog))
75 quit("!SetDialogOption: Invalid topic number specified");
76 if ((opt < 1) | (opt > _G(dialog)[dlg].numoptions)) {
77 // Pre-3.1.1 games had "dialog scripts" that were written in different language and
78 // parsed differently; its "option-on/off" commands were more permissive.
79 if (dlg_script) {
80 Debug::Printf(kDbgGroup_Game, kDbgMsg_Error, "SetDialogOption: Invalid option number specified (%d : %d)", dlg, opt);
81 return;
82 }
83 quit("!SetDialogOption: Invalid option number specified");
84 }
85 opt--;
86
87 _G(dialog)[dlg].optionflags[opt] &= ~DFLG_ON;
88 if ((onoroff == 1) & ((_G(dialog)[dlg].optionflags[opt] & DFLG_OFFPERM) == 0))
89 _G(dialog)[dlg].optionflags[opt] |= DFLG_ON;
90 else if (onoroff == 2)
91 _G(dialog)[dlg].optionflags[opt] |= DFLG_OFFPERM;
92 }
93
GetDialogOption(int dlg,int opt)94 int GetDialogOption(int dlg, int opt) {
95 if ((dlg < 0) | (dlg >= _GP(game).numdialog))
96 quit("!GetDialogOption: Invalid topic number specified");
97 if ((opt < 1) | (opt > _G(dialog)[dlg].numoptions))
98 quit("!GetDialogOption: Invalid option number specified");
99 opt--;
100
101 if (_G(dialog)[dlg].optionflags[opt] & DFLG_OFFPERM)
102 return 2;
103 if (_G(dialog)[dlg].optionflags[opt] & DFLG_ON)
104 return 1;
105 return 0;
106 }
107
108 } // namespace AGS3
109