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.31 by root, Sat Sep 16 22:24:12 2006 UTC vs.
Revision 1.41 by root, Tue Dec 12 22:37:05 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
36extern int nrofallocobjects, nroffreeobjects;
37 33
38/* 34/*
39 * Returns the maptile which has a name matching the given argument. 35 * Returns the maptile which has a name matching the given argument.
40 * return NULL if no match is found. 36 * return NULL if no match is found.
41 */ 37 */
159int 155int
160check_path (const char *name, int prepend_dir) 156check_path (const char *name, int prepend_dir)
161{ 157{
162 char buf[MAX_BUF]; 158 char buf[MAX_BUF];
163 159
164#ifndef WIN32
165 char *endbuf; 160 char *endbuf;
166 struct stat statbuf; 161 struct stat statbuf;
167 int mode = 0; 162 int mode = 0;
168#endif
169 163
170 if (prepend_dir) 164 if (prepend_dir)
171 strcpy (buf, create_pathname (name)); 165 strcpy (buf, create_pathname (name));
172 else 166 else
173 strcpy (buf, name); 167 strcpy (buf, name);
174#ifdef WIN32 /* ***win32: check this sucker in windows style. */
175 return (_access (buf, 0));
176#else
177 168
178 /* old method (strchr(buf, '\0')) seemd very odd to me - 169 /* old method (strchr(buf, '\0')) seemd very odd to me -
179 * this method should be equivalant and is clearer. 170 * this method should be equivalant and is clearer.
180 * Can not use strcat because we need to cycle through 171 * Can not use strcat because we need to cycle through
181 * all the names. 172 * all the names.
194 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || 185 if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) ||
195 (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))
196 mode |= 2; 187 mode |= 2;
197 188
198 return (mode); 189 return (mode);
199#endif
200} 190}
201 191
202/* 192/*
203 * Prints out debug-information about a map. 193 * Prints out debug-information about a map.
204 * Dumping these at llevError doesn't seem right, but is 194 * Dumping these at llevError doesn't seem right, but is
275 retval |= mp->spaces[newx + mp->width * newy].flags; 265 retval |= mp->spaces[newx + mp->width * newy].flags;
276 266
277 return retval; 267 return retval;
278} 268}
279 269
280
281/* 270/*
282 * Returns true if the given coordinate is blocked except by the 271 * Returns true if the given coordinate is blocked except by the
283 * object passed is not blocking. This is used with 272 * object passed is not blocking. This is used with
284 * multipart monsters - if we want to see if a 2x2 monster 273 * multipart monsters - if we want to see if a 2x2 monster
285 * can move 1 space to the left, we don't want its own area 274 * can move 1 space to the left, we don't want its own area
288 * monster. 277 * monster.
289 * m, x, y are the target map/coordinates - needed for map tiling. 278 * m, x, y are the target map/coordinates - needed for map tiling.
290 * the coordinates & map passed in should have been updated for tiling 279 * the coordinates & map passed in should have been updated for tiling
291 * by the caller. 280 * by the caller.
292 */ 281 */
293
294int 282int
295blocked_link (object *ob, maptile *m, int sx, int sy) 283blocked_link (object *ob, maptile *m, int sx, int sy)
296{ 284{
297 object *tmp; 285 object *tmp;
298 int mflags, blocked; 286 int mflags, blocked;
544{ 532{
545 int i, j; 533 int i, j;
546 int unique; 534 int unique;
547 object *op, *prev = NULL, *last_more = NULL, *otmp; 535 object *op, *prev = NULL, *last_more = NULL, *otmp;
548 536
549 op = get_object (); 537 op = object::create ();
550 op->map = m; /* To handle buttons correctly */ 538 op->map = m; /* To handle buttons correctly */
551 539
552 while ((i = load_object (fp, op, mapflags))) 540 while ((i = load_object (fp, op, mapflags)))
553 { 541 {
554 /* if the archetype for the object is null, means that we 542 /* if the archetype for the object is null, means that we
562 } 550 }
563 551
564 552
565 switch (i) 553 switch (i)
566 { 554 {
567 case LL_NORMAL: 555 case LL_NORMAL:
568 /* 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 */
569 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)
570 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);
571 else 559 else
572 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);
573 561
574 if (op->inv) 562 if (op->inv)
575 sum_weight (op); 563 sum_weight (op);
576 564
577 prev = op, last_more = op; 565 prev = op, last_more = op;
578 break; 566 break;
579 567
580 case LL_MORE: 568 case LL_MORE:
581 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);
582 op->head = prev, last_more->more = op, last_more = op; 570 op->head = prev, last_more->more = op, last_more = op;
583 break; 571 break;
584 } 572 }
585 573
586 if (mapflags & MAP_STYLE) 574 if (mapflags & MAP_STYLE)
587 remove_from_active_list (op); 575 remove_from_active_list (op);
588 576
589 op = get_object (); 577 op = object::create ();
590 op->map = m; 578 op->map = m;
591 } 579 }
592 580
593 for (i = 0; i < m->width; i++) 581 for (i = 0; i < m->width; i++)
594 { 582 {
598 /* check for unique items, or unique squares */ 586 /* check for unique items, or unique squares */
599 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)
600 { 588 {
601 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))
602 unique = 1; 590 unique = 1;
591
603 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) 592 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
604 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); 593 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
605 } 594 }
606 } 595 }
607 } 596 }
608 597
609 free_object (op); 598 op->destroy ();
610 link_multipart_objects (m); 599 link_multipart_objects (m);
611} 600}
612 601
613/* 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.
614 * 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,
647 636
648 } /* for this space */ 637 } /* for this space */
649 } /* for this j */ 638 } /* for this j */
650} 639}
651 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
652/* 658/*
653 * Allocates, initialises, and returns a pointer to a maptile. 659 * Allocates, initialises, and returns a pointer to a maptile.
654 * 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
655 * used anyways. MSW 2001-07-01 661 * used anyways. MSW 2001-07-01
656 */ 662 */
657
658maptile * 663maptile *
659get_linked_map (void) 664get_linked_map (void)
660{ 665{
661 maptile *map = new maptile; 666 maptile *mp, *map = new maptile;
662 maptile *mp;
663 667
664 for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); 668 for (mp = first_map; mp && mp->next; mp = mp->next);
669
665 if (mp == NULL) 670 if (mp == NULL)
666 first_map = map; 671 first_map = map;
667 else 672 else
668 mp->next = map; 673 mp->next = map;
669 674
670 map->in_memory = MAP_SWAPPED;
671 /* The maps used to pick up default x and y values from the
672 * map archetype. Mimic that behaviour.
673 */
674 MAP_WIDTH (map) = 16;
675 MAP_HEIGHT (map) = 16;
676 MAP_RESET_TIMEOUT (map) = 0;
677 MAP_TIMEOUT (map) = 300;
678 MAP_ENTER_X (map) = 0;
679 MAP_ENTER_Y (map) = 0;
680 /*set part to -1 indicating conversion to weather map not yet done */
681 MAP_WORLDPARTX (map) = -1;
682 MAP_WORLDPARTY (map) = -1;
683 return map; 675 return map;
684} 676}
685 677
686/* 678/*
687 * Allocates the arrays contained in a maptile. 679 * Allocates the arrays contained in a maptile.
688 * This basically allocates the dynamic array of spaces for the 680 * This basically allocates the dynamic array of spaces for the
689 * map. 681 * map.
690 */ 682 */
691
692void 683void
693allocate_map (maptile *m) 684maptile::allocate ()
694{ 685{
695 m->in_memory = MAP_IN_MEMORY; 686 in_memory = MAP_IN_MEMORY;
687
696 /* Log this condition and free the storage. We could I suppose 688 /* Log this condition and free the storage. We could I suppose
697 * 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,
698 * that is their poor assumption. 690 * that is their poor assumption.
699 */ 691 */
700 if (m->spaces) 692 if (spaces)
701 { 693 {
702 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);
703 free (m->spaces); 695 free (spaces);
704 } 696 }
705 697
706 m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); 698 spaces = (MapSpace *)
699 calloc (1, width * height * sizeof (MapSpace));
707 700
708 if (m->spaces == NULL) 701 if (!spaces)
709 fatal (OUT_OF_MEMORY); 702 fatal (OUT_OF_MEMORY);
710} 703}
711 704
712/* Create and returns a map of the specific size. Used 705/* Create and returns a map of the specific size. Used
713 * in random map code and the editor. 706 * in random map code and the editor.
718 maptile *m = get_linked_map (); 711 maptile *m = get_linked_map ();
719 712
720 m->width = sizex; 713 m->width = sizex;
721 m->height = sizey; 714 m->height = sizey;
722 m->in_memory = MAP_SWAPPED; 715 m->in_memory = MAP_SWAPPED;
723 allocate_map (m); 716 m->allocate ();
717
724 return m; 718 return m;
725} 719}
726 720
727/* 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
728 * 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
855{ 849{
856 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;
857 int msgpos = 0; 851 int msgpos = 0;
858 int maplorepos = 0; 852 int maplorepos = 0;
859 853
860 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 854 while (fgets (buf, HUGE_BUF, fp) != NULL)
861 { 855 {
862 buf[HUGE_BUF - 1] = 0; 856 buf[HUGE_BUF - 1] = 0;
863 key = buf; 857 key = buf;
858
864 while (isspace (*key)) 859 while (isspace (*key))
865 key++; 860 key++;
861
866 if (*key == 0) 862 if (*key == 0)
867 continue; /* empty line */ 863 continue; /* empty line */
864
868 value = strchr (key, ' '); 865 value = strchr (key, ' ');
866
869 if (!value) 867 if (!value)
870 { 868 {
871 end = strchr (key, '\n'); 869 if ((end = strchr (key, '\n')))
872 if (end != NULL)
873 {
874 *end = 0; 870 *end = 0;
875 }
876 } 871 }
877 else 872 else
878 { 873 {
879 *value = 0; 874 *value = 0;
880 value++; 875 value++;
881 end = strchr (value, '\n'); 876 end = strchr (value, '\n');
877
882 while (isspace (*value)) 878 while (isspace (*value))
883 { 879 {
884 value++; 880 value++;
881
885 if (*value == '\0' || value == end) 882 if (*value == '\0' || value == end)
886 { 883 {
887 /* Nothing but spaces. */ 884 /* Nothing but spaces. */
888 value = NULL; 885 value = NULL;
889 break; 886 break;
912 * that use the parameter. 909 * that use the parameter.
913 */ 910 */
914 911
915 if (!strcmp (key, "msg")) 912 if (!strcmp (key, "msg"))
916 { 913 {
917 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 914 while (fgets (buf, HUGE_BUF, fp) != NULL)
918 { 915 {
919 if (!strcmp (buf, "endmsg\n")) 916 if (!strcmp (buf, "endmsg\n"))
920 break; 917 break;
921 else 918 else
922 { 919 {
933 if (msgpos != 0) 930 if (msgpos != 0)
934 m->msg = strdup_local (msgbuf); 931 m->msg = strdup_local (msgbuf);
935 } 932 }
936 else if (!strcmp (key, "maplore")) 933 else if (!strcmp (key, "maplore"))
937 { 934 {
938 while (fgets (buf, HUGE_BUF - 1, fp) != NULL) 935 while (fgets (buf, HUGE_BUF, fp) != NULL)
939 { 936 {
940 if (!strcmp (buf, "endmaplore\n")) 937 if (!strcmp (buf, "endmaplore\n"))
941 break; 938 break;
942 else 939 else
943 { 940 {
971 /* first strcmp value on these are old names supported 968 /* first strcmp value on these are old names supported
972 * for compatibility reasons. The new values (second) are 969 * for compatibility reasons. The new values (second) are
973 * what really should be used. 970 * what really should be used.
974 */ 971 */
975 else if (!strcmp (key, "oid")) 972 else if (!strcmp (key, "oid"))
976 {
977 fp.get (m, atoi (value)); 973 fp.get (m, atoi (value));
978 }
979 else if (!strcmp (key, "attach")) 974 else if (!strcmp (key, "attach"))
980 {
981 m->attach = value; 975 m->attach = value;
982 }
983 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) 976 else if (!strcmp (key, "hp") || !strcmp (key, "enter_x"))
984 {
985 m->enter_x = atoi (value); 977 m->enter_x = atoi (value);
986 }
987 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) 978 else if (!strcmp (key, "sp") || !strcmp (key, "enter_y"))
988 {
989 m->enter_y = atoi (value); 979 m->enter_y = atoi (value);
990 }
991 else if (!strcmp (key, "x") || !strcmp (key, "width")) 980 else if (!strcmp (key, "x") || !strcmp (key, "width"))
992 {
993 m->width = atoi (value); 981 m->width = atoi (value);
994 }
995 else if (!strcmp (key, "y") || !strcmp (key, "height")) 982 else if (!strcmp (key, "y") || !strcmp (key, "height"))
996 {
997 m->height = atoi (value); 983 m->height = atoi (value);
998 }
999 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) 984 else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout"))
1000 {
1001 m->reset_timeout = atoi (value); 985 m->reset_timeout = atoi (value);
1002 }
1003 else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) 986 else if (!strcmp (key, "value") || !strcmp (key, "swap_time"))
1004 {
1005 m->timeout = atoi (value); 987 m->timeout = atoi (value);
1006 }
1007 else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) 988 else if (!strcmp (key, "level") || !strcmp (key, "difficulty"))
1008 { 989 m->difficulty = clamp (atoi (value), 1, settings.max_level);
1009 m->difficulty = atoi (value);
1010 }
1011 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) 990 else if (!strcmp (key, "invisible") || !strcmp (key, "darkness"))
1012 {
1013 m->darkness = atoi (value); 991 m->darkness = atoi (value);
1014 }
1015 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) 992 else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime"))
1016 {
1017 m->fixed_resettime = atoi (value); 993 m->fixed_resettime = atoi (value);
1018 }
1019 else if (!strcmp (key, "unique")) 994 else if (!strcmp (key, "unique"))
1020 {
1021 m->unique = atoi (value); 995 m->unique = atoi (value);
1022 }
1023 else if (!strcmp (key, "template")) 996 else if (!strcmp (key, "template"))
1024 {
1025 m->templatemap = atoi (value); 997 m->templatemap = atoi (value);
1026 }
1027 else if (!strcmp (key, "region")) 998 else if (!strcmp (key, "region"))
1028 {
1029 m->region = get_region_by_name (value); 999 m->region = get_region_by_name (value);
1030 }
1031 else if (!strcmp (key, "shopitems")) 1000 else if (!strcmp (key, "shopitems"))
1032 { 1001 {
1033 *end = 0; 1002 *end = 0;
1034 m->shopitems = parse_shop_string (value); 1003 m->shopitems = parse_shop_string (value);
1035 } 1004 }
1036 else if (!strcmp (key, "shopgreed")) 1005 else if (!strcmp (key, "shopgreed"))
1037 {
1038 m->shopgreed = atof (value); 1006 m->shopgreed = atof (value);
1039 }
1040 else if (!strcmp (key, "shopmin")) 1007 else if (!strcmp (key, "shopmin"))
1041 {
1042 m->shopmin = atol (value); 1008 m->shopmin = atol (value);
1043 }
1044 else if (!strcmp (key, "shopmax")) 1009 else if (!strcmp (key, "shopmax"))
1045 {
1046 m->shopmax = atol (value); 1010 m->shopmax = atol (value);
1047 }
1048 else if (!strcmp (key, "shoprace")) 1011 else if (!strcmp (key, "shoprace"))
1049 { 1012 {
1050 *end = 0; 1013 *end = 0;
1051 m->shoprace = strdup_local (value); 1014 m->shoprace = strdup_local (value);
1052 } 1015 }
1053 else if (!strcmp (key, "outdoor")) 1016 else if (!strcmp (key, "outdoor"))
1054 {
1055 m->outdoor = atoi (value); 1017 m->outdoor = atoi (value);
1056 }
1057 else if (!strcmp (key, "temp")) 1018 else if (!strcmp (key, "temp"))
1058 {
1059 m->temp = atoi (value); 1019 m->temp = atoi (value);
1060 }
1061 else if (!strcmp (key, "pressure")) 1020 else if (!strcmp (key, "pressure"))
1062 {
1063 m->pressure = atoi (value); 1021 m->pressure = atoi (value);
1064 }
1065 else if (!strcmp (key, "humid")) 1022 else if (!strcmp (key, "humid"))
1066 {
1067 m->humid = atoi (value); 1023 m->humid = atoi (value);
1068 }
1069 else if (!strcmp (key, "windspeed")) 1024 else if (!strcmp (key, "windspeed"))
1070 {
1071 m->windspeed = atoi (value); 1025 m->windspeed = atoi (value);
1072 }
1073 else if (!strcmp (key, "winddir")) 1026 else if (!strcmp (key, "winddir"))
1074 {
1075 m->winddir = atoi (value); 1027 m->winddir = atoi (value);
1076 }
1077 else if (!strcmp (key, "sky")) 1028 else if (!strcmp (key, "sky"))
1078 {
1079 m->sky = atoi (value); 1029 m->sky = atoi (value);
1080 }
1081 else if (!strcmp (key, "nosmooth")) 1030 else if (!strcmp (key, "nosmooth"))
1082 {
1083 m->nosmooth = atoi (value); 1031 m->nosmooth = atoi (value);
1084 }
1085 else if (!strncmp (key, "tile_path_", 10)) 1032 else if (!strncmp (key, "tile_path_", 10))
1086 { 1033 {
1087 int tile = atoi (key + 10); 1034 int tile = atoi (key + 10);
1088 1035
1089 if (tile < 1 || tile > 4) 1036 if (tile < 1 || tile > 4)
1132 m->tile_path[tile - 1] = strdup_local (path); 1079 m->tile_path[tile - 1] = strdup_local (path);
1133 } 1080 }
1134 } /* end if tile direction (in)valid */ 1081 } /* end if tile direction (in)valid */
1135 } 1082 }
1136 else 1083 else
1137 {
1138 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);
1139 }
1140 } 1085 }
1086
1141 if (!key || strcmp (key, "end")) 1087 if (!key || strcmp (key, "end"))
1142 { 1088 {
1143 LOG (llevError, "Got premature eof on map header!\n"); 1089 LOG (llevError, "Got premature eof on map header!\n");
1144 return 1; 1090 return 1;
1145 } 1091 }
1092
1146 return 0; 1093 return 0;
1147} 1094}
1148 1095
1149/* 1096/*
1150 * Opens the file "filename" and reads information about the map 1097 * Opens the file "filename" and reads information about the map
1186 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);
1187 delete_map (m); 1134 delete_map (m);
1188 return NULL; 1135 return NULL;
1189 } 1136 }
1190 1137
1191 allocate_map (m); 1138 m->allocate ();
1192 1139
1193 m->in_memory = MAP_LOADING; 1140 m->in_memory = MAP_LOADING;
1194 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); 1141 load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE));
1195 1142
1196 m->in_memory = MAP_IN_MEMORY; 1143 m->in_memory = MAP_IN_MEMORY;
1242 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);
1243 delete_map (m); 1190 delete_map (m);
1244 m = load_original_map (m->path, 0); 1191 m = load_original_map (m->path, 0);
1245 return NULL; 1192 return NULL;
1246 } 1193 }
1194
1247 allocate_map (m); 1195 m->allocate ();
1248 1196
1249 m->in_memory = MAP_LOADING; 1197 m->in_memory = MAP_LOADING;
1250 load_objects (m, thawer, 0); 1198 load_objects (m, thawer, 0);
1251 1199
1252 m->in_memory = MAP_IN_MEMORY; 1200 m->in_memory = MAP_IN_MEMORY;
1277 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);
1278 delete_map (m); 1226 delete_map (m);
1279 m = load_original_map (m->path, 0); 1227 m = load_original_map (m->path, 0);
1280 return NULL; 1228 return NULL;
1281 } 1229 }
1282 /*allocate_map(m); */ 1230 /*m->allocate ();*/
1283 1231
1284 m->in_memory = MAP_LOADING; 1232 m->in_memory = MAP_LOADING;
1285 load_objects (m, thawer, MAP_OVERLAY); 1233 load_objects (m, thawer, MAP_OVERLAY);
1286 1234
1287 m->in_memory = MAP_IN_MEMORY; 1235 m->in_memory = MAP_IN_MEMORY;
1301 1249
1302 for (i = 0; i < MAP_WIDTH (m); i++) 1250 for (i = 0; i < MAP_WIDTH (m); i++)
1303 for (j = 0; j < MAP_HEIGHT (m); j++) 1251 for (j = 0; j < MAP_HEIGHT (m); j++)
1304 { 1252 {
1305 unique = 0; 1253 unique = 0;
1254
1306 for (op = get_map_ob (m, i, j); op; op = next) 1255 for (op = get_map_ob (m, i, j); op; op = next)
1307 { 1256 {
1308 next = op->above; 1257 next = op->above;
1258
1309 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))
1310 unique = 1; 1260 unique = 1;
1261
1311 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) 1262 if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique))
1312 { 1263 {
1313 clean_object (op); 1264 clean_object (op);
1265
1314 if (QUERY_FLAG (op, FLAG_IS_LINKED)) 1266 if (QUERY_FLAG (op, FLAG_IS_LINKED))
1315 remove_button_link (op); 1267 remove_button_link (op);
1316 remove_ob (op); 1268
1317 free_object (op); 1269 op->destroy ();
1318 } 1270 }
1319 } 1271 }
1320 } 1272 }
1321} 1273}
1322 1274
1425 print_shop_string (m, shop); 1377 print_shop_string (m, shop);
1426 fprintf (freezer, "shopitems %s\n", shop); 1378 fprintf (freezer, "shopitems %s\n", shop);
1427 } 1379 }
1428 if (m->shopgreed) 1380 if (m->shopgreed)
1429 fprintf (freezer, "shopgreed %f\n", m->shopgreed); 1381 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1430#ifndef WIN32
1431 if (m->shopmin) 1382 if (m->shopmin)
1432 fprintf (freezer, "shopmin %llu\n", m->shopmin); 1383 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1433 if (m->shopmax) 1384 if (m->shopmax)
1434 fprintf (freezer, "shopmax %llu\n", m->shopmax); 1385 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1435#else
1436 if (m->shopmin)
1437 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1438 if (m->shopmax)
1439 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1440#endif
1441 if (m->shoprace) 1386 if (m->shoprace)
1442 fprintf (freezer, "shoprace %s\n", m->shoprace); 1387 fprintf (freezer, "shoprace %s\n", m->shoprace);
1443 if (m->darkness) 1388 if (m->darkness)
1444 fprintf (freezer, "darkness %d\n", m->darkness); 1389 fprintf (freezer, "darkness %d\n", m->darkness);
1445 if (m->width) 1390 if (m->width)
1524 object *tmp, *next; 1469 object *tmp, *next;
1525 1470
1526 for (tmp = op->inv; tmp; tmp = next) 1471 for (tmp = op->inv; tmp; tmp = next)
1527 { 1472 {
1528 next = tmp->below; 1473 next = tmp->below;
1474
1529 clean_object (tmp); 1475 clean_object (tmp);
1530 if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) 1476 if (QUERY_FLAG (tmp, FLAG_IS_LINKED))
1531 remove_button_link (tmp); 1477 remove_button_link (tmp);
1532 remove_ob (tmp); 1478
1533 free_object (tmp); 1479 tmp->destroy ();
1534 } 1480 }
1535} 1481}
1536 1482
1537/* 1483/*
1538 * Remove and free all objects in the given map. 1484 * Remove and free all objects in the given map.
1554 if (op == previous_obj) 1500 if (op == previous_obj)
1555 { 1501 {
1556 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); 1502 LOG (llevDebug, "free_all_objects: Link error, bailing out.\n");
1557 break; 1503 break;
1558 } 1504 }
1505
1559 previous_obj = op; 1506 previous_obj = op;
1507
1560 if (op->head != NULL) 1508 if (op->head != NULL)
1561 op = op->head; 1509 op = op->head;
1562 1510
1563 /* 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
1564 * 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.
1565 */ 1513 */
1566 if (m->in_memory == MAP_IN_MEMORY) 1514 if (m->in_memory == MAP_IN_MEMORY)
1567 clean_object (op); 1515 clean_object (op);
1568 remove_ob (op); 1516
1569 free_object (op); 1517 op->destroy ();
1570 } 1518 }
1571 } 1519 }
1572} 1520}
1573 1521
1574/* 1522/*

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines