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