ScummVM API documentation
tile_manager.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 NUVIE_CORE_TILE_MANAGER_H
23 #define NUVIE_CORE_TILE_MANAGER_H
24 
25 #include "ultima/nuvie/core/nuvie_defs.h"
26 #include "ultima/shared/std/string.h"
27 
28 namespace Ultima {
29 namespace Nuvie {
30 
31 class Configuration;
32 class Look;
33 
34 // tile types stored in masktype.vga
35 
36 #define U6TILE_PLAIN 0x0
37 #define U6TILE_TRANS 0x5
38 #define U6TILE_PBLCK 0xA
39 
40 #define TILEFLAG_WALL_MASK 0xf0 // 11110000
41 //flags1
42 #define TILEFLAG_WALL_NORTH 0x80
43 #define TILEFLAG_WALL_EAST 0x40
44 #define TILEFLAG_WALL_SOUTH 0x20
45 #define TILEFLAG_WALL_WEST 0x10
46 #define TILEFLAG_IMPEDANCE (TILEFLAG_WALL_NORTH|TILEFLAG_WALL_EAST|TILEFLAG_WALL_SOUTH|TILEFLAG_WALL_WEST)
47 #define TILEFLAG_IMPEDANCE_SHIFT 4
48 #define TILEFLAG_DAMAGING 0x8
49 #define TILEFLAG_WALL 0x4
50 #define TILEFLAG_BLOCKING 0x2
51 #define TILEFLAG_WATER 0x1
52 
53 //flags2
54 #define TILEFLAG_DOUBLE_WIDTH 0x80
55 #define TILEFLAG_DOUBLE_HEIGHT 0x40
56 #define TILEFLAG_MISSILE_BOUNDARY 0x20
57 #define TILEFLAG_TOPTILE 0x10
58 #define TILEFLAG_WINDOW 0x8
59 #define TILEFLAG_BOUNDARY 0x4
60 #define TILEFLAG_LIGHT_MSB 0x2
61 #define TILEFLAG_LIGHT_LSB 0x1
62 #define GET_TILE_LIGHT_LEVEL(x) (uint8)(x->flags2 & 0x3) // only use with a pointer
63 //flags3
64 #define TILEFLAG_ARTICLE_MSB 0x80 // 00 01 10 11
65 #define TILEFLAG_ARTICLE_LSB 0x40 // - a an the
66 #define TILEFLAG_UNKNOWN_3_5 0x20
67 #define TILEFLAG_IGNORE 0x10
68 #define TILEFLAG_UNKNOWN_3_3 0x8 // Flammable? Mostly_non_metal_object (not affected by acid-slug)?
69 #define TILEFLAG_FORCED_PASSABLE 0x4
70 #define TILEFLAG_CAN_PLACE_ONTOP 0x2
71 #define TILEFLAG_UNKNOWN_LAVA 0x1 // associated with some lava tiles
72 
73 // FIXME These should probably go else where.
74 #define TILE_U6_DIRECTION_CURSOR 364
75 #define TILE_U6_TARGET_CURSOR 365
76 
77 #define TILE_U6_GREEN_MAGIC 380
78 #define TILE_U6_PURPLE_MAGIC 381
79 #define TILE_U6_RED_MAGIC 382
80 #define TILE_U6_BLUE_MAGIC 383
81 #define TILE_U6_BLOCKED_EQUIP 389
82 #define TILE_U6_LIGHTNING 392
83 #define TILE_U6_FIREBALL 393
84 #define TILE_U6_SOME_KIND_OF_BLUE_FIELD 394 // ghost's outline for casting/going invis
85 #define TILE_U6_IS_THIS_AN_ICE_SHOT 395
86 #define TILE_U6_KILL_SHOT 396
87 #define TILE_U6_FIRE_SHOT 397
88 #define TILE_U6_SLING_STONE 398
89 #define TILE_U6_CANNONBALL 399
90 #define TILE_U6_EQUIP 410
91 #define TILE_U6_GARGOYLE_LENS_ANIM_1 440
92 #define TILE_U6_GARGOYLE_LENS_ANIM_2 441
93 #define TILE_U6_BRITANNIAN_LENS_ANIM_1 442
94 #define TILE_U6_BRITANNIAN_LENS_ANIM_2 443
95 #define TILE_U6_WIZARD_EYE 563
96 #define TILE_U6_ARROW 566
97 #define TILE_U6_BOLT 567
98 
99 #define TILE_SE_BLOCKED_EQUIP 391
100 #define TILE_SE_EQUIP 392
101 
102 #define TILE_MD_EQUIP 273
103 #define TILE_MD_BLOCKED_EQUIP 274
104 
105 #define TILE_MD_PURPLE_BERRY_MARKER 288
106 #define TILE_MD_GREEN_BERRY_MARKER 289
107 #define TILE_MD_BROWN_BERRY_MARKER 290
108 
109 #define TILE_WIDTH 16
110 #define TILE_HEIGHT 16
111 #define TILE_DATA_SIZE 256
112 
113 typedef struct {
114  uint16 tile_num;
115  bool passable;
116  bool water;
117  bool toptile;
118  bool dbl_width;
119  bool dbl_height;
120  bool transparent;
121  bool boundary;
122  bool damages;
123  uint8 article_n;
124 //uint8 qty;
125 //uint8 flags;
126 
127  uint8 flags1;
128  uint8 flags2;
129  uint8 flags3;
130 
131  unsigned char data[256];
132 } Tile;
133 
134 
135 typedef struct {
136  uint16 number_of_tiles_to_animate;
137  uint16 tile_to_animate[0x20];
138  uint16 first_anim_frame[0x20];
139  uint8 and_masks[0x20];
140  uint8 shift_values[0x20];
141  sint8 loop_count[0x20]; // times to animate (-1 = infinite)
142  uint8 loop[0x20]; // 0 = loop forwards, 1 = backwards
143 } Animdata;
144 
145 class TileManager {
146  Tile tile[2048];
147  uint16 tileindex[2048]; //used for animated tiles
148  uint16 game_counter, rgame_counter;
149  Animdata animdata;
150  Look *look;
151 
152  char *desc_buf; // for look
153  const Configuration *config;
154 
155  int game_type;
156 
157  Tile *extendedTiles;
158  uint16 numTiles;
159 
160 public:
161 
162  TileManager(const Configuration *cfg);
163  ~TileManager();
164 
165  bool loadTiles();
166  Tile *get_tile(uint16 tile_num);
167  Tile *get_anim_base_tile(uint16 tile_num);
168  Tile *get_original_tile(uint16 tile_num);
169  void set_tile_index(uint16 tile_index, uint16 tile_num);
170  uint16 get_tile_index(uint16 tile_index) const {
171  return tileindex[tile_index];
172  }
173  void set_anim_loop(uint16 tile_num, sint8 loopc, uint8 loop = 0);
174 
175  const char *lookAtTile(uint16 tile_num, uint16 qty, bool show_prefix);
176  bool tile_is_stackable(uint16 tile_num);
177  void update();
178  void update_timed_tiles(uint8 hour);
179 
180  uint8 get_number_of_animations() const {
181  return animdata.number_of_tiles_to_animate;
182  }
183  uint16 get_numtiles() const {
184  return numTiles;
185  }
186  uint16 get_anim_tile(uint8 anim_index) const {
187  return anim_index < animdata.number_of_tiles_to_animate ? animdata.tile_to_animate[anim_index] : 0;
188  }
189  uint16 get_anim_first_frame(uint8 anim_index) const {
190  return anim_index < animdata.number_of_tiles_to_animate ? animdata.first_anim_frame[anim_index] : 0;
191  }
192  void set_anim_first_frame(uint16 anim_index, uint16 new_start_tile_num);
193  void anim_play_repeated(uint8 anim_index);
194  void anim_stop_playing(uint8 anim_index);
195 
196 
197  Tile *get_rotated_tile(const Tile *tile, float rotate, uint8 src_y_offset = 0);
198  void get_rotated_tile(const Tile *tile, Tile *dest_tile, float rotate, uint8 src_y_offset = 0);
199 
200  Tile *get_cursor_tile();
201  Tile *get_use_tile();
202  const Tile *get_gump_cursor_tile();
203 
204  Tile *loadCustomTiles(const Common::Path &filename, bool overwrite_tiles, bool copy_tileflags, uint16 tile_num_start_offset);
205  void freeCustomTiles();
206  void exportTilesetToBmpFile(const Common::Path &filename, bool fixupU6Shoreline = true);
207 protected:
208 
209  bool loadAnimData();
210  bool loadTileFlag();
211  void decodePixelBlockTile(const unsigned char *tile_data, uint16 tile_num);
212 
213  bool loadAnimMask();
214 
215 private:
216 
217  Tile *get_extended_tile(uint16 tile_num);
218  void copyTileMetaData(Tile *dest, Tile *src);
219  Tile *addNewTiles(uint16 num_tiles);
220 
221  void writeBmpTileData(unsigned char *data, const Tile *t, bool transparent);
222 };
223 
224 } // End of namespace Nuvie
225 } // End of namespace Ultima
226 
227 #endif
Definition: configuration.h:61
Definition: path.h:52
Definition: tile_manager.h:145
Definition: detection.h:27
Definition: look.h:30
Definition: tile_manager.h:135
Definition: tile_manager.h:113