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.15 by root, Wed Aug 30 08:28:32 2006 UTC vs.
Revision 1.27 by root, Fri Sep 8 12:56:42 2006 UTC

1/* 1/*
2 * static char *rcsid_map_c = 2 * static char *rcsid_map_c =
3 * "$Id: map.C,v 1.15 2006/08/30 08:28:32 root Exp $"; 3 * "$Id: map.C,v 1.27 2006/09/08 12:56:42 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) ||
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
711 number_of_entries++; 704 number_of_entries++;
712 if (p) p++; 705 if (p) p++;
713 } 706 }
714 p=shop_string; 707 p=shop_string;
715 strip_endline(p); 708 strip_endline(p);
716 items=(shopitems *) CALLOC(number_of_entries+1, sizeof(shopitems)); 709 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++) { 710 for (i=0; i<number_of_entries; i++) {
719 if (!p) { 711 if (!p) {
720 LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n"); 712 LOG(llevError, "parse_shop_string: I seem to have run out of string, that shouldn't happen.\n");
721 break; 713 break;
722 } 714 }
823 value = NULL; 815 value = NULL;
824 break; 816 break;
825 } 817 }
826 } 818 }
827 } 819 }
820
828 if (!end) { 821 if (!end) {
829 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n", 822 LOG(llevError, "Error loading map header - did not find a newline - perhaps file is truncated? Buf=%s\n",
830 buf); 823 buf);
831 return 1; 824 return 1;
832 } 825 }
833
834 826
835 /* key is the field name, value is what it should be set 827 /* key is the field name, value is what it should be set
836 * to. We've already done the work to null terminate key, 828 * to. We've already done the work to null terminate key,
837 * and strip off any leading spaces for both of these. 829 * and strip off any leading spaces for both of these.
838 * We have not touched the newline at the end of the line - 830 * We have not touched the newline at the end of the line -
896 * what really should be used. 888 * what really should be used.
897 */ 889 */
898 else if (!strcmp(key,"oid")) { 890 else if (!strcmp(key,"oid")) {
899 fp.get (m, atoi(value)); 891 fp.get (m, atoi(value));
900 } else if (!strcmp(key, "attach")) { 892 } else if (!strcmp(key, "attach")) {
901 m->attach = add_string (value); 893 m->attach = value;
902 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { 894 } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) {
903 m->enter_x = atoi(value); 895 m->enter_x = atoi(value);
904 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { 896 } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) {
905 m->enter_y = atoi(value); 897 m->enter_y = atoi(value);
906 } else if (!strcmp(key,"x") || !strcmp(key, "width")) { 898 } else if (!strcmp(key,"x") || !strcmp(key, "width")) {
1018 1010
1019mapstruct *load_original_map(const char *filename, int flags) { 1011mapstruct *load_original_map(const char *filename, int flags) {
1020 mapstruct *m; 1012 mapstruct *m;
1021 char pathname[MAX_BUF]; 1013 char pathname[MAX_BUF];
1022 1014
1023 LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags);
1024 if (flags & MAP_PLAYER_UNIQUE) 1015 if (flags & MAP_PLAYER_UNIQUE)
1025 strcpy(pathname, filename); 1016 strcpy(pathname, filename);
1026 else if (flags & MAP_OVERLAY) 1017 else if (flags & MAP_OVERLAY)
1027 strcpy(pathname, create_overlay_pathname(filename)); 1018 strcpy(pathname, create_overlay_pathname(filename));
1028 else 1019 else
1029 strcpy(pathname, create_pathname(filename)); 1020 strcpy(pathname, create_pathname(filename));
1030 1021
1022 LOG(llevDebug, "load_original_map(%x): %s (%s)\n", flags, filename, pathname);
1023
1031 object_thawer thawer (pathname); 1024 object_thawer thawer (pathname);
1032 1025
1033 if (!thawer) 1026 if (!thawer)
1034 return 0; 1027 return 0;
1035 1028
1061 * Return the map object we load into (this can change from the passed 1054 * Return the map object we load into (this can change from the passed
1062 * option if we can't find the original map) 1055 * option if we can't find the original map)
1063 */ 1056 */
1064 1057
1065static mapstruct *load_temporary_map(mapstruct *m) { 1058static mapstruct *load_temporary_map(mapstruct *m) {
1066 int comp;
1067 char buf[MAX_BUF]; 1059 char buf[MAX_BUF];
1068 1060
1069 if (!m->tmpname) { 1061 if (!m->tmpname) {
1070 LOG(llevError, "No temporary filename for map %s\n", m->path); 1062 LOG(llevError, "No temporary filename for map %s\n", m->path);
1071 strcpy(buf, m->path); 1063 strcpy(buf, m->path);
1187 return; 1179 return;
1188 1180
1189 m->in_memory=MAP_LOADING; 1181 m->in_memory=MAP_LOADING;
1190 if (m->tmpname == NULL) /* if we have loaded unique items from */ 1182 if (m->tmpname == NULL) /* if we have loaded unique items from */
1191 delete_unique_items(m); /* original map before, don't duplicate them */ 1183 delete_unique_items(m); /* original map before, don't duplicate them */
1192 load_object(thawer, NULL, LO_NOREAD,0);
1193 load_objects (m, thawer, 0); 1184 load_objects (m, thawer, 0);
1194 1185
1195 m->in_memory=MAP_IN_MEMORY; 1186 m->in_memory=MAP_IN_MEMORY;
1196} 1187}
1197 1188
1206 */ 1197 */
1207 1198
1208int 1199int
1209new_save_map (mapstruct * m, int flag) 1200new_save_map (mapstruct * m, int flag)
1210{ 1201{
1211 char filename[MAX_BUF], buf[MAX_BUF], buf_s[MAX_BUF], shop[MAX_BUF]; 1202 char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF];
1212 int i; 1203 int i;
1213 1204
1214 if (flag && !*m->path) 1205 if (flag && !*m->path)
1215 { 1206 {
1216 LOG (llevError, "Tried to save map without path.\n"); 1207 LOG (llevError, "Tried to save map without path.\n");
1233 } 1224 }
1234 else 1225 else
1235 { 1226 {
1236 if (!m->tmpname) 1227 if (!m->tmpname)
1237 m->tmpname = tempnam_local (settings.tmpdir, NULL); 1228 m->tmpname = tempnam_local (settings.tmpdir, NULL);
1229
1238 strcpy (filename, m->tmpname); 1230 strcpy (filename, m->tmpname);
1239 } 1231 }
1240 1232
1241 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); 1233 LOG (llevDebug, "Saving map %s to %s\n", m->path, filename);
1242 m->in_memory = MAP_SAVING; 1234 m->in_memory = MAP_SAVING;
1243 1235
1244 object_freezer fp (filename); 1236 object_freezer freezer;
1245 1237
1246 /* legacy */ 1238 /* legacy */
1247 fprintf (fp, "arch map\n"); 1239 fprintf (freezer, "arch map\n");
1248 if (m->name) 1240 if (m->name)
1249 fprintf (fp, "name %s\n", m->name); 1241 fprintf (freezer, "name %s\n", m->name);
1250 if (!flag) 1242 if (!flag)
1251 fprintf (fp, "swap_time %d\n", m->swap_time); 1243 fprintf (freezer, "swap_time %d\n", m->swap_time);
1252 if (m->reset_timeout) 1244 if (m->reset_timeout)
1253 fprintf (fp, "reset_timeout %d\n", m->reset_timeout); 1245 fprintf (freezer, "reset_timeout %d\n", m->reset_timeout);
1254 if (m->fixed_resettime) 1246 if (m->fixed_resettime)
1255 fprintf (fp, "fixed_resettime %d\n", m->fixed_resettime); 1247 fprintf (freezer, "fixed_resettime %d\n", m->fixed_resettime);
1256 /* we unfortunately have no idea if this is a value the creator set 1248 /* we unfortunately have no idea if this is a value the creator set
1257 * or a difficulty value we generated when the map was first loaded 1249 * or a difficulty value we generated when the map was first loaded
1258 */ 1250 */
1259 if (m->difficulty) 1251 if (m->difficulty)
1260 fprintf (fp, "difficulty %d\n", m->difficulty); 1252 fprintf (freezer, "difficulty %d\n", m->difficulty);
1261 if (m->region) 1253 if (m->region)
1262 fprintf (fp, "region %s\n", m->region->name); 1254 fprintf (freezer, "region %s\n", m->region->name);
1263 if (m->shopitems) 1255 if (m->shopitems)
1264 { 1256 {
1265 print_shop_string (m, shop); 1257 print_shop_string (m, shop);
1266 fprintf (fp, "shopitems %s\n", shop); 1258 fprintf (freezer, "shopitems %s\n", shop);
1267 } 1259 }
1268 if (m->shopgreed) 1260 if (m->shopgreed)
1269 fprintf (fp, "shopgreed %f\n", m->shopgreed); 1261 fprintf (freezer, "shopgreed %f\n", m->shopgreed);
1270#ifndef WIN32 1262#ifndef WIN32
1271 if (m->shopmin) 1263 if (m->shopmin)
1272 fprintf (fp, "shopmin %llu\n", m->shopmin); 1264 fprintf (freezer, "shopmin %llu\n", m->shopmin);
1273 if (m->shopmax) 1265 if (m->shopmax)
1274 fprintf (fp, "shopmax %llu\n", m->shopmax); 1266 fprintf (freezer, "shopmax %llu\n", m->shopmax);
1275#else 1267#else
1276 if (m->shopmin) 1268 if (m->shopmin)
1277 fprintf (fp, "shopmin %I64u\n", m->shopmin); 1269 fprintf (freezer, "shopmin %I64u\n", m->shopmin);
1278 if (m->shopmax) 1270 if (m->shopmax)
1279 fprintf (fp, "shopmax %I64u\n", m->shopmax); 1271 fprintf (freezer, "shopmax %I64u\n", m->shopmax);
1280#endif 1272#endif
1281 if (m->shoprace) 1273 if (m->shoprace)
1282 fprintf (fp, "shoprace %s\n", m->shoprace); 1274 fprintf (freezer, "shoprace %s\n", m->shoprace);
1283 if (m->darkness) 1275 if (m->darkness)
1284 fprintf (fp, "darkness %d\n", m->darkness); 1276 fprintf (freezer, "darkness %d\n", m->darkness);
1285 if (m->width) 1277 if (m->width)
1286 fprintf (fp, "width %d\n", m->width); 1278 fprintf (freezer, "width %d\n", m->width);
1287 if (m->height) 1279 if (m->height)
1288 fprintf (fp, "height %d\n", m->height); 1280 fprintf (freezer, "height %d\n", m->height);
1289 if (m->enter_x) 1281 if (m->enter_x)
1290 fprintf (fp, "enter_x %d\n", m->enter_x); 1282 fprintf (freezer, "enter_x %d\n", m->enter_x);
1291 if (m->enter_y) 1283 if (m->enter_y)
1292 fprintf (fp, "enter_y %d\n", m->enter_y); 1284 fprintf (freezer, "enter_y %d\n", m->enter_y);
1293 if (m->msg) 1285 if (m->msg)
1294 fprintf (fp, "msg\n%sendmsg\n", m->msg); 1286 fprintf (freezer, "msg\n%sendmsg\n", m->msg);
1295 if (m->maplore) 1287 if (m->maplore)
1296 fprintf (fp, "maplore\n%sendmaplore\n", m->maplore); 1288 fprintf (freezer, "maplore\n%sendmaplore\n", m->maplore);
1297 if (m->unique) 1289 if (m->unique)
1298 fprintf (fp, "unique %d\n", m->unique); 1290 fprintf (freezer, "unique %d\n", m->unique);
1299 if (m->templatemap) 1291 if (m->templatemap)
1300 fprintf (fp, "template %d\n", m->templatemap); 1292 fprintf (freezer, "template %d\n", m->templatemap);
1301 if (m->outdoor) 1293 if (m->outdoor)
1302 fprintf (fp, "outdoor %d\n", m->outdoor); 1294 fprintf (freezer, "outdoor %d\n", m->outdoor);
1303 if (m->temp) 1295 if (m->temp)
1304 fprintf (fp, "temp %d\n", m->temp); 1296 fprintf (freezer, "temp %d\n", m->temp);
1305 if (m->pressure) 1297 if (m->pressure)
1306 fprintf (fp, "pressure %d\n", m->pressure); 1298 fprintf (freezer, "pressure %d\n", m->pressure);
1307 if (m->humid) 1299 if (m->humid)
1308 fprintf (fp, "humid %d\n", m->humid); 1300 fprintf (freezer, "humid %d\n", m->humid);
1309 if (m->windspeed) 1301 if (m->windspeed)
1310 fprintf (fp, "windspeed %d\n", m->windspeed); 1302 fprintf (freezer, "windspeed %d\n", m->windspeed);
1311 if (m->winddir) 1303 if (m->winddir)
1312 fprintf (fp, "winddir %d\n", m->winddir); 1304 fprintf (freezer, "winddir %d\n", m->winddir);
1313 if (m->sky) 1305 if (m->sky)
1314 fprintf (fp, "sky %d\n", m->sky); 1306 fprintf (freezer, "sky %d\n", m->sky);
1315 if (m->nosmooth) 1307 if (m->nosmooth)
1316 fprintf (fp, "nosmooth %d\n", m->nosmooth); 1308 fprintf (freezer, "nosmooth %d\n", m->nosmooth);
1317 1309
1318 /* Save any tiling information, except on overlays */ 1310 /* Save any tiling information, except on overlays */
1319 if (flag != 2) 1311 if (flag != 2)
1320 for (i = 0; i < 4; i++) 1312 for (i = 0; i < 4; i++)
1321 if (m->tile_path[i]) 1313 if (m->tile_path[i])
1322 fprintf (fp, "tile_path_%d %s\n", i + 1, m->tile_path[i]); 1314 fprintf (freezer, "tile_path_%d %s\n", i + 1, m->tile_path[i]);
1323 1315
1324 fp.put (m); 1316 freezer.put (m);
1325 fprintf (fp, "end\n"); 1317 fprintf (freezer, "end\n");
1326 1318
1327 /* In the game save unique items in the different file, but 1319 /* In the game save unique items in the different file, but
1328 * in the editor save them to the normal map file. 1320 * in the editor save them to the normal map file.
1329 * If unique map, save files in the proper destination (set by 1321 * If unique map, save files in the proper destination (set by
1330 * player) 1322 * player)
1331 */ 1323 */
1332 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap) 1324 if ((flag == 0 || flag == 2) && !m->unique && !m->templatemap)
1333 { 1325 {
1326 object_freezer unique;
1327
1328 if (flag == 2)
1329 save_objects (m, freezer, unique, 2);
1330 else
1331 save_objects (m, freezer, unique, 0);
1332
1334 sprintf (buf, "%s.v00", create_items_path (m->path)); 1333 sprintf (buf, "%s.v00", create_items_path (m->path));
1335 1334
1336 object_freezer fp2 (buf); 1335 unique.save (buf);
1337
1338 if (flag == 2)
1339 save_objects (m, fp, fp2, 2);
1340 else
1341 save_objects (m, fp, fp2, 0);
1342 } 1336 }
1343 else 1337 else
1344 { /* save same file when not playing, like in editor */ 1338 { /* save same file when not playing, like in editor */
1345 save_objects (m, fp, fp, 0); 1339 save_objects (m, freezer, freezer, 0);
1346 } 1340 }
1341
1342 freezer.save (filename);
1347 1343
1348 return 0; 1344 return 0;
1349} 1345}
1350 1346
1351 1347
1396 clean_object(op); 1392 clean_object(op);
1397 remove_ob(op); 1393 remove_ob(op);
1398 free_object(op); 1394 free_object(op);
1399 } 1395 }
1400 } 1396 }
1401#ifdef MANY_CORES
1402 /* I see periodic cores on metalforge where a map has been swapped out, but apparantly
1403 * an item on that map was not saved - look for that condition and die as appropriate -
1404 * this leaves more of the map data intact for better debugging.
1405 */
1406 for (op=objects; op!=NULL; op=op->next) {
1407 if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) {
1408 LOG(llevDebug,"free_all_objects: object %s still on map after it should have been freed\n", op->name);
1409 abort();
1410 }
1411 }
1412#endif
1413} 1397}
1414 1398
1415/* 1399/*
1416 * Frees everything allocated by the given mapstructure. 1400 * Frees everything allocated by the given mapstructure.
1417 * don't free tmpname - our caller is left to do that 1401 * don't free tmpname - our caller is left to do that
1427 if (flag && m->spaces) free_all_objects(m); 1411 if (flag && m->spaces) free_all_objects(m);
1428 if (m->name) FREE_AND_CLEAR(m->name); 1412 if (m->name) FREE_AND_CLEAR(m->name);
1429 if (m->spaces) FREE_AND_CLEAR(m->spaces); 1413 if (m->spaces) FREE_AND_CLEAR(m->spaces);
1430 if (m->msg) FREE_AND_CLEAR(m->msg); 1414 if (m->msg) FREE_AND_CLEAR(m->msg);
1431 if (m->maplore) FREE_AND_CLEAR(m->maplore); 1415 if (m->maplore) FREE_AND_CLEAR(m->maplore);
1432 if (m->shopitems) FREE_AND_CLEAR(m->shopitems); 1416 if (m->shopitems) delete [] m->shopitems; m->shopitems = 0;
1433 if (m->shoprace) FREE_AND_CLEAR(m->shoprace); 1417 if (m->shoprace) FREE_AND_CLEAR(m->shoprace);
1434 if (m->buttons) 1418 if (m->buttons)
1435 free_objectlinkpt(m->buttons); 1419 free_objectlinkpt(m->buttons);
1436 m->buttons = NULL; 1420 m->buttons = NULL;
1437 for (i=0; i<4; i++) { 1421 for (i=0; i<4; i++) {
1497 m->path); 1481 m->path);
1498 } 1482 }
1499 else 1483 else
1500 last->next = m->next; 1484 last->next = m->next;
1501 1485
1502 free (m); 1486 delete m;
1503} 1487}
1504 1488
1505 1489
1506 1490
1507/* 1491/*
1550 if (flags & MAP_PLAYER_UNIQUE) 1534 if (flags & MAP_PLAYER_UNIQUE)
1551 LOG(llevDebug, "Trying to load map %s.\n", name); 1535 LOG(llevDebug, "Trying to load map %s.\n", name);
1552 else 1536 else
1553 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); 1537 LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name));
1554 1538
1539 //eval_pv ("$x = Event::time", 1);//D
1555 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) 1540 if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE))))
1556 return (NULL); 1541 return (NULL);
1542 //eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D
1557 1543
1558 fix_auto_apply(m); /* Chests which open as default */ 1544 fix_auto_apply(m); /* Chests which open as default */
1559 1545
1560 /* If a player unique map, no extra unique object file to load. 1546 /* If a player unique map, no extra unique object file to load.
1561 * if from the editor, likewise. 1547 * if from the editor, likewise.
1562 */ 1548 */
1563 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE))) 1549 if (!(flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE)))
1564 load_unique_objects(m); 1550 load_unique_objects(m);
1565 1551
1566 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) { 1552 if (! (flags & (MAP_FLUSH|MAP_PLAYER_UNIQUE|MAP_OVERLAY))) {
1567 m=load_overlay_map(name, m); 1553 m=load_overlay_map(name, m);
1568 if (m==NULL) 1554 if (m==NULL)
1619 */ 1605 */
1620 1606
1621int calculate_difficulty(mapstruct *m) { 1607int calculate_difficulty(mapstruct *m) {
1622 object *op; 1608 object *op;
1623 archetype *at; 1609 archetype *at;
1624 int x, y, i, diff; 1610 int x, y, i;
1625 long monster_cnt = 0; 1611 long monster_cnt = 0;
1626 double avgexp = 0; 1612 double avgexp = 0;
1627 sint64 total_exp = 0; 1613 sint64 total_exp = 0;
1628 1614
1629 if (MAP_DIFFICULTY (m)) 1615 if (MAP_DIFFICULTY (m))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines