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 const Common::String &name() const { return _name; }
39  inline const PathFindingShape *activeFloor() const {
40  return _activeFloorI < 0 ? nullptr : &_floors[_activeFloorI];
41  }
42  inline int8 orderAt(Common::Point query) const {
43  return _activeFloorI < 0 ? 49 : activeFloor()->orderAt(query);
44  }
45  inline float depthAt(Common::Point query) const {
46  return _activeFloorI < 0 ? 1 : activeFloor()->depthAt(query);
47  }
48  inline uint8 characterAlphaTint() const { return _characterAlphaTint; }
49  inline uint8 characterAlphaPremultiplier() const { return _characterAlphaPremultiplier; }
50  inline bool fixedCameraOnEntering() const { return _fixedCameraOnEntering; }
51  inline int musicID() const { return _musicId; }
52 
53  using ObjectIterator = Common::Array<ObjectBase *>::const_iterator;
54  inline ObjectIterator beginObjects() const { return _objects.begin(); }
55  inline ObjectIterator endObjects() const { return _objects.end(); }
56 
57  void update();
58  void draw();
59  virtual bool updateInput();
60  virtual void loadResources();
61  virtual void freeResources();
62  virtual void syncGame(Common::Serializer &serializer);
63  ObjectBase *getObjectByName(const char *name) const;
64  void toggleActiveFloor();
65  void debugPrint(bool withObjects) const;
66 
67 protected:
68  Room(World *world, Common::SeekableReadStream &stream, bool hasUselessByte);
69  void updateScripts();
70  void updateRoomBounds();
71  void updateInteraction();
72  void updateObjects();
73  void drawObjects();
74  void drawDebug();
75  ShapeObject *getSelectedObject(ShapeObject *best = nullptr) const;
76 
77  World *_world;
78  Common::String _name;
79  PathFindingShape _floors[2];
80  bool _fixedCameraOnEntering;
81  int8 _activeFloorI = -1;
82  int _musicId = -1;
83  uint8
84  _characterAlphaTint,
86 
88 };
89 
90 class OptionsMenu final : public Room {
91 public:
92  static constexpr const char *kClassName = "CHabitacionMenuOpciones";
94 
95  bool updateInput() override;
96  void loadResources() override;
97 
98  void clearLastSelectedObject(); // to reset arm animation
99  inline SlideButton *&currentSlideButton() { return _currentSlideButton; }
100 
101 private:
102  ShapeObject *_lastSelectedObject = nullptr;
103  ObjectBase *_idleArm = nullptr;
104  SlideButton *_currentSlideButton = nullptr;
105 };
106 
107 class ConnectMenu final : public Room {
108 public:
109  static constexpr const char *kClassName = "CHabitacionConectar";
111 };
112 
113 class ListenMenu final : public Room {
114 public:
115  static constexpr const char *kClassName = "CHabitacionEsperar";
117 };
118 
119 class Inventory final : public Room {
120 public:
121  static constexpr const char *kClassName = "CInventario";
122  Inventory(World *world, Common::SeekableReadStream &stream);
123  ~Inventory() override;
124 
125  bool updateInput() override;
126 
127  void initItems();
128  void updateItemsByActiveCharacter();
129  void drawAsOverlay(int32 scrollY);
130  void open();
131  void close();
132 
133 private:
134  Item *getHoveredItem();
135 
136  Common::Array<Item *> _items;
137 };
138 
139 enum class GlobalAnimationKind {
140  GeneralFont = 0,
141  DialogFont,
142  Cursor,
143  MortadeloIcon,
144  FilemonIcon,
145  InventoryIcon,
146  MortadeloDisabledIcon, // only used for multiplayer
147  FilemonDisabledIcon,
148  InventoryDisabledIcon,
149 
150  Count
151 };
152 
153 class World final {
154 public:
155  World();
156  ~World();
157 
158  // reference-returning queries will error if the object does not exist
159 
160  using RoomIterator = Common::Array<const Room *>::const_iterator;
161  inline RoomIterator beginRooms() const { return _rooms.begin(); }
162  inline RoomIterator endRooms() const { return _rooms.end(); }
163  inline Room &globalRoom() const { assert(_globalRoom != nullptr); return *_globalRoom; }
164  inline Inventory &inventory() const { assert(_inventory != nullptr); return *_inventory; }
165  inline MainCharacter &filemon() const { assert(_filemon != nullptr); return *_filemon; }
166  inline MainCharacter &mortadelo() const { assert(_mortadelo != nullptr); return *_mortadelo; }
167  inline const Common::String &initScriptName() const { return _initScriptName; }
168  inline uint8 loadedMapCount() const { return _loadedMapCount; }
169 
170  inline bool somebodyUsing(ObjectBase *object) const {
171  return filemon().currentlyUsing() == object ||
172  mortadelo().currentlyUsing() == object;
173  }
174 
175  MainCharacter &getMainCharacterByKind(MainCharacterKind kind) const;
176  MainCharacter &getOtherMainCharacterByKind(MainCharacterKind kind) const;
177  Room *getRoomByName(const char *name) const;
178  ObjectBase *getObjectByName(const char *name) const;
179  ObjectBase *getObjectByName(MainCharacterKind character, const char *name) const;
180  ObjectBase *getObjectByNameFromAnyRoom(const char *name) const;
181  const Common::String &getGlobalAnimationName(GlobalAnimationKind kind) const;
182  const char *getLocalizedName(const Common::String &name) const;
183  const char *getDialogLine(int32 dialogId) const;
184 
185  void toggleObject(MainCharacterKind character, const char *objName, bool isEnabled);
186  void syncGame(Common::Serializer &s);
187 
188 private:
189  bool loadWorldFile(const char *path);
190  void loadLocalizedNames();
191  void loadDialogLines();
192 
193  // the default Hash<const char*> works on the characters, but the default EqualTo compares pointers...
194  struct StringEqualTo {
195  bool operator()(const char *a, const char *b) const { return strcmp(a, b) == 0; }
196  };
197 
198  Common::Array<Room *> _rooms;
199  Common::String _globalAnimationNames[(int)GlobalAnimationKind::Count];
200  Common::String _initScriptName;
201  Room *_globalRoom;
202  Inventory *_inventory;
203  MainCharacter *_filemon, *_mortadelo;
204  uint8 _loadedMapCount = 0;
205  Common::HashMap<const char *, const char *,
207  StringEqualTo> _localizedNames;
208  Common::Array<const char *> _dialogLines;
209  Common::Array<char> _namesChunk, _dialogChunk;
210 };
211 
212 }
213 
214 #endif // ALCACHOFA_ROOMS_H
Definition: objects.h:354
Definition: alcachofa.h:45
Definition: str.h:59
Definition: objects.h:36
Definition: rooms.h:107
Definition: objects.h:123
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:113
Definition: rooms.h:90
Definition: stream.h:745
Definition: serializer.h:79
Definition: objects.h:284
Definition: hashmap.h:85
const T * const_iterator
Definition: array.h:55
Definition: atari-cursor.h:35
Definition: rooms.h:119
Definition: rect.h:144
Definition: objects.h:528
Definition: hash-str.h:74
Definition: rooms.h:31
uint8 _characterAlphaPremultiplier
for some reason in percent instead of 0-255
Definition: rooms.h:84
Definition: rooms.h:153