… | |
… | |
42 | * map pointers. |
42 | * map pointers. |
43 | */ |
43 | */ |
44 | #define MAGIC_MAP_SIZE 50 |
44 | #define MAGIC_MAP_SIZE 50 |
45 | #define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2 |
45 | #define MAGIC_MAP_HALF MAGIC_MAP_SIZE/2 |
46 | |
46 | |
47 | #define MAP_LAYERS 4 |
47 | #define MAP_LAYERS 3 |
48 | |
48 | |
49 | /* This is when the map will reset */ |
49 | /* This is when the map will reset */ |
50 | #define MAP_WHEN_RESET(m) ((m)->reset_time) |
50 | #define MAP_WHEN_RESET(m) ((m)->reset_time) |
51 | |
51 | |
52 | #define MAP_RESET_TIMEOUT(m) ((m)->reset_timeout) |
52 | #define MAP_RESET_TIMEOUT(m) ((m)->reset_timeout) |
… | |
… | |
58 | /* mape darkness used to enforce the MAX_DARKNESS value. |
58 | /* mape darkness used to enforce the MAX_DARKNESS value. |
59 | * but IMO, if it is beyond max value, that should be fixed |
59 | * but IMO, if it is beyond max value, that should be fixed |
60 | * on the map or in the code. |
60 | * on the map or in the code. |
61 | */ |
61 | */ |
62 | #define MAP_DARKNESS(m) (m)->darkness |
62 | #define MAP_DARKNESS(m) (m)->darkness |
63 | |
|
|
64 | #define MAP_WIDTH(m) (m)->width |
|
|
65 | #define MAP_HEIGHT(m) (m)->height |
|
|
66 | |
63 | |
67 | /* Convenient function - total number of spaces is used |
64 | /* Convenient function - total number of spaces is used |
68 | * in many places. |
65 | * in many places. |
69 | */ |
66 | */ |
70 | #define MAP_SIZE(m) ((m)->width * (m)->height) |
67 | #define MAP_SIZE(m) ((m)->width * (m)->height) |
… | |
… | |
99 | * really be used, as it is multi tile aware. However, there are some cases |
96 | * really be used, as it is multi tile aware. However, there are some cases |
100 | * where it is known the map is not tiled or the values are known |
97 | * where it is known the map is not tiled or the values are known |
101 | * consistent (eg, op->map, op->x, op->y) |
98 | * consistent (eg, op->map, op->x, op->y) |
102 | */ |
99 | */ |
103 | // all those macros are herewith declared legacy |
100 | // all those macros are herewith declared legacy |
104 | #define GET_MAP_FLAGS(M,X,Y) (M)->at((X),(Y)).flags |
101 | #define GET_MAP_FLAGS(M,X,Y) (M)->at((X),(Y)).flags () |
105 | #define SET_MAP_FLAGS(M,X,Y,C) (M)->at((X),(Y)).flags = (C) |
|
|
106 | #define GET_MAP_LIGHT(M,X,Y) (M)->at((X),(Y)).light |
102 | #define GET_MAP_LIGHT(M,X,Y) (M)->at((X),(Y)).light |
107 | #define SET_MAP_LIGHT(M,X,Y,L) (M)->at((X),(Y)).light = (L) |
|
|
108 | #define GET_MAP_OB(M,X,Y) (M)->at((X),(Y)).bottom |
103 | #define GET_MAP_OB(M,X,Y) (M)->at((X),(Y)).bottom |
109 | #define GET_MAP_TOP(M,X,Y) (M)->at((X),(Y)).top |
104 | #define GET_MAP_TOP(M,X,Y) (M)->at((X),(Y)).top |
110 | #define SET_MAP_OB(M,X,Y,tmp) (M)->at((X),(Y)).bottom = (tmp) |
|
|
111 | #define SET_MAP_TOP(M,X,Y,tmp) (M)->at((X),(Y)).top = (tmp) |
|
|
112 | #define SET_MAP_FACE(M,X,Y,C,L) (M)->at((X),(Y)).faces[L] = (C) |
|
|
113 | #define GET_MAP_FACE(M,X,Y,L) (M)->at((X),(Y)).faces[L] |
105 | #define GET_MAP_FACE(M,X,Y,L) (M)->at((X),(Y)).faces[L] |
114 | #define SET_MAP_FACE_OBJ(M,X,Y,C,L) (M)->at((X),(Y)).faces_obj[L] = (C) |
|
|
115 | #define GET_MAP_FACE_OBJ(M,X,Y,L) (M)->at((X),(Y)).faces_obj[L] |
106 | #define GET_MAP_FACE_OBJ(M,X,Y,L) (M)->at((X),(Y)).faces_obj[L] |
116 | #define GET_MAP_MOVE_BLOCK(M,X,Y) (M)->at((X),(Y)).move_block |
107 | #define GET_MAP_MOVE_BLOCK(M,X,Y) (M)->at((X),(Y)).move_block |
117 | #define SET_MAP_MOVE_BLOCK(M,X,Y,C) (M)->at((X),(Y)).move_block = (C) |
|
|
118 | #define GET_MAP_MOVE_SLOW(M,X,Y) (M)->at((X),(Y)).move_slow |
108 | #define GET_MAP_MOVE_SLOW(M,X,Y) (M)->at((X),(Y)).move_slow |
119 | #define SET_MAP_MOVE_SLOW(M,X,Y,C) (M)->at((X),(Y)).move_slow = (C) |
|
|
120 | #define GET_MAP_MOVE_ON(M,X,Y) (M)->at((X),(Y)).move_on |
109 | #define GET_MAP_MOVE_ON(M,X,Y) (M)->at((X),(Y)).move_on |
121 | #define SET_MAP_MOVE_ON(M,X,Y,C) (M)->at((X),(Y)).move_on = (C) |
|
|
122 | #define GET_MAP_MOVE_OFF(M,X,Y) (M)->at((X),(Y)).move_off |
110 | #define GET_MAP_MOVE_OFF(M,X,Y) (M)->at((X),(Y)).move_off |
123 | #define SET_MAP_MOVE_OFF(M,X,Y,C) (M)->at((X),(Y)).move_off = (C) |
|
|
124 | |
111 | |
125 | /* You should really know what you are doing before using this - you |
112 | /* You should really know what you are doing before using this - you |
126 | * should almost always be using out_of_map instead, which takes into account |
113 | * should almost always be using out_of_map instead, which takes into account |
127 | * map tiling. |
114 | * map tiling. |
128 | */ |
115 | */ |
… | |
… | |
139 | * such as: bombs, potion usage, alchemy, spells |
126 | * such as: bombs, potion usage, alchemy, spells |
140 | * this was introduced to make shops safer |
127 | * this was introduced to make shops safer |
141 | * but is useful in other situations */ |
128 | * but is useful in other situations */ |
142 | #define P_IS_ALIVE 0x10 /* something alive is on this space */ |
129 | #define P_IS_ALIVE 0x10 /* something alive is on this space */ |
143 | #define P_NO_CLERIC 0x20 /* no clerical spells cast here */ |
130 | #define P_NO_CLERIC 0x20 /* no clerical spells cast here */ |
|
|
131 | |
144 | #define P_NEED_UPDATE 0x40 /* this space is out of date */ |
132 | #define P_NEED_UPDATE 0x80 /* this space is out of date */ |
145 | #define P_NO_ERROR 0x80 /* Purely temporary - if set, update_position |
|
|
146 | * does not complain if the flags are different. |
|
|
147 | */ |
|
|
148 | |
133 | |
149 | /* The following two values are not stored in the MapLook flags, but instead |
134 | /* The following two values are not stored in the MapLook flags, but instead |
150 | * used in the get_map_flags value - that function is used to return |
135 | * used in the get_map_flags value - that function is used to return |
151 | * the flag value, as well as other conditions - using a more general |
136 | * the flag value, as well as other conditions - using a more general |
152 | * function that does more of the work can hopefully be used to replace |
137 | * function that does more of the work can hopefully be used to replace |
… | |
… | |
170 | struct mapspace |
155 | struct mapspace |
171 | { |
156 | { |
172 | object *bottom; /* lowest object on this space */ |
157 | object *bottom; /* lowest object on this space */ |
173 | object *top; /* Highest object on this space */ |
158 | object *top; /* Highest object on this space */ |
174 | New_Face *faces[MAP_LAYERS]; /* faces for the 3 layers */ |
159 | New_Face *faces[MAP_LAYERS]; /* faces for the 3 layers */ |
175 | object *faces_obj[MAP_LAYERS]; /* face objects for the 3 layers */ |
160 | object *faces_obj[MAP_LAYERS];/* face objects for the 3 layers */ |
176 | uint8 flags; /* flags about this space (see the P_ values above) */ |
161 | uint8 flags_; /* flags about this space (see the P_ values above) */ |
177 | sint8 light; /* How much light this space provides */ |
162 | sint8 light; /* How much light this space provides */ |
178 | uint8 move_block; /* What movement types this space blocks */ |
163 | MoveType move_block; /* What movement types this space blocks */ |
179 | uint8 move_slow; /* What movement types this space slows */ |
164 | MoveType move_slow; /* What movement types this space slows */ |
180 | uint8 move_on; /* What movement types are activated */ |
165 | MoveType move_on; /* What movement types are activated */ |
181 | uint8 move_off; /* What movement types are activated */ |
166 | MoveType move_off; /* What movement types are activated */ |
|
|
167 | |
|
|
168 | void update_ (); |
|
|
169 | void update () |
|
|
170 | { |
|
|
171 | if (flags_ & P_NEED_UPDATE) |
|
|
172 | update_ (); |
|
|
173 | } |
|
|
174 | |
|
|
175 | uint8 flags () |
|
|
176 | { |
|
|
177 | update (); |
|
|
178 | return flags_; |
|
|
179 | } |
|
|
180 | |
|
|
181 | // maybe only inline quick flags_ checking? |
|
|
182 | object *player () |
|
|
183 | { |
|
|
184 | // search from the top, because players are usually on top |
|
|
185 | // make usually == always and this non-amortized O(1) |
|
|
186 | // could gte rid of P_PLAYER, too, then |
|
|
187 | if (flags () & P_PLAYER) |
|
|
188 | for (object *op = top; op; op = op->below) |
|
|
189 | if (op->type == PLAYER) |
|
|
190 | return op; |
|
|
191 | |
|
|
192 | return 0; |
|
|
193 | } |
182 | }; |
194 | }; |
183 | |
195 | |
184 | /* |
196 | /* |
185 | * this is an overlay structure of the whole world. It exists as a simple |
197 | * this is an overlay structure of the whole world. It exists as a simple |
186 | * high level map, which doesn't contain the full data of the underlying map. |
198 | * high level map, which doesn't contain the full data of the underlying map. |
… | |
… | |
252 | * almost certainly break various features. You may think |
264 | * almost certainly break various features. You may think |
253 | * it is safe to look at width and height values directly |
265 | * it is safe to look at width and height values directly |
254 | * (or even through the macros), but doing so will completely |
266 | * (or even through the macros), but doing so will completely |
255 | * break map tiling. |
267 | * break map tiling. |
256 | */ |
268 | */ |
257 | ACC_CLASS (maptile) |
269 | INTERFACE_CLASS (maptile) |
258 | struct maptile : zero_initialised, attachable<maptile> |
270 | struct maptile : zero_initialised, attachable |
259 | { |
271 | { |
260 | sint32 ACC (RO, width), ACC (RO, height); /* Width and height of map. */ |
272 | sint32 ACC (RO, width), ACC (RO, height); /* Width and height of map. */ |
261 | struct mapspace *spaces; /* Array of spaces on this map */ |
273 | struct mapspace *spaces; /* Array of spaces on this map */ |
262 | |
274 | |
263 | maptile *ACC (RW, next); /* Next map, linked list */ |
275 | maptile *ACC (RW, next); /* Next map, linked list */ |
… | |
… | |
306 | char *tile_path[4]; /* path to adjoining maps */ |
318 | char *tile_path[4]; /* path to adjoining maps */ |
307 | maptile *tile_map[4]; /* Next map, linked list */ |
319 | maptile *tile_map[4]; /* Next map, linked list */ |
308 | char ACC (RW, path)[HUGE_BUF]; /* Filename of the map */ |
320 | char ACC (RW, path)[HUGE_BUF]; /* Filename of the map */ |
309 | |
321 | |
310 | maptile (); |
322 | maptile (); |
|
|
323 | ~maptile (); |
|
|
324 | void do_destroy (); |
|
|
325 | void gather_callbacks (AV *&callbacks, event_type event) const; |
|
|
326 | |
311 | void allocate (); |
327 | void allocate (); |
312 | |
328 | |
313 | mapspace const &at (uint32 x, uint32 y) const { return spaces [x + width * y]; } |
329 | mapspace const &at (uint32 x, uint32 y) const { return spaces [x + width * y]; } |
314 | mapspace &at (uint32 x, uint32 y) { return spaces [x + width * y]; } |
330 | mapspace &at (uint32 x, uint32 y) { return spaces [x + width * y]; } |
315 | }; |
331 | }; |
… | |
… | |
330 | int distance_y; |
346 | int distance_y; |
331 | int direction; |
347 | int direction; |
332 | object *part; |
348 | object *part; |
333 | }; |
349 | }; |
334 | |
350 | |
|
|
351 | inline mapspace & |
|
|
352 | object::ms () const |
|
|
353 | { |
|
|
354 | return map->at (x, y); |
|
|
355 | } |
|
|
356 | |
335 | #endif |
357 | #endif |
336 | |
358 | |