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.33 by root, Sun Oct 8 16:51:50 2006 UTC vs.
Revision 1.43 by root, Thu Dec 14 22:45:40 2006 UTC

24 24
25#include <global.h> 25#include <global.h>
26#include <funcpoint.h> 26#include <funcpoint.h>
27 27
28#include <loader.h> 28#include <loader.h>
29#ifndef WIN32 /* ---win32 exclude header */
30# include <unistd.h> 29#include <unistd.h>
31#endif /* win32 */
32 30
33#include "path.h" 31#include "path.h"
34 32
35 33
36/* 34/*
157int 155int
158check_path (const char *name, int prepend_dir) 156check_path (const char *name, int prepend_dir)
159{ 157{
160 char buf[MAX_BUF]; 158 char buf[MAX_BUF];
161 159
162#ifndef WIN32
163 char *endbuf; 160 char *endbuf;
164 struct stat statbuf; 161 struct stat statbuf;
165 int mode = 0; 162 int mode = 0;
166#endif
167 163
168 if (prepend_dir) 164 if (prepend_dir)
169 strcpy (buf, create_pathname (name)); 165 strcpy (buf, create_pathname (name));
170 else 166 else
171 strcpy (buf, name); 167 strcpy (buf, name);
172#ifdef WIN32 /* ***win32: check this sucker in windows style. */
173 return (_access (buf, 0));
174#else
175 168
176 /* old method (strchr(buf, '\0')) seemd very odd to me - 169 /* old method (strchr(buf, '\0')) seemd very odd to me -
177 * this method should be equivalant and is clearer. 170 * this method should be equivalant and is clearer.
178 * Can not use strcat because we need to cycle through 171 * Can not use strcat because we need to cycle through
179 * all the names. 172 * all the names.
192 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || 185 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) ||
193 (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) 186 (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH))
194 mode |= 2; 187 mode |= 2;
195 188
196 return (mode); 189 return (mode);
197#endif
198} 190}
199 191
200/* 192/*
201 * Prints out debug-information about a map. 193 * Prints out debug-information about a map.
202 * Dumping these at llevError doesn't seem right, but is 194 * Dumping these at llevError doesn't seem right, but is
540{ 532{
541 int i, j; 533 int i, j;
542 int unique; 534 int unique;
543 object *op, *prev = NULL, *last_more = NULL, *otmp; 535 object *op, *prev = NULL, *last_more = NULL, *otmp;
544 536
545 op = get_object (); 537 op = object::create ();
546 op->map = m; /* To handle buttons correctly */ 538 op->map = m; /* To handle buttons correctly */
547 539
548 while ((i = load_object (fp, op, mapflags))) 540 while ((i = load_object (fp, op, mapflags)))
549 { 541 {
550 /* if the archetype for the object is null, means that we 542 /* if the archetype for the object is null, means that we
558 } 550 }
559 551
560 552
561 switch (i) 553 switch (i)
562 { 554 {
563 case LL_NORMAL: 555 case LL_NORMAL:
564 /* if we are loading an overlay, put the floors on the bottom */ 556 /* if we are loading an overlay, put the floors on the bottom */
565 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) 557 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY)
566 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); 558 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD);
567 else 559 else
568 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 560 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD);
569 561
570 if (op->inv) 562 if (op->inv)
571 sum_weight (op); 563 sum_weight (op);
572 564
573 prev = op, last_more = op; 565 prev = op, last_more = op;
574 break; 566 break;
575 567
576 case LL_MORE: 568 case LL_MORE:
577 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 569 insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY);
578 op->head = prev, last_more->more = op, last_more = op; 570 op->head = prev, last_more->more = op, last_more = op;
579 break; 571 break;
580 } 572 }
581 573
582 if (mapflags & MAP_STYLE) 574 if (mapflags & MAP_STYLE)
583 remove_from_active_list (op); 575 remove_from_active_list (op);
584 576
585 op = get_object (); 577 op = object::create ();
586 op->map = m; 578 op->map = m;
587 } 579 }
588 580
589 for (i = 0; i < m->width; i++) 581 for (i = 0; i < m->width; i++)
590 { 582 {
594 /* check for unique items, or unique squares */ 586 /* check for unique items, or unique squares */
595 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) 587 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above)
596 { 588 {
597 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) 589 if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
598 unique = 1; 590 unique = 1;
591
599 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) 592 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
600 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); 593 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
601 } 594 }
602 } 595 }
603 } 596 }
604 597
605 free_object (op); 598 op->destroy ();
606 link_multipart_objects (m); 599 link_multipart_objects (m);
607} 600}
608 601
609/* This saves all the objects on the map in a non destructive fashion. 602/* This saves all the objects on the map in a non destructive fashion.
610 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 603 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
643 636
644 } /* for this space */ 637 } /* for this space */
645 } /* for this j */ 638 } /* for this j */
646} 639}
647 640
641maptile::maptile ()
642{
643 in_memory = MAP_SWAPPED;
644 /* The maps used to pick up default x and y values from the
645 * map archetype. Mimic that behaviour.
646 */
647 MAP_WIDTH (this) = 16;
648 MAP_HEIGHT (this) = 16;
649 MAP_RESET_TIMEOUT (this) = 0;
650 MAP_TIMEOUT (this) = 300;
651 MAP_ENTER_X (this) = 0;
652 MAP_ENTER_Y (this) = 0;
653 /*set part to -1 indicating conversion to weather map not yet done */
654 MAP_WORLDPARTX (this) = -1;
655 MAP_WORLDPARTY (this) = -1;
656}
657
648/* 658/*
649 * Allocates, initialises, and returns a pointer to a maptile. 659 * Allocates, initialises, and returns a pointer to a maptile.
650 * Modified to no longer take a path option which was not being 660 * Modified to no longer take a path option which was not being
651 * used anyways. MSW 2001-07-01 661 * used anyways. MSW 2001-07-01
652 */ 662 */
653
654maptile * 663maptile *
655get_linked_map (void) 664get_linked_map (void)
656{ 665{
657 maptile *map = new maptile; 666 maptile *mp, *map = new maptile;
658 maptile *mp;
659 667
660 for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); 668 for (mp = first_map; mp && mp->next; mp = mp->next);
669
661 if (mp == NULL) 670 if (mp == NULL)
662 first_map = map; 671 first_map = map;
663 else 672 else
664 mp->next = map; 673 mp->next = map;
665 674
666 map->in_memory = MAP_SWAPPED;
667 /* The maps used to pick up default x and y values from the
668 * map archetype. Mimic that behaviour.
669 */
670 MAP_WIDTH (map) = 16;
671 MAP_HEIGHT (map) = 16;
672 MAP_RESET_TIMEOUT (map) = 0;
673 MAP_TIMEOUT (map) = 300;
674 MAP_ENTER_X (map) = 0;
675 MAP_ENTER_Y (map) = 0;
676 /*set part to -1 indicating conversion to weather map not yet done */
677 MAP_WORLDPARTX (map) = -1;
678 MAP_WORLDPARTY (map) = -1;
679 return map; 675 return map;
680} 676}
681 677
682/* 678/*
683 * Allocates the arrays contained in a maptile. 679 * Allocates the arrays contained in a maptile.
684 * This basically allocates the dynamic array of spaces for the 680 * This basically allocates the dynamic array of spaces for the
685 * map. 681 * map.
686 */ 682 */
687
688void 683void
689allocate_map (maptile *m) 684maptile::allocate ()
690{ 685{
691 m->in_memory = MAP_IN_MEMORY; 686 in_memory = MAP_IN_MEMORY;
687
692 /* Log this condition and free the storage. We could I suppose 688 /* Log this condition and free the storage. We could I suppose
693 * realloc, but if the caller is presuming the data will be intact, 689 * realloc, but if the caller is presuming the data will be intact,
694 * that is their poor assumption. 690 * that is their poor assumption.
695 */ 691 */
696 if (m->spaces) 692 if (spaces)
697 { 693 {
698 LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); 694 LOG (llevError, "allocate_map called with already allocated map (%s)\n", path);
699 free (m->spaces); 695 free (spaces);
700 } 696 }
701 697
702 m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); 698 spaces = (MapSpace *)
699 calloc (1, width * height * sizeof (MapSpace));
703 700
704 if (m->spaces == NULL) 701 if (!spaces)
705 fatal (OUT_OF_MEMORY); 702 fatal (OUT_OF_MEMORY);
706} 703}
707 704
708/* Create and returns a map of the specific size. Used 705/* Create and returns a map of the specific size. Used
709 * in random map code and the editor. 706 * in random map code and the editor.
714 maptile *m = get_linked_map (); 711 maptile *m = get_linked_map ();
715 712
716 m->width = sizex; 713 m->width = sizex;
717 m->height = sizey; 714 m->height = sizey;
718 m->in_memory = MAP_SWAPPED; 715 m->in_memory = MAP_SWAPPED;
719 allocate_map (m); 716 m->allocate ();
717
720 return m; 718 return m;
721} 719}
722 720
723/* Takes a string from a map definition and outputs a pointer to the array of shopitems 721/* Takes a string from a map definition and outputs a pointer to the array of shopitems
724 * corresponding to that string. Memory is allocated for this, it must be freed 722 * corresponding to that string. Memory is allocated for this, it must be freed
732 char *shop_string, *p, *q, *next_semicolon, *next_colon; 730 char *shop_string, *p, *q, *next_semicolon, *next_colon;
733 shopitems *items = NULL; 731 shopitems *items = NULL;
734 int i = 0, number_of_entries = 0; 732 int i = 0, number_of_entries = 0;
735 const typedata *current_type; 733 const typedata *current_type;
736 734
737 shop_string = strdup_local (input_string); 735 shop_string = strdup (input_string);
738 p = shop_string; 736 p = shop_string;
739 /* first we'll count the entries, we'll need that for allocating the array shortly */ 737 /* first we'll count the entries, we'll need that for allocating the array shortly */
740 while (p) 738 while (p)
741 { 739 {
742 p = strchr (p, ';'); 740 p = strchr (p, ';');
851{ 849{
852 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; 850 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end;
853 int msgpos = 0; 851 int msgpos = 0;
854 int maplorepos = 0; 852 int maplorepos = 0;
855 853
856 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 854 while (fgets (buf, HUGE_BUF, fp) != NULL)
857 { 855 {
858 buf[HUGE_BUF - 1] = 0; 856 buf[HUGE_BUF - 1] = 0;
859 key = buf; 857 key = buf;
858
860 while (isspace (*key)) 859 while (isspace (*key))
861 key++; 860 key++;
861
862 if (*key == 0) 862 if (*key == 0)
863 continue; /* empty line */ 863 continue; /* empty line */
864
864 value = strchr (key, ' '); 865 value = strchr (key, ' ');
866
865 if (!value) 867 if (!value)
866 { 868 {
867 end = strchr (key, '\n'); 869 if ((end = strchr (key, '\n')))
868 if (end != NULL)
869 {
870 *end = 0; 870 *end = 0;
871 }
872 } 871 }
873 else 872 else
874 { 873 {
875 *value = 0; 874 *value = 0;
876 value++; 875 value++;
877 end = strchr (value, '\n'); 876 end = strchr (value, '\n');
877
878 while (isspace (*value)) 878 while (isspace (*value))
879 { 879 {
880 value++; 880 value++;
881
881 if (*value == '\0' || value == end) 882 if (*value == '\0' || value == end)
882 { 883 {
883 /* Nothing but spaces. */ 884 /* Nothing but spaces. */
884 value = NULL; 885 value = NULL;
885 break; 886 break;
908 * that use the parameter. 909 * that use the parameter.
909 */ 910 */
910 911
911 if (!strcmp (key, "msg")) 912 if (!strcmp (key, "msg"))
912 { 913 {
913 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 914 while (fgets (buf, HUGE_BUF, fp) != NULL)
914 { 915 {
915 if (!strcmp (buf, "endmsg\n")) 916 if (!strcmp (buf, "endmsg\n"))
916 break; 917 break;
917 else 918 else
918 { 919 {
925 * with nothing between). There is no reason in those cases to 926 * with nothing between). There is no reason in those cases to
926 * keep the empty message. Also, msgbuf contains garbage data 927 * keep the empty message. Also, msgbuf contains garbage data
927 * when msgpos is zero, so copying it results in crashes 928 * when msgpos is zero, so copying it results in crashes
928 */ 929 */
929 if (msgpos != 0) 930 if (msgpos != 0)
930 m->msg = strdup_local (msgbuf); 931 m->msg = strdup (msgbuf);
931 } 932 }
932 else if (!strcmp (key, "maplore")) 933 else if (!strcmp (key, "maplore"))
933 { 934 {
934 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 935 while (fgets (buf, HUGE_BUF, fp) != NULL)
935 { 936 {
936 if (!strcmp (buf, "endmaplore\n")) 937 if (!strcmp (buf, "endmaplore\n"))
937 break; 938 break;
938 else 939 else
939 { 940 {
941 strcpy (maplorebuf + maplorepos, buf); 942 strcpy (maplorebuf + maplorepos, buf);
942 maplorepos += strlen (buf); 943 maplorepos += strlen (buf);
943 } 944 }
944 } 945 }
945 if (maplorepos != 0) 946 if (maplorepos != 0)
946 m->maplore = strdup_local (maplorebuf); 947 m->maplore = strdup (maplorebuf);
947 } 948 }
948 else if (!strcmp (key, "end")) 949 else if (!strcmp (key, "end"))
949 { 950 {
950 break; 951 break;
951 } 952 }
960 LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); 961 LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value);
961 } 962 }
962 else if (!strcmp (key, "name")) 963 else if (!strcmp (key, "name"))
963 { 964 {
964 *end = 0; 965 *end = 0;
965 m->name = strdup_local (value); 966 m->name = strdup (value);
966 } 967 }
967 /* first strcmp value on these are old names supported 968 /* first strcmp value on these are old names supported
968 * for compatibility reasons. The new values (second) are 969 * for compatibility reasons. The new values (second) are
969 * what really should be used. 970 * what really should be used.
970 */ 971 */
971 else if (!strcmp (key, "oid")) 972 else if (!strcmp (key, "oid"))
972 {
973 fp.get (m, atoi (value)); 973 fp.get (m, atoi (value));
974 }
975 else if (!strcmp (key, "attach")) 974 else if (!strcmp (key, "attach"))
976 {
977 m->attach = value; 975 m->attach = value;
978 }
979 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) 976 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x"))
980 {
981 m->enter_x = atoi (value); 977 m->enter_x = atoi (value);
982 }
983 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) 978 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y"))
984 {
985 m->enter_y = atoi (value); 979 m->enter_y = atoi (value);
986 }
987 else if (!strcmp (key, "x") || !strcmp (key, "width")) 980 else if (!strcmp (key, "x") || !strcmp (key, "width"))
988 {
989 m->width = atoi (value); 981 m->width = atoi (value);
990 }
991 else if (!strcmp (key, "y") || !strcmp (key, "height")) 982 else if (!strcmp (key, "y") || !strcmp (key, "height"))
992 {
993 m->height = atoi (value); 983 m->height = atoi (value);
994 }
995 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) 984 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout"))
996 {
997 m->reset_timeout = atoi (value); 985 m->reset_timeout = atoi (value);
998 }
999 else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) 986 else if (!strcmp (key, "value") || !strcmp (key, "swap_time"))
1000 {
1001 m->timeout = atoi (value); 987 m->timeout = atoi (value);
1002 }
1003 else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) 988 else if (!strcmp (key, "level") || !strcmp (key, "difficulty"))
1004 { 989 m->difficulty = clamp (atoi (value), 1, settings.max_level);
1005 m->difficulty = atoi (value);
1006 }
1007 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) 990 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness"))
1008 {
1009 m->darkness = atoi (value); 991 m->darkness = atoi (value);
1010 }
1011 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) 992 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime"))
1012 {
1013 m->fixed_resettime = atoi (value); 993 m->fixed_resettime = atoi (value);
1014 }
1015 else if (!strcmp (key, "unique")) 994 else if (!strcmp (key, "unique"))
1016 {
1017 m->unique = atoi (value); 995 m->unique = atoi (value);
1018 }
1019 else if (!strcmp (key, "template")) 996 else if (!strcmp (key, "template"))
1020 {
1021 m->templatemap = atoi (value); 997 m->templatemap = atoi (value);
1022 }
1023 else if (!strcmp (key, "region")) 998 else if (!strcmp (key, "region"))
1024 {
1025 m->region = get_region_by_name (value); 999 m->region = get_region_by_name (value);
1026 }
1027 else if (!strcmp (key, "shopitems")) 1000 else if (!strcmp (key, "shopitems"))
1028 { 1001 {
1029 *end = 0; 1002 *end = 0;
1030 m->shopitems = parse_shop_string (value); 1003 m->shopitems = parse_shop_string (value);
1031 } 1004 }
1032 else if (!strcmp (key, "shopgreed")) 1005 else if (!strcmp (key, "shopgreed"))
1033 {
1034 m->shopgreed = atof (value); 1006 m->shopgreed = atof (value);
1035 }
1036 else if (!strcmp (key, "shopmin")) 1007 else if (!strcmp (key, "shopmin"))
1037 {
1038 m->shopmin = atol (value); 1008 m->shopmin = atol (value);
1039 }
1040 else if (!strcmp (key, "shopmax")) 1009 else if (!strcmp (key, "shopmax"))
1041 {
1042 m->shopmax = atol (value); 1010 m->shopmax = atol (value);
1043 }
1044 else if (!strcmp (key, "shoprace")) 1011 else if (!strcmp (key, "shoprace"))
1045 { 1012 {
1046 *end = 0; 1013 *end = 0;
1047 m->shoprace = strdup_local (value); 1014 m->shoprace = strdup (value);
1048 } 1015 }
1049 else if (!strcmp (key, "outdoor")) 1016 else if (!strcmp (key, "outdoor"))
1050 {
1051 m->outdoor = atoi (value); 1017 m->outdoor = atoi (value);
1052 }
1053 else if (!strcmp (key, "temp")) 1018 else if (!strcmp (key, "temp"))
1054 {
1055 m->temp = atoi (value); 1019 m->temp = atoi (value);
1056 }
1057 else if (!strcmp (key, "pressure")) 1020 else if (!strcmp (key, "pressure"))
1058 {
1059 m->pressure = atoi (value); 1021 m->pressure = atoi (value);
1060 }
1061 else if (!strcmp (key, "humid")) 1022 else if (!strcmp (key, "humid"))
1062 {
1063 m->humid = atoi (value); 1023 m->humid = atoi (value);
1064 }
1065 else if (!strcmp (key, "windspeed")) 1024 else if (!strcmp (key, "windspeed"))
1066 {
1067 m->windspeed = atoi (value); 1025 m->windspeed = atoi (value);
1068 }
1069 else if (!strcmp (key, "winddir")) 1026 else if (!strcmp (key, "winddir"))
1070 {
1071 m->winddir = atoi (value); 1027 m->winddir = atoi (value);
1072 }
1073 else if (!strcmp (key, "sky")) 1028 else if (!strcmp (key, "sky"))
1074 {
1075 m->sky = atoi (value); 1029 m->sky = atoi (value);
1076 }
1077 else if (!strcmp (key, "nosmooth")) 1030 else if (!strcmp (key, "nosmooth"))
1078 {
1079 m->nosmooth = atoi (value); 1031 m->nosmooth = atoi (value);
1080 }
1081 else if (!strncmp (key, "tile_path_", 10)) 1032 else if (!strncmp (key, "tile_path_", 10))
1082 { 1033 {
1083 int tile = atoi (key + 10); 1034 int tile = atoi (key + 10);
1084 1035
1085 if (tile < 1 || tile > 4) 1036 if (tile < 1 || tile > 4)
1118 } 1069 }
1119 1070
1120 if (editor) 1071 if (editor)
1121 { 1072 {
1122 /* Use the value as in the file. */ 1073 /* Use the value as in the file. */
1123 m->tile_path[tile - 1] = strdup_local (value); 1074 m->tile_path[tile - 1] = strdup (value);
1124 } 1075 }
1125 else if (path != NULL) 1076 else if (path != NULL)
1126 { 1077 {
1127 /* Use the normalized value. */ 1078 /* Use the normalized value. */
1128 m->tile_path[tile - 1] = strdup_local (path); 1079 m->tile_path[tile - 1] = strdup (path);
1129 } 1080 }
1130 } /* end if tile direction (in)valid */ 1081 } /* end if tile direction (in)valid */
1131 } 1082 }
1132 else 1083 else
1133 {
1134 LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); 1084 LOG (llevError, "Got unknown value in map header: %s %s\n", key, value);
1135 }
1136 } 1085 }
1086
1137 if (!key || strcmp (key, "end")) 1087 if (!key || strcmp (key, "end"))
1138 { 1088 {
1139 LOG (llevError, "Got premature eof on map header!\n"); 1089 LOG (llevError, "Got premature eof on map header!\n");
1140 return 1; 1090 return 1;
1141 } 1091 }
1092
1142 return 0; 1093 return 0;
1143} 1094}
1144 1095
1145/* 1096/*
1146 * Opens the file "filename" and reads information about the map 1097 * Opens the file "filename" and reads information about the map
1182 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); 1133 LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags);
1183 delete_map (m); 1134 delete_map (m);
1184 return NULL; 1135 return NULL;
1185 } 1136 }
1186 1137
1187 allocate_map (m); 1138 m->allocate ();
1188 1139
1189 m->in_memory = MAP_LOADING; 1140 m->in_memory = MAP_LOADING;
1190 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1141 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1191 1142
1192 m->in_memory = MAP_IN_MEMORY; 1143 m->in_memory = MAP_IN_MEMORY;
1238 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); 1189 LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname);
1239 delete_map (m); 1190 delete_map (m);
1240 m = load_original_map (m->path, 0); 1191 m = load_original_map (m->path, 0);
1241 return NULL; 1192 return NULL;
1242 } 1193 }
1194
1243 allocate_map (m); 1195 m->allocate ();
1244 1196
1245 m->in_memory = MAP_LOADING; 1197 m->in_memory = MAP_LOADING;
1246 load_objects (m, thawer, 0); 1198 load_objects (m, thawer, 0);
1247 1199
1248 m->in_memory = MAP_IN_MEMORY; 1200 m->in_memory = MAP_IN_MEMORY;
1273 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); 1225 LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname);
1274 delete_map (m); 1226 delete_map (m);
1275 m = load_original_map (m->path, 0); 1227 m = load_original_map (m->path, 0);
1276 return NULL; 1228 return NULL;
1277 } 1229 }
1278 /*allocate_map(m); */ 1230 /*m->allocate ();*/
1279 1231
1280 m->in_memory = MAP_LOADING; 1232 m->in_memory = MAP_LOADING;
1281 load_objects (m, thawer, MAP_OVERLAY); 1233 load_objects (m, thawer, MAP_OVERLAY);
1282 1234
1283 m->in_memory = MAP_IN_MEMORY; 1235 m->in_memory = MAP_IN_MEMORY;
1297 1249
1298 for (i = 0; i < MAP_WIDTH (m); i++) 1250 for (i = 0; i < MAP_WIDTH (m); i++)
1299 for (j = 0; j < MAP_HEIGHT (m); j++) 1251 for (j = 0; j < MAP_HEIGHT (m); j++)
1300 { 1252 {
1301 unique = 0; 1253 unique = 0;
1254
1302 for (op = get_map_ob (m, i, j); op; op = next) 1255 for (op = get_map_ob (m, i, j); op; op = next)
1303 { 1256 {
1304 next = op->above; 1257 next = op->above;
1258
1305 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 1259 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
1306 unique = 1; 1260 unique = 1;
1261
1307 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 1262 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
1308 { 1263 {
1309 clean_object (op); 1264 clean_object (op);
1265
1310 if (QUERY_FLAG (op, FLAG_IS_LINKED)) 1266 if (QUERY_FLAG (op, FLAG_IS_LINKED))
1311 remove_button_link (op); 1267 remove_button_link (op);
1312 remove_ob (op); 1268
1313 free_object (op); 1269 op->destroy ();
1314 } 1270 }
1315 } 1271 }
1316 } 1272 }
1317} 1273}
1318 1274
1387 make_path_to_file (filename); 1343 make_path_to_file (filename);
1388 } 1344 }
1389 else 1345 else
1390 { 1346 {
1391 if (!m->tmpname) 1347 if (!m->tmpname)
1392 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1348 m->tmpname = tempnam (settings.tmpdir, NULL);
1393 1349
1394 strcpy (filename, m->tmpname); 1350 strcpy (filename, m->tmpname);
1395 } 1351 }
1396 1352
1397 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1353 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1421 print_shop_string (m, shop); 1377 print_shop_string (m, shop);
1422 fprintf (freezer, "shopitems %s\n", shop); 1378 fprintf (freezer, "shopitems %s\n", shop);
1423 } 1379 }
1424 if (m->shopgreed) 1380 if (m->shopgreed)
1425 fprintf (freezer, "shopgreed %f\n", m->shopgreed); 1381 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1426#ifndef WIN32
1427 if (m->shopmin) 1382 if (m->shopmin)
1428 fprintf (freezer, "shopmin %llu\n", m->shopmin); 1383 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1429 if (m->shopmax) 1384 if (m->shopmax)
1430 fprintf (freezer, "shopmax %llu\n", m->shopmax); 1385 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1431#else
1432 if (m->shopmin)
1433 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1434 if (m->shopmax)
1435 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1436#endif
1437 if (m->shoprace) 1386 if (m->shoprace)
1438 fprintf (freezer, "shoprace %s\n", m->shoprace); 1387 fprintf (freezer, "shoprace %s\n", m->shoprace);
1439 if (m->darkness) 1388 if (m->darkness)
1440 fprintf (freezer, "darkness %d\n", m->darkness); 1389 fprintf (freezer, "darkness %d\n", m->darkness);
1441 if (m->width) 1390 if (m->width)
1520 object *tmp, *next; 1469 object *tmp, *next;
1521 1470
1522 for (tmp = op->inv; tmp; tmp = next) 1471 for (tmp = op->inv; tmp; tmp = next)
1523 { 1472 {
1524 next = tmp->below; 1473 next = tmp->below;
1474
1525 clean_object (tmp); 1475 clean_object (tmp);
1526 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 1476 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
1527 remove_button_link (tmp); 1477 remove_button_link (tmp);
1528 remove_ob (tmp); 1478
1529 free_object (tmp); 1479 tmp->destroy ();
1530 } 1480 }
1531} 1481}
1532 1482
1533/* 1483/*
1534 * Remove and free all objects in the given map. 1484 * Remove and free all objects in the given map.
1550 if (op == previous_obj) 1500 if (op == previous_obj)
1551 { 1501 {
1552 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); 1502 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n");
1553 break; 1503 break;
1554 } 1504 }
1505
1555 previous_obj = op; 1506 previous_obj = op;
1507
1556 if (op->head != NULL) 1508 if (op->head != NULL)
1557 op = op->head; 1509 op = op->head;
1558 1510
1559 /* If the map isn't in memory, free_object will remove and 1511 /* If the map isn't in memory, free_object will remove and
1560 * free objects in op's inventory. So let it do the job. 1512 * free objects in op's inventory. So let it do the job.
1561 */ 1513 */
1562 if (m->in_memory == MAP_IN_MEMORY) 1514 if (m->in_memory == MAP_IN_MEMORY)
1563 clean_object (op); 1515 clean_object (op);
1564 remove_ob (op); 1516
1565 free_object (op); 1517 op->destroy ();
1566 } 1518 }
1567 } 1519 }
1568} 1520}
1569 1521
1570/* 1522/*
1580 if (!m->in_memory) 1532 if (!m->in_memory)
1581 { 1533 {
1582 LOG (llevError, "Trying to free freed map.\n"); 1534 LOG (llevError, "Trying to free freed map.\n");
1583 return; 1535 return;
1584 } 1536 }
1537
1538 // TODO: use new/delete
1539#define FREE_AND_CLEAR(p) { free (p); p = NULL; }
1540
1585 if (flag && m->spaces) 1541 if (flag && m->spaces)
1586 free_all_objects (m); 1542 free_all_objects (m);
1587 if (m->name) 1543 if (m->name)
1588 FREE_AND_CLEAR (m->name); 1544 FREE_AND_CLEAR (m->name);
1589 if (m->spaces) 1545 if (m->spaces)
1590 FREE_AND_CLEAR (m->spaces); 1546 FREE_AND_CLEAR (m->spaces);
1591 if (m->msg) 1547 if (m->msg)
1592 FREE_AND_CLEAR (m->msg); 1548 FREE_AND_CLEAR (m->msg);
1593 if (m->maplore) 1549 if (m->maplore)
1594 FREE_AND_CLEAR (m->maplore); 1550 FREE_AND_CLEAR (m->maplore);
1595 if (m->shopitems) 1551
1596 delete[]m->shopitems; 1552 delete [] m->shopitems;
1597 m->shopitems = 0; 1553 m->shopitems = 0;
1554
1598 if (m->shoprace) 1555 if (m->shoprace)
1599 FREE_AND_CLEAR (m->shoprace); 1556 FREE_AND_CLEAR (m->shoprace);
1557
1600 if (m->buttons) 1558 if (m->buttons)
1601 free_objectlinkpt (m->buttons); 1559 free_objectlinkpt (m->buttons);
1560
1602 m->buttons = NULL; 1561 m->buttons = NULL;
1562
1603 for (i = 0; i < 4; i++) 1563 for (i = 0; i < 4; i++)
1604 { 1564 {
1605 if (m->tile_path[i]) 1565 if (m->tile_path[i])
1606 FREE_AND_CLEAR (m->tile_path[i]); 1566 FREE_AND_CLEAR (m->tile_path[i]);
1607 m->tile_map[i] = NULL; 1567 m->tile_map[i] = NULL;
1608 } 1568 }
1569
1609 m->in_memory = MAP_SWAPPED; 1570 m->in_memory = MAP_SWAPPED;
1571
1572#undef FREE_AND_CLEAR
1573
1610} 1574}
1611 1575
1612/* 1576/*
1613 * function: vanish maptile 1577 * function: vanish maptile
1614 * m : pointer to maptile, if NULL no action 1578 * m : pointer to maptile, if NULL no action
2144 timeout = MAP_RESET_TIMEOUT (map); 2108 timeout = MAP_RESET_TIMEOUT (map);
2145 if (timeout <= 0) 2109 if (timeout <= 0)
2146 timeout = MAP_DEFAULTRESET; 2110 timeout = MAP_DEFAULTRESET;
2147 if (timeout >= MAP_MAXRESET) 2111 if (timeout >= MAP_MAXRESET)
2148 timeout = MAP_MAXRESET; 2112 timeout = MAP_MAXRESET;
2149 MAP_WHEN_RESET (map) = seconds () + timeout; 2113 MAP_WHEN_RESET (map) = time (0) + timeout;
2150} 2114}
2151 2115
2152/* this updates the orig_map->tile_map[tile_num] value after loading 2116/* this updates the orig_map->tile_map[tile_num] value after loading
2153 * the map. It also takes care of linking back the freshly loaded 2117 * the map. It also takes care of linking back the freshly loaded
2154 * maps tile_map values if it tiles back to this one. It returns 2118 * maps tile_map values if it tiles back to this one. It returns

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines