ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
room_struct.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 //
23 // RoomStruct, a class describing initial room data.
24 //
25 // Because of the imperfect implementation there is inconsistency in how
26 // this data is interpreted at the runtime.
27 // Some of that data is never supposed to be changed at runtime. Another
28 // may be changed, but these changes are lost as soon as room is unloaded.
29 // The changes that must remain in memory are kept as separate classes:
30 // see RoomStatus, RoomObject etc.
31 //
32 // Partially this is because same class was used for both engine and editor,
33 // while runtime code was not available for the editor.
34 //
35 // This is also the reason why some classes here are named with the "Info"
36 // postfix. For example, RoomObjectInfo is the initial object data, and
37 // there is also RoomObject runtime-only class for mutable data.
38 //
39 // [ivan-mogilko] In my opinion, eventually there should be only one room class
40 // and one class per room entity, regardless of whether code is shared with
41 // the editor or not. But that would require extensive refactor/rewrite of
42 // the engine code, and savegame read/write code.
43 //
44 //=============================================================================
45 
46 #ifndef AGS_SHARED_GAME_ROOM_INFO_H
47 #define AGS_SHARED_GAME_ROOM_INFO_H
48 
49 #include "common/std/memory.h"
50 #include "ags/lib/allegro.h" // RGB
51 #include "ags/shared/ac/common_defines.h"
52 #include "ags/shared/game/interactions.h"
53 #include "ags/shared/util/geometry.h"
54 #include "ags/shared/util/string.h"
55 
56 namespace AGS3 {
57 
58 struct ccScript;
59 struct SpriteInfo;
60 typedef std::shared_ptr<ccScript> PScript;
61 
62 // TODO: move the following enums under AGS::Shared namespace
63 // later, when more engine source is put in AGS namespace and
64 // refactored.
65 
66 // Room's area mask type
67 enum RoomAreaMask {
68  kRoomAreaNone = 0,
69  kRoomAreaHotspot,
70  kRoomAreaWalkBehind,
71  kRoomAreaWalkable,
72  kRoomAreaRegion
73 };
74 
75 // Room's audio volume modifier
76 enum RoomVolumeMod {
77  kRoomVolumeQuietest = -3,
78  kRoomVolumeQuieter = -2,
79  kRoomVolumeQuiet = -1,
80  kRoomVolumeNormal = 0,
81  kRoomVolumeLoud = 1,
82  kRoomVolumeLouder = 2,
83  kRoomVolumeLoudest = 3,
84  // These two options are only settable at runtime by SetMusicVolume()
85  kRoomVolumeExtra1 = 4,
86  kRoomVolumeExtra2 = 5,
87 
88  kRoomVolumeMin = kRoomVolumeQuietest,
89  kRoomVolumeMax = kRoomVolumeExtra2,
90 };
91 
92 // Extended room boolean options
93 enum RoomFlags {
94  kRoomFlag_BkgFrameLocked = 0x01
95 };
96 
97 // Flag tells that walkable area does not have continious zoom
98 #define NOT_VECTOR_SCALED -10000
99 // Flags tells that room is not linked to particular game ID
100 #define NO_GAME_ID_IN_ROOM_FILE 16325
101 
102 #define MAX_ROOM_BGFRAMES 5 // max number of frames in animating bg scene
103 
104 #define MAX_ROOM_HOTSPOTS 50 // v2.62: 20 -> 30; v2.8: -> 50
105 #define MAX_ROOM_OBJECTS_v300 40 // for some legacy logic support
106 #define MAX_ROOM_OBJECTS 256 // v3.6.0: 40 -> 256 (now limited by room format)
107 #define MAX_ROOM_REGIONS 16
108 #define MAX_WALK_AREAS 16
109 #define MAX_WALK_BEHINDS 16
110 
111 #define MAX_MESSAGES 100
112 
113 
114 namespace AGS {
115 namespace Shared {
116 
117 class Bitmap;
118 class Stream;
119 
120 typedef std::shared_ptr<Bitmap> PBitmap;
121 
122 // Various room options
123 struct RoomOptions {
124  // Index of the startup music in the room
125  // this is a deprecated option, used before 3.2.* with old audio API.
126  int StartupMusic;
127  // If saving and loading game is disabled in the room;
128  // this is a deprecated option that affects only built-in save/load dialogs
129  bool SaveLoadDisabled;
130  // If player character is turned off in the room
131  bool PlayerCharOff;
132  // Apply player character's normal view when entering this room
133  int PlayerView;
134  // Room's music volume modifier
135  RoomVolumeMod MusicVolume;
136  // A collection of RoomFlags
137  int Flags;
138 
139  RoomOptions();
140 };
141 
142 // Single room background frame
143 struct RoomBgFrame {
144  PBitmap Graphic;
145  // Palette is only valid in 8-bit games
146  RGB Palette[256];
147  // Tells if this frame should keep previous frame palette instead of using its own
148  bool IsPaletteShared;
149 
150  RoomBgFrame();
151 };
152 
153 // Describes room edges (coordinates of four edges)
154 struct RoomEdges {
155  int32_t Left;
156  int32_t Right;
157  int32_t Top;
158  int32_t Bottom;
159 
160  RoomEdges();
161  RoomEdges(int l, int r, int t, int b);
162 };
163 
164 // Room hotspot description
165 struct RoomHotspot {
166  String Name;
167  String ScriptName;
168  // Custom properties
169  StringIMap Properties;
170  // Old-style interactions
172  // Event script links
173  PInteractionScripts EventHandlers;
174 
175  // Player will automatically walk here when interacting with hotspot
176  Point WalkTo;
177 };
178 
179 // Room object description
181  int32_t Room;
182  int32_t X;
183  int32_t Y;
184  int32_t Sprite;
185  bool IsOn;
186  // Object's z-order in the room, or -1 (use Y)
187  int32_t Baseline;
188  int32_t Flags;
189  String Name;
190  String ScriptName;
191  // Custom properties
192  StringIMap Properties;
193  // Old-style interactions
195  // Event script links
196  PInteractionScripts EventHandlers;
197 
198  RoomObjectInfo();
199 };
200 
201 // Room region description
202 struct RoomRegion {
203  // Light level (-100 -> +100) or Tint luminance (0 - 255)
204  int32_t Light;
205  // Tint setting (R-B-G-S)
206  int32_t Tint;
207  // Custom properties
208  StringIMap Properties;
209  // Old-style interactions
211  // Event script links
212  PInteractionScripts EventHandlers;
213 
214  RoomRegion();
215 };
216 
217 // Walkable area description
218 struct WalkArea {
219  // Apply player character's normal view on this area
220  int32_t CharacterView;
221  // Character's scaling (-100 -> +100 %)
222  // General scaling, or scaling at the farthest point
223  int32_t ScalingFar;
224  // Scaling at the nearest point, or NOT_VECTOR_SCALED for uniform scaling
225  int32_t ScalingNear;
226  // Optional override for player character view
227  int32_t PlayerView;
228  // Top and bottom Y of the area
229  int32_t Top;
230  int32_t Bottom;
231 
232  WalkArea();
233 };
234 
235 // Walk-behind description
236 struct WalkBehind {
237  // Object's z-order in the room
238  int32_t Baseline;
239 
240  WalkBehind();
241 };
242 
243 // Room messages
244 
245 #define MSG_DISPLAYNEXT 0x01 // supercedes using alt-200 at end of message
246 #define MSG_TIMELIMIT 0x02
247 
248 struct MessageInfo {
249  int8 DisplayAs; // 0 - std display window, >=1 - as character's speech
250  int8 Flags; // combination of MSG_xxx flags
251 
252  MessageInfo();
253 };
254 
255 
256 // Room's legacy resolution type
257 enum RoomResolutionType {
258  kRoomRealRes = 0, // room should always be treated as-is
259  kRoomLoRes = 1, // created for low-resolution game
260  kRoomHiRes = 2 // created for high-resolution game
261 };
262 
263 
264 //
265 // Description of a single room.
266 // This class contains initial room data. Some of it may still be modified
267 // at the runtime, but then these changes get lost as soon as room is unloaded.
268 //
269 class RoomStruct {
270 public:
271  RoomStruct();
272  ~RoomStruct();
273 
274  // Gets if room should adjust its base size depending on game's resolution
275  inline bool IsRelativeRes() const {
276  return _resolution != kRoomRealRes;
277  }
278  // Gets if room belongs to high resolution
279  inline bool IsLegacyHiRes() const {
280  return _resolution == kRoomHiRes;
281  }
282  // Gets legacy resolution type
283  inline RoomResolutionType GetResolutionType() const {
284  return _resolution;
285  }
286 
287  // Releases room resources
288  void Free();
289  // Release room messages and scripts correspondingly. These two functions are needed
290  // at very specific occasion when only part of the room resources has to be freed.
291  void FreeMessages();
292  void FreeScripts();
293  // Init default room state
294  void InitDefaults();
295  // Set legacy resolution type
296  void SetResolution(RoomResolutionType type);
297 
298  // Gets bitmap of particular mask layer
299  Bitmap *GetMask(RoomAreaMask mask) const;
300  // Gets mask's scale relative to the room's background size
301  float GetMaskScale(RoomAreaMask mask) const;
302 
303  // TODO: see later whether it may be more convenient to move these to the Region class instead.
304  // Gets if the given region has light level set
305  bool HasRegionLightLevel(int id) const;
306  // Gets if the given region has a tint set
307  bool HasRegionTint(int id) const;
308  // Gets region's light level in -100 to 100 range value; returns 0 (default level) if region's tint is set
309  int GetRegionLightLevel(int id) const;
310  // Gets region's tint luminance in 0 to 100 range value; returns 0 if region's light level is set
311  int GetRegionTintLuminance(int id) const;
312 
313  // TODO: all members are currently public because they are used everywhere; hide them later
314 public:
315  // Game's unique ID, corresponds to GameSetupStructBase::uniqueid.
316  // If this field has a valid value and does not match actual game's id,
317  // then engine will refuse to start this room.
318  // May be set to NO_GAME_ID_IN_ROOM_FILE to let it run within any game.
319  int32_t GameID;
320  // Loaded room file's data version. This value may be used to know when
321  // the room must have behavior specific to certain version of AGS.
322  int32_t DataVersion;
323 
324  // Room region masks resolution. Defines the relation between room and mask units.
325  // Mask point is calculated as roompt / MaskResolution. Must be >= 1.
326  int32_t MaskResolution;
327  // Size of the room, in logical coordinates (= pixels)
328  int32_t Width;
329  int32_t Height;
330  // Primary room palette (8-bit games)
331  RGB Palette[256];
332 
333  // Basic room options
334  RoomOptions Options;
335 
336  // Background frames
337  int32_t BackgroundBPP; // bytes per pixel
338  size_t BgFrameCount;
339  RoomBgFrame BgFrames[MAX_ROOM_BGFRAMES];
340  // Speed at which background frames are changing, 0 - no auto animation
341  int32_t BgAnimSpeed;
342  // Edges
343  RoomEdges Edges;
344  // Region masks
345  PBitmap HotspotMask;
346  PBitmap RegionMask;
347  PBitmap WalkAreaMask;
348  PBitmap WalkBehindMask;
349  // Room entities
350  size_t HotspotCount;
351  RoomHotspot Hotspots[MAX_ROOM_HOTSPOTS];
353  size_t RegionCount;
354  RoomRegion Regions[MAX_ROOM_REGIONS];
355  size_t WalkAreaCount;
356  WalkArea WalkAreas[MAX_WALK_AREAS];
357  size_t WalkBehindCount;
358  WalkBehind WalkBehinds[MAX_WALK_BEHINDS];
359 
360  // Old numbered room messages (used with DisplayMessage, etc)
361  size_t MessageCount;
362  String Messages[MAX_MESSAGES];
363  MessageInfo MessageInfos[MAX_MESSAGES];
364 
365  // Custom properties
366  StringIMap Properties;
367  // Old-style interactions
368  InterVarVector LocalVariables;
370  // Event script links
371  PInteractionScripts EventHandlers;
372  // Compiled room script
373  PScript CompiledScript;
374  // Various extended options with string values, meta-data etc
375  StringMap StrOptions;
376 
377 private:
378  // Room's legacy resolution type, defines relation room and game's resolution
379  RoomResolutionType _resolution;
380 };
381 
382 
383 // Loads new room data into the given RoomStruct object
384 void load_room(const String &filename, RoomStruct *room, bool game_is_hires, const std::vector<SpriteInfo> &sprinfos);
385 // Checks if it's necessary and upscales low-res room backgrounds and masks for the high resolution game
386 // NOTE: it does not upscale object coordinates, because that is usually done when the room is loaded
387 void UpscaleRoomBackground(RoomStruct *room, bool game_is_hires);
388 // Ensures that all existing room masks match room background size and
389 // MaskResolution property, resizes mask bitmaps if necessary.
390 void FixRoomMasks(RoomStruct *room);
391 // Adjusts bitmap size if necessary and returns either new or old bitmap.
392 PBitmap FixBitmap(PBitmap bmp, int dst_width, int dst_height);
393 
394 } // namespace Shared
395 } // namespace AGS
396 } // namespace AGS3
397 
398 #endif
Definition: achievements_tables.h:27
Definition: vector.h:39
Definition: room_struct.h:218
Definition: interactions.h:154
Definition: room_struct.h:248
Definition: allegro_bitmap.h:44
Definition: room_struct.h:180
Definition: geometry.h:87
Definition: room_struct.h:202
Definition: room_struct.h:236
Definition: room_struct.h:143
Definition: room_struct.h:165
Definition: color.h:49
Definition: string.h:62
Definition: room_struct.h:269
Definition: room_struct.h:154
Definition: ptr.h:159
Definition: ags.h:40
Definition: room_struct.h:123
Definition: atari-screen.h:44