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 // Nancy15 alternates between three protagonists (Nancy and the Hardy boys
54 // Frank and Joe), each of whom keeps their own UI and journal. The two
55 // brothers share their progress: whichever is played second inherits it
56 // from the other.
57 static const uint kMaxPlayerCharacters = 3;
58 static const uint kPlayerCharacterFrank = 1;
59 static const uint kPlayerCharacterJoe = 2;
60 
61 // Inventory action records name the character whose inventory they change.
62 // This value stands for whoever is being played at the time.
63 static const byte kPlayerCharacterActive = 9;
64 
65 // Taskbar popup UI types. Shared by ControlUIItems (AR 29), UIPopupPrepScene
66 // (AR 32) and the Scene UI-prep-scene machinery.
67 enum UIType {
68  kUITypeInventory = 1,
69  kUITypeNotebook = 2,
70  kUITypeCellphone = 3
71 };
72 
73 // Inventory items use types
74 static const byte kInvItemUseThenLose = 0;
75 static const byte kInvItemKeepAlways = 1;
76 static const byte kInvItemReturn = 2;
77 static const byte kInvItemNewSceneView = 3;
78 
79 // Inventory item sound override commands
80 static const byte kInvSoundOverrideCommandNoSound = 0;
81 static const byte kInvSoundOverrideCommandTurnOff = 1;
82 static const byte kInvSoundOverrideCommandNewSound = 2;
83 static const byte kInvSoundOverrideCommandICant = 3;
84 
85 // Dependency types
86 static const byte kFlagEvent = 1;
87 static const byte kFlagInventory = 2;
88 static const byte kFlagCursor = 3;
89 
90 // Scene panning
91 static const byte kPanNone = 0;
92 static const byte kPan360 = 1;
93 static const byte kPanLeftRight = 2;
94 
95 // Scene sound flags
96 static const byte kContinueSceneSound = 1;
97 static const byte kLoadSceneSound = 0;
98 
99 // Scene rotation special values
100 static const uint16 kInvertedNode = 77;
101 static const uint16 kNoAutoScroll = 333;
102 
103 // Clock bump types
104 static const byte kAbsoluteClockBump = 1;
105 static const byte kRelativeClockBump = 2;
106 
107 // Time of day
108 static const byte kPlayerDay = 0;
109 static const byte kPlayerNight = 1;
110 static const byte kPlayerDuskDawn = 2;
111 
112 // Video
113 static const byte kSmallVideoFormat = 1;
114 static const byte kLargeVideoFormat = 2;
115 
116 // Video container. Auto picks per game type.
117 static const byte kVideoPlaytypeAVF = 0;
118 static const byte kVideoPlaytypeBink = 1;
119 static const byte kVideoPlaytypeAuto = 2;
120 
121 // Overlay transparency mode. 1 = opaque, anything >= kPlayOverlayTransparent is
122 // drawn transparent (the original engine is 16bpp color-key, with no alpha/blend
123 // path, so every transparent mode - Nancy12 also uses 3 - is a plain color key).
124 static const byte kPlayOverlayPlain = 1;
125 static const byte kPlayOverlayTransparent = 2;
126 static const byte kPlayOverlayTransparent2 = 3;
127 
128 static const byte kPlayOverlaySceneChange = 1;
129 static const byte kPlayOverlayNoSceneChange = 2;
130 
131 static const byte kPlayOverlayStatic = 1;
132 static const byte kPlayOverlayAnimated = 2;
133 
134 static const byte kPlayOverlayOnce = 1;
135 static const byte kPlayOverlayLoop = 2;
136 
137 static const byte kPlayOverlayForward = 1;
138 static const byte kPlayOverlayReverse = 2;
139 
140 static const byte kPlayOverlayWithHotspot = 1;
141 static const byte kPlayOverlayNoHotspot = 2;
142 
143 // Table access
144 static const byte kNoChangeTableValue = 0;
145 static const byte kIncrementTableValue = 1;
146 static const byte kDecrementTableValue = 2;
147 static const uint16 kNoTableIndex = 99;
148 static const int16 kNoTableValue = 9999;
149 
150 // Autotext ordering info
151 static const uint16 kListLIFO = 0;
152 static const uint16 kListFIFO = 1;
153 
154 // 3D sound rotation
155 static const byte kRotateAroundX = 0;
156 static const byte kRotateAroundY = 1;
157 static const byte kRotateAroundZ = 2;
158 
159 enum MovementDirection : byte { kUp = 1, kDown = 2, kLeft = 4, kRight = 8, kMoveFast = 16 };
160 
161 // Separate namespace to remove possible clashes
162 namespace NancyState {
163 enum NancyState {
164  // Original engine states
165  kBoot, kLogo, kCredits, kMap,
166  kMainMenu, kLoadSave, kSetup,
167  kHelp, kScene, kSaveDialog,
168  kDesignSelect, // Nancy15 only
169 
170  // Not real states
171  kNone,
172  kQuit,
173  kPause, // only used when the GMM is on screen
174 };
175 }
176 
177 // Describes a scene transition
179  uint16 sceneID = kNoScene;
180  uint16 frameID = 0;
181  uint16 verticalOffset = 0;
182  uint16 continueSceneSound = kLoadSceneSound;
183 
184  int8 paletteID = -1; // TVD only
185 
186  Math::Vector3d listenerFrontVector = Math::Vector3d(0, 0, 1);
187  uint16 frontVectorFrameID = 0;
188 
189  void readData(Common::SeekableReadStream &stream, bool longFormat = false);
190 };
191 
192 // Describes a single flag change or comparison
194  int16 label = -1;
195  byte flag = 0;
196 };
197 
199  SceneChangeDescription _sceneChange;
200  FlagDescription _flag;
201 
202  void readData(Common::SeekableReadStream &stream, bool reverseFormat = false, bool terse = false);
203  void execute();
204 };
205 
206 // Describes a hotspot
208  uint16 frameID = 0;
209  Common::Rect coords;
210 
211  void readData(Common::SeekableReadStream &stream);
212 };
213 
214 // Describes a blit operation, dependent on a background frame
216  uint16 frameID = 0; // Frame ID of the Scene background
217  uint16 staticRectID = 0; // Used in Overlay
218  uint hasHotspot = kPlayOverlayNoHotspot;
219  Common::Rect src;
220  Common::Rect dest;
221 
222  void readData(Common::SeekableReadStream &stream, bool longFormat = false);
223 };
224 
225 // Describes 10 event flag changes to be executed when an action is triggered
227  FlagDescription descs[10];
228 
229  void readData(Common::SeekableReadStream &stream);
230  void execute();
231 };
232 
233 // A Nancy 10+ cellphone list entry: an email message (mode 0) or a web-search
234 // link (mode 1). Added at runtime by AR 131 (AddSearchLink); the first entry of
235 // each list may instead be embedded in the UICL chunk. Which fields are used
236 // depends on the mode (see CellPhonePopup). The byte layout differs per source,
237 // so each site fills the fields itself rather than sharing a readData.
238 struct SearchLink {
239  Common::String key; // CVTX key whose looked-up text is the list row
240  Common::String value; // body CVTX key (email); unused for search
241  int16 extra = 0; // page index (search); unused for email
242  int16 flag = 0; // stored by the original but unused; reserved
243  int16 eventFlag = -1; // event-flag index set when the entry is opened
244  bool read = false; // email only: set once the message is opened
245 };
246 
248  int16 frameID = kFrNoFrame;
249  Common::Rect srcRect;
250  Common::Rect destRect;
251  // 2 unknown/empty rects
252 
253  void readData(Common::SeekableReadStream &stream, bool hasTrailingRects = false);
254 };
255 
256 // Describes set of effects that can be applied to sounds.
257 // Defaults are set according to the values used by PlaySoundTerse
259  uint32 minTimeDelay = 500;
260  uint32 maxTimeDelay = 2000;
261 
262  int32 randomMoveMinX = 0;
263  int32 randomMoveMaxX = 0;
264  int32 randomMoveMinY = 0;
265  int32 randomMoveMaxY = 0;
266  int32 randomMoveMinZ = 0;
267  int32 randomMoveMaxZ = 0;
268 
269  int32 fixedPosX = 0;
270  int32 fixedPosY = 0;
271  int32 fixedPosZ = 0;
272 
273  uint32 moveStepTime = 1000;
274  int32 numMoveSteps = 10;
275 
276  int32 linearMoveStartX = 0;
277  int32 linearMoveEndX = 0;
278  int32 linearMoveStartY = 0;
279  int32 linearMoveEndY = 0;
280  int32 linearMoveStartZ = 0;
281  int32 linearMoveEndZ = 0;
282 
283  int32 rotateMoveStartX = 0;
284  int32 rotateMoveStartY = 0;
285  int32 rotateMoveStartZ = 0;
286  byte rotateMoveAxis = kRotateAroundY;
287 
288  uint32 minDistance = 0;
289  uint32 maxDistance = 0;
290 
291  void readData(Common::SeekableReadStream &stream);
292 };
293 
294 // Descrbes a single sound. Combines four different structs found in the data in one
296  Common::String name = "NO SOUND";
297  uint16 channelID = 0;
298  uint16 playCommands = 1;
299  uint16 numLoops = 1;
300  uint16 volume = 50;
301  uint16 panAnchorFrame = 0;
302  uint32 samplesPerSec = 0;
303  bool isPanning = false;
304 
305  void readNormal(Common::SeekableReadStream &stream);
306  void readDIGI(Common::SeekableReadStream &stream);
307  void readMenu(Common::SeekableReadStream &stream);
308  void readScene(Common::SeekableReadStream &stream);
309  void readTerse(Common::SeekableReadStream &stream);
310 };
311 
312 // The "random sound" block shared by some Nancy 12 puzzles
315  int16 channel = 0;
316  int32 numLoops = 0;
317  int16 volume = 0;
318 
319  void readData(Common::SeekableReadStream &stream);
320 };
321 
322 // Structs inside nancy.dat, which contains all the data that was
323 // originally stored inside the executable
324 
325 enum class StaticDataConditionType { kEvent = 0, kInventory = 1, kDifficulty = 2 };
326 struct StaticDataFlag { byte type; int16 label; byte flag; };
327 
329  byte textID;
330  uint16 sceneID;
331  Common::String soundID;
333 
334  void readData(Common::SeekableReadStream &stream);
335 };
336 
338  Common::Array<uint16> sceneIDs;
340  StaticDataFlag flagToSet;
341 
342  void readData(Common::SeekableReadStream &stream);
343 };
344 
345 struct Goodbye {
346  Common::String soundID;
348 
349  void readData(Common::SeekableReadStream &stream);
350 };
351 
352 struct Hint {
353  byte textID;
354  int16 hintWeight;
355  SceneChangeDescription sceneChange;
356  Common::String soundIDs[3];
358 
359  void readData(Common::SeekableReadStream &stream);
360 };
361 
363  byte numChannels;
364  byte numSceneSpecificChannels;
365  Common::Array<byte> speechChannels;
366  Common::Array<byte> musicChannels;
367  Common::Array<byte> sfxChannels;
368 
369  void readData(Common::SeekableReadStream &stream);
370 };
371 
372 struct StaticData {
373  // Default values are for nancy1, provided for debugging purposes
374  uint16 numItems = 11;
375  uint16 numEventFlags = 168;
376  Common::Array<uint16> mapAccessSceneIDs;
377  Common::Array<uint16> genericEventFlags;
378  uint16 numCursorTypes = 4;
379  uint32 logoEndAfter = 7000;
380  int16 wonGameFlagID = -1;
381 
382  // Data for sound channels
383  SoundChannelInfo soundChannelInfo;
384 
385  // In-game strings and related logic
387  Common::Array<Goodbye> goodbyes;
389 
390  Common::Array<Common::String> conditionalDialogueTexts;
391  Common::Array<Common::String> goodbyeTexts;
393  Common::String ringingText;
394  Common::String emptySaveText;
395 
396  // Debug strings
397  Common::Array<Common::String> eventFlagNames;
398 
399  void readData(Common::SeekableReadStream &stream, Common::Language language, uint32 endPos, int8 majorVersion, int8 minorVersion);
400 };
401 
402 // Source-rect order shared by the close button and slider widgets in the
403 // Nancy 10+ popup header. The tab/filter strips use a different order, with
404 // the active entry at index 0.
405 enum UIButtonState {
406  kUIButtonIdle = 0,
407  kUIButtonHover = 1,
408  kUIButtonPressed = 2, // dragging, for sliders
409  kUIButtonDisabled = 3
410 };
411 
412 // Reusable button widget embedded in Nancy 10+ popup UIs.
414  static const uint kRecordSize = 239;
415  Common::Path primaryImageName;
416  Common::Path secondaryImageName;
417  uint32 id = 0;
418  Common::Rect sourceRects[4];
419  Common::Rect srcBackgroundRestore;
420  Common::Rect destRect;
421  uint32 destUsesGameFrameOffset = 0; // translate dest by game-frame origin when non-zero
422  uint32 hoverEnableFlag = 0;
423  uint32 hoverCursorFlag = 0; // swap cursor sprite on hover when set
424  uint32 secondaryStateField = 0;
425  uint32 initialState = 0; // 0=idle, 1=hover, 2=pressed, 3/4=disabled
426  uint32 reservedField = 0;
427  SoundDescription clickSound;
428 };
429 
430 // A UIButton slot. Used for the notebook tab strip (UINB) and the
431 // inventory category-filter strip (UIIV).
432 struct UIButtonSlot {
433  static const uint kRecordSize = 247;
434  uint32 enabled = 0;
435  uint32 id = 0; // slot identifier (filter category / tab)
436  UIButtonRecord button;
437 };
438 
439 // Reusable slider widget embedded in Nancy 10+ popup UIs.
441  static const uint kRecordSize = 198;
442  Common::Path primaryImageName;
443  Common::Path secondaryImageName;
444  uint32 id = 0;
445  Common::Rect sourceRects[4];
446  Common::Rect srcBackgroundRestore;
447  Common::Rect destRect;
448  uint32 destUsesGameFrameOffset = 0; // translate dest by game-frame origin when non-zero
449  uint32 unknownA = 0;
450  uint32 isDraggable = 0; // when zero, the slider stays at its current value on click
451  uint32 unknownC = 0;
452  uint32 orientation = 0; // 0 = horizontal, 1 = vertical
453  uint32 positionHint = 0; // 0/1 left/right for horiz, 2/3 top/bottom for vert
454  uint32 secondaryStateField = 0;
455  uint32 initialState = 0; // 0=idle, 1=hover, 2=dragging
456 };
457 
458 // Common header shared by all Nancy 10 popup-UI chunks
459 // (UIIV, UICO, UICL, UINB).
461  Common::Path imageName; // background image
462  uint32 unknownHeaderField = 0; // chunk version
463  int16 linkbackScene = 9999; // return scene; 9999 = none
464  Common::Rect normalSrcRect; // SRC rect on the popup overlay image when in state 2 (normal size)
465  Common::Rect maximizedSrcRect; // SRC rect on the popup overlay image when in state 3 (maximized size)
466  Common::Rect normalDestRect; // DEST rect on screen for state 2 (normal size)
467  Common::Rect maximizedDestRect; // DEST rect on screen for state 3 (maximized size)
468  uint32 overlayInGameFrame = 0; // if non-zero, both dest rects are translated during initialization
469  SoundDescription sounds[4]; // open/close/button-click sound slots
470 
471  uint32 secondaryButtonEnabled = 0;
472  UIButtonRecord secondaryButton;
473  uint32 sliderEnabled = 0;
474  UISliderRecord slider;
475 };
476 
477 } // End of namespace Nancy
478 
479 #endif // NANCY_COMMONYPES_H
Definition: commontypes.h:226
Definition: commontypes.h:372
Definition: str.h:59
Definition: commontypes.h:178
Definition: commontypes.h:326
Definition: commontypes.h:352
Definition: commontypes.h:328
Definition: rect.h:536
Definition: path.h:52
Definition: commontypes.h:440
Definition: stream.h:745
Definition: commontypes.h:258
Definition: commontypes.h:215
Definition: commontypes.h:345
Definition: commontypes.h:198
Definition: commontypes.h:413
Definition: commontypes.h:362
Definition: commontypes.h:313
Definition: algorithm.h:29
Definition: commontypes.h:460
Definition: commontypes.h:295
Definition: commontypes.h:432
Definition: commontypes.h:193
Definition: commontypes.h:247
Definition: commontypes.h:207
Definition: commontypes.h:337
Definition: actionmanager.h:32
Language
Definition: language.h:45