1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/* Based on Archetype interpreter version 1.01 */
#ifndef ARCHETYPE_ARCHETYPE
#define ARCHETYPE_ARCHETYPE
#include "glk/glk_api.h"
#include "glk/archetype/array.h"
#include "glk/archetype/interpreter.h"
#include "glk/archetype/semantic.h"
#include "glk/archetype/statement.h"
#include "glk/archetype/string.h"
namespace Glk {
namespace Archetype {
enum DebugFlag {
DEBUG_BYTES = 0x01,
DEBUG_MSGS = 0x02,
DEBUG_EXPR = 0x04,
DEBUG_STMT = 0x08
};
/**
* Archetype game interpreter
*/
class Archetype : public GlkAPI {
private:
int _saveSlot;
winid_t _mainWindow;
String _lastOutputText;
public:
// keywords.cpp
XArrayType Literals, Vocabulary;
XArrayType Type_ID_List, Object_ID_List, Attribute_ID_List;
// parser.cpp
String Command;
int Abbreviate;
ListType Proximate;
ListType verb_names;
ListType object_names;
// semantic.cpp
XArrayType Type_List, Object_List;
ListType Overlooked;
StringPtr NullStr;
private:
/**
* Engine initialization
*/
bool initialize();
/**
* Engine cleanup
*/
void deinitialize();
/**
* Main interpreter method
*/
void interpret();
/**
* Given an object number, attribute number, anddesired_type, returns the value of the lookup
* in the given result.If the desired_type is LVALUE, then it creates a new attribute node
* in the object's own attribute list(if not already existing) and returns a pointer to it.
* If RVALUE, it evaluates any expression it may find, returning the result of the evaluation.
*
* Also performs inheritance, looking back through the object's family tree to find the attribute.
*/
void lookup(int the_obj, int the_attr, ResultType &result, ContextType &context, DesiredType desired);
/**
* Sends the given message number to the object of the given number. This procedure performs
* inheritance; that is, it will search back through the object's ancestry in order to find
* someone to perform the message.Has to do something tricky with the default message:
* it must first search the entire ancestry for an explicit message, then search again for
* a default, if none found.
* @param transport how to send the message : sending to an object,
* passing to an object, or sending(passing) to a type.
* @param message message to send
* @param recipient number of object to receive message
* @param result Output result of the sending
* @param context Context
* @returns true if the recipient handles the message; false if it doesn't
*/
bool send_message(int transport, int message_sent, int recipient, ResultType &result,
ContextType &context);
/**
* Evaluates the given expression
*/
void eval_expr(ExprTree the_expr, ResultType &result, ContextType &context, DesiredType desired);
/**
* Evaluates the given expression as though it were a condition. Will succeed if the given
* expression is not UNDEFINED and not false.
* @param the_expr Expression to evaluate
* @returns true if the condition can be considered true; false otherwise
*/
bool eval_condition(ExprTree the_expr, ContextType &context);
/**
* Given a pointer to a statement, executes that statement. Very heavily called
* @param the_stmt pointer to statement to be executed
* @param result the "value" of the execution(for example, the last expression
* of a compound statement
*/
void exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType &context);
public:
/**
* Constructor
*/
Archetype(OSystem *syst, const GlkGameDescription &gameDesc);
/**
* Run the game
*/
virtual void runGame() override;
/**
* Returns the running interpreter type
*/
virtual InterpreterType getInterpreterType() const override {
return INTERPRETER_ARCHETYPE;
}
/**
* Savegames aren't supported for Archetype games
*/
virtual Common::Error readSaveData(Common::SeekableReadStream *rs) override;
/**
* Savegames aren't supported for Archetype games
*/
virtual Common::Error writeGameData(Common::WriteStream *ws) override;
/**
* Returns true if a savegame is being loaded directly from the ScummVM launcher
*/
bool loadingSavegame() const {
return _saveSlot >= 0;
}
/**
* Handles loading the savegame specified in the ScummVM launcher
*/
Common::Error loadLauncherSavegame();
/**
* Write some text to the screen
*/
void write(const String fmt, ...);
/**
* Write a line to the screen
*/
void writeln(const String fmt, ...);
void writeln() { writeln(""); }
/**
* Read an input line typed by the player
*/
String readLine();
/**
* Read in a single key
*/
char readKey();
};
extern Archetype *g_vm;
} // End of namespace Archetype
} // End of namespace Glk
#endif
|