ScummVM API documentation
actionrecord.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 NANCY_ACTION_ACTIONRECORD_H
23#define NANCY_ACTION_ACTIONRECORD_H
24
25#include "engines/nancy/time.h"
26#include "engines/nancy/cursor.h"
27#include "engines/nancy/commontypes.h"
28#include "engines/nancy/renderobject.h"
29
30namespace Common {
31class SeekableReadStream;
32}
33
34namespace Nancy {
35
36class NancyEngine;
37class NancyConsole;
38struct NancyInput;
39
40namespace Action {
41
42enum struct DependencyType : int16 {
43 kNone = 0,
44 kInventory = 1,
45 kEvent = 2,
46 kLogic = 3,
47 kElapsedGameTime = 4,
48 kElapsedSceneTime = 5,
49 kElapsedPlayerTime = 6,
50 kSamsSight = 7, // Not implemented
51 kSamsSound = 8, // Not implemented
52 kSceneCount = 9,
53 kElapsedPlayerDay = 10,
54 kCursorType = 11,
55 kPlayerTOD = 12,
56 // Nancy11 used types 13/14 for software-timer less-/greater-than checks (with 22
57 // for "is active"). Nancy12 moved the software-timer checks to types 22-25 and
58 // left 13/14 unused. Nancy14 then repurposed type 13 into a value-table test
59 // (label = value index, milliseconds = threshold, condition = comparison); 14
60 // stays unused.
61 kTimerLessThanDependencyTime = 13,
62 kTimerGreaterThanDependencyTime = 14,
63 kDifficultyLevel = 15,
64 kClosedCaptioning = 16,
65 kSound = 17,
66 kOpenParenthesis = 18,
67 kCloseParenthesis = 19,
68 kRandom = 20,
69 kDefaultAR = 21,
70 kTimerIsActive = 22, // Nancy11+ software-timer slot is running (or paused, in Nancy12+)
71 kTimerEqualsDependencyTime = 23, // The next three compare a running software
72 kTimerBelowDependencyTime = 24, // timer's elapsed time against the dependency's
73 kTimerAboveDependencyTime = 25, // own time, and only while that slot is running
74 kPlayerCharacter = 26 // Nancy15+ which protagonist is being played
75};
76
77// Describes a condition that needs to be fulfilled before the
78// action record can be executed
80 DependencyType type = DependencyType::kNone;
81 int16 label = -1;
82 int16 condition = -1;
83 bool orFlag = false;
84 int16 hours = -1;
85 int16 minutes = -1;
86 int16 seconds = -1;
87 int16 milliseconds = -1;
88
89 bool satisfied = false;
90 Time timeData;
91
92 // Only used for kRandom
93 bool stopEvaluating = false;
94
95 // Used to support the dependency tree structure in nancy3 and up
96 // The only valid field in dependencies with children is the orFlag
98
99 void reset();
100};
101
102// Describes a single action that will be performed on every update.
103// Supports conditional execution (via dependencies) and can have
104// clickable hotspots on screen.
105// Does _not_ support drawing to screen, records that need this functionality
106// will have to subclass RenderActionRecord.
108public:
109 enum ExecutionState { kBegin, kRun, kActionTrigger };
110 enum ExecutionType { kOneShot = 1, kRepeating = 2 };
111 ActionRecord() :
112 _type(0),
113 _execType(kOneShot),
114 _isActive(false),
115 _isDone(false),
116 _hasHotspot(false),
117 _state(ExecutionState::kBegin),
118 _cursorDependency(nullptr) {}
119 virtual ~ActionRecord() {}
120
121 virtual void readData(Common::SeekableReadStream &stream) = 0;
122 virtual void execute() {}
123 virtual void onPause(bool pause) {}
124
125 virtual CursorManager::CursorType getHoverCursor() const { return CursorManager::kHotspot; }
126 virtual bool cursorSetFromScript() const { return false; }
127 virtual void handleInput(NancyInput &input) {}
128
129 // Used for debugging
130 virtual Common::String getRecordTypeName() const = 0;
131 virtual Common::String getRecordExtraInfo() const { return ""; }
132
133 // Used for handling kCursorType dependency
134 virtual bool canHaveHotspot() const { return false; }
135
136 // Records returning true survive the upcoming scene change (i.e. are not
137 // deleted by Scene::clearSceneData / ActionManager::clearActionRecords).
138 // `nextSceneIsNoArt` is true when the incoming scene is a "NO_ART_SCENE": a
139 // videoless scene that keeps the previous scene's frame on screen and only
140 // overlays new logic. The original engine's ClearNoArtSceneData clears the
141 // conversation / sound / phone records but leaves the ambient character
142 // videos playing, so e.g. a character stays visible while a phone-call
143 // conversation runs in front of them.
144 virtual bool survivesSceneChange(bool nextSceneIsNoArt) const { return false; }
145
146protected:
147 void finishExecution();
148
149public:
150 Common::String _description;
151 Common::String _includeSource; // the included file this record came from, empty for the scene's own
152 byte _type;
153 ExecutionType _execType;
154 // 0x32 data
155 DependencyRecord _dependencies;
156 // 0x3A numDependencies
157 bool _isActive;
158 // 0x3C satisfiedDependencies[]
159 // 0x48 timers[]
160 // 0x78 orFlags[]
161 bool _isDone;
162 bool _hasHotspot;
163 Common::Rect _hotspot;
164 ExecutionState _state;
165 DependencyRecord *_cursorDependency;
166};
167
168// Base class for visual ActionRecords
169class RenderActionRecord : public virtual ActionRecord, public RenderObject {
170public:
171 RenderActionRecord(uint zOrder) : RenderObject(zOrder) {}
172 virtual ~RenderActionRecord() {}
173
175
176 // This makes sure the AR is re-added to the render system
177 // when returning from a different state (e.g. the Help screen)
178 void onPause(bool pause) override { if (!pause) registerGraphics(); }
179};
180
181// Dummy AR for classes that haven't been implemented/don't work in the current game version
183 void execute() override;
184 void readData(Common::SeekableReadStream &stream) override {}
185 Common::String getRecordTypeName() const override { return "Unimplemented"; }
186};
187
188} // End of namespace Action
189} // End of namespace Nancy
190
191#endif // NANCY_ACTION_ACTIONRECORD_H
Definition: array.h:52
Definition: stream.h:745
Definition: str.h:59
Definition: actionrecord.h:107
Definition: actionrecord.h:169
Definition: actionrecord.h:182
Definition: renderobject.h:48
Definition: algorithm.h:29
Definition: actionmanager.h:32
Definition: rect.h:536
Definition: actionrecord.h:79
Definition: input.h:41
Definition: time.h:30