… | |
… | |
32 | |
32 | |
33 | /* |
33 | /* |
34 | * Returns the maptile which has a name matching the given argument. |
34 | * Returns the maptile which has a name matching the given argument. |
35 | * return NULL if no match is found. |
35 | * return NULL if no match is found. |
36 | */ |
36 | */ |
37 | |
|
|
38 | maptile * |
37 | maptile * |
39 | has_been_loaded (const char *name) |
38 | has_been_loaded (const char *name) |
40 | { |
39 | { |
41 | maptile *map; |
40 | maptile *map; |
42 | |
41 | |
43 | if (!name || !*name) |
42 | if (!name || !*name) |
44 | return 0; |
43 | return 0; |
|
|
44 | |
45 | for (map = first_map; map; map = map->next) |
45 | for (map = first_map; map; map = map->next) |
46 | if (!strcmp (name, map->path)) |
46 | if (!strcmp (name, map->path)) |
47 | break; |
47 | break; |
|
|
48 | |
48 | return (map); |
49 | return (map); |
49 | } |
50 | } |
50 | |
51 | |
51 | /* |
52 | /* |
52 | * This makes a path absolute outside the world of Crossfire. |
53 | * This makes a path absolute outside the world of Crossfire. |
… | |
… | |
196 | |
197 | |
197 | void |
198 | void |
198 | dump_map (const maptile *m) |
199 | dump_map (const maptile *m) |
199 | { |
200 | { |
200 | LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); |
201 | LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); |
201 | LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m)); |
202 | LOG (llevError, "Size: %dx%d Start: %d,%d\n", m->width, m->height, m->enter_x, m->enter_y); |
202 | |
203 | |
203 | if (m->msg != NULL) |
204 | if (m->msg != NULL) |
204 | LOG (llevError, "Message:\n%s", m->msg); |
205 | LOG (llevError, "Message:\n%s", m->msg); |
205 | |
206 | |
206 | if (m->maplore != NULL) |
207 | if (m->maplore != NULL) |
… | |
… | |
483 | { |
484 | { |
484 | int x, y; |
485 | int x, y; |
485 | object *tmp, *op, *last, *above; |
486 | object *tmp, *op, *last, *above; |
486 | archetype *at; |
487 | archetype *at; |
487 | |
488 | |
488 | for (x = 0; x < MAP_WIDTH (m); x++) |
489 | for (x = 0; x < m->width; x++) |
489 | for (y = 0; y < MAP_HEIGHT (m); y++) |
490 | for (y = 0; y < m->height; y++) |
490 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above) |
491 | for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above) |
491 | { |
492 | { |
492 | above = tmp->above; |
493 | above = tmp->above; |
493 | |
494 | |
494 | /* already multipart - don't do anything more */ |
495 | /* already multipart - don't do anything more */ |
… | |
… | |
606 | { |
607 | { |
607 | int i, j = 0, unique = 0; |
608 | int i, j = 0, unique = 0; |
608 | object *op; |
609 | object *op; |
609 | |
610 | |
610 | /* first pass - save one-part objects */ |
611 | /* first pass - save one-part objects */ |
611 | for (i = 0; i < MAP_WIDTH (m); i++) |
612 | for (i = 0; i < m->width; i++) |
612 | for (j = 0; j < MAP_HEIGHT (m); j++) |
613 | for (j = 0; j < m->height; j++) |
613 | { |
614 | { |
614 | unique = 0; |
615 | unique = 0; |
615 | for (op = GET_MAP_OB (m, i, j); op; op = op->above) |
616 | for (op = m->at (i, j).bot; op; op = op->above) |
616 | { |
617 | { |
617 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
618 | if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE]) |
618 | unique = 1; |
619 | unique = 1; |
619 | |
620 | |
620 | if (op->type == PLAYER) |
621 | if (op->type == PLAYER) |
621 | continue; |
622 | continue; |
622 | |
623 | |
623 | if (op->head || op->owner) |
624 | if (op->head || op->owner) |
624 | continue; |
625 | continue; |
625 | |
626 | |
626 | if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) |
627 | if (unique || op->flag [FLAG_UNIQUE]) |
627 | save_object (fp2, op, 3); |
628 | save_object (fp2, op, 3); |
628 | else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) |
629 | else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID]))) |
629 | save_object (fp, op, 3); |
630 | save_object (fp, op, 3); |
630 | } |
631 | } |
631 | } |
632 | } |
632 | } |
633 | } |
633 | |
634 | |
… | |
… | |
635 | { |
636 | { |
636 | in_memory = MAP_SWAPPED; |
637 | in_memory = MAP_SWAPPED; |
637 | /* The maps used to pick up default x and y values from the |
638 | /* The maps used to pick up default x and y values from the |
638 | * map archetype. Mimic that behaviour. |
639 | * map archetype. Mimic that behaviour. |
639 | */ |
640 | */ |
640 | MAP_WIDTH (this) = 16; |
641 | this->width = 16; |
641 | MAP_HEIGHT (this) = 16; |
642 | this->height = 16; |
642 | MAP_RESET_TIMEOUT (this) = 0; |
643 | this->reset_timeout = 0; |
643 | MAP_TIMEOUT (this) = 300; |
644 | this->timeout = 300; |
644 | MAP_ENTER_X (this) = 0; |
645 | this->enter_x = 0; |
645 | MAP_ENTER_Y (this) = 0; |
646 | this->enter_y = 0; |
646 | /*set part to -1 indicating conversion to weather map not yet done */ |
647 | /*set part to -1 indicating conversion to weather map not yet done */ |
647 | MAP_WORLDPARTX (this) = -1; |
648 | this->worldpartx = -1; |
648 | MAP_WORLDPARTY (this) = -1; |
649 | this->worldparty = -1; |
649 | } |
650 | } |
650 | |
651 | |
651 | /* |
652 | /* |
652 | * Allocates, initialises, and returns a pointer to a maptile. |
653 | * Allocates, initialises, and returns a pointer to a maptile. |
653 | * Modified to no longer take a path option which was not being |
654 | * Modified to no longer take a path option which was not being |
… | |
… | |
1132 | |
1133 | |
1133 | m->in_memory = MAP_LOADING; |
1134 | m->in_memory = MAP_LOADING; |
1134 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1135 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1135 | |
1136 | |
1136 | m->in_memory = MAP_IN_MEMORY; |
1137 | m->in_memory = MAP_IN_MEMORY; |
1137 | if (!MAP_DIFFICULTY (m)) |
1138 | if (!m->difficulty) |
1138 | MAP_DIFFICULTY (m) = calculate_difficulty (m); |
1139 | m->difficulty = calculate_difficulty (m); |
1139 | set_map_reset_time (m); |
1140 | set_map_reset_time (m); |
1140 | m->instantiate (); |
1141 | m->instantiate (); |
1141 | return (m); |
1142 | return (m); |
1142 | } |
1143 | } |
1143 | |
1144 | |
… | |
… | |
1238 | delete_unique_items (maptile *m) |
1239 | delete_unique_items (maptile *m) |
1239 | { |
1240 | { |
1240 | int i, j, unique; |
1241 | int i, j, unique; |
1241 | object *op, *next; |
1242 | object *op, *next; |
1242 | |
1243 | |
1243 | for (i = 0; i < MAP_WIDTH (m); i++) |
1244 | for (i = 0; i < m->width; i++) |
1244 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1245 | for (j = 0; j < m->height; j++) |
1245 | { |
1246 | { |
1246 | unique = 0; |
1247 | unique = 0; |
1247 | |
1248 | |
1248 | for (op = GET_MAP_OB (m, i, j); op; op = next) |
1249 | for (op = GET_MAP_OB (m, i, j); op; op = next) |
1249 | { |
1250 | { |
… | |
… | |
1288 | return; |
1289 | return; |
1289 | |
1290 | |
1290 | m->in_memory = MAP_LOADING; |
1291 | m->in_memory = MAP_LOADING; |
1291 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1292 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1292 | delete_unique_items (m); /* original map before, don't duplicate them */ |
1293 | delete_unique_items (m); /* original map before, don't duplicate them */ |
|
|
1294 | |
1293 | load_objects (m, thawer, 0); |
1295 | load_objects (m, thawer, 0); |
1294 | |
1296 | |
1295 | m->in_memory = MAP_IN_MEMORY; |
1297 | m->in_memory = MAP_IN_MEMORY; |
1296 | } |
1298 | } |
1297 | |
|
|
1298 | |
1299 | |
1299 | /* |
1300 | /* |
1300 | * Saves a map to file. If flag is set, it is saved into the same |
1301 | * Saves a map to file. If flag is set, it is saved into the same |
1301 | * file it was (originally) loaded from. Otherwise a temporary |
1302 | * file it was (originally) loaded from. Otherwise a temporary |
1302 | * filename will be genarated, and the file will be stored there. |
1303 | * filename will be genarated, and the file will be stored there. |
1303 | * The temporary filename will be stored in the maptileure. |
1304 | * The temporary filename will be stored in the maptileure. |
1304 | * If the map is unique, we also save to the filename in the map |
1305 | * If the map is unique, we also save to the filename in the map |
1305 | * (this should have been updated when first loaded) |
1306 | * (this should have been updated when first loaded) |
1306 | */ |
1307 | */ |
1307 | |
|
|
1308 | int |
1308 | int |
1309 | new_save_map (maptile *m, int flag) |
1309 | new_save_map (maptile *m, int flag) |
1310 | { |
1310 | { |
1311 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1311 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1312 | int i; |
1312 | int i; |
… | |
… | |
1453 | free_all_objects (maptile *m) |
1453 | free_all_objects (maptile *m) |
1454 | { |
1454 | { |
1455 | if (!m->spaces) |
1455 | if (!m->spaces) |
1456 | return; |
1456 | return; |
1457 | |
1457 | |
1458 | for (int i = 0; i < MAP_WIDTH (m); i++) |
1458 | for (int i = 0; i < m->width; i++) |
1459 | for (int j = 0; j < MAP_HEIGHT (m); j++) |
1459 | for (int j = 0; j < m->height; j++) |
1460 | { |
1460 | { |
1461 | mapspace &ms = m->at (i, j); |
1461 | mapspace &ms = m->at (i, j); |
1462 | |
1462 | |
1463 | while (object *op = ms.bottom) |
1463 | while (object *op = ms.bot) |
1464 | { |
1464 | { |
1465 | if (op->head) |
1465 | if (op->head) |
1466 | op = op->head; |
1466 | op = op->head; |
1467 | |
1467 | |
1468 | op->destroy_inv (false); |
1468 | op->destroy_inv (false); |
… | |
… | |
1476 | * don't free tmpname - our caller is left to do that |
1476 | * don't free tmpname - our caller is left to do that |
1477 | */ |
1477 | */ |
1478 | void |
1478 | void |
1479 | free_map (maptile *m, int flag) |
1479 | free_map (maptile *m, int flag) |
1480 | { |
1480 | { |
1481 | if (m->in_memory != MAP_IN_MEMORY) |
1481 | if (!m->in_memory) //TODO: makes no sense to me? |
1482 | return; |
1482 | return; |
1483 | |
1483 | |
1484 | m->in_memory = MAP_SAVING; |
1484 | m->in_memory = MAP_SAVING; |
1485 | |
1485 | |
1486 | // TODO: use new/delete |
1486 | // TODO: use new/delete |
1487 | #define FREE_AND_CLEAR(p) { free (p); p = NULL; } |
|
|
1488 | |
1487 | |
1489 | if (flag && m->spaces) |
1488 | if (flag && m->spaces) |
1490 | free_all_objects (m); |
1489 | free_all_objects (m); |
1491 | if (m->name) |
|
|
1492 | FREE_AND_CLEAR (m->name); |
|
|
1493 | if (m->spaces) |
|
|
1494 | FREE_AND_CLEAR (m->spaces); |
|
|
1495 | if (m->msg) |
|
|
1496 | FREE_AND_CLEAR (m->msg); |
|
|
1497 | if (m->maplore) |
|
|
1498 | FREE_AND_CLEAR (m->maplore); |
|
|
1499 | |
1490 | |
1500 | delete [] m->shopitems; |
1491 | free (m->name), m->name = 0; |
1501 | m->shopitems = 0; |
1492 | free (m->spaces), m->spaces = 0; |
1502 | |
1493 | free (m->msg), m->msg = 0; |
1503 | if (m->shoprace) |
1494 | free (m->maplore), m->maplore = 0; |
1504 | FREE_AND_CLEAR (m->shoprace); |
1495 | free (m->shoprace), m->shoprace = 0; |
|
|
1496 | delete [] m->shopitems, m->shopitems = 0; |
1505 | |
1497 | |
1506 | if (m->buttons) |
1498 | if (m->buttons) |
1507 | free_objectlinkpt (m->buttons); |
1499 | free_objectlinkpt (m->buttons), m->buttons = 0; |
1508 | |
|
|
1509 | m->buttons = NULL; |
|
|
1510 | |
1500 | |
1511 | for (int i = 0; i < 4; i++) |
1501 | for (int i = 0; i < 4; i++) |
1512 | { |
1502 | { |
1513 | if (m->tile_path[i]) |
1503 | if (m->tile_path[i]) |
1514 | FREE_AND_CLEAR (m->tile_path[i]); |
1504 | free (m->tile_path[i]), m->tile_path[i] = 0; |
1515 | |
1505 | |
1516 | m->tile_map[i] = 0; |
1506 | m->tile_map[i] = 0; |
1517 | } |
1507 | } |
1518 | |
1508 | |
1519 | m->in_memory = MAP_SWAPPED; |
1509 | m->in_memory = MAP_SWAPPED; |
1520 | |
|
|
1521 | #undef FREE_AND_CLEAR |
|
|
1522 | } |
1510 | } |
1523 | |
1511 | |
1524 | maptile::~maptile () |
1512 | maptile::~maptile () |
1525 | { |
1513 | { |
1526 | free_map (this, 1); |
1514 | free_map (this, 1); |
… | |
… | |
1692 | int x, y, i; |
1680 | int x, y, i; |
1693 | long monster_cnt = 0; |
1681 | long monster_cnt = 0; |
1694 | double avgexp = 0; |
1682 | double avgexp = 0; |
1695 | sint64 total_exp = 0; |
1683 | sint64 total_exp = 0; |
1696 | |
1684 | |
1697 | if (MAP_DIFFICULTY (m)) |
1685 | if (m->difficulty) |
1698 | { |
1686 | { |
1699 | LOG (llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY (m)); |
1687 | LOG (llevDebug, "Using stored map difficulty: %d\n", m->difficulty); |
1700 | return MAP_DIFFICULTY (m); |
1688 | return m->difficulty; |
1701 | } |
1689 | } |
1702 | |
1690 | |
1703 | for (x = 0; x < MAP_WIDTH (m); x++) |
1691 | for (x = 0; x < m->width; x++) |
1704 | for (y = 0; y < MAP_HEIGHT (m); y++) |
1692 | for (y = 0; y < m->height; y++) |
1705 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
1693 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
1706 | { |
1694 | { |
1707 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1695 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1708 | { |
1696 | { |
1709 | total_exp += op->stats.exp; |
1697 | total_exp += op->stats.exp; |
… | |
… | |
1826 | |
1814 | |
1827 | middle_obj = 0; |
1815 | middle_obj = 0; |
1828 | top_obj = 0; |
1816 | top_obj = 0; |
1829 | floor_obj = 0; |
1817 | floor_obj = 0; |
1830 | |
1818 | |
1831 | for (tmp = bottom; tmp; last = tmp, tmp = tmp->above) |
1819 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1832 | { |
1820 | { |
1833 | /* This could be made additive I guess (two lights better than |
1821 | /* This could be made additive I guess (two lights better than |
1834 | * one). But if so, it shouldn't be a simple additive - 2 |
1822 | * one). But if so, it shouldn't be a simple additive - 2 |
1835 | * light bulbs do not illuminate twice as far as once since |
1823 | * light bulbs do not illuminate twice as far as once since |
1836 | * it is a dissapation factor that is cubed. |
1824 | * it is a dissapation factor that is cubed. |
… | |
… | |
1986 | void |
1974 | void |
1987 | set_map_reset_time (maptile *map) |
1975 | set_map_reset_time (maptile *map) |
1988 | { |
1976 | { |
1989 | int timeout; |
1977 | int timeout; |
1990 | |
1978 | |
1991 | timeout = MAP_RESET_TIMEOUT (map); |
1979 | timeout = map->reset_timeout; |
1992 | if (timeout <= 0) |
1980 | if (timeout <= 0) |
1993 | timeout = MAP_DEFAULTRESET; |
1981 | timeout = MAP_DEFAULTRESET; |
1994 | if (timeout >= MAP_MAXRESET) |
1982 | if (timeout >= MAP_MAXRESET) |
1995 | timeout = MAP_MAXRESET; |
1983 | timeout = MAP_MAXRESET; |
1996 | MAP_WHEN_RESET (map) = time (0) + timeout; |
1984 | map->reset_time = time (0) + timeout; |
1997 | } |
1985 | } |
1998 | |
1986 | |
1999 | /* this updates the orig_map->tile_map[tile_num] value after loading |
1987 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2000 | * the map. It also takes care of linking back the freshly loaded |
1988 | * the map. It also takes care of linking back the freshly loaded |
2001 | * maps tile_map values if it tiles back to this one. It returns |
1989 | * maps tile_map values if it tiles back to this one. It returns |
… | |
… | |
2044 | return 1; |
2032 | return 1; |
2045 | |
2033 | |
2046 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2034 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2047 | load_and_link_tiled_map (m, 3); |
2035 | load_and_link_tiled_map (m, 3); |
2048 | |
2036 | |
2049 | return (out_of_map (m->tile_map[3], x + MAP_WIDTH (m->tile_map[3]), y)); |
2037 | return (out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y)); |
2050 | } |
2038 | } |
2051 | |
2039 | |
2052 | if (x >= MAP_WIDTH (m)) |
2040 | if (x >= m->width) |
2053 | { |
2041 | { |
2054 | if (!m->tile_path[1]) |
2042 | if (!m->tile_path[1]) |
2055 | return 1; |
2043 | return 1; |
2056 | |
2044 | |
2057 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2045 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2058 | load_and_link_tiled_map (m, 1); |
2046 | load_and_link_tiled_map (m, 1); |
2059 | |
2047 | |
2060 | return (out_of_map (m->tile_map[1], x - MAP_WIDTH (m), y)); |
2048 | return (out_of_map (m->tile_map[1], x - m->width, y)); |
2061 | } |
2049 | } |
2062 | |
2050 | |
2063 | if (y < 0) |
2051 | if (y < 0) |
2064 | { |
2052 | { |
2065 | if (!m->tile_path[0]) |
2053 | if (!m->tile_path[0]) |
2066 | return 1; |
2054 | return 1; |
2067 | |
2055 | |
2068 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2056 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2069 | load_and_link_tiled_map (m, 0); |
2057 | load_and_link_tiled_map (m, 0); |
2070 | |
2058 | |
2071 | return (out_of_map (m->tile_map[0], x, y + MAP_HEIGHT (m->tile_map[0]))); |
2059 | return (out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height)); |
2072 | } |
2060 | } |
2073 | |
2061 | |
2074 | if (y >= MAP_HEIGHT (m)) |
2062 | if (y >= m->height) |
2075 | { |
2063 | { |
2076 | if (!m->tile_path[2]) |
2064 | if (!m->tile_path[2]) |
2077 | return 1; |
2065 | return 1; |
2078 | |
2066 | |
2079 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2067 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2080 | load_and_link_tiled_map (m, 2); |
2068 | load_and_link_tiled_map (m, 2); |
2081 | |
2069 | |
2082 | return (out_of_map (m->tile_map[2], x, y - MAP_HEIGHT (m))); |
2070 | return (out_of_map (m->tile_map[2], x, y - m->height)); |
2083 | } |
2071 | } |
2084 | |
2072 | |
2085 | /* Simple case - coordinates are within this local |
2073 | /* Simple case - coordinates are within this local |
2086 | * map. |
2074 | * map. |
2087 | */ |
2075 | */ |
… | |
… | |
2105 | if (!m->tile_path[3]) |
2093 | if (!m->tile_path[3]) |
2106 | return 0; |
2094 | return 0; |
2107 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2095 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
2108 | load_and_link_tiled_map (m, 3); |
2096 | load_and_link_tiled_map (m, 3); |
2109 | |
2097 | |
2110 | *x += MAP_WIDTH (m->tile_map[3]); |
2098 | *x += m->tile_map[3]->width; |
2111 | return (get_map_from_coord (m->tile_map[3], x, y)); |
2099 | return (get_map_from_coord (m->tile_map[3], x, y)); |
2112 | } |
2100 | } |
2113 | |
2101 | |
2114 | if (*x >= MAP_WIDTH (m)) |
2102 | if (*x >= m->width) |
2115 | { |
2103 | { |
2116 | if (!m->tile_path[1]) |
2104 | if (!m->tile_path[1]) |
2117 | return 0; |
2105 | return 0; |
2118 | |
2106 | |
2119 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2107 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
2120 | load_and_link_tiled_map (m, 1); |
2108 | load_and_link_tiled_map (m, 1); |
2121 | |
2109 | |
2122 | *x -= MAP_WIDTH (m); |
2110 | *x -= m->width; |
2123 | return (get_map_from_coord (m->tile_map[1], x, y)); |
2111 | return (get_map_from_coord (m->tile_map[1], x, y)); |
2124 | } |
2112 | } |
2125 | |
2113 | |
2126 | if (*y < 0) |
2114 | if (*y < 0) |
2127 | { |
2115 | { |
… | |
… | |
2129 | return 0; |
2117 | return 0; |
2130 | |
2118 | |
2131 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2119 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
2132 | load_and_link_tiled_map (m, 0); |
2120 | load_and_link_tiled_map (m, 0); |
2133 | |
2121 | |
2134 | *y += MAP_HEIGHT (m->tile_map[0]); |
2122 | *y += m->tile_map[0]->height; |
2135 | return (get_map_from_coord (m->tile_map[0], x, y)); |
2123 | return (get_map_from_coord (m->tile_map[0], x, y)); |
2136 | } |
2124 | } |
2137 | |
2125 | |
2138 | if (*y >= MAP_HEIGHT (m)) |
2126 | if (*y >= m->height) |
2139 | { |
2127 | { |
2140 | if (!m->tile_path[2]) |
2128 | if (!m->tile_path[2]) |
2141 | return 0; |
2129 | return 0; |
2142 | |
2130 | |
2143 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2131 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
2144 | load_and_link_tiled_map (m, 2); |
2132 | load_and_link_tiled_map (m, 2); |
2145 | |
2133 | |
2146 | *y -= MAP_HEIGHT (m); |
2134 | *y -= m->height; |
2147 | return (get_map_from_coord (m->tile_map[2], x, y)); |
2135 | return (get_map_from_coord (m->tile_map[2], x, y)); |
2148 | } |
2136 | } |
2149 | |
2137 | |
2150 | /* Simple case - coordinates are within this local |
2138 | /* Simple case - coordinates are within this local |
2151 | * map. |
2139 | * map. |
… | |
… | |
2171 | |
2159 | |
2172 | } |
2160 | } |
2173 | else if (map1->tile_map[0] == map2) |
2161 | else if (map1->tile_map[0] == map2) |
2174 | { /* up */ |
2162 | { /* up */ |
2175 | *dx = 0; |
2163 | *dx = 0; |
2176 | *dy = -MAP_HEIGHT (map2); |
2164 | *dy = -map2->height; |
2177 | } |
2165 | } |
2178 | else if (map1->tile_map[1] == map2) |
2166 | else if (map1->tile_map[1] == map2) |
2179 | { /* right */ |
2167 | { /* right */ |
2180 | *dx = MAP_WIDTH (map1); |
2168 | *dx = map1->width; |
2181 | *dy = 0; |
2169 | *dy = 0; |
2182 | } |
2170 | } |
2183 | else if (map1->tile_map[2] == map2) |
2171 | else if (map1->tile_map[2] == map2) |
2184 | { /* down */ |
2172 | { /* down */ |
2185 | *dx = 0; |
2173 | *dx = 0; |
2186 | *dy = MAP_HEIGHT (map1); |
2174 | *dy = map1->height; |
2187 | } |
2175 | } |
2188 | else if (map1->tile_map[3] == map2) |
2176 | else if (map1->tile_map[3] == map2) |
2189 | { /* left */ |
2177 | { /* left */ |
2190 | *dx = -MAP_WIDTH (map2); |
2178 | *dx = -map2->width; |
2191 | *dy = 0; |
2179 | *dy = 0; |
2192 | |
2180 | |
2193 | } |
2181 | } |
2194 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) |
2182 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) |
2195 | { /* up right */ |
2183 | { /* up right */ |
2196 | *dx = MAP_WIDTH (map1->tile_map[0]); |
2184 | *dx = map1->tile_map[0]->width; |
2197 | *dy = -MAP_HEIGHT (map1->tile_map[0]); |
2185 | *dy = -map1->tile_map[0]->height; |
2198 | } |
2186 | } |
2199 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) |
2187 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) |
2200 | { /* up left */ |
2188 | { /* up left */ |
2201 | *dx = -MAP_WIDTH (map2); |
2189 | *dx = -map2->width; |
2202 | *dy = -MAP_HEIGHT (map1->tile_map[0]); |
2190 | *dy = -map1->tile_map[0]->height; |
2203 | } |
2191 | } |
2204 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) |
2192 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) |
2205 | { /* right up */ |
2193 | { /* right up */ |
2206 | *dx = MAP_WIDTH (map1); |
2194 | *dx = map1->width; |
2207 | *dy = -MAP_HEIGHT (map2); |
2195 | *dy = -map2->height; |
2208 | } |
2196 | } |
2209 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) |
2197 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) |
2210 | { /* right down */ |
2198 | { /* right down */ |
2211 | *dx = MAP_WIDTH (map1); |
2199 | *dx = map1->width; |
2212 | *dy = MAP_HEIGHT (map1->tile_map[1]); |
2200 | *dy = map1->tile_map[1]->height; |
2213 | } |
2201 | } |
2214 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) |
2202 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) |
2215 | { /* down right */ |
2203 | { /* down right */ |
2216 | *dx = MAP_WIDTH (map1->tile_map[2]); |
2204 | *dx = map1->tile_map[2]->width; |
2217 | *dy = MAP_HEIGHT (map1); |
2205 | *dy = map1->height; |
2218 | } |
2206 | } |
2219 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) |
2207 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) |
2220 | { /* down left */ |
2208 | { /* down left */ |
2221 | *dx = -MAP_WIDTH (map2); |
2209 | *dx = -map2->width; |
2222 | *dy = MAP_HEIGHT (map1); |
2210 | *dy = map1->height; |
2223 | } |
2211 | } |
2224 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) |
2212 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) |
2225 | { /* left up */ |
2213 | { /* left up */ |
2226 | *dx = -MAP_WIDTH (map1->tile_map[3]); |
2214 | *dx = -map1->tile_map[3]->width; |
2227 | *dy = -MAP_HEIGHT (map2); |
2215 | *dy = -map2->height; |
2228 | } |
2216 | } |
2229 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) |
2217 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) |
2230 | { /* left down */ |
2218 | { /* left down */ |
2231 | *dx = -MAP_WIDTH (map1->tile_map[3]); |
2219 | *dx = -map1->tile_map[3]->width; |
2232 | *dy = MAP_HEIGHT (map1->tile_map[3]); |
2220 | *dy = map1->tile_map[3]->height; |
2233 | |
2221 | |
2234 | } |
2222 | } |
2235 | else |
2223 | else |
2236 | { /* not "adjacent" enough */ |
2224 | { /* not "adjacent" enough */ |
2237 | return 0; |
2225 | return 0; |