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.53 by root, Wed Dec 27 09:28:01 2006 UTC vs.
Revision 1.55 by root, Wed Dec 27 18:09:48 2006 UTC

18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 20
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22*/
23
24 23
25#include <global.h> 24#include <global.h>
26#include <funcpoint.h> 25#include <funcpoint.h>
27 26
28#include <loader.h> 27#include <loader.h>
612 for (op = m->at (i, j).bot; op; op = op->above) 611 for (op = m->at (i, j).bot; op; op = op->above)
613 { 612 {
614 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) 613 if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR])
615 unique = 1; 614 unique = 1;
616 615
617 if (op->type == PLAYER) 616 if (!op->can_map_save ())
618 continue;
619
620 if (op->head || op->owner)
621 continue; 617 continue;
622 618
623 if (unique || op->flag [FLAG_UNIQUE]) 619 if (unique || op->flag [FLAG_UNIQUE])
624 save_object (fp2, op, 1); 620 save_object (fp2, op, 1);
625 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID]))) 621 else if (flag == 0 || (flag == 2 && (!op->flag [FLAG_OBJ_ORIGINAL] && !op->flag [FLAG_UNPAID])))
629} 625}
630 626
631maptile::maptile () 627maptile::maptile ()
632{ 628{
633 in_memory = MAP_SWAPPED; 629 in_memory = MAP_SWAPPED;
630
634 /* The maps used to pick up default x and y values from the 631 /* The maps used to pick up default x and y values from the
635 * map archetype. Mimic that behaviour. 632 * map archetype. Mimic that behaviour.
636 */ 633 */
637 width = 16; 634 width = 16;
638 height = 16; 635 height = 16;
643 /*set part to -1 indicating conversion to weather map not yet done */ 640 /*set part to -1 indicating conversion to weather map not yet done */
644 worldpartx = -1; 641 worldpartx = -1;
645 worldparty = -1; 642 worldparty = -1;
646} 643}
647 644
645void
646maptile::link ()
647{
648 next = first_map;
649 first_map = this;
650}
651
652void
653maptile::unlink ()
654{
655 if (first_map == this)
656 first_map = next;
657 else
658 {
659 for_all_maps (m)
660 if (m->next = this)
661 {
662 m->next = next;
663 return;
664 }
665
666 LOG (llevError, "maptile::unlink() map not on list: %s\n", path);
667 }
668}
669
648/* 670/*
649 * Allocates, initialises, and returns a pointer to a maptile. 671 * Allocates, initialises, and returns a pointer to a maptile.
650 * Modified to no longer take a path option which was not being 672 * Modified to no longer take a path option which was not being
651 * used anyways. MSW 2001-07-01 673 * used anyways. MSW 2001-07-01
652 */ 674 */
653maptile * 675maptile *
654get_linked_map (void) 676get_linked_map (void)
655{ 677{
656 maptile *map = new maptile; 678 maptile *map = new maptile;
657 679 map->link ();
658 map->next = first_map;
659 first_map = map;
660
661 return map; 680 return map;
662} 681}
663 682
664/* 683/*
665 * Allocates the arrays contained in a maptile. 684 * Allocates the arrays contained in a maptile.
690maptile * 709maptile *
691get_empty_map (int sizex, int sizey) 710get_empty_map (int sizex, int sizey)
692{ 711{
693 maptile *m = get_linked_map (); 712 maptile *m = get_linked_map ();
694 713
695 m->width = sizex; 714 m->width = sizex;
696 m->height = sizey; 715 m->height = sizey;
697 m->in_memory = MAP_SWAPPED; 716 m->in_memory = MAP_SWAPPED;
717
698 m->allocate (); 718 m->allocate ();
699 719
700 return m; 720 return m;
701} 721}
702 722
703/* Takes a string from a map definition and outputs a pointer to the array of shopitems 723/* Takes a string from a map definition and outputs a pointer to the array of shopitems
704 * corresponding to that string. Memory is allocated for this, it must be freed 724 * corresponding to that string. Memory is allocated for this, it must be freed
705 * at a later date. 725 * at a later date.
706 * Called by parse_map_headers below. 726 * Called by parse_map_headers below.
707 */ 727 */
708
709static shopitems * 728static shopitems *
710parse_shop_string (const char *input_string) 729parse_shop_string (const char *input_string)
711{ 730{
712 char *shop_string, *p, *q, *next_semicolon, *next_colon; 731 char *shop_string, *p, *q, *next_semicolon, *next_colon;
713 shopitems *items = NULL; 732 shopitems *items = NULL;
722 p = strchr (p, ';'); 741 p = strchr (p, ';');
723 number_of_entries++; 742 number_of_entries++;
724 if (p) 743 if (p)
725 p++; 744 p++;
726 } 745 }
746
727 p = shop_string; 747 p = shop_string;
728 strip_endline (p); 748 strip_endline (p);
729 items = new shopitems[number_of_entries + 1]; 749 items = new shopitems[number_of_entries + 1];
730 for (i = 0; i < number_of_entries; i++) 750 for (i = 0; i < number_of_entries; i++)
731 { 751 {
732 if (!p) 752 if (!p)
733 { 753 {
734 LOG (llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n"); 754 LOG (llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
735 break; 755 break;
736 } 756 }
757
737 next_semicolon = strchr (p, ';'); 758 next_semicolon = strchr (p, ';');
738 next_colon = strchr (p, ':'); 759 next_colon = strchr (p, ':');
739 /* if there is a stregth specified, figure out what it is, we'll need it soon. */ 760 /* if there is a stregth specified, figure out what it is, we'll need it soon. */
740 if (next_colon && (!next_semicolon || next_colon < next_semicolon)) 761 if (next_colon && (!next_semicolon || next_colon < next_semicolon))
741 items[i].strength = atoi (strchr (p, ':') + 1); 762 items[i].strength = atoi (strchr (p, ':') + 1);
768 * the next entry while we're at it, better print a warning 789 * the next entry while we're at it, better print a warning
769 */ 790 */
770 LOG (llevError, "invalid type %s defined in shopitems in string %s\n", p, input_string); 791 LOG (llevError, "invalid type %s defined in shopitems in string %s\n", p, input_string);
771 } 792 }
772 } 793 }
794
773 items[i].index = number_of_entries; 795 items[i].index = number_of_entries;
774 if (next_semicolon) 796 if (next_semicolon)
775 p = ++next_semicolon; 797 p = ++next_semicolon;
776 else 798 else
777 p = NULL; 799 p = NULL;
778 } 800 }
801
779 free (shop_string); 802 free (shop_string);
780 return items; 803 return items;
781} 804}
782 805
783/* opposite of parse string, this puts the string that was originally fed in to 806/* opposite of parse string, this puts the string that was originally fed in to
792 for (i = 0; i < m->shopitems[0].index; i++) 815 for (i = 0; i < m->shopitems[0].index; i++)
793 { 816 {
794 if (m->shopitems[i].typenum) 817 if (m->shopitems[i].typenum)
795 { 818 {
796 if (m->shopitems[i].strength) 819 if (m->shopitems[i].strength)
797 {
798 sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength); 820 sprintf (tmp, "%s:%d;", m->shopitems[i].name, m->shopitems[i].strength);
799 }
800 else 821 else
801 sprintf (tmp, "%s;", m->shopitems[i].name); 822 sprintf (tmp, "%s;", m->shopitems[i].name);
802 } 823 }
803 else 824 else
804 { 825 {
805 if (m->shopitems[i].strength) 826 if (m->shopitems[i].strength)
806 {
807 sprintf (tmp, "*:%d;", m->shopitems[i].strength); 827 sprintf (tmp, "*:%d;", m->shopitems[i].strength);
808 }
809 else 828 else
810 sprintf (tmp, "*"); 829 sprintf (tmp, "*");
811 } 830 }
831
812 strcat (output_string, tmp); 832 strcat (output_string, tmp);
813 } 833 }
814} 834}
815 835
816/* This loads the header information of the map. The header 836/* This loads the header information of the map. The header
1084 * MAP_BLOCK, in which case we block on this load. This happens in all 1104 * MAP_BLOCK, in which case we block on this load. This happens in all
1085 * cases, no matter if this flag is set or not. 1105 * cases, no matter if this flag is set or not.
1086 * MAP_STYLE: style map - don't add active objects, don't add to server 1106 * MAP_STYLE: style map - don't add active objects, don't add to server
1087 * managed map list. 1107 * managed map list.
1088 */ 1108 */
1089
1090maptile * 1109maptile *
1091load_original_map (const char *filename, int flags) 1110load_original_map (const char *filename, int flags)
1092{ 1111{
1093 maptile *m; 1112 maptile *m;
1094 char pathname[MAX_BUF]; 1113 char pathname[MAX_BUF];
1133/* 1152/*
1134 * Loads a map, which has been loaded earlier, from file. 1153 * Loads a map, which has been loaded earlier, from file.
1135 * Return the map object we load into (this can change from the passed 1154 * Return the map object we load into (this can change from the passed
1136 * option if we can't find the original map) 1155 * option if we can't find the original map)
1137 */ 1156 */
1138
1139static maptile * 1157static maptile *
1140load_temporary_map (maptile *m) 1158load_temporary_map (maptile *m)
1141{ 1159{
1142 char buf[MAX_BUF]; 1160 char buf[MAX_BUF];
1143 1161
1187/* 1205/*
1188 * Loads a map, which has been loaded earlier, from file. 1206 * Loads a map, which has been loaded earlier, from file.
1189 * Return the map object we load into (this can change from the passed 1207 * Return the map object we load into (this can change from the passed
1190 * option if we can't find the original map) 1208 * option if we can't find the original map)
1191 */ 1209 */
1192
1193maptile * 1210maptile *
1194load_overlay_map (const char *filename, maptile *m) 1211load_overlay_map (const char *filename, maptile *m)
1195{ 1212{
1196 char pathname[MAX_BUF]; 1213 char pathname[MAX_BUF];
1197 1214
1500void 1517void
1501maptile::do_destroy () 1518maptile::do_destroy ()
1502{ 1519{
1503 attachable::do_destroy (); 1520 attachable::do_destroy ();
1504 1521
1522 unlink ();
1523
1505 free_map (this, 1); 1524 free_map (this, 1);
1506 free (tmpname), tmpname = 0; 1525 free (tmpname), tmpname = 0;
1507 1526
1508 /* We need to look through all the maps and see if any maps 1527 /* We need to look through all the maps and see if any maps
1509 * are pointing at this one for tiling information. Since 1528 * are pointing at this one for tiling information. Since
1513 //TODO: non-euclidean-tiling MUST GO 1532 //TODO: non-euclidean-tiling MUST GO
1514 for_all_maps (m) 1533 for_all_maps (m)
1515 for (int i = 0; i < 4; i++) 1534 for (int i = 0; i < 4; i++)
1516 if (m->tile_map[i] == this) 1535 if (m->tile_map[i] == this)
1517 m->tile_map[i] = 0; 1536 m->tile_map[i] = 0;
1518
1519 if (first_map == this)
1520 first_map = next;
1521 else
1522 for_all_maps (m)
1523 if (m->next = this)
1524 {
1525 m->next = next;
1526 break;
1527 }
1528} 1537}
1529 1538
1530//TODO: must go 1539//TODO: must go
1531void 1540void
1532delete_map (maptile *m) 1541delete_map (maptile *m)
1580 if (flags & MAP_PLAYER_UNIQUE) 1589 if (flags & MAP_PLAYER_UNIQUE)
1581 LOG (llevDebug, "Trying to load map %s.\n", name); 1590 LOG (llevDebug, "Trying to load map %s.\n", name);
1582 else 1591 else
1583 LOG (llevDebug, "Trying to load map %s.\n", create_pathname (name)); 1592 LOG (llevDebug, "Trying to load map %s.\n", create_pathname (name));
1584 1593
1585 //eval_pv ("$x = Event::time", 1);//D
1586 if (!(m = load_original_map (name, (flags & MAP_PLAYER_UNIQUE)))) 1594 if (!(m = load_original_map (name, (flags & MAP_PLAYER_UNIQUE))))
1587 return (NULL); 1595 return (NULL);
1588 //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1589 1596
1590 fix_auto_apply (m); /* Chests which open as default */ 1597 fix_auto_apply (m); /* Chests which open as default */
1591 1598
1592 /* If a player unique map, no extra unique object file to load. 1599 /* If a player unique map, no extra unique object file to load.
1593 * if from the editor, likewise. 1600 * if from the editor, likewise.
1956} 1963}
1957 1964
1958void 1965void
1959set_map_reset_time (maptile *map) 1966set_map_reset_time (maptile *map)
1960{ 1967{
1961 int timeout;
1962
1963 timeout = map->reset_timeout; 1968 int timeout = map->reset_timeout;
1969
1964 if (timeout <= 0) 1970 if (timeout <= 0)
1965 timeout = MAP_DEFAULTRESET; 1971 timeout = MAP_DEFAULTRESET;
1966 if (timeout >= MAP_MAXRESET) 1972 if (timeout >= MAP_MAXRESET)
1967 timeout = MAP_MAXRESET; 1973 timeout = MAP_MAXRESET;
1974
1968 map->reset_time = time (0) + timeout; 1975 map->reset_time = time (0) + timeout;
1969} 1976}
1970 1977
1971/* this updates the orig_map->tile_map[tile_num] value after loading 1978/* this updates the orig_map->tile_map[tile_num] value after loading
1972 * the map. It also takes care of linking back the freshly loaded 1979 * the map. It also takes care of linking back the freshly loaded

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines