ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.47 by root, Mon Dec 25 11:25:49 2006 UTC vs.
Revision 1.53 by root, Wed Dec 27 09:28:01 2006 UTC

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
38maptile * 37maptile *
39has_been_loaded (const char *name) 38has_been_loaded (const char *name)
40{ 39{
41 maptile *map;
42
43 if (!name || !*name) 40 if (!name || !*name)
44 return 0; 41 return 0;
45 for (map = first_map; map; map = map->next) 42
43 for_all_maps (map)
46 if (!strcmp (name, map->path)) 44 if (!strcmp (name, map->path))
47 break;
48 return (map); 45 return map;
46
47 return 0;
49} 48}
50 49
51/* 50/*
52 * This makes a path absolute outside the world of Crossfire. 51 * This makes a path absolute outside the world of Crossfire.
53 * In other words, it prepends LIBDIR/MAPDIR/ to the given path 52 * In other words, it prepends LIBDIR/MAPDIR/ to the given path
196 195
197void 196void
198dump_map (const maptile *m) 197dump_map (const maptile *m)
199{ 198{
200 LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); 199 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)); 200 LOG (llevError, "Size: %dx%d Start: %d,%d\n", m->width, m->height, m->enter_x, m->enter_y);
202 201
203 if (m->msg != NULL) 202 if (m->msg != NULL)
204 LOG (llevError, "Message:\n%s", m->msg); 203 LOG (llevError, "Message:\n%s", m->msg);
205 204
206 if (m->maplore != NULL) 205 if (m->maplore != NULL)
220 */ 219 */
221 220
222void 221void
223dump_all_maps (void) 222dump_all_maps (void)
224{ 223{
225 maptile *m; 224 for_all_maps (m)
226
227 for (m = first_map; m; m = m->next)
228 dump_map (m); 225 dump_map (m);
229} 226}
230 227
231/* This rolls up wall, blocks_magic, blocks_view, etc, all into 228/* This rolls up wall, blocks_magic, blocks_view, etc, all into
232 * one function that just returns a P_.. value (see map.h) 229 * one function that just returns a P_.. value (see map.h)
475 * 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
476 * 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
477 * 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
478 * the more sections and not re-add sections for them. 475 * the more sections and not re-add sections for them.
479 */ 476 */
480
481static void 477static void
482link_multipart_objects (maptile *m) 478link_multipart_objects (maptile *m)
483{ 479{
484 int x, y; 480 int x, y;
485 object *tmp, *op, *last, *above; 481 object *tmp, *op, *last, *above;
486 archetype *at; 482 archetype *at;
487 483
488 for (x = 0; x < MAP_WIDTH (m); x++) 484 for (x = 0; x < m->width; x++)
489 for (y = 0; y < MAP_HEIGHT (m); y++) 485 for (y = 0; y < m->height; y++)
490 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above) 486 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above)
491 { 487 {
492 above = tmp->above; 488 above = tmp->above;
493 489
494 /* already multipart - don't do anything more */ 490 /* already multipart - don't do anything more */
600 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 596 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
601 * and we only save the head of multi part objects - this is needed 597 * and we only save the head of multi part objects - this is needed
602 * in order to do map tiling properly. 598 * in order to do map tiling properly.
603 */ 599 */
604void 600void
605save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag) 601save_objects (maptile *m, object_freezer &fp, object_freezer &fp2, int flag)
606{ 602{
607 int i, j = 0, unique = 0; 603 int i, j = 0, unique = 0;
608 object *op; 604 object *op;
609 605
610 /* first pass - save one-part objects */ 606 /* first pass - save one-part objects */
611 for (i = 0; i < MAP_WIDTH (m); i++) 607 for (i = 0; i < m->width; i++)
612 for (j = 0; j < MAP_HEIGHT (m); j++) 608 for (j = 0; j < m->height; j++)
613 { 609 {
614 unique = 0; 610 unique = 0;
611
615 for (op = GET_MAP_OB (m, i, j); op; op = op->above) 612 for (op = m->at (i, j).bot; op; op = op->above)
616 { 613 {
617 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 614 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
618 unique = 1; 615 unique = 1;
619 616
620 if (op->type == PLAYER) 617 if (op->type == PLAYER)
621 continue; 618 continue;
622 619
623 if (op->head || op->owner) 620 if (op->head || op->owner)
624 continue; 621 continue;
625 622
626 if (unique || QUERY_FLAG (op, FLAG_UNIQUE)) 623 if (unique || op->flag [FLAG_UNIQUE])
627 save_object (fp2, op, 3); 624 save_object (fp2, op, 1);
628 else if (flag == 0 || (flag == 2 && (!QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) && !QUERY_FLAG (op, FLAG_UNPAID)))) 625 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID])))
629 save_object (fp, op, 3); 626 save_object (fp, op, 1);
630 } 627 }
631 } 628 }
632} 629}
633 630
634maptile::maptile () 631maptile::maptile ()
635{ 632{
636 in_memory = MAP_SWAPPED; 633 in_memory = MAP_SWAPPED;
637 /* 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
638 * map archetype. Mimic that behaviour. 635 * map archetype. Mimic that behaviour.
639 */ 636 */
640 MAP_WIDTH (this) = 16; 637 width = 16;
641 MAP_HEIGHT (this) = 16; 638 height = 16;
642 MAP_RESET_TIMEOUT (this) = 0; 639 reset_timeout = 0;
643 MAP_TIMEOUT (this) = 300; 640 timeout = 300;
644 MAP_ENTER_X (this) = 0; 641 enter_x = 0;
645 MAP_ENTER_Y (this) = 0; 642 enter_y = 0;
646 /*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 */
647 MAP_WORLDPARTX (this) = -1; 644 worldpartx = -1;
648 MAP_WORLDPARTY (this) = -1; 645 worldparty = -1;
649} 646}
650 647
651/* 648/*
652 * Allocates, initialises, and returns a pointer to a maptile. 649 * Allocates, initialises, and returns a pointer to a maptile.
653 * 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
654 * used anyways. MSW 2001-07-01 651 * used anyways. MSW 2001-07-01
655 */ 652 */
656maptile * 653maptile *
657get_linked_map (void) 654get_linked_map (void)
658{ 655{
659 maptile *mp, *map = new maptile; 656 maptile *map = new maptile;
660 657
661 for (mp = first_map; mp && mp->next; mp = mp->next); 658 map->next = first_map;
662
663 if (mp == NULL)
664 first_map = map; 659 first_map = map;
665 else
666 mp->next = map;
667 660
668 return map; 661 return map;
669} 662}
670 663
671/* 664/*
683 * that is their poor assumption. 676 * that is their poor assumption.
684 */ 677 */
685 if (spaces) 678 if (spaces)
686 { 679 {
687 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);
688 free (spaces); 681 sfree (spaces, size ());
689 } 682 }
690 683
691 spaces = (mapspace *) 684 spaces = salloc0<mapspace> (size ());
692 calloc (1, width * height * sizeof (mapspace));
693
694 if (!spaces)
695 fatal (OUT_OF_MEMORY);
696} 685}
697 686
698/* Create and returns a map of the specific size. Used 687/* Create and returns a map of the specific size. Used
699 * in random map code and the editor. 688 * in random map code and the editor.
700 */ 689 */
1132 1121
1133 m->in_memory = MAP_LOADING; 1122 m->in_memory = MAP_LOADING;
1134 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1123 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1135 1124
1136 m->in_memory = MAP_IN_MEMORY; 1125 m->in_memory = MAP_IN_MEMORY;
1137 if (!MAP_DIFFICULTY (m)) 1126 if (!m->difficulty)
1138 MAP_DIFFICULTY (m) = calculate_difficulty (m); 1127 m->difficulty = calculate_difficulty (m);
1139 set_map_reset_time (m); 1128 set_map_reset_time (m);
1140 m->instantiate (); 1129 m->instantiate ();
1141 return (m); 1130 return (m);
1142} 1131}
1143 1132
1238delete_unique_items (maptile *m) 1227delete_unique_items (maptile *m)
1239{ 1228{
1240 int i, j, unique; 1229 int i, j, unique;
1241 object *op, *next; 1230 object *op, *next;
1242 1231
1243 for (i = 0; i < MAP_WIDTH (m); i++) 1232 for (i = 0; i < m->width; i++)
1244 for (j = 0; j < MAP_HEIGHT (m); j++) 1233 for (j = 0; j < m->height; j++)
1245 { 1234 {
1246 unique = 0; 1235 unique = 0;
1247 1236
1248 for (op = GET_MAP_OB (m, i, j); op; op = next) 1237 for (op = GET_MAP_OB (m, i, j); op; op = next)
1249 { 1238 {
1259 } 1248 }
1260 } 1249 }
1261 } 1250 }
1262} 1251}
1263 1252
1264
1265/* 1253/*
1266 * 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
1267 * m is the map to load unique items into. 1255 * m is the map to load unique items into.
1268 */ 1256 */
1269static void 1257static void
1288 return; 1276 return;
1289 1277
1290 m->in_memory = MAP_LOADING; 1278 m->in_memory = MAP_LOADING;
1291 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1279 if (m->tmpname == NULL) /* if we have loaded unique items from */
1292 delete_unique_items (m); /* original map before, don't duplicate them */ 1280 delete_unique_items (m); /* original map before, don't duplicate them */
1281
1293 load_objects (m, thawer, 0); 1282 load_objects (m, thawer, 0);
1294 1283
1295 m->in_memory = MAP_IN_MEMORY; 1284 m->in_memory = MAP_IN_MEMORY;
1296} 1285}
1297
1298 1286
1299/* 1287/*
1300 * Saves a map to file. If flag is set, it is saved into the same 1288 * 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 1289 * file it was (originally) loaded from. Otherwise a temporary
1302 * filename will be genarated, and the file will be stored there. 1290 * filename will be genarated, and the file will be stored there.
1303 * The temporary filename will be stored in the maptileure. 1291 * The temporary filename will be stored in the maptileure.
1304 * If the map is unique, we also save to the filename in the map 1292 * If the map is unique, we also save to the filename in the map
1305 * (this should have been updated when first loaded) 1293 * (this should have been updated when first loaded)
1306 */ 1294 */
1307
1308int 1295int
1309new_save_map (maptile *m, int flag) 1296new_save_map (maptile *m, int flag)
1310{ 1297{
1311 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; 1298 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1312 int i; 1299 int i;
1453free_all_objects (maptile *m) 1440free_all_objects (maptile *m)
1454{ 1441{
1455 if (!m->spaces) 1442 if (!m->spaces)
1456 return; 1443 return;
1457 1444
1458 for (int i = 0; i < MAP_WIDTH (m); i++) 1445 for (int i = 0; i < m->width; i++)
1459 for (int j = 0; j < MAP_HEIGHT (m); j++) 1446 for (int j = 0; j < m->height; j++)
1460 { 1447 {
1461 mapspace &ms = m->at (i, j); 1448 mapspace &ms = m->at (i, j);
1462 1449
1463 while (object *op = ms.bottom) 1450 while (object *op = ms.bot)
1464 { 1451 {
1465 if (op->head) 1452 if (op->head)
1466 op = op->head; 1453 op = op->head;
1467 1454
1468 op->destroy_inv (false); 1455 op->destroy_inv (false);
1476 * don't free tmpname - our caller is left to do that 1463 * don't free tmpname - our caller is left to do that
1477 */ 1464 */
1478void 1465void
1479free_map (maptile *m, int flag) 1466free_map (maptile *m, int flag)
1480{ 1467{
1481 if (m->in_memory != MAP_IN_MEMORY) 1468 if (!m->in_memory) //TODO: makes no sense to me?
1482 return; 1469 return;
1483 1470
1484 m->in_memory = MAP_SAVING; 1471 m->in_memory = MAP_SAVING;
1485 1472
1486 // TODO: use new/delete 1473 // TODO: use new/delete
1487#define FREE_AND_CLEAR(p) { free (p); p = NULL; }
1488 1474
1489 if (flag && m->spaces) 1475 if (flag && m->spaces)
1490 free_all_objects (m); 1476 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 1477
1500 delete [] m->shopitems; 1478 sfree (m->spaces, m->size ()), m->spaces = 0;
1501 m->shopitems = 0;
1502 1479
1503 if (m->shoprace) 1480 free (m->name), m->name = 0;
1504 FREE_AND_CLEAR (m->shoprace); 1481 free (m->msg), m->msg = 0;
1482 free (m->maplore), m->maplore = 0;
1483 free (m->shoprace), m->shoprace = 0;
1484 delete [] m->shopitems, m->shopitems = 0;
1505 1485
1506 if (m->buttons) 1486 if (m->buttons)
1507 free_objectlinkpt (m->buttons); 1487 free_objectlinkpt (m->buttons), m->buttons = 0;
1508
1509 m->buttons = NULL;
1510 1488
1511 for (int i = 0; i < 4; i++) 1489 for (int i = 0; i < 4; i++)
1512 { 1490 free (m->tile_path[i]), m->tile_path[i] = 0;
1513 if (m->tile_path[i])
1514 FREE_AND_CLEAR (m->tile_path[i]);
1515
1516 m->tile_map[i] = 0;
1517 }
1518 1491
1519 m->in_memory = MAP_SWAPPED; 1492 m->in_memory = MAP_SWAPPED;
1520
1521#undef FREE_AND_CLEAR
1522} 1493}
1523 1494
1524maptile::~maptile () 1495maptile::~maptile ()
1525{ 1496{
1526 free_map (this, 1); 1497 assert (destroyed ());
1527 free (tmpname);
1528} 1498}
1529 1499
1530void 1500void
1531maptile::do_destroy () 1501maptile::do_destroy ()
1532{ 1502{
1533 attachable::do_destroy (); 1503 attachable::do_destroy ();
1534 1504
1535 free_all_objects (this); 1505 free_map (this, 1);
1506 free (tmpname), tmpname = 0;
1536 1507
1537 /* 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
1538 * are pointing at this one for tiling information. Since 1509 * are pointing at this one for tiling information. Since
1539 * 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
1540 * maps this map tiles with and clears those. 1511 * maps this map tiles with and clears those.
1541 */ 1512 */
1542 //TODO: non-euclidean-tiling MUST GO 1513 //TODO: non-euclidean-tiling MUST GO
1543 for (maptile *m = first_map; m; m = m->next) 1514 for_all_maps (m)
1544 for (int i = 0; i < 4; i++) 1515 for (int i = 0; i < 4; i++)
1545 if (m->tile_map[i] == this) 1516 if (m->tile_map[i] == this)
1546 m->tile_map[i] = 0; 1517 m->tile_map[i] = 0;
1547 1518
1548 if (first_map == this) 1519 if (first_map == this)
1549 first_map = next; 1520 first_map = next;
1550 else 1521 else
1551 for (maptile *m = first_map; m; m = m->next) 1522 for_all_maps (m)
1552 if (m->next = this) 1523 if (m->next = this)
1553 { 1524 {
1554 m->next = next; 1525 m->next = next;
1555 break; 1526 break;
1556 } 1527 }
1692 int x, y, i; 1663 int x, y, i;
1693 long monster_cnt = 0; 1664 long monster_cnt = 0;
1694 double avgexp = 0; 1665 double avgexp = 0;
1695 sint64 total_exp = 0; 1666 sint64 total_exp = 0;
1696 1667
1697 if (MAP_DIFFICULTY (m)) 1668 if (m->difficulty)
1698 { 1669 {
1699 LOG (llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY (m)); 1670 LOG (llevDebug, "Using stored map difficulty: %d\n", m->difficulty);
1700 return MAP_DIFFICULTY (m); 1671 return m->difficulty;
1701 } 1672 }
1702 1673
1703 for (x = 0; x < MAP_WIDTH (m); x++) 1674 for (x = 0; x < m->width; x++)
1704 for (y = 0; y < MAP_HEIGHT (m); y++) 1675 for (y = 0; y < m->height; y++)
1705 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) 1676 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above)
1706 { 1677 {
1707 if (QUERY_FLAG (op, FLAG_MONSTER)) 1678 if (QUERY_FLAG (op, FLAG_MONSTER))
1708 { 1679 {
1709 total_exp += op->stats.exp; 1680 total_exp += op->stats.exp;
1758 if (first_map->in_memory == MAP_SAVING) 1729 if (first_map->in_memory == MAP_SAVING)
1759 first_map->in_memory = MAP_IN_MEMORY; 1730 first_map->in_memory = MAP_IN_MEMORY;
1760 delete_map (first_map); 1731 delete_map (first_map);
1761 real_maps++; 1732 real_maps++;
1762 } 1733 }
1734
1763 LOG (llevDebug, "free_all_maps: Freed %d maps\n", real_maps); 1735 LOG (llevDebug, "free_all_maps: Freed %d maps\n", real_maps);
1764} 1736}
1765 1737
1766/* change_map_light() - used to change map light level (darkness) 1738/* change_map_light() - used to change map light level (darkness)
1767 * up or down. Returns true if successful. It should now be 1739 * up or down. Returns true if successful. It should now be
1826 1798
1827 middle_obj = 0; 1799 middle_obj = 0;
1828 top_obj = 0; 1800 top_obj = 0;
1829 floor_obj = 0; 1801 floor_obj = 0;
1830 1802
1831 for (tmp = bottom; tmp; last = tmp, tmp = tmp->above) 1803 for (tmp = bot; tmp; last = tmp, tmp = tmp->above)
1832 { 1804 {
1833 /* This could be made additive I guess (two lights better than 1805 /* This could be made additive I guess (two lights better than
1834 * one). But if so, it shouldn't be a simple additive - 2 1806 * one). But if so, it shouldn't be a simple additive - 2
1835 * light bulbs do not illuminate twice as far as once since 1807 * light bulbs do not illuminate twice as far as once since
1836 * it is a dissapation factor that is cubed. 1808 * it is a dissapation factor that is cubed.
1986void 1958void
1987set_map_reset_time (maptile *map) 1959set_map_reset_time (maptile *map)
1988{ 1960{
1989 int timeout; 1961 int timeout;
1990 1962
1991 timeout = MAP_RESET_TIMEOUT (map); 1963 timeout = map->reset_timeout;
1992 if (timeout <= 0) 1964 if (timeout <= 0)
1993 timeout = MAP_DEFAULTRESET; 1965 timeout = MAP_DEFAULTRESET;
1994 if (timeout >= MAP_MAXRESET) 1966 if (timeout >= MAP_MAXRESET)
1995 timeout = MAP_MAXRESET; 1967 timeout = MAP_MAXRESET;
1996 MAP_WHEN_RESET (map) = time (0) + timeout; 1968 map->reset_time = time (0) + timeout;
1997} 1969}
1998 1970
1999/* this updates the orig_map->tile_map[tile_num] value after loading 1971/* 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 1972 * 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 1973 * maps tile_map values if it tiles back to this one. It returns
2044 return 1; 2016 return 1;
2045 2017
2046 if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) 2018 if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY)
2047 load_and_link_tiled_map (m, 3); 2019 load_and_link_tiled_map (m, 3);
2048 2020
2049 return (out_of_map (m->tile_map[3], x + MAP_WIDTH (m->tile_map[3]), y)); 2021 return (out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y));
2050 } 2022 }
2051 2023
2052 if (x >= MAP_WIDTH (m)) 2024 if (x >= m->width)
2053 { 2025 {
2054 if (!m->tile_path[1]) 2026 if (!m->tile_path[1])
2055 return 1; 2027 return 1;
2056 2028
2057 if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) 2029 if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY)
2058 load_and_link_tiled_map (m, 1); 2030 load_and_link_tiled_map (m, 1);
2059 2031
2060 return (out_of_map (m->tile_map[1], x - MAP_WIDTH (m), y)); 2032 return (out_of_map (m->tile_map[1], x - m->width, y));
2061 } 2033 }
2062 2034
2063 if (y < 0) 2035 if (y < 0)
2064 { 2036 {
2065 if (!m->tile_path[0]) 2037 if (!m->tile_path[0])
2066 return 1; 2038 return 1;
2067 2039
2068 if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) 2040 if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY)
2069 load_and_link_tiled_map (m, 0); 2041 load_and_link_tiled_map (m, 0);
2070 2042
2071 return (out_of_map (m->tile_map[0], x, y + MAP_HEIGHT (m->tile_map[0]))); 2043 return (out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height));
2072 } 2044 }
2073 2045
2074 if (y >= MAP_HEIGHT (m)) 2046 if (y >= m->height)
2075 { 2047 {
2076 if (!m->tile_path[2]) 2048 if (!m->tile_path[2])
2077 return 1; 2049 return 1;
2078 2050
2079 if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) 2051 if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY)
2080 load_and_link_tiled_map (m, 2); 2052 load_and_link_tiled_map (m, 2);
2081 2053
2082 return (out_of_map (m->tile_map[2], x, y - MAP_HEIGHT (m))); 2054 return (out_of_map (m->tile_map[2], x, y - m->height));
2083 } 2055 }
2084 2056
2085 /* Simple case - coordinates are within this local 2057 /* Simple case - coordinates are within this local
2086 * map. 2058 * map.
2087 */ 2059 */
2105 if (!m->tile_path[3]) 2077 if (!m->tile_path[3])
2106 return 0; 2078 return 0;
2107 if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) 2079 if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY)
2108 load_and_link_tiled_map (m, 3); 2080 load_and_link_tiled_map (m, 3);
2109 2081
2110 *x += MAP_WIDTH (m->tile_map[3]); 2082 *x += m->tile_map[3]->width;
2111 return (get_map_from_coord (m->tile_map[3], x, y)); 2083 return (get_map_from_coord (m->tile_map[3], x, y));
2112 } 2084 }
2113 2085
2114 if (*x >= MAP_WIDTH (m)) 2086 if (*x >= m->width)
2115 { 2087 {
2116 if (!m->tile_path[1]) 2088 if (!m->tile_path[1])
2117 return 0; 2089 return 0;
2118 2090
2119 if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) 2091 if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY)
2120 load_and_link_tiled_map (m, 1); 2092 load_and_link_tiled_map (m, 1);
2121 2093
2122 *x -= MAP_WIDTH (m); 2094 *x -= m->width;
2123 return (get_map_from_coord (m->tile_map[1], x, y)); 2095 return (get_map_from_coord (m->tile_map[1], x, y));
2124 } 2096 }
2125 2097
2126 if (*y < 0) 2098 if (*y < 0)
2127 { 2099 {
2129 return 0; 2101 return 0;
2130 2102
2131 if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) 2103 if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY)
2132 load_and_link_tiled_map (m, 0); 2104 load_and_link_tiled_map (m, 0);
2133 2105
2134 *y += MAP_HEIGHT (m->tile_map[0]); 2106 *y += m->tile_map[0]->height;
2135 return (get_map_from_coord (m->tile_map[0], x, y)); 2107 return (get_map_from_coord (m->tile_map[0], x, y));
2136 } 2108 }
2137 2109
2138 if (*y >= MAP_HEIGHT (m)) 2110 if (*y >= m->height)
2139 { 2111 {
2140 if (!m->tile_path[2]) 2112 if (!m->tile_path[2])
2141 return 0; 2113 return 0;
2142 2114
2143 if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) 2115 if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY)
2144 load_and_link_tiled_map (m, 2); 2116 load_and_link_tiled_map (m, 2);
2145 2117
2146 *y -= MAP_HEIGHT (m); 2118 *y -= m->height;
2147 return (get_map_from_coord (m->tile_map[2], x, y)); 2119 return (get_map_from_coord (m->tile_map[2], x, y));
2148 } 2120 }
2149 2121
2150 /* Simple case - coordinates are within this local 2122 /* Simple case - coordinates are within this local
2151 * map. 2123 * map.
2171 2143
2172 } 2144 }
2173 else if (map1->tile_map[0] == map2) 2145 else if (map1->tile_map[0] == map2)
2174 { /* up */ 2146 { /* up */
2175 *dx = 0; 2147 *dx = 0;
2176 *dy = -MAP_HEIGHT (map2); 2148 *dy = -map2->height;
2177 } 2149 }
2178 else if (map1->tile_map[1] == map2) 2150 else if (map1->tile_map[1] == map2)
2179 { /* right */ 2151 { /* right */
2180 *dx = MAP_WIDTH (map1); 2152 *dx = map1->width;
2181 *dy = 0; 2153 *dy = 0;
2182 } 2154 }
2183 else if (map1->tile_map[2] == map2) 2155 else if (map1->tile_map[2] == map2)
2184 { /* down */ 2156 { /* down */
2185 *dx = 0; 2157 *dx = 0;
2186 *dy = MAP_HEIGHT (map1); 2158 *dy = map1->height;
2187 } 2159 }
2188 else if (map1->tile_map[3] == map2) 2160 else if (map1->tile_map[3] == map2)
2189 { /* left */ 2161 { /* left */
2190 *dx = -MAP_WIDTH (map2); 2162 *dx = -map2->width;
2191 *dy = 0; 2163 *dy = 0;
2192 2164
2193 } 2165 }
2194 else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2) 2166 else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[1] == map2)
2195 { /* up right */ 2167 { /* up right */
2196 *dx = MAP_WIDTH (map1->tile_map[0]); 2168 *dx = map1->tile_map[0]->width;
2197 *dy = -MAP_HEIGHT (map1->tile_map[0]); 2169 *dy = -map1->tile_map[0]->height;
2198 } 2170 }
2199 else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2) 2171 else if (map1->tile_map[0] && map1->tile_map[0]->tile_map[3] == map2)
2200 { /* up left */ 2172 { /* up left */
2201 *dx = -MAP_WIDTH (map2); 2173 *dx = -map2->width;
2202 *dy = -MAP_HEIGHT (map1->tile_map[0]); 2174 *dy = -map1->tile_map[0]->height;
2203 } 2175 }
2204 else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2) 2176 else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[0] == map2)
2205 { /* right up */ 2177 { /* right up */
2206 *dx = MAP_WIDTH (map1); 2178 *dx = map1->width;
2207 *dy = -MAP_HEIGHT (map2); 2179 *dy = -map2->height;
2208 } 2180 }
2209 else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2) 2181 else if (map1->tile_map[1] && map1->tile_map[1]->tile_map[2] == map2)
2210 { /* right down */ 2182 { /* right down */
2211 *dx = MAP_WIDTH (map1); 2183 *dx = map1->width;
2212 *dy = MAP_HEIGHT (map1->tile_map[1]); 2184 *dy = map1->tile_map[1]->height;
2213 } 2185 }
2214 else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2) 2186 else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[1] == map2)
2215 { /* down right */ 2187 { /* down right */
2216 *dx = MAP_WIDTH (map1->tile_map[2]); 2188 *dx = map1->tile_map[2]->width;
2217 *dy = MAP_HEIGHT (map1); 2189 *dy = map1->height;
2218 } 2190 }
2219 else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2) 2191 else if (map1->tile_map[2] && map1->tile_map[2]->tile_map[3] == map2)
2220 { /* down left */ 2192 { /* down left */
2221 *dx = -MAP_WIDTH (map2); 2193 *dx = -map2->width;
2222 *dy = MAP_HEIGHT (map1); 2194 *dy = map1->height;
2223 } 2195 }
2224 else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2) 2196 else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[0] == map2)
2225 { /* left up */ 2197 { /* left up */
2226 *dx = -MAP_WIDTH (map1->tile_map[3]); 2198 *dx = -map1->tile_map[3]->width;
2227 *dy = -MAP_HEIGHT (map2); 2199 *dy = -map2->height;
2228 } 2200 }
2229 else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2) 2201 else if (map1->tile_map[3] && map1->tile_map[3]->tile_map[2] == map2)
2230 { /* left down */ 2202 { /* left down */
2231 *dx = -MAP_WIDTH (map1->tile_map[3]); 2203 *dx = -map1->tile_map[3]->width;
2232 *dy = MAP_HEIGHT (map1->tile_map[3]); 2204 *dy = map1->tile_map[3]->height;
2233 2205
2234 } 2206 }
2235 else 2207 else
2236 { /* not "adjacent" enough */ 2208 { /* not "adjacent" enough */
2237 return 0; 2209 return 0;
2362{ 2334{
2363 int dx, dy; 2335 int dx, dy;
2364 2336
2365 return adjacent_map (op1->map, op2->map, &dx, &dy); 2337 return adjacent_map (op1->map, op2->map, &dx, &dy);
2366} 2338}
2339
2340object *
2341maptile::insert (object *op, int x, int y, object *originator, int flags)
2342{
2343 if (!op->flag [FLAG_REMOVED])
2344 op->remove ();
2345
2346 return insert_ob_in_map_at (op, this, originator, flags, x, y);
2347}
2348

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines