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