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 * MIT License:
21 *
22 * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
23 *
24 * Permission is hereby granted, free of charge, to any person
25 * obtaining a copy of this software and associated documentation
26 * files (the "Software"), to deal in the Software without
27 * restriction, including without limitation the rights to use,
28 * copy, modify, merge, publish, distribute, sublicense, and/or sell
29 * copies of the Software, and to permit persons to whom the
30 * Software is furnished to do so, subject to the following
31 * conditions:
32 *
33 * The above copyright notice and this permission notice shall be
34 * included in all copies or substantial portions of the Software.
35 *
36 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
38 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
40 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
41 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
43 * OTHER DEALINGS IN THE SOFTWARE.
44 *
45 */
46
47#ifndef WAGE_SCRIPT_H
48#define WAGE_SCRIPT_H
49
50namespace Wage {
51
52class Script {
53public:
54 Script(Common::SeekableReadStream *data, int num, WageEngine *engine);
55 ~Script();
56
57private:
59
60 WageEngine *_engine;
61 World *_world;
62 int _loopCount;
63 Common::String *_inputText;
64 Designed *_inputClick;
65 bool _handled;
66
67 class Operand {
68 public:
69 union {
70 Obj *obj;
71 Chr *chr;
72 Designed *designed;
73 Scene *scene;
74 int16 number;
75 Common::String *string;
76 Designed *inputClick;
77 } _value;
78 OperandType _type;
79
80 Operand(Obj *value, OperandType type) {
81 _value.obj = value;
82 assert(type == OBJ);
83 _type = type;
84 }
85
86 Operand(Chr *value, OperandType type) {
87 _value.chr = value;
88 assert(type == CHR);
89 _type = type;
90 }
91
92 Operand(Scene *value, OperandType type) {
93 _value.scene = value;
94 assert(type == SCENE);
95 _type = type;
96 }
97
98 Operand(int value, OperandType type) {
99 _value.number = value;
100 assert(type == NUMBER);
101 _type = type;
102 }
103
104 Operand(Common::String *value, OperandType type) {
105 _value.string = value;
106 assert(type == STRING || type == TEXT_INPUT);
107 _type = type;
108 }
109
110 Operand(Designed *value, OperandType type) {
111 _value.inputClick = value;
112 assert(type == CLICK_INPUT);
113 _type = type;
114 }
115
116 ~Operand() {
117 if (_type == STRING)
118 delete _value.string;
119 }
120
121 Common::String toString() const;
122 };
123
124 struct ScriptText {
125 int offset;
126 Common::String line;
127 };
128
129public:
130 void print();
131 void printLine(int offset);
132 bool execute(World *world, int loopCount, Common::String *inputText, Designed *inputClick);
133
134private:
135 Common::String preprocessInputText(Common::String inputText);
136 Operand *readOperand();
137 Operand *readStringOperand();
138 const char *readOperator();
139 void processIf();
140 void skipBlock();
141 void skipIf();
142 bool compare(Operand *o1, Operand *o2, int comparator);
143 bool eval(Operand *lhs, const char *op, Operand *rhs);
144 bool evaluatePair(Operand *lhs, const char *op, Operand *rhs);
145 Operand *convertOperand(Operand *operand, int type);
146 bool evalClickCondition(Operand *lhs, const char *op, Operand *rhs);
147 bool evalClickEquality(Operand *lhs, Operand *rhs, bool partialMatch);
148 void processMove();
149 void processLet();
150
151 void assign(byte operandType, int uservar, uint16 value);
152
153 void convertToText();
154
155public:
156 Common::Array<ScriptText *> _scriptText;
157};
158
159} // End of namespace Wage
160
161#endif
Definition: stream.h:745
Definition: str.h:59
Definition: entities.h:131
Definition: entities.h:112
Definition: entities.h:232
Definition: entities.h:301
Definition: script.h:52
Definition: wage.h:128
Definition: world.h:61