ScummVM API documentation
tile.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 ULTIMA4_MAP_TILE_H
23 #define ULTIMA4_MAP_TILE_H
24 
25 #include "ultima/ultima4/map/direction.h"
26 #include "ultima/ultima4/core/types.h"
27 #include "ultima/ultima4/map/tileset.h"
28 #include "ultima/shared/std/containers.h"
29 
30 namespace Ultima {
31 namespace Ultima4 {
32 
33 class ConfigElement;
34 class Image;
35 class Tileset;
36 class TileAnim;
37 
38 /* attr masks */
39 #define MASK_SHIP 0x0001
40 #define MASK_HORSE 0x0002
41 #define MASK_BALLOON 0x0004
42 #define MASK_DISPEL 0x0008
43 #define MASK_TALKOVER 0x0010
44 #define MASK_DOOR 0x0020
45 #define MASK_LOCKEDDOOR 0x0040
46 #define MASK_CHEST 0x0080
47 #define MASK_ATTACKOVER 0x0100
48 #define MASK_CANLANDBALLOON 0x0200
49 #define MASK_REPLACEMENT 0x0400
50 #define MASK_WATER_REPLACEMENT 0x0800
51 #define MASK_FOREGROUND 0x1000
52 #define MASK_LIVING_THING 0x2000
53 
54 
55 /* movement masks */
56 #define MASK_SWIMABLE 0x0001
57 #define MASK_SAILABLE 0x0002
58 #define MASK_UNFLYABLE 0x0004
59 #define MASK_CREATURE_UNWALKABLE 0x0008
60 
65 class Tile : private Uncopyable {
66 public:
67  Tile(Tileset *tileset);
68  ~Tile();
69 
73  void loadProperties(const ConfigElement &conf);
74 
75  TileId getId() const {
76  return _id;
77  }
78  const Common::String &getName() const {
79  return _name;
80  }
81  int getWidth() const {
82  return _w;
83  }
84  int getHeight() const {
85  return _h;
86  }
87  int getFrames() const {
88  return _frames;
89  }
90  int getScale() const {
91  return _scale;
92  }
93  TileAnim *getAnim() const {
94  return _anim;
95  }
96  Image *getImage();
97  const Common::String &getLooksLike() const {
98  return _looksLike;
99  }
100 
101  bool isTiledInDungeon() const {
102  return _tiledInDungeon;
103  }
104  bool isLandForeground() const {
105  return _foreground;
106  }
107  bool isWaterForeground() const {
108  return _waterForeground;
109  }
110 
111  int canWalkOn(Direction d) const {
112  return DIR_IN_MASK(d, rule->_walkOnDirs);
113  }
114  int canWalkOff(Direction d) const {
115  return DIR_IN_MASK(d, rule->_walkOffDirs);
116  }
117 
122  int canAttackOver() const {
123  return isWalkable() || isSwimable() || isSailable() || (rule->_mask & MASK_ATTACKOVER);
124  }
125  int canLandBalloon() const {
126  return rule->_mask & MASK_CANLANDBALLOON;
127  }
128  int isLivingObject() const {
129  return rule->_mask & MASK_LIVING_THING;
130  }
131  int isReplacement() const {
132  return rule->_mask & MASK_REPLACEMENT;
133  }
134  int isWaterReplacement() const {
135  return rule->_mask & MASK_WATER_REPLACEMENT;
136  }
137 
138  int isWalkable() const {
139  return rule->_walkOnDirs > 0;
140  }
141  bool isCreatureWalkable() const {
142  return canWalkOn(DIR_ADVANCE) && !(rule->_movementMask & MASK_CREATURE_UNWALKABLE);
143  }
144  bool isDungeonWalkable() const;
145  bool isDungeonFloor() const;
146  int isSwimable() const {
147  return rule->_movementMask & MASK_SWIMABLE;
148  }
149  int isSailable() const {
150  return rule->_movementMask & MASK_SAILABLE;
151  }
152  bool isWater() const {
153  return (isSwimable() || isSailable());
154  }
155  int isFlyable() const {
156  return !(rule->_movementMask & MASK_UNFLYABLE);
157  }
158  int isDoor() const {
159  return rule->_mask & MASK_DOOR;
160  }
161  int isLockedDoor() const {
162  return rule->_mask & MASK_LOCKEDDOOR;
163  }
164  int isChest() const {
165  return rule->_mask & MASK_CHEST;
166  }
167  int isShip() const {
168  return rule->_mask & MASK_SHIP;
169  }
170  bool isPirateShip() const {
171  return _name == "pirate_ship";
172  }
173  int isHorse() const {
174  return rule->_mask & MASK_HORSE;
175  }
176  int isBalloon() const {
177  return rule->_mask & MASK_BALLOON;
178  }
179  int canDispel() const {
180  return rule->_mask & MASK_DISPEL;
181  }
182  int canTalkOver() const {
183  return rule->_mask & MASK_TALKOVER;
184  }
185  TileSpeed getSpeed() const {
186  return rule->_speed;
187  }
188  TileEffect getEffect() const {
189  return rule->_effect;
190  }
191 
192  bool isOpaque() const;
193 
198  bool isForeground() const;
199  Direction directionForFrame(int frame) const;
200  int frameForDirection(Direction d) const;
201 
202  static void resetNextId() {
203  _nextId = 0;
204  }
205  static bool canTalkOverTile(const Tile *tile) {
206  return tile->canTalkOver() != 0;
207  }
208  static bool canAttackOverTile(const Tile *tile) {
209  return tile->canAttackOver() != 0;
210  }
211  void deleteImage();
212 
213 private:
217  void loadImage();
218 
219 private:
220  TileId _id;
221  Common::String _name;
222  Tileset *_tileSet;
223  int _w, _h;
224  int _frames;
225  int _scale;
226  TileAnim *_anim;
227  bool _opaque;
229  bool _foreground;
230  bool _waterForeground;
232  TileRule *rule;
233  Common::String _imageName;
234  Common::String _looksLike;
236  Image *_image;
237  bool _tiledInDungeon;
238  Std::vector<Direction> _directions;
239 
240  Common::String _animationRule;
241 
242 
243  static TileId _nextId;
244 };
245 
246 } // End of namespace Ultima4
247 } // End of namespace Ultima
248 
249 #endif
Definition: str.h:59
Definition: config.h:127
int canAttackOver() const
Definition: tile.h:122
Definition: detection.h:27
Definition: types.h:70
void loadProperties(const ConfigElement &conf)
bool isForeground() const
Definition: tileset.h:59
Definition: tileset.h:40
Definition: tileanim.h:197
Definition: tile.h:65
Definition: movie_decoder.h:32