ScummVM API documentation
commontypes.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_COMMONYPES_H
23 #define NANCY_COMMONYPES_H
24 
25 #include "common/rect.h"
26 #include "common/array.h"
27 #include "common/language.h"
28 #include "common/path.h"
29 #include "common/str.h"
30 #include "math/vector3d.h"
31 
32 namespace Common {
33 class SeekableReadStream;
34 }
35 
36 namespace Nancy {
37 
38 class NancyEngine;
39 
40 // The original engine used a large amount of #defines for numerical constants,
41 // which can be found listed inside the gameflow.h file shipping with many of
42 // the titles (the Russian variant of nancy1 has it as a separate file, while
43 // nancy2 and above embed it within the ciftree).
44 //
45 // Other, more specific constants are declared within their related classes,
46 // so as not to litter the namespace
47 
48 static const int8 kFlagNoLabel = -1;
49 static const int8 kEvNoEvent = -1;
50 static const int8 kFrNoFrame = -1;
51 static const uint16 kNoScene = 9999;
52 
53 // Inventory items use types
54 static const byte kInvItemUseThenLose = 0;
55 static const byte kInvItemKeepAlways = 1;
56 static const byte kInvItemReturn = 2;
57 static const byte kInvItemNewSceneView = 3;
58 
59 // Inventory item sound override commands
60 static const byte kInvSoundOverrideCommandNoSound = 0;
61 static const byte kInvSoundOverrideCommandTurnOff = 1;
62 static const byte kInvSoundOverrideCommandNewSound = 2;
63 static const byte kInvSoundOverrideCommandICant = 3;
64 
65 // Dependency types
66 static const byte kFlagEvent = 1;
67 static const byte kFlagInventory = 2;
68 static const byte kFlagCursor = 3;
69 
70 // Scene panning
71 static const byte kPanNone = 0;
72 static const byte kPan360 = 1;
73 static const byte kPanLeftRight = 2;
74 
75 // Scene sound flags
76 static const byte kContinueSceneSound = 1;
77 static const byte kLoadSceneSound = 0;
78 
79 // Scene rotation special values
80 static const uint16 kInvertedNode = 77;
81 static const uint16 kNoAutoScroll = 333;
82 
83 // Clock bump types
84 static const byte kAbsoluteClockBump = 1;
85 static const byte kRelativeClockBump = 2;
86 
87 // Time of day
88 static const byte kPlayerDay = 0;
89 static const byte kPlayerNight = 1;
90 static const byte kPlayerDuskDawn = 2;
91 
92 // Video
93 static const byte kSmallVideoFormat = 1;
94 static const byte kLargeVideoFormat = 2;
95 
96 static const byte kVideoPlaytypeAVF = 0;
97 static const byte kVideoPlaytypeBink = 1;
98 
99 // Overlay
100 static const byte kPlayOverlayPlain = 1;
101 static const byte kPlayOverlayTransparent = 2;
102 
103 static const byte kPlayOverlaySceneChange = 1;
104 static const byte kPlayOverlayNoSceneChange = 2;
105 
106 static const byte kPlayOverlayStatic = 1;
107 static const byte kPlayOverlayAnimated = 2;
108 
109 static const byte kPlayOverlayOnce = 1;
110 static const byte kPlayOverlayLoop = 2;
111 
112 static const byte kPlayOverlayForward = 1;
113 static const byte kPlayOverlayReverse = 2;
114 
115 static const byte kPlayOverlayWithHotspot = 1;
116 static const byte kPlayOverlayNoHotspot = 2;
117 
118 // Table access
119 static const byte kNoChangeTableValue = 0;
120 static const byte kIncrementTableValue = 1;
121 static const byte kDecrementTableValue = 2;
122 static const uint16 kNoTableIndex = 99;
123 static const int16 kNoTableValue = 9999;
124 
125 // Autotext ordering info
126 static const uint16 kListLIFO = 0;
127 static const uint16 kListFIFO = 1;
128 
129 // 3D sound rotation
130 static const byte kRotateAroundX = 0;
131 static const byte kRotateAroundY = 1;
132 static const byte kRotateAroundZ = 2;
133 
134 enum MovementDirection : byte { kUp = 1, kDown = 2, kLeft = 4, kRight = 8, kMoveFast = 16 };
135 
136 // Separate namespace to remove possible clashes
137 namespace NancyState {
138 enum NancyState {
139  // Original engine states
140  kBoot, kLogo, kCredits, kMap,
141  kMainMenu, kLoadSave, kSetup,
142  kHelp, kScene, kSaveDialog,
143 
144  // Not real states
145  kNone,
146  kQuit,
147  kPause, // only used when the GMM is on screen
148 };
149 }
150 
151 // Describes a scene transition
153  uint16 sceneID = kNoScene;
154  uint16 frameID = 0;
155  uint16 verticalOffset = 0;
156  uint16 continueSceneSound = kLoadSceneSound;
157 
158  int8 paletteID = -1; // TVD only
159 
160  Math::Vector3d listenerFrontVector = Math::Vector3d(0, 0, 1);
161  uint16 frontVectorFrameID = 0;
162 
163  void readData(Common::SeekableReadStream &stream, bool longFormat = false);
164 };
165 
166 // Describes a single flag change or comparison
168  int16 label = -1;
169  byte flag = 0;
170 };
171 
173  SceneChangeDescription _sceneChange;
174  FlagDescription _flag;
175 
176  void readData(Common::SeekableReadStream &stream, bool reverseFormat = false);
177  void execute();
178 };
179 
180 // Describes a hotspot
182  uint16 frameID = 0;
183  Common::Rect coords;
184 
185  void readData(Common::SeekableReadStream &stream);
186 };
187 
188 // Describes a blit operation, dependent on a background frame
190  uint16 frameID = 0; // Frame ID of the Scene background
191  uint16 staticRectID = 0; // Used in Overlay
192  uint hasHotspot = kPlayOverlayNoHotspot;
193  Common::Rect src;
194  Common::Rect dest;
195 
196  void readData(Common::SeekableReadStream &stream, bool longFormat = false);
197 };
198 
199 // Describes 10 event flag changes to be executed when an action is triggered
201  FlagDescription descs[10];
202 
203  void readData(Common::SeekableReadStream &stream);
204  void execute();
205 };
206 
208  int16 frameID = kFrNoFrame;
209  Common::Rect srcRect;
210  Common::Rect destRect;
211  // 2 unknown/empty rects
212 
213  void readData(Common::SeekableReadStream &stream);
214 };
215 
216 // Describes set of effects that can be applied to sounds.
217 // Defaults are set according to the values used by PlaySoundTerse
219  uint32 minTimeDelay = 500;
220  uint32 maxTimeDelay = 2000;
221 
222  int32 randomMoveMinX = 0;
223  int32 randomMoveMaxX = 0;
224  int32 randomMoveMinY = 0;
225  int32 randomMoveMaxY = 0;
226  int32 randomMoveMinZ = 0;
227  int32 randomMoveMaxZ = 0;
228 
229  int32 fixedPosX = 0;
230  int32 fixedPosY = 0;
231  int32 fixedPosZ = 0;
232 
233  uint32 moveStepTime = 1000;
234  int32 numMoveSteps = 10;
235 
236  int32 linearMoveStartX = 0;
237  int32 linearMoveEndX = 0;
238  int32 linearMoveStartY = 0;
239  int32 linearMoveEndY = 0;
240  int32 linearMoveStartZ = 0;
241  int32 linearMoveEndZ = 0;
242 
243  int32 rotateMoveStartX = 0;
244  int32 rotateMoveStartY = 0;
245  int32 rotateMoveStartZ = 0;
246  byte rotateMoveAxis = kRotateAroundY;
247 
248  uint32 minDistance = 0;
249  uint32 maxDistance = 0;
250 
251  void readData(Common::SeekableReadStream &stream);
252 };
253 
254 // Descrbes a single sound. Combines four different structs found in the data in one
256  Common::String name = "NO SOUND";
257  uint16 channelID = 0;
258  uint16 playCommands = 1;
259  uint16 numLoops = 1;
260  uint16 volume = 50;
261  uint16 panAnchorFrame = 0;
262  uint32 samplesPerSec = 0;
263  bool isPanning = false;
264 
265  void readNormal(Common::SeekableReadStream &stream);
266  void readDIGI(Common::SeekableReadStream &stream);
267  void readMenu(Common::SeekableReadStream &stream);
268  void readScene(Common::SeekableReadStream &stream);
269  void readTerse(Common::SeekableReadStream &stream);
270 };
271 
272 // Structs inside nancy.dat, which contains all the data that was
273 // originally stored inside the executable
274 
275 enum class StaticDataConditionType { kEvent = 0, kInventory = 1, kDifficulty = 2 };
276 struct StaticDataFlag { byte type; int16 label; byte flag; };
277 
279  byte textID;
280  uint16 sceneID;
281  Common::String soundID;
283 
284  void readData(Common::SeekableReadStream &stream);
285 };
286 
288  Common::Array<uint16> sceneIDs;
290  StaticDataFlag flagToSet;
291 
292  void readData(Common::SeekableReadStream &stream);
293 };
294 
295 struct Goodbye {
296  Common::String soundID;
298 
299  void readData(Common::SeekableReadStream &stream);
300 };
301 
302 struct Hint {
303  byte textID;
304  int16 hintWeight;
305  SceneChangeDescription sceneChange;
306  Common::String soundIDs[3];
308 
309  void readData(Common::SeekableReadStream &stream);
310 };
311 
313  byte numChannels;
314  byte numSceneSpecificChannels;
315  Common::Array<byte> speechChannels;
316  Common::Array<byte> musicChannels;
317  Common::Array<byte> sfxChannels;
318 
319  void readData(Common::SeekableReadStream &stream);
320 };
321 
322 struct StaticData {
323  // Default values are for nancy1, provided for debugging purposes
324  uint16 numItems = 11;
325  uint16 numEventFlags = 168;
326  Common::Array<uint16> mapAccessSceneIDs;
327  Common::Array<uint16> genericEventFlags;
328  uint16 numCursorTypes = 4;
329  uint32 logoEndAfter = 7000;
330  int16 wonGameFlagID = -1;
331 
332  // Data for sound channels
333  SoundChannelInfo soundChannelInfo;
334 
335  // In-game strings and related logic
337  Common::Array<Goodbye> goodbyes;
339 
340  Common::Array<Common::String> conditionalDialogueTexts;
341  Common::Array<Common::String> goodbyeTexts;
343  Common::String ringingText;
344  Common::String emptySaveText;
345 
346  // Debug strings
347  Common::Array<Common::String> eventFlagNames;
348 
349  void readData(Common::SeekableReadStream &stream, Common::Language language, uint32 endPos, int8 majorVersion, int8 minorVersion);
350 };
351 
352 // Reusable button widget embedded in Nancy 10+ popup UIs.
354  static const uint kRecordSize = 239;
355  Common::Path primaryImageName;
356  Common::Path secondaryImageName;
357  uint32 id = 0;
358  Common::Rect sourceRects[4];
359  Common::Rect srcBackgroundRestore;
360  Common::Rect destRect;
361  uint32 destUsesGameFrameOffset = 0; // translate dest by game-frame origin when non-zero
362  uint32 hoverEnableFlag = 0;
363  uint32 hoverCursorFlag = 0; // swap cursor sprite on hover when set
364  uint32 secondaryStateField = 0;
365  uint32 initialState = 0; // 0=idle, 1=hover, 2=pressed, 3/4=disabled
366  uint32 reservedField = 0;
367  SoundDescription clickSound;
368 };
369 
370 // A UIButton slot. Used for the notebook tab strip (UINB) and the
371 // inventory category-filter strip (UIIV).
372 struct UIButtonSlot {
373  static const uint kRecordSize = 247;
374  uint32 enabled = 0;
375  uint32 id = 0; // slot identifier (filter category / tab)
376  UIButtonRecord button;
377 };
378 
379 // Reusable slider widget embedded in Nancy 10+ popup UIs.
381  static const uint kRecordSize = 198;
382  Common::Path primaryImageName;
383  Common::Path secondaryImageName;
384  uint32 id = 0;
385  Common::Rect sourceRects[4];
386  Common::Rect srcBackgroundRestore;
387  Common::Rect destRect;
388  uint32 destUsesGameFrameOffset = 0; // translate dest by game-frame origin when non-zero
389  uint32 unknownA = 0;
390  uint32 isDraggable = 0; // when zero, the slider stays at its current value on click
391  uint32 unknownC = 0;
392  uint32 orientation = 0; // 0 = horizontal, 1 = vertical
393  uint32 positionHint = 0; // 0/1 left/right for horiz, 2/3 top/bottom for vert
394  uint32 secondaryStateField = 0;
395  uint32 initialState = 0; // 0=idle, 1=hover, 2=dragging
396 };
397 
398 // Common header shared by all Nancy 10 popup-UI chunks
399 // (UIIV, UICO, UICL, UINB).
401  Common::Path imageName; // background image
402  uint32 unknownHeaderField = 0; // chunk version
403  int16 linkbackScene = 9999; // return scene; 9999 = none
404  Common::Rect normalSrcRect; // SRC rect on the popup overlay image when in state 2 (normal size)
405  Common::Rect maximizedSrcRect; // SRC rect on the popup overlay image when in state 3 (maximized size)
406  Common::Rect normalDestRect; // DEST rect on screen for state 2 (normal size)
407  Common::Rect maximizedDestRect; // DEST rect on screen for state 3 (maximized size)
408  uint32 overlayInGameFrame = 0; // if non-zero, both dest rects are translated during initialization
409  SoundDescription sounds[4]; // open/close/button-click sound slots
410 
411  uint32 secondaryButtonEnabled = 0;
412  UIButtonRecord secondaryButton;
413  uint32 sliderEnabled = 0;
414  UISliderRecord slider;
415 };
416 
417 } // End of namespace Nancy
418 
419 #endif // NANCY_COMMONYPES_H
Definition: commontypes.h:200
Definition: commontypes.h:322
Definition: str.h:59
Definition: commontypes.h:152
Definition: array.h:52
Definition: commontypes.h:276
Definition: commontypes.h:302
Definition: commontypes.h:278
Definition: rect.h:524
Definition: path.h:52
Definition: commontypes.h:380
Definition: stream.h:745
Definition: commontypes.h:218
Definition: commontypes.h:189
Definition: commontypes.h:295
Definition: commontypes.h:172
Definition: commontypes.h:353
Definition: commontypes.h:312
Definition: algorithm.h:29
Definition: commontypes.h:400
Definition: commontypes.h:255
Definition: commontypes.h:372
Definition: commontypes.h:167
Definition: commontypes.h:207
Definition: commontypes.h:181
Definition: commontypes.h:287
Definition: actionmanager.h:32
Language
Definition: language.h:45