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