… | |
… | |
35 | * return NULL if no match is found. |
35 | * return NULL if no match is found. |
36 | */ |
36 | */ |
37 | maptile * |
37 | maptile * |
38 | has_been_loaded (const char *name) |
38 | has_been_loaded (const char *name) |
39 | { |
39 | { |
40 | maptile *map; |
|
|
41 | |
|
|
42 | if (!name || !*name) |
40 | if (!name || !*name) |
43 | return 0; |
41 | return 0; |
44 | |
42 | |
45 | for (map = first_map; map; map = map->next) |
43 | for_all_maps (map) |
46 | if (!strcmp (name, map->path)) |
44 | if (!strcmp (name, map->path)) |
47 | break; |
|
|
48 | |
|
|
49 | return (map); |
45 | return map; |
|
|
46 | |
|
|
47 | return 0; |
50 | } |
48 | } |
51 | |
49 | |
52 | /* |
50 | /* |
53 | * This makes a path absolute outside the world of Crossfire. |
51 | * This makes a path absolute outside the world of Crossfire. |
54 | * In other words, it prepends LIBDIR/MAPDIR/ to the given path |
52 | * In other words, it prepends LIBDIR/MAPDIR/ to the given path |
… | |
… | |
221 | */ |
219 | */ |
222 | |
220 | |
223 | void |
221 | void |
224 | dump_all_maps (void) |
222 | dump_all_maps (void) |
225 | { |
223 | { |
226 | maptile *m; |
224 | for_all_maps (m) |
227 | |
|
|
228 | for (m = first_map; m; m = m->next) |
|
|
229 | dump_map (m); |
225 | dump_map (m); |
230 | } |
226 | } |
231 | |
227 | |
232 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
228 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
233 | * one function that just returns a P_.. value (see map.h) |
229 | * one function that just returns a P_.. value (see map.h) |
… | |
… | |
476 | * for objects whose arch says they are multipart yet according to the |
472 | * for objects whose arch says they are multipart yet according to the |
477 | * info we have, they only have the head (as would be expected when |
473 | * info we have, they only have the head (as would be expected when |
478 | * they are saved). We do have to look for the old maps that did save |
474 | * they are saved). We do have to look for the old maps that did save |
479 | * the more sections and not re-add sections for them. |
475 | * the more sections and not re-add sections for them. |
480 | */ |
476 | */ |
481 | |
|
|
482 | static void |
477 | static void |
483 | link_multipart_objects (maptile *m) |
478 | link_multipart_objects (maptile *m) |
484 | { |
479 | { |
485 | int x, y; |
480 | int x, y; |
486 | object *tmp, *op, *last, *above; |
481 | object *tmp, *op, *last, *above; |
… | |
… | |
637 | { |
632 | { |
638 | in_memory = MAP_SWAPPED; |
633 | in_memory = MAP_SWAPPED; |
639 | /* The maps used to pick up default x and y values from the |
634 | /* The maps used to pick up default x and y values from the |
640 | * map archetype. Mimic that behaviour. |
635 | * map archetype. Mimic that behaviour. |
641 | */ |
636 | */ |
642 | this->width = 16; |
637 | width = 16; |
643 | this->height = 16; |
638 | height = 16; |
644 | this->reset_timeout = 0; |
639 | reset_timeout = 0; |
645 | this->timeout = 300; |
640 | timeout = 300; |
646 | this->enter_x = 0; |
641 | enter_x = 0; |
647 | this->enter_y = 0; |
642 | enter_y = 0; |
648 | /*set part to -1 indicating conversion to weather map not yet done */ |
643 | /*set part to -1 indicating conversion to weather map not yet done */ |
649 | this->worldpartx = -1; |
644 | worldpartx = -1; |
650 | this->worldparty = -1; |
645 | worldparty = -1; |
651 | } |
646 | } |
652 | |
647 | |
653 | /* |
648 | /* |
654 | * Allocates, initialises, and returns a pointer to a maptile. |
649 | * Allocates, initialises, and returns a pointer to a maptile. |
655 | * Modified to no longer take a path option which was not being |
650 | * Modified to no longer take a path option which was not being |
656 | * used anyways. MSW 2001-07-01 |
651 | * used anyways. MSW 2001-07-01 |
657 | */ |
652 | */ |
658 | maptile * |
653 | maptile * |
659 | get_linked_map (void) |
654 | get_linked_map (void) |
660 | { |
655 | { |
661 | maptile *mp, *map = new maptile; |
656 | maptile *map = new maptile; |
662 | |
657 | |
663 | for (mp = first_map; mp && mp->next; mp = mp->next); |
658 | map->next = first_map; |
664 | |
|
|
665 | if (mp == NULL) |
|
|
666 | first_map = map; |
659 | first_map = map; |
667 | else |
|
|
668 | mp->next = map; |
|
|
669 | |
660 | |
670 | return map; |
661 | return map; |
671 | } |
662 | } |
672 | |
663 | |
673 | /* |
664 | /* |
… | |
… | |
685 | * that is their poor assumption. |
676 | * that is their poor assumption. |
686 | */ |
677 | */ |
687 | if (spaces) |
678 | if (spaces) |
688 | { |
679 | { |
689 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
680 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
690 | free (spaces); |
681 | sfree (spaces, size ()); |
691 | } |
682 | } |
692 | |
683 | |
693 | spaces = (mapspace *) |
684 | spaces = salloc0<mapspace> (size ()); |
694 | calloc (1, width * height * sizeof (mapspace)); |
|
|
695 | |
|
|
696 | if (!spaces) |
|
|
697 | fatal (OUT_OF_MEMORY); |
|
|
698 | } |
685 | } |
699 | |
686 | |
700 | /* Create and returns a map of the specific size. Used |
687 | /* Create and returns a map of the specific size. Used |
701 | * in random map code and the editor. |
688 | * in random map code and the editor. |
702 | */ |
689 | */ |
… | |
… | |
1260 | op->destroy (); |
1247 | op->destroy (); |
1261 | } |
1248 | } |
1262 | } |
1249 | } |
1263 | } |
1250 | } |
1264 | } |
1251 | } |
1265 | |
|
|
1266 | |
1252 | |
1267 | /* |
1253 | /* |
1268 | * Loads unique objects from file(s) into the map which is in memory |
1254 | * Loads unique objects from file(s) into the map which is in memory |
1269 | * m is the map to load unique items into. |
1255 | * m is the map to load unique items into. |
1270 | */ |
1256 | */ |
… | |
… | |
1487 | // TODO: use new/delete |
1473 | // TODO: use new/delete |
1488 | |
1474 | |
1489 | if (flag && m->spaces) |
1475 | if (flag && m->spaces) |
1490 | free_all_objects (m); |
1476 | free_all_objects (m); |
1491 | |
1477 | |
|
|
1478 | sfree (m->spaces, m->size ()), m->spaces = 0; |
|
|
1479 | |
1492 | free (m->name), m->name = 0; |
1480 | free (m->name), m->name = 0; |
1493 | free (m->spaces), m->spaces = 0; |
|
|
1494 | free (m->msg), m->msg = 0; |
1481 | free (m->msg), m->msg = 0; |
1495 | free (m->maplore), m->maplore = 0; |
1482 | free (m->maplore), m->maplore = 0; |
1496 | free (m->shoprace), m->shoprace = 0; |
1483 | free (m->shoprace), m->shoprace = 0; |
1497 | delete [] m->shopitems, m->shopitems = 0; |
1484 | delete [] m->shopitems, m->shopitems = 0; |
1498 | |
1485 | |
1499 | if (m->buttons) |
1486 | if (m->buttons) |
1500 | free_objectlinkpt (m->buttons), m->buttons = 0; |
1487 | free_objectlinkpt (m->buttons), m->buttons = 0; |
1501 | |
1488 | |
1502 | for (int i = 0; i < 4; i++) |
1489 | for (int i = 0; i < 4; i++) |
1503 | { |
|
|
1504 | if (m->tile_path[i]) |
|
|
1505 | free (m->tile_path[i]), m->tile_path[i] = 0; |
1490 | free (m->tile_path[i]), m->tile_path[i] = 0; |
1506 | |
|
|
1507 | m->tile_map[i] = 0; |
|
|
1508 | } |
|
|
1509 | |
1491 | |
1510 | m->in_memory = MAP_SWAPPED; |
1492 | m->in_memory = MAP_SWAPPED; |
1511 | } |
1493 | } |
1512 | |
1494 | |
1513 | maptile::~maptile () |
1495 | maptile::~maptile () |
1514 | { |
1496 | { |
1515 | free_map (this, 1); |
1497 | assert (destroyed ()); |
1516 | free (tmpname); |
|
|
1517 | } |
1498 | } |
1518 | |
1499 | |
1519 | void |
1500 | void |
1520 | maptile::do_destroy () |
1501 | maptile::do_destroy () |
1521 | { |
1502 | { |
1522 | attachable::do_destroy (); |
1503 | attachable::do_destroy (); |
1523 | |
1504 | |
1524 | free_all_objects (this); |
1505 | free_map (this, 1); |
|
|
1506 | free (tmpname), tmpname = 0; |
1525 | |
1507 | |
1526 | /* We need to look through all the maps and see if any maps |
1508 | /* We need to look through all the maps and see if any maps |
1527 | * are pointing at this one for tiling information. Since |
1509 | * are pointing at this one for tiling information. Since |
1528 | * tiling can be asymetric, we just can not look to see which |
1510 | * tiling can be asymetric, we just can not look to see which |
1529 | * maps this map tiles with and clears those. |
1511 | * maps this map tiles with and clears those. |
1530 | */ |
1512 | */ |
1531 | //TODO: non-euclidean-tiling MUST GO |
1513 | //TODO: non-euclidean-tiling MUST GO |
1532 | for (maptile *m = first_map; m; m = m->next) |
1514 | for_all_maps (m) |
1533 | for (int i = 0; i < 4; i++) |
1515 | for (int i = 0; i < 4; i++) |
1534 | if (m->tile_map[i] == this) |
1516 | if (m->tile_map[i] == this) |
1535 | m->tile_map[i] = 0; |
1517 | m->tile_map[i] = 0; |
1536 | |
1518 | |
1537 | if (first_map == this) |
1519 | if (first_map == this) |
1538 | first_map = next; |
1520 | first_map = next; |
1539 | else |
1521 | else |
1540 | for (maptile *m = first_map; m; m = m->next) |
1522 | for_all_maps (m) |
1541 | if (m->next = this) |
1523 | if (m->next = this) |
1542 | { |
1524 | { |
1543 | m->next = next; |
1525 | m->next = next; |
1544 | break; |
1526 | break; |
1545 | } |
1527 | } |
… | |
… | |
1747 | if (first_map->in_memory == MAP_SAVING) |
1729 | if (first_map->in_memory == MAP_SAVING) |
1748 | first_map->in_memory = MAP_IN_MEMORY; |
1730 | first_map->in_memory = MAP_IN_MEMORY; |
1749 | delete_map (first_map); |
1731 | delete_map (first_map); |
1750 | real_maps++; |
1732 | real_maps++; |
1751 | } |
1733 | } |
|
|
1734 | |
1752 | LOG (llevDebug, "free_all_maps: Freed %d maps\n", real_maps); |
1735 | LOG (llevDebug, "free_all_maps: Freed %d maps\n", real_maps); |
1753 | } |
1736 | } |
1754 | |
1737 | |
1755 | /* change_map_light() - used to change map light level (darkness) |
1738 | /* change_map_light() - used to change map light level (darkness) |
1756 | * up or down. Returns true if successful. It should now be |
1739 | * up or down. Returns true if successful. It should now be |