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 ULTIMA4_GAME_SCRIPT_H
23
#define ULTIMA4_GAME_SCRIPT_H
24
25
#include "ultima/ultima4/core/types.h"
26
#include "ultima/shared/conf/xml_node.h"
27
#include "common/file.h"
28
#include "common/list.h"
29
30
namespace
Ultima {
31
namespace
Ultima4 {
32
46
class
Script
{
47
public
:
55
class
Provider
{
56
public
:
57
virtual
~Provider
() {}
58
virtual
Common::String
translate(
Common::Array<Common::String>
&parts) = 0;
59
};
60
61
private
:
65
class
Variable {
66
public
:
67
Variable();
68
Variable(
const
Common::String
&v);
69
Variable(
const
int
&v);
70
71
int
&getInt();
72
Common::String
&getString();
73
74
void
setValue(
const
int
&v);
75
void
setValue(
const
Common::String
&v);
76
void
unset();
77
78
bool
isInt()
const
;
79
bool
isString()
const
;
80
bool
isSet()
const
;
81
82
private
:
83
int
_iVal;
84
Common::String
_sVal;
85
bool
_set;
86
};
87
88
public
:
92
enum
ReturnCode
{
93
RET_OK,
94
RET_REDIRECTED,
95
RET_STOP
96
};
97
101
enum
State
{
102
STATE_UNLOADED,
103
STATE_NORMAL,
104
STATE_DONE,
105
STATE_INPUT
106
};
107
111
enum
InputType
{
112
INPUT_CHOICE,
113
INPUT_NUMBER,
114
INPUT_STRING,
115
INPUT_DIRECTION,
116
INPUT_PLAYER,
117
INPUT_KEYPRESS
118
};
119
123
enum
Action
{
124
ACTION_SET_CONTEXT,
125
ACTION_UNSET_CONTEXT,
126
ACTION_END,
127
ACTION_REDIRECT,
128
ACTION_WAIT_FOR_KEY,
129
ACTION_WAIT,
130
ACTION_STOP,
131
ACTION_INCLUDE,
132
ACTION_FOR_LOOP,
133
ACTION_RANDOM,
134
ACTION_MOVE,
135
ACTION_SLEEP,
136
ACTION_CURSOR,
137
ACTION_PAY,
138
ACTION_IF,
139
ACTION_INPUT,
140
ACTION_ADD,
141
ACTION_LOSE,
142
ACTION_HEAL,
143
ACTION_CAST_SPELL,
144
ACTION_DAMAGE,
145
ACTION_KARMA,
146
ACTION_MUSIC,
147
ACTION_SET_VARIABLE,
148
ACTION_ZTATS
149
};
150
154
Script
();
155
~Script
();
156
160
void
addProvider
(
const
Common::String
&name,
Provider
*p);
161
165
bool
load
(
const
Common::String
&filename,
const
Common::String
&baseId,
const
Common::String
&subNodeName =
""
,
const
Common::String
&subNodeId =
""
);
166
170
void
unload
();
171
175
void
run
(
const
Common::String
&script);
176
180
ReturnCode
execute
(
Shared::XMLNode
*script,
Shared::XMLNode
*currentItem =
nullptr
,
Common::String
*output =
nullptr
);
181
185
void
_continue
();
186
190
void
resetState
();
191
void
setState(
State
state);
192
State
getState();
193
194
void
setTarget(
const
Common::String
&val);
195
void
setChoices(
const
Common::String
&val);
196
void
setVar(
const
Common::String
&name,
const
Common::String
&val);
197
void
setVar(
const
Common::String
&name,
int
val);
198
void
unsetVar(
const
Common::String
&name);
199
200
Common::String
getTarget();
201
InputType
getInputType();
202
Common::String
getInputName();
203
Common::String
getChoices();
204
int
getInputMaxLen();
205
206
private
:
210
void
translate(
Common::String
*script);
211
215
Shared::XMLNode
*find(
Shared::XMLNode
*node,
const
Common::String
&script,
const
Common::String
&choice =
""
,
bool
_default =
false
);
216
221
Common::String
getPropAsStr(
Common::List<Shared::XMLNode *>
&nodes,
const
Common::String
&prop,
bool
recursive);
222
223
Common::String
getPropAsStr(
Shared::XMLNode
*node,
const
Common::String
&prop,
bool
recursive =
false
);
224
228
int
getPropAsInt(
Common::List<Shared::XMLNode *>
&nodes,
const
Common::String
&prop,
bool
recursive);
229
230
int
getPropAsInt(
Shared::XMLNode
*node,
const
Common::String
&prop,
bool
recursive =
false
);
231
235
Common::String
getContent(
Shared::XMLNode
*node);
236
237
/*
238
* Action Functions
239
*/
243
ReturnCode
pushContext(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
244
248
ReturnCode
popContext(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
249
253
ReturnCode
end(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
254
258
ReturnCode
waitForKeypress(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
259
263
ReturnCode
redirect(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
264
268
ReturnCode
include(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
269
273
ReturnCode
wait(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
274
278
ReturnCode
forLoop(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
279
283
ReturnCode
randomScript(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
284
288
ReturnCode
move(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
289
293
ReturnCode
sleep(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
294
298
ReturnCode
cursor(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
299
303
ReturnCode
pay(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
304
308
ReturnCode
_if(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
309
313
ReturnCode
input(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
314
318
ReturnCode
add(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
319
323
ReturnCode
lose(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
324
328
ReturnCode
heal(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
329
333
ReturnCode
castSpell(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
334
338
ReturnCode
damage(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
339
343
ReturnCode
karma(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
344
348
ReturnCode
music(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
349
353
ReturnCode
setVar(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
354
358
ReturnCode
ztats(
Shared::XMLNode
*script,
Shared::XMLNode
*current);
359
360
/*
361
* Math and comparison functions
362
*/
363
370
void
mathParseChildren(
Shared::XMLNode
*math,
Common::String
*result);
371
375
int
mathValue(
const
Common::String
&str);
376
380
int
math(
int
lval,
int
rval,
Common::String
&op);
381
387
bool
mathParse(
const
Common::String
&str,
int
*lval,
int
*rval,
Common::String
*op);
388
393
void
parseOperation(
const
Common::String
&str,
Common::String
*lval,
Common::String
*rval,
Common::String
*op);
394
399
bool
compare(
const
Common::String
&str);
400
404
void
funcParse(
const
Common::String
&str,
Common::String
*funcName,
Common::String
*contents);
405
406
/*
407
* Static variables
408
*/
409
private
:
410
typedef
Common::HashMap<Common::String, Action>
ActionMap
;
411
ActionMap
_actionMap;
412
413
private
:
414
void
removeCurrentVariable(
const
Common::String
&name);
415
Shared::XMLNode
*_vendorScriptDoc;
416
Shared::XMLNode
*_scriptNode;
417
bool
_debug;
418
419
State
_state;
420
Shared::XMLNode
*_currentScript;
421
Shared::XMLNode
*_currentItem;
422
Common::List<Shared::XMLNode *>
_translationContext;
423
Common::String
_target;
424
InputType
_inputType;
425
Common::String
_inputName;
426
int
_inputMaxLen;
428
Common::String
_nounName;
429
Common::String
_idPropName;
432
Common::String
_choices;
433
int
_iterator;
434
435
Common::HashMap<Common::String, Variable *>
_variables;
436
Common::HashMap<Common::String, Provider *>
_providers;
437
};
438
439
}
// End of namespace Ultima4
440
}
// End of namespace Ultima
441
442
#endif
Common::Array< Common::String >
Common::HashMap< Common::String, Action >
Common::List
Definition:
list.h:44
Common::String
Definition:
str.h:59
Ultima::Shared::XMLNode
Definition:
xml_node.h:36
Ultima::Ultima4::Script::Provider
Definition:
script.h:55
Ultima::Ultima4::Script
Definition:
script.h:46
Ultima::Ultima4::Script::State
State
Definition:
script.h:101
Ultima::Ultima4::Script::resetState
void resetState()
Ultima::Ultima4::Script::load
bool load(const Common::String &filename, const Common::String &baseId, const Common::String &subNodeName="", const Common::String &subNodeId="")
Ultima::Ultima4::Script::Action
Action
Definition:
script.h:123
Ultima::Ultima4::Script::_continue
void _continue()
Ultima::Ultima4::Script::ReturnCode
ReturnCode
Definition:
script.h:92
Ultima::Ultima4::Script::execute
ReturnCode execute(Shared::XMLNode *script, Shared::XMLNode *currentItem=nullptr, Common::String *output=nullptr)
Ultima::Ultima4::Script::InputType
InputType
Definition:
script.h:111
Ultima::Ultima4::Script::Script
Script()
Ultima::Ultima4::Script::addProvider
void addProvider(const Common::String &name, Provider *p)
Ultima::Ultima4::Script::unload
void unload()
Ultima::Ultima4::Script::run
void run(const Common::String &script)
engines
ultima
ultima4
game
script.h
Generated on Sat Oct 24 2026 09:27:29 for ScummVM API documentation by
1.9.4