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.22 by root, Mon Sep 4 11:07:59 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.22 2006/09/04 11:07:59 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
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 */
517 * file pointer. 503 * file pointer.
518 * mapflags is the same as we get with load_original_map 504 * mapflags is the same as we get with load_original_map
519 */ 505 */
520 506
521void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { 507void load_objects (mapstruct *m, object_thawer &fp, int mapflags) {
522 int i,j,bufstate=LO_NEWFILE; 508 int i,j;
523 int unique; 509 int unique;
524 object *op, *prev=NULL,*last_more=NULL, *otmp; 510 object *op, *prev=NULL,*last_more=NULL, *otmp;
525 511
526 op=get_object(); 512 op=get_object();
527 op->map = m; /* To handle buttons correctly */ 513 op->map = m; /* To handle buttons correctly */
528 514
529 while((i = load_object (fp, op, bufstate, mapflags))) { 515 while((i = load_object (fp, op, mapflags))) {
530 /* Since the loading of the map header does not load an object
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) {
541 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?op->name:"(null)"); 521 LOG(llevDebug,"Discarding object without arch: %s\n", op->name?(const char *)op->name:"(null)");
542 continue; 522 continue;
543 } 523 }
544 524
545 525
546 switch(i) { 526 switch(i) {
626 * Modified to no longer take a path option which was not being 606 * Modified to no longer take a path option which was not being
627 * used anyways. MSW 2001-07-01 607 * used anyways. MSW 2001-07-01
628 */ 608 */
629 609
630mapstruct *get_linked_map(void) { 610mapstruct *get_linked_map(void) {
631 mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); 611 mapstruct *map = new mapstruct;
632 mapstruct *mp; 612 mapstruct *mp;
633
634 if(map==NULL)
635 fatal(OUT_OF_MEMORY);
636 613
637 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next); 614 for(mp=first_map;mp!=NULL&&mp->next!=NULL;mp=mp->next);
638 if(mp==NULL) 615 if(mp==NULL)
639 first_map=map; 616 first_map=map;
640 else 617 else
823 value = NULL; 800 value = NULL;
824 break; 801 break;
825 } 802 }
826 } 803 }
827 } 804 }
805
828 if (!end) { 806 if (!end) {
829 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", 807 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n",
830 buf); 808 buf);
831 return 1; 809 return 1;
832 } 810 }
833
834 811
835 /* key is the field name, value is what it should be set 812 /* key is the field name, value is what it should be set
836 * to. We've already done the work to null terminate key, 813 * to. We've already done the work to null terminate key,
837 * and strip off any leading spaces for both of these. 814 * and strip off any leading spaces for both of these.
838 * We have not touched the newline at the end of the line - 815 * We have not touched the newline at the end of the line -
895 * for compatibility reasons. The new values (second) are 872 * for compatibility reasons. The new values (second) are
896 * what really should be used. 873 * what really should be used.
897 */ 874 */
898 else if (!strcmp(key,"oid")) { 875 else if (!strcmp(key,"oid")) {
899 fp.get (m, atoi(value)); 876 fp.get (m, atoi(value));
877 } else if (!strcmp(key, "attach")) {
878 m->attach = value;
900 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 879 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
901 m->enter_x = atoi(value); 880 m->enter_x = atoi(value);
902 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 881 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
903 m->enter_y = atoi(value); 882 m->enter_y = atoi(value);
904 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 883 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
947 m->winddir = atoi(value); 926 m->winddir = atoi(value);
948 } else if (!strcmp(key, "sky")) { 927 } else if (!strcmp(key, "sky")) {
949 m->sky = atoi(value); 928 m->sky = atoi(value);
950 } else if (!strcmp(key, "nosmooth")) { 929 } else if (!strcmp(key, "nosmooth")) {
951 m->nosmooth = atoi(value); 930 m->nosmooth = atoi(value);
952 } else if (!strcmp(key, "safe_map")) {
953 m->safe_map = atoi(value);
954 } 931 }
955 else if (!strncmp(key,"tile_path_", 10)) { 932 else if (!strncmp(key,"tile_path_", 10)) {
956 int tile=atoi(key+10); 933 int tile=atoi(key+10);
957 934
958 if (tile<1 || tile>4) { 935 if (tile<1 || tile>4) {
997 LOG(llevError,"Got unknown value in map header: %s %s\n", key, value); 974 LOG(llevError,"Got unknown value in map header: %s %s\n", key, value);
998 } 975 }
999 } 976 }
1000 if (!key || strcmp(key,"end")) { 977 if (!key || strcmp(key,"end")) {
1001 LOG(llevError,"Got premature eof on map header!\n"); 978 LOG(llevError,"Got premature eof on map header!\n");
979 abort();//D
1002 return 1; 980 return 1;
1003 } 981 }
1004 return 0; 982 return 0;
1005} 983}
1006 984
1015 * MAP_STYLE: style map - don't add active objects, don't add to server 993 * MAP_STYLE: style map - don't add active objects, don't add to server
1016 * managed map list. 994 * managed map list.
1017 */ 995 */
1018 996
1019mapstruct *load_original_map(const char *filename, int flags) { 997mapstruct *load_original_map(const char *filename, int flags) {
1020 FILE *fp;
1021 mapstruct *m; 998 mapstruct *m;
1022 int comp;
1023 char pathname[MAX_BUF]; 999 char pathname[MAX_BUF];
1024 1000
1025 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags);
1026 if (flags & MAP_PLAYER_UNIQUE) 1001 if (flags & MAP_PLAYER_UNIQUE)
1027 strcpy(pathname, filename); 1002 strcpy(pathname, filename);
1028 else if (flags & MAP_OVERLAY) 1003 else if (flags & MAP_OVERLAY)
1029 strcpy(pathname, create_overlay_pathname(filename)); 1004 strcpy(pathname, create_overlay_pathname(filename));
1030 else 1005 else
1031 strcpy(pathname, create_pathname(filename)); 1006 strcpy(pathname, create_pathname(filename));
1032 1007
1033 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) { 1008 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 1009
1038 object_thawer thawer (fp, filename); 1010 object_thawer thawer (pathname);
1011
1012 if (!thawer)
1013 return 0;
1039 1014
1040 m = get_linked_map(); 1015 m = get_linked_map();
1041 1016
1042 strcpy (m->path, filename); 1017 strcpy (m->path, filename);
1043 if (load_map_header(thawer, m)) { 1018 if (load_map_header(thawer, m)) {
1049 1024
1050 allocate_map(m); 1025 allocate_map(m);
1051 1026
1052 m->in_memory=MAP_LOADING; 1027 m->in_memory=MAP_LOADING;
1053 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); 1028 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE));
1054 close_and_delete(fp, comp); 1029
1055 m->in_memory=MAP_IN_MEMORY; 1030 m->in_memory=MAP_IN_MEMORY;
1056 if (!MAP_DIFFICULTY(m)) 1031 if (!MAP_DIFFICULTY(m))
1057 MAP_DIFFICULTY(m)=calculate_difficulty(m); 1032 MAP_DIFFICULTY(m)=calculate_difficulty(m);
1058 set_map_reset_time(m); 1033 set_map_reset_time(m);
1059 INVOKE_MAP (INSTANTIATE, m); 1034 m->instantiate ();
1060 return (m); 1035 return (m);
1061} 1036}
1062 1037
1063/* 1038/*
1064 * Loads a map, which has been loaded earlier, from file. 1039 * Loads a map, which has been loaded earlier, from file.
1065 * Return the map object we load into (this can change from the passed 1040 * Return the map object we load into (this can change from the passed
1066 * option if we can't find the original map) 1041 * option if we can't find the original map)
1067 */ 1042 */
1068 1043
1069static mapstruct *load_temporary_map(mapstruct *m) { 1044static mapstruct *load_temporary_map(mapstruct *m) {
1070 FILE *fp;
1071 int comp; 1045 int comp;
1072 char buf[MAX_BUF]; 1046 char buf[MAX_BUF];
1073 1047
1074 if (!m->tmpname) { 1048 if (!m->tmpname) {
1075 LOG(llevError, "No temporary filename for map %s\n", m->path); 1049 LOG(llevError, "No temporary filename for map %s\n", m->path);
1079 if(m==NULL) return NULL; 1053 if(m==NULL) return NULL;
1080 fix_auto_apply(m); /* Chests which open as default */ 1054 fix_auto_apply(m); /* Chests which open as default */
1081 return m; 1055 return m;
1082 } 1056 }
1083 1057
1084 if((fp=open_and_uncompress(m->tmpname,0, &comp))==NULL) { 1058 object_thawer thawer (m->tmpname);
1085 LOG(llevError, "Cannot open %s: %s\n",m->tmpname, strerror_local(errno)); 1059
1060 if (!thawer)
1061 {
1086 strcpy(buf, m->path); 1062 strcpy (buf, m->path);
1087 delete_map(m); 1063 delete_map (m);
1088 m = load_original_map(buf, 0); 1064 m = load_original_map (buf, 0);
1089 if(m==NULL) return NULL; 1065 if (!m) return NULL;
1090 fix_auto_apply(m); /* Chests which open as default */ 1066 fix_auto_apply (m); /* Chests which open as default */
1091 return m; 1067 return m;
1092 } 1068 }
1093
1094 object_thawer thawer (fp, m->tmpname);
1095 1069
1096 if (load_map_header(thawer, m)) { 1070 if (load_map_header(thawer, m)) {
1097 LOG(llevError,"Error loading map header for %s (%s)\n", 1071 LOG(llevError,"Error loading map header for %s (%s)\n",
1098 m->path, m->tmpname); 1072 m->path, m->tmpname);
1099 delete_map(m); 1073 delete_map(m);
1102 } 1076 }
1103 allocate_map(m); 1077 allocate_map(m);
1104 1078
1105 m->in_memory=MAP_LOADING; 1079 m->in_memory=MAP_LOADING;
1106 load_objects (m, thawer, 0); 1080 load_objects (m, thawer, 0);
1107 close_and_delete(fp, comp); 1081
1108 m->in_memory=MAP_IN_MEMORY; 1082 m->in_memory=MAP_IN_MEMORY;
1109 INVOKE_MAP (SWAPIN, m); 1083 INVOKE_MAP (SWAPIN, m);
1110 return m; 1084 return m;
1111} 1085}
1112 1086
1115 * Return the map object we load into (this can change from the passed 1089 * Return the map object we load into (this can change from the passed
1116 * option if we can't find the original map) 1090 * option if we can't find the original map)
1117 */ 1091 */
1118 1092
1119mapstruct *load_overlay_map(const char *filename, mapstruct *m) { 1093mapstruct *load_overlay_map(const char *filename, mapstruct *m) {
1120 FILE *fp;
1121 int comp;
1122 char pathname[MAX_BUF]; 1094 char pathname[MAX_BUF];
1123 1095
1124 strcpy(pathname, create_overlay_pathname(filename)); 1096 strcpy(pathname, create_overlay_pathname(filename));
1125 1097
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); 1098 object_thawer thawer (pathname);
1099
1100 if (!thawer)
1101 return m;
1132 1102
1133 if (load_map_header(thawer, m)) { 1103 if (load_map_header(thawer, m)) {
1134 LOG(llevError,"Error loading map header for overlay %s (%s)\n", 1104 LOG(llevError,"Error loading map header for overlay %s (%s)\n",
1135 m->path, pathname); 1105 m->path, pathname);
1136 delete_map(m); 1106 delete_map(m);
1139 } 1109 }
1140 /*allocate_map(m);*/ 1110 /*allocate_map(m);*/
1141 1111
1142 m->in_memory=MAP_LOADING; 1112 m->in_memory=MAP_LOADING;
1143 load_objects (m, thawer, MAP_OVERLAY); 1113 load_objects (m, thawer, MAP_OVERLAY);
1144 close_and_delete(fp, comp); 1114
1145 m->in_memory=MAP_IN_MEMORY; 1115 m->in_memory=MAP_IN_MEMORY;
1146 return m; 1116 return m;
1147} 1117}
1148 1118
1149/****************************************************************************** 1119/******************************************************************************
1178/* 1148/*
1179 * Loads unique objects from file(s) into the map which is in memory 1149 * Loads unique objects from file(s) into the map which is in memory
1180 * m is the map to load unique items into. 1150 * m is the map to load unique items into.
1181 */ 1151 */
1182static void load_unique_objects(mapstruct *m) { 1152static void load_unique_objects(mapstruct *m) {
1183 FILE *fp;
1184 int comp,count; 1153 int count;
1185 char firstname[MAX_BUF]; 1154 char firstname[MAX_BUF];
1186 1155
1187 for (count=0; count<10; count++) { 1156 for (count=0; count<10; count++) {
1188 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count); 1157 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count);
1189 if (!access(firstname, R_OK)) break; 1158 if (!access(firstname, R_OK)) break;
1190 } 1159 }
1191 /* If we get here, we did not find any map */ 1160 /* If we get here, we did not find any map */
1192 if (count==10) return; 1161 if (count==10) return;
1193 1162
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); 1163 object_thawer thawer (firstname);
1164
1165 if (!thawer)
1166 return;
1203 1167
1204 m->in_memory=MAP_LOADING; 1168 m->in_memory=MAP_LOADING;
1205 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1169 if (m->tmpname == NULL) /* if we have loaded unique items from */
1206 delete_unique_items(m); /* original map before, don't duplicate them */ 1170 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); 1171 load_objects (m, thawer, 0);
1209 close_and_delete(fp, comp); 1172
1210 m->in_memory=MAP_IN_MEMORY; 1173 m->in_memory=MAP_IN_MEMORY;
1211} 1174}
1212 1175
1213 1176
1214/* 1177/*
1248 } 1211 }
1249 else 1212 else
1250 { 1213 {
1251 if (!m->tmpname) 1214 if (!m->tmpname)
1252 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1215 m->tmpname = tempnam_local (settings.tmpdir, NULL);
1216
1253 strcpy (filename, m->tmpname); 1217 strcpy (filename, m->tmpname);
1254 } 1218 }
1255 1219
1256 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1220 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1257 m->in_memory = MAP_SAVING; 1221 m->in_memory = MAP_SAVING;
1258 1222
1259 object_freezer fp (filename); 1223 object_freezer freezer;
1260 1224
1261 /* legacy */ 1225 /* legacy */
1262 fprintf (fp, "arch map\n"); 1226 fprintf (freezer, "arch map\n");
1263 if (m->name) 1227 if (m->name)
1264 fprintf (fp, "name %s\n", m->name); 1228 fprintf (freezer, "name %s\n", m->name);
1265 if (!flag) 1229 if (!flag)
1266 fprintf (fp, "swap_time %d\n", m->swap_time); 1230 fprintf (freezer, "swap_time %d\n", m->swap_time);
1267 if (m->reset_timeout) 1231 if (m->reset_timeout)
1268 fprintf (fp, "reset_timeout %d\n", m->reset_timeout); 1232 fprintf (freezer, "reset_timeout %d\n", m->reset_timeout);
1269 if (m->fixed_resettime) 1233 if (m->fixed_resettime)
1270 fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); 1234 fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime);
1271 /* we unfortunately have no idea if this is a value the creator set 1235 /* 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 1236 * or a difficulty value we generated when the map was first loaded
1273 */ 1237 */
1274 if (m->difficulty) 1238 if (m->difficulty)
1275 fprintf (fp, "difficulty %d\n", m->difficulty); 1239 fprintf (freezer, "difficulty %d\n", m->difficulty);
1276 if (m->region) 1240 if (m->region)
1277 fprintf (fp, "region %s\n", m->region->name); 1241 fprintf (freezer, "region %s\n", m->region->name);
1278 if (m->shopitems) 1242 if (m->shopitems)
1279 { 1243 {
1280 print_shop_string (m, shop); 1244 print_shop_string (m, shop);
1281 fprintf (fp, "shopitems %s\n", shop); 1245 fprintf (freezer, "shopitems %s\n", shop);
1282 } 1246 }
1283 if (m->shopgreed) 1247 if (m->shopgreed)
1284 fprintf (fp, "shopgreed %f\n", m->shopgreed); 1248 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1285#ifndef WIN32 1249#ifndef WIN32
1286 if (m->shopmin) 1250 if (m->shopmin)
1287 fprintf (fp, "shopmin %llu\n", m->shopmin); 1251 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1288 if (m->shopmax) 1252 if (m->shopmax)
1289 fprintf (fp, "shopmax %llu\n", m->shopmax); 1253 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1290#else 1254#else
1291 if (m->shopmin) 1255 if (m->shopmin)
1292 fprintf (fp, "shopmin %I64u\n", m->shopmin); 1256 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1293 if (m->shopmax) 1257 if (m->shopmax)
1294 fprintf (fp, "shopmax %I64u\n", m->shopmax); 1258 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1295#endif 1259#endif
1296 if (m->shoprace) 1260 if (m->shoprace)
1297 fprintf (fp, "shoprace %s\n", m->shoprace); 1261 fprintf (freezer, "shoprace %s\n", m->shoprace);
1298 if (m->darkness) 1262 if (m->darkness)
1299 fprintf (fp, "darkness %d\n", m->darkness); 1263 fprintf (freezer, "darkness %d\n", m->darkness);
1300 if (m->width) 1264 if (m->width)
1301 fprintf (fp, "width %d\n", m->width); 1265 fprintf (freezer, "width %d\n", m->width);
1302 if (m->height) 1266 if (m->height)
1303 fprintf (fp, "height %d\n", m->height); 1267 fprintf (freezer, "height %d\n", m->height);
1304 if (m->enter_x) 1268 if (m->enter_x)
1305 fprintf (fp, "enter_x %d\n", m->enter_x); 1269 fprintf (freezer, "enter_x %d\n", m->enter_x);
1306 if (m->enter_y) 1270 if (m->enter_y)
1307 fprintf (fp, "enter_y %d\n", m->enter_y); 1271 fprintf (freezer, "enter_y %d\n", m->enter_y);
1308 if (m->msg) 1272 if (m->msg)
1309 fprintf (fp, "msg\n%sendmsg\n", m->msg); 1273 fprintf (freezer, "msg\n%sendmsg\n", m->msg);
1310 if (m->maplore) 1274 if (m->maplore)
1311 fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); 1275 fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore);
1312 if (m->unique) 1276 if (m->unique)
1313 fprintf (fp, "unique %d\n", m->unique); 1277 fprintf (freezer, "unique %d\n", m->unique);
1314 if (m->templatemap) 1278 if (m->templatemap)
1315 fprintf (fp, "template %d\n", m->templatemap); 1279 fprintf (freezer, "template %d\n", m->templatemap);
1316 if (m->outdoor) 1280 if (m->outdoor)
1317 fprintf (fp, "outdoor %d\n", m->outdoor); 1281 fprintf (freezer, "outdoor %d\n", m->outdoor);
1318 if (m->temp) 1282 if (m->temp)
1319 fprintf (fp, "temp %d\n", m->temp); 1283 fprintf (freezer, "temp %d\n", m->temp);
1320 if (m->pressure) 1284 if (m->pressure)
1321 fprintf (fp, "pressure %d\n", m->pressure); 1285 fprintf (freezer, "pressure %d\n", m->pressure);
1322 if (m->humid) 1286 if (m->humid)
1323 fprintf (fp, "humid %d\n", m->humid); 1287 fprintf (freezer, "humid %d\n", m->humid);
1324 if (m->windspeed) 1288 if (m->windspeed)
1325 fprintf (fp, "windspeed %d\n", m->windspeed); 1289 fprintf (freezer, "windspeed %d\n", m->windspeed);
1326 if (m->winddir) 1290 if (m->winddir)
1327 fprintf (fp, "winddir %d\n", m->winddir); 1291 fprintf (freezer, "winddir %d\n", m->winddir);
1328 if (m->sky) 1292 if (m->sky)
1329 fprintf (fp, "sky %d\n", m->sky); 1293 fprintf (freezer, "sky %d\n", m->sky);
1330 if (m->nosmooth) 1294 if (m->nosmooth)
1331 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1295 fprintf (freezer, "nosmooth %d\n", m->nosmooth);
1332 if (m->safe_map)
1333 fprintf (fp, "safe_map %d\n", m->safe_map);
1334 1296
1335 /* Save any tiling information, except on overlays */ 1297 /* Save any tiling information, except on overlays */
1336 if (flag != 2) 1298 if (flag != 2)
1337 for (i = 0; i < 4; i++) 1299 for (i = 0; i < 4; i++)
1338 if (m->tile_path[i]) 1300 if (m->tile_path[i])
1339 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); 1301 fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]);
1340 1302
1303 freezer.put (m);
1341 fprintf (fp, "end\n"); 1304 fprintf (freezer, "end\n");
1342 1305
1343 /* In the game save unique items in the different file, but 1306 /* In the game save unique items in the different file, but
1344 * in the editor save them to the normal map file. 1307 * in the editor save them to the normal map file.
1345 * If unique map, save files in the proper destination (set by 1308 * If unique map, save files in the proper destination (set by
1346 * player) 1309 * player)
1347 */ 1310 */
1348 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) 1311 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap)
1349 { 1312 {
1313 object_freezer unique;
1314
1315 if (flag == 2)
1316 save_objects (m, freezer, unique, 2);
1317 else
1318 save_objects (m, freezer, unique, 0);
1319
1350 sprintf (buf, "%s.v00", create_items_path (m->path)); 1320 sprintf (buf, "%s.v00", create_items_path (m->path));
1351 1321
1352 object_freezer fp2 (buf); 1322 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 } 1323 }
1359 else 1324 else
1360 { /* save same file when not playing, like in editor */ 1325 { /* save same file when not playing, like in editor */
1361 save_objects (m, fp, fp, 0); 1326 save_objects (m, freezer, freezer, 0);
1362 } 1327 }
1328
1329 freezer.save (filename);
1363 1330
1364 return 0; 1331 return 0;
1365} 1332}
1366 1333
1367 1334
1412 clean_object(op); 1379 clean_object(op);
1413 remove_ob(op); 1380 remove_ob(op);
1414 free_object(op); 1381 free_object(op);
1415 } 1382 }
1416 } 1383 }
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} 1384}
1430 1385
1431/* 1386/*
1432 * Frees everything allocated by the given mapstructure. 1387 * Frees everything allocated by the given mapstructure.
1433 * don't free tmpname - our caller is left to do that 1388 * don't free tmpname - our caller is left to do that
1513 m->path); 1468 m->path);
1514 } 1469 }
1515 else 1470 else
1516 last->next = m->next; 1471 last->next = m->next;
1517 1472
1518 free (m); 1473 delete m;
1519} 1474}
1520 1475
1521 1476
1522 1477
1523/* 1478/*
1566 if (flags & MAP_PLAYER_UNIQUE) 1521 if (flags & MAP_PLAYER_UNIQUE)
1567 LOG(llevDebug, "Trying to load map %s.\n", name); 1522 LOG(llevDebug, "Trying to load map %s.\n", name);
1568 else 1523 else
1569 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); 1524 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name));
1570 1525
1526 //0.427459955215454 /var/crossfire/players/Saladon/_scorn_apartment_apartments
1527 //0.414906024932861
1528 //0.427063941955566
1529 eval_pv ("$x = Event::time", 1);//D
1571 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) 1530 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE))))
1572 return (NULL); 1531 return (NULL);
1532 eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1573 1533
1574 fix_auto_apply(m); /* Chests which open as default */ 1534 fix_auto_apply(m); /* Chests which open as default */
1575 1535
1576 /* If a player unique map, no extra unique object file to load. 1536 /* If a player unique map, no extra unique object file to load.
1577 * if from the editor, likewise. 1537 * if from the editor, likewise.
1582 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1542 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1583 m=load_overlay_map(name, m); 1543 m=load_overlay_map(name, m);
1584 if (m==NULL) 1544 if (m==NULL)
1585 return NULL; 1545 return NULL;
1586 } 1546 }
1547
1548 if (flags & MAP_PLAYER_UNIQUE)
1549 INVOKE_MAP (SWAPIN, m);
1587 1550
1588 } else { 1551 } else {
1589 /* If in this loop, we found a temporary map, so load it up. */ 1552 /* If in this loop, we found a temporary map, so load it up. */
1590 1553
1591 m=load_temporary_map (m); 1554 m=load_temporary_map (m);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines