… | |
… | |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <funcpoint.h> |
26 | #include <funcpoint.h> |
27 | |
27 | |
28 | #include <loader.h> |
28 | #include <loader.h> |
29 | #ifndef WIN32 /* ---win32 exclude header */ |
|
|
30 | # include <unistd.h> |
29 | #include <unistd.h> |
31 | #endif /* win32 */ |
|
|
32 | |
30 | |
33 | #include "path.h" |
31 | #include "path.h" |
34 | |
|
|
35 | |
|
|
36 | extern int nrofallocobjects, nroffreeobjects; |
|
|
37 | |
32 | |
38 | /* |
33 | /* |
39 | * Returns the maptile which has a name matching the given argument. |
34 | * Returns the maptile which has a name matching the given argument. |
40 | * return NULL if no match is found. |
35 | * return NULL if no match is found. |
41 | */ |
36 | */ |
… | |
… | |
159 | int |
154 | int |
160 | check_path (const char *name, int prepend_dir) |
155 | check_path (const char *name, int prepend_dir) |
161 | { |
156 | { |
162 | char buf[MAX_BUF]; |
157 | char buf[MAX_BUF]; |
163 | |
158 | |
164 | #ifndef WIN32 |
|
|
165 | char *endbuf; |
159 | char *endbuf; |
166 | struct stat statbuf; |
160 | struct stat statbuf; |
167 | int mode = 0; |
161 | int mode = 0; |
168 | #endif |
|
|
169 | |
162 | |
170 | if (prepend_dir) |
163 | if (prepend_dir) |
171 | strcpy (buf, create_pathname (name)); |
164 | strcpy (buf, create_pathname (name)); |
172 | else |
165 | else |
173 | strcpy (buf, name); |
166 | strcpy (buf, name); |
174 | #ifdef WIN32 /* ***win32: check this sucker in windows style. */ |
|
|
175 | return (_access (buf, 0)); |
|
|
176 | #else |
|
|
177 | |
167 | |
178 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
168 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
179 | * this method should be equivalant and is clearer. |
169 | * this method should be equivalant and is clearer. |
180 | * Can not use strcat because we need to cycle through |
170 | * Can not use strcat because we need to cycle through |
181 | * all the names. |
171 | * all the names. |
… | |
… | |
194 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
184 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
195 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
185 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
196 | mode |= 2; |
186 | mode |= 2; |
197 | |
187 | |
198 | return (mode); |
188 | return (mode); |
199 | #endif |
|
|
200 | } |
189 | } |
201 | |
190 | |
202 | /* |
191 | /* |
203 | * Prints out debug-information about a map. |
192 | * Prints out debug-information about a map. |
204 | * Dumping these at llevError doesn't seem right, but is |
193 | * Dumping these at llevError doesn't seem right, but is |
… | |
… | |
542 | { |
531 | { |
543 | int i, j; |
532 | int i, j; |
544 | int unique; |
533 | int unique; |
545 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
534 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
546 | |
535 | |
547 | op = get_object (); |
536 | op = object::create (); |
548 | op->map = m; /* To handle buttons correctly */ |
537 | op->map = m; /* To handle buttons correctly */ |
549 | |
538 | |
550 | while ((i = load_object (fp, op, mapflags))) |
539 | while ((i = load_object (fp, op, mapflags))) |
551 | { |
540 | { |
552 | /* if the archetype for the object is null, means that we |
541 | /* if the archetype for the object is null, means that we |
… | |
… | |
560 | } |
549 | } |
561 | |
550 | |
562 | |
551 | |
563 | switch (i) |
552 | switch (i) |
564 | { |
553 | { |
565 | case LL_NORMAL: |
554 | case LL_NORMAL: |
566 | /* if we are loading an overlay, put the floors on the bottom */ |
555 | /* if we are loading an overlay, put the floors on the bottom */ |
567 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
556 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
568 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
557 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
569 | else |
558 | else |
570 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
559 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
571 | |
560 | |
572 | if (op->inv) |
561 | if (op->inv) |
573 | sum_weight (op); |
562 | sum_weight (op); |
574 | |
563 | |
575 | prev = op, last_more = op; |
564 | prev = op, last_more = op; |
576 | break; |
565 | break; |
577 | |
566 | |
578 | case LL_MORE: |
567 | case LL_MORE: |
579 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
568 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
580 | op->head = prev, last_more->more = op, last_more = op; |
569 | op->head = prev, last_more->more = op, last_more = op; |
581 | break; |
570 | break; |
582 | } |
571 | } |
583 | |
572 | |
584 | if (mapflags & MAP_STYLE) |
573 | if (mapflags & MAP_STYLE) |
585 | remove_from_active_list (op); |
574 | remove_from_active_list (op); |
586 | |
575 | |
587 | op = get_object (); |
576 | op = object::create (); |
588 | op->map = m; |
577 | op->map = m; |
589 | } |
578 | } |
590 | |
579 | |
591 | for (i = 0; i < m->width; i++) |
580 | for (i = 0; i < m->width; i++) |
592 | { |
581 | { |
… | |
… | |
596 | /* check for unique items, or unique squares */ |
585 | /* check for unique items, or unique squares */ |
597 | for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) |
586 | for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) |
598 | { |
587 | { |
599 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
588 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
600 | unique = 1; |
589 | unique = 1; |
|
|
590 | |
601 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
591 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
602 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
592 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
603 | } |
593 | } |
604 | } |
594 | } |
605 | } |
595 | } |
606 | |
596 | |
607 | free_object (op); |
597 | op->destroy (); |
608 | link_multipart_objects (m); |
598 | link_multipart_objects (m); |
609 | } |
599 | } |
610 | |
600 | |
611 | /* This saves all the objects on the map in a non destructive fashion. |
601 | /* This saves all the objects on the map in a non destructive fashion. |
612 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
602 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
… | |
… | |
645 | |
635 | |
646 | } /* for this space */ |
636 | } /* for this space */ |
647 | } /* for this j */ |
637 | } /* for this j */ |
648 | } |
638 | } |
649 | |
639 | |
|
|
640 | maptile::maptile () |
|
|
641 | { |
|
|
642 | in_memory = MAP_SWAPPED; |
|
|
643 | /* The maps used to pick up default x and y values from the |
|
|
644 | * map archetype. Mimic that behaviour. |
|
|
645 | */ |
|
|
646 | MAP_WIDTH (this) = 16; |
|
|
647 | MAP_HEIGHT (this) = 16; |
|
|
648 | MAP_RESET_TIMEOUT (this) = 0; |
|
|
649 | MAP_TIMEOUT (this) = 300; |
|
|
650 | MAP_ENTER_X (this) = 0; |
|
|
651 | MAP_ENTER_Y (this) = 0; |
|
|
652 | /*set part to -1 indicating conversion to weather map not yet done */ |
|
|
653 | MAP_WORLDPARTX (this) = -1; |
|
|
654 | MAP_WORLDPARTY (this) = -1; |
|
|
655 | } |
|
|
656 | |
650 | /* |
657 | /* |
651 | * Allocates, initialises, and returns a pointer to a maptile. |
658 | * Allocates, initialises, and returns a pointer to a maptile. |
652 | * Modified to no longer take a path option which was not being |
659 | * Modified to no longer take a path option which was not being |
653 | * used anyways. MSW 2001-07-01 |
660 | * used anyways. MSW 2001-07-01 |
654 | */ |
661 | */ |
655 | |
|
|
656 | maptile * |
662 | maptile * |
657 | get_linked_map (void) |
663 | get_linked_map (void) |
658 | { |
664 | { |
659 | maptile *map = new maptile; |
665 | maptile *mp, *map = new maptile; |
660 | maptile *mp; |
|
|
661 | |
666 | |
662 | for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); |
667 | for (mp = first_map; mp && mp->next; mp = mp->next); |
|
|
668 | |
663 | if (mp == NULL) |
669 | if (mp == NULL) |
664 | first_map = map; |
670 | first_map = map; |
665 | else |
671 | else |
666 | mp->next = map; |
672 | mp->next = map; |
667 | |
673 | |
668 | map->in_memory = MAP_SWAPPED; |
|
|
669 | /* The maps used to pick up default x and y values from the |
|
|
670 | * map archetype. Mimic that behaviour. |
|
|
671 | */ |
|
|
672 | MAP_WIDTH (map) = 16; |
|
|
673 | MAP_HEIGHT (map) = 16; |
|
|
674 | MAP_RESET_TIMEOUT (map) = 0; |
|
|
675 | MAP_TIMEOUT (map) = 300; |
|
|
676 | MAP_ENTER_X (map) = 0; |
|
|
677 | MAP_ENTER_Y (map) = 0; |
|
|
678 | /*set part to -1 indicating conversion to weather map not yet done */ |
|
|
679 | MAP_WORLDPARTX (map) = -1; |
|
|
680 | MAP_WORLDPARTY (map) = -1; |
|
|
681 | return map; |
674 | return map; |
682 | } |
675 | } |
683 | |
676 | |
684 | /* |
677 | /* |
685 | * Allocates the arrays contained in a maptile. |
678 | * Allocates the arrays contained in a maptile. |
686 | * This basically allocates the dynamic array of spaces for the |
679 | * This basically allocates the dynamic array of spaces for the |
687 | * map. |
680 | * map. |
688 | */ |
681 | */ |
689 | |
|
|
690 | void |
682 | void |
691 | allocate_map (maptile *m) |
683 | maptile::allocate () |
692 | { |
684 | { |
693 | m->in_memory = MAP_IN_MEMORY; |
685 | in_memory = MAP_IN_MEMORY; |
|
|
686 | |
694 | /* Log this condition and free the storage. We could I suppose |
687 | /* Log this condition and free the storage. We could I suppose |
695 | * realloc, but if the caller is presuming the data will be intact, |
688 | * realloc, but if the caller is presuming the data will be intact, |
696 | * that is their poor assumption. |
689 | * that is their poor assumption. |
697 | */ |
690 | */ |
698 | if (m->spaces) |
691 | if (spaces) |
699 | { |
692 | { |
700 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); |
693 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
701 | free (m->spaces); |
694 | free (spaces); |
702 | } |
695 | } |
703 | |
696 | |
704 | m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); |
697 | spaces = (MapSpace *) |
|
|
698 | calloc (1, width * height * sizeof (MapSpace)); |
705 | |
699 | |
706 | if (m->spaces == NULL) |
700 | if (!spaces) |
707 | fatal (OUT_OF_MEMORY); |
701 | fatal (OUT_OF_MEMORY); |
708 | } |
702 | } |
709 | |
703 | |
710 | /* Create and returns a map of the specific size. Used |
704 | /* Create and returns a map of the specific size. Used |
711 | * in random map code and the editor. |
705 | * in random map code and the editor. |
… | |
… | |
716 | maptile *m = get_linked_map (); |
710 | maptile *m = get_linked_map (); |
717 | |
711 | |
718 | m->width = sizex; |
712 | m->width = sizex; |
719 | m->height = sizey; |
713 | m->height = sizey; |
720 | m->in_memory = MAP_SWAPPED; |
714 | m->in_memory = MAP_SWAPPED; |
721 | allocate_map (m); |
715 | m->allocate (); |
|
|
716 | |
722 | return m; |
717 | return m; |
723 | } |
718 | } |
724 | |
719 | |
725 | /* Takes a string from a map definition and outputs a pointer to the array of shopitems |
720 | /* Takes a string from a map definition and outputs a pointer to the array of shopitems |
726 | * corresponding to that string. Memory is allocated for this, it must be freed |
721 | * corresponding to that string. Memory is allocated for this, it must be freed |
… | |
… | |
734 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
729 | char *shop_string, *p, *q, *next_semicolon, *next_colon; |
735 | shopitems *items = NULL; |
730 | shopitems *items = NULL; |
736 | int i = 0, number_of_entries = 0; |
731 | int i = 0, number_of_entries = 0; |
737 | const typedata *current_type; |
732 | const typedata *current_type; |
738 | |
733 | |
739 | shop_string = strdup_local (input_string); |
734 | shop_string = strdup (input_string); |
740 | p = shop_string; |
735 | p = shop_string; |
741 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
736 | /* first we'll count the entries, we'll need that for allocating the array shortly */ |
742 | while (p) |
737 | while (p) |
743 | { |
738 | { |
744 | p = strchr (p, ';'); |
739 | p = strchr (p, ';'); |
… | |
… | |
853 | { |
848 | { |
854 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
849 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
855 | int msgpos = 0; |
850 | int msgpos = 0; |
856 | int maplorepos = 0; |
851 | int maplorepos = 0; |
857 | |
852 | |
858 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
853 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
859 | { |
854 | { |
860 | buf[HUGE_BUF - 1] = 0; |
855 | buf[HUGE_BUF - 1] = 0; |
861 | key = buf; |
856 | key = buf; |
|
|
857 | |
862 | while (isspace (*key)) |
858 | while (isspace (*key)) |
863 | key++; |
859 | key++; |
|
|
860 | |
864 | if (*key == 0) |
861 | if (*key == 0) |
865 | continue; /* empty line */ |
862 | continue; /* empty line */ |
|
|
863 | |
866 | value = strchr (key, ' '); |
864 | value = strchr (key, ' '); |
|
|
865 | |
867 | if (!value) |
866 | if (!value) |
868 | { |
867 | { |
869 | end = strchr (key, '\n'); |
868 | if ((end = strchr (key, '\n'))) |
870 | if (end != NULL) |
|
|
871 | { |
|
|
872 | *end = 0; |
869 | *end = 0; |
873 | } |
|
|
874 | } |
870 | } |
875 | else |
871 | else |
876 | { |
872 | { |
877 | *value = 0; |
873 | *value = 0; |
878 | value++; |
874 | value++; |
879 | end = strchr (value, '\n'); |
875 | end = strchr (value, '\n'); |
|
|
876 | |
880 | while (isspace (*value)) |
877 | while (isspace (*value)) |
881 | { |
878 | { |
882 | value++; |
879 | value++; |
|
|
880 | |
883 | if (*value == '\0' || value == end) |
881 | if (*value == '\0' || value == end) |
884 | { |
882 | { |
885 | /* Nothing but spaces. */ |
883 | /* Nothing but spaces. */ |
886 | value = NULL; |
884 | value = NULL; |
887 | break; |
885 | break; |
… | |
… | |
910 | * that use the parameter. |
908 | * that use the parameter. |
911 | */ |
909 | */ |
912 | |
910 | |
913 | if (!strcmp (key, "msg")) |
911 | if (!strcmp (key, "msg")) |
914 | { |
912 | { |
915 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
913 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
916 | { |
914 | { |
917 | if (!strcmp (buf, "endmsg\n")) |
915 | if (!strcmp (buf, "endmsg\n")) |
918 | break; |
916 | break; |
919 | else |
917 | else |
920 | { |
918 | { |
… | |
… | |
927 | * with nothing between). There is no reason in those cases to |
925 | * with nothing between). There is no reason in those cases to |
928 | * keep the empty message. Also, msgbuf contains garbage data |
926 | * keep the empty message. Also, msgbuf contains garbage data |
929 | * when msgpos is zero, so copying it results in crashes |
927 | * when msgpos is zero, so copying it results in crashes |
930 | */ |
928 | */ |
931 | if (msgpos != 0) |
929 | if (msgpos != 0) |
932 | m->msg = strdup_local (msgbuf); |
930 | m->msg = strdup (msgbuf); |
933 | } |
931 | } |
934 | else if (!strcmp (key, "maplore")) |
932 | else if (!strcmp (key, "maplore")) |
935 | { |
933 | { |
936 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
934 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
937 | { |
935 | { |
938 | if (!strcmp (buf, "endmaplore\n")) |
936 | if (!strcmp (buf, "endmaplore\n")) |
939 | break; |
937 | break; |
940 | else |
938 | else |
941 | { |
939 | { |
… | |
… | |
943 | strcpy (maplorebuf + maplorepos, buf); |
941 | strcpy (maplorebuf + maplorepos, buf); |
944 | maplorepos += strlen (buf); |
942 | maplorepos += strlen (buf); |
945 | } |
943 | } |
946 | } |
944 | } |
947 | if (maplorepos != 0) |
945 | if (maplorepos != 0) |
948 | m->maplore = strdup_local (maplorebuf); |
946 | m->maplore = strdup (maplorebuf); |
949 | } |
947 | } |
950 | else if (!strcmp (key, "end")) |
948 | else if (!strcmp (key, "end")) |
951 | { |
949 | { |
952 | break; |
950 | break; |
953 | } |
951 | } |
… | |
… | |
962 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
960 | LOG (llevError, "loading map and got a non 'arch map' line(%s %s)?\n", key, value); |
963 | } |
961 | } |
964 | else if (!strcmp (key, "name")) |
962 | else if (!strcmp (key, "name")) |
965 | { |
963 | { |
966 | *end = 0; |
964 | *end = 0; |
967 | m->name = strdup_local (value); |
965 | m->name = strdup (value); |
968 | } |
966 | } |
969 | /* first strcmp value on these are old names supported |
967 | /* first strcmp value on these are old names supported |
970 | * for compatibility reasons. The new values (second) are |
968 | * for compatibility reasons. The new values (second) are |
971 | * what really should be used. |
969 | * what really should be used. |
972 | */ |
970 | */ |
973 | else if (!strcmp (key, "oid")) |
971 | else if (!strcmp (key, "oid")) |
974 | { |
|
|
975 | fp.get (m, atoi (value)); |
972 | fp.get (m, atoi (value)); |
976 | } |
|
|
977 | else if (!strcmp (key, "attach")) |
973 | else if (!strcmp (key, "attach")) |
978 | { |
|
|
979 | m->attach = value; |
974 | m->attach = value; |
980 | } |
|
|
981 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
975 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
982 | { |
|
|
983 | m->enter_x = atoi (value); |
976 | m->enter_x = atoi (value); |
984 | } |
|
|
985 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
977 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
986 | { |
|
|
987 | m->enter_y = atoi (value); |
978 | m->enter_y = atoi (value); |
988 | } |
|
|
989 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
979 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
990 | { |
|
|
991 | m->width = atoi (value); |
980 | m->width = atoi (value); |
992 | } |
|
|
993 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
981 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
994 | { |
|
|
995 | m->height = atoi (value); |
982 | m->height = atoi (value); |
996 | } |
|
|
997 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
983 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
998 | { |
|
|
999 | m->reset_timeout = atoi (value); |
984 | m->reset_timeout = atoi (value); |
1000 | } |
|
|
1001 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
985 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
1002 | { |
|
|
1003 | m->timeout = atoi (value); |
986 | m->timeout = atoi (value); |
1004 | } |
|
|
1005 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
987 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
1006 | { |
988 | m->difficulty = clamp (atoi (value), 1, settings.max_level); |
1007 | m->difficulty = atoi (value); |
|
|
1008 | } |
|
|
1009 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
989 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
1010 | { |
|
|
1011 | m->darkness = atoi (value); |
990 | m->darkness = atoi (value); |
1012 | } |
|
|
1013 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
991 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
1014 | { |
|
|
1015 | m->fixed_resettime = atoi (value); |
992 | m->fixed_resettime = atoi (value); |
1016 | } |
|
|
1017 | else if (!strcmp (key, "unique")) |
993 | else if (!strcmp (key, "unique")) |
1018 | { |
|
|
1019 | m->unique = atoi (value); |
994 | m->unique = atoi (value); |
1020 | } |
|
|
1021 | else if (!strcmp (key, "template")) |
995 | else if (!strcmp (key, "template")) |
1022 | { |
|
|
1023 | m->templatemap = atoi (value); |
996 | m->templatemap = atoi (value); |
1024 | } |
|
|
1025 | else if (!strcmp (key, "region")) |
997 | else if (!strcmp (key, "region")) |
1026 | { |
|
|
1027 | m->region = get_region_by_name (value); |
998 | m->region = get_region_by_name (value); |
1028 | } |
|
|
1029 | else if (!strcmp (key, "shopitems")) |
999 | else if (!strcmp (key, "shopitems")) |
1030 | { |
1000 | { |
1031 | *end = 0; |
1001 | *end = 0; |
1032 | m->shopitems = parse_shop_string (value); |
1002 | m->shopitems = parse_shop_string (value); |
1033 | } |
1003 | } |
1034 | else if (!strcmp (key, "shopgreed")) |
1004 | else if (!strcmp (key, "shopgreed")) |
1035 | { |
|
|
1036 | m->shopgreed = atof (value); |
1005 | m->shopgreed = atof (value); |
1037 | } |
|
|
1038 | else if (!strcmp (key, "shopmin")) |
1006 | else if (!strcmp (key, "shopmin")) |
1039 | { |
|
|
1040 | m->shopmin = atol (value); |
1007 | m->shopmin = atol (value); |
1041 | } |
|
|
1042 | else if (!strcmp (key, "shopmax")) |
1008 | else if (!strcmp (key, "shopmax")) |
1043 | { |
|
|
1044 | m->shopmax = atol (value); |
1009 | m->shopmax = atol (value); |
1045 | } |
|
|
1046 | else if (!strcmp (key, "shoprace")) |
1010 | else if (!strcmp (key, "shoprace")) |
1047 | { |
1011 | { |
1048 | *end = 0; |
1012 | *end = 0; |
1049 | m->shoprace = strdup_local (value); |
1013 | m->shoprace = strdup (value); |
1050 | } |
1014 | } |
1051 | else if (!strcmp (key, "outdoor")) |
1015 | else if (!strcmp (key, "outdoor")) |
1052 | { |
|
|
1053 | m->outdoor = atoi (value); |
1016 | m->outdoor = atoi (value); |
1054 | } |
|
|
1055 | else if (!strcmp (key, "temp")) |
1017 | else if (!strcmp (key, "temp")) |
1056 | { |
|
|
1057 | m->temp = atoi (value); |
1018 | m->temp = atoi (value); |
1058 | } |
|
|
1059 | else if (!strcmp (key, "pressure")) |
1019 | else if (!strcmp (key, "pressure")) |
1060 | { |
|
|
1061 | m->pressure = atoi (value); |
1020 | m->pressure = atoi (value); |
1062 | } |
|
|
1063 | else if (!strcmp (key, "humid")) |
1021 | else if (!strcmp (key, "humid")) |
1064 | { |
|
|
1065 | m->humid = atoi (value); |
1022 | m->humid = atoi (value); |
1066 | } |
|
|
1067 | else if (!strcmp (key, "windspeed")) |
1023 | else if (!strcmp (key, "windspeed")) |
1068 | { |
|
|
1069 | m->windspeed = atoi (value); |
1024 | m->windspeed = atoi (value); |
1070 | } |
|
|
1071 | else if (!strcmp (key, "winddir")) |
1025 | else if (!strcmp (key, "winddir")) |
1072 | { |
|
|
1073 | m->winddir = atoi (value); |
1026 | m->winddir = atoi (value); |
1074 | } |
|
|
1075 | else if (!strcmp (key, "sky")) |
1027 | else if (!strcmp (key, "sky")) |
1076 | { |
|
|
1077 | m->sky = atoi (value); |
1028 | m->sky = atoi (value); |
1078 | } |
|
|
1079 | else if (!strcmp (key, "nosmooth")) |
1029 | else if (!strcmp (key, "nosmooth")) |
1080 | { |
|
|
1081 | m->nosmooth = atoi (value); |
1030 | m->nosmooth = atoi (value); |
1082 | } |
|
|
1083 | else if (!strncmp (key, "tile_path_", 10)) |
1031 | else if (!strncmp (key, "tile_path_", 10)) |
1084 | { |
1032 | { |
1085 | int tile = atoi (key + 10); |
1033 | int tile = atoi (key + 10); |
1086 | |
1034 | |
1087 | if (tile < 1 || tile > 4) |
1035 | if (tile < 1 || tile > 4) |
… | |
… | |
1120 | } |
1068 | } |
1121 | |
1069 | |
1122 | if (editor) |
1070 | if (editor) |
1123 | { |
1071 | { |
1124 | /* Use the value as in the file. */ |
1072 | /* Use the value as in the file. */ |
1125 | m->tile_path[tile - 1] = strdup_local (value); |
1073 | m->tile_path[tile - 1] = strdup (value); |
1126 | } |
1074 | } |
1127 | else if (path != NULL) |
1075 | else if (path != NULL) |
1128 | { |
1076 | { |
1129 | /* Use the normalized value. */ |
1077 | /* Use the normalized value. */ |
1130 | m->tile_path[tile - 1] = strdup_local (path); |
1078 | m->tile_path[tile - 1] = strdup (path); |
1131 | } |
1079 | } |
1132 | } /* end if tile direction (in)valid */ |
1080 | } /* end if tile direction (in)valid */ |
1133 | } |
1081 | } |
1134 | else |
1082 | else |
1135 | { |
|
|
1136 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1083 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1137 | } |
|
|
1138 | } |
1084 | } |
|
|
1085 | |
1139 | if (!key || strcmp (key, "end")) |
1086 | if (!key || strcmp (key, "end")) |
1140 | { |
1087 | { |
1141 | LOG (llevError, "Got premature eof on map header!\n"); |
1088 | LOG (llevError, "Got premature eof on map header!\n"); |
1142 | return 1; |
1089 | return 1; |
1143 | } |
1090 | } |
|
|
1091 | |
1144 | return 0; |
1092 | return 0; |
1145 | } |
1093 | } |
1146 | |
1094 | |
1147 | /* |
1095 | /* |
1148 | * Opens the file "filename" and reads information about the map |
1096 | * Opens the file "filename" and reads information about the map |
… | |
… | |
1184 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1132 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1185 | delete_map (m); |
1133 | delete_map (m); |
1186 | return NULL; |
1134 | return NULL; |
1187 | } |
1135 | } |
1188 | |
1136 | |
1189 | allocate_map (m); |
1137 | m->allocate (); |
1190 | |
1138 | |
1191 | m->in_memory = MAP_LOADING; |
1139 | m->in_memory = MAP_LOADING; |
1192 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1140 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1193 | |
1141 | |
1194 | m->in_memory = MAP_IN_MEMORY; |
1142 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1240 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1188 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1241 | delete_map (m); |
1189 | delete_map (m); |
1242 | m = load_original_map (m->path, 0); |
1190 | m = load_original_map (m->path, 0); |
1243 | return NULL; |
1191 | return NULL; |
1244 | } |
1192 | } |
|
|
1193 | |
1245 | allocate_map (m); |
1194 | m->allocate (); |
1246 | |
1195 | |
1247 | m->in_memory = MAP_LOADING; |
1196 | m->in_memory = MAP_LOADING; |
1248 | load_objects (m, thawer, 0); |
1197 | load_objects (m, thawer, 0); |
1249 | |
1198 | |
1250 | m->in_memory = MAP_IN_MEMORY; |
1199 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1275 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1224 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1276 | delete_map (m); |
1225 | delete_map (m); |
1277 | m = load_original_map (m->path, 0); |
1226 | m = load_original_map (m->path, 0); |
1278 | return NULL; |
1227 | return NULL; |
1279 | } |
1228 | } |
1280 | /*allocate_map(m); */ |
1229 | /*m->allocate ();*/ |
1281 | |
1230 | |
1282 | m->in_memory = MAP_LOADING; |
1231 | m->in_memory = MAP_LOADING; |
1283 | load_objects (m, thawer, MAP_OVERLAY); |
1232 | load_objects (m, thawer, MAP_OVERLAY); |
1284 | |
1233 | |
1285 | m->in_memory = MAP_IN_MEMORY; |
1234 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1299 | |
1248 | |
1300 | for (i = 0; i < MAP_WIDTH (m); i++) |
1249 | for (i = 0; i < MAP_WIDTH (m); i++) |
1301 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1250 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1302 | { |
1251 | { |
1303 | unique = 0; |
1252 | unique = 0; |
|
|
1253 | |
1304 | for (op = get_map_ob (m, i, j); op; op = next) |
1254 | for (op = get_map_ob (m, i, j); op; op = next) |
1305 | { |
1255 | { |
1306 | next = op->above; |
1256 | next = op->above; |
|
|
1257 | |
1307 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1258 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1308 | unique = 1; |
1259 | unique = 1; |
|
|
1260 | |
1309 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1261 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1310 | { |
1262 | { |
1311 | clean_object (op); |
1263 | clean_object (op); |
|
|
1264 | |
1312 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1265 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1313 | remove_button_link (op); |
1266 | remove_button_link (op); |
1314 | remove_ob (op); |
1267 | |
1315 | free_object (op); |
1268 | op->destroy (); |
1316 | } |
1269 | } |
1317 | } |
1270 | } |
1318 | } |
1271 | } |
1319 | } |
1272 | } |
1320 | |
1273 | |
… | |
… | |
1389 | make_path_to_file (filename); |
1342 | make_path_to_file (filename); |
1390 | } |
1343 | } |
1391 | else |
1344 | else |
1392 | { |
1345 | { |
1393 | if (!m->tmpname) |
1346 | if (!m->tmpname) |
1394 | m->tmpname = tempnam_local (settings.tmpdir, NULL); |
1347 | m->tmpname = tempnam (settings.tmpdir, NULL); |
1395 | |
1348 | |
1396 | strcpy (filename, m->tmpname); |
1349 | strcpy (filename, m->tmpname); |
1397 | } |
1350 | } |
1398 | |
1351 | |
1399 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
1352 | LOG (llevDebug, "Saving map %s to %s\n", m->path, filename); |
… | |
… | |
1423 | print_shop_string (m, shop); |
1376 | print_shop_string (m, shop); |
1424 | fprintf (freezer, "shopitems %s\n", shop); |
1377 | fprintf (freezer, "shopitems %s\n", shop); |
1425 | } |
1378 | } |
1426 | if (m->shopgreed) |
1379 | if (m->shopgreed) |
1427 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1380 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1428 | #ifndef WIN32 |
|
|
1429 | if (m->shopmin) |
1381 | if (m->shopmin) |
1430 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1382 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1431 | if (m->shopmax) |
1383 | if (m->shopmax) |
1432 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1384 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1433 | #else |
|
|
1434 | if (m->shopmin) |
|
|
1435 | fprintf (freezer, "shopmin %I64u\n", m->shopmin); |
|
|
1436 | if (m->shopmax) |
|
|
1437 | fprintf (freezer, "shopmax %I64u\n", m->shopmax); |
|
|
1438 | #endif |
|
|
1439 | if (m->shoprace) |
1385 | if (m->shoprace) |
1440 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1386 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1441 | if (m->darkness) |
1387 | if (m->darkness) |
1442 | fprintf (freezer, "darkness %d\n", m->darkness); |
1388 | fprintf (freezer, "darkness %d\n", m->darkness); |
1443 | if (m->width) |
1389 | if (m->width) |
… | |
… | |
1522 | object *tmp, *next; |
1468 | object *tmp, *next; |
1523 | |
1469 | |
1524 | for (tmp = op->inv; tmp; tmp = next) |
1470 | for (tmp = op->inv; tmp; tmp = next) |
1525 | { |
1471 | { |
1526 | next = tmp->below; |
1472 | next = tmp->below; |
|
|
1473 | |
1527 | clean_object (tmp); |
1474 | clean_object (tmp); |
1528 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1475 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1529 | remove_button_link (tmp); |
1476 | remove_button_link (tmp); |
1530 | remove_ob (tmp); |
1477 | |
1531 | free_object (tmp); |
1478 | tmp->destroy (); |
1532 | } |
1479 | } |
1533 | } |
1480 | } |
1534 | |
1481 | |
1535 | /* |
1482 | /* |
1536 | * Remove and free all objects in the given map. |
1483 | * Remove and free all objects in the given map. |
… | |
… | |
1552 | if (op == previous_obj) |
1499 | if (op == previous_obj) |
1553 | { |
1500 | { |
1554 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1501 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1555 | break; |
1502 | break; |
1556 | } |
1503 | } |
|
|
1504 | |
1557 | previous_obj = op; |
1505 | previous_obj = op; |
|
|
1506 | |
1558 | if (op->head != NULL) |
1507 | if (op->head != NULL) |
1559 | op = op->head; |
1508 | op = op->head; |
1560 | |
1509 | |
1561 | /* If the map isn't in memory, free_object will remove and |
1510 | /* If the map isn't in memory, free_object will remove and |
1562 | * free objects in op's inventory. So let it do the job. |
1511 | * free objects in op's inventory. So let it do the job. |
1563 | */ |
1512 | */ |
1564 | if (m->in_memory == MAP_IN_MEMORY) |
1513 | if (m->in_memory == MAP_IN_MEMORY) |
1565 | clean_object (op); |
1514 | clean_object (op); |
1566 | remove_ob (op); |
1515 | |
1567 | free_object (op); |
1516 | op->destroy (); |
1568 | } |
1517 | } |
1569 | } |
1518 | } |
1570 | } |
1519 | } |
1571 | |
1520 | |
1572 | /* |
1521 | /* |
… | |
… | |
1582 | if (!m->in_memory) |
1531 | if (!m->in_memory) |
1583 | { |
1532 | { |
1584 | LOG (llevError, "Trying to free freed map.\n"); |
1533 | LOG (llevError, "Trying to free freed map.\n"); |
1585 | return; |
1534 | return; |
1586 | } |
1535 | } |
|
|
1536 | |
|
|
1537 | // TODO: use new/delete |
|
|
1538 | #define FREE_AND_CLEAR(p) { free (p); p = NULL; } |
|
|
1539 | |
1587 | if (flag && m->spaces) |
1540 | if (flag && m->spaces) |
1588 | free_all_objects (m); |
1541 | free_all_objects (m); |
1589 | if (m->name) |
1542 | if (m->name) |
1590 | FREE_AND_CLEAR (m->name); |
1543 | FREE_AND_CLEAR (m->name); |
1591 | if (m->spaces) |
1544 | if (m->spaces) |
1592 | FREE_AND_CLEAR (m->spaces); |
1545 | FREE_AND_CLEAR (m->spaces); |
1593 | if (m->msg) |
1546 | if (m->msg) |
1594 | FREE_AND_CLEAR (m->msg); |
1547 | FREE_AND_CLEAR (m->msg); |
1595 | if (m->maplore) |
1548 | if (m->maplore) |
1596 | FREE_AND_CLEAR (m->maplore); |
1549 | FREE_AND_CLEAR (m->maplore); |
1597 | if (m->shopitems) |
1550 | |
1598 | delete[]m->shopitems; |
1551 | delete [] m->shopitems; |
1599 | m->shopitems = 0; |
1552 | m->shopitems = 0; |
|
|
1553 | |
1600 | if (m->shoprace) |
1554 | if (m->shoprace) |
1601 | FREE_AND_CLEAR (m->shoprace); |
1555 | FREE_AND_CLEAR (m->shoprace); |
|
|
1556 | |
1602 | if (m->buttons) |
1557 | if (m->buttons) |
1603 | free_objectlinkpt (m->buttons); |
1558 | free_objectlinkpt (m->buttons); |
|
|
1559 | |
1604 | m->buttons = NULL; |
1560 | m->buttons = NULL; |
|
|
1561 | |
1605 | for (i = 0; i < 4; i++) |
1562 | for (i = 0; i < 4; i++) |
1606 | { |
1563 | { |
1607 | if (m->tile_path[i]) |
1564 | if (m->tile_path[i]) |
1608 | FREE_AND_CLEAR (m->tile_path[i]); |
1565 | FREE_AND_CLEAR (m->tile_path[i]); |
1609 | m->tile_map[i] = NULL; |
1566 | m->tile_map[i] = NULL; |
1610 | } |
1567 | } |
|
|
1568 | |
1611 | m->in_memory = MAP_SWAPPED; |
1569 | m->in_memory = MAP_SWAPPED; |
|
|
1570 | |
|
|
1571 | #undef FREE_AND_CLEAR |
|
|
1572 | |
1612 | } |
1573 | } |
1613 | |
1574 | |
1614 | /* |
1575 | /* |
1615 | * function: vanish maptile |
1576 | * function: vanish maptile |
1616 | * m : pointer to maptile, if NULL no action |
1577 | * m : pointer to maptile, if NULL no action |
… | |
… | |
1676 | else |
1637 | else |
1677 | last->next = m->next; |
1638 | last->next = m->next; |
1678 | |
1639 | |
1679 | delete m; |
1640 | delete m; |
1680 | } |
1641 | } |
1681 | |
|
|
1682 | |
|
|
1683 | |
1642 | |
1684 | /* |
1643 | /* |
1685 | * Makes sure the given map is loaded and swapped in. |
1644 | * Makes sure the given map is loaded and swapped in. |
1686 | * name is path name of the map. |
1645 | * name is path name of the map. |
1687 | * flags meaning: |
1646 | * flags meaning: |
… | |
… | |
1690 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1649 | * 0x2 (MAP_PLAYER_UNIQUE) - this is a unique map for each player. |
1691 | * dont do any more name translation on it. |
1650 | * dont do any more name translation on it. |
1692 | * |
1651 | * |
1693 | * Returns a pointer to the given map. |
1652 | * Returns a pointer to the given map. |
1694 | */ |
1653 | */ |
1695 | |
|
|
1696 | maptile * |
1654 | maptile * |
1697 | ready_map_name (const char *name, int flags) |
1655 | ready_map_name (const char *name, int flags) |
1698 | { |
1656 | { |
1699 | maptile *m; |
1657 | maptile *m; |
1700 | |
1658 | |
… | |
… | |
2146 | timeout = MAP_RESET_TIMEOUT (map); |
2104 | timeout = MAP_RESET_TIMEOUT (map); |
2147 | if (timeout <= 0) |
2105 | if (timeout <= 0) |
2148 | timeout = MAP_DEFAULTRESET; |
2106 | timeout = MAP_DEFAULTRESET; |
2149 | if (timeout >= MAP_MAXRESET) |
2107 | if (timeout >= MAP_MAXRESET) |
2150 | timeout = MAP_MAXRESET; |
2108 | timeout = MAP_MAXRESET; |
2151 | MAP_WHEN_RESET (map) = seconds () + timeout; |
2109 | MAP_WHEN_RESET (map) = time (0) + timeout; |
2152 | } |
2110 | } |
2153 | |
2111 | |
2154 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2112 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2155 | * the map. It also takes care of linking back the freshly loaded |
2113 | * the map. It also takes care of linking back the freshly loaded |
2156 | * maps tile_map values if it tiles back to this one. It returns |
2114 | * maps tile_map values if it tiles back to this one. It returns |