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.48 by root, Mon Dec 25 14:43:22 2006 UTC vs.
Revision 1.51 by root, Mon Dec 25 17:11:16 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; 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
197void 198void
198dump_map (const maptile *m) 199dump_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", m->width, m->height, 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)
600 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 601 * 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 602 * and we only save the head of multi part objects - this is needed
602 * in order to do map tiling properly. 603 * in order to do map tiling properly.
603 */ 604 */
604void 605void
605save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag) 606save_objects (maptile *m, object_freezer &fp, object_freezer &fp2, int flag)
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 < m->width; i++) 612 for (i = 0; i < m->width; i++)
612 for (j = 0; j < m->height; j++) 613 for (j = 0; j < m->height; j++)
613 { 614 {
614 unique = 0; 615 unique = 0;
616
615 for (op = m->at (i, j).bottom; op; op = op->above) 617 for (op = m->at (i, j).bot; op; op = op->above)
616 { 618 {
617 if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE]) 619 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
618 unique = 1; 620 unique = 1;
619 621
620 if (op->type == PLAYER) 622 if (op->type == PLAYER)
621 continue; 623 continue;
622 624
623 if (op->head || op->owner) 625 if (op->head || op->owner)
624 continue; 626 continue;
625 627
626 if (unique || op->flag [FLAG_UNIQUE]) 628 if (unique || op->flag [FLAG_UNIQUE])
627 save_object (fp2, op, 3); 629 save_object (fp2, op, 1);
628 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID]))) 630 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID])))
629 save_object (fp, op, 3); 631 save_object (fp, op, 1);
630 } 632 }
631 } 633 }
632} 634}
633 635
634maptile::maptile () 636maptile::maptile ()
637 /* The maps used to pick up default x and y values from the 639 /* The maps used to pick up default x and y values from the
638 * map archetype. Mimic that behaviour. 640 * map archetype. Mimic that behaviour.
639 */ 641 */
640 this->width = 16; 642 this->width = 16;
641 this->height = 16; 643 this->height = 16;
642 MAP_RESET_TIMEOUT (this) = 0; 644 this->reset_timeout = 0;
643 MAP_TIMEOUT (this) = 300; 645 this->timeout = 300;
644 MAP_ENTER_X (this) = 0; 646 this->enter_x = 0;
645 MAP_ENTER_Y (this) = 0; 647 this->enter_y = 0;
646 /*set part to -1 indicating conversion to weather map not yet done */ 648 /*set part to -1 indicating conversion to weather map not yet done */
647 MAP_WORLDPARTX (this) = -1; 649 this->worldpartx = -1;
648 MAP_WORLDPARTY (this) = -1; 650 this->worldparty = -1;
649} 651}
650 652
651/* 653/*
652 * Allocates, initialises, and returns a pointer to a maptile. 654 * Allocates, initialises, and returns a pointer to a maptile.
653 * Modified to no longer take a path option which was not being 655 * Modified to no longer take a path option which was not being
1132 1134
1133 m->in_memory = MAP_LOADING; 1135 m->in_memory = MAP_LOADING;
1134 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1136 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1135 1137
1136 m->in_memory = MAP_IN_MEMORY; 1138 m->in_memory = MAP_IN_MEMORY;
1137 if (!MAP_DIFFICULTY (m)) 1139 if (!m->difficulty)
1138 MAP_DIFFICULTY (m) = calculate_difficulty (m); 1140 m->difficulty = calculate_difficulty (m);
1139 set_map_reset_time (m); 1141 set_map_reset_time (m);
1140 m->instantiate (); 1142 m->instantiate ();
1141 return (m); 1143 return (m);
1142} 1144}
1143 1145
1288 return; 1290 return;
1289 1291
1290 m->in_memory = MAP_LOADING; 1292 m->in_memory = MAP_LOADING;
1291 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1293 if (m->tmpname == NULL) /* if we have loaded unique items from */
1292 delete_unique_items (m); /* original map before, don't duplicate them */ 1294 delete_unique_items (m); /* original map before, don't duplicate them */
1295
1293 load_objects (m, thawer, 0); 1296 load_objects (m, thawer, 0);
1294 1297
1295 m->in_memory = MAP_IN_MEMORY; 1298 m->in_memory = MAP_IN_MEMORY;
1296} 1299}
1297
1298 1300
1299/* 1301/*
1300 * Saves a map to file. If flag is set, it is saved into the same 1302 * 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 1303 * file it was (originally) loaded from. Otherwise a temporary
1302 * filename will be genarated, and the file will be stored there. 1304 * filename will be genarated, and the file will be stored there.
1303 * The temporary filename will be stored in the maptileure. 1305 * The temporary filename will be stored in the maptileure.
1304 * If the map is unique, we also save to the filename in the map 1306 * If the map is unique, we also save to the filename in the map
1305 * (this should have been updated when first loaded) 1307 * (this should have been updated when first loaded)
1306 */ 1308 */
1307
1308int 1309int
1309new_save_map (maptile *m, int flag) 1310new_save_map (maptile *m, int flag)
1310{ 1311{
1311 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; 1312 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1312 int i; 1313 int i;
1458 for (int i = 0; i < m->width; i++) 1459 for (int i = 0; i < m->width; i++)
1459 for (int j = 0; j < m->height; j++) 1460 for (int j = 0; j < m->height; j++)
1460 { 1461 {
1461 mapspace &ms = m->at (i, j); 1462 mapspace &ms = m->at (i, j);
1462 1463
1463 while (object *op = ms.bottom) 1464 while (object *op = ms.bot)
1464 { 1465 {
1465 if (op->head) 1466 if (op->head)
1466 op = op->head; 1467 op = op->head;
1467 1468
1468 op->destroy_inv (false); 1469 op->destroy_inv (false);
1476 * don't free tmpname - our caller is left to do that 1477 * don't free tmpname - our caller is left to do that
1477 */ 1478 */
1478void 1479void
1479free_map (maptile *m, int flag) 1480free_map (maptile *m, int flag)
1480{ 1481{
1481 if (m->in_memory != MAP_IN_MEMORY) 1482 if (!m->in_memory) //TODO: makes no sense to me?
1482 return; 1483 return;
1483 1484
1484 m->in_memory = MAP_SAVING; 1485 m->in_memory = MAP_SAVING;
1485 1486
1486 // TODO: use new/delete 1487 // TODO: use new/delete
1487#define FREE_AND_CLEAR(p) { free (p); p = NULL; }
1488 1488
1489 if (flag && m->spaces) 1489 if (flag && m->spaces)
1490 free_all_objects (m); 1490 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 1491
1500 delete [] m->shopitems; 1492 free (m->name), m->name = 0;
1501 m->shopitems = 0; 1493 free (m->spaces), m->spaces = 0;
1502 1494 free (m->msg), m->msg = 0;
1503 if (m->shoprace) 1495 free (m->maplore), m->maplore = 0;
1504 FREE_AND_CLEAR (m->shoprace); 1496 free (m->shoprace), m->shoprace = 0;
1497 delete [] m->shopitems, m->shopitems = 0;
1505 1498
1506 if (m->buttons) 1499 if (m->buttons)
1507 free_objectlinkpt (m->buttons); 1500 free_objectlinkpt (m->buttons), m->buttons = 0;
1508
1509 m->buttons = NULL;
1510 1501
1511 for (int i = 0; i < 4; i++) 1502 for (int i = 0; i < 4; i++)
1512 { 1503 {
1513 if (m->tile_path[i]) 1504 if (m->tile_path[i])
1514 FREE_AND_CLEAR (m->tile_path[i]); 1505 free (m->tile_path[i]), m->tile_path[i] = 0;
1515 1506
1516 m->tile_map[i] = 0; 1507 m->tile_map[i] = 0;
1517 } 1508 }
1518 1509
1519 m->in_memory = MAP_SWAPPED; 1510 m->in_memory = MAP_SWAPPED;
1520
1521#undef FREE_AND_CLEAR
1522} 1511}
1523 1512
1524maptile::~maptile () 1513maptile::~maptile ()
1525{ 1514{
1526 free_map (this, 1); 1515 free_map (this, 1);
1692 int x, y, i; 1681 int x, y, i;
1693 long monster_cnt = 0; 1682 long monster_cnt = 0;
1694 double avgexp = 0; 1683 double avgexp = 0;
1695 sint64 total_exp = 0; 1684 sint64 total_exp = 0;
1696 1685
1697 if (MAP_DIFFICULTY (m)) 1686 if (m->difficulty)
1698 { 1687 {
1699 LOG (llevDebug, "Using stored map difficulty: %d\n", MAP_DIFFICULTY (m)); 1688 LOG (llevDebug, "Using stored map difficulty: %d\n", m->difficulty);
1700 return MAP_DIFFICULTY (m); 1689 return m->difficulty;
1701 } 1690 }
1702 1691
1703 for (x = 0; x < m->width; x++) 1692 for (x = 0; x < m->width; x++)
1704 for (y = 0; y < m->height; y++) 1693 for (y = 0; y < m->height; y++)
1705 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) 1694 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above)
1826 1815
1827 middle_obj = 0; 1816 middle_obj = 0;
1828 top_obj = 0; 1817 top_obj = 0;
1829 floor_obj = 0; 1818 floor_obj = 0;
1830 1819
1831 for (tmp = bottom; tmp; last = tmp, tmp = tmp->above) 1820 for (tmp = bot; tmp; last = tmp, tmp = tmp->above)
1832 { 1821 {
1833 /* This could be made additive I guess (two lights better than 1822 /* This could be made additive I guess (two lights better than
1834 * one). But if so, it shouldn't be a simple additive - 2 1823 * one). But if so, it shouldn't be a simple additive - 2
1835 * light bulbs do not illuminate twice as far as once since 1824 * light bulbs do not illuminate twice as far as once since
1836 * it is a dissapation factor that is cubed. 1825 * it is a dissapation factor that is cubed.
1986void 1975void
1987set_map_reset_time (maptile *map) 1976set_map_reset_time (maptile *map)
1988{ 1977{
1989 int timeout; 1978 int timeout;
1990 1979
1991 timeout = MAP_RESET_TIMEOUT (map); 1980 timeout = map->reset_timeout;
1992 if (timeout <= 0) 1981 if (timeout <= 0)
1993 timeout = MAP_DEFAULTRESET; 1982 timeout = MAP_DEFAULTRESET;
1994 if (timeout >= MAP_MAXRESET) 1983 if (timeout >= MAP_MAXRESET)
1995 timeout = MAP_MAXRESET; 1984 timeout = MAP_MAXRESET;
1996 MAP_WHEN_RESET (map) = time (0) + timeout; 1985 map->reset_time = time (0) + timeout;
1997} 1986}
1998 1987
1999/* this updates the orig_map->tile_map[tile_num] value after loading 1988/* 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 1989 * 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 1990 * maps tile_map values if it tiles back to this one. It returns

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines