ScummVM API documentation
rooms.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 ALCACHOFA_ROOMS_H
23 #define ALCACHOFA_ROOMS_H
24 
25 #include "alcachofa/objects.h"
26 
27 namespace Alcachofa {
28 
29 class World;
30 
31 class Room {
32 public:
33  static constexpr const char *kClassName = "CHabitacion";
34  Room(World *world, Common::SeekableReadStream &stream);
35  virtual ~Room();
36 
37  inline World &world() { return *_world; }
38  inline uint8 mapIndex() const { return _mapIndex; }
39  inline const Common::String &name() const { return _name; }
40  inline const PathFindingShape *activeFloor() const {
41  return _activeFloorI < 0 ? nullptr : &_floors[_activeFloorI];
42  }
43  inline int8 orderAt(Common::Point query) const {
44  return _activeFloorI < 0 ? 49 : activeFloor()->orderAt(query);
45  }
46  inline float depthAt(Common::Point query) const {
47  return _activeFloorI < 0 ? 1 : activeFloor()->depthAt(query);
48  }
49  inline uint8 characterAlphaTint() const { return _characterAlphaTint; }
50  inline uint8 characterAlphaPremultiplier() const { return _characterAlphaPremultiplier; }
51  inline bool fixedCameraOnEntering() const { return _fixedCameraOnEntering; }
52  inline int musicID() const { return _musicId; }
53 
54  using ObjectIterator = Common::Array<ObjectBase *>::const_iterator;
55  inline ObjectIterator beginObjects() const { return _objects.begin(); }
56  inline ObjectIterator endObjects() const { return _objects.end(); }
57 
58  void update();
59  void draw();
60  virtual bool updateInput();
61  virtual void loadResources();
62  virtual void freeResources();
63  virtual void syncGame(Common::Serializer &serializer);
64  ObjectBase *getObjectByName(const char *name) const;
65  void toggleActiveFloor();
66  void debugPrint(bool withObjects) const;
67 
68 protected:
69  Room(World *world);
70  void readRoomV1(Common::SeekableReadStream &stream);
71  void readRoomV2and3(Common::SeekableReadStream &stream, bool hasUselessByte);
72  void readObjects(Common::SeekableReadStream &stream);
73  void initBackground();
74  void updateScripts();
75  void updateRoomBounds();
76  void updateInteraction();
77  void updateObjects();
78  void drawObjects();
79  void drawDebug();
80  ShapeObject *getSelectedObject(ShapeObject *best = nullptr) const;
81 
82  World *_world;
83  ObjectBase *_backgroundObject = nullptr;
84  Common::String _name, _backgroundName;
85  PathFindingShape _floors[2];
86  bool _fixedCameraOnEntering = false;
87  int8 _activeFloorI = -1;
88  int _musicId = -1;
89  int16 _backgroundScale = kBaseScale;
90  uint8
91  _mapIndex,
92  _characterAlphaTint = 0,
94 
96 };
97 
98 // only used for V1 where Rooms by default have no floor
99 class RoomWithFloor final : public Room {
100 public:
101  static constexpr const char *kClassName = "CHabitacionConSuelo";
103 };
104 
105 class OptionsMenu final : public Room {
106 public:
107  static constexpr const char *kClassName = "CHabitacionMenuOpciones";
109 
110  bool updateInput() override;
111  void loadResources() override;
112 
113  void clearLastSelectedObject(); // to reset arm animation
114  inline SlideButton *&currentSlideButton() { return _currentSlideButton; }
115 
116 private:
117  ShapeObject *_lastSelectedObject = nullptr;
118  ObjectBase *_idleArm = nullptr;
119  SlideButton *_currentSlideButton = nullptr;
120 };
121 
122 class ConnectMenu final : public Room {
123 public:
124  static constexpr const char *kClassName = "CHabitacionConectar";
126 };
127 
128 class ListenMenu final : public Room {
129 public:
130  static constexpr const char *kClassName = "CHabitacionEsperar";
132 };
133 
134 class Inventory final : public Room {
135 public:
136  static constexpr const char *kClassName = "CInventario";
137  Inventory(World *world, Common::SeekableReadStream &stream);
138  ~Inventory() override;
139 
140  bool updateInput() override;
141 
142  void initItems();
143  void updateItemsByActiveCharacter();
144  void drawAsOverlay(int32 scrollY);
145  void open();
146  void close();
147 
148 private:
149  Item *getHoveredItem();
150 
151  Common::Array<Item *> _items;
152 };
153 
154 enum class GlobalAnimationKind {
155  GeneralFont = 0,
156  DialogFont,
157  Cursor,
158  MortadeloIcon,
159  FilemonIcon,
160  InventoryIcon,
161  MortadeloDisabledIcon, // only used for multiplayer
162  FilemonDisabledIcon,
163  InventoryDisabledIcon,
164 
165  Count
166 };
167 
168 constexpr char kNoXORKey = 0;
169 constexpr char kEmbeddedXORKey = -128;
170 
171 class World final {
172 public:
173  ~World();
174  void load();
175 
176  // reference-returning queries will error if the object does not exist
177 
178  using RoomIterator = Common::Array<const Room *>::const_iterator;
179  inline RoomIterator beginRooms() const { return _rooms.begin(); }
180  inline RoomIterator endRooms() const { return _rooms.end(); }
181  inline Room &globalRoom() const { assert(_globalRoom != nullptr); return *_globalRoom; }
182  inline Inventory &inventory() const { assert(_inventory != nullptr); return *_inventory; }
183  inline MainCharacter &filemon() const { assert(_filemon != nullptr); return *_filemon; }
184  inline MainCharacter &mortadelo() const { assert(_mortadelo != nullptr); return *_mortadelo; }
185  inline GameFileReference scriptFileRef() const { return _scriptFileRef; }
186  inline const Common::String &initScriptName() const { return _initScriptName; }
187  inline uint8 loadedMapCount() const { return _loadedMapCount; }
188 
189  inline bool somebodyUsing(ObjectBase *object) const {
190  return filemon().currentlyUsing() == object ||
191  mortadelo().currentlyUsing() == object;
192  }
193 
194  MainCharacter &getMainCharacterByKind(MainCharacterKind kind) const;
195  MainCharacter &getOtherMainCharacterByKind(MainCharacterKind kind) const;
196  Room *getRoomByName(const char *name) const;
197  ObjectBase *getObjectByName(const char *name) const;
198  ObjectBase *getObjectByName(MainCharacterKind character, const char *name) const;
199  ObjectBase *getObjectByNameFromAnyRoom(const char *name) const;
200  const GameFileReference &getGlobalAnimation(GlobalAnimationKind kind) const;
201  const char *getLocalizedName(const Common::String &name) const;
202  const char *getDialogLine(int32 dialogId) const;
203 
204  void toggleObject(MainCharacterKind character, const char *objName, bool isEnabled);
205  void syncGame(Common::Serializer &s);
206 
207  GameFileReference readFileRef(Common::SeekableReadStream &stream) const;
209 
210 private:
211  bool loadWorldFileV3(const char *path);
212  bool loadWorldFileV2(const char *path);
213  bool loadWorldFileV1(const char *path);
214  void readRooms(Common::File &file);
215  void loadLocalizedNames();
216  void loadDialogLines();
217 
218  // the default Hash<const char*> works on the characters, but the default EqualTo compares pointers...
219  struct StringEqualTo {
220  bool operator()(const char *a, const char *b) const { return strcmp(a, b) == 0; }
221  };
222 
224  Common::Array<Room *> _rooms;
225  GameFileReference _globalAnimations[(int)GlobalAnimationKind::Count];
226  Common::String _initScriptName;
227  GameFileReference _scriptFileRef;
228  Room *_globalRoom;
229  Inventory *_inventory;
230  MainCharacter *_filemon, *_mortadelo;
231  uint8 _loadedMapCount = 0;
232  Common::HashMap<const char *, const char *,
234  StringEqualTo> _localizedNames;
235  Common::Array<const char *> _dialogLines;
236  Common::Array<char> _namesChunk, _dialogChunk;
237  bool _isLoading = true;
238 };
239 
240 }
241 
242 #endif // ALCACHOFA_ROOMS_H
Definition: objects.h:396
Definition: alcachofa.h:45
Definition: str.h:59
Definition: objects.h:37
Definition: rooms.h:122
Definition: objects.h:124
Definition: array.h:52
Path finding is based on the Shape class with the invariant that every polygon is a convex polygon wi...
Definition: shape.h:159
Definition: rooms.h:128
Definition: rooms.h:99
Definition: rooms.h:105
Definition: stream.h:745
Definition: serializer.h:79
Definition: objects.h:317
Definition: hashmap.h:85
const T * const_iterator
Definition: array.h:55
Definition: atari-cursor.h:35
Definition: file.h:47
Definition: rooms.h:134
References a game file either as path or as embedded byte range.
Definition: common.h:197
Definition: rect.h:144
Definition: objects.h:572
Definition: hash-str.h:74
Definition: rooms.h:31
uint8 _characterAlphaPremultiplier
for some reason in percent instead of 0-255
Definition: rooms.h:93
Definition: rooms.h:171