… | |
… | |
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 | extern int nrofallocobjects, nroffreeobjects; |
|
|
37 | |
|
|
38 | /* |
34 | /* |
39 | * Returns the mapstruct 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 | */ |
42 | |
38 | |
43 | mapstruct * |
39 | maptile * |
44 | has_been_loaded (const char *name) |
40 | has_been_loaded (const char *name) |
45 | { |
41 | { |
46 | mapstruct *map; |
42 | maptile *map; |
47 | |
43 | |
48 | if (!name || !*name) |
44 | if (!name || !*name) |
49 | return 0; |
45 | return 0; |
50 | for (map = first_map; map; map = map->next) |
46 | for (map = first_map; map; map = map->next) |
51 | if (!strcmp (name, map->path)) |
47 | if (!strcmp (name, map->path)) |
… | |
… | |
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 |
205 | * necessary to make sure the information is in fact logged. |
195 | * necessary to make sure the information is in fact logged. |
206 | */ |
196 | */ |
207 | |
197 | |
208 | void |
198 | void |
209 | dump_map (const mapstruct *m) |
199 | dump_map (const maptile *m) |
210 | { |
200 | { |
211 | LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); |
201 | LOG (llevError, "Map %s status: %d.\n", m->path, m->in_memory); |
212 | LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m)); |
202 | LOG (llevError, "Size: %dx%d Start: %d,%d\n", MAP_WIDTH (m), MAP_HEIGHT (m), MAP_ENTER_X (m), MAP_ENTER_Y (m)); |
213 | |
203 | |
214 | if (m->msg != NULL) |
204 | if (m->msg != NULL) |
… | |
… | |
231 | */ |
221 | */ |
232 | |
222 | |
233 | void |
223 | void |
234 | dump_all_maps (void) |
224 | dump_all_maps (void) |
235 | { |
225 | { |
236 | mapstruct *m; |
226 | maptile *m; |
237 | |
227 | |
238 | for (m = first_map; m != NULL; m = m->next) |
228 | for (m = first_map; m != NULL; m = m->next) |
239 | { |
229 | { |
240 | dump_map (m); |
230 | dump_map (m); |
241 | } |
231 | } |
… | |
… | |
250 | * is needed. The case of not passing values is if we're just |
240 | * is needed. The case of not passing values is if we're just |
251 | * checking for the existence of something on those spaces, but |
241 | * checking for the existence of something on those spaces, but |
252 | * don't expect to insert/remove anything from those spaces. |
242 | * don't expect to insert/remove anything from those spaces. |
253 | */ |
243 | */ |
254 | int |
244 | int |
255 | get_map_flags (mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) |
245 | get_map_flags (maptile *oldmap, maptile **newmap, sint16 x, sint16 y, sint16 * nx, sint16 * ny) |
256 | { |
246 | { |
257 | sint16 newx, newy; |
247 | sint16 newx, newy; |
258 | int retval = 0; |
248 | int retval = 0; |
259 | mapstruct *mp; |
249 | maptile *mp; |
260 | |
250 | |
261 | if (out_of_map (oldmap, x, y)) |
251 | if (out_of_map (oldmap, x, y)) |
262 | return P_OUT_OF_MAP; |
252 | return P_OUT_OF_MAP; |
263 | newx = x; |
253 | newx = x; |
264 | newy = y; |
254 | newy = y; |
… | |
… | |
275 | retval |= mp->spaces[newx + mp->width * newy].flags; |
265 | retval |= mp->spaces[newx + mp->width * newy].flags; |
276 | |
266 | |
277 | return retval; |
267 | return retval; |
278 | } |
268 | } |
279 | |
269 | |
280 | |
|
|
281 | /* |
270 | /* |
282 | * Returns true if the given coordinate is blocked except by the |
271 | * Returns true if the given coordinate is blocked except by the |
283 | * object passed is not blocking. This is used with |
272 | * object passed is not blocking. This is used with |
284 | * multipart monsters - if we want to see if a 2x2 monster |
273 | * multipart monsters - if we want to see if a 2x2 monster |
285 | * can move 1 space to the left, we don't want its own area |
274 | * can move 1 space to the left, we don't want its own area |
… | |
… | |
288 | * monster. |
277 | * monster. |
289 | * m, x, y are the target map/coordinates - needed for map tiling. |
278 | * m, x, y are the target map/coordinates - needed for map tiling. |
290 | * the coordinates & map passed in should have been updated for tiling |
279 | * the coordinates & map passed in should have been updated for tiling |
291 | * by the caller. |
280 | * by the caller. |
292 | */ |
281 | */ |
293 | |
|
|
294 | int |
282 | int |
295 | blocked_link (object *ob, mapstruct *m, int sx, int sy) |
283 | blocked_link (object *ob, maptile *m, int sx, int sy) |
296 | { |
284 | { |
297 | object *tmp; |
285 | object *tmp; |
298 | int mflags, blocked; |
286 | int mflags, blocked; |
299 | |
287 | |
300 | /* Make sure the coordinates are valid - they should be, as caller should |
288 | /* Make sure the coordinates are valid - they should be, as caller should |
… | |
… | |
412 | * code, we need to have actual object to check its move_type |
400 | * code, we need to have actual object to check its move_type |
413 | * against the move_block values. |
401 | * against the move_block values. |
414 | */ |
402 | */ |
415 | |
403 | |
416 | int |
404 | int |
417 | ob_blocked (const object *ob, mapstruct *m, sint16 x, sint16 y) |
405 | ob_blocked (const object *ob, maptile *m, sint16 x, sint16 y) |
418 | { |
406 | { |
419 | archetype *tmp; |
407 | archetype *tmp; |
420 | int flag; |
408 | int flag; |
421 | mapstruct *m1; |
409 | maptile *m1; |
422 | sint16 sx, sy; |
410 | sint16 sx, sy; |
423 | |
411 | |
424 | if (ob == NULL) |
412 | if (ob == NULL) |
425 | { |
413 | { |
426 | flag = get_map_flags (m, &m1, x, y, &sx, &sy); |
414 | flag = get_map_flags (m, &m1, x, y, &sx, &sy); |
… | |
… | |
491 | * they are saved). We do have to look for the old maps that did save |
479 | * they are saved). We do have to look for the old maps that did save |
492 | * the more sections and not re-add sections for them. |
480 | * the more sections and not re-add sections for them. |
493 | */ |
481 | */ |
494 | |
482 | |
495 | static void |
483 | static void |
496 | link_multipart_objects (mapstruct *m) |
484 | link_multipart_objects (maptile *m) |
497 | { |
485 | { |
498 | int x, y; |
486 | int x, y; |
499 | object *tmp, *op, *last, *above; |
487 | object *tmp, *op, *last, *above; |
500 | archetype *at; |
488 | archetype *at; |
501 | |
489 | |
… | |
… | |
538 | * Loads (ands parses) the objects into a given map from the specified |
526 | * Loads (ands parses) the objects into a given map from the specified |
539 | * file pointer. |
527 | * file pointer. |
540 | * mapflags is the same as we get with load_original_map |
528 | * mapflags is the same as we get with load_original_map |
541 | */ |
529 | */ |
542 | void |
530 | void |
543 | load_objects (mapstruct *m, object_thawer & fp, int mapflags) |
531 | load_objects (maptile *m, object_thawer & fp, int mapflags) |
544 | { |
532 | { |
545 | int i, j; |
533 | int i, j; |
546 | int unique; |
534 | int unique; |
547 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
535 | object *op, *prev = NULL, *last_more = NULL, *otmp; |
548 | |
536 | |
… | |
… | |
614 | * 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, |
615 | * and we only save the head of multi part objects - this is needed |
603 | * and we only save the head of multi part objects - this is needed |
616 | * in order to do map tiling properly. |
604 | * in order to do map tiling properly. |
617 | */ |
605 | */ |
618 | void |
606 | void |
619 | save_objects (mapstruct *m, object_freezer & fp, object_freezer & fp2, int flag) |
607 | save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag) |
620 | { |
608 | { |
621 | int i, j = 0, unique = 0; |
609 | int i, j = 0, unique = 0; |
622 | object *op; |
610 | object *op; |
623 | |
611 | |
624 | /* first pass - save one-part objects */ |
612 | /* first pass - save one-part objects */ |
… | |
… | |
647 | |
635 | |
648 | } /* for this space */ |
636 | } /* for this space */ |
649 | } /* for this j */ |
637 | } /* for this j */ |
650 | } |
638 | } |
651 | |
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 | |
652 | /* |
657 | /* |
653 | * Allocates, initialises, and returns a pointer to a mapstruct. |
658 | * Allocates, initialises, and returns a pointer to a maptile. |
654 | * 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 |
655 | * used anyways. MSW 2001-07-01 |
660 | * used anyways. MSW 2001-07-01 |
656 | */ |
661 | */ |
657 | |
662 | maptile * |
658 | mapstruct * |
|
|
659 | get_linked_map (void) |
663 | get_linked_map (void) |
660 | { |
664 | { |
661 | mapstruct *map = new mapstruct; |
665 | maptile *mp, *map = new maptile; |
662 | mapstruct *mp; |
|
|
663 | |
666 | |
664 | for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); |
667 | for (mp = first_map; mp && mp->next; mp = mp->next); |
|
|
668 | |
665 | if (mp == NULL) |
669 | if (mp == NULL) |
666 | first_map = map; |
670 | first_map = map; |
667 | else |
671 | else |
668 | mp->next = map; |
672 | mp->next = map; |
669 | |
673 | |
670 | map->in_memory = MAP_SWAPPED; |
|
|
671 | /* The maps used to pick up default x and y values from the |
|
|
672 | * map archetype. Mimic that behaviour. |
|
|
673 | */ |
|
|
674 | MAP_WIDTH (map) = 16; |
|
|
675 | MAP_HEIGHT (map) = 16; |
|
|
676 | MAP_RESET_TIMEOUT (map) = 0; |
|
|
677 | MAP_TIMEOUT (map) = 300; |
|
|
678 | MAP_ENTER_X (map) = 0; |
|
|
679 | MAP_ENTER_Y (map) = 0; |
|
|
680 | /*set part to -1 indicating conversion to weather map not yet done */ |
|
|
681 | MAP_WORLDPARTX (map) = -1; |
|
|
682 | MAP_WORLDPARTY (map) = -1; |
|
|
683 | return map; |
674 | return map; |
684 | } |
675 | } |
685 | |
676 | |
686 | /* |
677 | /* |
687 | * Allocates the arrays contained in a mapstruct. |
678 | * Allocates the arrays contained in a maptile. |
688 | * This basically allocates the dynamic array of spaces for the |
679 | * This basically allocates the dynamic array of spaces for the |
689 | * map. |
680 | * map. |
690 | */ |
681 | */ |
691 | |
|
|
692 | void |
682 | void |
693 | allocate_map (mapstruct *m) |
683 | maptile::allocate () |
694 | { |
684 | { |
695 | m->in_memory = MAP_IN_MEMORY; |
685 | in_memory = MAP_IN_MEMORY; |
|
|
686 | |
696 | /* Log this condition and free the storage. We could I suppose |
687 | /* Log this condition and free the storage. We could I suppose |
697 | * 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, |
698 | * that is their poor assumption. |
689 | * that is their poor assumption. |
699 | */ |
690 | */ |
700 | if (m->spaces) |
691 | if (spaces) |
701 | { |
692 | { |
702 | 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); |
703 | free (m->spaces); |
694 | free (spaces); |
704 | } |
695 | } |
705 | |
696 | |
706 | m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); |
697 | spaces = (MapSpace *) |
|
|
698 | calloc (1, width * height * sizeof (MapSpace)); |
707 | |
699 | |
708 | if (m->spaces == NULL) |
700 | if (!spaces) |
709 | fatal (OUT_OF_MEMORY); |
701 | fatal (OUT_OF_MEMORY); |
710 | } |
702 | } |
711 | |
703 | |
712 | /* Create and returns a map of the specific size. Used |
704 | /* Create and returns a map of the specific size. Used |
713 | * in random map code and the editor. |
705 | * in random map code and the editor. |
714 | */ |
706 | */ |
715 | mapstruct * |
707 | maptile * |
716 | get_empty_map (int sizex, int sizey) |
708 | get_empty_map (int sizex, int sizey) |
717 | { |
709 | { |
718 | mapstruct *m = get_linked_map (); |
710 | maptile *m = get_linked_map (); |
719 | |
711 | |
720 | m->width = sizex; |
712 | m->width = sizex; |
721 | m->height = sizey; |
713 | m->height = sizey; |
722 | m->in_memory = MAP_SWAPPED; |
714 | m->in_memory = MAP_SWAPPED; |
723 | allocate_map (m); |
715 | m->allocate (); |
|
|
716 | |
724 | return m; |
717 | return m; |
725 | } |
718 | } |
726 | |
719 | |
727 | /* 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 |
728 | * 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 |
… | |
… | |
805 | } |
798 | } |
806 | |
799 | |
807 | /* opposite of parse string, this puts the string that was originally fed in to |
800 | /* opposite of parse string, this puts the string that was originally fed in to |
808 | * the map (or something equivilent) into output_string. */ |
801 | * the map (or something equivilent) into output_string. */ |
809 | static void |
802 | static void |
810 | print_shop_string (mapstruct *m, char *output_string) |
803 | print_shop_string (maptile *m, char *output_string) |
811 | { |
804 | { |
812 | int i; |
805 | int i; |
813 | char tmp[MAX_BUF]; |
806 | char tmp[MAX_BUF]; |
814 | |
807 | |
815 | strcpy (output_string, ""); |
808 | strcpy (output_string, ""); |
… | |
… | |
849 | * MSW 2001-07-01 |
842 | * MSW 2001-07-01 |
850 | * return 0 on success, 1 on failure. |
843 | * return 0 on success, 1 on failure. |
851 | */ |
844 | */ |
852 | |
845 | |
853 | static int |
846 | static int |
854 | load_map_header (object_thawer & fp, mapstruct *m) |
847 | load_map_header (object_thawer & fp, maptile *m) |
855 | { |
848 | { |
856 | 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; |
857 | int msgpos = 0; |
850 | int msgpos = 0; |
858 | int maplorepos = 0; |
851 | int maplorepos = 0; |
859 | |
852 | |
860 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
853 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
861 | { |
854 | { |
862 | buf[HUGE_BUF - 1] = 0; |
855 | buf[HUGE_BUF - 1] = 0; |
863 | key = buf; |
856 | key = buf; |
|
|
857 | |
864 | while (isspace (*key)) |
858 | while (isspace (*key)) |
865 | key++; |
859 | key++; |
|
|
860 | |
866 | if (*key == 0) |
861 | if (*key == 0) |
867 | continue; /* empty line */ |
862 | continue; /* empty line */ |
|
|
863 | |
868 | value = strchr (key, ' '); |
864 | value = strchr (key, ' '); |
|
|
865 | |
869 | if (!value) |
866 | if (!value) |
870 | { |
867 | { |
871 | end = strchr (key, '\n'); |
868 | if ((end = strchr (key, '\n'))) |
872 | if (end != NULL) |
|
|
873 | { |
|
|
874 | *end = 0; |
869 | *end = 0; |
875 | } |
|
|
876 | } |
870 | } |
877 | else |
871 | else |
878 | { |
872 | { |
879 | *value = 0; |
873 | *value = 0; |
880 | value++; |
874 | value++; |
881 | end = strchr (value, '\n'); |
875 | end = strchr (value, '\n'); |
|
|
876 | |
882 | while (isspace (*value)) |
877 | while (isspace (*value)) |
883 | { |
878 | { |
884 | value++; |
879 | value++; |
|
|
880 | |
885 | if (*value == '\0' || value == end) |
881 | if (*value == '\0' || value == end) |
886 | { |
882 | { |
887 | /* Nothing but spaces. */ |
883 | /* Nothing but spaces. */ |
888 | value = NULL; |
884 | value = NULL; |
889 | break; |
885 | break; |
… | |
… | |
912 | * that use the parameter. |
908 | * that use the parameter. |
913 | */ |
909 | */ |
914 | |
910 | |
915 | if (!strcmp (key, "msg")) |
911 | if (!strcmp (key, "msg")) |
916 | { |
912 | { |
917 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
913 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
918 | { |
914 | { |
919 | if (!strcmp (buf, "endmsg\n")) |
915 | if (!strcmp (buf, "endmsg\n")) |
920 | break; |
916 | break; |
921 | else |
917 | else |
922 | { |
918 | { |
… | |
… | |
933 | if (msgpos != 0) |
929 | if (msgpos != 0) |
934 | m->msg = strdup_local (msgbuf); |
930 | m->msg = strdup_local (msgbuf); |
935 | } |
931 | } |
936 | else if (!strcmp (key, "maplore")) |
932 | else if (!strcmp (key, "maplore")) |
937 | { |
933 | { |
938 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
934 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
939 | { |
935 | { |
940 | if (!strcmp (buf, "endmaplore\n")) |
936 | if (!strcmp (buf, "endmaplore\n")) |
941 | break; |
937 | break; |
942 | else |
938 | else |
943 | { |
939 | { |
… | |
… | |
1147 | } |
1143 | } |
1148 | |
1144 | |
1149 | /* |
1145 | /* |
1150 | * Opens the file "filename" and reads information about the map |
1146 | * Opens the file "filename" and reads information about the map |
1151 | * from the given file, and stores it in a newly allocated |
1147 | * from the given file, and stores it in a newly allocated |
1152 | * mapstruct. A pointer to this structure is returned, or NULL on failure. |
1148 | * maptile. A pointer to this structure is returned, or NULL on failure. |
1153 | * flags correspond to those in map.h. Main ones used are |
1149 | * flags correspond to those in map.h. Main ones used are |
1154 | * MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and |
1150 | * MAP_PLAYER_UNIQUE, in which case we don't do any name changes, and |
1155 | * MAP_BLOCK, in which case we block on this load. This happens in all |
1151 | * MAP_BLOCK, in which case we block on this load. This happens in all |
1156 | * cases, no matter if this flag is set or not. |
1152 | * cases, no matter if this flag is set or not. |
1157 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1153 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1158 | * managed map list. |
1154 | * managed map list. |
1159 | */ |
1155 | */ |
1160 | |
1156 | |
1161 | mapstruct * |
1157 | maptile * |
1162 | load_original_map (const char *filename, int flags) |
1158 | load_original_map (const char *filename, int flags) |
1163 | { |
1159 | { |
1164 | mapstruct *m; |
1160 | maptile *m; |
1165 | char pathname[MAX_BUF]; |
1161 | char pathname[MAX_BUF]; |
1166 | |
1162 | |
1167 | if (flags & MAP_PLAYER_UNIQUE) |
1163 | if (flags & MAP_PLAYER_UNIQUE) |
1168 | strcpy (pathname, filename); |
1164 | strcpy (pathname, filename); |
1169 | else if (flags & MAP_OVERLAY) |
1165 | else if (flags & MAP_OVERLAY) |
… | |
… | |
1186 | 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); |
1187 | delete_map (m); |
1183 | delete_map (m); |
1188 | return NULL; |
1184 | return NULL; |
1189 | } |
1185 | } |
1190 | |
1186 | |
1191 | allocate_map (m); |
1187 | m->allocate (); |
1192 | |
1188 | |
1193 | m->in_memory = MAP_LOADING; |
1189 | m->in_memory = MAP_LOADING; |
1194 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1190 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1195 | |
1191 | |
1196 | m->in_memory = MAP_IN_MEMORY; |
1192 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1205 | * Loads a map, which has been loaded earlier, from file. |
1201 | * Loads a map, which has been loaded earlier, from file. |
1206 | * Return the map object we load into (this can change from the passed |
1202 | * Return the map object we load into (this can change from the passed |
1207 | * option if we can't find the original map) |
1203 | * option if we can't find the original map) |
1208 | */ |
1204 | */ |
1209 | |
1205 | |
1210 | static mapstruct * |
1206 | static maptile * |
1211 | load_temporary_map (mapstruct *m) |
1207 | load_temporary_map (maptile *m) |
1212 | { |
1208 | { |
1213 | char buf[MAX_BUF]; |
1209 | char buf[MAX_BUF]; |
1214 | |
1210 | |
1215 | if (!m->tmpname) |
1211 | if (!m->tmpname) |
1216 | { |
1212 | { |
… | |
… | |
1242 | 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); |
1243 | delete_map (m); |
1239 | delete_map (m); |
1244 | m = load_original_map (m->path, 0); |
1240 | m = load_original_map (m->path, 0); |
1245 | return NULL; |
1241 | return NULL; |
1246 | } |
1242 | } |
|
|
1243 | |
1247 | allocate_map (m); |
1244 | m->allocate (); |
1248 | |
1245 | |
1249 | m->in_memory = MAP_LOADING; |
1246 | m->in_memory = MAP_LOADING; |
1250 | load_objects (m, thawer, 0); |
1247 | load_objects (m, thawer, 0); |
1251 | |
1248 | |
1252 | m->in_memory = MAP_IN_MEMORY; |
1249 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1258 | * Loads a map, which has been loaded earlier, from file. |
1255 | * Loads a map, which has been loaded earlier, from file. |
1259 | * Return the map object we load into (this can change from the passed |
1256 | * Return the map object we load into (this can change from the passed |
1260 | * option if we can't find the original map) |
1257 | * option if we can't find the original map) |
1261 | */ |
1258 | */ |
1262 | |
1259 | |
1263 | mapstruct * |
1260 | maptile * |
1264 | load_overlay_map (const char *filename, mapstruct *m) |
1261 | load_overlay_map (const char *filename, maptile *m) |
1265 | { |
1262 | { |
1266 | char pathname[MAX_BUF]; |
1263 | char pathname[MAX_BUF]; |
1267 | |
1264 | |
1268 | strcpy (pathname, create_overlay_pathname (filename)); |
1265 | strcpy (pathname, create_overlay_pathname (filename)); |
1269 | |
1266 | |
… | |
… | |
1277 | 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); |
1278 | delete_map (m); |
1275 | delete_map (m); |
1279 | m = load_original_map (m->path, 0); |
1276 | m = load_original_map (m->path, 0); |
1280 | return NULL; |
1277 | return NULL; |
1281 | } |
1278 | } |
1282 | /*allocate_map(m); */ |
1279 | /*m->allocate ();*/ |
1283 | |
1280 | |
1284 | m->in_memory = MAP_LOADING; |
1281 | m->in_memory = MAP_LOADING; |
1285 | load_objects (m, thawer, MAP_OVERLAY); |
1282 | load_objects (m, thawer, MAP_OVERLAY); |
1286 | |
1283 | |
1287 | m->in_memory = MAP_IN_MEMORY; |
1284 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1292 | * This is the start of unique map handling code |
1289 | * This is the start of unique map handling code |
1293 | *****************************************************************************/ |
1290 | *****************************************************************************/ |
1294 | |
1291 | |
1295 | /* This goes through map 'm' and removed any unique items on the map. */ |
1292 | /* This goes through map 'm' and removed any unique items on the map. */ |
1296 | static void |
1293 | static void |
1297 | delete_unique_items (mapstruct *m) |
1294 | delete_unique_items (maptile *m) |
1298 | { |
1295 | { |
1299 | int i, j, unique; |
1296 | int i, j, unique; |
1300 | object *op, *next; |
1297 | object *op, *next; |
1301 | |
1298 | |
1302 | for (i = 0; i < MAP_WIDTH (m); i++) |
1299 | for (i = 0; i < MAP_WIDTH (m); i++) |
… | |
… | |
1324 | /* |
1321 | /* |
1325 | * Loads unique objects from file(s) into the map which is in memory |
1322 | * Loads unique objects from file(s) into the map which is in memory |
1326 | * m is the map to load unique items into. |
1323 | * m is the map to load unique items into. |
1327 | */ |
1324 | */ |
1328 | static void |
1325 | static void |
1329 | load_unique_objects (mapstruct *m) |
1326 | load_unique_objects (maptile *m) |
1330 | { |
1327 | { |
1331 | int count; |
1328 | int count; |
1332 | char firstname[MAX_BUF]; |
1329 | char firstname[MAX_BUF]; |
1333 | |
1330 | |
1334 | for (count = 0; count < 10; count++) |
1331 | for (count = 0; count < 10; count++) |
… | |
… | |
1357 | |
1354 | |
1358 | /* |
1355 | /* |
1359 | * Saves a map to file. If flag is set, it is saved into the same |
1356 | * Saves a map to file. If flag is set, it is saved into the same |
1360 | * file it was (originally) loaded from. Otherwise a temporary |
1357 | * file it was (originally) loaded from. Otherwise a temporary |
1361 | * filename will be genarated, and the file will be stored there. |
1358 | * filename will be genarated, and the file will be stored there. |
1362 | * The temporary filename will be stored in the mapstructure. |
1359 | * The temporary filename will be stored in the maptileure. |
1363 | * If the map is unique, we also save to the filename in the map |
1360 | * If the map is unique, we also save to the filename in the map |
1364 | * (this should have been updated when first loaded) |
1361 | * (this should have been updated when first loaded) |
1365 | */ |
1362 | */ |
1366 | |
1363 | |
1367 | int |
1364 | int |
1368 | new_save_map (mapstruct *m, int flag) |
1365 | new_save_map (maptile *m, int flag) |
1369 | { |
1366 | { |
1370 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1367 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1371 | int i; |
1368 | int i; |
1372 | |
1369 | |
1373 | if (flag && !*m->path) |
1370 | if (flag && !*m->path) |
… | |
… | |
1425 | print_shop_string (m, shop); |
1422 | print_shop_string (m, shop); |
1426 | fprintf (freezer, "shopitems %s\n", shop); |
1423 | fprintf (freezer, "shopitems %s\n", shop); |
1427 | } |
1424 | } |
1428 | if (m->shopgreed) |
1425 | if (m->shopgreed) |
1429 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1426 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1430 | #ifndef WIN32 |
|
|
1431 | if (m->shopmin) |
1427 | if (m->shopmin) |
1432 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1428 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1433 | if (m->shopmax) |
1429 | if (m->shopmax) |
1434 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1430 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1435 | #else |
|
|
1436 | if (m->shopmin) |
|
|
1437 | fprintf (freezer, "shopmin %I64u\n", m->shopmin); |
|
|
1438 | if (m->shopmax) |
|
|
1439 | fprintf (freezer, "shopmax %I64u\n", m->shopmax); |
|
|
1440 | #endif |
|
|
1441 | if (m->shoprace) |
1431 | if (m->shoprace) |
1442 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1432 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1443 | if (m->darkness) |
1433 | if (m->darkness) |
1444 | fprintf (freezer, "darkness %d\n", m->darkness); |
1434 | fprintf (freezer, "darkness %d\n", m->darkness); |
1445 | if (m->width) |
1435 | if (m->width) |
… | |
… | |
1537 | /* |
1527 | /* |
1538 | * Remove and free all objects in the given map. |
1528 | * Remove and free all objects in the given map. |
1539 | */ |
1529 | */ |
1540 | |
1530 | |
1541 | void |
1531 | void |
1542 | free_all_objects (mapstruct *m) |
1532 | free_all_objects (maptile *m) |
1543 | { |
1533 | { |
1544 | int i, j; |
1534 | int i, j; |
1545 | object *op; |
1535 | object *op; |
1546 | |
1536 | |
1547 | for (i = 0; i < MAP_WIDTH (m); i++) |
1537 | for (i = 0; i < MAP_WIDTH (m); i++) |
… | |
… | |
1570 | } |
1560 | } |
1571 | } |
1561 | } |
1572 | } |
1562 | } |
1573 | |
1563 | |
1574 | /* |
1564 | /* |
1575 | * Frees everything allocated by the given mapstructure. |
1565 | * Frees everything allocated by the given maptileure. |
1576 | * don't free tmpname - our caller is left to do that |
1566 | * don't free tmpname - our caller is left to do that |
1577 | */ |
1567 | */ |
1578 | |
1568 | |
1579 | void |
1569 | void |
1580 | free_map (mapstruct *m, int flag) |
1570 | free_map (maptile *m, int flag) |
1581 | { |
1571 | { |
1582 | int i; |
1572 | int i; |
1583 | |
1573 | |
1584 | if (!m->in_memory) |
1574 | if (!m->in_memory) |
1585 | { |
1575 | { |
… | |
… | |
1612 | } |
1602 | } |
1613 | m->in_memory = MAP_SWAPPED; |
1603 | m->in_memory = MAP_SWAPPED; |
1614 | } |
1604 | } |
1615 | |
1605 | |
1616 | /* |
1606 | /* |
1617 | * function: vanish mapstruct |
1607 | * function: vanish maptile |
1618 | * m : pointer to mapstruct, if NULL no action |
1608 | * m : pointer to maptile, if NULL no action |
1619 | * this deletes all the data on the map (freeing pointers) |
1609 | * this deletes all the data on the map (freeing pointers) |
1620 | * and then removes this map from the global linked list of maps. |
1610 | * and then removes this map from the global linked list of maps. |
1621 | */ |
1611 | */ |
1622 | |
1612 | |
1623 | void |
1613 | void |
1624 | delete_map (mapstruct *m) |
1614 | delete_map (maptile *m) |
1625 | { |
1615 | { |
1626 | mapstruct *tmp, *last; |
1616 | maptile *tmp, *last; |
1627 | int i; |
1617 | int i; |
1628 | |
1618 | |
1629 | if (!m) |
1619 | if (!m) |
1630 | return; |
1620 | return; |
1631 | |
1621 | |
… | |
… | |
1693 | * dont do any more name translation on it. |
1683 | * dont do any more name translation on it. |
1694 | * |
1684 | * |
1695 | * Returns a pointer to the given map. |
1685 | * Returns a pointer to the given map. |
1696 | */ |
1686 | */ |
1697 | |
1687 | |
1698 | mapstruct * |
1688 | maptile * |
1699 | ready_map_name (const char *name, int flags) |
1689 | ready_map_name (const char *name, int flags) |
1700 | { |
1690 | { |
1701 | mapstruct *m; |
1691 | maptile *m; |
1702 | |
1692 | |
1703 | if (!name) |
1693 | if (!name) |
1704 | return (NULL); |
1694 | return (NULL); |
1705 | |
1695 | |
1706 | /* Have we been at this level before? */ |
1696 | /* Have we been at this level before? */ |
… | |
… | |
1808 | * have a difficulty set than using this function - human calculation |
1798 | * have a difficulty set than using this function - human calculation |
1809 | * is much better than this functions guesswork. |
1799 | * is much better than this functions guesswork. |
1810 | */ |
1800 | */ |
1811 | |
1801 | |
1812 | int |
1802 | int |
1813 | calculate_difficulty (mapstruct *m) |
1803 | calculate_difficulty (maptile *m) |
1814 | { |
1804 | { |
1815 | object *op; |
1805 | object *op; |
1816 | archetype *at; |
1806 | archetype *at; |
1817 | int x, y, i; |
1807 | int x, y, i; |
1818 | long monster_cnt = 0; |
1808 | long monster_cnt = 0; |
… | |
… | |
1860 | |
1850 | |
1861 | return 1; |
1851 | return 1; |
1862 | } |
1852 | } |
1863 | |
1853 | |
1864 | void |
1854 | void |
1865 | clean_tmp_map (mapstruct *m) |
1855 | clean_tmp_map (maptile *m) |
1866 | { |
1856 | { |
1867 | if (m->tmpname == NULL) |
1857 | if (m->tmpname == NULL) |
1868 | return; |
1858 | return; |
1869 | INVOKE_MAP (CLEAN, m); |
1859 | INVOKE_MAP (CLEAN, m); |
1870 | (void) unlink (m->tmpname); |
1860 | (void) unlink (m->tmpname); |
… | |
… | |
1895 | * to maps than los. |
1885 | * to maps than los. |
1896 | * postive values make it darker, negative make it brighter |
1886 | * postive values make it darker, negative make it brighter |
1897 | */ |
1887 | */ |
1898 | |
1888 | |
1899 | int |
1889 | int |
1900 | change_map_light (mapstruct *m, int change) |
1890 | change_map_light (maptile *m, int change) |
1901 | { |
1891 | { |
1902 | int new_level = m->darkness + change; |
1892 | int new_level = m->darkness + change; |
1903 | |
1893 | |
1904 | /* Nothing to do */ |
1894 | /* Nothing to do */ |
1905 | if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) |
1895 | if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) |
… | |
… | |
1936 | * on the map (what it looks like, whether it blocks magic, |
1926 | * on the map (what it looks like, whether it blocks magic, |
1937 | * has a living creatures, prevents people from passing |
1927 | * has a living creatures, prevents people from passing |
1938 | * through, etc) |
1928 | * through, etc) |
1939 | */ |
1929 | */ |
1940 | void |
1930 | void |
1941 | update_position (mapstruct *m, int x, int y) |
1931 | update_position (maptile *m, int x, int y) |
1942 | { |
1932 | { |
1943 | object *tmp, *last = NULL; |
1933 | object *tmp, *last = NULL; |
1944 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1934 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1945 | New_Face *top, *floor, *middle; |
1935 | New_Face *top, *floor, *middle; |
1946 | object *top_obj, *floor_obj, *middle_obj; |
1936 | object *top_obj, *floor_obj, *middle_obj; |
… | |
… | |
2139 | SET_MAP_LIGHT (m, x, y, light); |
2129 | SET_MAP_LIGHT (m, x, y, light); |
2140 | } |
2130 | } |
2141 | |
2131 | |
2142 | |
2132 | |
2143 | void |
2133 | void |
2144 | set_map_reset_time (mapstruct *map) |
2134 | set_map_reset_time (maptile *map) |
2145 | { |
2135 | { |
2146 | int timeout; |
2136 | int timeout; |
2147 | |
2137 | |
2148 | timeout = MAP_RESET_TIMEOUT (map); |
2138 | timeout = MAP_RESET_TIMEOUT (map); |
2149 | if (timeout <= 0) |
2139 | if (timeout <= 0) |
… | |
… | |
2158 | * maps tile_map values if it tiles back to this one. It returns |
2148 | * maps tile_map values if it tiles back to this one. It returns |
2159 | * the value of orig_map->tile_map[tile_num]. It really only does this |
2149 | * the value of orig_map->tile_map[tile_num]. It really only does this |
2160 | * so that it is easier for calling functions to verify success. |
2150 | * so that it is easier for calling functions to verify success. |
2161 | */ |
2151 | */ |
2162 | |
2152 | |
2163 | static mapstruct * |
2153 | static maptile * |
2164 | load_and_link_tiled_map (mapstruct *orig_map, int tile_num) |
2154 | load_and_link_tiled_map (maptile *orig_map, int tile_num) |
2165 | { |
2155 | { |
2166 | int dest_tile = (tile_num + 2) % 4; |
2156 | int dest_tile = (tile_num + 2) % 4; |
2167 | char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); |
2157 | char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); |
2168 | |
2158 | |
2169 | orig_map->tile_map[tile_num] = ready_map_name (path, 0); |
2159 | orig_map->tile_map[tile_num] = ready_map_name (path, 0); |
… | |
… | |
2184 | * tiled maps. |
2174 | * tiled maps. |
2185 | * |
2175 | * |
2186 | * |
2176 | * |
2187 | */ |
2177 | */ |
2188 | int |
2178 | int |
2189 | out_of_map (mapstruct *m, int x, int y) |
2179 | out_of_map (maptile *m, int x, int y) |
2190 | { |
2180 | { |
2191 | |
2181 | |
2192 | /* If we get passed a null map, this is obviously the |
2182 | /* If we get passed a null map, this is obviously the |
2193 | * case. This generally shouldn't happen, but if the |
2183 | * case. This generally shouldn't happen, but if the |
2194 | * map loads fail below, it could happen. |
2184 | * map loads fail below, it could happen. |
… | |
… | |
2249 | * the map as that the coordinates are really on, and |
2239 | * the map as that the coordinates are really on, and |
2250 | * updates x and y to be the localized coordinates. |
2240 | * updates x and y to be the localized coordinates. |
2251 | * Using this is more efficient of calling out_of_map |
2241 | * Using this is more efficient of calling out_of_map |
2252 | * and then figuring out what the real map is |
2242 | * and then figuring out what the real map is |
2253 | */ |
2243 | */ |
2254 | mapstruct * |
2244 | maptile * |
2255 | get_map_from_coord (mapstruct *m, sint16 * x, sint16 * y) |
2245 | get_map_from_coord (maptile *m, sint16 * x, sint16 * y) |
2256 | { |
2246 | { |
2257 | |
2247 | |
2258 | if (*x < 0) |
2248 | if (*x < 0) |
2259 | { |
2249 | { |
2260 | if (!m->tile_path[3]) |
2250 | if (!m->tile_path[3]) |
… | |
… | |
2306 | /** |
2296 | /** |
2307 | * Return whether map2 is adjacent to map1. If so, store the distance from |
2297 | * Return whether map2 is adjacent to map1. If so, store the distance from |
2308 | * map1 to map2 in dx/dy. |
2298 | * map1 to map2 in dx/dy. |
2309 | */ |
2299 | */ |
2310 | static int |
2300 | static int |
2311 | adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) |
2301 | adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy) |
2312 | { |
2302 | { |
2313 | if (!map1 || !map2) |
2303 | if (!map1 || !map2) |
2314 | return 0; |
2304 | return 0; |
2315 | |
2305 | |
2316 | if (map1 == map2) |
2306 | if (map1 == map2) |
… | |
… | |
2474 | * for something in the future. Also, since no object is pasted, the best |
2464 | * for something in the future. Also, since no object is pasted, the best |
2475 | * field of the rv_vector is set to NULL. |
2465 | * field of the rv_vector is set to NULL. |
2476 | */ |
2466 | */ |
2477 | |
2467 | |
2478 | void |
2468 | void |
2479 | get_rangevector_from_mapcoord (const mapstruct *m, int x, int y, const object *op2, rv_vector * retval, int flags) |
2469 | get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector * retval, int flags) |
2480 | { |
2470 | { |
2481 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
2471 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
2482 | { |
2472 | { |
2483 | /* be conservative and fill in _some_ data */ |
2473 | /* be conservative and fill in _some_ data */ |
2484 | retval->distance = 100000; |
2474 | retval->distance = 100000; |