… | |
… | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
20 | |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | |
|
|
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <funcpoint.h> |
25 | #include <funcpoint.h> |
27 | |
26 | |
28 | #include <loader.h> |
27 | #include <loader.h> |
29 | #ifndef WIN32 /* ---win32 exclude header */ |
|
|
30 | # include <unistd.h> |
28 | #include <unistd.h> |
31 | #endif /* win32 */ |
|
|
32 | |
29 | |
33 | #include "path.h" |
30 | #include "path.h" |
34 | |
|
|
35 | |
31 | |
36 | /* |
32 | /* |
37 | * Returns the maptile which has a name matching the given argument. |
33 | * Returns the maptile which has a name matching the given argument. |
38 | * return NULL if no match is found. |
34 | * return NULL if no match is found. |
39 | */ |
35 | */ |
40 | |
|
|
41 | maptile * |
36 | maptile * |
42 | has_been_loaded (const char *name) |
37 | has_been_loaded (const char *name) |
43 | { |
38 | { |
44 | maptile *map; |
|
|
45 | |
|
|
46 | if (!name || !*name) |
39 | if (!name || !*name) |
47 | return 0; |
40 | return 0; |
48 | for (map = first_map; map; map = map->next) |
41 | |
|
|
42 | for_all_maps (map) |
49 | if (!strcmp (name, map->path)) |
43 | if (!strcmp (name, map->path)) |
50 | break; |
|
|
51 | return (map); |
44 | return map; |
|
|
45 | |
|
|
46 | return 0; |
52 | } |
47 | } |
53 | |
48 | |
54 | /* |
49 | /* |
55 | * This makes a path absolute outside the world of Crossfire. |
50 | * This makes a path absolute outside the world of Crossfire. |
56 | * In other words, it prepends LIBDIR/MAPDIR/ to the given path |
51 | * In other words, it prepends LIBDIR/MAPDIR/ to the given path |
… | |
… | |
157 | int |
152 | int |
158 | check_path (const char *name, int prepend_dir) |
153 | check_path (const char *name, int prepend_dir) |
159 | { |
154 | { |
160 | char buf[MAX_BUF]; |
155 | char buf[MAX_BUF]; |
161 | |
156 | |
162 | #ifndef WIN32 |
|
|
163 | char *endbuf; |
157 | char *endbuf; |
164 | struct stat statbuf; |
158 | struct stat statbuf; |
165 | int mode = 0; |
159 | int mode = 0; |
166 | #endif |
|
|
167 | |
160 | |
168 | if (prepend_dir) |
161 | if (prepend_dir) |
169 | strcpy (buf, create_pathname (name)); |
162 | strcpy (buf, create_pathname (name)); |
170 | else |
163 | else |
171 | strcpy (buf, name); |
164 | strcpy (buf, name); |
172 | #ifdef WIN32 /* ***win32: check this sucker in windows style. */ |
|
|
173 | return (_access (buf, 0)); |
|
|
174 | #else |
|
|
175 | |
165 | |
176 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
166 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
177 | * this method should be equivalant and is clearer. |
167 | * this method should be equivalant and is clearer. |
178 | * Can not use strcat because we need to cycle through |
168 | * Can not use strcat because we need to cycle through |
179 | * all the names. |
169 | * all the names. |
… | |
… | |
192 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
182 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
193 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
183 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
194 | mode |= 2; |
184 | mode |= 2; |
195 | |
185 | |
196 | return (mode); |
186 | return (mode); |
197 | #endif |
|
|
198 | } |
187 | } |
199 | |
188 | |
200 | /* |
189 | /* |
201 | * Prints out debug-information about a map. |
190 | * Prints out debug-information about a map. |
202 | * Dumping these at llevError doesn't seem right, but is |
191 | * Dumping these at llevError doesn't seem right, but is |
… | |
… | |
205 | |
194 | |
206 | void |
195 | void |
207 | dump_map (const maptile *m) |
196 | dump_map (const maptile *m) |
208 | { |
197 | { |
209 | LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); |
198 | LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); |
210 | LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m)); |
199 | LOG (llevError, "Size: %dx%d Start: %d,%d\n", m->width, m->height, m->enter_x, m->enter_y); |
211 | |
200 | |
212 | if (m->msg != NULL) |
201 | if (m->msg != NULL) |
213 | LOG (llevError, "Message:\n%s", m->msg); |
202 | LOG (llevError, "Message:\n%s", m->msg); |
214 | |
203 | |
215 | if (m->maplore != NULL) |
204 | if (m->maplore != NULL) |
… | |
… | |
229 | */ |
218 | */ |
230 | |
219 | |
231 | void |
220 | void |
232 | dump_all_maps (void) |
221 | dump_all_maps (void) |
233 | { |
222 | { |
234 | maptile *m; |
223 | for_all_maps (m) |
235 | |
|
|
236 | for (m = first_map; m != NULL; m = m->next) |
|
|
237 | { |
|
|
238 | dump_map (m); |
224 | dump_map (m); |
239 | } |
|
|
240 | } |
225 | } |
241 | |
226 | |
242 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
227 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
243 | * one function that just returns a P_.. value (see map.h) |
228 | * one function that just returns a P_.. value (see map.h) |
244 | * it will also do map translation for tiled maps, returning |
229 | * it will also do map translation for tiled maps, returning |
… | |
… | |
248 | * is needed. The case of not passing values is if we're just |
233 | * is needed. The case of not passing values is if we're just |
249 | * checking for the existence of something on those spaces, but |
234 | * checking for the existence of something on those spaces, but |
250 | * don't expect to insert/remove anything from those spaces. |
235 | * don't expect to insert/remove anything from those spaces. |
251 | */ |
236 | */ |
252 | int |
237 | int |
253 | get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) |
238 | get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny) |
254 | { |
239 | { |
255 | sint16 newx, newy; |
240 | sint16 newx, newy; |
256 | int retval = 0; |
241 | int retval = 0; |
257 | maptile *mp; |
242 | maptile *mp; |
258 | |
243 | |
259 | if (out_of_map (oldmap, x, y)) |
|
|
260 | return P_OUT_OF_MAP; |
|
|
261 | newx = x; |
244 | newx = x; |
262 | newy = y; |
245 | newy = y; |
|
|
246 | |
263 | mp = get_map_from_coord (oldmap, &newx, &newy); |
247 | mp = get_map_from_coord (oldmap, &newx, &newy); |
|
|
248 | |
|
|
249 | if (!mp) |
|
|
250 | return P_OUT_OF_MAP; |
|
|
251 | |
264 | if (mp != oldmap) |
252 | if (mp != oldmap) |
265 | retval |= P_NEW_MAP; |
253 | retval |= P_NEW_MAP; |
266 | if (newmap) |
|
|
267 | *newmap = mp; |
|
|
268 | if (nx) |
|
|
269 | *nx = newx; |
|
|
270 | if (ny) |
|
|
271 | *ny = newy; |
|
|
272 | |
254 | |
273 | retval |= mp->spaces[newx + mp->width * newy].flags; |
255 | if (newmap) *newmap = mp; |
|
|
256 | if (nx) *nx = newx; |
|
|
257 | if (ny) *ny = newy; |
274 | |
258 | |
275 | return retval; |
259 | return retval | mp->at (newx, newy).flags (); |
276 | } |
260 | } |
277 | |
261 | |
278 | /* |
262 | /* |
279 | * Returns true if the given coordinate is blocked except by the |
263 | * Returns true if the given coordinate is blocked except by the |
280 | * object passed is not blocking. This is used with |
264 | * object passed is not blocking. This is used with |
… | |
… | |
303 | } |
287 | } |
304 | |
288 | |
305 | /* Save some cycles - instead of calling get_map_flags(), just get the value |
289 | /* Save some cycles - instead of calling get_map_flags(), just get the value |
306 | * directly. |
290 | * directly. |
307 | */ |
291 | */ |
308 | mflags = m->spaces[sx + m->width * sy].flags; |
292 | mflags = m->at (sx, sy).flags (); |
309 | |
293 | |
310 | blocked = GET_MAP_MOVE_BLOCK (m, sx, sy); |
294 | blocked = GET_MAP_MOVE_BLOCK (m, sx, sy); |
311 | |
295 | |
312 | /* If space is currently not blocked by anything, no need to |
296 | /* If space is currently not blocked by anything, no need to |
313 | * go further. Not true for players - all sorts of special |
297 | * go further. Not true for players - all sorts of special |
… | |
… | |
332 | /* We basically go through the stack of objects, and if there is |
316 | /* We basically go through the stack of objects, and if there is |
333 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
317 | * some other object that has NO_PASS or FLAG_ALIVE set, return |
334 | * true. If we get through the entire stack, that must mean |
318 | * true. If we get through the entire stack, that must mean |
335 | * ob is blocking it, so return 0. |
319 | * ob is blocking it, so return 0. |
336 | */ |
320 | */ |
337 | for (tmp = GET_MAP_OB (m, sx, sy); tmp != NULL; tmp = tmp->above) |
321 | for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above) |
338 | { |
322 | { |
339 | |
323 | |
340 | /* This must be before the checks below. Code for inventory checkers. */ |
324 | /* This must be before the checks below. Code for inventory checkers. */ |
341 | if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) |
325 | if (tmp->type == CHECK_INV && OB_MOVE_BLOCK (ob, tmp)) |
342 | { |
326 | { |
… | |
… | |
406 | * |
390 | * |
407 | * Note this used to be arch_blocked, but with new movement |
391 | * Note this used to be arch_blocked, but with new movement |
408 | * code, we need to have actual object to check its move_type |
392 | * code, we need to have actual object to check its move_type |
409 | * against the move_block values. |
393 | * against the move_block values. |
410 | */ |
394 | */ |
411 | |
|
|
412 | int |
395 | int |
413 | ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) |
396 | ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) |
414 | { |
397 | { |
415 | archetype *tmp; |
398 | archetype *tmp; |
416 | int flag; |
399 | int flag; |
… | |
… | |
422 | flag = get_map_flags (m, &m1, x, y, &sx, &sy); |
405 | flag = get_map_flags (m, &m1, x, y, &sx, &sy); |
423 | if (flag & P_OUT_OF_MAP) |
406 | if (flag & P_OUT_OF_MAP) |
424 | return P_OUT_OF_MAP; |
407 | return P_OUT_OF_MAP; |
425 | |
408 | |
426 | /* don't have object, so don't know what types would block */ |
409 | /* don't have object, so don't know what types would block */ |
427 | return (GET_MAP_MOVE_BLOCK (m1, sx, sy)); |
410 | return m1->at (sx, sy).move_block; |
428 | } |
411 | } |
429 | |
412 | |
430 | for (tmp = ob->arch; tmp != NULL; tmp = tmp->more) |
413 | for (tmp = ob->arch; tmp; tmp = tmp->more) |
431 | { |
414 | { |
432 | flag = get_map_flags (m, &m1, x + tmp->clone.x, y + tmp->clone.y, &sx, &sy); |
415 | flag = get_map_flags (m, &m1, x + tmp->clone.x, y + tmp->clone.y, &sx, &sy); |
433 | |
416 | |
434 | if (flag & P_OUT_OF_MAP) |
417 | if (flag & P_OUT_OF_MAP) |
435 | return P_OUT_OF_MAP; |
418 | return P_OUT_OF_MAP; |
436 | if (flag & P_IS_ALIVE) |
419 | if (flag & P_IS_ALIVE) |
437 | return P_IS_ALIVE; |
420 | return P_IS_ALIVE; |
438 | |
421 | |
|
|
422 | mapspace &ms = m1->at (sx, sy); |
|
|
423 | |
|
|
424 | |
439 | /* find_first_free_spot() calls this function. However, often |
425 | /* find_first_free_spot() calls this function. However, often |
440 | * ob doesn't have any move type (when used to place exits) |
426 | * ob doesn't have any move type (when used to place exits) |
441 | * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. |
427 | * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. |
442 | */ |
428 | */ |
443 | |
429 | |
444 | if (ob->move_type == 0 && GET_MAP_MOVE_BLOCK (m1, sx, sy) != MOVE_ALL) |
430 | if (ob->move_type == 0 && ms.move_block != MOVE_ALL) |
445 | continue; |
431 | continue; |
446 | |
432 | |
447 | /* Note it is intentional that we check ob - the movement type of the |
433 | /* Note it is intentional that we check ob - the movement type of the |
448 | * head of the object should correspond for the entire object. |
434 | * head of the object should correspond for the entire object. |
449 | */ |
435 | */ |
450 | if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m1, sx, sy))) |
436 | if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block)) |
451 | return AB_NO_PASS; |
437 | return P_NO_PASS; |
452 | |
|
|
453 | } |
438 | } |
|
|
439 | |
454 | return 0; |
440 | return 0; |
455 | } |
441 | } |
456 | |
442 | |
457 | /* When the map is loaded, load_object does not actually insert objects |
443 | /* When the map is loaded, load_object does not actually insert objects |
458 | * into inventory, but just links them. What this does is go through |
444 | * into inventory, but just links them. What this does is go through |
… | |
… | |
485 | * for objects whose arch says they are multipart yet according to the |
471 | * for objects whose arch says they are multipart yet according to the |
486 | * info we have, they only have the head (as would be expected when |
472 | * info we have, they only have the head (as would be expected when |
487 | * they are saved). We do have to look for the old maps that did save |
473 | * they are saved). We do have to look for the old maps that did save |
488 | * the more sections and not re-add sections for them. |
474 | * the more sections and not re-add sections for them. |
489 | */ |
475 | */ |
490 | |
|
|
491 | static void |
476 | static void |
492 | link_multipart_objects (maptile *m) |
477 | link_multipart_objects (maptile *m) |
493 | { |
478 | { |
494 | int x, y; |
479 | int x, y; |
495 | object *tmp, *op, *last, *above; |
480 | object *tmp, *op, *last, *above; |
496 | archetype *at; |
481 | archetype *at; |
497 | |
482 | |
498 | for (x = 0; x < MAP_WIDTH (m); x++) |
483 | for (x = 0; x < m->width; x++) |
499 | for (y = 0; y < MAP_HEIGHT (m); y++) |
484 | for (y = 0; y < m->height; y++) |
500 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = above) |
485 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above) |
501 | { |
486 | { |
502 | above = tmp->above; |
487 | above = tmp->above; |
503 | |
488 | |
504 | /* already multipart - don't do anything more */ |
489 | /* already multipart - don't do anything more */ |
505 | if (tmp->head || tmp->more) |
490 | if (tmp->head || tmp->more) |
… | |
… | |
540 | { |
525 | { |
541 | int i, j; |
526 | int i, j; |
542 | int unique; |
527 | int unique; |
543 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
528 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
544 | |
529 | |
545 | op = get_object (); |
530 | op = object::create (); |
546 | op->map = m; /* To handle buttons correctly */ |
531 | op->map = m; /* To handle buttons correctly */ |
547 | |
532 | |
548 | while ((i = load_object (fp, op, mapflags))) |
533 | while ((i = load_object (fp, op, mapflags))) |
549 | { |
534 | { |
550 | /* if the archetype for the object is null, means that we |
535 | /* if the archetype for the object is null, means that we |
… | |
… | |
555 | { |
540 | { |
556 | LOG (llevDebug, "Discarding object without arch: %s\n", op->name ? (const char *) op->name : "(null)"); |
541 | LOG (llevDebug, "Discarding object without arch: %s\n", op->name ? (const char *) op->name : "(null)"); |
557 | continue; |
542 | continue; |
558 | } |
543 | } |
559 | |
544 | |
560 | |
|
|
561 | switch (i) |
545 | switch (i) |
562 | { |
546 | { |
563 | case LL_NORMAL: |
547 | case LL_NORMAL: |
564 | /* if we are loading an overlay, put the floors on the bottom */ |
548 | /* if we are loading an overlay, put the floors on the bottom */ |
565 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
549 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
566 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
550 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
567 | else |
551 | else |
568 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
552 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
569 | |
553 | |
570 | if (op->inv) |
554 | if (op->inv) |
571 | sum_weight (op); |
555 | sum_weight (op); |
572 | |
556 | |
573 | prev = op, last_more = op; |
557 | prev = op, last_more = op; |
574 | break; |
558 | break; |
575 | |
559 | |
576 | case LL_MORE: |
560 | case LL_MORE: |
577 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
561 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
578 | op->head = prev, last_more->more = op, last_more = op; |
562 | op->head = prev, last_more->more = op, last_more = op; |
579 | break; |
563 | break; |
580 | } |
564 | } |
581 | |
565 | |
582 | if (mapflags & MAP_STYLE) |
566 | if (mapflags & MAP_STYLE) |
583 | remove_from_active_list (op); |
567 | remove_from_active_list (op); |
584 | |
568 | |
585 | op = get_object (); |
569 | op = object::create (); |
586 | op->map = m; |
570 | op->map = m; |
587 | } |
571 | } |
588 | |
572 | |
589 | for (i = 0; i < m->width; i++) |
573 | for (i = 0; i < m->width; i++) |
590 | { |
574 | { |
591 | for (j = 0; j < m->height; j++) |
575 | for (j = 0; j < m->height; j++) |
592 | { |
576 | { |
593 | unique = 0; |
577 | unique = 0; |
594 | /* check for unique items, or unique squares */ |
578 | /* check for unique items, or unique squares */ |
595 | for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) |
579 | for (otmp = GET_MAP_OB (m, i, j); otmp; otmp = otmp->above) |
596 | { |
580 | { |
597 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
581 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
598 | unique = 1; |
582 | unique = 1; |
|
|
583 | |
599 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
584 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
600 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
585 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
601 | } |
586 | } |
602 | } |
587 | } |
603 | } |
588 | } |
604 | |
589 | |
605 | free_object (op); |
590 | op->destroy (); |
606 | link_multipart_objects (m); |
591 | link_multipart_objects (m); |
607 | } |
592 | } |
608 | |
593 | |
609 | /* This saves all the objects on the map in a non destructive fashion. |
594 | /* This saves all the objects on the map in a non destructive fashion. |
610 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
595 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
611 | * and we only save the head of multi part objects - this is needed |
596 | * and we only save the head of multi part objects - this is needed |
612 | * in order to do map tiling properly. |
597 | * in order to do map tiling properly. |
613 | */ |
598 | */ |
614 | void |
599 | void |
615 | save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag) |
600 | save_objects (maptile *m, object_freezer &fp, object_freezer &fp2, int flag) |
616 | { |
601 | { |
617 | int i, j = 0, unique = 0; |
602 | int i, j = 0, unique = 0; |
618 | object *op; |
603 | object *op; |
619 | |
604 | |
620 | /* first pass - save one-part objects */ |
605 | /* first pass - save one-part objects */ |
621 | for (i = 0; i < MAP_WIDTH (m); i++) |
606 | for (i = 0; i < m->width; i++) |
622 | for (j = 0; j < MAP_HEIGHT (m); j++) |
607 | for (j = 0; j < m->height; j++) |
623 | { |
608 | { |
624 | unique = 0; |
609 | unique = 0; |
|
|
610 | |
625 | for (op = get_map_ob (m, i, j); op; op = op->above) |
611 | for (op = m->at (i, j).bot; op; op = op->above) |
626 | { |
612 | { |
627 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
613 | if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) |
628 | unique = 1; |
614 | unique = 1; |
629 | |
615 | |
630 | if (op->type == PLAYER) |
616 | if (!op->can_map_save ()) |
631 | { |
|
|
632 | LOG (llevDebug, "Player on map that is being saved\n"); |
|
|
633 | continue; |
|
|
634 | } |
|
|
635 | |
|
|
636 | if (op->head || op->owner) |
|
|
637 | continue; |
617 | continue; |
638 | |
618 | |
639 | if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) |
619 | if (unique || op->flag [FLAG_UNIQUE]) |
640 | save_object (fp2, op, 3); |
620 | save_object (fp2, op, 1); |
641 | else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) |
621 | else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID]))) |
642 | save_object (fp, op, 3); |
622 | save_object (fp, op, 1); |
643 | |
623 | } |
644 | } /* for this space */ |
624 | } |
645 | } /* for this j */ |
|
|
646 | } |
625 | } |
647 | |
626 | |
648 | maptile::maptile () |
627 | maptile::maptile () |
649 | { |
628 | { |
650 | in_memory = MAP_SWAPPED; |
629 | in_memory = MAP_SWAPPED; |
|
|
630 | |
651 | /* The maps used to pick up default x and y values from the |
631 | /* The maps used to pick up default x and y values from the |
652 | * map archetype. Mimic that behaviour. |
632 | * map archetype. Mimic that behaviour. |
653 | */ |
633 | */ |
654 | MAP_WIDTH (this) = 16; |
634 | width = 16; |
655 | MAP_HEIGHT (this) = 16; |
635 | height = 16; |
656 | MAP_RESET_TIMEOUT (this) = 0; |
636 | reset_timeout = 0; |
657 | MAP_TIMEOUT (this) = 300; |
637 | timeout = 300; |
658 | MAP_ENTER_X (this) = 0; |
638 | enter_x = 0; |
659 | MAP_ENTER_Y (this) = 0; |
639 | enter_y = 0; |
660 | /*set part to -1 indicating conversion to weather map not yet done */ |
640 | /*set part to -1 indicating conversion to weather map not yet done */ |
661 | MAP_WORLDPARTX (this) = -1; |
641 | worldpartx = -1; |
662 | MAP_WORLDPARTY (this) = -1; |
642 | worldparty = -1; |
|
|
643 | } |
|
|
644 | |
|
|
645 | void |
|
|
646 | maptile::link () |
|
|
647 | { |
|
|
648 | next = first_map; |
|
|
649 | first_map = this; |
|
|
650 | } |
|
|
651 | |
|
|
652 | void |
|
|
653 | maptile::unlink () |
|
|
654 | { |
|
|
655 | if (first_map == this) |
|
|
656 | first_map = next; |
|
|
657 | else |
|
|
658 | { |
|
|
659 | for_all_maps (m) |
|
|
660 | if (m->next = this) |
|
|
661 | { |
|
|
662 | m->next = next; |
|
|
663 | return; |
|
|
664 | } |
|
|
665 | |
|
|
666 | LOG (llevError, "maptile::unlink() map not on list: %s\n", path); |
|
|
667 | } |
663 | } |
668 | } |
664 | |
669 | |
665 | /* |
670 | /* |
666 | * Allocates, initialises, and returns a pointer to a maptile. |
671 | * Allocates, initialises, and returns a pointer to a maptile. |
667 | * Modified to no longer take a path option which was not being |
672 | * Modified to no longer take a path option which was not being |
668 | * used anyways. MSW 2001-07-01 |
673 | * used anyways. MSW 2001-07-01 |
669 | */ |
674 | */ |
670 | maptile * |
675 | maptile * |
671 | get_linked_map (void) |
676 | get_linked_map (void) |
672 | { |
677 | { |
673 | maptile *mp, *map = new maptile; |
678 | maptile *map = new maptile; |
674 | |
679 | map->link (); |
675 | for (mp = first_map; mp && mp->next; mp = mp->next); |
|
|
676 | |
|
|
677 | if (mp == NULL) |
|
|
678 | first_map = map; |
|
|
679 | else |
|
|
680 | mp->next = map; |
|
|
681 | |
|
|
682 | return map; |
680 | return map; |
683 | } |
681 | } |
684 | |
682 | |
685 | /* |
683 | /* |
686 | * Allocates the arrays contained in a maptile. |
684 | * Allocates the arrays contained in a maptile. |
… | |
… | |
697 | * that is their poor assumption. |
695 | * that is their poor assumption. |
698 | */ |
696 | */ |
699 | if (spaces) |
697 | if (spaces) |
700 | { |
698 | { |
701 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
699 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
702 | free (spaces); |
700 | sfree (spaces, size ()); |
703 | } |
701 | } |
704 | |
702 | |
705 | spaces = (MapSpace *) |
703 | spaces = salloc0<mapspace> (size ()); |
706 | calloc (1, width * height * sizeof (MapSpace)); |
|
|
707 | |
|
|
708 | if (!spaces) |
|
|
709 | fatal (OUT_OF_MEMORY); |
|
|
710 | } |
704 | } |
711 | |
705 | |
712 | /* Create and returns a map of the specific size. Used |
706 | /* Create and returns a map of the specific size. Used |
713 | * in random map code and the editor. |
707 | * in random map code and the editor. |
714 | */ |
708 | */ |
715 | maptile * |
709 | maptile * |
716 | get_empty_map (int sizex, int sizey) |
710 | get_empty_map (int sizex, int sizey) |
717 | { |
711 | { |
718 | maptile *m = get_linked_map (); |
712 | maptile *m = get_linked_map (); |
719 | |
713 | |
720 | m->width = sizex; |
714 | m->width = sizex; |
721 | m->height = sizey; |
715 | m->height = sizey; |
722 | m->in_memory = MAP_SWAPPED; |
716 | m->in_memory = MAP_SWAPPED; |
|
|
717 | |
723 | m->allocate (); |
718 | m->allocate (); |
724 | |
719 | |
725 | return m; |
720 | return m; |
726 | } |
721 | } |
727 | |
722 | |
728 | /* Takes a string from a map definition and outputs a pointer to the array of shopitems |
723 | /* Takes a string from a map definition and outputs a pointer to the array of shopitems |
729 | * corresponding to that string. Memory is allocated for this, it must be freed |
724 | * corresponding to that string. Memory is allocated for this, it must be freed |
730 | * at a later date. |
725 | * at a later date. |
731 | * Called by parse_map_headers below. |
726 | * Called by parse_map_headers below. |
732 | */ |
727 | */ |
733 | |
|
|
734 | static shopitems * |
728 | static shopitems * |
735 | parse_shop_string (const char *input_string) |
729 | parse_shop_string (const char *input_string) |
736 | { |
730 | { |
737 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
731 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
738 | shopitems *items = NULL; |
732 | shopitems *items = NULL; |
739 | int i = 0, number_of_entries = 0; |
733 | int i = 0, number_of_entries = 0; |
740 | const typedata *current_type; |
734 | const typedata *current_type; |
741 | |
735 | |
742 | shop_string = strdup_local (input_string); |
736 | shop_string = strdup (input_string); |
743 | p = shop_string; |
737 | p = shop_string; |
744 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
738 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
745 | while (p) |
739 | while (p) |
746 | { |
740 | { |
747 | p = strchr (p, ';'); |
741 | p = strchr (p, ';'); |
748 | number_of_entries++; |
742 | number_of_entries++; |
749 | if (p) |
743 | if (p) |
750 | p++; |
744 | p++; |
751 | } |
745 | } |
|
|
746 | |
752 | p = shop_string; |
747 | p = shop_string; |
753 | strip_endline (p); |
748 | strip_endline (p); |
754 | items = new shopitems[number_of_entries + 1]; |
749 | items = new shopitems[number_of_entries + 1]; |
755 | for (i = 0; i < number_of_entries; i++) |
750 | for (i = 0; i < number_of_entries; i++) |
756 | { |
751 | { |
757 | if (!p) |
752 | if (!p) |
758 | { |
753 | { |
759 | LOG (llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n"); |
754 | LOG (llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n"); |
760 | break; |
755 | break; |
761 | } |
756 | } |
|
|
757 | |
762 | next_semicolon = strchr (p, ';'); |
758 | next_semicolon = strchr (p, ';'); |
763 | next_colon = strchr (p, ':'); |
759 | next_colon = strchr (p, ':'); |
764 | /* if there is a stregth specified, figure out what it is, we'll need it soon. */ |
760 | /* if there is a stregth specified, figure out what it is, we'll need it soon. */ |
765 | if (next_colon && (!next_semicolon || next_colon < next_semicolon)) |
761 | if (next_colon && (!next_semicolon || next_colon < next_semicolon)) |
766 | items[i].strength = atoi (strchr (p, ':') + 1); |
762 | items[i].strength = atoi (strchr (p, ':') + 1); |
… | |
… | |
793 | * the next entry while we're at it, better print a warning |
789 | * the next entry while we're at it, better print a warning |
794 | */ |
790 | */ |
795 | LOG (llevError, "invalid type %s defined in shopitems in string %s\n", p, input_string); |
791 | LOG (llevError, "invalid type %s defined in shopitems in string %s\n", p, input_string); |
796 | } |
792 | } |
797 | } |
793 | } |
|
|
794 | |
798 | items[i].index = number_of_entries; |
795 | items[i].index = number_of_entries; |
799 | if (next_semicolon) |
796 | if (next_semicolon) |
800 | p = ++next_semicolon; |
797 | p = ++next_semicolon; |
801 | else |
798 | else |
802 | p = NULL; |
799 | p = NULL; |
803 | } |
800 | } |
|
|
801 | |
804 | free (shop_string); |
802 | free (shop_string); |
805 | return items; |
803 | return items; |
806 | } |
804 | } |
807 | |
805 | |
808 | /* opposite of parse string, this puts the string that was originally fed in to |
806 | /* opposite of parse string, this puts the string that was originally fed in to |
… | |
… | |
817 | for (i = 0; i < m->shopitems[0].index; i++) |
815 | for (i = 0; i < m->shopitems[0].index; i++) |
818 | { |
816 | { |
819 | if (m->shopitems[i].typenum) |
817 | if (m->shopitems[i].typenum) |
820 | { |
818 | { |
821 | if (m->shopitems[i].strength) |
819 | if (m->shopitems[i].strength) |
822 | { |
|
|
823 | sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); |
820 | sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); |
824 | } |
|
|
825 | else |
821 | else |
826 | sprintf (tmp, "%s;", m->shopitems[i].name); |
822 | sprintf (tmp, "%s;", m->shopitems[i].name); |
827 | } |
823 | } |
828 | else |
824 | else |
829 | { |
825 | { |
830 | if (m->shopitems[i].strength) |
826 | if (m->shopitems[i].strength) |
831 | { |
|
|
832 | sprintf (tmp, "*:%d;", m->shopitems[i].strength); |
827 | sprintf (tmp, "*:%d;", m->shopitems[i].strength); |
833 | } |
|
|
834 | else |
828 | else |
835 | sprintf (tmp, "*"); |
829 | sprintf (tmp, "*"); |
836 | } |
830 | } |
|
|
831 | |
837 | strcat (output_string, tmp); |
832 | strcat (output_string, tmp); |
838 | } |
833 | } |
839 | } |
834 | } |
840 | |
835 | |
841 | /* This loads the header information of the map. The header |
836 | /* This loads the header information of the map. The header |
… | |
… | |
856 | { |
851 | { |
857 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
852 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
858 | int msgpos = 0; |
853 | int msgpos = 0; |
859 | int maplorepos = 0; |
854 | int maplorepos = 0; |
860 | |
855 | |
861 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
856 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
862 | { |
857 | { |
863 | buf[HUGE_BUF - 1] = 0; |
858 | buf[HUGE_BUF - 1] = 0; |
864 | key = buf; |
859 | key = buf; |
|
|
860 | |
865 | while (isspace (*key)) |
861 | while (isspace (*key)) |
866 | key++; |
862 | key++; |
|
|
863 | |
867 | if (*key == 0) |
864 | if (*key == 0) |
868 | continue; /* empty line */ |
865 | continue; /* empty line */ |
|
|
866 | |
869 | value = strchr (key, ' '); |
867 | value = strchr (key, ' '); |
|
|
868 | |
870 | if (!value) |
869 | if (!value) |
871 | { |
870 | { |
872 | end = strchr (key, '\n'); |
871 | if ((end = strchr (key, '\n'))) |
873 | if (end != NULL) |
|
|
874 | { |
|
|
875 | *end = 0; |
872 | *end = 0; |
876 | } |
|
|
877 | } |
873 | } |
878 | else |
874 | else |
879 | { |
875 | { |
880 | *value = 0; |
876 | *value = 0; |
881 | value++; |
877 | value++; |
882 | end = strchr (value, '\n'); |
878 | end = strchr (value, '\n'); |
|
|
879 | |
883 | while (isspace (*value)) |
880 | while (isspace (*value)) |
884 | { |
881 | { |
885 | value++; |
882 | value++; |
|
|
883 | |
886 | if (*value == '\0' || value == end) |
884 | if (*value == '\0' || value == end) |
887 | { |
885 | { |
888 | /* Nothing but spaces. */ |
886 | /* Nothing but spaces. */ |
889 | value = NULL; |
887 | value = NULL; |
890 | break; |
888 | break; |
… | |
… | |
913 | * that use the parameter. |
911 | * that use the parameter. |
914 | */ |
912 | */ |
915 | |
913 | |
916 | if (!strcmp (key, "msg")) |
914 | if (!strcmp (key, "msg")) |
917 | { |
915 | { |
918 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
916 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
919 | { |
917 | { |
920 | if (!strcmp (buf, "endmsg\n")) |
918 | if (!strcmp (buf, "endmsg\n")) |
921 | break; |
919 | break; |
922 | else |
920 | else |
923 | { |
921 | { |
… | |
… | |
930 | * with nothing between). There is no reason in those cases to |
928 | * with nothing between). There is no reason in those cases to |
931 | * keep the empty message. Also, msgbuf contains garbage data |
929 | * keep the empty message. Also, msgbuf contains garbage data |
932 | * when msgpos is zero, so copying it results in crashes |
930 | * when msgpos is zero, so copying it results in crashes |
933 | */ |
931 | */ |
934 | if (msgpos != 0) |
932 | if (msgpos != 0) |
935 | m->msg = strdup_local (msgbuf); |
933 | m->msg = strdup (msgbuf); |
936 | } |
934 | } |
937 | else if (!strcmp (key, "maplore")) |
935 | else if (!strcmp (key, "maplore")) |
938 | { |
936 | { |
939 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
937 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
940 | { |
938 | { |
941 | if (!strcmp (buf, "endmaplore\n")) |
939 | if (!strcmp (buf, "endmaplore\n")) |
942 | break; |
940 | break; |
943 | else |
941 | else |
944 | { |
942 | { |
… | |
… | |
946 | strcpy (maplorebuf + maplorepos, buf); |
944 | strcpy (maplorebuf + maplorepos, buf); |
947 | maplorepos += strlen (buf); |
945 | maplorepos += strlen (buf); |
948 | } |
946 | } |
949 | } |
947 | } |
950 | if (maplorepos != 0) |
948 | if (maplorepos != 0) |
951 | m->maplore = strdup_local (maplorebuf); |
949 | m->maplore = strdup (maplorebuf); |
952 | } |
950 | } |
953 | else if (!strcmp (key, "end")) |
951 | else if (!strcmp (key, "end")) |
954 | { |
952 | { |
955 | break; |
953 | break; |
956 | } |
954 | } |
… | |
… | |
965 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
963 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
966 | } |
964 | } |
967 | else if (!strcmp (key, "name")) |
965 | else if (!strcmp (key, "name")) |
968 | { |
966 | { |
969 | *end = 0; |
967 | *end = 0; |
970 | m->name = strdup_local (value); |
968 | m->name = strdup (value); |
971 | } |
969 | } |
972 | /* first strcmp value on these are old names supported |
970 | /* first strcmp value on these are old names supported |
973 | * for compatibility reasons. The new values (second) are |
971 | * for compatibility reasons. The new values (second) are |
974 | * what really should be used. |
972 | * what really should be used. |
975 | */ |
973 | */ |
976 | else if (!strcmp (key, "oid")) |
974 | else if (!strcmp (key, "oid")) |
977 | { |
|
|
978 | fp.get (m, atoi (value)); |
975 | fp.get (m, atoi (value)); |
979 | } |
|
|
980 | else if (!strcmp (key, "attach")) |
976 | else if (!strcmp (key, "attach")) |
981 | { |
|
|
982 | m->attach = value; |
977 | m->attach = value; |
983 | } |
|
|
984 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
978 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
985 | { |
|
|
986 | m->enter_x = atoi (value); |
979 | m->enter_x = atoi (value); |
987 | } |
|
|
988 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
980 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
989 | { |
|
|
990 | m->enter_y = atoi (value); |
981 | m->enter_y = atoi (value); |
991 | } |
|
|
992 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
982 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
993 | { |
|
|
994 | m->width = atoi (value); |
983 | m->width = atoi (value); |
995 | } |
|
|
996 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
984 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
997 | { |
|
|
998 | m->height = atoi (value); |
985 | m->height = atoi (value); |
999 | } |
|
|
1000 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
986 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
1001 | { |
|
|
1002 | m->reset_timeout = atoi (value); |
987 | m->reset_timeout = atoi (value); |
1003 | } |
|
|
1004 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
988 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
1005 | { |
|
|
1006 | m->timeout = atoi (value); |
989 | m->timeout = atoi (value); |
1007 | } |
|
|
1008 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
990 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
1009 | { |
991 | m->difficulty = clamp (atoi (value), 1, settings.max_level); |
1010 | m->difficulty = atoi (value); |
|
|
1011 | } |
|
|
1012 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
992 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
1013 | { |
|
|
1014 | m->darkness = atoi (value); |
993 | m->darkness = atoi (value); |
1015 | } |
|
|
1016 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
994 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
1017 | { |
|
|
1018 | m->fixed_resettime = atoi (value); |
995 | m->fixed_resettime = atoi (value); |
1019 | } |
|
|
1020 | else if (!strcmp (key, "unique")) |
996 | else if (!strcmp (key, "unique")) |
1021 | { |
|
|
1022 | m->unique = atoi (value); |
997 | m->unique = atoi (value); |
1023 | } |
|
|
1024 | else if (!strcmp (key, "template")) |
998 | else if (!strcmp (key, "template")) |
1025 | { |
|
|
1026 | m->templatemap = atoi (value); |
999 | m->templatemap = atoi (value); |
1027 | } |
|
|
1028 | else if (!strcmp (key, "region")) |
1000 | else if (!strcmp (key, "region")) |
1029 | { |
|
|
1030 | m->region = get_region_by_name (value); |
1001 | m->region = get_region_by_name (value); |
1031 | } |
|
|
1032 | else if (!strcmp (key, "shopitems")) |
1002 | else if (!strcmp (key, "shopitems")) |
1033 | { |
1003 | { |
1034 | *end = 0; |
1004 | *end = 0; |
1035 | m->shopitems = parse_shop_string (value); |
1005 | m->shopitems = parse_shop_string (value); |
1036 | } |
1006 | } |
1037 | else if (!strcmp (key, "shopgreed")) |
1007 | else if (!strcmp (key, "shopgreed")) |
1038 | { |
|
|
1039 | m->shopgreed = atof (value); |
1008 | m->shopgreed = atof (value); |
1040 | } |
|
|
1041 | else if (!strcmp (key, "shopmin")) |
1009 | else if (!strcmp (key, "shopmin")) |
1042 | { |
|
|
1043 | m->shopmin = atol (value); |
1010 | m->shopmin = atol (value); |
1044 | } |
|
|
1045 | else if (!strcmp (key, "shopmax")) |
1011 | else if (!strcmp (key, "shopmax")) |
1046 | { |
|
|
1047 | m->shopmax = atol (value); |
1012 | m->shopmax = atol (value); |
1048 | } |
|
|
1049 | else if (!strcmp (key, "shoprace")) |
1013 | else if (!strcmp (key, "shoprace")) |
1050 | { |
1014 | { |
1051 | *end = 0; |
1015 | *end = 0; |
1052 | m->shoprace = strdup_local (value); |
1016 | m->shoprace = strdup (value); |
1053 | } |
1017 | } |
1054 | else if (!strcmp (key, "outdoor")) |
1018 | else if (!strcmp (key, "outdoor")) |
1055 | { |
|
|
1056 | m->outdoor = atoi (value); |
1019 | m->outdoor = atoi (value); |
1057 | } |
|
|
1058 | else if (!strcmp (key, "temp")) |
1020 | else if (!strcmp (key, "temp")) |
1059 | { |
|
|
1060 | m->temp = atoi (value); |
1021 | m->temp = atoi (value); |
1061 | } |
|
|
1062 | else if (!strcmp (key, "pressure")) |
1022 | else if (!strcmp (key, "pressure")) |
1063 | { |
|
|
1064 | m->pressure = atoi (value); |
1023 | m->pressure = atoi (value); |
1065 | } |
|
|
1066 | else if (!strcmp (key, "humid")) |
1024 | else if (!strcmp (key, "humid")) |
1067 | { |
|
|
1068 | m->humid = atoi (value); |
1025 | m->humid = atoi (value); |
1069 | } |
|
|
1070 | else if (!strcmp (key, "windspeed")) |
1026 | else if (!strcmp (key, "windspeed")) |
1071 | { |
|
|
1072 | m->windspeed = atoi (value); |
1027 | m->windspeed = atoi (value); |
1073 | } |
|
|
1074 | else if (!strcmp (key, "winddir")) |
1028 | else if (!strcmp (key, "winddir")) |
1075 | { |
|
|
1076 | m->winddir = atoi (value); |
1029 | m->winddir = atoi (value); |
1077 | } |
|
|
1078 | else if (!strcmp (key, "sky")) |
1030 | else if (!strcmp (key, "sky")) |
1079 | { |
|
|
1080 | m->sky = atoi (value); |
1031 | m->sky = atoi (value); |
1081 | } |
|
|
1082 | else if (!strcmp (key, "nosmooth")) |
1032 | else if (!strcmp (key, "nosmooth")) |
1083 | { |
|
|
1084 | m->nosmooth = atoi (value); |
1033 | m->nosmooth = atoi (value); |
1085 | } |
|
|
1086 | else if (!strncmp (key, "tile_path_", 10)) |
1034 | else if (!strncmp (key, "tile_path_", 10)) |
1087 | { |
1035 | { |
1088 | int tile = atoi (key + 10); |
1036 | int tile = atoi (key + 10); |
1089 | |
1037 | |
1090 | if (tile < 1 || tile > 4) |
1038 | if (tile < 1 || tile > 4) |
… | |
… | |
1123 | } |
1071 | } |
1124 | |
1072 | |
1125 | if (editor) |
1073 | if (editor) |
1126 | { |
1074 | { |
1127 | /* Use the value as in the file. */ |
1075 | /* Use the value as in the file. */ |
1128 | m->tile_path[tile - 1] = strdup_local (value); |
1076 | m->tile_path[tile - 1] = strdup (value); |
1129 | } |
1077 | } |
1130 | else if (path != NULL) |
1078 | else if (path != NULL) |
1131 | { |
1079 | { |
1132 | /* Use the normalized value. */ |
1080 | /* Use the normalized value. */ |
1133 | m->tile_path[tile - 1] = strdup_local (path); |
1081 | m->tile_path[tile - 1] = strdup (path); |
1134 | } |
1082 | } |
1135 | } /* end if tile direction (in)valid */ |
1083 | } /* end if tile direction (in)valid */ |
1136 | } |
1084 | } |
1137 | else |
1085 | else |
1138 | { |
|
|
1139 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1086 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1140 | } |
|
|
1141 | } |
1087 | } |
|
|
1088 | |
1142 | if (!key || strcmp (key, "end")) |
1089 | if (!key || strcmp (key, "end")) |
1143 | { |
1090 | { |
1144 | LOG (llevError, "Got premature eof on map header!\n"); |
1091 | LOG (llevError, "Got premature eof on map header!\n"); |
1145 | return 1; |
1092 | return 1; |
1146 | } |
1093 | } |
|
|
1094 | |
1147 | return 0; |
1095 | return 0; |
1148 | } |
1096 | } |
1149 | |
1097 | |
1150 | /* |
1098 | /* |
1151 | * Opens the file "filename" and reads information about the map |
1099 | * Opens the file "filename" and reads information about the map |
… | |
… | |
1156 | * MAP_BLOCK, in which case we block on this load. This happens in all |
1104 | * MAP_BLOCK, in which case we block on this load. This happens in all |
1157 | * cases, no matter if this flag is set or not. |
1105 | * cases, no matter if this flag is set or not. |
1158 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1106 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1159 | * managed map list. |
1107 | * managed map list. |
1160 | */ |
1108 | */ |
1161 | |
|
|
1162 | maptile * |
1109 | maptile * |
1163 | load_original_map (const char *filename, int flags) |
1110 | load_original_map (const char *filename, int flags) |
1164 | { |
1111 | { |
1165 | maptile *m; |
1112 | maptile *m; |
1166 | char pathname[MAX_BUF]; |
1113 | char pathname[MAX_BUF]; |
… | |
… | |
1184 | strcpy (m->path, filename); |
1131 | strcpy (m->path, filename); |
1185 | if (load_map_header (thawer, m)) |
1132 | if (load_map_header (thawer, m)) |
1186 | { |
1133 | { |
1187 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1134 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1188 | delete_map (m); |
1135 | delete_map (m); |
1189 | return NULL; |
1136 | return 0; |
1190 | } |
1137 | } |
1191 | |
1138 | |
1192 | m->allocate (); |
1139 | m->allocate (); |
1193 | |
1140 | |
1194 | m->in_memory = MAP_LOADING; |
1141 | m->in_memory = MAP_LOADING; |
1195 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1142 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1196 | |
1143 | |
1197 | m->in_memory = MAP_IN_MEMORY; |
1144 | m->in_memory = MAP_IN_MEMORY; |
1198 | if (!MAP_DIFFICULTY (m)) |
1145 | if (!m->difficulty) |
1199 | MAP_DIFFICULTY (m) = calculate_difficulty (m); |
1146 | m->difficulty = calculate_difficulty (m); |
1200 | set_map_reset_time (m); |
1147 | set_map_reset_time (m); |
1201 | m->instantiate (); |
1148 | m->instantiate (); |
1202 | return (m); |
1149 | return (m); |
1203 | } |
1150 | } |
1204 | |
1151 | |
1205 | /* |
1152 | /* |
1206 | * Loads a map, which has been loaded earlier, from file. |
1153 | * Loads a map, which has been loaded earlier, from file. |
1207 | * Return the map object we load into (this can change from the passed |
1154 | * Return the map object we load into (this can change from the passed |
1208 | * option if we can't find the original map) |
1155 | * option if we can't find the original map) |
1209 | */ |
1156 | */ |
1210 | |
|
|
1211 | static maptile * |
1157 | static maptile * |
1212 | load_temporary_map (maptile *m) |
1158 | load_temporary_map (maptile *m) |
1213 | { |
1159 | { |
1214 | char buf[MAX_BUF]; |
1160 | char buf[MAX_BUF]; |
1215 | |
1161 | |
… | |
… | |
1259 | /* |
1205 | /* |
1260 | * Loads a map, which has been loaded earlier, from file. |
1206 | * Loads a map, which has been loaded earlier, from file. |
1261 | * Return the map object we load into (this can change from the passed |
1207 | * Return the map object we load into (this can change from the passed |
1262 | * option if we can't find the original map) |
1208 | * option if we can't find the original map) |
1263 | */ |
1209 | */ |
1264 | |
|
|
1265 | maptile * |
1210 | maptile * |
1266 | load_overlay_map (const char *filename, maptile *m) |
1211 | load_overlay_map (const char *filename, maptile *m) |
1267 | { |
1212 | { |
1268 | char pathname[MAX_BUF]; |
1213 | char pathname[MAX_BUF]; |
1269 | |
1214 | |
… | |
… | |
1277 | if (load_map_header (thawer, m)) |
1222 | if (load_map_header (thawer, m)) |
1278 | { |
1223 | { |
1279 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1224 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1280 | delete_map (m); |
1225 | delete_map (m); |
1281 | m = load_original_map (m->path, 0); |
1226 | m = load_original_map (m->path, 0); |
1282 | return NULL; |
1227 | return 0; |
1283 | } |
1228 | } |
1284 | /*m->allocate ();*/ |
1229 | /*m->allocate ();*/ |
1285 | |
1230 | |
1286 | m->in_memory = MAP_LOADING; |
1231 | m->in_memory = MAP_LOADING; |
1287 | load_objects (m, thawer, MAP_OVERLAY); |
1232 | load_objects (m, thawer, MAP_OVERLAY); |
… | |
… | |
1299 | delete_unique_items (maptile *m) |
1244 | delete_unique_items (maptile *m) |
1300 | { |
1245 | { |
1301 | int i, j, unique; |
1246 | int i, j, unique; |
1302 | object *op, *next; |
1247 | object *op, *next; |
1303 | |
1248 | |
1304 | for (i = 0; i < MAP_WIDTH (m); i++) |
1249 | for (i = 0; i < m->width; i++) |
1305 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1250 | for (j = 0; j < m->height; j++) |
1306 | { |
1251 | { |
1307 | unique = 0; |
1252 | unique = 0; |
|
|
1253 | |
1308 | for (op = get_map_ob (m, i, j); op; op = next) |
1254 | for (op = GET_MAP_OB (m, i, j); op; op = next) |
1309 | { |
1255 | { |
1310 | next = op->above; |
1256 | next = op->above; |
|
|
1257 | |
1311 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1258 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1312 | unique = 1; |
1259 | unique = 1; |
|
|
1260 | |
1313 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1261 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1314 | { |
1262 | { |
1315 | clean_object (op); |
1263 | op->destroy_inv (false); |
1316 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1264 | op->destroy (); |
1317 | remove_button_link (op); |
|
|
1318 | remove_ob (op); |
|
|
1319 | free_object (op); |
|
|
1320 | } |
1265 | } |
1321 | } |
1266 | } |
1322 | } |
1267 | } |
1323 | } |
1268 | } |
1324 | |
1269 | |
1325 | |
|
|
1326 | /* |
1270 | /* |
1327 | * Loads unique objects from file(s) into the map which is in memory |
1271 | * Loads unique objects from file(s) into the map which is in memory |
1328 | * m is the map to load unique items into. |
1272 | * m is the map to load unique items into. |
1329 | */ |
1273 | */ |
1330 | static void |
1274 | static void |
… | |
… | |
1349 | return; |
1293 | return; |
1350 | |
1294 | |
1351 | m->in_memory = MAP_LOADING; |
1295 | m->in_memory = MAP_LOADING; |
1352 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1296 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1353 | delete_unique_items (m); /* original map before, don't duplicate them */ |
1297 | delete_unique_items (m); /* original map before, don't duplicate them */ |
|
|
1298 | |
1354 | load_objects (m, thawer, 0); |
1299 | load_objects (m, thawer, 0); |
1355 | |
1300 | |
1356 | m->in_memory = MAP_IN_MEMORY; |
1301 | m->in_memory = MAP_IN_MEMORY; |
1357 | } |
1302 | } |
1358 | |
|
|
1359 | |
1303 | |
1360 | /* |
1304 | /* |
1361 | * Saves a map to file. If flag is set, it is saved into the same |
1305 | * Saves a map to file. If flag is set, it is saved into the same |
1362 | * file it was (originally) loaded from. Otherwise a temporary |
1306 | * file it was (originally) loaded from. Otherwise a temporary |
1363 | * filename will be genarated, and the file will be stored there. |
1307 | * filename will be genarated, and the file will be stored there. |
1364 | * The temporary filename will be stored in the maptileure. |
1308 | * The temporary filename will be stored in the maptileure. |
1365 | * If the map is unique, we also save to the filename in the map |
1309 | * If the map is unique, we also save to the filename in the map |
1366 | * (this should have been updated when first loaded) |
1310 | * (this should have been updated when first loaded) |
1367 | */ |
1311 | */ |
1368 | |
|
|
1369 | int |
1312 | int |
1370 | new_save_map (maptile *m, int flag) |
1313 | new_save_map (maptile *m, int flag) |
1371 | { |
1314 | { |
1372 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1315 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1373 | int i; |
1316 | int i; |
… | |
… | |
1393 | make_path_to_file (filename); |
1336 | make_path_to_file (filename); |
1394 | } |
1337 | } |
1395 | else |
1338 | else |
1396 | { |
1339 | { |
1397 | if (!m->tmpname) |
1340 | if (!m->tmpname) |
1398 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
1341 | m->tmpname = tempnam (settings.tmpdir, NULL); |
1399 | |
1342 | |
1400 | strcpy (filename, m->tmpname); |
1343 | strcpy (filename, m->tmpname); |
1401 | } |
1344 | } |
1402 | |
1345 | |
1403 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1346 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
… | |
… | |
1427 | print_shop_string (m, shop); |
1370 | print_shop_string (m, shop); |
1428 | fprintf (freezer, "shopitems %s\n", shop); |
1371 | fprintf (freezer, "shopitems %s\n", shop); |
1429 | } |
1372 | } |
1430 | if (m->shopgreed) |
1373 | if (m->shopgreed) |
1431 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1374 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1432 | #ifndef WIN32 |
|
|
1433 | if (m->shopmin) |
1375 | if (m->shopmin) |
1434 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1376 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1435 | if (m->shopmax) |
1377 | if (m->shopmax) |
1436 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1378 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1437 | #else |
|
|
1438 | if (m->shopmin) |
|
|
1439 | fprintf (freezer, "shopmin %I64u\n", m->shopmin); |
|
|
1440 | if (m->shopmax) |
|
|
1441 | fprintf (freezer, "shopmax %I64u\n", m->shopmax); |
|
|
1442 | #endif |
|
|
1443 | if (m->shoprace) |
1379 | if (m->shoprace) |
1444 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1380 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1445 | if (m->darkness) |
1381 | if (m->darkness) |
1446 | fprintf (freezer, "darkness %d\n", m->darkness); |
1382 | fprintf (freezer, "darkness %d\n", m->darkness); |
1447 | if (m->width) |
1383 | if (m->width) |
… | |
… | |
1512 | freezer.save (filename); |
1448 | freezer.save (filename); |
1513 | |
1449 | |
1514 | return 0; |
1450 | return 0; |
1515 | } |
1451 | } |
1516 | |
1452 | |
1517 | |
|
|
1518 | /* |
|
|
1519 | * Remove and free all objects in the inventory of the given object. |
|
|
1520 | * object.c ? |
|
|
1521 | */ |
|
|
1522 | |
|
|
1523 | void |
|
|
1524 | clean_object (object *op) |
|
|
1525 | { |
|
|
1526 | object *tmp, *next; |
|
|
1527 | |
|
|
1528 | for (tmp = op->inv; tmp; tmp = next) |
|
|
1529 | { |
|
|
1530 | next = tmp->below; |
|
|
1531 | clean_object (tmp); |
|
|
1532 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
|
|
1533 | remove_button_link (tmp); |
|
|
1534 | remove_ob (tmp); |
|
|
1535 | free_object (tmp); |
|
|
1536 | } |
|
|
1537 | } |
|
|
1538 | |
|
|
1539 | /* |
1453 | /* |
1540 | * Remove and free all objects in the given map. |
1454 | * Remove and free all objects in the given map. |
1541 | */ |
1455 | */ |
1542 | |
|
|
1543 | void |
1456 | void |
1544 | free_all_objects (maptile *m) |
1457 | free_all_objects (maptile *m) |
1545 | { |
1458 | { |
1546 | int i, j; |
1459 | if (!m->spaces) |
1547 | object *op; |
1460 | return; |
1548 | |
1461 | |
1549 | for (i = 0; i < MAP_WIDTH (m); i++) |
1462 | for (int i = 0; i < m->width; i++) |
1550 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1463 | for (int j = 0; j < m->height; j++) |
1551 | { |
1464 | { |
1552 | object *previous_obj = NULL; |
1465 | mapspace &ms = m->at (i, j); |
1553 | |
1466 | |
1554 | while ((op = GET_MAP_OB (m, i, j)) != NULL) |
1467 | while (object *op = ms.bot) |
1555 | { |
1468 | { |
1556 | if (op == previous_obj) |
|
|
1557 | { |
|
|
1558 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
|
|
1559 | break; |
|
|
1560 | } |
|
|
1561 | previous_obj = op; |
|
|
1562 | if (op->head != NULL) |
1469 | if (op->head) |
1563 | op = op->head; |
1470 | op = op->head; |
1564 | |
1471 | |
1565 | /* If the map isn't in memory, free_object will remove and |
1472 | op->destroy_inv (false); |
1566 | * free objects in op's inventory. So let it do the job. |
1473 | op->destroy (); |
1567 | */ |
|
|
1568 | if (m->in_memory == MAP_IN_MEMORY) |
|
|
1569 | clean_object (op); |
|
|
1570 | remove_ob (op); |
|
|
1571 | free_object (op); |
|
|
1572 | } |
1474 | } |
1573 | } |
1475 | } |
1574 | } |
1476 | } |
1575 | |
1477 | |
1576 | /* |
1478 | /* |
1577 | * Frees everything allocated by the given maptileure. |
1479 | * Frees everything allocated by the given maptileure. |
1578 | * don't free tmpname - our caller is left to do that |
1480 | * don't free tmpname - our caller is left to do that |
1579 | */ |
1481 | */ |
1580 | |
|
|
1581 | void |
1482 | void |
1582 | free_map (maptile *m, int flag) |
1483 | free_map (maptile *m, int flag) |
1583 | { |
1484 | { |
1584 | int i; |
1485 | if (!m->in_memory) //TODO: makes no sense to me? |
1585 | |
|
|
1586 | if (!m->in_memory) |
|
|
1587 | { |
|
|
1588 | LOG (llevError, "Trying to free freed map.\n"); |
|
|
1589 | return; |
1486 | return; |
1590 | } |
1487 | |
|
|
1488 | m->in_memory = MAP_SAVING; |
|
|
1489 | |
|
|
1490 | // TODO: use new/delete |
|
|
1491 | |
1591 | if (flag && m->spaces) |
1492 | if (flag && m->spaces) |
1592 | free_all_objects (m); |
1493 | free_all_objects (m); |
1593 | if (m->name) |
1494 | |
1594 | FREE_AND_CLEAR (m->name); |
1495 | sfree (m->spaces, m->size ()), m->spaces = 0; |
1595 | if (m->spaces) |
1496 | |
1596 | FREE_AND_CLEAR (m->spaces); |
1497 | free (m->name), m->name = 0; |
1597 | if (m->msg) |
1498 | free (m->msg), m->msg = 0; |
1598 | FREE_AND_CLEAR (m->msg); |
1499 | free (m->maplore), m->maplore = 0; |
1599 | if (m->maplore) |
1500 | free (m->shoprace), m->shoprace = 0; |
1600 | FREE_AND_CLEAR (m->maplore); |
1501 | delete [] m->shopitems, m->shopitems = 0; |
1601 | if (m->shopitems) |
1502 | |
1602 | delete[]m->shopitems; |
|
|
1603 | m->shopitems = 0; |
|
|
1604 | if (m->shoprace) |
|
|
1605 | FREE_AND_CLEAR (m->shoprace); |
|
|
1606 | if (m->buttons) |
1503 | if (m->buttons) |
1607 | free_objectlinkpt (m->buttons); |
1504 | free_objectlinkpt (m->buttons), m->buttons = 0; |
1608 | m->buttons = NULL; |
1505 | |
1609 | for (i = 0; i < 4; i++) |
1506 | for (int i = 0; i < 4; i++) |
1610 | { |
1507 | free (m->tile_path[i]), m->tile_path[i] = 0; |
1611 | if (m->tile_path[i]) |
1508 | |
1612 | FREE_AND_CLEAR (m->tile_path[i]); |
|
|
1613 | m->tile_map[i] = NULL; |
|
|
1614 | } |
|
|
1615 | m->in_memory = MAP_SWAPPED; |
1509 | m->in_memory = MAP_SWAPPED; |
1616 | } |
1510 | } |
1617 | |
1511 | |
1618 | /* |
1512 | maptile::~maptile () |
1619 | * function: vanish maptile |
1513 | { |
1620 | * m : pointer to maptile, if NULL no action |
1514 | assert (destroyed ()); |
1621 | * this deletes all the data on the map (freeing pointers) |
1515 | } |
1622 | * and then removes this map from the global linked list of maps. |
1516 | |
|
|
1517 | void |
|
|
1518 | maptile::do_destroy () |
|
|
1519 | { |
|
|
1520 | attachable::do_destroy (); |
|
|
1521 | |
|
|
1522 | unlink (); |
|
|
1523 | |
|
|
1524 | free_map (this, 1); |
|
|
1525 | free (tmpname), tmpname = 0; |
|
|
1526 | |
|
|
1527 | /* We need to look through all the maps and see if any maps |
|
|
1528 | * are pointing at this one for tiling information. Since |
|
|
1529 | * tiling can be asymetric, we just can not look to see which |
|
|
1530 | * maps this map tiles with and clears those. |
1623 | */ |
1531 | */ |
|
|
1532 | //TODO: non-euclidean-tiling MUST GO |
|
|
1533 | for_all_maps (m) |
|
|
1534 | for (int i = 0; i < 4; i++) |
|
|
1535 | if (m->tile_map[i] == this) |
|
|
1536 | m->tile_map[i] = 0; |
|
|
1537 | } |
1624 | |
1538 | |
|
|
1539 | //TODO: must go |
1625 | void |
1540 | void |
1626 | delete_map (maptile *m) |
1541 | delete_map (maptile *m) |
1627 | { |
1542 | { |
1628 | maptile *tmp, *last; |
|
|
1629 | int i; |
|
|
1630 | |
|
|
1631 | if (!m) |
1543 | if (m) |
1632 | return; |
1544 | m->destroy (); |
1633 | |
|
|
1634 | m->clear (); |
|
|
1635 | |
|
|
1636 | if (m->in_memory == MAP_IN_MEMORY) |
|
|
1637 | { |
|
|
1638 | /* change to MAP_SAVING, even though we are not, |
|
|
1639 | * so that remove_ob doesn't do as much work. |
|
|
1640 | */ |
|
|
1641 | m->in_memory = MAP_SAVING; |
|
|
1642 | free_map (m, 1); |
|
|
1643 | } |
|
|
1644 | /* move this out of free_map, since tmpname can still be needed if |
|
|
1645 | * the map is swapped out. |
|
|
1646 | */ |
|
|
1647 | if (m->tmpname) |
|
|
1648 | { |
|
|
1649 | free (m->tmpname); |
|
|
1650 | m->tmpname = NULL; |
|
|
1651 | } |
|
|
1652 | last = NULL; |
|
|
1653 | /* We need to look through all the maps and see if any maps |
|
|
1654 | * are pointing at this one for tiling information. Since |
|
|
1655 | * tiling can be assymetric, we just can not look to see which |
|
|
1656 | * maps this map tiles with and clears those. |
|
|
1657 | */ |
|
|
1658 | for (tmp = first_map; tmp != NULL; tmp = tmp->next) |
|
|
1659 | { |
|
|
1660 | if (tmp->next == m) |
|
|
1661 | last = tmp; |
|
|
1662 | |
|
|
1663 | /* This should hopefully get unrolled on a decent compiler */ |
|
|
1664 | for (i = 0; i < 4; i++) |
|
|
1665 | if (tmp->tile_map[i] == m) |
|
|
1666 | tmp->tile_map[i] = NULL; |
|
|
1667 | } |
|
|
1668 | |
|
|
1669 | /* If last is null, then this should be the first map in the list */ |
|
|
1670 | if (!last) |
|
|
1671 | { |
|
|
1672 | if (m == first_map) |
|
|
1673 | first_map = m->next; |
|
|
1674 | else |
|
|
1675 | /* m->path is a static char, so should hopefully still have |
|
|
1676 | * some useful data in it. |
|
|
1677 | */ |
|
|
1678 | LOG (llevError, "delete_map: Unable to find map %s in list\n", m->path); |
|
|
1679 | } |
|
|
1680 | else |
|
|
1681 | last->next = m->next; |
|
|
1682 | |
|
|
1683 | delete m; |
|
|
1684 | } |
1545 | } |
1685 | |
|
|
1686 | |
|
|
1687 | |
1546 | |
1688 | /* |
1547 | /* |
1689 | * Makes sure the given map is loaded and swapped in. |
1548 | * Makes sure the given map is loaded and swapped in. |
1690 | * name is path name of the map. |
1549 | * name is path name of the map. |
1691 | * flags meaning: |
1550 | * flags meaning: |
… | |
… | |
1694 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1553 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1695 | * dont do any more name translation on it. |
1554 | * dont do any more name translation on it. |
1696 | * |
1555 | * |
1697 | * Returns a pointer to the given map. |
1556 | * Returns a pointer to the given map. |
1698 | */ |
1557 | */ |
1699 | |
|
|
1700 | maptile * |
1558 | maptile * |
1701 | ready_map_name (const char *name, int flags) |
1559 | ready_map_name (const char *name, int flags) |
1702 | { |
1560 | { |
1703 | maptile *m; |
|
|
1704 | |
|
|
1705 | if (!name) |
1561 | if (!name) |
1706 | return (NULL); |
1562 | return 0; |
1707 | |
1563 | |
1708 | /* Have we been at this level before? */ |
1564 | /* Have we been at this level before? */ |
1709 | m = has_been_loaded (name); |
1565 | maptile *m = has_been_loaded (name); |
1710 | |
1566 | |
1711 | /* Map is good to go, so just return it */ |
1567 | /* Map is good to go, so just return it */ |
1712 | if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) |
1568 | if (m && (m->in_memory == MAP_LOADING || m->in_memory == MAP_IN_MEMORY)) |
1713 | { |
|
|
1714 | return m; |
1569 | return m; |
1715 | } |
|
|
1716 | |
1570 | |
1717 | /* unique maps always get loaded from their original location, and never |
1571 | /* unique maps always get loaded from their original location, and never |
1718 | * a temp location. Likewise, if map_flush is set, or we have never loaded |
1572 | * a temp location. Likewise, if map_flush is set, or we have never loaded |
1719 | * this map, load it now. I removed the reset checking from here - |
1573 | * this map, load it now. I removed the reset checking from here - |
1720 | * it seems the probability of a player trying to enter a map that should |
1574 | * it seems the probability of a player trying to enter a map that should |
… | |
… | |
1722 | * a bit cleaner (and players probably shouldn't rely on exact timing for |
1576 | * a bit cleaner (and players probably shouldn't rely on exact timing for |
1723 | * resets in any case - if they really care, they should use the 'maps command. |
1577 | * resets in any case - if they really care, they should use the 'maps command. |
1724 | */ |
1578 | */ |
1725 | if ((flags & (MAP_FLUSH | MAP_PLAYER_UNIQUE)) || !m) |
1579 | if ((flags & (MAP_FLUSH | MAP_PLAYER_UNIQUE)) || !m) |
1726 | { |
1580 | { |
1727 | |
|
|
1728 | /* first visit or time to reset */ |
1581 | /* first visit or time to reset */ |
1729 | if (m) |
1582 | if (m) |
1730 | { |
1583 | { |
1731 | clean_tmp_map (m); /* Doesn't make much difference */ |
1584 | clean_tmp_map (m); /* Doesn't make much difference */ |
1732 | delete_map (m); |
1585 | delete_map (m); |
… | |
… | |
1736 | if (flags & MAP_PLAYER_UNIQUE) |
1589 | if (flags & MAP_PLAYER_UNIQUE) |
1737 | LOG (llevDebug, "Trying to load map %s.\n", name); |
1590 | LOG (llevDebug, "Trying to load map %s.\n", name); |
1738 | else |
1591 | else |
1739 | LOG (llevDebug, "Trying to load map %s.\n", create_pathname (name)); |
1592 | LOG (llevDebug, "Trying to load map %s.\n", create_pathname (name)); |
1740 | |
1593 | |
1741 | //eval_pv ("$x = Event::time", 1);//D |
|
|
1742 | if (!(m = load_original_map (name, (flags & MAP_PLAYER_UNIQUE)))) |
1594 | if (!(m = load_original_map (name, (flags & MAP_PLAYER_UNIQUE)))) |
1743 | return (NULL); |
1595 | return (NULL); |
1744 | //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D |
|
|
1745 | |
1596 | |
1746 | fix_auto_apply (m); /* Chests which open as default */ |
1597 | fix_auto_apply (m); /* Chests which open as default */ |
1747 | |
1598 | |
1748 | /* If a player unique map, no extra unique object file to load. |
1599 | /* If a player unique map, no extra unique object file to load. |
1749 | * if from the editor, likewise. |
1600 | * if from the editor, likewise. |
… | |
… | |
1819 | int x, y, i; |
1670 | int x, y, i; |
1820 | long monster_cnt = 0; |
1671 | long monster_cnt = 0; |
1821 | double avgexp = 0; |
1672 | double avgexp = 0; |
1822 | sint64 total_exp = 0; |
1673 | sint64 total_exp = 0; |
1823 | |
1674 | |
1824 | if (MAP_DIFFICULTY (m)) |
1675 | if (m->difficulty) |
1825 | { |
1676 | { |
1826 | LOG (llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY (m)); |
1677 | LOG (llevDebug, "Using stored map difficulty: %d\n", m->difficulty); |
1827 | return MAP_DIFFICULTY (m); |
1678 | return m->difficulty; |
1828 | } |
1679 | } |
1829 | |
1680 | |
1830 | for (x = 0; x < MAP_WIDTH (m); x++) |
1681 | for (x = 0; x < m->width; x++) |
1831 | for (y = 0; y < MAP_HEIGHT (m); y++) |
1682 | for (y = 0; y < m->height; y++) |
1832 | for (op = get_map_ob (m, x, y); op != NULL; op = op->above) |
1683 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
1833 | { |
1684 | { |
1834 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1685 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1835 | { |
1686 | { |
1836 | total_exp += op->stats.exp; |
1687 | total_exp += op->stats.exp; |
1837 | monster_cnt++; |
1688 | monster_cnt++; |
… | |
… | |
1885 | if (first_map->in_memory == MAP_SAVING) |
1736 | if (first_map->in_memory == MAP_SAVING) |
1886 | first_map->in_memory = MAP_IN_MEMORY; |
1737 | first_map->in_memory = MAP_IN_MEMORY; |
1887 | delete_map (first_map); |
1738 | delete_map (first_map); |
1888 | real_maps++; |
1739 | real_maps++; |
1889 | } |
1740 | } |
|
|
1741 | |
1890 | LOG (llevDebug, "free_all_maps: Freed %d maps\n", real_maps); |
1742 | LOG (llevDebug, "free_all_maps: Freed %d maps\n", real_maps); |
1891 | } |
1743 | } |
1892 | |
1744 | |
1893 | /* change_map_light() - used to change map light level (darkness) |
1745 | /* change_map_light() - used to change map light level (darkness) |
1894 | * up or down. Returns true if successful. It should now be |
1746 | * up or down. Returns true if successful. It should now be |
… | |
… | |
1930 | /* All clients need to get re-updated for the change */ |
1782 | /* All clients need to get re-updated for the change */ |
1931 | update_all_map_los (m); |
1783 | update_all_map_los (m); |
1932 | return 1; |
1784 | return 1; |
1933 | } |
1785 | } |
1934 | |
1786 | |
1935 | |
|
|
1936 | /* |
1787 | /* |
1937 | * This function updates various attributes about a specific space |
1788 | * This function updates various attributes about a specific space |
1938 | * on the map (what it looks like, whether it blocks magic, |
1789 | * on the map (what it looks like, whether it blocks magic, |
1939 | * has a living creatures, prevents people from passing |
1790 | * has a living creatures, prevents people from passing |
1940 | * through, etc) |
1791 | * through, etc) |
1941 | */ |
1792 | */ |
1942 | void |
1793 | void |
1943 | update_position (maptile *m, int x, int y) |
1794 | mapspace::update_ () |
1944 | { |
1795 | { |
1945 | object *tmp, *last = NULL; |
1796 | object *tmp, *last = 0; |
1946 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1797 | uint8 flags = 0, light = 0, anywhere = 0; |
1947 | New_Face *top, *floor, *middle; |
1798 | New_Face *top, *floor, *middle; |
1948 | object *top_obj, *floor_obj, *middle_obj; |
1799 | object *top_obj, *floor_obj, *middle_obj; |
1949 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1800 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1950 | |
1801 | |
1951 | oldflags = GET_MAP_FLAGS (m, x, y); |
|
|
1952 | if (!(oldflags & P_NEED_UPDATE)) |
|
|
1953 | { |
|
|
1954 | LOG (llevDebug, "update_position called with P_NEED_UPDATE not set: %s (%d, %d)\n", m->path, x, y); |
|
|
1955 | return; |
|
|
1956 | } |
|
|
1957 | |
|
|
1958 | middle = blank_face; |
1802 | middle = blank_face; |
1959 | top = blank_face; |
1803 | top = blank_face; |
1960 | floor = blank_face; |
1804 | floor = blank_face; |
1961 | |
1805 | |
1962 | middle_obj = NULL; |
1806 | middle_obj = 0; |
1963 | top_obj = NULL; |
1807 | top_obj = 0; |
1964 | floor_obj = NULL; |
1808 | floor_obj = 0; |
1965 | |
1809 | |
1966 | for (tmp = get_map_ob (m, x, y); tmp; last = tmp, tmp = tmp->above) |
1810 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1967 | { |
1811 | { |
1968 | |
|
|
1969 | /* This could be made additive I guess (two lights better than |
1812 | /* This could be made additive I guess (two lights better than |
1970 | * one). But if so, it shouldn't be a simple additive - 2 |
1813 | * one). But if so, it shouldn't be a simple additive - 2 |
1971 | * light bulbs do not illuminate twice as far as once since |
1814 | * light bulbs do not illuminate twice as far as once since |
1972 | * it is a disapation factor that is squared (or is it cubed?) |
1815 | * it is a dissapation factor that is cubed. |
1973 | */ |
1816 | */ |
1974 | if (tmp->glow_radius > light) |
1817 | if (tmp->glow_radius > light) |
1975 | light = tmp->glow_radius; |
1818 | light = tmp->glow_radius; |
1976 | |
1819 | |
1977 | /* This call is needed in order to update objects the player |
1820 | /* This call is needed in order to update objects the player |
… | |
… | |
2015 | { |
1858 | { |
2016 | middle = tmp->face; |
1859 | middle = tmp->face; |
2017 | middle_obj = tmp; |
1860 | middle_obj = tmp; |
2018 | } |
1861 | } |
2019 | } |
1862 | } |
|
|
1863 | |
2020 | if (tmp == tmp->above) |
1864 | if (tmp == tmp->above) |
2021 | { |
1865 | { |
2022 | LOG (llevError, "Error in structure of map\n"); |
1866 | LOG (llevError, "Error in structure of map\n"); |
2023 | exit (-1); |
1867 | exit (-1); |
2024 | } |
1868 | } |
2025 | |
1869 | |
2026 | move_slow |= tmp->move_slow; |
1870 | move_slow |= tmp->move_slow; |
2027 | move_block |= tmp->move_block; |
1871 | move_block |= tmp->move_block; |
2028 | move_on |= tmp->move_on; |
1872 | move_on |= tmp->move_on; |
2029 | move_off |= tmp->move_off; |
1873 | move_off |= tmp->move_off; |
2030 | move_allow |= tmp->move_allow; |
1874 | move_allow |= tmp->move_allow; |
2031 | |
1875 | |
2032 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
|
|
2033 | flags |= P_IS_ALIVE; |
|
|
2034 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) |
|
|
2035 | flags |= P_NO_MAGIC; |
|
|
2036 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) |
|
|
2037 | flags |= P_NO_CLERIC; |
|
|
2038 | if (tmp->type == SAFE_GROUND) |
|
|
2039 | flags |= P_SAFE; |
|
|
2040 | |
|
|
2041 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) |
1876 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW; |
2042 | flags |= P_BLOCKSVIEW; |
1877 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC; |
2043 | } /* for stack of objects */ |
1878 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
2044 | |
1879 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
2045 | /* we don't want to rely on this function to have accurate flags, but |
1880 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
2046 | * since we're already doing the work, we calculate them here. |
1881 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
2047 | * if they don't match, logic is broken someplace. |
|
|
2048 | */ |
|
|
2049 | if (((oldflags & ~(P_NEED_UPDATE | P_NO_ERROR)) != flags) && (!(oldflags & P_NO_ERROR))) |
|
|
2050 | { |
1882 | } |
2051 | LOG (llevDebug, "update_position: updated flags do not match old flags: %s (old=%d,new=%d) %x != %x\n", |
1883 | |
2052 | m->path, x, y, (oldflags & ~P_NEED_UPDATE), flags); |
1884 | this->light = light; |
2053 | } |
1885 | this->flags_ = flags; |
2054 | SET_MAP_FLAGS (m, x, y, flags); |
1886 | this->move_block = move_block & ~move_allow; |
2055 | SET_MAP_MOVE_BLOCK (m, x, y, move_block & ~move_allow); |
1887 | this->move_on = move_on; |
2056 | SET_MAP_MOVE_ON (m, x, y, move_on); |
1888 | this->move_off = move_off; |
2057 | SET_MAP_MOVE_OFF (m, x, y, move_off); |
1889 | this->move_slow = move_slow; |
2058 | SET_MAP_MOVE_SLOW (m, x, y, move_slow); |
|
|
2059 | |
1890 | |
2060 | /* At this point, we have a floor face (if there is a floor), |
1891 | /* At this point, we have a floor face (if there is a floor), |
2061 | * and the floor is set - we are not going to touch it at |
1892 | * and the floor is set - we are not going to touch it at |
2062 | * this point. |
1893 | * this point. |
2063 | * middle contains the highest visibility face. |
1894 | * middle contains the highest visibility face. |
… | |
… | |
2117 | break; |
1948 | break; |
2118 | } |
1949 | } |
2119 | } |
1950 | } |
2120 | } |
1951 | } |
2121 | } |
1952 | } |
|
|
1953 | |
2122 | if (middle == floor) |
1954 | if (middle == floor) |
2123 | middle = blank_face; |
1955 | middle = blank_face; |
|
|
1956 | |
2124 | if (top == middle) |
1957 | if (top == middle) |
2125 | middle = blank_face; |
1958 | middle = blank_face; |
2126 | SET_MAP_FACE (m, x, y, top, 0); |
|
|
2127 | if (top != blank_face) |
|
|
2128 | SET_MAP_FACE_OBJ (m, x, y, top_obj, 0); |
|
|
2129 | else |
|
|
2130 | SET_MAP_FACE_OBJ (m, x, y, NULL, 0); |
|
|
2131 | SET_MAP_FACE (m, x, y, middle, 1); |
|
|
2132 | if (middle != blank_face) |
|
|
2133 | SET_MAP_FACE_OBJ (m, x, y, middle_obj, 1); |
|
|
2134 | else |
|
|
2135 | SET_MAP_FACE_OBJ (m, x, y, NULL, 1); |
|
|
2136 | SET_MAP_FACE (m, x, y, floor, 2); |
|
|
2137 | if (floor != blank_face) |
|
|
2138 | SET_MAP_FACE_OBJ (m, x, y, floor_obj, 2); |
|
|
2139 | else |
|
|
2140 | SET_MAP_FACE_OBJ (m, x, y, NULL, 2); |
|
|
2141 | SET_MAP_LIGHT (m, x, y, light); |
|
|
2142 | } |
|
|
2143 | |
1959 | |
|
|
1960 | faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; |
|
|
1961 | faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; |
|
|
1962 | faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; |
|
|
1963 | } |
2144 | |
1964 | |
2145 | void |
1965 | void |
2146 | set_map_reset_time (maptile *map) |
1966 | set_map_reset_time (maptile *map) |
2147 | { |
1967 | { |
2148 | int timeout; |
1968 | int timeout = map->reset_timeout; |
2149 | |
1969 | |
2150 | timeout = MAP_RESET_TIMEOUT (map); |
|
|
2151 | if (timeout <= 0) |
1970 | if (timeout <= 0) |
2152 | timeout = MAP_DEFAULTRESET; |
1971 | timeout = MAP_DEFAULTRESET; |
2153 | if (timeout >= MAP_MAXRESET) |
1972 | if (timeout >= MAP_MAXRESET) |
2154 | timeout = MAP_MAXRESET; |
1973 | timeout = MAP_MAXRESET; |
2155 | MAP_WHEN_RESET (map) = seconds () + timeout; |
1974 | |
|
|
1975 | map->reset_time = time (0) + timeout; |
2156 | } |
1976 | } |
2157 | |
1977 | |
2158 | /* this updates the orig_map->tile_map[tile_num] value after loading |
1978 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2159 | * the map. It also takes care of linking back the freshly loaded |
1979 | * the map. It also takes care of linking back the freshly loaded |
2160 | * maps tile_map values if it tiles back to this one. It returns |
1980 | * maps tile_map values if it tiles back to this one. It returns |
… | |
… | |
2188 | * |
2008 | * |
2189 | */ |
2009 | */ |
2190 | int |
2010 | int |
2191 | out_of_map (maptile *m, int x, int y) |
2011 | out_of_map (maptile *m, int x, int y) |
2192 | { |
2012 | { |
2193 | |
|
|
2194 | /* If we get passed a null map, this is obviously the |
2013 | /* If we get passed a null map, this is obviously the |
2195 | * case. This generally shouldn't happen, but if the |
2014 | * case. This generally shouldn't happen, but if the |
2196 | * map loads fail below, it could happen. |
2015 | * map loads fail below, it could happen. |
2197 | */ |
2016 | */ |
2198 | if (!m) |
2017 | if (!m) |
… | |
… | |
2200 | |
2019 | |
2201 | if (x < 0) |
2020 | if (x < 0) |
2202 | { |
2021 | { |
2203 | if (!m->tile_path[3]) |
2022 | if (!m->tile_path[3]) |
2204 | return 1; |
2023 | return 1; |
|
|
2024 | |
2205 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2025 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2206 | { |
|
|
2207 | load_and_link_tiled_map (m, 3); |
2026 | load_and_link_tiled_map (m, 3); |
2208 | } |
2027 | |
2209 | return (out_of_map (m->tile_map[3], x + MAP_WIDTH (m->tile_map[3]), y)); |
2028 | return (out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y)); |
2210 | } |
2029 | } |
2211 | if (x >= MAP_WIDTH (m)) |
2030 | |
|
|
2031 | if (x >= m->width) |
2212 | { |
2032 | { |
2213 | if (!m->tile_path[1]) |
2033 | if (!m->tile_path[1]) |
2214 | return 1; |
2034 | return 1; |
|
|
2035 | |
2215 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2036 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2216 | { |
|
|
2217 | load_and_link_tiled_map (m, 1); |
2037 | load_and_link_tiled_map (m, 1); |
2218 | } |
2038 | |
2219 | return (out_of_map (m->tile_map[1], x - MAP_WIDTH (m), y)); |
2039 | return (out_of_map (m->tile_map[1], x - m->width, y)); |
2220 | } |
2040 | } |
|
|
2041 | |
2221 | if (y < 0) |
2042 | if (y < 0) |
2222 | { |
2043 | { |
2223 | if (!m->tile_path[0]) |
2044 | if (!m->tile_path[0]) |
2224 | return 1; |
2045 | return 1; |
|
|
2046 | |
2225 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2047 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2226 | { |
|
|
2227 | load_and_link_tiled_map (m, 0); |
2048 | load_and_link_tiled_map (m, 0); |
2228 | } |
2049 | |
2229 | return (out_of_map (m->tile_map[0], x, y + MAP_HEIGHT (m->tile_map[0]))); |
2050 | return (out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height)); |
2230 | } |
2051 | } |
2231 | if (y >= MAP_HEIGHT (m)) |
2052 | |
|
|
2053 | if (y >= m->height) |
2232 | { |
2054 | { |
2233 | if (!m->tile_path[2]) |
2055 | if (!m->tile_path[2]) |
2234 | return 1; |
2056 | return 1; |
|
|
2057 | |
2235 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2058 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2236 | { |
|
|
2237 | load_and_link_tiled_map (m, 2); |
2059 | load_and_link_tiled_map (m, 2); |
2238 | } |
2060 | |
2239 | return (out_of_map (m->tile_map[2], x, y - MAP_HEIGHT (m))); |
2061 | return (out_of_map (m->tile_map[2], x, y - m->height)); |
2240 | } |
2062 | } |
2241 | |
2063 | |
2242 | /* Simple case - coordinates are within this local |
2064 | /* Simple case - coordinates are within this local |
2243 | * map. |
2065 | * map. |
2244 | */ |
2066 | */ |
… | |
… | |
2258 | { |
2080 | { |
2259 | |
2081 | |
2260 | if (*x < 0) |
2082 | if (*x < 0) |
2261 | { |
2083 | { |
2262 | if (!m->tile_path[3]) |
2084 | if (!m->tile_path[3]) |
2263 | return NULL; |
2085 | return 0; |
2264 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2086 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2265 | load_and_link_tiled_map (m, 3); |
2087 | load_and_link_tiled_map (m, 3); |
2266 | |
2088 | |
2267 | *x += MAP_WIDTH (m->tile_map[3]); |
2089 | *x += m->tile_map[3]->width; |
2268 | return (get_map_from_coord (m->tile_map[3], x, y)); |
2090 | return (get_map_from_coord (m->tile_map[3], x, y)); |
2269 | } |
2091 | } |
2270 | if (*x >= MAP_WIDTH (m)) |
2092 | |
|
|
2093 | if (*x >= m->width) |
2271 | { |
2094 | { |
2272 | if (!m->tile_path[1]) |
2095 | if (!m->tile_path[1]) |
2273 | return NULL; |
2096 | return 0; |
|
|
2097 | |
2274 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2098 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2275 | load_and_link_tiled_map (m, 1); |
2099 | load_and_link_tiled_map (m, 1); |
2276 | |
2100 | |
2277 | *x -= MAP_WIDTH (m); |
2101 | *x -= m->width; |
2278 | return (get_map_from_coord (m->tile_map[1], x, y)); |
2102 | return (get_map_from_coord (m->tile_map[1], x, y)); |
2279 | } |
2103 | } |
|
|
2104 | |
2280 | if (*y < 0) |
2105 | if (*y < 0) |
2281 | { |
2106 | { |
2282 | if (!m->tile_path[0]) |
2107 | if (!m->tile_path[0]) |
2283 | return NULL; |
2108 | return 0; |
|
|
2109 | |
2284 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2110 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2285 | load_and_link_tiled_map (m, 0); |
2111 | load_and_link_tiled_map (m, 0); |
2286 | |
2112 | |
2287 | *y += MAP_HEIGHT (m->tile_map[0]); |
2113 | *y += m->tile_map[0]->height; |
2288 | return (get_map_from_coord (m->tile_map[0], x, y)); |
2114 | return (get_map_from_coord (m->tile_map[0], x, y)); |
2289 | } |
2115 | } |
2290 | if (*y >= MAP_HEIGHT (m)) |
2116 | |
|
|
2117 | if (*y >= m->height) |
2291 | { |
2118 | { |
2292 | if (!m->tile_path[2]) |
2119 | if (!m->tile_path[2]) |
2293 | return NULL; |
2120 | return 0; |
|
|
2121 | |
2294 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2122 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2295 | load_and_link_tiled_map (m, 2); |
2123 | load_and_link_tiled_map (m, 2); |
2296 | |
2124 | |
2297 | *y -= MAP_HEIGHT (m); |
2125 | *y -= m->height; |
2298 | return (get_map_from_coord (m->tile_map[2], x, y)); |
2126 | return (get_map_from_coord (m->tile_map[2], x, y)); |
2299 | } |
2127 | } |
2300 | |
2128 | |
2301 | /* Simple case - coordinates are within this local |
2129 | /* Simple case - coordinates are within this local |
2302 | * map. |
2130 | * map. |
… | |
… | |
2322 | |
2150 | |
2323 | } |
2151 | } |
2324 | else if (map1->tile_map[0] == map2) |
2152 | else if (map1->tile_map[0] == map2) |
2325 | { /* up */ |
2153 | { /* up */ |
2326 | *dx = 0; |
2154 | *dx = 0; |
2327 | *dy = -MAP_HEIGHT (map2); |
2155 | *dy = -map2->height; |
2328 | } |
2156 | } |
2329 | else if (map1->tile_map[1] == map2) |
2157 | else if (map1->tile_map[1] == map2) |
2330 | { /* right */ |
2158 | { /* right */ |
2331 | *dx = MAP_WIDTH (map1); |
2159 | *dx = map1->width; |
2332 | *dy = 0; |
2160 | *dy = 0; |
2333 | } |
2161 | } |
2334 | else if (map1->tile_map[2] == map2) |
2162 | else if (map1->tile_map[2] == map2) |
2335 | { /* down */ |
2163 | { /* down */ |
2336 | *dx = 0; |
2164 | *dx = 0; |
2337 | *dy = MAP_HEIGHT (map1); |
2165 | *dy = map1->height; |
2338 | } |
2166 | } |
2339 | else if (map1->tile_map[3] == map2) |
2167 | else if (map1->tile_map[3] == map2) |
2340 | { /* left */ |
2168 | { /* left */ |
2341 | *dx = -MAP_WIDTH (map2); |
2169 | *dx = -map2->width; |
2342 | *dy = 0; |
2170 | *dy = 0; |
2343 | |
2171 | |
2344 | } |
2172 | } |
2345 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) |
2173 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) |
2346 | { /* up right */ |
2174 | { /* up right */ |
2347 | *dx = MAP_WIDTH (map1->tile_map[0]); |
2175 | *dx = map1->tile_map[0]->width; |
2348 | *dy = -MAP_HEIGHT (map1->tile_map[0]); |
2176 | *dy = -map1->tile_map[0]->height; |
2349 | } |
2177 | } |
2350 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) |
2178 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) |
2351 | { /* up left */ |
2179 | { /* up left */ |
2352 | *dx = -MAP_WIDTH (map2); |
2180 | *dx = -map2->width; |
2353 | *dy = -MAP_HEIGHT (map1->tile_map[0]); |
2181 | *dy = -map1->tile_map[0]->height; |
2354 | } |
2182 | } |
2355 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) |
2183 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) |
2356 | { /* right up */ |
2184 | { /* right up */ |
2357 | *dx = MAP_WIDTH (map1); |
2185 | *dx = map1->width; |
2358 | *dy = -MAP_HEIGHT (map2); |
2186 | *dy = -map2->height; |
2359 | } |
2187 | } |
2360 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) |
2188 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) |
2361 | { /* right down */ |
2189 | { /* right down */ |
2362 | *dx = MAP_WIDTH (map1); |
2190 | *dx = map1->width; |
2363 | *dy = MAP_HEIGHT (map1->tile_map[1]); |
2191 | *dy = map1->tile_map[1]->height; |
2364 | } |
2192 | } |
2365 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) |
2193 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) |
2366 | { /* down right */ |
2194 | { /* down right */ |
2367 | *dx = MAP_WIDTH (map1->tile_map[2]); |
2195 | *dx = map1->tile_map[2]->width; |
2368 | *dy = MAP_HEIGHT (map1); |
2196 | *dy = map1->height; |
2369 | } |
2197 | } |
2370 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) |
2198 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) |
2371 | { /* down left */ |
2199 | { /* down left */ |
2372 | *dx = -MAP_WIDTH (map2); |
2200 | *dx = -map2->width; |
2373 | *dy = MAP_HEIGHT (map1); |
2201 | *dy = map1->height; |
2374 | } |
2202 | } |
2375 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) |
2203 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) |
2376 | { /* left up */ |
2204 | { /* left up */ |
2377 | *dx = -MAP_WIDTH (map1->tile_map[3]); |
2205 | *dx = -map1->tile_map[3]->width; |
2378 | *dy = -MAP_HEIGHT (map2); |
2206 | *dy = -map2->height; |
2379 | } |
2207 | } |
2380 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) |
2208 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) |
2381 | { /* left down */ |
2209 | { /* left down */ |
2382 | *dx = -MAP_WIDTH (map1->tile_map[3]); |
2210 | *dx = -map1->tile_map[3]->width; |
2383 | *dy = MAP_HEIGHT (map1->tile_map[3]); |
2211 | *dy = map1->tile_map[3]->height; |
2384 | |
2212 | |
2385 | } |
2213 | } |
2386 | else |
2214 | else |
2387 | { /* not "adjacent" enough */ |
2215 | { /* not "adjacent" enough */ |
2388 | return 0; |
2216 | return 0; |
… | |
… | |
2513 | { |
2341 | { |
2514 | int dx, dy; |
2342 | int dx, dy; |
2515 | |
2343 | |
2516 | return adjacent_map (op1->map, op2->map, &dx, &dy); |
2344 | return adjacent_map (op1->map, op2->map, &dx, &dy); |
2517 | } |
2345 | } |
|
|
2346 | |
|
|
2347 | object * |
|
|
2348 | maptile::insert (object *op, int x, int y, object *originator, int flags) |
|
|
2349 | { |
|
|
2350 | if (!op->flag [FLAG_REMOVED]) |
|
|
2351 | op->remove (); |
|
|
2352 | |
|
|
2353 | return insert_ob_in_map_at (op, this, originator, flags, x, y); |
|
|
2354 | } |
|
|
2355 | |