… | |
… | |
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 | |
32 | |
35 | |
33 | |
36 | /* |
34 | /* |
… | |
… | |
157 | int |
155 | int |
158 | check_path (const char *name, int prepend_dir) |
156 | check_path (const char *name, int prepend_dir) |
159 | { |
157 | { |
160 | char buf[MAX_BUF]; |
158 | char buf[MAX_BUF]; |
161 | |
159 | |
162 | #ifndef WIN32 |
|
|
163 | char *endbuf; |
160 | char *endbuf; |
164 | struct stat statbuf; |
161 | struct stat statbuf; |
165 | int mode = 0; |
162 | int mode = 0; |
166 | #endif |
|
|
167 | |
163 | |
168 | if (prepend_dir) |
164 | if (prepend_dir) |
169 | strcpy (buf, create_pathname (name)); |
165 | strcpy (buf, create_pathname (name)); |
170 | else |
166 | else |
171 | strcpy (buf, name); |
167 | strcpy (buf, name); |
172 | #ifdef WIN32 /* ***win32: check this sucker in windows style. */ |
|
|
173 | return (_access (buf, 0)); |
|
|
174 | #else |
|
|
175 | |
168 | |
176 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
169 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
177 | * this method should be equivalant and is clearer. |
170 | * this method should be equivalant and is clearer. |
178 | * Can not use strcat because we need to cycle through |
171 | * Can not use strcat because we need to cycle through |
179 | * all the names. |
172 | * all the names. |
… | |
… | |
192 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
185 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
193 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
186 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
194 | mode |= 2; |
187 | mode |= 2; |
195 | |
188 | |
196 | return (mode); |
189 | return (mode); |
197 | #endif |
|
|
198 | } |
190 | } |
199 | |
191 | |
200 | /* |
192 | /* |
201 | * Prints out debug-information about a map. |
193 | * Prints out debug-information about a map. |
202 | * Dumping these at llevError doesn't seem right, but is |
194 | * Dumping these at llevError doesn't seem right, but is |
… | |
… | |
643 | |
635 | |
644 | } /* for this space */ |
636 | } /* for this space */ |
645 | } /* for this j */ |
637 | } /* for this j */ |
646 | } |
638 | } |
647 | |
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 | |
648 | /* |
657 | /* |
649 | * Allocates, initialises, and returns a pointer to a maptile. |
658 | * Allocates, initialises, and returns a pointer to a maptile. |
650 | * 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 |
651 | * used anyways. MSW 2001-07-01 |
660 | * used anyways. MSW 2001-07-01 |
652 | */ |
661 | */ |
653 | |
|
|
654 | maptile * |
662 | maptile * |
655 | get_linked_map (void) |
663 | get_linked_map (void) |
656 | { |
664 | { |
657 | maptile *map = new maptile; |
665 | maptile *mp, *map = new maptile; |
658 | maptile *mp; |
|
|
659 | |
666 | |
660 | for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); |
667 | for (mp = first_map; mp && mp->next; mp = mp->next); |
|
|
668 | |
661 | if (mp == NULL) |
669 | if (mp == NULL) |
662 | first_map = map; |
670 | first_map = map; |
663 | else |
671 | else |
664 | mp->next = map; |
672 | mp->next = map; |
665 | |
673 | |
666 | map->in_memory = MAP_SWAPPED; |
|
|
667 | /* The maps used to pick up default x and y values from the |
|
|
668 | * map archetype. Mimic that behaviour. |
|
|
669 | */ |
|
|
670 | MAP_WIDTH (map) = 16; |
|
|
671 | MAP_HEIGHT (map) = 16; |
|
|
672 | MAP_RESET_TIMEOUT (map) = 0; |
|
|
673 | MAP_TIMEOUT (map) = 300; |
|
|
674 | MAP_ENTER_X (map) = 0; |
|
|
675 | MAP_ENTER_Y (map) = 0; |
|
|
676 | /*set part to -1 indicating conversion to weather map not yet done */ |
|
|
677 | MAP_WORLDPARTX (map) = -1; |
|
|
678 | MAP_WORLDPARTY (map) = -1; |
|
|
679 | return map; |
674 | return map; |
680 | } |
675 | } |
681 | |
676 | |
682 | /* |
677 | /* |
683 | * Allocates the arrays contained in a maptile. |
678 | * Allocates the arrays contained in a maptile. |
684 | * This basically allocates the dynamic array of spaces for the |
679 | * This basically allocates the dynamic array of spaces for the |
685 | * map. |
680 | * map. |
686 | */ |
681 | */ |
687 | |
|
|
688 | void |
682 | void |
689 | allocate_map (maptile *m) |
683 | maptile::allocate () |
690 | { |
684 | { |
691 | m->in_memory = MAP_IN_MEMORY; |
685 | in_memory = MAP_IN_MEMORY; |
|
|
686 | |
692 | /* Log this condition and free the storage. We could I suppose |
687 | /* Log this condition and free the storage. We could I suppose |
693 | * 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, |
694 | * that is their poor assumption. |
689 | * that is their poor assumption. |
695 | */ |
690 | */ |
696 | if (m->spaces) |
691 | if (spaces) |
697 | { |
692 | { |
698 | 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); |
699 | free (m->spaces); |
694 | free (spaces); |
700 | } |
695 | } |
701 | |
696 | |
702 | m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); |
697 | spaces = (MapSpace *) |
|
|
698 | calloc (1, width * height * sizeof (MapSpace)); |
703 | |
699 | |
704 | if (m->spaces == NULL) |
700 | if (!spaces) |
705 | fatal (OUT_OF_MEMORY); |
701 | fatal (OUT_OF_MEMORY); |
706 | } |
702 | } |
707 | |
703 | |
708 | /* Create and returns a map of the specific size. Used |
704 | /* Create and returns a map of the specific size. Used |
709 | * in random map code and the editor. |
705 | * in random map code and the editor. |
… | |
… | |
714 | maptile *m = get_linked_map (); |
710 | maptile *m = get_linked_map (); |
715 | |
711 | |
716 | m->width = sizex; |
712 | m->width = sizex; |
717 | m->height = sizey; |
713 | m->height = sizey; |
718 | m->in_memory = MAP_SWAPPED; |
714 | m->in_memory = MAP_SWAPPED; |
719 | allocate_map (m); |
715 | m->allocate (); |
|
|
716 | |
720 | return m; |
717 | return m; |
721 | } |
718 | } |
722 | |
719 | |
723 | /* 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 |
724 | * 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 |
… | |
… | |
851 | { |
848 | { |
852 | 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; |
853 | int msgpos = 0; |
850 | int msgpos = 0; |
854 | int maplorepos = 0; |
851 | int maplorepos = 0; |
855 | |
852 | |
856 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
853 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
857 | { |
854 | { |
858 | buf[HUGE_BUF - 1] = 0; |
855 | buf[HUGE_BUF - 1] = 0; |
859 | key = buf; |
856 | key = buf; |
|
|
857 | |
860 | while (isspace (*key)) |
858 | while (isspace (*key)) |
861 | key++; |
859 | key++; |
|
|
860 | |
862 | if (*key == 0) |
861 | if (*key == 0) |
863 | continue; /* empty line */ |
862 | continue; /* empty line */ |
|
|
863 | |
864 | value = strchr (key, ' '); |
864 | value = strchr (key, ' '); |
|
|
865 | |
865 | if (!value) |
866 | if (!value) |
866 | { |
867 | { |
867 | end = strchr (key, '\n'); |
868 | if ((end = strchr (key, '\n'))) |
868 | if (end != NULL) |
|
|
869 | { |
|
|
870 | *end = 0; |
869 | *end = 0; |
871 | } |
|
|
872 | } |
870 | } |
873 | else |
871 | else |
874 | { |
872 | { |
875 | *value = 0; |
873 | *value = 0; |
876 | value++; |
874 | value++; |
877 | end = strchr (value, '\n'); |
875 | end = strchr (value, '\n'); |
|
|
876 | |
878 | while (isspace (*value)) |
877 | while (isspace (*value)) |
879 | { |
878 | { |
880 | value++; |
879 | value++; |
|
|
880 | |
881 | if (*value == '\0' || value == end) |
881 | if (*value == '\0' || value == end) |
882 | { |
882 | { |
883 | /* Nothing but spaces. */ |
883 | /* Nothing but spaces. */ |
884 | value = NULL; |
884 | value = NULL; |
885 | break; |
885 | break; |
… | |
… | |
908 | * that use the parameter. |
908 | * that use the parameter. |
909 | */ |
909 | */ |
910 | |
910 | |
911 | if (!strcmp (key, "msg")) |
911 | if (!strcmp (key, "msg")) |
912 | { |
912 | { |
913 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
913 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
914 | { |
914 | { |
915 | if (!strcmp (buf, "endmsg\n")) |
915 | if (!strcmp (buf, "endmsg\n")) |
916 | break; |
916 | break; |
917 | else |
917 | else |
918 | { |
918 | { |
… | |
… | |
929 | if (msgpos != 0) |
929 | if (msgpos != 0) |
930 | m->msg = strdup_local (msgbuf); |
930 | m->msg = strdup_local (msgbuf); |
931 | } |
931 | } |
932 | else if (!strcmp (key, "maplore")) |
932 | else if (!strcmp (key, "maplore")) |
933 | { |
933 | { |
934 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
934 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
935 | { |
935 | { |
936 | if (!strcmp (buf, "endmaplore\n")) |
936 | if (!strcmp (buf, "endmaplore\n")) |
937 | break; |
937 | break; |
938 | else |
938 | else |
939 | { |
939 | { |
… | |
… | |
1182 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1182 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1183 | delete_map (m); |
1183 | delete_map (m); |
1184 | return NULL; |
1184 | return NULL; |
1185 | } |
1185 | } |
1186 | |
1186 | |
1187 | allocate_map (m); |
1187 | m->allocate (); |
1188 | |
1188 | |
1189 | m->in_memory = MAP_LOADING; |
1189 | m->in_memory = MAP_LOADING; |
1190 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1190 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1191 | |
1191 | |
1192 | m->in_memory = MAP_IN_MEMORY; |
1192 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1238 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1238 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1239 | delete_map (m); |
1239 | delete_map (m); |
1240 | m = load_original_map (m->path, 0); |
1240 | m = load_original_map (m->path, 0); |
1241 | return NULL; |
1241 | return NULL; |
1242 | } |
1242 | } |
|
|
1243 | |
1243 | allocate_map (m); |
1244 | m->allocate (); |
1244 | |
1245 | |
1245 | m->in_memory = MAP_LOADING; |
1246 | m->in_memory = MAP_LOADING; |
1246 | load_objects (m, thawer, 0); |
1247 | load_objects (m, thawer, 0); |
1247 | |
1248 | |
1248 | m->in_memory = MAP_IN_MEMORY; |
1249 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1273 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1274 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1274 | delete_map (m); |
1275 | delete_map (m); |
1275 | m = load_original_map (m->path, 0); |
1276 | m = load_original_map (m->path, 0); |
1276 | return NULL; |
1277 | return NULL; |
1277 | } |
1278 | } |
1278 | /*allocate_map(m); */ |
1279 | /*m->allocate ();*/ |
1279 | |
1280 | |
1280 | m->in_memory = MAP_LOADING; |
1281 | m->in_memory = MAP_LOADING; |
1281 | load_objects (m, thawer, MAP_OVERLAY); |
1282 | load_objects (m, thawer, MAP_OVERLAY); |
1282 | |
1283 | |
1283 | m->in_memory = MAP_IN_MEMORY; |
1284 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1421 | print_shop_string (m, shop); |
1422 | print_shop_string (m, shop); |
1422 | fprintf (freezer, "shopitems %s\n", shop); |
1423 | fprintf (freezer, "shopitems %s\n", shop); |
1423 | } |
1424 | } |
1424 | if (m->shopgreed) |
1425 | if (m->shopgreed) |
1425 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1426 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1426 | #ifndef WIN32 |
|
|
1427 | if (m->shopmin) |
1427 | if (m->shopmin) |
1428 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1428 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1429 | if (m->shopmax) |
1429 | if (m->shopmax) |
1430 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1430 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1431 | #else |
|
|
1432 | if (m->shopmin) |
|
|
1433 | fprintf (freezer, "shopmin %I64u\n", m->shopmin); |
|
|
1434 | if (m->shopmax) |
|
|
1435 | fprintf (freezer, "shopmax %I64u\n", m->shopmax); |
|
|
1436 | #endif |
|
|
1437 | if (m->shoprace) |
1431 | if (m->shoprace) |
1438 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1432 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1439 | if (m->darkness) |
1433 | if (m->darkness) |
1440 | fprintf (freezer, "darkness %d\n", m->darkness); |
1434 | fprintf (freezer, "darkness %d\n", m->darkness); |
1441 | if (m->width) |
1435 | if (m->width) |