… | |
… | |
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 | |
|
|
36 | extern int nrofallocobjects, nroffreeobjects; |
|
|
37 | |
33 | |
38 | /* |
34 | /* |
39 | * Returns the maptile which has a name matching the given argument. |
35 | * Returns the maptile which has a name matching the given argument. |
40 | * return NULL if no match is found. |
36 | * return NULL if no match is found. |
41 | */ |
37 | */ |
… | |
… | |
159 | int |
155 | int |
160 | check_path (const char *name, int prepend_dir) |
156 | check_path (const char *name, int prepend_dir) |
161 | { |
157 | { |
162 | char buf[MAX_BUF]; |
158 | char buf[MAX_BUF]; |
163 | |
159 | |
164 | #ifndef WIN32 |
|
|
165 | char *endbuf; |
160 | char *endbuf; |
166 | struct stat statbuf; |
161 | struct stat statbuf; |
167 | int mode = 0; |
162 | int mode = 0; |
168 | #endif |
|
|
169 | |
163 | |
170 | if (prepend_dir) |
164 | if (prepend_dir) |
171 | strcpy (buf, create_pathname (name)); |
165 | strcpy (buf, create_pathname (name)); |
172 | else |
166 | else |
173 | strcpy (buf, name); |
167 | strcpy (buf, name); |
174 | #ifdef WIN32 /* ***win32: check this sucker in windows style. */ |
|
|
175 | return (_access (buf, 0)); |
|
|
176 | #else |
|
|
177 | |
168 | |
178 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
169 | /* old method (strchr(buf, '\0')) seemd very odd to me - |
179 | * this method should be equivalant and is clearer. |
170 | * this method should be equivalant and is clearer. |
180 | * Can not use strcat because we need to cycle through |
171 | * Can not use strcat because we need to cycle through |
181 | * all the names. |
172 | * all the names. |
… | |
… | |
194 | if ((statbuf.st_mode & S_IWGRP && getegid () == statbuf.st_gid) || |
185 | 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)) |
186 | (statbuf.st_mode & S_IWUSR && geteuid () == statbuf.st_uid) || (statbuf.st_mode & S_IWOTH)) |
196 | mode |= 2; |
187 | mode |= 2; |
197 | |
188 | |
198 | return (mode); |
189 | return (mode); |
199 | #endif |
|
|
200 | } |
190 | } |
201 | |
191 | |
202 | /* |
192 | /* |
203 | * Prints out debug-information about a map. |
193 | * Prints out debug-information about a map. |
204 | * Dumping these at llevError doesn't seem right, but is |
194 | * Dumping these at llevError doesn't seem right, but is |
… | |
… | |
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 |
… | |
… | |
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 | { |
… | |
… | |
931 | if (msgpos != 0) |
929 | if (msgpos != 0) |
932 | m->msg = strdup_local (msgbuf); |
930 | m->msg = strdup_local (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 | { |
… | |
… | |
1184 | 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); |
1185 | delete_map (m); |
1183 | delete_map (m); |
1186 | return NULL; |
1184 | return NULL; |
1187 | } |
1185 | } |
1188 | |
1186 | |
1189 | allocate_map (m); |
1187 | m->allocate (); |
1190 | |
1188 | |
1191 | m->in_memory = MAP_LOADING; |
1189 | m->in_memory = MAP_LOADING; |
1192 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1190 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1193 | |
1191 | |
1194 | m->in_memory = MAP_IN_MEMORY; |
1192 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1240 | 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); |
1241 | delete_map (m); |
1239 | delete_map (m); |
1242 | m = load_original_map (m->path, 0); |
1240 | m = load_original_map (m->path, 0); |
1243 | return NULL; |
1241 | return NULL; |
1244 | } |
1242 | } |
|
|
1243 | |
1245 | allocate_map (m); |
1244 | m->allocate (); |
1246 | |
1245 | |
1247 | m->in_memory = MAP_LOADING; |
1246 | m->in_memory = MAP_LOADING; |
1248 | load_objects (m, thawer, 0); |
1247 | load_objects (m, thawer, 0); |
1249 | |
1248 | |
1250 | m->in_memory = MAP_IN_MEMORY; |
1249 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1275 | 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); |
1276 | delete_map (m); |
1275 | delete_map (m); |
1277 | m = load_original_map (m->path, 0); |
1276 | m = load_original_map (m->path, 0); |
1278 | return NULL; |
1277 | return NULL; |
1279 | } |
1278 | } |
1280 | /*allocate_map(m); */ |
1279 | /*m->allocate ();*/ |
1281 | |
1280 | |
1282 | m->in_memory = MAP_LOADING; |
1281 | m->in_memory = MAP_LOADING; |
1283 | load_objects (m, thawer, MAP_OVERLAY); |
1282 | load_objects (m, thawer, MAP_OVERLAY); |
1284 | |
1283 | |
1285 | m->in_memory = MAP_IN_MEMORY; |
1284 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1423 | print_shop_string (m, shop); |
1422 | print_shop_string (m, shop); |
1424 | fprintf (freezer, "shopitems %s\n", shop); |
1423 | fprintf (freezer, "shopitems %s\n", shop); |
1425 | } |
1424 | } |
1426 | if (m->shopgreed) |
1425 | if (m->shopgreed) |
1427 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1426 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1428 | #ifndef WIN32 |
|
|
1429 | if (m->shopmin) |
1427 | if (m->shopmin) |
1430 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1428 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1431 | if (m->shopmax) |
1429 | if (m->shopmax) |
1432 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1430 | 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) |
1431 | if (m->shoprace) |
1440 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1432 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1441 | if (m->darkness) |
1433 | if (m->darkness) |
1442 | fprintf (freezer, "darkness %d\n", m->darkness); |
1434 | fprintf (freezer, "darkness %d\n", m->darkness); |
1443 | if (m->width) |
1435 | if (m->width) |