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.13 by elmex, Tue Aug 29 09:35:51 2006 UTC vs.
Revision 1.26 by pippijn, Thu Sep 7 09:37:12 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.13 2006/08/29 09:35:51 elmex Exp $"; 3 * "$Id: map.C,v 1.26 2006/09/07 09:37:12 pippijn 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) ||
490 op->x += tmp->x; 482 op->x += tmp->x;
491 op->y += tmp->y; 483 op->y += tmp->y;
492 op->head = tmp; 484 op->head = tmp;
493 op->map = m; 485 op->map = m;
494 last->more = op; 486 last->more = op;
495 if (tmp->name != op->name) {
496 if (op->name) free_string(op->name);
497 op->name = add_string(tmp->name); 487 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); 488 op->title = tmp->title;
502 }
503 /* we could link all the parts onto tmp, and then just 489 /* we could link all the parts onto tmp, and then just
504 * call insert_ob_in_map once, but the effect is the same, 490 * 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 491 * 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. 492 * the coding is simpler to just to it here with each part.
507 */ 493 */
508 insert_ob_in_map(op, op->map, tmp,INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON); 494 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 */ 495 } /* for at = tmp->arch->more */
510 } /* for objects on this space */ 496 } /* for objects on this space */
511} 497}
512 498
513
514
515/* 499/*
516 * Loads (ands parses) the objects into a given map from the specified 500 * Loads (ands parses) the objects into a given map from the specified
517 * file pointer. 501 * file pointer.
518 * mapflags is the same as we get with load_original_map 502 * mapflags is the same as we get with load_original_map
519 */ 503 */
520 504void
521void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { 505load_objects (mapstruct *m, object_thawer &fp, int mapflags)
522 int i,j,bufstate=LO_NEWFILE; 506{
507 int i, j;
523 int unique; 508 int unique;
524 object *op, *prev=NULL,*last_more=NULL, *otmp; 509 object *op, *prev = NULL, *last_more = NULL, *otmp;
525 510
526 op=get_object(); 511 op = get_object ();
527 op->map = m; /* To handle buttons correctly */ 512 op->map = m; /* To handle buttons correctly */
528 513
529 while((i = load_object (fp, op, bufstate, mapflags))) { 514 while ((i = load_object (fp, op, mapflags)))
530 /* Since the loading of the map header does not load an object 515 {
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 516 /* if the archetype for the object is null, means that we
537 * got an invalid object. Don't do anything with it - the game 517 * 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. 518 * or editor will not be able to do anything with it either.
539 */ 519 */
540 if (op->arch==NULL) { 520 if (op->arch == NULL)
521 {
541 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?op->name:"(null)"); 522 LOG (llevDebug, "Discarding object without arch: %s\n",
523 op->name ? (const char *) op->name : "(null)");
542 continue; 524 continue;
525 }
526
527
528 switch (i)
543 } 529 {
544
545
546 switch(i) {
547 case LL_NORMAL: 530 case LL_NORMAL:
548 /* if we are loading an overlay, put the floors on the bottom */ 531 /* if we are loading an overlay, put the floors on the bottom */
549 if ((QUERY_FLAG(op, FLAG_IS_FLOOR) || 532 if ((QUERY_FLAG (op, FLAG_IS_FLOOR) ||
550 QUERY_FLAG(op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) 533 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); 534 insert_ob_in_map (op, m, op,
535 INS_NO_MERGE | INS_NO_WALK_ON |
536 INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD);
552 else 537 else
553 insert_ob_in_map(op,m,op,INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); 538 insert_ob_in_map (op, m, op,
539 INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP |
540 INS_MAP_LOAD);
554 541
555 if (op->inv) 542 if (op->inv)
556 sum_weight(op); 543 sum_weight (op);
557 544
558 prev=op,last_more=op; 545 prev = op, last_more = op;
559 break; 546 break;
560 547
561 case LL_MORE: 548 case LL_MORE:
562 insert_ob_in_map(op,m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); 549 insert_ob_in_map (op, m, op,
550 INS_NO_MERGE | INS_NO_WALK_ON |
551 INS_ABOVE_FLOOR_ONLY);
563 op->head=prev,last_more->more=op,last_more=op; 552 op->head = prev, last_more->more = op, last_more = op;
564 break; 553 break;
565 } 554 }
555
566 if (mapflags & MAP_STYLE) { 556 if (mapflags & MAP_STYLE)
567 remove_from_active_list(op); 557 remove_from_active_list (op);
568 } 558
569 op=get_object(); 559 op = get_object ();
570 op->map = m; 560 op->map = m;
571 } 561 }
562
572 for (i=0;i<m->width;i++){ 563 for (i = 0; i < m->width; i++)
564 {
573 for (j=0;j<m->height;j++){ 565 for (j = 0; j < m->height; j++)
566 {
574 unique =0; 567 unique = 0;
575 /* check for unique items, or unique squares */ 568 /* check for unique items, or unique squares */
576 for (otmp = get_map_ob(m, i, j); otmp; otmp = otmp->above) { 569 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)) 570 {
571 if (QUERY_FLAG (otmp, FLAG_UNIQUE)
572 || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL))
578 unique = 1; 573 unique = 1;
579 if (!(mapflags & (MAP_OVERLAY|MAP_PLAYER_UNIQUE) || unique)) 574 if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique))
580 SET_FLAG(otmp, FLAG_OBJ_ORIGINAL); 575 SET_FLAG (otmp, FLAG_OBJ_ORIGINAL);
581 } 576 }
582 } 577 }
583 } 578 }
579
584 free_object(op); 580 free_object (op);
585 link_multipart_objects(m); 581 link_multipart_objects (m);
586} 582}
587 583
588/* This saves all the objects on the map in a non destructive fashion. 584/* 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, 585 * 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 586 * 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 622 * Modified to no longer take a path option which was not being
627 * used anyways. MSW 2001-07-01 623 * used anyways. MSW 2001-07-01
628 */ 624 */
629 625
630mapstruct *get_linked_map(void) { 626mapstruct *get_linked_map(void) {
631 mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); 627 mapstruct *map = new mapstruct;
632 mapstruct *mp; 628 mapstruct *mp;
633
634 if(map==NULL)
635 fatal(OUT_OF_MEMORY);
636 629
637 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next); 630 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next);
638 if(mp==NULL) 631 if(mp==NULL)
639 first_map=map; 632 first_map=map;
640 else 633 else
823 value = NULL; 816 value = NULL;
824 break; 817 break;
825 } 818 }
826 } 819 }
827 } 820 }
821
828 if (!end) { 822 if (!end) {
829 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", 823 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n",
830 buf); 824 buf);
831 return 1; 825 return 1;
832 } 826 }
833
834 827
835 /* key is the field name, value is what it should be set 828 /* key is the field name, value is what it should be set
836 * to. We've already done the work to null terminate key, 829 * to. We've already done the work to null terminate key,
837 * and strip off any leading spaces for both of these. 830 * and strip off any leading spaces for both of these.
838 * We have not touched the newline at the end of the line - 831 * We have not touched the newline at the end of the line -
896 * what really should be used. 889 * what really should be used.
897 */ 890 */
898 else if (!strcmp(key,"oid")) { 891 else if (!strcmp(key,"oid")) {
899 fp.get (m, atoi(value)); 892 fp.get (m, atoi(value));
900 } else if (!strcmp(key, "attach")) { 893 } else if (!strcmp(key, "attach")) {
901 m->attach = add_string (value); 894 m->attach = value;
902 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 895 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
903 m->enter_x = atoi(value); 896 m->enter_x = atoi(value);
904 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 897 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
905 m->enter_y = atoi(value); 898 m->enter_y = atoi(value);
906 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 899 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
1015 * MAP_STYLE: style map - don't add active objects, don't add to server 1008 * MAP_STYLE: style map - don't add active objects, don't add to server
1016 * managed map list. 1009 * managed map list.
1017 */ 1010 */
1018 1011
1019mapstruct *load_original_map(const char *filename, int flags) { 1012mapstruct *load_original_map(const char *filename, int flags) {
1020 FILE *fp;
1021 mapstruct *m; 1013 mapstruct *m;
1022 int comp;
1023 char pathname[MAX_BUF]; 1014 char pathname[MAX_BUF];
1024 1015
1025 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags);
1026 if (flags & MAP_PLAYER_UNIQUE) 1016 if (flags & MAP_PLAYER_UNIQUE)
1027 strcpy(pathname, filename); 1017 strcpy(pathname, filename);
1028 else if (flags & MAP_OVERLAY) 1018 else if (flags & MAP_OVERLAY)
1029 strcpy(pathname, create_overlay_pathname(filename)); 1019 strcpy(pathname, create_overlay_pathname(filename));
1030 else 1020 else
1031 strcpy(pathname, create_pathname(filename)); 1021 strcpy(pathname, create_pathname(filename));
1032 1022
1033 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) { 1023 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 1024
1038 object_thawer thawer (fp, filename); 1025 object_thawer thawer (pathname);
1026
1027 if (!thawer)
1028 return 0;
1039 1029
1040 m = get_linked_map(); 1030 m = get_linked_map();
1041 1031
1042 strcpy (m->path, filename); 1032 strcpy (m->path, filename);
1043 if (load_map_header(thawer, m)) { 1033 if (load_map_header(thawer, m)) {
1049 1039
1050 allocate_map(m); 1040 allocate_map(m);
1051 1041
1052 m->in_memory=MAP_LOADING; 1042 m->in_memory=MAP_LOADING;
1053 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); 1043 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE));
1054 close_and_delete(fp, comp); 1044
1055 m->in_memory=MAP_IN_MEMORY; 1045 m->in_memory=MAP_IN_MEMORY;
1056 if (!MAP_DIFFICULTY(m)) 1046 if (!MAP_DIFFICULTY(m))
1057 MAP_DIFFICULTY(m)=calculate_difficulty(m); 1047 MAP_DIFFICULTY(m)=calculate_difficulty(m);
1058 set_map_reset_time(m); 1048 set_map_reset_time(m);
1059 m->instantiate (); 1049 m->instantiate ();
1065 * Return the map object we load into (this can change from the passed 1055 * Return the map object we load into (this can change from the passed
1066 * option if we can't find the original map) 1056 * option if we can't find the original map)
1067 */ 1057 */
1068 1058
1069static mapstruct *load_temporary_map(mapstruct *m) { 1059static mapstruct *load_temporary_map(mapstruct *m) {
1070 FILE *fp;
1071 int comp;
1072 char buf[MAX_BUF]; 1060 char buf[MAX_BUF];
1073 1061
1074 if (!m->tmpname) { 1062 if (!m->tmpname) {
1075 LOG(llevError, "No temporary filename for map %s\n", m->path); 1063 LOG(llevError, "No temporary filename for map %s\n", m->path);
1076 strcpy(buf, m->path); 1064 strcpy(buf, m->path);
1079 if(m==NULL) return NULL; 1067 if(m==NULL) return NULL;
1080 fix_auto_apply(m); /* Chests which open as default */ 1068 fix_auto_apply(m); /* Chests which open as default */
1081 return m; 1069 return m;
1082 } 1070 }
1083 1071
1084 if((fp=open_and_uncompress(m->tmpname,0, &comp))==NULL) { 1072 object_thawer thawer (m->tmpname);
1085 LOG(llevError, "Cannot open %s: %s\n",m->tmpname, strerror_local(errno)); 1073
1074 if (!thawer)
1075 {
1086 strcpy(buf, m->path); 1076 strcpy (buf, m->path);
1087 delete_map(m); 1077 delete_map (m);
1088 m = load_original_map(buf, 0); 1078 m = load_original_map (buf, 0);
1089 if(m==NULL) return NULL; 1079 if (!m) return NULL;
1090 fix_auto_apply(m); /* Chests which open as default */ 1080 fix_auto_apply (m); /* Chests which open as default */
1091 return m; 1081 return m;
1092 } 1082 }
1093
1094 object_thawer thawer (fp, m->tmpname);
1095 1083
1096 if (load_map_header(thawer, m)) { 1084 if (load_map_header(thawer, m)) {
1097 LOG(llevError,"Error loading map header for %s (%s)\n", 1085 LOG(llevError,"Error loading map header for %s (%s)\n",
1098 m->path, m->tmpname); 1086 m->path, m->tmpname);
1099 delete_map(m); 1087 delete_map(m);
1102 } 1090 }
1103 allocate_map(m); 1091 allocate_map(m);
1104 1092
1105 m->in_memory=MAP_LOADING; 1093 m->in_memory=MAP_LOADING;
1106 load_objects (m, thawer, 0); 1094 load_objects (m, thawer, 0);
1107 close_and_delete(fp, comp); 1095
1108 m->in_memory=MAP_IN_MEMORY; 1096 m->in_memory=MAP_IN_MEMORY;
1109 INVOKE_MAP (SWAPIN, m); 1097 INVOKE_MAP (SWAPIN, m);
1110 return m; 1098 return m;
1111} 1099}
1112 1100
1115 * Return the map object we load into (this can change from the passed 1103 * Return the map object we load into (this can change from the passed
1116 * option if we can't find the original map) 1104 * option if we can't find the original map)
1117 */ 1105 */
1118 1106
1119mapstruct *load_overlay_map(const char *filename, mapstruct *m) { 1107mapstruct *load_overlay_map(const char *filename, mapstruct *m) {
1120 FILE *fp;
1121 int comp;
1122 char pathname[MAX_BUF]; 1108 char pathname[MAX_BUF];
1123 1109
1124 strcpy(pathname, create_overlay_pathname(filename)); 1110 strcpy(pathname, create_overlay_pathname(filename));
1125 1111
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); 1112 object_thawer thawer (pathname);
1113
1114 if (!thawer)
1115 return m;
1132 1116
1133 if (load_map_header(thawer, m)) { 1117 if (load_map_header(thawer, m)) {
1134 LOG(llevError,"Error loading map header for overlay %s (%s)\n", 1118 LOG(llevError,"Error loading map header for overlay %s (%s)\n",
1135 m->path, pathname); 1119 m->path, pathname);
1136 delete_map(m); 1120 delete_map(m);
1139 } 1123 }
1140 /*allocate_map(m);*/ 1124 /*allocate_map(m);*/
1141 1125
1142 m->in_memory=MAP_LOADING; 1126 m->in_memory=MAP_LOADING;
1143 load_objects (m, thawer, MAP_OVERLAY); 1127 load_objects (m, thawer, MAP_OVERLAY);
1144 close_and_delete(fp, comp); 1128
1145 m->in_memory=MAP_IN_MEMORY; 1129 m->in_memory=MAP_IN_MEMORY;
1146 return m; 1130 return m;
1147} 1131}
1148 1132
1149/****************************************************************************** 1133/******************************************************************************
1178/* 1162/*
1179 * Loads unique objects from file(s) into the map which is in memory 1163 * Loads unique objects from file(s) into the map which is in memory
1180 * m is the map to load unique items into. 1164 * m is the map to load unique items into.
1181 */ 1165 */
1182static void load_unique_objects(mapstruct *m) { 1166static void load_unique_objects(mapstruct *m) {
1183 FILE *fp;
1184 int comp,count; 1167 int count;
1185 char firstname[MAX_BUF]; 1168 char firstname[MAX_BUF];
1186 1169
1187 for (count=0; count<10; count++) { 1170 for (count=0; count<10; count++) {
1188 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count); 1171 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count);
1189 if (!access(firstname, R_OK)) break; 1172 if (!access(firstname, R_OK)) break;
1190 } 1173 }
1191 /* If we get here, we did not find any map */ 1174 /* If we get here, we did not find any map */
1192 if (count==10) return; 1175 if (count==10) return;
1193 1176
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); 1177 object_thawer thawer (firstname);
1178
1179 if (!thawer)
1180 return;
1203 1181
1204 m->in_memory=MAP_LOADING; 1182 m->in_memory=MAP_LOADING;
1205 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1183 if (m->tmpname == NULL) /* if we have loaded unique items from */
1206 delete_unique_items(m); /* original map before, don't duplicate them */ 1184 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); 1185 load_objects (m, thawer, 0);
1209 close_and_delete(fp, comp); 1186
1210 m->in_memory=MAP_IN_MEMORY; 1187 m->in_memory=MAP_IN_MEMORY;
1211} 1188}
1212 1189
1213 1190
1214/* 1191/*
1221 */ 1198 */
1222 1199
1223int 1200int
1224new_save_map (mapstruct * m, int flag) 1201new_save_map (mapstruct * m, int flag)
1225{ 1202{
1226 char filename[MAX_BUF], buf[MAX_BUF], buf_s[MAX_BUF], shop[MAX_BUF]; 1203 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1227 int i; 1204 int i;
1228 1205
1229 if (flag && !*m->path) 1206 if (flag && !*m->path)
1230 { 1207 {
1231 LOG (llevError, "Tried to save map without path.\n"); 1208 LOG (llevError, "Tried to save map without path.\n");
1248 } 1225 }
1249 else 1226 else
1250 { 1227 {
1251 if (!m->tmpname) 1228 if (!m->tmpname)
1252 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1229 m->tmpname = tempnam_local (settings.tmpdir, NULL);
1230
1253 strcpy (filename, m->tmpname); 1231 strcpy (filename, m->tmpname);
1254 } 1232 }
1255 1233
1256 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1234 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1257 m->in_memory = MAP_SAVING; 1235 m->in_memory = MAP_SAVING;
1258 1236
1259 object_freezer fp (filename); 1237 object_freezer freezer;
1260 1238
1261 /* legacy */ 1239 /* legacy */
1262 fprintf (fp, "arch map\n"); 1240 fprintf (freezer, "arch map\n");
1263 if (m->name) 1241 if (m->name)
1264 fprintf (fp, "name %s\n", m->name); 1242 fprintf (freezer, "name %s\n", m->name);
1265 if (!flag) 1243 if (!flag)
1266 fprintf (fp, "swap_time %d\n", m->swap_time); 1244 fprintf (freezer, "swap_time %d\n", m->swap_time);
1267 if (m->reset_timeout) 1245 if (m->reset_timeout)
1268 fprintf (fp, "reset_timeout %d\n", m->reset_timeout); 1246 fprintf (freezer, "reset_timeout %d\n", m->reset_timeout);
1269 if (m->fixed_resettime) 1247 if (m->fixed_resettime)
1270 fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); 1248 fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime);
1271 /* we unfortunately have no idea if this is a value the creator set 1249 /* 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 1250 * or a difficulty value we generated when the map was first loaded
1273 */ 1251 */
1274 if (m->difficulty) 1252 if (m->difficulty)
1275 fprintf (fp, "difficulty %d\n", m->difficulty); 1253 fprintf (freezer, "difficulty %d\n", m->difficulty);
1276 if (m->region) 1254 if (m->region)
1277 fprintf (fp, "region %s\n", m->region->name); 1255 fprintf (freezer, "region %s\n", m->region->name);
1278 if (m->shopitems) 1256 if (m->shopitems)
1279 { 1257 {
1280 print_shop_string (m, shop); 1258 print_shop_string (m, shop);
1281 fprintf (fp, "shopitems %s\n", shop); 1259 fprintf (freezer, "shopitems %s\n", shop);
1282 } 1260 }
1283 if (m->shopgreed) 1261 if (m->shopgreed)
1284 fprintf (fp, "shopgreed %f\n", m->shopgreed); 1262 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1285#ifndef WIN32 1263#ifndef WIN32
1286 if (m->shopmin) 1264 if (m->shopmin)
1287 fprintf (fp, "shopmin %llu\n", m->shopmin); 1265 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1288 if (m->shopmax) 1266 if (m->shopmax)
1289 fprintf (fp, "shopmax %llu\n", m->shopmax); 1267 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1290#else 1268#else
1291 if (m->shopmin) 1269 if (m->shopmin)
1292 fprintf (fp, "shopmin %I64u\n", m->shopmin); 1270 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1293 if (m->shopmax) 1271 if (m->shopmax)
1294 fprintf (fp, "shopmax %I64u\n", m->shopmax); 1272 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1295#endif 1273#endif
1296 if (m->shoprace) 1274 if (m->shoprace)
1297 fprintf (fp, "shoprace %s\n", m->shoprace); 1275 fprintf (freezer, "shoprace %s\n", m->shoprace);
1298 if (m->darkness) 1276 if (m->darkness)
1299 fprintf (fp, "darkness %d\n", m->darkness); 1277 fprintf (freezer, "darkness %d\n", m->darkness);
1300 if (m->width) 1278 if (m->width)
1301 fprintf (fp, "width %d\n", m->width); 1279 fprintf (freezer, "width %d\n", m->width);
1302 if (m->height) 1280 if (m->height)
1303 fprintf (fp, "height %d\n", m->height); 1281 fprintf (freezer, "height %d\n", m->height);
1304 if (m->enter_x) 1282 if (m->enter_x)
1305 fprintf (fp, "enter_x %d\n", m->enter_x); 1283 fprintf (freezer, "enter_x %d\n", m->enter_x);
1306 if (m->enter_y) 1284 if (m->enter_y)
1307 fprintf (fp, "enter_y %d\n", m->enter_y); 1285 fprintf (freezer, "enter_y %d\n", m->enter_y);
1308 if (m->msg) 1286 if (m->msg)
1309 fprintf (fp, "msg\n%sendmsg\n", m->msg); 1287 fprintf (freezer, "msg\n%sendmsg\n", m->msg);
1310 if (m->maplore) 1288 if (m->maplore)
1311 fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); 1289 fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore);
1312 if (m->unique) 1290 if (m->unique)
1313 fprintf (fp, "unique %d\n", m->unique); 1291 fprintf (freezer, "unique %d\n", m->unique);
1314 if (m->templatemap) 1292 if (m->templatemap)
1315 fprintf (fp, "template %d\n", m->templatemap); 1293 fprintf (freezer, "template %d\n", m->templatemap);
1316 if (m->outdoor) 1294 if (m->outdoor)
1317 fprintf (fp, "outdoor %d\n", m->outdoor); 1295 fprintf (freezer, "outdoor %d\n", m->outdoor);
1318 if (m->temp) 1296 if (m->temp)
1319 fprintf (fp, "temp %d\n", m->temp); 1297 fprintf (freezer, "temp %d\n", m->temp);
1320 if (m->pressure) 1298 if (m->pressure)
1321 fprintf (fp, "pressure %d\n", m->pressure); 1299 fprintf (freezer, "pressure %d\n", m->pressure);
1322 if (m->humid) 1300 if (m->humid)
1323 fprintf (fp, "humid %d\n", m->humid); 1301 fprintf (freezer, "humid %d\n", m->humid);
1324 if (m->windspeed) 1302 if (m->windspeed)
1325 fprintf (fp, "windspeed %d\n", m->windspeed); 1303 fprintf (freezer, "windspeed %d\n", m->windspeed);
1326 if (m->winddir) 1304 if (m->winddir)
1327 fprintf (fp, "winddir %d\n", m->winddir); 1305 fprintf (freezer, "winddir %d\n", m->winddir);
1328 if (m->sky) 1306 if (m->sky)
1329 fprintf (fp, "sky %d\n", m->sky); 1307 fprintf (freezer, "sky %d\n", m->sky);
1330 if (m->nosmooth) 1308 if (m->nosmooth)
1331 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1309 fprintf (freezer, "nosmooth %d\n", m->nosmooth);
1332 1310
1333 /* Save any tiling information, except on overlays */ 1311 /* Save any tiling information, except on overlays */
1334 if (flag != 2) 1312 if (flag != 2)
1335 for (i = 0; i < 4; i++) 1313 for (i = 0; i < 4; i++)
1336 if (m->tile_path[i]) 1314 if (m->tile_path[i])
1337 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); 1315 fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]);
1338 1316
1339 fp.put (m); 1317 freezer.put (m);
1340 fprintf (fp, "end\n"); 1318 fprintf (freezer, "end\n");
1341 1319
1342 /* In the game save unique items in the different file, but 1320 /* In the game save unique items in the different file, but
1343 * in the editor save them to the normal map file. 1321 * in the editor save them to the normal map file.
1344 * If unique map, save files in the proper destination (set by 1322 * If unique map, save files in the proper destination (set by
1345 * player) 1323 * player)
1346 */ 1324 */
1347 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) 1325 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap)
1348 { 1326 {
1327 object_freezer unique;
1328
1329 if (flag == 2)
1330 save_objects (m, freezer, unique, 2);
1331 else
1332 save_objects (m, freezer, unique, 0);
1333
1349 sprintf (buf, "%s.v00", create_items_path (m->path)); 1334 sprintf (buf, "%s.v00", create_items_path (m->path));
1350 1335
1351 object_freezer fp2 (buf); 1336 unique.save (buf);
1352
1353 if (flag == 2)
1354 save_objects (m, fp, fp2, 2);
1355 else
1356 save_objects (m, fp, fp2, 0);
1357 } 1337 }
1358 else 1338 else
1359 { /* save same file when not playing, like in editor */ 1339 { /* save same file when not playing, like in editor */
1360 save_objects (m, fp, fp, 0); 1340 save_objects (m, freezer, freezer, 0);
1361 } 1341 }
1342
1343 freezer.save (filename);
1362 1344
1363 return 0; 1345 return 0;
1364} 1346}
1365 1347
1366 1348
1411 clean_object(op); 1393 clean_object(op);
1412 remove_ob(op); 1394 remove_ob(op);
1413 free_object(op); 1395 free_object(op);
1414 } 1396 }
1415 } 1397 }
1416#ifdef MANY_CORES
1417 /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1418 * an item on that map was not saved - look for that condition and die as appropriate -
1419 * this leaves more of the map data intact for better debugging.
1420 */
1421 for (op=objects; op!=NULL; op=op->next) {
1422 if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1423 LOG(llevDebug,"free_all_objects: object %s still on map after it should have been freed\n", op->name);
1424 abort();
1425 }
1426 }
1427#endif
1428} 1398}
1429 1399
1430/* 1400/*
1431 * Frees everything allocated by the given mapstructure. 1401 * Frees everything allocated by the given mapstructure.
1432 * don't free tmpname - our caller is left to do that 1402 * don't free tmpname - our caller is left to do that
1512 m->path); 1482 m->path);
1513 } 1483 }
1514 else 1484 else
1515 last->next = m->next; 1485 last->next = m->next;
1516 1486
1517 free (m); 1487 delete m;
1518} 1488}
1519 1489
1520 1490
1521 1491
1522/* 1492/*
1565 if (flags & MAP_PLAYER_UNIQUE) 1535 if (flags & MAP_PLAYER_UNIQUE)
1566 LOG(llevDebug, "Trying to load map %s.\n", name); 1536 LOG(llevDebug, "Trying to load map %s.\n", name);
1567 else 1537 else
1568 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); 1538 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name));
1569 1539
1540 //eval_pv ("$x = Event::time", 1);//D
1570 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) 1541 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE))))
1571 return (NULL); 1542 return (NULL);
1543 //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1572 1544
1573 fix_auto_apply(m); /* Chests which open as default */ 1545 fix_auto_apply(m); /* Chests which open as default */
1574 1546
1575 /* If a player unique map, no extra unique object file to load. 1547 /* If a player unique map, no extra unique object file to load.
1576 * if from the editor, likewise. 1548 * if from the editor, likewise.
1577 */ 1549 */
1578 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE))) 1550 if (!(flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE)))
1579 load_unique_objects(m); 1551 load_unique_objects(m);
1580 1552
1581 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1553 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1582 m=load_overlay_map(name, m); 1554 m=load_overlay_map(name, m);
1583 if (m==NULL) 1555 if (m==NULL)
1584 return NULL; 1556 return NULL;
1585 } 1557 }
1558
1559 if (flags & MAP_PLAYER_UNIQUE)
1560 INVOKE_MAP (SWAPIN, m);
1586 1561
1587 } else { 1562 } else {
1588 /* If in this loop, we found a temporary map, so load it up. */ 1563 /* If in this loop, we found a temporary map, so load it up. */
1589 1564
1590 m=load_temporary_map (m); 1565 m=load_temporary_map (m);
1631 */ 1606 */
1632 1607
1633int calculate_difficulty(mapstruct *m) { 1608int calculate_difficulty(mapstruct *m) {
1634 object *op; 1609 object *op;
1635 archetype *at; 1610 archetype *at;
1636 int x, y, i, diff; 1611 int x, y, i;
1637 long monster_cnt = 0; 1612 long monster_cnt = 0;
1638 double avgexp = 0; 1613 double avgexp = 0;
1639 sint64 total_exp = 0; 1614 sint64 total_exp = 0;
1640 1615
1641 if (MAP_DIFFICULTY (m)) 1616 if (MAP_DIFFICULTY (m))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines