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 
31 namespace Common {
32 class SeekableReadStream;
33 class String;
34 }
35 
36 namespace MutationOfJB {
37 
38 class Command;
39 class LabelCommand;
40 class Game;
41 class GotoCommand;
42 class ConditionalCommand;
43 class Script;
44 class RandomCommand;
45 struct GameData;
46 
47 typedef Common::Array<Command *> Commands;
48 
49 struct 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 
72 public:
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 
103 private:
104 };
105 
107 public:
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 
123 private:
124  Game &_game;
125  Command *_activeCommand;
126  Common::Stack<Command *> _callStack;
127  Script *_localScriptOverride;
128 };
129 
130 class Script {
131 public:
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 
143 private:
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: str.h:59
Definition: script.h:106
Definition: game.h:50
Definition: randomcommand.h:46
Definition: script.h:130
Definition: stream.h:745
Definition: script.h:71
Definition: command.h:85
Definition: animationdecoder.h:36
Definition: conditionalcommand.h:42
Definition: algorithm.h:29
Definition: gamedata.h:443
Definition: script.h:49
Definition: stack.h:102