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 MUTATIONOFJB_SCRIPT_H
23#define MUTATIONOFJB_SCRIPT_H
24
25#include "mutationofjb/commands/command.h"
26#include "common/array.h"
27#include "common/hashmap.h"
28#include "common/hash-str.h"
29#include "common/stack.h"
30
31namespace Common {
32class SeekableReadStream;
33class String;
34}
35
36namespace MutationOfJB {
37
38class Command;
39class LabelCommand;
40class Game;
41class GotoCommand;
42class ConditionalCommand;
43class Script;
44class RandomCommand;
45struct GameData;
46
47typedef Common::Array<Command *> Commands;
48
49struct ActionInfo {
50 enum Action {
51 Look,
52 Walk,
53 Talk,
54 Use,
55 PickUp
56 };
57
58 Action _action;
59 Common::String _entity1Name;
60 Common::String _entity2Name;
61 bool _walkTo;
62 Command *_command;
63};
64
70
72public:
74 bool readLine(Common::String &line);
75 void addConditionalCommand(ConditionalCommand *command, char tag, bool firstHash);
76 void addLookSection(const Common::String &item, bool walkTo);
77
79 Command *_currentCommand;
80 Command *_lastCommand;
81
83 ConditionalCommand *_command;
84 char _tag;
85 bool _firstHash;
86 };
88 ConditionalCommandInfos _pendingCondCommands;
89
91 LabelMap _labels;
92
94 PendingGotoMap _pendingGotos;
95
96 RandomCommand *_pendingRandomCommand;
97
98 ActionInfos _actionInfos;
99 Macros _macros;
100 Startups _startups;
101 Extras _extras;
102
103private:
104};
105
107public:
108 ScriptExecutionContext(Game &game, Script *localScriptOverride = nullptr) : _game(game), _activeCommand(nullptr), _localScriptOverride(localScriptOverride) {}
109 void clear();
110
111 Command::ExecuteResult runActiveCommand();
112 Command::ExecuteResult startCommand(Command *cmd);
113 Command::ExecuteResult startStartupSection();
114
115 void pushReturnCommand(Command *);
116 Command *popReturnCommand();
117 Game &getGame();
118 GameData &getGameData();
119 Command *getMacro(const Common::String &name) const;
120 Command *getExtra(const Common::String &name) const;
121 bool isCommandRunning() const;
122
123private:
124 Game &_game;
125 Command *_activeCommand;
126 Common::Stack<Command *> _callStack;
127 Script *_localScriptOverride;
128};
129
130class Script {
131public:
132 bool loadFromStream(Common::SeekableReadStream &stream);
133 ~Script();
134
135 const ActionInfos &getActionInfos(ActionInfo::Action action);
136 const Commands &getAllCommands() const;
137 const Macros &getMacros() const;
138 const Startups &getStartups() const;
139 Command *getMacro(const Common::String &name) const;
140 Command *getStartup(uint8 startupId) const;
141 Command *getExtra(const Common::String &name) const;
142
143private:
144 void destroy();
145 Commands _allCommands;
146 ActionInfos _actionInfos[5];
147 Macros _macros;
148 Startups _startups;
149 Extras _extras;
150};
151
152}
153
154#endif
Definition: stream.h:745
Definition: stack.h:102
Definition: str.h:59
Definition: command.h:85
Definition: conditionalcommand.h:42
Definition: game.h:50
Definition: randomcommand.h:46
Definition: script.h:106
Definition: script.h:130
Definition: script.h:71
Definition: algorithm.h:29
Definition: script.h:49
Definition: gamedata.h:443