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  kTimerLessThanDependencyTime = 13,
57  kTimerGreaterThanDependencyTime = 14,
58  kDifficultyLevel = 15,
59  kClosedCaptioning = 16,
60  kSound = 17,
61  kOpenParenthesis = 18,
62  kCloseParenthesis = 19,
63  kRandom = 20,
64  kDefaultAR = 21,
65  kTimerIsActive = 22 // Nancy11+ software-timer slot is running/counting
66 };
67 
68 // Describes a condition that needs to be fulfilled before the
69 // action record can be executed
71  DependencyType type = DependencyType::kNone;
72  int16 label = -1;
73  int16 condition = -1;
74  bool orFlag = false;
75  int16 hours = -1;
76  int16 minutes = -1;
77  int16 seconds = -1;
78  int16 milliseconds = -1;
79 
80  bool satisfied = false;
81  Time timeData;
82 
83  // Only used for kRandom
84  bool stopEvaluating = false;
85 
86  // Used to support the dependency tree structure in nancy3 and up
87  // The only valid field in dependencies with children is the orFlag
89 
90  void reset();
91 };
92 
93 // Describes a single action that will be performed on every update.
94 // Supports conditional execution (via dependencies) and can have
95 // clickable hotspots on screen.
96 // Does _not_ support drawing to screen, records that need this functionality
97 // will have to subclass RenderActionRecord.
98 class ActionRecord {
99 public:
100  enum ExecutionState { kBegin, kRun, kActionTrigger };
101  enum ExecutionType { kOneShot = 1, kRepeating = 2 };
102  ActionRecord() :
103  _type(0),
104  _execType(kOneShot),
105  _isActive(false),
106  _isDone(false),
107  _hasHotspot(false),
108  _state(ExecutionState::kBegin),
109  _days(-1),
110  _cursorDependency(nullptr) {}
111  virtual ~ActionRecord() {}
112 
113  virtual void readData(Common::SeekableReadStream &stream) = 0;
114  virtual void execute() {}
115  virtual void onPause(bool pause) {}
116 
117  virtual CursorManager::CursorType getHoverCursor() const { return CursorManager::kHotspot; }
118  virtual bool cursorSetFromScript() const { return false; }
119  virtual void handleInput(NancyInput &input) {}
120 
121  // Used for debugging
122  virtual Common::String getRecordTypeName() const = 0;
123  virtual Common::String getRecordExtraInfo() const { return ""; }
124 
125  // Used for handling kCursorType dependency
126  virtual bool canHaveHotspot() const { return false; }
127 
128  // Records returning true survive Scene::clearSceneData / ActionManager::clearActionRecords.
129  virtual bool isPersistentAcrossScenes() const { return false; }
130 
131 protected:
132  void finishExecution();
133 
134 public:
135  Common::String _description;
136  byte _type;
137  ExecutionType _execType;
138  // 0x32 data
139  DependencyRecord _dependencies;
140  // 0x3A numDependencies
141  bool _isActive;
142  // 0x3C satisfiedDependencies[]
143  // 0x48 timers[]
144  // 0x78 orFlags[]
145  bool _isDone;
146  bool _hasHotspot;
147  Common::Rect _hotspot;
148  ExecutionState _state;
149  int16 _days;
150  DependencyRecord *_cursorDependency;
151 };
152 
153 // Base class for visual ActionRecords
154 class RenderActionRecord : public virtual ActionRecord, public RenderObject {
155 public:
156  RenderActionRecord(uint zOrder) : RenderObject(zOrder) {}
157  virtual ~RenderActionRecord() {}
158 
160 
161  // This makes sure the AR is re-added to the render system
162  // when returning from a different state (e.g. the Help screen)
163  void onPause(bool pause) override { if (!pause) registerGraphics(); }
164 };
165 
166 // Dummy AR for classes that haven't been implemented/don't work in the current game version
167 class Unimplemented : public ActionRecord {
168  void execute() override;
169  void readData(Common::SeekableReadStream &stream) override {}
170  Common::String getRecordTypeName() const override { return "Unimplemented"; }
171 };
172 
173 } // End of namespace Action
174 } // End of namespace Nancy
175 
176 #endif // NANCY_ACTION_ACTIONRECORD_H
Definition: str.h:59
Definition: time.h:30
Definition: array.h:52
Definition: actionrecord.h:70
Definition: rect.h:536
Definition: actionrecord.h:167
Definition: stream.h:745
Definition: input.h:41
Definition: actionrecord.h:154
Definition: renderobject.h:36
Definition: actionrecord.h:98
Definition: algorithm.h:29
Definition: actionmanager.h:32