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 
30 namespace Common {
31 class SeekableReadStream;
32 }
33 
34 namespace Nancy {
35 
36 class NancyEngine;
37 class NancyConsole;
38 struct NancyInput;
39 
40 namespace Action {
41 
42 enum 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/counting
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.
108 public:
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  _days(-1),
119  _cursorDependency(nullptr) {}
120  virtual ~ActionRecord() {}
121 
122  virtual void readData(Common::SeekableReadStream &stream) = 0;
123  virtual void execute() {}
124  virtual void onPause(bool pause) {}
125 
126  virtual CursorManager::CursorType getHoverCursor() const { return CursorManager::kHotspot; }
127  virtual bool cursorSetFromScript() const { return false; }
128  virtual void handleInput(NancyInput &input) {}
129 
130  // Used for debugging
131  virtual Common::String getRecordTypeName() const = 0;
132  virtual Common::String getRecordExtraInfo() const { return ""; }
133 
134  // Used for handling kCursorType dependency
135  virtual bool canHaveHotspot() const { return false; }
136 
137  // Records returning true survive the upcoming scene change (i.e. are not
138  // deleted by Scene::clearSceneData / ActionManager::clearActionRecords).
139  // `nextSceneIsNoArt` is true when the incoming scene is a "NO_ART_SCENE": a
140  // videoless scene that keeps the previous scene's frame on screen and only
141  // overlays new logic. The original engine's ClearNoArtSceneData clears the
142  // conversation / sound / phone records but leaves the ambient character
143  // videos playing, so e.g. a character stays visible while a phone-call
144  // conversation runs in front of them.
145  virtual bool survivesSceneChange(bool nextSceneIsNoArt) const { return false; }
146 
147 protected:
148  void finishExecution();
149 
150 public:
151  Common::String _description;
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  int16 _days;
166  DependencyRecord *_cursorDependency;
167 };
168 
169 // Base class for visual ActionRecords
170 class RenderActionRecord : public virtual ActionRecord, public RenderObject {
171 public:
172  RenderActionRecord(uint zOrder) : RenderObject(zOrder) {}
173  virtual ~RenderActionRecord() {}
174 
176 
177  // This makes sure the AR is re-added to the render system
178  // when returning from a different state (e.g. the Help screen)
179  void onPause(bool pause) override { if (!pause) registerGraphics(); }
180 };
181 
182 // Dummy AR for classes that haven't been implemented/don't work in the current game version
183 class Unimplemented : public ActionRecord {
184  void execute() override;
185  void readData(Common::SeekableReadStream &stream) override {}
186  Common::String getRecordTypeName() const override { return "Unimplemented"; }
187 };
188 
189 } // End of namespace Action
190 } // End of namespace Nancy
191 
192 #endif // NANCY_ACTION_ACTIONRECORD_H
Definition: str.h:59
Definition: time.h:30
Definition: array.h:52
Definition: actionrecord.h:79
Definition: rect.h:536
Definition: actionrecord.h:183
Definition: stream.h:745
Definition: input.h:41
Definition: actionrecord.h:170
Definition: renderobject.h:36
Definition: actionrecord.h:107
Definition: algorithm.h:29
Definition: actionmanager.h:32