ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
px_scriptengine.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  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_GAME_ENGINE_SCRIPTENGINE_H
28 #define ICB_GAME_ENGINE_SCRIPTENGINE_H
29 
30 #include "engines/icb/common/px_string.h"
31 #include "engines/icb/common/px_game_object.h"
32 #include "engines/icb/common/px_globalvariables.h"
33 
34 namespace ICB {
35 
36 #define SCRIPT_CHECK_TEXT "SDS>"
37 #define SCRIPT_CHECK_TEXT_LEN 4
38 
39 enum scriptInterpreterReturnCodes {
40  IR_RET_END_THE_CYCLE = 0, // done enough this cycle
41  IR_RET_SCRIPT_FINISHED = 1, // current script has finished and hit closing brace
42  IR_RET_CONT_THIS_CYCLE = 2 // FN_ returned an IR_TERMINATE to interpreter so we just go around - new script or gosub
43 };
44 
45 scriptInterpreterReturnCodes RunScript(const char *&scriptData, // A pointer to the script data that can be modified
46  CGame *object, // A pointer to the object that owns this object
47  int32 *engineReturnValue = NULL,
48  const char *scriptSourceName = NULL); // A value to return to the game engine
49 
50 void SetScriptDebugging(bool8 f); // Set script debugging flag
51 
52 extern CpxGlobalScriptVariables *g_globalScriptVariables;
53 
54 #define CP_END_SCRIPT 0 // Terminate a script
55 #define CP_PUSH_INT32 1 // Push a number on to the stack
56 #define CP_PUSH_ADDRESS_LOCAL_VAR32 2 // Push the address of a local variable
57 
58 //#define CP_CALL_SCRIPT_ON_TRUE 3 // Call a script if the expression result is true
59 // Not sure where this is used
60 
61 #define CP_SKIPONFALSE 4 // Skip if the bottom value on the stack is false
62 #define CP_SKIPALLWAYS 5 // Skip a block of code
63 #define CP_SKIPONTRUE 6 // Skip if the bottom value on the stack is true
64 #define CP_RETURN 7 // return the value on the stack to the game engine
65 #define CP_PUSH_GLOBAL_VAR32 8 // Set a variable to 1
66 #define CP_POP_GLOBAL_VAR32 9 // Pop a global variable
67 #define CP_CALL_MCODE 10 // Call a machine code function
68 #define CP_QUIT 11 // Quit for a cycle
69 #define CP_PUSH_STRING 12 // Push a pointer to a string
70 //#define CP_LINE_NUMBER 13 // Notify a change of script line number
71 #define CP_CALL_VSCRIPT_ON_TRUE 14 // Call a virtual script if the expression result is true
72 // The script name is taken from the object virtual
73 // script table
74 #define CP_SAVE_MCODE_START 15 // Save the mcode code start for restarting when necessary
75 #define CP_PUSH_LOCAL_VAR32 16 // Push a local variable on to the stack
76 #define CP_POP_LOCAL_VAR32 17 // Pop a local variable from the stack
77 #define CP_PUSH_LOCAL_VARSTRING 18 // Push a local variable on to the stack
78 #define CP_DEBUG 19 // A debug command
79 #define CP_INITIALISEGLOBAL 20 // Initialise a global variable
80 
81 #define CP_SWITCH 21 // takes value of the stack and uses with switch table...
82 
83 #define CP_PUSH_0 22 // push 0 on the stack (a slight speed advantage and a space saving)
84 #define CP_PUSH_1 23 // push 1 on the stack (a slight speed advantage and a space saving)
85 
86 // It was decided that the following fix to the return code of fn routines
87 // in expressions was not to be applied, but the code has been kept just in
88 // case
89 
90 // special push variations to save space
91 #define CP_PUSH_INT16 26
92 #define CP_PUSH_INT8 27
93 #define CP_PUSH_STRING_REFERENCE 28
94 
95 // An invalid token
96 #define CP_INVALID_TOKEN 29 // For functions where a token is required, but not appropriate
97 
98 // Binary Operators
99 
100 #define OP_ISEQUAL 30 // '=='
101 #define OP_PLUS 31 // '+'
102 #define OP_TIMES 32 // '*'
103 #define OP_MINUS 33 // '-'
104 #define OP_DIVIDE 34 // '/'
105 #define OP_LSTHAN 35 // <
106 #define OP_NOTEQUAL 36 // '!='
107 #define OP_ANDAND 37 // &&
108 #define OP_OROR 38 // || or OR
109 #define OP_GTTHAN 39 // >
110 #define OP_GTTHANE 41 // >=
111 #define OP_LSTHANE 42 // <=
112 
113 // Unary Operators
114 
115 #define TK_UNARY_NOT 50 // ! Invert a boolean
116 #define TK_UNARY_MINUS 51 // - Negate a number
117 
118 // a special op which pushes the string "player" onto the stack
119 #define CP_PUSH_STRING_PLAYER 52
120 
121 // a new version of call_mcode which sets inside expression to true (saves 1 byte per fn_call)
122 #define CP_CALL_MCODE_EXPR 53
123 
124 // Command tokens, only ever used internally
125 #define CT_IF 100 // An if statement
126 #define CT_CLOSEBRACKET 101 // )
127 #define CT_SEMICOLON 102 // ;
128 #define CT_ONCE 103 // the 'once' command
129 #define CT_CLOSEBRACE 104 // }
130 #define CT_DOUBLECLOSEBRACE 105 // Two tab indent reduction
131 #define CT_DO 106 // the 'do' command
132 #define CT_RETURN 107 // return a value to the engine
133 #define CT_SWITCH 108 // Switch
134 #define CT_QUIT 109 // Quit for a cycle
135 #define CT_COMMA 110 // ,
136 #define CT_OPENBRACE 111 // {
137 #define CT_DEBUG 112 // Debug commands
138 #define CT_INITIALISEGLOBAL 113 // Initialise a global variable
139 #define CT_WHILE 114 // the 'while' command
140 
141 } // End of namespace ICB
142 
143 #endif
Definition: actor.h:32