ScummVM API documentation
script.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef AGS_ENGINE_SCRIPT_SCRIPT_H
23#define AGS_ENGINE_SCRIPT_SCRIPT_H
24
25#include "common/std/memory.h"
26#include "common/std/vector.h"
27
28#include "ags/engine/script/cc_instance.h"
29#include "ags/engine/script/executing_script.h"
30#include "ags/engine/script/non_blocking_script_function.h"
31#include "ags/engine/ac/dynobj/script_system.h"
32#include "ags/shared/game/interactions.h"
33#include "ags/shared/util/string.h"
34
35namespace AGS3 {
36
37using AGS::Shared::String;
38using AGS::Shared::Interaction;
39using AGS::Shared::InteractionCommandList;
40using AGS::Shared::InteractionScripts;
41using AGS::Shared::InteractionVariable;
42
43#define LATE_REP_EXEC_ALWAYS_NAME "late_repeatedly_execute_always"
44#define REP_EXEC_ALWAYS_NAME "repeatedly_execute_always"
45#define REP_EXEC_NAME "repeatedly_execute"
46
47// ObjectEvent - a struct holds data of the object's interaction event,
48// such as object's reference and accompanying parameters
50 // Name of the script block to run, may be used as a formatting string;
51 // has a form of "objecttype%d"
52 String BlockName;
53 // Script block's ID, commonly corresponds to the object's ID
54 int BlockID = 0;
55 // Dynamic object this event was called for (if applicable)
56 RuntimeScriptValue DynObj;
57 // Interaction mode that triggered this event (if applicable)
58 int Mode = MODE_NONE;
59
60 ObjectEvent() = default;
61 ObjectEvent(const String &block_name, int block_id = 0)
62 : BlockName(block_name), BlockID(block_id) {}
63 ObjectEvent(const String &block_name, int block_id,
64 const RuntimeScriptValue &dyn_obj, int mode = MODE_NONE)
65 : BlockName(block_name), BlockID(block_id), DynObj(dyn_obj), Mode(mode) {}
66};
67
68int run_dialog_request(int parmtr);
69void run_function_on_non_blocking_thread(NonBlockingScriptFunction *funcToRun);
70
71// TODO: run_interaction_event() and run_interaction_script()
72// are in most part duplicating each other, except for the script callback run method.
73// May these types be made children of the same base, or stored in a group struct?
74// This would also let simplify the calling code in RunObjectInteraction, etc.
75//
76// Runs the ObjectEvent using an old interaction callback type of 'evnt' index,
77// or alternatively of 'chkAny' index, if previous does not exist;
78// 'isInv' tells if this is a inventory event (it has a slightly different handling for that)
79// Returns 0 normally, or -1 telling of a game state change (eg. a room change occurred).
80int run_interaction_event(const ObjectEvent &obj_evt, Interaction *nint, int evnt, int chkAny = -1, bool isInv = false);
81// Runs the ObjectEvent using a script callback of 'evnt' index,
82// or alternatively of 'chkAny' index, if previous does not exist
83// Returns 0 normally, or -1 telling of a game state change (eg. a room change occurred).
84int run_interaction_script(const ObjectEvent &obj_evt, InteractionScripts *nint, int evnt, int chkAny = -1);
85int run_interaction_commandlist(const ObjectEvent &obj_evt, InteractionCommandList *nicl, int *timesrun, int *cmdsrun);
86void run_unhandled_event(const ObjectEvent &obj_evt, int evnt);
87int create_global_script();
88void cancel_all_scripts();
89
90ccInstance *GetScriptInstanceByType(ScriptInstType sc_inst);
91// Queues a script function to be run either called by the engine or from another script
92void QueueScriptFunction(ScriptInstType sc_inst, const char *fn_name, size_t param_count = 0,
93 const RuntimeScriptValue *params = nullptr);
94// Try to run a script function on a given script instance
95int RunScriptFunction(ccInstance *sci, const char *tsname, size_t param_count = 0,
96 const RuntimeScriptValue *params = nullptr);
97// Run a script function in all the regular script modules, in order, where available
98// includes globalscript, but not the current room script.
99void RunScriptFunctionInModules(const char *tsname, size_t param_count = 0,
100 const RuntimeScriptValue *params = nullptr);
101// Run an obligatory script function in the current room script
102int RunScriptFunctionInRoom(const char *tsname, size_t param_count = 0,
103 const RuntimeScriptValue *params = nullptr);
104// Try to run a script function, guessing the behavior by its name and script instance type;
105// depending on the type may run a claimable callback chain
106int RunScriptFunctionAuto(ScriptInstType sc_inst, const char *fn_name, size_t param_count = 0,
107 const RuntimeScriptValue *params = nullptr);
108
109// Preallocates script module instances
110void AllocScriptModules();
111// Delete all the script instance objects
112void FreeAllScriptInstances();
113// Delete only the current room script instance
114void FreeRoomScriptInstance();
115// Deletes all the global scripts and modules;
116// this frees all of the bytecode and runtime script memory.
117void FreeGlobalScripts();
118
119String GetScriptName(ccInstance *sci);
120
121//=============================================================================
122
123char *make_ts_func_name(const char *base, int iii, int subd);
124// Performs various updates to the game after script interpreter returns control to the engine.
125// Executes actions and does changes that are not executed immediately at script command, for
126// optimisation and other reasons.
127void post_script_cleanup();
128void quit_with_script_error(const char *functionName);
129int get_nivalue(InteractionCommandList *nic, int idx, int parm);
130InteractionVariable *get_interaction_variable(int varindx);
131InteractionVariable *FindGraphicalVariable(const char *varName);
132void can_run_delayed_command();
133
134// Gets current running script position
135bool get_script_position(ScriptPosition &script_pos);
136String cc_get_callstack(int max_lines = INT_MAX);
137
138// [ikm] we keep ccInstances saved in unique_ptrs globally for now
139// (e.g. as opposed to shared_ptrs), because the script handling part of the
140// engine is quite fragile and prone to errors whenever the instance is not
141// **deleted** in precise time. This is related to:
142// - ccScript's "instances" counting, which affects script exports reg/unreg;
143// - loadedInstances array.
144// One of the examples is the save restoration, that may occur in the midst
145// of a post-script cleanup process, whilst the engine's stack still has
146// references to the ccInstances that are going to be deleted on cleanup.
147// Ideally, this part of the engine should be refactored awhole with a goal
148// to make it safe and consistent.
150
151} // namespace AGS3
152
153#endif
Definition: string.h:60
Definition: ptr.h:572
Definition: interactions.h:122
Definition: interactions.h:154
Definition: interactions.h:201
Definition: interactions.h:185
Definition: non_blocking_script_function.h:31
Definition: script.h:49
Definition: runtime_script_value.h:63
Definition: cc_instance.h:98
Definition: cc_instance.h:114