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.50 by root, Mon Dec 25 15:28:35 2006 UTC vs.
Revision 1.53 by root, Wed Dec 27 09:28:01 2006 UTC

35 * return NULL if no match is found. 35 * return NULL if no match is found.
36 */ 36 */
37maptile * 37maptile *
38has_been_loaded (const char *name) 38has_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
223void 221void
224dump_all_maps (void) 222dump_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
482static void 477static void
483link_multipart_objects (maptile *m) 478link_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;
601 * 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,
602 * 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
603 * in order to do map tiling properly. 598 * in order to do map tiling properly.
604 */ 599 */
605void 600void
606save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag) 601save_objects (maptile *m, object_freezer &fp, object_freezer &fp2, int flag)
607{ 602{
608 int i, j = 0, unique = 0; 603 int i, j = 0, unique = 0;
609 object *op; 604 object *op;
610 605
611 /* first pass - save one-part objects */ 606 /* first pass - save one-part objects */
612 for (i = 0; i < m->width; i++) 607 for (i = 0; i < m->width; i++)
613 for (j = 0; j < m->height; j++) 608 for (j = 0; j < m->height; j++)
614 { 609 {
615 unique = 0; 610 unique = 0;
611
616 for (op = m->at (i, j).bot; op; op = op->above) 612 for (op = m->at (i, j).bot; op; op = op->above)
617 { 613 {
618 if (op->flag [FLAG_IS_FLOOR] && op->flag [FLAG_UNIQUE]) 614 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
619 unique = 1; 615 unique = 1;
620 616
621 if (op->type == PLAYER) 617 if (op->type == PLAYER)
622 continue; 618 continue;
623 619
624 if (op->head || op->owner) 620 if (op->head || op->owner)
625 continue; 621 continue;
626 622
627 if (unique || op->flag [FLAG_UNIQUE]) 623 if (unique || op->flag [FLAG_UNIQUE])
628 save_object (fp2, op, 3); 624 save_object (fp2, op, 1);
629 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID]))) 625 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID])))
630 save_object (fp, op, 3); 626 save_object (fp, op, 1);
631 } 627 }
632 } 628 }
633} 629}
634 630
635maptile::maptile () 631maptile::maptile ()
636{ 632{
637 in_memory = MAP_SWAPPED; 633 in_memory = MAP_SWAPPED;
638 /* 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
639 * map archetype. Mimic that behaviour. 635 * map archetype. Mimic that behaviour.
640 */ 636 */
641 this->width = 16; 637 width = 16;
642 this->height = 16; 638 height = 16;
643 this->reset_timeout = 0; 639 reset_timeout = 0;
644 this->timeout = 300; 640 timeout = 300;
645 this->enter_x = 0; 641 enter_x = 0;
646 this->enter_y = 0; 642 enter_y = 0;
647 /*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 */
648 this->worldpartx = -1; 644 worldpartx = -1;
649 this->worldparty = -1; 645 worldparty = -1;
650} 646}
651 647
652/* 648/*
653 * Allocates, initialises, and returns a pointer to a maptile. 649 * Allocates, initialises, and returns a pointer to a maptile.
654 * 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
655 * used anyways. MSW 2001-07-01 651 * used anyways. MSW 2001-07-01
656 */ 652 */
657maptile * 653maptile *
658get_linked_map (void) 654get_linked_map (void)
659{ 655{
660 maptile *mp, *map = new maptile; 656 maptile *map = new maptile;
661 657
662 for (mp = first_map; mp && mp->next; mp = mp->next); 658 map->next = first_map;
663
664 if (mp == NULL)
665 first_map = map; 659 first_map = map;
666 else
667 mp->next = map;
668 660
669 return map; 661 return map;
670} 662}
671 663
672/* 664/*
684 * that is their poor assumption. 676 * that is their poor assumption.
685 */ 677 */
686 if (spaces) 678 if (spaces)
687 { 679 {
688 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);
689 free (spaces); 681 sfree (spaces, size ());
690 } 682 }
691 683
692 spaces = (mapspace *) 684 spaces = salloc0<mapspace> (size ());
693 calloc (1, width * height * sizeof (mapspace));
694
695 if (!spaces)
696 fatal (OUT_OF_MEMORY);
697} 685}
698 686
699/* Create and returns a map of the specific size. Used 687/* Create and returns a map of the specific size. Used
700 * in random map code and the editor. 688 * in random map code and the editor.
701 */ 689 */
1259 op->destroy (); 1247 op->destroy ();
1260 } 1248 }
1261 } 1249 }
1262 } 1250 }
1263} 1251}
1264
1265 1252
1266/* 1253/*
1267 * 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
1268 * m is the map to load unique items into. 1255 * m is the map to load unique items into.
1269 */ 1256 */
1486 // TODO: use new/delete 1473 // TODO: use new/delete
1487 1474
1488 if (flag && m->spaces) 1475 if (flag && m->spaces)
1489 free_all_objects (m); 1476 free_all_objects (m);
1490 1477
1478 sfree (m->spaces, m->size ()), m->spaces = 0;
1479
1491 free (m->name), m->name = 0; 1480 free (m->name), m->name = 0;
1492 free (m->spaces), m->spaces = 0;
1493 free (m->msg), m->msg = 0; 1481 free (m->msg), m->msg = 0;
1494 free (m->maplore), m->maplore = 0; 1482 free (m->maplore), m->maplore = 0;
1495 free (m->shoprace), m->shoprace = 0; 1483 free (m->shoprace), m->shoprace = 0;
1496 delete [] m->shopitems, m->shopitems = 0; 1484 delete [] m->shopitems, m->shopitems = 0;
1497 1485
1498 if (m->buttons) 1486 if (m->buttons)
1499 free_objectlinkpt (m->buttons), m->buttons = 0; 1487 free_objectlinkpt (m->buttons), m->buttons = 0;
1500 1488
1501 for (int i = 0; i < 4; i++) 1489 for (int i = 0; i < 4; i++)
1502 {
1503 if (m->tile_path[i])
1504 free (m->tile_path[i]), m->tile_path[i] = 0; 1490 free (m->tile_path[i]), m->tile_path[i] = 0;
1505
1506 m->tile_map[i] = 0;
1507 }
1508 1491
1509 m->in_memory = MAP_SWAPPED; 1492 m->in_memory = MAP_SWAPPED;
1510} 1493}
1511 1494
1512maptile::~maptile () 1495maptile::~maptile ()
1513{ 1496{
1514 free_map (this, 1); 1497 assert (destroyed ());
1515 free (tmpname);
1516} 1498}
1517 1499
1518void 1500void
1519maptile::do_destroy () 1501maptile::do_destroy ()
1520{ 1502{
1521 attachable::do_destroy (); 1503 attachable::do_destroy ();
1522 1504
1523 free_all_objects (this); 1505 free_map (this, 1);
1506 free (tmpname), tmpname = 0;
1524 1507
1525 /* 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
1526 * are pointing at this one for tiling information. Since 1509 * are pointing at this one for tiling information. Since
1527 * 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
1528 * maps this map tiles with and clears those. 1511 * maps this map tiles with and clears those.
1529 */ 1512 */
1530 //TODO: non-euclidean-tiling MUST GO 1513 //TODO: non-euclidean-tiling MUST GO
1531 for (maptile *m = first_map; m; m = m->next) 1514 for_all_maps (m)
1532 for (int i = 0; i < 4; i++) 1515 for (int i = 0; i < 4; i++)
1533 if (m->tile_map[i] == this) 1516 if (m->tile_map[i] == this)
1534 m->tile_map[i] = 0; 1517 m->tile_map[i] = 0;
1535 1518
1536 if (first_map == this) 1519 if (first_map == this)
1537 first_map = next; 1520 first_map = next;
1538 else 1521 else
1539 for (maptile *m = first_map; m; m = m->next) 1522 for_all_maps (m)
1540 if (m->next = this) 1523 if (m->next = this)
1541 { 1524 {
1542 m->next = next; 1525 m->next = next;
1543 break; 1526 break;
1544 } 1527 }
1746 if (first_map->in_memory == MAP_SAVING) 1729 if (first_map->in_memory == MAP_SAVING)
1747 first_map->in_memory = MAP_IN_MEMORY; 1730 first_map->in_memory = MAP_IN_MEMORY;
1748 delete_map (first_map); 1731 delete_map (first_map);
1749 real_maps++; 1732 real_maps++;
1750 } 1733 }
1734
1751 LOG (llevDebug, "free_all_maps: Freed %d maps\n", real_maps); 1735 LOG (llevDebug, "free_all_maps: Freed %d maps\n", real_maps);
1752} 1736}
1753 1737
1754/* change_map_light() - used to change map light level (darkness) 1738/* change_map_light() - used to change map light level (darkness)
1755 * up or down. Returns true if successful. It should now be 1739 * up or down. Returns true if successful. It should now be
2350{ 2334{
2351 int dx, dy; 2335 int dx, dy;
2352 2336
2353 return adjacent_map (op1->map, op2->map, &dx, &dy); 2337 return adjacent_map (op1->map, op2->map, &dx, &dy);
2354} 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