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.10 by root, Mon Aug 28 14:05:23 2006 UTC vs.
Revision 1.21 by root, Sun Sep 3 22:45:55 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.10 2006/08/28 14:05:23 root Exp $"; 3 * "$Id: map.C,v 1.21 2006/09/03 22:45:55 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
793 * currently, there are few enough fields this is not a big deal. 770 * currently, there are few enough fields this is not a big deal.
794 * MSW 2001-07-01 771 * MSW 2001-07-01
795 * return 0 on success, 1 on failure. 772 * return 0 on success, 1 on failure.
796 */ 773 */
797 774
798static int load_map_header(FILE *fp, mapstruct *m) 775static int load_map_header(object_thawer &fp, mapstruct *m)
799{ 776{
800 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key=NULL, *value, *end; 777 char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key=NULL, *value, *end;
801 int msgpos=0; 778 int msgpos=0;
802 int maplorepos=0; 779 int maplorepos=0;
803 780
893 } 870 }
894 /* first strcmp value on these are old names supported 871 /* first strcmp value on these are old names supported
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 */
875 else if (!strcmp(key,"oid")) {
876 fp.get (m, atoi(value));
877 } else if (!strcmp(key, "attach")) {
878 m->attach = value;
898 else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 879 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
899 m->enter_x = atoi(value); 880 m->enter_x = atoi(value);
900 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 881 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
901 m->enter_y = atoi(value); 882 m->enter_y = atoi(value);
902 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 883 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
903 m->width = atoi(value); 884 m->width = atoi(value);
945 m->winddir = atoi(value); 926 m->winddir = atoi(value);
946 } else if (!strcmp(key, "sky")) { 927 } else if (!strcmp(key, "sky")) {
947 m->sky = atoi(value); 928 m->sky = atoi(value);
948 } else if (!strcmp(key, "nosmooth")) { 929 } else if (!strcmp(key, "nosmooth")) {
949 m->nosmooth = atoi(value); 930 m->nosmooth = atoi(value);
950 } else if (!strcmp(key, "safe_map")) {
951 m->safe_map = atoi(value);
952 } 931 }
953 else if (!strncmp(key,"tile_path_", 10)) { 932 else if (!strncmp(key,"tile_path_", 10)) {
954 int tile=atoi(key+10); 933 int tile=atoi(key+10);
955 934
956 if (tile<1 || tile>4) { 935 if (tile<1 || tile>4) {
1013 * MAP_STYLE: style map - don't add active objects, don't add to server 992 * MAP_STYLE: style map - don't add active objects, don't add to server
1014 * managed map list. 993 * managed map list.
1015 */ 994 */
1016 995
1017mapstruct *load_original_map(const char *filename, int flags) { 996mapstruct *load_original_map(const char *filename, int flags) {
1018 FILE *fp;
1019 mapstruct *m; 997 mapstruct *m;
1020 int comp;
1021 char pathname[MAX_BUF]; 998 char pathname[MAX_BUF];
1022 999
1023 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); 1000 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags);
1024 if (flags & MAP_PLAYER_UNIQUE) 1001 if (flags & MAP_PLAYER_UNIQUE)
1025 strcpy(pathname, filename); 1002 strcpy(pathname, filename);
1026 else if (flags & MAP_OVERLAY) 1003 else if (flags & MAP_OVERLAY)
1027 strcpy(pathname, create_overlay_pathname(filename)); 1004 strcpy(pathname, create_overlay_pathname(filename));
1028 else 1005 else
1029 strcpy(pathname, create_pathname(filename)); 1006 strcpy(pathname, create_pathname(filename));
1030 1007
1031 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) {
1032 LOG(llevError, "Can't open %s: %s\n", pathname, strerror_local(errno));
1033 return (NULL);
1034 }
1035
1036 object_thawer thawer (fp, filename); 1008 object_thawer thawer (pathname);
1009
1010 if (!thawer)
1011 return 0;
1037 1012
1038 m = get_linked_map(); 1013 m = get_linked_map();
1039 1014
1040 strcpy (m->path, filename); 1015 strcpy (m->path, filename);
1041 if (load_map_header(fp, m)) { 1016 if (load_map_header(thawer, m)) {
1042 LOG(llevError,"Error loading map header for %s, flags=%d\n", 1017 LOG(llevError,"Error loading map header for %s, flags=%d\n",
1043 filename, flags); 1018 filename, flags);
1044 delete_map(m); 1019 delete_map(m);
1045 return NULL; 1020 return NULL;
1046 } 1021 }
1047 1022
1048 allocate_map(m); 1023 allocate_map(m);
1049 1024
1050 m->in_memory=MAP_LOADING; 1025 m->in_memory=MAP_LOADING;
1051 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE)); 1026 load_objects (m, thawer, flags & (MAP_BLOCK|MAP_STYLE));
1052 close_and_delete(fp, comp); 1027
1053 m->in_memory=MAP_IN_MEMORY; 1028 m->in_memory=MAP_IN_MEMORY;
1054 if (!MAP_DIFFICULTY(m)) 1029 if (!MAP_DIFFICULTY(m))
1055 MAP_DIFFICULTY(m)=calculate_difficulty(m); 1030 MAP_DIFFICULTY(m)=calculate_difficulty(m);
1056 set_map_reset_time(m); 1031 set_map_reset_time(m);
1057 INVOKE_MAP (INSTANTIATE, m); 1032 m->instantiate ();
1058 return (m); 1033 return (m);
1059} 1034}
1060 1035
1061/* 1036/*
1062 * Loads a map, which has been loaded earlier, from file. 1037 * Loads a map, which has been loaded earlier, from file.
1063 * Return the map object we load into (this can change from the passed 1038 * Return the map object we load into (this can change from the passed
1064 * option if we can't find the original map) 1039 * option if we can't find the original map)
1065 */ 1040 */
1066 1041
1067static mapstruct *load_temporary_map(mapstruct *m) { 1042static mapstruct *load_temporary_map(mapstruct *m) {
1068 FILE *fp;
1069 int comp; 1043 int comp;
1070 char buf[MAX_BUF]; 1044 char buf[MAX_BUF];
1071 1045
1072 if (!m->tmpname) { 1046 if (!m->tmpname) {
1073 LOG(llevError, "No temporary filename for map %s\n", m->path); 1047 LOG(llevError, "No temporary filename for map %s\n", m->path);
1077 if(m==NULL) return NULL; 1051 if(m==NULL) return NULL;
1078 fix_auto_apply(m); /* Chests which open as default */ 1052 fix_auto_apply(m); /* Chests which open as default */
1079 return m; 1053 return m;
1080 } 1054 }
1081 1055
1082 if((fp=open_and_uncompress(m->tmpname,0, &comp))==NULL) { 1056 object_thawer thawer (m->tmpname);
1083 LOG(llevError, "Cannot open %s: %s\n",m->tmpname, strerror_local(errno)); 1057
1058 if (!thawer)
1059 {
1084 strcpy(buf, m->path); 1060 strcpy (buf, m->path);
1085 delete_map(m); 1061 delete_map (m);
1086 m = load_original_map(buf, 0); 1062 m = load_original_map (buf, 0);
1087 if(m==NULL) return NULL; 1063 if (!m) return NULL;
1088 fix_auto_apply(m); /* Chests which open as default */ 1064 fix_auto_apply (m); /* Chests which open as default */
1089 return m; 1065 return m;
1090 } 1066 }
1091
1092 object_thawer thawer (fp, m->tmpname);
1093 1067
1094 if (load_map_header(thawer, m)) { 1068 if (load_map_header(thawer, m)) {
1095 LOG(llevError,"Error loading map header for %s (%s)\n", 1069 LOG(llevError,"Error loading map header for %s (%s)\n",
1096 m->path, m->tmpname); 1070 m->path, m->tmpname);
1097 delete_map(m); 1071 delete_map(m);
1100 } 1074 }
1101 allocate_map(m); 1075 allocate_map(m);
1102 1076
1103 m->in_memory=MAP_LOADING; 1077 m->in_memory=MAP_LOADING;
1104 load_objects (m, thawer, 0); 1078 load_objects (m, thawer, 0);
1105 close_and_delete(fp, comp); 1079
1106 m->in_memory=MAP_IN_MEMORY; 1080 m->in_memory=MAP_IN_MEMORY;
1107 INVOKE_MAP (SWAPIN, m); 1081 INVOKE_MAP (SWAPIN, m);
1108 return m; 1082 return m;
1109} 1083}
1110 1084
1113 * Return the map object we load into (this can change from the passed 1087 * Return the map object we load into (this can change from the passed
1114 * option if we can't find the original map) 1088 * option if we can't find the original map)
1115 */ 1089 */
1116 1090
1117mapstruct *load_overlay_map(const char *filename, mapstruct *m) { 1091mapstruct *load_overlay_map(const char *filename, mapstruct *m) {
1118 FILE *fp;
1119 int comp;
1120 char pathname[MAX_BUF]; 1092 char pathname[MAX_BUF];
1121 1093
1122 strcpy(pathname, create_overlay_pathname(filename)); 1094 strcpy(pathname, create_overlay_pathname(filename));
1123 1095
1124 if((fp=open_and_uncompress(pathname, 0, &comp))==NULL) {
1125/* LOG(llevDebug,"Can't open overlay %s\n", pathname);*/
1126 return m;
1127 }
1128
1129 object_thawer thawer (fp, pathname); 1096 object_thawer thawer (pathname);
1097
1098 if (!thawer)
1099 return m;
1130 1100
1131 if (load_map_header(thawer, m)) { 1101 if (load_map_header(thawer, m)) {
1132 LOG(llevError,"Error loading map header for overlay %s (%s)\n", 1102 LOG(llevError,"Error loading map header for overlay %s (%s)\n",
1133 m->path, pathname); 1103 m->path, pathname);
1134 delete_map(m); 1104 delete_map(m);
1137 } 1107 }
1138 /*allocate_map(m);*/ 1108 /*allocate_map(m);*/
1139 1109
1140 m->in_memory=MAP_LOADING; 1110 m->in_memory=MAP_LOADING;
1141 load_objects (m, thawer, MAP_OVERLAY); 1111 load_objects (m, thawer, MAP_OVERLAY);
1142 close_and_delete(fp, comp); 1112
1143 m->in_memory=MAP_IN_MEMORY; 1113 m->in_memory=MAP_IN_MEMORY;
1144 return m; 1114 return m;
1145} 1115}
1146 1116
1147/****************************************************************************** 1117/******************************************************************************
1176/* 1146/*
1177 * Loads unique objects from file(s) into the map which is in memory 1147 * Loads unique objects from file(s) into the map which is in memory
1178 * m is the map to load unique items into. 1148 * m is the map to load unique items into.
1179 */ 1149 */
1180static void load_unique_objects(mapstruct *m) { 1150static void load_unique_objects(mapstruct *m) {
1181 FILE *fp;
1182 int comp,count; 1151 int count;
1183 char firstname[MAX_BUF]; 1152 char firstname[MAX_BUF];
1184 1153
1185 for (count=0; count<10; count++) { 1154 for (count=0; count<10; count++) {
1186 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count); 1155 sprintf(firstname, "%s.v%02d", create_items_path(m->path), count);
1187 if (!access(firstname, R_OK)) break; 1156 if (!access(firstname, R_OK)) break;
1188 } 1157 }
1189 /* If we get here, we did not find any map */ 1158 /* If we get here, we did not find any map */
1190 if (count==10) return; 1159 if (count==10) return;
1191 1160
1192 if ((fp=open_and_uncompress(firstname, 0, &comp))==NULL) {
1193 /* There is no expectation that every map will have unique items, but this
1194 * is debug output, so leave it in.
1195 */
1196 LOG(llevDebug, "Can't open unique items file for %s\n", create_items_path(m->path));
1197 return;
1198 }
1199
1200 object_thawer thawer (fp, firstname); 1161 object_thawer thawer (firstname);
1162
1163 if (!thawer)
1164 return;
1201 1165
1202 m->in_memory=MAP_LOADING; 1166 m->in_memory=MAP_LOADING;
1203 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1167 if (m->tmpname == NULL) /* if we have loaded unique items from */
1204 delete_unique_items(m); /* original map before, don't duplicate them */ 1168 delete_unique_items(m); /* original map before, don't duplicate them */
1205 load_object(thawer, NULL, LO_NOREAD,0);
1206 load_objects (m, thawer, 0); 1169 load_objects (m, thawer, 0);
1207 close_and_delete(fp, comp); 1170
1208 m->in_memory=MAP_IN_MEMORY; 1171 m->in_memory=MAP_IN_MEMORY;
1209} 1172}
1210 1173
1211 1174
1212/* 1175/*
1246 } 1209 }
1247 else 1210 else
1248 { 1211 {
1249 if (!m->tmpname) 1212 if (!m->tmpname)
1250 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1213 m->tmpname = tempnam_local (settings.tmpdir, NULL);
1214
1251 strcpy (filename, m->tmpname); 1215 strcpy (filename, m->tmpname);
1252 } 1216 }
1253 1217
1254 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1218 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1255 m->in_memory = MAP_SAVING; 1219 m->in_memory = MAP_SAVING;
1256 1220
1257 object_freezer fp (filename); 1221 object_freezer freezer;
1258 1222
1259 /* legacy */ 1223 /* legacy */
1260 fprintf (fp, "arch map\n"); 1224 fprintf (freezer, "arch map\n");
1261 if (m->name) 1225 if (m->name)
1262 fprintf (fp, "name %s\n", m->name); 1226 fprintf (freezer, "name %s\n", m->name);
1263 if (!flag) 1227 if (!flag)
1264 fprintf (fp, "swap_time %d\n", m->swap_time); 1228 fprintf (freezer, "swap_time %d\n", m->swap_time);
1265 if (m->reset_timeout) 1229 if (m->reset_timeout)
1266 fprintf (fp, "reset_timeout %d\n", m->reset_timeout); 1230 fprintf (freezer, "reset_timeout %d\n", m->reset_timeout);
1267 if (m->fixed_resettime) 1231 if (m->fixed_resettime)
1268 fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); 1232 fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime);
1269 /* we unfortunately have no idea if this is a value the creator set 1233 /* we unfortunately have no idea if this is a value the creator set
1270 * or a difficulty value we generated when the map was first loaded 1234 * or a difficulty value we generated when the map was first loaded
1271 */ 1235 */
1272 if (m->difficulty) 1236 if (m->difficulty)
1273 fprintf (fp, "difficulty %d\n", m->difficulty); 1237 fprintf (freezer, "difficulty %d\n", m->difficulty);
1274 if (m->region) 1238 if (m->region)
1275 fprintf (fp, "region %s\n", m->region->name); 1239 fprintf (freezer, "region %s\n", m->region->name);
1276 if (m->shopitems) 1240 if (m->shopitems)
1277 { 1241 {
1278 print_shop_string (m, shop); 1242 print_shop_string (m, shop);
1279 fprintf (fp, "shopitems %s\n", shop); 1243 fprintf (freezer, "shopitems %s\n", shop);
1280 } 1244 }
1281 if (m->shopgreed) 1245 if (m->shopgreed)
1282 fprintf (fp, "shopgreed %f\n", m->shopgreed); 1246 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1283#ifndef WIN32 1247#ifndef WIN32
1284 if (m->shopmin) 1248 if (m->shopmin)
1285 fprintf (fp, "shopmin %llu\n", m->shopmin); 1249 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1286 if (m->shopmax) 1250 if (m->shopmax)
1287 fprintf (fp, "shopmax %llu\n", m->shopmax); 1251 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1288#else 1252#else
1289 if (m->shopmin) 1253 if (m->shopmin)
1290 fprintf (fp, "shopmin %I64u\n", m->shopmin); 1254 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1291 if (m->shopmax) 1255 if (m->shopmax)
1292 fprintf (fp, "shopmax %I64u\n", m->shopmax); 1256 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1293#endif 1257#endif
1294 if (m->shoprace) 1258 if (m->shoprace)
1295 fprintf (fp, "shoprace %s\n", m->shoprace); 1259 fprintf (freezer, "shoprace %s\n", m->shoprace);
1296 if (m->darkness) 1260 if (m->darkness)
1297 fprintf (fp, "darkness %d\n", m->darkness); 1261 fprintf (freezer, "darkness %d\n", m->darkness);
1298 if (m->width) 1262 if (m->width)
1299 fprintf (fp, "width %d\n", m->width); 1263 fprintf (freezer, "width %d\n", m->width);
1300 if (m->height) 1264 if (m->height)
1301 fprintf (fp, "height %d\n", m->height); 1265 fprintf (freezer, "height %d\n", m->height);
1302 if (m->enter_x) 1266 if (m->enter_x)
1303 fprintf (fp, "enter_x %d\n", m->enter_x); 1267 fprintf (freezer, "enter_x %d\n", m->enter_x);
1304 if (m->enter_y) 1268 if (m->enter_y)
1305 fprintf (fp, "enter_y %d\n", m->enter_y); 1269 fprintf (freezer, "enter_y %d\n", m->enter_y);
1306 if (m->msg) 1270 if (m->msg)
1307 fprintf (fp, "msg\n%sendmsg\n", m->msg); 1271 fprintf (freezer, "msg\n%sendmsg\n", m->msg);
1308 if (m->maplore) 1272 if (m->maplore)
1309 fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); 1273 fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore);
1310 if (m->unique) 1274 if (m->unique)
1311 fprintf (fp, "unique %d\n", m->unique); 1275 fprintf (freezer, "unique %d\n", m->unique);
1312 if (m->templatemap) 1276 if (m->templatemap)
1313 fprintf (fp, "template %d\n", m->templatemap); 1277 fprintf (freezer, "template %d\n", m->templatemap);
1314 if (m->outdoor) 1278 if (m->outdoor)
1315 fprintf (fp, "outdoor %d\n", m->outdoor); 1279 fprintf (freezer, "outdoor %d\n", m->outdoor);
1316 if (m->temp) 1280 if (m->temp)
1317 fprintf (fp, "temp %d\n", m->temp); 1281 fprintf (freezer, "temp %d\n", m->temp);
1318 if (m->pressure) 1282 if (m->pressure)
1319 fprintf (fp, "pressure %d\n", m->pressure); 1283 fprintf (freezer, "pressure %d\n", m->pressure);
1320 if (m->humid) 1284 if (m->humid)
1321 fprintf (fp, "humid %d\n", m->humid); 1285 fprintf (freezer, "humid %d\n", m->humid);
1322 if (m->windspeed) 1286 if (m->windspeed)
1323 fprintf (fp, "windspeed %d\n", m->windspeed); 1287 fprintf (freezer, "windspeed %d\n", m->windspeed);
1324 if (m->winddir) 1288 if (m->winddir)
1325 fprintf (fp, "winddir %d\n", m->winddir); 1289 fprintf (freezer, "winddir %d\n", m->winddir);
1326 if (m->sky) 1290 if (m->sky)
1327 fprintf (fp, "sky %d\n", m->sky); 1291 fprintf (freezer, "sky %d\n", m->sky);
1328 if (m->nosmooth) 1292 if (m->nosmooth)
1329 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1293 fprintf (freezer, "nosmooth %d\n", m->nosmooth);
1330 if (m->safe_map)
1331 fprintf (fp, "safe_map %d\n", m->safe_map);
1332 1294
1333 /* Save any tiling information, except on overlays */ 1295 /* Save any tiling information, except on overlays */
1334 if (flag != 2) 1296 if (flag != 2)
1335 for (i = 0; i < 4; i++) 1297 for (i = 0; i < 4; i++)
1336 if (m->tile_path[i]) 1298 if (m->tile_path[i])
1337 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); 1299 fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]);
1338 1300
1301 freezer.put (m);
1339 fprintf (fp, "end\n"); 1302 fprintf (freezer, "end\n");
1340 1303
1341 /* In the game save unique items in the different file, but 1304 /* In the game save unique items in the different file, but
1342 * in the editor save them to the normal map file. 1305 * in the editor save them to the normal map file.
1343 * If unique map, save files in the proper destination (set by 1306 * If unique map, save files in the proper destination (set by
1344 * player) 1307 * player)
1345 */ 1308 */
1346 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) 1309 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap)
1347 { 1310 {
1311 object_freezer unique;
1312
1313 if (flag == 2)
1314 save_objects (m, freezer, unique, 2);
1315 else
1316 save_objects (m, freezer, unique, 0);
1317
1348 sprintf (buf, "%s.v00", create_items_path (m->path)); 1318 sprintf (buf, "%s.v00", create_items_path (m->path));
1349 1319
1350 object_freezer fp2 (buf); 1320 unique.save (buf);
1351
1352 if (flag == 2)
1353 save_objects (m, fp, fp2, 2);
1354 else
1355 save_objects (m, fp, fp2, 0);
1356 } 1321 }
1357 else 1322 else
1358 { /* save same file when not playing, like in editor */ 1323 { /* save same file when not playing, like in editor */
1359 save_objects (m, fp, fp, 0); 1324 save_objects (m, freezer, freezer, 0);
1360 } 1325 }
1326
1327 freezer.save (filename);
1361 1328
1362 return 0; 1329 return 0;
1363} 1330}
1364 1331
1365 1332
1410 clean_object(op); 1377 clean_object(op);
1411 remove_ob(op); 1378 remove_ob(op);
1412 free_object(op); 1379 free_object(op);
1413 } 1380 }
1414 } 1381 }
1415#ifdef MANY_CORES
1416 /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1417 * an item on that map was not saved - look for that condition and die as appropriate -
1418 * this leaves more of the map data intact for better debugging.
1419 */
1420 for (op=objects; op!=NULL; op=op->next) {
1421 if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1422 LOG(llevDebug,"free_all_objects: object %s still on map after it should have been freed\n", op->name);
1423 abort();
1424 }
1425 }
1426#endif
1427} 1382}
1428 1383
1429/* 1384/*
1430 * Frees everything allocated by the given mapstructure. 1385 * Frees everything allocated by the given mapstructure.
1431 * don't free tmpname - our caller is left to do that 1386 * don't free tmpname - our caller is left to do that
1466 mapstruct *tmp, *last; 1421 mapstruct *tmp, *last;
1467 int i; 1422 int i;
1468 1423
1469 if (!m) 1424 if (!m)
1470 return; 1425 return;
1426
1427 m->clear ();
1428
1471 if (m->in_memory == MAP_IN_MEMORY) { 1429 if (m->in_memory == MAP_IN_MEMORY) {
1472 /* change to MAP_SAVING, even though we are not, 1430 /* change to MAP_SAVING, even though we are not,
1473 * so that remove_ob doesn't do as much work. 1431 * so that remove_ob doesn't do as much work.
1474 */ 1432 */
1475 m->in_memory = MAP_SAVING; 1433 m->in_memory = MAP_SAVING;
1508 m->path); 1466 m->path);
1509 } 1467 }
1510 else 1468 else
1511 last->next = m->next; 1469 last->next = m->next;
1512 1470
1513 free (m); 1471 delete m;
1514} 1472}
1515 1473
1516 1474
1517 1475
1518/* 1476/*
1561 if (flags & MAP_PLAYER_UNIQUE) 1519 if (flags & MAP_PLAYER_UNIQUE)
1562 LOG(llevDebug, "Trying to load map %s.\n", name); 1520 LOG(llevDebug, "Trying to load map %s.\n", name);
1563 else 1521 else
1564 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); 1522 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name));
1565 1523
1524 //0.427459955215454 /var/crossfire/players/Saladon/_scorn_apartment_apartments
1525 //0.414906024932861
1526 //0.427063941955566
1527 eval_pv ("$x = Event::time", 1);//D
1566 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) 1528 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE))))
1567 return (NULL); 1529 return (NULL);
1530 eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1568 1531
1569 fix_auto_apply(m); /* Chests which open as default */ 1532 fix_auto_apply(m); /* Chests which open as default */
1570 1533
1571 /* If a player unique map, no extra unique object file to load. 1534 /* If a player unique map, no extra unique object file to load.
1572 * if from the editor, likewise. 1535 * if from the editor, likewise.
1577 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1540 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1578 m=load_overlay_map(name, m); 1541 m=load_overlay_map(name, m);
1579 if (m==NULL) 1542 if (m==NULL)
1580 return NULL; 1543 return NULL;
1581 } 1544 }
1545
1546 if (flags & MAP_PLAYER_UNIQUE)
1547 INVOKE_MAP (SWAPIN, m);
1582 1548
1583 } else { 1549 } else {
1584 /* If in this loop, we found a temporary map, so load it up. */ 1550 /* If in this loop, we found a temporary map, so load it up. */
1585 1551
1586 m=load_temporary_map (m); 1552 m=load_temporary_map (m);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines