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.11 by root, Mon Aug 28 16:12:59 2006 UTC vs.
Revision 1.28 by root, Fri Sep 8 18:26:22 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.11 2006/08/28 16:12:59 root Exp $"; 3 * "$Id: map.C,v 1.28 2006/09/08 18:26:22 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
155{ 155{
156 char buf[MAX_BUF]; 156 char buf[MAX_BUF];
157#ifndef WIN32 157#ifndef WIN32
158 char *endbuf; 158 char *endbuf;
159 struct stat statbuf; 159 struct stat statbuf;
160 int mode = 0, i; 160 int mode = 0;
161#endif 161#endif
162 162
163 if (prepend_dir) 163 if (prepend_dir)
164 strcpy (buf, create_pathname(name)); 164 strcpy (buf, create_pathname(name));
165 else 165 else
173 * Can not use strcat because we need to cycle through 173 * Can not use strcat because we need to cycle through
174 * all the names. 174 * all the names.
175 */ 175 */
176 endbuf = buf + strlen(buf); 176 endbuf = buf + strlen(buf);
177 177
178 for (i = 0; i < NROF_COMPRESS_METHODS; i++) {
179 if (uncomp[i][0])
180 strcpy(endbuf, uncomp[i][0]);
181 else
182 *endbuf = '\0';
183 if (!stat (buf, &statbuf)) 178 if (stat (buf, &statbuf))
184 break;
185 }
186 if (i == NROF_COMPRESS_METHODS)
187 return (-1); 179 return -1;
188 if (!S_ISREG (statbuf.st_mode)) 180 if (!S_ISREG (statbuf.st_mode))
189 return (-1); 181 return (-1);
190 182
191 if (((statbuf.st_mode & S_IRGRP) && getegid() == statbuf.st_gid) || 183 if (((statbuf.st_mode & S_IRGRP) && getegid() == statbuf.st_gid) ||
192 ((statbuf.st_mode & S_IRUSR) && geteuid() == statbuf.st_uid) || 184 ((statbuf.st_mode & S_IRUSR) && geteuid() == statbuf.st_uid) ||
263 if (mp != oldmap) 255 if (mp != oldmap)
264 retval |= P_NEW_MAP; 256 retval |= P_NEW_MAP;
265 if (newmap) *newmap = mp; 257 if (newmap) *newmap = mp;
266 if (nx) *nx = newx; 258 if (nx) *nx = newx;
267 if (ny) *ny = newy; 259 if (ny) *ny = newy;
260
268 retval |= mp->spaces[newx + mp->width * newy].flags; 261 retval |= mp->spaces[newx + mp->width * newy].flags;
269
270 if (retval & P_SAFE)
271 retval |= P_NO_MAGIC | P_NO_CLERIC; // P_SAFE does imply these
272 262
273 return retval; 263 return retval;
274} 264}
275 265
276 266
490 op->x += tmp->x; 480 op->x += tmp->x;
491 op->y += tmp->y; 481 op->y += tmp->y;
492 op->head = tmp; 482 op->head = tmp;
493 op->map = m; 483 op->map = m;
494 last->more = op; 484 last->more = op;
495 if (tmp->name != op->name) {
496 if (op->name) free_string(op->name);
497 op->name = add_string(tmp->name); 485 op->name = tmp->name;
498 }
499 if (tmp->title != op->title) {
500 if (op->title) free_string(op->title);
501 op->title = add_string(tmp->title); 486 op->title = tmp->title;
502 }
503 /* we could link all the parts onto tmp, and then just 487 /* we could link all the parts onto tmp, and then just
504 * call insert_ob_in_map once, but the effect is the same, 488 * call insert_ob_in_map once, but the effect is the same,
505 * as insert_ob_in_map will call itself with each part, and 489 * as insert_ob_in_map will call itself with each part, and
506 * the coding is simpler to just to it here with each part. 490 * the coding is simpler to just to it here with each part.
507 */ 491 */
508 insert_ob_in_map(op, op->map, tmp,INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON); 492 insert_ob_in_map(op, op->map, tmp,INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON);
509 } /* for at = tmp->arch->more */ 493 } /* for at = tmp->arch->more */
510 } /* for objects on this space */ 494 } /* for objects on this space */
511} 495}
512 496
513
514
515/* 497/*
516 * Loads (ands parses) the objects into a given map from the specified 498 * Loads (ands parses) the objects into a given map from the specified
517 * file pointer. 499 * file pointer.
518 * mapflags is the same as we get with load_original_map 500 * mapflags is the same as we get with load_original_map
519 */ 501 */
520 502void
521void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { 503load_objects (mapstruct *m, object_thawer &fp, int mapflags)
522 int i,j,bufstate=LO_NEWFILE; 504{
505 int i, j;
523 int unique; 506 int unique;
524 object *op, *prev=NULL,*last_more=NULL, *otmp; 507 object *op, *prev = NULL, *last_more = NULL, *otmp;
525 508
526 op=get_object(); 509 op = get_object ();
527 op->map = m; /* To handle buttons correctly */ 510 op->map = m; /* To handle buttons correctly */
528 511
529 while((i = load_object (fp, op, bufstate, mapflags))) { 512 while ((i = load_object (fp, op, mapflags)))
530 /* Since the loading of the map header does not load an object 513 {
531 * anymore, we need to pass LO_NEWFILE for the first object loaded,
532 * and then switch to LO_REPEAT for faster loading.
533 */
534 bufstate = LO_REPEAT;
535
536 /* if the archetype for the object is null, means that we 514 /* if the archetype for the object is null, means that we
537 * got an invalid object. Don't do anything with it - the game 515 * got an invalid object. Don't do anything with it - the game
538 * or editor will not be able to do anything with it either. 516 * or editor will not be able to do anything with it either.
539 */ 517 */
540 if (op->arch==NULL) { 518 if (op->arch == NULL)
519 {
541 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?op->name:"(null)"); 520 LOG (llevDebug, "Discarding object without arch: %s\n",
521 op->name ? (const char *) op->name : "(null)");
542 continue; 522 continue;
523 }
524
525
526 switch (i)
543 } 527 {
544
545
546 switch(i) {
547 case LL_NORMAL: 528 case LL_NORMAL:
548 /* if we are loading an overlay, put the floors on the bottom */ 529 /* if we are loading an overlay, put the floors on the bottom */
549 if ((QUERY_FLAG(op, FLAG_IS_FLOOR) || 530 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) ||
550 QUERY_FLAG(op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) 531 QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY)
551 insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); 532 insert_ob_in_map (op, m, op,
533 INS_NO_MERGE | INS_NO_WALK_ON |
534 INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD);
552 else 535 else
553 insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 536 insert_ob_in_map (op, m, op,
537 INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP |
538 INS_MAP_LOAD);
554 539
555 if (op->inv) 540 if (op->inv)
556 sum_weight(op); 541 sum_weight (op);
557 542
558 prev=op,last_more=op; 543 prev = op, last_more = op;
559 break; 544 break;
560 545
561 case LL_MORE: 546 case LL_MORE:
562 insert_ob_in_map(op,m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 547 insert_ob_in_map (op, m, op,
548 INS_NO_MERGE | INS_NO_WALK_ON |
549 INS_ABOVE_FLOOR_ONLY);
563 op->head=prev,last_more->more=op,last_more=op; 550 op->head = prev, last_more->more = op, last_more = op;
564 break; 551 break;
565 } 552 }
553
566 if (mapflags & MAP_STYLE) { 554 if (mapflags & MAP_STYLE)
567 remove_from_active_list(op); 555 remove_from_active_list (op);
568 } 556
569 op=get_object(); 557 op = get_object ();
570 op->map = m; 558 op->map = m;
571 } 559 }
560
572 for (i=0;i<m->width;i++){ 561 for (i = 0; i < m->width; i++)
562 {
573 for (j=0;j<m->height;j++){ 563 for (j = 0; j < m->height; j++)
564 {
574 unique =0; 565 unique = 0;
575 /* check for unique items, or unique squares */ 566 /* check for unique items, or unique squares */
576 for (otmp = get_map_ob(m, i, j); otmp; otmp = otmp->above) { 567 for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above)
577 if (QUERY_FLAG(otmp, FLAG_UNIQUE) || QUERY_FLAG(otmp, FLAG_OBJ_SAVE_ON_OVL)) 568 {
569 if (QUERY_FLAG (otmp, FLAG_UNIQUE)
570 || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
578 unique = 1; 571 unique = 1;
579 if (!(mapflags & (MAP_OVERLAY|MAP_PLAYER_UNIQUE) || unique)) 572 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
580 SET_FLAG(otmp, FLAG_OBJ_ORIGINAL); 573 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
581 } 574 }
582 } 575 }
583 } 576 }
577
584 free_object(op); 578 free_object (op);
585 link_multipart_objects(m); 579 link_multipart_objects (m);
586} 580}
587 581
588/* This saves all the objects on the map in a non destructive fashion. 582/* This saves all the objects on the map in a non destructive fashion.
589 * Modified by MSW 2001-07-01 to do in a single pass - reduces code, 583 * Modified by MSW 2001-07-01 to do in a single pass - reduces code,
590 * and we only save the head of multi part objects - this is needed 584 * and we only save the head of multi part objects - this is needed
626 * Modified to no longer take a path option which was not being 620 * Modified to no longer take a path option which was not being
627 * used anyways. MSW 2001-07-01 621 * used anyways. MSW 2001-07-01
628 */ 622 */
629 623
630mapstruct *get_linked_map(void) { 624mapstruct *get_linked_map(void) {
631 mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); 625 mapstruct *map = new mapstruct;
632 mapstruct *mp; 626 mapstruct *mp;
633
634 if(map==NULL)
635 fatal(OUT_OF_MEMORY);
636 627
637 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next); 628 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next);
638 if(mp==NULL) 629 if(mp==NULL)
639 first_map=map; 630 first_map=map;
640 else 631 else
711 number_of_entries++; 702 number_of_entries++;
712 if (p) p++; 703 if (p) p++;
713 } 704 }
714 p=shop_string; 705 p=shop_string;
715 strip_endline(p); 706 strip_endline(p);
716 items=(shopitems *) CALLOC(number_of_entries+1, sizeof(shopitems)); 707 items = new shopitems [number_of_entries + 1];
717 memset(items, 0, (sizeof(shopitems) * number_of_entries+1));
718 for (i=0; i<number_of_entries; i++) { 708 for (i=0; i<number_of_entries; i++) {
719 if (!p) { 709 if (!p) {
720 LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n"); 710 LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
721 break; 711 break;
722 } 712 }
823 value = NULL; 813 value = NULL;
824 break; 814 break;
825 } 815 }
826 } 816 }
827 } 817 }
818
828 if (!end) { 819 if (!end) {
829 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", 820 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n",
830 buf); 821 buf);
831 return 1; 822 return 1;
832 } 823 }
833
834 824
835 /* key is the field name, value is what it should be set 825 /* key is the field name, value is what it should be set
836 * to. We've already done the work to null terminate key, 826 * to. We've already done the work to null terminate key,
837 * and strip off any leading spaces for both of these. 827 * and strip off any leading spaces for both of these.
838 * We have not touched the newline at the end of the line - 828 * We have not touched the newline at the end of the line -
895 * for compatibility reasons. The new values (second) are 885 * for compatibility reasons. The new values (second) are
896 * what really should be used. 886 * what really should be used.
897 */ 887 */
898 else if (!strcmp(key,"oid")) { 888 else if (!strcmp(key,"oid")) {
899 fp.get (m, atoi(value)); 889 fp.get (m, atoi(value));
890 } else if (!strcmp(key, "attach")) {
891 m->attach = value;
900 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 892 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
901 m->enter_x = atoi(value); 893 m->enter_x = atoi(value);
902 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 894 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
903 m->enter_y = atoi(value); 895 m->enter_y = atoi(value);
904 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 896 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
947 m->winddir = atoi(value); 939 m->winddir = atoi(value);
948 } else if (!strcmp(key, "sky")) { 940 } else if (!strcmp(key, "sky")) {
949 m->sky = atoi(value); 941 m->sky = atoi(value);
950 } else if (!strcmp(key, "nosmooth")) { 942 } else if (!strcmp(key, "nosmooth")) {
951 m->nosmooth = atoi(value); 943 m->nosmooth = atoi(value);
952 } else if (!strcmp(key, "safe_map")) {
953 m->safe_map = atoi(value);
954 } 944 }
955 else if (!strncmp(key,"tile_path_", 10)) { 945 else if (!strncmp(key,"tile_path_", 10)) {
956 int tile=atoi(key+10); 946 int tile=atoi(key+10);
957 947
958 if (tile<1 || tile>4) { 948 if (tile<1 || tile>4) {
1015 * MAP_STYLE: style map - don't add active objects, don't add to server 1005 * MAP_STYLE: style map - don't add active objects, don't add to server
1016 * managed map list. 1006 * managed map list.
1017 */ 1007 */
1018 1008
1019mapstruct *load_original_map(const char *filename, int flags) { 1009mapstruct *load_original_map(const char *filename, int flags) {
1020 FILE *fp;
1021 mapstruct *m; 1010 mapstruct *m;
1022 int comp;
1023 char pathname[MAX_BUF]; 1011 char pathname[MAX_BUF];
1024 1012
1025 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags);
1026 if (flags & MAP_PLAYER_UNIQUE) 1013 if (flags & MAP_PLAYER_UNIQUE)
1027 strcpy(pathname, filename); 1014 strcpy(pathname, filename);
1028 else if (flags & MAP_OVERLAY) 1015 else if (flags & MAP_OVERLAY)
1029 strcpy(pathname, create_overlay_pathname(filename)); 1016 strcpy(pathname, create_overlay_pathname(filename));
1030 else 1017 else
1031 strcpy(pathname, create_pathname(filename)); 1018 strcpy(pathname, create_pathname(filename));
1032 1019
1033 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) { 1020 LOG(llevDebug, "load_original_map(%x): %s (%s)\n", flags, filename, pathname);
1034 LOG(llevError, "Can't open %s: %s\n", pathname, strerror_local(errno));
1035 return (NULL);
1036 }
1037 1021
1038 object_thawer thawer (fp, filename); 1022 object_thawer thawer (pathname);
1023
1024 if (!thawer)
1025 return 0;
1039 1026
1040 m = get_linked_map(); 1027 m = get_linked_map();
1041 1028
1042 strcpy (m->path, filename); 1029 strcpy (m->path, filename);
1043 if (load_map_header(thawer, m)) { 1030 if (load_map_header(thawer, m)) {
1049 1036
1050 allocate_map(m); 1037 allocate_map(m);
1051 1038
1052 m->in_memory=MAP_LOADING; 1039 m->in_memory=MAP_LOADING;
1053 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); 1040 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE));
1054 close_and_delete(fp, comp); 1041
1055 m->in_memory=MAP_IN_MEMORY; 1042 m->in_memory=MAP_IN_MEMORY;
1056 if (!MAP_DIFFICULTY(m)) 1043 if (!MAP_DIFFICULTY(m))
1057 MAP_DIFFICULTY(m)=calculate_difficulty(m); 1044 MAP_DIFFICULTY(m)=calculate_difficulty(m);
1058 set_map_reset_time(m); 1045 set_map_reset_time(m);
1059 INVOKE_MAP (INSTANTIATE, m); 1046 m->instantiate ();
1060 return (m); 1047 return (m);
1061} 1048}
1062 1049
1063/* 1050/*
1064 * Loads a map, which has been loaded earlier, from file. 1051 * Loads a map, which has been loaded earlier, from file.
1065 * Return the map object we load into (this can change from the passed 1052 * Return the map object we load into (this can change from the passed
1066 * option if we can't find the original map) 1053 * option if we can't find the original map)
1067 */ 1054 */
1068 1055
1069static mapstruct *load_temporary_map(mapstruct *m) { 1056static mapstruct *load_temporary_map(mapstruct *m) {
1070 FILE *fp;
1071 int comp;
1072 char buf[MAX_BUF]; 1057 char buf[MAX_BUF];
1073 1058
1074 if (!m->tmpname) { 1059 if (!m->tmpname) {
1075 LOG(llevError, "No temporary filename for map %s\n", m->path); 1060 LOG(llevError, "No temporary filename for map %s\n", m->path);
1076 strcpy(buf, m->path); 1061 strcpy(buf, m->path);
1079 if(m==NULL) return NULL; 1064 if(m==NULL) return NULL;
1080 fix_auto_apply(m); /* Chests which open as default */ 1065 fix_auto_apply(m); /* Chests which open as default */
1081 return m; 1066 return m;
1082 } 1067 }
1083 1068
1084 if((fp=open_and_uncompress(m->tmpname,0, &comp))==NULL) { 1069 object_thawer thawer (m->tmpname);
1085 LOG(llevError, "Cannot open %s: %s\n",m->tmpname, strerror_local(errno)); 1070
1071 if (!thawer)
1072 {
1086 strcpy(buf, m->path); 1073 strcpy (buf, m->path);
1087 delete_map(m); 1074 delete_map (m);
1088 m = load_original_map(buf, 0); 1075 m = load_original_map (buf, 0);
1089 if(m==NULL) return NULL; 1076 if (!m) return NULL;
1090 fix_auto_apply(m); /* Chests which open as default */ 1077 fix_auto_apply (m); /* Chests which open as default */
1091 return m; 1078 return m;
1092 } 1079 }
1093
1094 object_thawer thawer (fp, m->tmpname);
1095 1080
1096 if (load_map_header(thawer, m)) { 1081 if (load_map_header(thawer, m)) {
1097 LOG(llevError,"Error loading map header for %s (%s)\n", 1082 LOG(llevError,"Error loading map header for %s (%s)\n",
1098 m->path, m->tmpname); 1083 m->path, m->tmpname);
1099 delete_map(m); 1084 delete_map(m);
1102 } 1087 }
1103 allocate_map(m); 1088 allocate_map(m);
1104 1089
1105 m->in_memory=MAP_LOADING; 1090 m->in_memory=MAP_LOADING;
1106 load_objects (m, thawer, 0); 1091 load_objects (m, thawer, 0);
1107 close_and_delete(fp, comp); 1092
1108 m->in_memory=MAP_IN_MEMORY; 1093 m->in_memory=MAP_IN_MEMORY;
1109 INVOKE_MAP (SWAPIN, m); 1094 INVOKE_MAP (SWAPIN, m);
1110 return m; 1095 return m;
1111} 1096}
1112 1097
1115 * Return the map object we load into (this can change from the passed 1100 * Return the map object we load into (this can change from the passed
1116 * option if we can't find the original map) 1101 * option if we can't find the original map)
1117 */ 1102 */
1118 1103
1119mapstruct *load_overlay_map(const char *filename, mapstruct *m) { 1104mapstruct *load_overlay_map(const char *filename, mapstruct *m) {
1120 FILE *fp;
1121 int comp;
1122 char pathname[MAX_BUF]; 1105 char pathname[MAX_BUF];
1123 1106
1124 strcpy(pathname, create_overlay_pathname(filename)); 1107 strcpy(pathname, create_overlay_pathname(filename));
1125 1108
1126 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) {
1127/* LOG(llevDebug,"Can't open overlay %s\n", pathname);*/
1128 return m;
1129 }
1130
1131 object_thawer thawer (fp, pathname); 1109 object_thawer thawer (pathname);
1110
1111 if (!thawer)
1112 return m;
1132 1113
1133 if (load_map_header(thawer, m)) { 1114 if (load_map_header(thawer, m)) {
1134 LOG(llevError,"Error loading map header for overlay %s (%s)\n", 1115 LOG(llevError,"Error loading map header for overlay %s (%s)\n",
1135 m->path, pathname); 1116 m->path, pathname);
1136 delete_map(m); 1117 delete_map(m);
1139 } 1120 }
1140 /*allocate_map(m);*/ 1121 /*allocate_map(m);*/
1141 1122
1142 m->in_memory=MAP_LOADING; 1123 m->in_memory=MAP_LOADING;
1143 load_objects (m, thawer, MAP_OVERLAY); 1124 load_objects (m, thawer, MAP_OVERLAY);
1144 close_and_delete(fp, comp); 1125
1145 m->in_memory=MAP_IN_MEMORY; 1126 m->in_memory=MAP_IN_MEMORY;
1146 return m; 1127 return m;
1147} 1128}
1148 1129
1149/****************************************************************************** 1130/******************************************************************************
1178/* 1159/*
1179 * Loads unique objects from file(s) into the map which is in memory 1160 * Loads unique objects from file(s) into the map which is in memory
1180 * m is the map to load unique items into. 1161 * m is the map to load unique items into.
1181 */ 1162 */
1182static void load_unique_objects(mapstruct *m) { 1163static void load_unique_objects(mapstruct *m) {
1183 FILE *fp;
1184 int comp,count; 1164 int count;
1185 char firstname[MAX_BUF]; 1165 char firstname[MAX_BUF];
1186 1166
1187 for (count=0; count<10; count++) { 1167 for (count=0; count<10; count++) {
1188 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count); 1168 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count);
1189 if (!access(firstname, R_OK)) break; 1169 if (!access(firstname, R_OK)) break;
1190 } 1170 }
1191 /* If we get here, we did not find any map */ 1171 /* If we get here, we did not find any map */
1192 if (count==10) return; 1172 if (count==10) return;
1193 1173
1194 if ((fp=open_and_uncompress(firstname, 0, &comp))==NULL) {
1195 /* There is no expectation that every map will have unique items, but this
1196 * is debug output, so leave it in.
1197 */
1198 LOG(llevDebug, "Can't open unique items file for %s\n", create_items_path(m->path));
1199 return;
1200 }
1201
1202 object_thawer thawer (fp, firstname); 1174 object_thawer thawer (firstname);
1175
1176 if (!thawer)
1177 return;
1203 1178
1204 m->in_memory=MAP_LOADING; 1179 m->in_memory=MAP_LOADING;
1205 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1180 if (m->tmpname == NULL) /* if we have loaded unique items from */
1206 delete_unique_items(m); /* original map before, don't duplicate them */ 1181 delete_unique_items(m); /* original map before, don't duplicate them */
1207 load_object(thawer, NULL, LO_NOREAD,0);
1208 load_objects (m, thawer, 0); 1182 load_objects (m, thawer, 0);
1209 close_and_delete(fp, comp); 1183
1210 m->in_memory=MAP_IN_MEMORY; 1184 m->in_memory=MAP_IN_MEMORY;
1211} 1185}
1212 1186
1213 1187
1214/* 1188/*
1221 */ 1195 */
1222 1196
1223int 1197int
1224new_save_map (mapstruct * m, int flag) 1198new_save_map (mapstruct * m, int flag)
1225{ 1199{
1226 char filename[MAX_BUF], buf[MAX_BUF], buf_s[MAX_BUF], shop[MAX_BUF]; 1200 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1227 int i; 1201 int i;
1228 1202
1229 if (flag && !*m->path) 1203 if (flag && !*m->path)
1230 { 1204 {
1231 LOG (llevError, "Tried to save map without path.\n"); 1205 LOG (llevError, "Tried to save map without path.\n");
1248 } 1222 }
1249 else 1223 else
1250 { 1224 {
1251 if (!m->tmpname) 1225 if (!m->tmpname)
1252 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1226 m->tmpname = tempnam_local (settings.tmpdir, NULL);
1227
1253 strcpy (filename, m->tmpname); 1228 strcpy (filename, m->tmpname);
1254 } 1229 }
1255 1230
1256 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1231 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1257 m->in_memory = MAP_SAVING; 1232 m->in_memory = MAP_SAVING;
1258 1233
1259 object_freezer fp (filename); 1234 object_freezer freezer;
1260 1235
1261 /* legacy */ 1236 /* legacy */
1262 fprintf (fp, "arch map\n"); 1237 fprintf (freezer, "arch map\n");
1263 if (m->name) 1238 if (m->name)
1264 fprintf (fp, "name %s\n", m->name); 1239 fprintf (freezer, "name %s\n", m->name);
1265 if (!flag) 1240 if (!flag)
1266 fprintf (fp, "swap_time %d\n", m->swap_time); 1241 fprintf (freezer, "swap_time %d\n", m->swap_time);
1267 if (m->reset_timeout) 1242 if (m->reset_timeout)
1268 fprintf (fp, "reset_timeout %d\n", m->reset_timeout); 1243 fprintf (freezer, "reset_timeout %d\n", m->reset_timeout);
1269 if (m->fixed_resettime) 1244 if (m->fixed_resettime)
1270 fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); 1245 fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime);
1271 /* we unfortunately have no idea if this is a value the creator set 1246 /* we unfortunately have no idea if this is a value the creator set
1272 * or a difficulty value we generated when the map was first loaded 1247 * or a difficulty value we generated when the map was first loaded
1273 */ 1248 */
1274 if (m->difficulty) 1249 if (m->difficulty)
1275 fprintf (fp, "difficulty %d\n", m->difficulty); 1250 fprintf (freezer, "difficulty %d\n", m->difficulty);
1276 if (m->region) 1251 if (m->region)
1277 fprintf (fp, "region %s\n", m->region->name); 1252 fprintf (freezer, "region %s\n", m->region->name);
1278 if (m->shopitems) 1253 if (m->shopitems)
1279 { 1254 {
1280 print_shop_string (m, shop); 1255 print_shop_string (m, shop);
1281 fprintf (fp, "shopitems %s\n", shop); 1256 fprintf (freezer, "shopitems %s\n", shop);
1282 } 1257 }
1283 if (m->shopgreed) 1258 if (m->shopgreed)
1284 fprintf (fp, "shopgreed %f\n", m->shopgreed); 1259 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1285#ifndef WIN32 1260#ifndef WIN32
1286 if (m->shopmin) 1261 if (m->shopmin)
1287 fprintf (fp, "shopmin %llu\n", m->shopmin); 1262 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1288 if (m->shopmax) 1263 if (m->shopmax)
1289 fprintf (fp, "shopmax %llu\n", m->shopmax); 1264 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1290#else 1265#else
1291 if (m->shopmin) 1266 if (m->shopmin)
1292 fprintf (fp, "shopmin %I64u\n", m->shopmin); 1267 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1293 if (m->shopmax) 1268 if (m->shopmax)
1294 fprintf (fp, "shopmax %I64u\n", m->shopmax); 1269 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1295#endif 1270#endif
1296 if (m->shoprace) 1271 if (m->shoprace)
1297 fprintf (fp, "shoprace %s\n", m->shoprace); 1272 fprintf (freezer, "shoprace %s\n", m->shoprace);
1298 if (m->darkness) 1273 if (m->darkness)
1299 fprintf (fp, "darkness %d\n", m->darkness); 1274 fprintf (freezer, "darkness %d\n", m->darkness);
1300 if (m->width) 1275 if (m->width)
1301 fprintf (fp, "width %d\n", m->width); 1276 fprintf (freezer, "width %d\n", m->width);
1302 if (m->height) 1277 if (m->height)
1303 fprintf (fp, "height %d\n", m->height); 1278 fprintf (freezer, "height %d\n", m->height);
1304 if (m->enter_x) 1279 if (m->enter_x)
1305 fprintf (fp, "enter_x %d\n", m->enter_x); 1280 fprintf (freezer, "enter_x %d\n", m->enter_x);
1306 if (m->enter_y) 1281 if (m->enter_y)
1307 fprintf (fp, "enter_y %d\n", m->enter_y); 1282 fprintf (freezer, "enter_y %d\n", m->enter_y);
1308 if (m->msg) 1283 if (m->msg)
1309 fprintf (fp, "msg\n%sendmsg\n", m->msg); 1284 fprintf (freezer, "msg\n%sendmsg\n", m->msg);
1310 if (m->maplore) 1285 if (m->maplore)
1311 fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); 1286 fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore);
1312 if (m->unique) 1287 if (m->unique)
1313 fprintf (fp, "unique %d\n", m->unique); 1288 fprintf (freezer, "unique %d\n", m->unique);
1314 if (m->templatemap) 1289 if (m->templatemap)
1315 fprintf (fp, "template %d\n", m->templatemap); 1290 fprintf (freezer, "template %d\n", m->templatemap);
1316 if (m->outdoor) 1291 if (m->outdoor)
1317 fprintf (fp, "outdoor %d\n", m->outdoor); 1292 fprintf (freezer, "outdoor %d\n", m->outdoor);
1318 if (m->temp) 1293 if (m->temp)
1319 fprintf (fp, "temp %d\n", m->temp); 1294 fprintf (freezer, "temp %d\n", m->temp);
1320 if (m->pressure) 1295 if (m->pressure)
1321 fprintf (fp, "pressure %d\n", m->pressure); 1296 fprintf (freezer, "pressure %d\n", m->pressure);
1322 if (m->humid) 1297 if (m->humid)
1323 fprintf (fp, "humid %d\n", m->humid); 1298 fprintf (freezer, "humid %d\n", m->humid);
1324 if (m->windspeed) 1299 if (m->windspeed)
1325 fprintf (fp, "windspeed %d\n", m->windspeed); 1300 fprintf (freezer, "windspeed %d\n", m->windspeed);
1326 if (m->winddir) 1301 if (m->winddir)
1327 fprintf (fp, "winddir %d\n", m->winddir); 1302 fprintf (freezer, "winddir %d\n", m->winddir);
1328 if (m->sky) 1303 if (m->sky)
1329 fprintf (fp, "sky %d\n", m->sky); 1304 fprintf (freezer, "sky %d\n", m->sky);
1330 if (m->nosmooth) 1305 if (m->nosmooth)
1331 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1306 fprintf (freezer, "nosmooth %d\n", m->nosmooth);
1332 if (m->safe_map)
1333 fprintf (fp, "safe_map %d\n", m->safe_map);
1334 1307
1335 /* Save any tiling information, except on overlays */ 1308 /* Save any tiling information, except on overlays */
1336 if (flag != 2) 1309 if (flag != 2)
1337 for (i = 0; i < 4; i++) 1310 for (i = 0; i < 4; i++)
1338 if (m->tile_path[i]) 1311 if (m->tile_path[i])
1339 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); 1312 fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]);
1340 1313
1314 freezer.put (m);
1341 fprintf (fp, "end\n"); 1315 fprintf (freezer, "end\n");
1342 1316
1343 /* In the game save unique items in the different file, but 1317 /* In the game save unique items in the different file, but
1344 * in the editor save them to the normal map file. 1318 * in the editor save them to the normal map file.
1345 * If unique map, save files in the proper destination (set by 1319 * If unique map, save files in the proper destination (set by
1346 * player) 1320 * player)
1347 */ 1321 */
1348 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) 1322 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap)
1349 { 1323 {
1324 object_freezer unique;
1325
1326 if (flag == 2)
1327 save_objects (m, freezer, unique, 2);
1328 else
1329 save_objects (m, freezer, unique, 0);
1330
1350 sprintf (buf, "%s.v00", create_items_path (m->path)); 1331 sprintf (buf, "%s.v00", create_items_path (m->path));
1351 1332
1352 object_freezer fp2 (buf); 1333 unique.save (buf);
1353
1354 if (flag == 2)
1355 save_objects (m, fp, fp2, 2);
1356 else
1357 save_objects (m, fp, fp2, 0);
1358 } 1334 }
1359 else 1335 else
1360 { /* save same file when not playing, like in editor */ 1336 { /* save same file when not playing, like in editor */
1361 save_objects (m, fp, fp, 0); 1337 save_objects (m, freezer, freezer, 0);
1362 } 1338 }
1339
1340 freezer.save (filename);
1363 1341
1364 return 0; 1342 return 0;
1365} 1343}
1366 1344
1367 1345
1412 clean_object(op); 1390 clean_object(op);
1413 remove_ob(op); 1391 remove_ob(op);
1414 free_object(op); 1392 free_object(op);
1415 } 1393 }
1416 } 1394 }
1417#ifdef MANY_CORES
1418 /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1419 * an item on that map was not saved - look for that condition and die as appropriate -
1420 * this leaves more of the map data intact for better debugging.
1421 */
1422 for (op=objects; op!=NULL; op=op->next) {
1423 if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1424 LOG(llevDebug,"free_all_objects: object %s still on map after it should have been freed\n", op->name);
1425 abort();
1426 }
1427 }
1428#endif
1429} 1395}
1430 1396
1431/* 1397/*
1432 * Frees everything allocated by the given mapstructure. 1398 * Frees everything allocated by the given mapstructure.
1433 * don't free tmpname - our caller is left to do that 1399 * don't free tmpname - our caller is left to do that
1443 if (flag && m->spaces) free_all_objects(m); 1409 if (flag && m->spaces) free_all_objects(m);
1444 if (m->name) FREE_AND_CLEAR(m->name); 1410 if (m->name) FREE_AND_CLEAR(m->name);
1445 if (m->spaces) FREE_AND_CLEAR(m->spaces); 1411 if (m->spaces) FREE_AND_CLEAR(m->spaces);
1446 if (m->msg) FREE_AND_CLEAR(m->msg); 1412 if (m->msg) FREE_AND_CLEAR(m->msg);
1447 if (m->maplore) FREE_AND_CLEAR(m->maplore); 1413 if (m->maplore) FREE_AND_CLEAR(m->maplore);
1448 if (m->shopitems) FREE_AND_CLEAR(m->shopitems); 1414 if (m->shopitems) delete [] m->shopitems; m->shopitems = 0;
1449 if (m->shoprace) FREE_AND_CLEAR(m->shoprace); 1415 if (m->shoprace) FREE_AND_CLEAR(m->shoprace);
1450 if (m->buttons) 1416 if (m->buttons)
1451 free_objectlinkpt(m->buttons); 1417 free_objectlinkpt(m->buttons);
1452 m->buttons = NULL; 1418 m->buttons = NULL;
1453 for (i=0; i<4; i++) { 1419 for (i=0; i<4; i++) {
1513 m->path); 1479 m->path);
1514 } 1480 }
1515 else 1481 else
1516 last->next = m->next; 1482 last->next = m->next;
1517 1483
1518 free (m); 1484 delete m;
1519} 1485}
1520 1486
1521 1487
1522 1488
1523/* 1489/*
1566 if (flags & MAP_PLAYER_UNIQUE) 1532 if (flags & MAP_PLAYER_UNIQUE)
1567 LOG(llevDebug, "Trying to load map %s.\n", name); 1533 LOG(llevDebug, "Trying to load map %s.\n", name);
1568 else 1534 else
1569 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); 1535 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name));
1570 1536
1537 //eval_pv ("$x = Event::time", 1);//D
1571 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) 1538 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE))))
1572 return (NULL); 1539 return (NULL);
1540 //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1573 1541
1574 fix_auto_apply(m); /* Chests which open as default */ 1542 fix_auto_apply(m); /* Chests which open as default */
1575 1543
1576 /* If a player unique map, no extra unique object file to load. 1544 /* If a player unique map, no extra unique object file to load.
1577 * if from the editor, likewise. 1545 * if from the editor, likewise.
1578 */ 1546 */
1579 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE))) 1547 if (!(flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE)))
1580 load_unique_objects(m); 1548 load_unique_objects(m);
1581 1549
1582 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1550 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1583 m=load_overlay_map(name, m); 1551 m=load_overlay_map(name, m);
1584 if (m==NULL) 1552 if (m==NULL)
1585 return NULL; 1553 return NULL;
1586 } 1554 }
1555
1556 if (flags & MAP_PLAYER_UNIQUE)
1557 INVOKE_MAP (SWAPIN, m);
1587 1558
1588 } else { 1559 } else {
1589 /* If in this loop, we found a temporary map, so load it up. */ 1560 /* If in this loop, we found a temporary map, so load it up. */
1590 1561
1591 m=load_temporary_map (m); 1562 m=load_temporary_map (m);
1632 */ 1603 */
1633 1604
1634int calculate_difficulty(mapstruct *m) { 1605int calculate_difficulty(mapstruct *m) {
1635 object *op; 1606 object *op;
1636 archetype *at; 1607 archetype *at;
1637 int x, y, i, diff; 1608 int x, y, i;
1638 long monster_cnt = 0; 1609 long monster_cnt = 0;
1639 double avgexp = 0; 1610 double avgexp = 0;
1640 sint64 total_exp = 0; 1611 sint64 total_exp = 0;
1641 1612
1642 if (MAP_DIFFICULTY (m)) 1613 if (MAP_DIFFICULTY (m))
1832 if (QUERY_FLAG(tmp,FLAG_NO_MAGIC)) 1803 if (QUERY_FLAG(tmp,FLAG_NO_MAGIC))
1833 flags |= P_NO_MAGIC; 1804 flags |= P_NO_MAGIC;
1834 if (QUERY_FLAG(tmp,FLAG_DAMNED)) 1805 if (QUERY_FLAG(tmp,FLAG_DAMNED))
1835 flags |= P_NO_CLERIC; 1806 flags |= P_NO_CLERIC;
1836 if (tmp->type == SAFE_GROUND) 1807 if (tmp->type == SAFE_GROUND)
1837 flags |= P_SAFE | P_NO_CLERIC | P_NO_MAGIC; 1808 flags |= P_SAFE;
1838 1809
1839 if (QUERY_FLAG(tmp,FLAG_BLOCKSVIEW)) 1810 if (QUERY_FLAG(tmp,FLAG_BLOCKSVIEW))
1840 flags |= P_BLOCKSVIEW; 1811 flags |= P_BLOCKSVIEW;
1841 } /* for stack of objects */ 1812 } /* for stack of objects */
1842 1813

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines