1 | /* |
1 | /* |
2 | * static char *rcsid_map_c = |
2 | * static char *rcsid_map_c = |
3 | * "$Id: map.C,v 1.18 2006/08/31 17:54:14 root Exp $"; |
3 | * "$Id: map.C,v 1.23 2006/09/04 15:51:24 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 | |
… | |
… | |
482 | op->x += tmp->x; |
482 | op->x += tmp->x; |
483 | op->y += tmp->y; |
483 | op->y += tmp->y; |
484 | op->head = tmp; |
484 | op->head = tmp; |
485 | op->map = m; |
485 | op->map = m; |
486 | last->more = op; |
486 | last->more = op; |
487 | if (tmp->name != op->name) { |
|
|
488 | if (op->name) free_string(op->name); |
|
|
489 | op->name = add_string(tmp->name); |
487 | op->name = tmp->name; |
490 | } |
|
|
491 | if (tmp->title != op->title) { |
|
|
492 | if (op->title) free_string(op->title); |
|
|
493 | op->title = add_string(tmp->title); |
488 | op->title = tmp->title; |
494 | } |
|
|
495 | /* we could link all the parts onto tmp, and then just |
489 | /* we could link all the parts onto tmp, and then just |
496 | * 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, |
497 | * 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 |
498 | * 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. |
499 | */ |
493 | */ |
… | |
… | |
509 | * file pointer. |
503 | * file pointer. |
510 | * mapflags is the same as we get with load_original_map |
504 | * mapflags is the same as we get with load_original_map |
511 | */ |
505 | */ |
512 | |
506 | |
513 | void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { |
507 | void load_objects (mapstruct *m, object_thawer &fp, int mapflags) { |
514 | int i,j,bufstate=LO_NEWFILE; |
508 | int i,j; |
515 | int unique; |
509 | int unique; |
516 | object *op, *prev=NULL,*last_more=NULL, *otmp; |
510 | object *op, *prev=NULL,*last_more=NULL, *otmp; |
517 | |
511 | |
518 | op=get_object(); |
512 | op=get_object(); |
519 | op->map = m; /* To handle buttons correctly */ |
513 | op->map = m; /* To handle buttons correctly */ |
520 | |
514 | |
521 | while((i = load_object (fp, op, bufstate, mapflags))) { |
515 | while((i = load_object (fp, op, mapflags))) { |
522 | /* Since the loading of the map header does not load an object |
|
|
523 | * anymore, we need to pass LO_NEWFILE for the first object loaded, |
|
|
524 | * and then switch to LO_REPEAT for faster loading. |
|
|
525 | */ |
|
|
526 | bufstate = LO_REPEAT; |
|
|
527 | |
|
|
528 | /* if the archetype for the object is null, means that we |
516 | /* if the archetype for the object is null, means that we |
529 | * 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 |
530 | * 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. |
531 | */ |
519 | */ |
532 | if (op->arch==NULL) { |
520 | if (op->arch==NULL) { |
… | |
… | |
618 | * 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 |
619 | * used anyways. MSW 2001-07-01 |
607 | * used anyways. MSW 2001-07-01 |
620 | */ |
608 | */ |
621 | |
609 | |
622 | mapstruct *get_linked_map(void) { |
610 | mapstruct *get_linked_map(void) { |
623 | mapstruct *map=(mapstruct *) calloc(1,sizeof(mapstruct)); |
611 | mapstruct *map = new mapstruct; |
624 | mapstruct *mp; |
612 | mapstruct *mp; |
625 | |
|
|
626 | if(map==NULL) |
|
|
627 | fatal(OUT_OF_MEMORY); |
|
|
628 | |
613 | |
629 | 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); |
630 | if(mp==NULL) |
615 | if(mp==NULL) |
631 | first_map=map; |
616 | first_map=map; |
632 | else |
617 | else |
… | |
… | |
815 | value = NULL; |
800 | value = NULL; |
816 | break; |
801 | break; |
817 | } |
802 | } |
818 | } |
803 | } |
819 | } |
804 | } |
|
|
805 | |
820 | if (!end) { |
806 | if (!end) { |
821 | 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", |
822 | buf); |
808 | buf); |
823 | return 1; |
809 | return 1; |
824 | } |
810 | } |
825 | |
|
|
826 | |
811 | |
827 | /* 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 |
828 | * to. We've already done the work to null terminate key, |
813 | * to. We've already done the work to null terminate key, |
829 | * and strip off any leading spaces for both of these. |
814 | * and strip off any leading spaces for both of these. |
830 | * 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 - |
… | |
… | |
888 | * what really should be used. |
873 | * what really should be used. |
889 | */ |
874 | */ |
890 | else if (!strcmp(key,"oid")) { |
875 | else if (!strcmp(key,"oid")) { |
891 | fp.get (m, atoi(value)); |
876 | fp.get (m, atoi(value)); |
892 | } else if (!strcmp(key, "attach")) { |
877 | } else if (!strcmp(key, "attach")) { |
893 | m->attach = add_string (value); |
878 | m->attach = value; |
894 | } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { |
879 | } else if (!strcmp(key,"hp") || !strcmp(key, "enter_x")) { |
895 | m->enter_x = atoi(value); |
880 | m->enter_x = atoi(value); |
896 | } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { |
881 | } else if (!strcmp(key,"sp") || !strcmp(key, "enter_y")) { |
897 | m->enter_y = atoi(value); |
882 | m->enter_y = atoi(value); |
898 | } else if (!strcmp(key,"x") || !strcmp(key, "width")) { |
883 | } else if (!strcmp(key,"x") || !strcmp(key, "width")) { |
… | |
… | |
1010 | |
995 | |
1011 | mapstruct *load_original_map(const char *filename, int flags) { |
996 | mapstruct *load_original_map(const char *filename, int flags) { |
1012 | mapstruct *m; |
997 | mapstruct *m; |
1013 | char pathname[MAX_BUF]; |
998 | char pathname[MAX_BUF]; |
1014 | |
999 | |
1015 | LOG(llevDebug, "load_original_map: %s (%x)\n", filename,flags); |
|
|
1016 | if (flags & MAP_PLAYER_UNIQUE) |
1000 | if (flags & MAP_PLAYER_UNIQUE) |
1017 | strcpy(pathname, filename); |
1001 | strcpy(pathname, filename); |
1018 | else if (flags & MAP_OVERLAY) |
1002 | else if (flags & MAP_OVERLAY) |
1019 | strcpy(pathname, create_overlay_pathname(filename)); |
1003 | strcpy(pathname, create_overlay_pathname(filename)); |
1020 | else |
1004 | else |
1021 | strcpy(pathname, create_pathname(filename)); |
1005 | strcpy(pathname, create_pathname(filename)); |
|
|
1006 | |
|
|
1007 | LOG(llevDebug, "load_original_map(%x): %s (%s)\n", flags, filename, pathname); |
1022 | |
1008 | |
1023 | object_thawer thawer (pathname); |
1009 | object_thawer thawer (pathname); |
1024 | |
1010 | |
1025 | if (!thawer) |
1011 | if (!thawer) |
1026 | return 0; |
1012 | return 0; |
… | |
… | |
1179 | return; |
1165 | return; |
1180 | |
1166 | |
1181 | m->in_memory=MAP_LOADING; |
1167 | m->in_memory=MAP_LOADING; |
1182 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1168 | if (m->tmpname == NULL) /* if we have loaded unique items from */ |
1183 | delete_unique_items(m); /* original map before, don't duplicate them */ |
1169 | delete_unique_items(m); /* original map before, don't duplicate them */ |
1184 | load_object(thawer, NULL, LO_NOREAD,0); |
|
|
1185 | load_objects (m, thawer, 0); |
1170 | load_objects (m, thawer, 0); |
1186 | |
1171 | |
1187 | m->in_memory=MAP_IN_MEMORY; |
1172 | m->in_memory=MAP_IN_MEMORY; |
1188 | } |
1173 | } |
1189 | |
1174 | |
… | |
… | |
1393 | clean_object(op); |
1378 | clean_object(op); |
1394 | remove_ob(op); |
1379 | remove_ob(op); |
1395 | free_object(op); |
1380 | free_object(op); |
1396 | } |
1381 | } |
1397 | } |
1382 | } |
1398 | #ifdef MANY_CORES |
|
|
1399 | /* I see periodic cores on metalforge where a map has been swapped out, but apparantly |
|
|
1400 | * an item on that map was not saved - look for that condition and die as appropriate - |
|
|
1401 | * this leaves more of the map data intact for better debugging. |
|
|
1402 | */ |
|
|
1403 | for (op=objects; op!=NULL; op=op->next) { |
|
|
1404 | if (!QUERY_FLAG(op, FLAG_REMOVED) && op->map == m) { |
|
|
1405 | LOG(llevDebug,"free_all_objects: object %s still on map after it should have been freed\n", op->name); |
|
|
1406 | abort(); |
|
|
1407 | } |
|
|
1408 | } |
|
|
1409 | #endif |
|
|
1410 | } |
1383 | } |
1411 | |
1384 | |
1412 | /* |
1385 | /* |
1413 | * Frees everything allocated by the given mapstructure. |
1386 | * Frees everything allocated by the given mapstructure. |
1414 | * don't free tmpname - our caller is left to do that |
1387 | * don't free tmpname - our caller is left to do that |
… | |
… | |
1494 | m->path); |
1467 | m->path); |
1495 | } |
1468 | } |
1496 | else |
1469 | else |
1497 | last->next = m->next; |
1470 | last->next = m->next; |
1498 | |
1471 | |
1499 | free (m); |
1472 | delete m; |
1500 | } |
1473 | } |
1501 | |
1474 | |
1502 | |
1475 | |
1503 | |
1476 | |
1504 | /* |
1477 | /* |
… | |
… | |
1547 | if (flags & MAP_PLAYER_UNIQUE) |
1520 | if (flags & MAP_PLAYER_UNIQUE) |
1548 | LOG(llevDebug, "Trying to load map %s.\n", name); |
1521 | LOG(llevDebug, "Trying to load map %s.\n", name); |
1549 | else |
1522 | else |
1550 | LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); |
1523 | LOG(llevDebug, "Trying to load map %s.\n", create_pathname(name)); |
1551 | |
1524 | |
|
|
1525 | //0.427459955215454 /var/crossfire/players/Saladon/_scorn_apartment_apartments |
|
|
1526 | //0.414906024932861 |
|
|
1527 | //0.427063941955566 |
|
|
1528 | eval_pv ("$x = Event::time", 1);//D |
1552 | if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) |
1529 | if (!(m = load_original_map(name, (flags & MAP_PLAYER_UNIQUE)))) |
1553 | return (NULL); |
1530 | return (NULL); |
|
|
1531 | eval_pv ("warn \"LOAD \", Event::time - $x", 1);//D |
1554 | |
1532 | |
1555 | fix_auto_apply(m); /* Chests which open as default */ |
1533 | fix_auto_apply(m); /* Chests which open as default */ |
1556 | |
1534 | |
1557 | /* If a player unique map, no extra unique object file to load. |
1535 | /* If a player unique map, no extra unique object file to load. |
1558 | * if from the editor, likewise. |
1536 | * if from the editor, likewise. |