… | |
… | |
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 | |
549 | op = get_object (); |
537 | op = object::create (); |
550 | op->map = m; /* To handle buttons correctly */ |
538 | op->map = m; /* To handle buttons correctly */ |
551 | |
539 | |
552 | while ((i = load_object (fp, op, mapflags))) |
540 | while ((i = load_object (fp, op, mapflags))) |
553 | { |
541 | { |
554 | /* if the archetype for the object is null, means that we |
542 | /* if the archetype for the object is null, means that we |
… | |
… | |
562 | } |
550 | } |
563 | |
551 | |
564 | |
552 | |
565 | switch (i) |
553 | switch (i) |
566 | { |
554 | { |
567 | case LL_NORMAL: |
555 | case LL_NORMAL: |
568 | /* if we are loading an overlay, put the floors on the bottom */ |
556 | /* if we are loading an overlay, put the floors on the bottom */ |
569 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
557 | if ((QUERY_FLAG (op, FLAG_IS_FLOOR) || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)) && mapflags & MAP_OVERLAY) |
570 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
558 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY | INS_MAP_LOAD); |
571 | else |
559 | else |
572 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
560 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
573 | |
561 | |
574 | if (op->inv) |
562 | if (op->inv) |
575 | sum_weight (op); |
563 | sum_weight (op); |
576 | |
564 | |
577 | prev = op, last_more = op; |
565 | prev = op, last_more = op; |
578 | break; |
566 | break; |
579 | |
567 | |
580 | case LL_MORE: |
568 | case LL_MORE: |
581 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
569 | insert_ob_in_map (op, m, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ABOVE_FLOOR_ONLY); |
582 | op->head = prev, last_more->more = op, last_more = op; |
570 | op->head = prev, last_more->more = op, last_more = op; |
583 | break; |
571 | break; |
584 | } |
572 | } |
585 | |
573 | |
586 | if (mapflags & MAP_STYLE) |
574 | if (mapflags & MAP_STYLE) |
587 | remove_from_active_list (op); |
575 | remove_from_active_list (op); |
588 | |
576 | |
589 | op = get_object (); |
577 | op = object::create (); |
590 | op->map = m; |
578 | op->map = m; |
591 | } |
579 | } |
592 | |
580 | |
593 | for (i = 0; i < m->width; i++) |
581 | for (i = 0; i < m->width; i++) |
594 | { |
582 | { |
… | |
… | |
598 | /* check for unique items, or unique squares */ |
586 | /* check for unique items, or unique squares */ |
599 | for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) |
587 | for (otmp = get_map_ob (m, i, j); otmp; otmp = otmp->above) |
600 | { |
588 | { |
601 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
589 | if (QUERY_FLAG (otmp, FLAG_UNIQUE) || QUERY_FLAG (otmp, FLAG_OBJ_SAVE_ON_OVL)) |
602 | unique = 1; |
590 | unique = 1; |
|
|
591 | |
603 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
592 | if (!(mapflags & (MAP_OVERLAY | MAP_PLAYER_UNIQUE) || unique)) |
604 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
593 | SET_FLAG (otmp, FLAG_OBJ_ORIGINAL); |
605 | } |
594 | } |
606 | } |
595 | } |
607 | } |
596 | } |
608 | |
597 | |
609 | free_object (op); |
598 | op->destroy (); |
610 | link_multipart_objects (m); |
599 | link_multipart_objects (m); |
611 | } |
600 | } |
612 | |
601 | |
613 | /* This saves all the objects on the map in a non destructive fashion. |
602 | /* This saves all the objects on the map in a non destructive fashion. |
614 | * Modified by MSW 2001-07-01 to do in a single pass - reduces code, |
603 | * 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 |
604 | * and we only save the head of multi part objects - this is needed |
616 | * in order to do map tiling properly. |
605 | * in order to do map tiling properly. |
617 | */ |
606 | */ |
618 | void |
607 | void |
619 | save_objects (mapstruct *m, object_freezer & fp, object_freezer & fp2, int flag) |
608 | save_objects (maptile *m, object_freezer & fp, object_freezer & fp2, int flag) |
620 | { |
609 | { |
621 | int i, j = 0, unique = 0; |
610 | int i, j = 0, unique = 0; |
622 | object *op; |
611 | object *op; |
623 | |
612 | |
624 | /* first pass - save one-part objects */ |
613 | /* first pass - save one-part objects */ |
… | |
… | |
647 | |
636 | |
648 | } /* for this space */ |
637 | } /* for this space */ |
649 | } /* for this j */ |
638 | } /* for this j */ |
650 | } |
639 | } |
651 | |
640 | |
|
|
641 | maptile::maptile () |
|
|
642 | { |
|
|
643 | in_memory = MAP_SWAPPED; |
|
|
644 | /* The maps used to pick up default x and y values from the |
|
|
645 | * map archetype. Mimic that behaviour. |
|
|
646 | */ |
|
|
647 | MAP_WIDTH (this) = 16; |
|
|
648 | MAP_HEIGHT (this) = 16; |
|
|
649 | MAP_RESET_TIMEOUT (this) = 0; |
|
|
650 | MAP_TIMEOUT (this) = 300; |
|
|
651 | MAP_ENTER_X (this) = 0; |
|
|
652 | MAP_ENTER_Y (this) = 0; |
|
|
653 | /*set part to -1 indicating conversion to weather map not yet done */ |
|
|
654 | MAP_WORLDPARTX (this) = -1; |
|
|
655 | MAP_WORLDPARTY (this) = -1; |
|
|
656 | } |
|
|
657 | |
652 | /* |
658 | /* |
653 | * Allocates, initialises, and returns a pointer to a mapstruct. |
659 | * Allocates, initialises, and returns a pointer to a maptile. |
654 | * Modified to no longer take a path option which was not being |
660 | * Modified to no longer take a path option which was not being |
655 | * used anyways. MSW 2001-07-01 |
661 | * used anyways. MSW 2001-07-01 |
656 | */ |
662 | */ |
657 | |
663 | maptile * |
658 | mapstruct * |
|
|
659 | get_linked_map (void) |
664 | get_linked_map (void) |
660 | { |
665 | { |
661 | mapstruct *map = new mapstruct; |
666 | maptile *mp, *map = new maptile; |
662 | mapstruct *mp; |
|
|
663 | |
667 | |
664 | for (mp = first_map; mp != NULL && mp->next != NULL; mp = mp->next); |
668 | for (mp = first_map; mp && mp->next; mp = mp->next); |
|
|
669 | |
665 | if (mp == NULL) |
670 | if (mp == NULL) |
666 | first_map = map; |
671 | first_map = map; |
667 | else |
672 | else |
668 | mp->next = map; |
673 | mp->next = map; |
669 | |
674 | |
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; |
675 | return map; |
684 | } |
676 | } |
685 | |
677 | |
686 | /* |
678 | /* |
687 | * Allocates the arrays contained in a mapstruct. |
679 | * Allocates the arrays contained in a maptile. |
688 | * This basically allocates the dynamic array of spaces for the |
680 | * This basically allocates the dynamic array of spaces for the |
689 | * map. |
681 | * map. |
690 | */ |
682 | */ |
691 | |
|
|
692 | void |
683 | void |
693 | allocate_map (mapstruct *m) |
684 | maptile::allocate () |
694 | { |
685 | { |
695 | m->in_memory = MAP_IN_MEMORY; |
686 | in_memory = MAP_IN_MEMORY; |
|
|
687 | |
696 | /* Log this condition and free the storage. We could I suppose |
688 | /* Log this condition and free the storage. We could I suppose |
697 | * realloc, but if the caller is presuming the data will be intact, |
689 | * realloc, but if the caller is presuming the data will be intact, |
698 | * that is their poor assumption. |
690 | * that is their poor assumption. |
699 | */ |
691 | */ |
700 | if (m->spaces) |
692 | if (spaces) |
701 | { |
693 | { |
702 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", m->path); |
694 | LOG (llevError, "allocate_map called with already allocated map (%s)\n", path); |
703 | free (m->spaces); |
695 | free (spaces); |
704 | } |
696 | } |
705 | |
697 | |
706 | m->spaces = (MapSpace *) calloc (1, MAP_WIDTH (m) * MAP_HEIGHT (m) * sizeof (MapSpace)); |
698 | spaces = (MapSpace *) |
|
|
699 | calloc (1, width * height * sizeof (MapSpace)); |
707 | |
700 | |
708 | if (m->spaces == NULL) |
701 | if (!spaces) |
709 | fatal (OUT_OF_MEMORY); |
702 | fatal (OUT_OF_MEMORY); |
710 | } |
703 | } |
711 | |
704 | |
712 | /* Create and returns a map of the specific size. Used |
705 | /* Create and returns a map of the specific size. Used |
713 | * in random map code and the editor. |
706 | * in random map code and the editor. |
714 | */ |
707 | */ |
715 | mapstruct * |
708 | maptile * |
716 | get_empty_map (int sizex, int sizey) |
709 | get_empty_map (int sizex, int sizey) |
717 | { |
710 | { |
718 | mapstruct *m = get_linked_map (); |
711 | maptile *m = get_linked_map (); |
719 | |
712 | |
720 | m->width = sizex; |
713 | m->width = sizex; |
721 | m->height = sizey; |
714 | m->height = sizey; |
722 | m->in_memory = MAP_SWAPPED; |
715 | m->in_memory = MAP_SWAPPED; |
723 | allocate_map (m); |
716 | m->allocate (); |
|
|
717 | |
724 | return m; |
718 | return m; |
725 | } |
719 | } |
726 | |
720 | |
727 | /* Takes a string from a map definition and outputs a pointer to the array of shopitems |
721 | /* 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 |
722 | * corresponding to that string. Memory is allocated for this, it must be freed |
… | |
… | |
805 | } |
799 | } |
806 | |
800 | |
807 | /* opposite of parse string, this puts the string that was originally fed in to |
801 | /* opposite of parse string, this puts the string that was originally fed in to |
808 | * the map (or something equivilent) into output_string. */ |
802 | * the map (or something equivilent) into output_string. */ |
809 | static void |
803 | static void |
810 | print_shop_string (mapstruct *m, char *output_string) |
804 | print_shop_string (maptile *m, char *output_string) |
811 | { |
805 | { |
812 | int i; |
806 | int i; |
813 | char tmp[MAX_BUF]; |
807 | char tmp[MAX_BUF]; |
814 | |
808 | |
815 | strcpy (output_string, ""); |
809 | strcpy (output_string, ""); |
… | |
… | |
849 | * MSW 2001-07-01 |
843 | * MSW 2001-07-01 |
850 | * return 0 on success, 1 on failure. |
844 | * return 0 on success, 1 on failure. |
851 | */ |
845 | */ |
852 | |
846 | |
853 | static int |
847 | static int |
854 | load_map_header (object_thawer & fp, mapstruct *m) |
848 | load_map_header (object_thawer & fp, maptile *m) |
855 | { |
849 | { |
856 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
850 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], maplorebuf[HUGE_BUF], *key = NULL, *value, *end; |
857 | int msgpos = 0; |
851 | int msgpos = 0; |
858 | int maplorepos = 0; |
852 | int maplorepos = 0; |
859 | |
853 | |
860 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
854 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
861 | { |
855 | { |
862 | buf[HUGE_BUF - 1] = 0; |
856 | buf[HUGE_BUF - 1] = 0; |
863 | key = buf; |
857 | key = buf; |
|
|
858 | |
864 | while (isspace (*key)) |
859 | while (isspace (*key)) |
865 | key++; |
860 | key++; |
|
|
861 | |
866 | if (*key == 0) |
862 | if (*key == 0) |
867 | continue; /* empty line */ |
863 | continue; /* empty line */ |
|
|
864 | |
868 | value = strchr (key, ' '); |
865 | value = strchr (key, ' '); |
|
|
866 | |
869 | if (!value) |
867 | if (!value) |
870 | { |
868 | { |
871 | end = strchr (key, '\n'); |
869 | if ((end = strchr (key, '\n'))) |
872 | if (end != NULL) |
|
|
873 | { |
|
|
874 | *end = 0; |
870 | *end = 0; |
875 | } |
|
|
876 | } |
871 | } |
877 | else |
872 | else |
878 | { |
873 | { |
879 | *value = 0; |
874 | *value = 0; |
880 | value++; |
875 | value++; |
881 | end = strchr (value, '\n'); |
876 | end = strchr (value, '\n'); |
|
|
877 | |
882 | while (isspace (*value)) |
878 | while (isspace (*value)) |
883 | { |
879 | { |
884 | value++; |
880 | value++; |
|
|
881 | |
885 | if (*value == '\0' || value == end) |
882 | if (*value == '\0' || value == end) |
886 | { |
883 | { |
887 | /* Nothing but spaces. */ |
884 | /* Nothing but spaces. */ |
888 | value = NULL; |
885 | value = NULL; |
889 | break; |
886 | break; |
… | |
… | |
912 | * that use the parameter. |
909 | * that use the parameter. |
913 | */ |
910 | */ |
914 | |
911 | |
915 | if (!strcmp (key, "msg")) |
912 | if (!strcmp (key, "msg")) |
916 | { |
913 | { |
917 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
914 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
918 | { |
915 | { |
919 | if (!strcmp (buf, "endmsg\n")) |
916 | if (!strcmp (buf, "endmsg\n")) |
920 | break; |
917 | break; |
921 | else |
918 | else |
922 | { |
919 | { |
… | |
… | |
933 | if (msgpos != 0) |
930 | if (msgpos != 0) |
934 | m->msg = strdup_local (msgbuf); |
931 | m->msg = strdup_local (msgbuf); |
935 | } |
932 | } |
936 | else if (!strcmp (key, "maplore")) |
933 | else if (!strcmp (key, "maplore")) |
937 | { |
934 | { |
938 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
935 | while (fgets (buf, HUGE_BUF, fp) != NULL) |
939 | { |
936 | { |
940 | if (!strcmp (buf, "endmaplore\n")) |
937 | if (!strcmp (buf, "endmaplore\n")) |
941 | break; |
938 | break; |
942 | else |
939 | else |
943 | { |
940 | { |
… | |
… | |
971 | /* first strcmp value on these are old names supported |
968 | /* first strcmp value on these are old names supported |
972 | * for compatibility reasons. The new values (second) are |
969 | * for compatibility reasons. The new values (second) are |
973 | * what really should be used. |
970 | * what really should be used. |
974 | */ |
971 | */ |
975 | else if (!strcmp (key, "oid")) |
972 | else if (!strcmp (key, "oid")) |
976 | { |
|
|
977 | fp.get (m, atoi (value)); |
973 | fp.get (m, atoi (value)); |
978 | } |
|
|
979 | else if (!strcmp (key, "attach")) |
974 | else if (!strcmp (key, "attach")) |
980 | { |
|
|
981 | m->attach = value; |
975 | m->attach = value; |
982 | } |
|
|
983 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
976 | else if (!strcmp (key, "hp") || !strcmp (key, "enter_x")) |
984 | { |
|
|
985 | m->enter_x = atoi (value); |
977 | m->enter_x = atoi (value); |
986 | } |
|
|
987 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
978 | else if (!strcmp (key, "sp") || !strcmp (key, "enter_y")) |
988 | { |
|
|
989 | m->enter_y = atoi (value); |
979 | m->enter_y = atoi (value); |
990 | } |
|
|
991 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
980 | else if (!strcmp (key, "x") || !strcmp (key, "width")) |
992 | { |
|
|
993 | m->width = atoi (value); |
981 | m->width = atoi (value); |
994 | } |
|
|
995 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
982 | else if (!strcmp (key, "y") || !strcmp (key, "height")) |
996 | { |
|
|
997 | m->height = atoi (value); |
983 | m->height = atoi (value); |
998 | } |
|
|
999 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
984 | else if (!strcmp (key, "weight") || !strcmp (key, "reset_timeout")) |
1000 | { |
|
|
1001 | m->reset_timeout = atoi (value); |
985 | m->reset_timeout = atoi (value); |
1002 | } |
|
|
1003 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
986 | else if (!strcmp (key, "value") || !strcmp (key, "swap_time")) |
1004 | { |
|
|
1005 | m->timeout = atoi (value); |
987 | m->timeout = atoi (value); |
1006 | } |
|
|
1007 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
988 | else if (!strcmp (key, "level") || !strcmp (key, "difficulty")) |
1008 | { |
989 | m->difficulty = clamp (atoi (value), 1, settings.max_level); |
1009 | m->difficulty = atoi (value); |
|
|
1010 | } |
|
|
1011 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
990 | else if (!strcmp (key, "invisible") || !strcmp (key, "darkness")) |
1012 | { |
|
|
1013 | m->darkness = atoi (value); |
991 | m->darkness = atoi (value); |
1014 | } |
|
|
1015 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
992 | else if (!strcmp (key, "stand_still") || !strcmp (key, "fixed_resettime")) |
1016 | { |
|
|
1017 | m->fixed_resettime = atoi (value); |
993 | m->fixed_resettime = atoi (value); |
1018 | } |
|
|
1019 | else if (!strcmp (key, "unique")) |
994 | else if (!strcmp (key, "unique")) |
1020 | { |
|
|
1021 | m->unique = atoi (value); |
995 | m->unique = atoi (value); |
1022 | } |
|
|
1023 | else if (!strcmp (key, "template")) |
996 | else if (!strcmp (key, "template")) |
1024 | { |
|
|
1025 | m->templatemap = atoi (value); |
997 | m->templatemap = atoi (value); |
1026 | } |
|
|
1027 | else if (!strcmp (key, "region")) |
998 | else if (!strcmp (key, "region")) |
1028 | { |
|
|
1029 | m->region = get_region_by_name (value); |
999 | m->region = get_region_by_name (value); |
1030 | } |
|
|
1031 | else if (!strcmp (key, "shopitems")) |
1000 | else if (!strcmp (key, "shopitems")) |
1032 | { |
1001 | { |
1033 | *end = 0; |
1002 | *end = 0; |
1034 | m->shopitems = parse_shop_string (value); |
1003 | m->shopitems = parse_shop_string (value); |
1035 | } |
1004 | } |
1036 | else if (!strcmp (key, "shopgreed")) |
1005 | else if (!strcmp (key, "shopgreed")) |
1037 | { |
|
|
1038 | m->shopgreed = atof (value); |
1006 | m->shopgreed = atof (value); |
1039 | } |
|
|
1040 | else if (!strcmp (key, "shopmin")) |
1007 | else if (!strcmp (key, "shopmin")) |
1041 | { |
|
|
1042 | m->shopmin = atol (value); |
1008 | m->shopmin = atol (value); |
1043 | } |
|
|
1044 | else if (!strcmp (key, "shopmax")) |
1009 | else if (!strcmp (key, "shopmax")) |
1045 | { |
|
|
1046 | m->shopmax = atol (value); |
1010 | m->shopmax = atol (value); |
1047 | } |
|
|
1048 | else if (!strcmp (key, "shoprace")) |
1011 | else if (!strcmp (key, "shoprace")) |
1049 | { |
1012 | { |
1050 | *end = 0; |
1013 | *end = 0; |
1051 | m->shoprace = strdup_local (value); |
1014 | m->shoprace = strdup_local (value); |
1052 | } |
1015 | } |
1053 | else if (!strcmp (key, "outdoor")) |
1016 | else if (!strcmp (key, "outdoor")) |
1054 | { |
|
|
1055 | m->outdoor = atoi (value); |
1017 | m->outdoor = atoi (value); |
1056 | } |
|
|
1057 | else if (!strcmp (key, "temp")) |
1018 | else if (!strcmp (key, "temp")) |
1058 | { |
|
|
1059 | m->temp = atoi (value); |
1019 | m->temp = atoi (value); |
1060 | } |
|
|
1061 | else if (!strcmp (key, "pressure")) |
1020 | else if (!strcmp (key, "pressure")) |
1062 | { |
|
|
1063 | m->pressure = atoi (value); |
1021 | m->pressure = atoi (value); |
1064 | } |
|
|
1065 | else if (!strcmp (key, "humid")) |
1022 | else if (!strcmp (key, "humid")) |
1066 | { |
|
|
1067 | m->humid = atoi (value); |
1023 | m->humid = atoi (value); |
1068 | } |
|
|
1069 | else if (!strcmp (key, "windspeed")) |
1024 | else if (!strcmp (key, "windspeed")) |
1070 | { |
|
|
1071 | m->windspeed = atoi (value); |
1025 | m->windspeed = atoi (value); |
1072 | } |
|
|
1073 | else if (!strcmp (key, "winddir")) |
1026 | else if (!strcmp (key, "winddir")) |
1074 | { |
|
|
1075 | m->winddir = atoi (value); |
1027 | m->winddir = atoi (value); |
1076 | } |
|
|
1077 | else if (!strcmp (key, "sky")) |
1028 | else if (!strcmp (key, "sky")) |
1078 | { |
|
|
1079 | m->sky = atoi (value); |
1029 | m->sky = atoi (value); |
1080 | } |
|
|
1081 | else if (!strcmp (key, "nosmooth")) |
1030 | else if (!strcmp (key, "nosmooth")) |
1082 | { |
|
|
1083 | m->nosmooth = atoi (value); |
1031 | m->nosmooth = atoi (value); |
1084 | } |
|
|
1085 | else if (!strncmp (key, "tile_path_", 10)) |
1032 | else if (!strncmp (key, "tile_path_", 10)) |
1086 | { |
1033 | { |
1087 | int tile = atoi (key + 10); |
1034 | int tile = atoi (key + 10); |
1088 | |
1035 | |
1089 | if (tile < 1 || tile > 4) |
1036 | if (tile < 1 || tile > 4) |
… | |
… | |
1132 | m->tile_path[tile - 1] = strdup_local (path); |
1079 | m->tile_path[tile - 1] = strdup_local (path); |
1133 | } |
1080 | } |
1134 | } /* end if tile direction (in)valid */ |
1081 | } /* end if tile direction (in)valid */ |
1135 | } |
1082 | } |
1136 | else |
1083 | else |
1137 | { |
|
|
1138 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1084 | LOG (llevError, "Got unknown value in map header: %s %s\n", key, value); |
1139 | } |
|
|
1140 | } |
1085 | } |
|
|
1086 | |
1141 | if (!key || strcmp (key, "end")) |
1087 | if (!key || strcmp (key, "end")) |
1142 | { |
1088 | { |
1143 | LOG (llevError, "Got premature eof on map header!\n"); |
1089 | LOG (llevError, "Got premature eof on map header!\n"); |
1144 | return 1; |
1090 | return 1; |
1145 | } |
1091 | } |
|
|
1092 | |
1146 | return 0; |
1093 | return 0; |
1147 | } |
1094 | } |
1148 | |
1095 | |
1149 | /* |
1096 | /* |
1150 | * Opens the file "filename" and reads information about the map |
1097 | * Opens the file "filename" and reads information about the map |
1151 | * from the given file, and stores it in a newly allocated |
1098 | * from the given file, and stores it in a newly allocated |
1152 | * mapstruct. A pointer to this structure is returned, or NULL on failure. |
1099 | * maptile. A pointer to this structure is returned, or NULL on failure. |
1153 | * flags correspond to those in map.h. Main ones used are |
1100 | * 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 |
1101 | * 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 |
1102 | * 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. |
1103 | * 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 |
1104 | * MAP_STYLE: style map - don't add active objects, don't add to server |
1158 | * managed map list. |
1105 | * managed map list. |
1159 | */ |
1106 | */ |
1160 | |
1107 | |
1161 | mapstruct * |
1108 | maptile * |
1162 | load_original_map (const char *filename, int flags) |
1109 | load_original_map (const char *filename, int flags) |
1163 | { |
1110 | { |
1164 | mapstruct *m; |
1111 | maptile *m; |
1165 | char pathname[MAX_BUF]; |
1112 | char pathname[MAX_BUF]; |
1166 | |
1113 | |
1167 | if (flags & MAP_PLAYER_UNIQUE) |
1114 | if (flags & MAP_PLAYER_UNIQUE) |
1168 | strcpy (pathname, filename); |
1115 | strcpy (pathname, filename); |
1169 | else if (flags & MAP_OVERLAY) |
1116 | else if (flags & MAP_OVERLAY) |
… | |
… | |
1186 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1133 | LOG (llevError, "Error loading map header for %s, flags=%d\n", filename, flags); |
1187 | delete_map (m); |
1134 | delete_map (m); |
1188 | return NULL; |
1135 | return NULL; |
1189 | } |
1136 | } |
1190 | |
1137 | |
1191 | allocate_map (m); |
1138 | m->allocate (); |
1192 | |
1139 | |
1193 | m->in_memory = MAP_LOADING; |
1140 | m->in_memory = MAP_LOADING; |
1194 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1141 | load_objects (m, thawer, flags & (MAP_BLOCK | MAP_STYLE)); |
1195 | |
1142 | |
1196 | m->in_memory = MAP_IN_MEMORY; |
1143 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1205 | * Loads a map, which has been loaded earlier, from file. |
1152 | * Loads a map, which has been loaded earlier, from file. |
1206 | * Return the map object we load into (this can change from the passed |
1153 | * Return the map object we load into (this can change from the passed |
1207 | * option if we can't find the original map) |
1154 | * option if we can't find the original map) |
1208 | */ |
1155 | */ |
1209 | |
1156 | |
1210 | static mapstruct * |
1157 | static maptile * |
1211 | load_temporary_map (mapstruct *m) |
1158 | load_temporary_map (maptile *m) |
1212 | { |
1159 | { |
1213 | char buf[MAX_BUF]; |
1160 | char buf[MAX_BUF]; |
1214 | |
1161 | |
1215 | if (!m->tmpname) |
1162 | if (!m->tmpname) |
1216 | { |
1163 | { |
… | |
… | |
1242 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1189 | LOG (llevError, "Error loading map header for %s (%s)\n", m->path, m->tmpname); |
1243 | delete_map (m); |
1190 | delete_map (m); |
1244 | m = load_original_map (m->path, 0); |
1191 | m = load_original_map (m->path, 0); |
1245 | return NULL; |
1192 | return NULL; |
1246 | } |
1193 | } |
|
|
1194 | |
1247 | allocate_map (m); |
1195 | m->allocate (); |
1248 | |
1196 | |
1249 | m->in_memory = MAP_LOADING; |
1197 | m->in_memory = MAP_LOADING; |
1250 | load_objects (m, thawer, 0); |
1198 | load_objects (m, thawer, 0); |
1251 | |
1199 | |
1252 | m->in_memory = MAP_IN_MEMORY; |
1200 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1258 | * Loads a map, which has been loaded earlier, from file. |
1206 | * Loads a map, which has been loaded earlier, from file. |
1259 | * Return the map object we load into (this can change from the passed |
1207 | * Return the map object we load into (this can change from the passed |
1260 | * option if we can't find the original map) |
1208 | * option if we can't find the original map) |
1261 | */ |
1209 | */ |
1262 | |
1210 | |
1263 | mapstruct * |
1211 | maptile * |
1264 | load_overlay_map (const char *filename, mapstruct *m) |
1212 | load_overlay_map (const char *filename, maptile *m) |
1265 | { |
1213 | { |
1266 | char pathname[MAX_BUF]; |
1214 | char pathname[MAX_BUF]; |
1267 | |
1215 | |
1268 | strcpy (pathname, create_overlay_pathname (filename)); |
1216 | strcpy (pathname, create_overlay_pathname (filename)); |
1269 | |
1217 | |
… | |
… | |
1277 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1225 | LOG (llevError, "Error loading map header for overlay %s (%s)\n", m->path, pathname); |
1278 | delete_map (m); |
1226 | delete_map (m); |
1279 | m = load_original_map (m->path, 0); |
1227 | m = load_original_map (m->path, 0); |
1280 | return NULL; |
1228 | return NULL; |
1281 | } |
1229 | } |
1282 | /*allocate_map(m); */ |
1230 | /*m->allocate ();*/ |
1283 | |
1231 | |
1284 | m->in_memory = MAP_LOADING; |
1232 | m->in_memory = MAP_LOADING; |
1285 | load_objects (m, thawer, MAP_OVERLAY); |
1233 | load_objects (m, thawer, MAP_OVERLAY); |
1286 | |
1234 | |
1287 | m->in_memory = MAP_IN_MEMORY; |
1235 | m->in_memory = MAP_IN_MEMORY; |
… | |
… | |
1292 | * This is the start of unique map handling code |
1240 | * This is the start of unique map handling code |
1293 | *****************************************************************************/ |
1241 | *****************************************************************************/ |
1294 | |
1242 | |
1295 | /* This goes through map 'm' and removed any unique items on the map. */ |
1243 | /* This goes through map 'm' and removed any unique items on the map. */ |
1296 | static void |
1244 | static void |
1297 | delete_unique_items (mapstruct *m) |
1245 | delete_unique_items (maptile *m) |
1298 | { |
1246 | { |
1299 | int i, j, unique; |
1247 | int i, j, unique; |
1300 | object *op, *next; |
1248 | object *op, *next; |
1301 | |
1249 | |
1302 | for (i = 0; i < MAP_WIDTH (m); i++) |
1250 | for (i = 0; i < MAP_WIDTH (m); i++) |
1303 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1251 | for (j = 0; j < MAP_HEIGHT (m); j++) |
1304 | { |
1252 | { |
1305 | unique = 0; |
1253 | unique = 0; |
|
|
1254 | |
1306 | for (op = get_map_ob (m, i, j); op; op = next) |
1255 | for (op = get_map_ob (m, i, j); op; op = next) |
1307 | { |
1256 | { |
1308 | next = op->above; |
1257 | next = op->above; |
|
|
1258 | |
1309 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1259 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
1310 | unique = 1; |
1260 | unique = 1; |
|
|
1261 | |
1311 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1262 | if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
1312 | { |
1263 | { |
1313 | clean_object (op); |
1264 | clean_object (op); |
|
|
1265 | |
1314 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1266 | if (QUERY_FLAG (op, FLAG_IS_LINKED)) |
1315 | remove_button_link (op); |
1267 | remove_button_link (op); |
1316 | remove_ob (op); |
1268 | |
1317 | free_object (op); |
1269 | op->destroy (); |
1318 | } |
1270 | } |
1319 | } |
1271 | } |
1320 | } |
1272 | } |
1321 | } |
1273 | } |
1322 | |
1274 | |
… | |
… | |
1324 | /* |
1276 | /* |
1325 | * Loads unique objects from file(s) into the map which is in memory |
1277 | * Loads unique objects from file(s) into the map which is in memory |
1326 | * m is the map to load unique items into. |
1278 | * m is the map to load unique items into. |
1327 | */ |
1279 | */ |
1328 | static void |
1280 | static void |
1329 | load_unique_objects (mapstruct *m) |
1281 | load_unique_objects (maptile *m) |
1330 | { |
1282 | { |
1331 | int count; |
1283 | int count; |
1332 | char firstname[MAX_BUF]; |
1284 | char firstname[MAX_BUF]; |
1333 | |
1285 | |
1334 | for (count = 0; count < 10; count++) |
1286 | for (count = 0; count < 10; count++) |
… | |
… | |
1357 | |
1309 | |
1358 | /* |
1310 | /* |
1359 | * Saves a map to file. If flag is set, it is saved into the same |
1311 | * 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 |
1312 | * file it was (originally) loaded from. Otherwise a temporary |
1361 | * filename will be genarated, and the file will be stored there. |
1313 | * filename will be genarated, and the file will be stored there. |
1362 | * The temporary filename will be stored in the mapstructure. |
1314 | * The temporary filename will be stored in the maptileure. |
1363 | * If the map is unique, we also save to the filename in the map |
1315 | * If the map is unique, we also save to the filename in the map |
1364 | * (this should have been updated when first loaded) |
1316 | * (this should have been updated when first loaded) |
1365 | */ |
1317 | */ |
1366 | |
1318 | |
1367 | int |
1319 | int |
1368 | new_save_map (mapstruct *m, int flag) |
1320 | new_save_map (maptile *m, int flag) |
1369 | { |
1321 | { |
1370 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1322 | char filename[MAX_BUF], buf[MAX_BUF], shop[MAX_BUF]; |
1371 | int i; |
1323 | int i; |
1372 | |
1324 | |
1373 | if (flag && !*m->path) |
1325 | if (flag && !*m->path) |
… | |
… | |
1425 | print_shop_string (m, shop); |
1377 | print_shop_string (m, shop); |
1426 | fprintf (freezer, "shopitems %s\n", shop); |
1378 | fprintf (freezer, "shopitems %s\n", shop); |
1427 | } |
1379 | } |
1428 | if (m->shopgreed) |
1380 | if (m->shopgreed) |
1429 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1381 | fprintf (freezer, "shopgreed %f\n", m->shopgreed); |
1430 | #ifndef WIN32 |
|
|
1431 | if (m->shopmin) |
1382 | if (m->shopmin) |
1432 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1383 | fprintf (freezer, "shopmin %llu\n", m->shopmin); |
1433 | if (m->shopmax) |
1384 | if (m->shopmax) |
1434 | fprintf (freezer, "shopmax %llu\n", m->shopmax); |
1385 | 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) |
1386 | if (m->shoprace) |
1442 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1387 | fprintf (freezer, "shoprace %s\n", m->shoprace); |
1443 | if (m->darkness) |
1388 | if (m->darkness) |
1444 | fprintf (freezer, "darkness %d\n", m->darkness); |
1389 | fprintf (freezer, "darkness %d\n", m->darkness); |
1445 | if (m->width) |
1390 | if (m->width) |
… | |
… | |
1524 | object *tmp, *next; |
1469 | object *tmp, *next; |
1525 | |
1470 | |
1526 | for (tmp = op->inv; tmp; tmp = next) |
1471 | for (tmp = op->inv; tmp; tmp = next) |
1527 | { |
1472 | { |
1528 | next = tmp->below; |
1473 | next = tmp->below; |
|
|
1474 | |
1529 | clean_object (tmp); |
1475 | clean_object (tmp); |
1530 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1476 | if (QUERY_FLAG (tmp, FLAG_IS_LINKED)) |
1531 | remove_button_link (tmp); |
1477 | remove_button_link (tmp); |
1532 | remove_ob (tmp); |
1478 | |
1533 | free_object (tmp); |
1479 | tmp->destroy (); |
1534 | } |
1480 | } |
1535 | } |
1481 | } |
1536 | |
1482 | |
1537 | /* |
1483 | /* |
1538 | * Remove and free all objects in the given map. |
1484 | * Remove and free all objects in the given map. |
1539 | */ |
1485 | */ |
1540 | |
1486 | |
1541 | void |
1487 | void |
1542 | free_all_objects (mapstruct *m) |
1488 | free_all_objects (maptile *m) |
1543 | { |
1489 | { |
1544 | int i, j; |
1490 | int i, j; |
1545 | object *op; |
1491 | object *op; |
1546 | |
1492 | |
1547 | for (i = 0; i < MAP_WIDTH (m); i++) |
1493 | for (i = 0; i < MAP_WIDTH (m); i++) |
… | |
… | |
1554 | if (op == previous_obj) |
1500 | if (op == previous_obj) |
1555 | { |
1501 | { |
1556 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1502 | LOG (llevDebug, "free_all_objects: Link error, bailing out.\n"); |
1557 | break; |
1503 | break; |
1558 | } |
1504 | } |
|
|
1505 | |
1559 | previous_obj = op; |
1506 | previous_obj = op; |
|
|
1507 | |
1560 | if (op->head != NULL) |
1508 | if (op->head != NULL) |
1561 | op = op->head; |
1509 | op = op->head; |
1562 | |
1510 | |
1563 | /* If the map isn't in memory, free_object will remove and |
1511 | /* If the map isn't in memory, free_object will remove and |
1564 | * free objects in op's inventory. So let it do the job. |
1512 | * free objects in op's inventory. So let it do the job. |
1565 | */ |
1513 | */ |
1566 | if (m->in_memory == MAP_IN_MEMORY) |
1514 | if (m->in_memory == MAP_IN_MEMORY) |
1567 | clean_object (op); |
1515 | clean_object (op); |
1568 | remove_ob (op); |
1516 | |
1569 | free_object (op); |
1517 | op->destroy (); |
1570 | } |
1518 | } |
1571 | } |
1519 | } |
1572 | } |
1520 | } |
1573 | |
1521 | |
1574 | /* |
1522 | /* |
1575 | * Frees everything allocated by the given mapstructure. |
1523 | * Frees everything allocated by the given maptileure. |
1576 | * don't free tmpname - our caller is left to do that |
1524 | * don't free tmpname - our caller is left to do that |
1577 | */ |
1525 | */ |
1578 | |
1526 | |
1579 | void |
1527 | void |
1580 | free_map (mapstruct *m, int flag) |
1528 | free_map (maptile *m, int flag) |
1581 | { |
1529 | { |
1582 | int i; |
1530 | int i; |
1583 | |
1531 | |
1584 | if (!m->in_memory) |
1532 | if (!m->in_memory) |
1585 | { |
1533 | { |
1586 | LOG (llevError, "Trying to free freed map.\n"); |
1534 | LOG (llevError, "Trying to free freed map.\n"); |
1587 | return; |
1535 | return; |
1588 | } |
1536 | } |
|
|
1537 | |
|
|
1538 | // TODO: use new/delete |
|
|
1539 | #define FREE_AND_CLEAR(p) { free (p); p = NULL; } |
|
|
1540 | |
1589 | if (flag && m->spaces) |
1541 | if (flag && m->spaces) |
1590 | free_all_objects (m); |
1542 | free_all_objects (m); |
1591 | if (m->name) |
1543 | if (m->name) |
1592 | FREE_AND_CLEAR (m->name); |
1544 | FREE_AND_CLEAR (m->name); |
1593 | if (m->spaces) |
1545 | if (m->spaces) |
1594 | FREE_AND_CLEAR (m->spaces); |
1546 | FREE_AND_CLEAR (m->spaces); |
1595 | if (m->msg) |
1547 | if (m->msg) |
1596 | FREE_AND_CLEAR (m->msg); |
1548 | FREE_AND_CLEAR (m->msg); |
1597 | if (m->maplore) |
1549 | if (m->maplore) |
1598 | FREE_AND_CLEAR (m->maplore); |
1550 | FREE_AND_CLEAR (m->maplore); |
1599 | if (m->shopitems) |
1551 | |
1600 | delete[]m->shopitems; |
1552 | delete [] m->shopitems; |
1601 | m->shopitems = 0; |
1553 | m->shopitems = 0; |
|
|
1554 | |
1602 | if (m->shoprace) |
1555 | if (m->shoprace) |
1603 | FREE_AND_CLEAR (m->shoprace); |
1556 | FREE_AND_CLEAR (m->shoprace); |
|
|
1557 | |
1604 | if (m->buttons) |
1558 | if (m->buttons) |
1605 | free_objectlinkpt (m->buttons); |
1559 | free_objectlinkpt (m->buttons); |
|
|
1560 | |
1606 | m->buttons = NULL; |
1561 | m->buttons = NULL; |
|
|
1562 | |
1607 | for (i = 0; i < 4; i++) |
1563 | for (i = 0; i < 4; i++) |
1608 | { |
1564 | { |
1609 | if (m->tile_path[i]) |
1565 | if (m->tile_path[i]) |
1610 | FREE_AND_CLEAR (m->tile_path[i]); |
1566 | FREE_AND_CLEAR (m->tile_path[i]); |
1611 | m->tile_map[i] = NULL; |
1567 | m->tile_map[i] = NULL; |
1612 | } |
1568 | } |
|
|
1569 | |
1613 | m->in_memory = MAP_SWAPPED; |
1570 | m->in_memory = MAP_SWAPPED; |
|
|
1571 | |
|
|
1572 | #undef FREE_AND_CLEAR |
|
|
1573 | |
1614 | } |
1574 | } |
1615 | |
1575 | |
1616 | /* |
1576 | /* |
1617 | * function: vanish mapstruct |
1577 | * function: vanish maptile |
1618 | * m : pointer to mapstruct, if NULL no action |
1578 | * m : pointer to maptile, if NULL no action |
1619 | * this deletes all the data on the map (freeing pointers) |
1579 | * this deletes all the data on the map (freeing pointers) |
1620 | * and then removes this map from the global linked list of maps. |
1580 | * and then removes this map from the global linked list of maps. |
1621 | */ |
1581 | */ |
1622 | |
1582 | |
1623 | void |
1583 | void |
1624 | delete_map (mapstruct *m) |
1584 | delete_map (maptile *m) |
1625 | { |
1585 | { |
1626 | mapstruct *tmp, *last; |
1586 | maptile *tmp, *last; |
1627 | int i; |
1587 | int i; |
1628 | |
1588 | |
1629 | if (!m) |
1589 | if (!m) |
1630 | return; |
1590 | return; |
1631 | |
1591 | |
… | |
… | |
1693 | * dont do any more name translation on it. |
1653 | * dont do any more name translation on it. |
1694 | * |
1654 | * |
1695 | * Returns a pointer to the given map. |
1655 | * Returns a pointer to the given map. |
1696 | */ |
1656 | */ |
1697 | |
1657 | |
1698 | mapstruct * |
1658 | maptile * |
1699 | ready_map_name (const char *name, int flags) |
1659 | ready_map_name (const char *name, int flags) |
1700 | { |
1660 | { |
1701 | mapstruct *m; |
1661 | maptile *m; |
1702 | |
1662 | |
1703 | if (!name) |
1663 | if (!name) |
1704 | return (NULL); |
1664 | return (NULL); |
1705 | |
1665 | |
1706 | /* Have we been at this level before? */ |
1666 | /* Have we been at this level before? */ |
… | |
… | |
1808 | * have a difficulty set than using this function - human calculation |
1768 | * have a difficulty set than using this function - human calculation |
1809 | * is much better than this functions guesswork. |
1769 | * is much better than this functions guesswork. |
1810 | */ |
1770 | */ |
1811 | |
1771 | |
1812 | int |
1772 | int |
1813 | calculate_difficulty (mapstruct *m) |
1773 | calculate_difficulty (maptile *m) |
1814 | { |
1774 | { |
1815 | object *op; |
1775 | object *op; |
1816 | archetype *at; |
1776 | archetype *at; |
1817 | int x, y, i; |
1777 | int x, y, i; |
1818 | long monster_cnt = 0; |
1778 | long monster_cnt = 0; |
… | |
… | |
1860 | |
1820 | |
1861 | return 1; |
1821 | return 1; |
1862 | } |
1822 | } |
1863 | |
1823 | |
1864 | void |
1824 | void |
1865 | clean_tmp_map (mapstruct *m) |
1825 | clean_tmp_map (maptile *m) |
1866 | { |
1826 | { |
1867 | if (m->tmpname == NULL) |
1827 | if (m->tmpname == NULL) |
1868 | return; |
1828 | return; |
1869 | INVOKE_MAP (CLEAN, m); |
1829 | INVOKE_MAP (CLEAN, m); |
1870 | (void) unlink (m->tmpname); |
1830 | (void) unlink (m->tmpname); |
… | |
… | |
1895 | * to maps than los. |
1855 | * to maps than los. |
1896 | * postive values make it darker, negative make it brighter |
1856 | * postive values make it darker, negative make it brighter |
1897 | */ |
1857 | */ |
1898 | |
1858 | |
1899 | int |
1859 | int |
1900 | change_map_light (mapstruct *m, int change) |
1860 | change_map_light (maptile *m, int change) |
1901 | { |
1861 | { |
1902 | int new_level = m->darkness + change; |
1862 | int new_level = m->darkness + change; |
1903 | |
1863 | |
1904 | /* Nothing to do */ |
1864 | /* Nothing to do */ |
1905 | if (!change || (new_level <= 0 && m->darkness == 0) || (new_level >= MAX_DARKNESS && m->darkness >= MAX_DARKNESS)) |
1865 | 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, |
1896 | * on the map (what it looks like, whether it blocks magic, |
1937 | * has a living creatures, prevents people from passing |
1897 | * has a living creatures, prevents people from passing |
1938 | * through, etc) |
1898 | * through, etc) |
1939 | */ |
1899 | */ |
1940 | void |
1900 | void |
1941 | update_position (mapstruct *m, int x, int y) |
1901 | update_position (maptile *m, int x, int y) |
1942 | { |
1902 | { |
1943 | object *tmp, *last = NULL; |
1903 | object *tmp, *last = NULL; |
1944 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1904 | uint8 flags = 0, oldflags, light = 0, anywhere = 0; |
1945 | New_Face *top, *floor, *middle; |
1905 | New_Face *top, *floor, *middle; |
1946 | object *top_obj, *floor_obj, *middle_obj; |
1906 | object *top_obj, *floor_obj, *middle_obj; |
… | |
… | |
2139 | SET_MAP_LIGHT (m, x, y, light); |
2099 | SET_MAP_LIGHT (m, x, y, light); |
2140 | } |
2100 | } |
2141 | |
2101 | |
2142 | |
2102 | |
2143 | void |
2103 | void |
2144 | set_map_reset_time (mapstruct *map) |
2104 | set_map_reset_time (maptile *map) |
2145 | { |
2105 | { |
2146 | int timeout; |
2106 | int timeout; |
2147 | |
2107 | |
2148 | timeout = MAP_RESET_TIMEOUT (map); |
2108 | timeout = MAP_RESET_TIMEOUT (map); |
2149 | if (timeout <= 0) |
2109 | if (timeout <= 0) |
2150 | timeout = MAP_DEFAULTRESET; |
2110 | timeout = MAP_DEFAULTRESET; |
2151 | if (timeout >= MAP_MAXRESET) |
2111 | if (timeout >= MAP_MAXRESET) |
2152 | timeout = MAP_MAXRESET; |
2112 | timeout = MAP_MAXRESET; |
2153 | MAP_WHEN_RESET (map) = seconds () + timeout; |
2113 | MAP_WHEN_RESET (map) = time (0) + timeout; |
2154 | } |
2114 | } |
2155 | |
2115 | |
2156 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2116 | /* this updates the orig_map->tile_map[tile_num] value after loading |
2157 | * the map. It also takes care of linking back the freshly loaded |
2117 | * the map. It also takes care of linking back the freshly loaded |
2158 | * maps tile_map values if it tiles back to this one. It returns |
2118 | * 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 |
2119 | * 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. |
2120 | * so that it is easier for calling functions to verify success. |
2161 | */ |
2121 | */ |
2162 | |
2122 | |
2163 | static mapstruct * |
2123 | static maptile * |
2164 | load_and_link_tiled_map (mapstruct *orig_map, int tile_num) |
2124 | load_and_link_tiled_map (maptile *orig_map, int tile_num) |
2165 | { |
2125 | { |
2166 | int dest_tile = (tile_num + 2) % 4; |
2126 | int dest_tile = (tile_num + 2) % 4; |
2167 | char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); |
2127 | char *path = path_combine_and_normalize (orig_map->path, orig_map->tile_path[tile_num]); |
2168 | |
2128 | |
2169 | orig_map->tile_map[tile_num] = ready_map_name (path, 0); |
2129 | orig_map->tile_map[tile_num] = ready_map_name (path, 0); |
… | |
… | |
2184 | * tiled maps. |
2144 | * tiled maps. |
2185 | * |
2145 | * |
2186 | * |
2146 | * |
2187 | */ |
2147 | */ |
2188 | int |
2148 | int |
2189 | out_of_map (mapstruct *m, int x, int y) |
2149 | out_of_map (maptile *m, int x, int y) |
2190 | { |
2150 | { |
2191 | |
2151 | |
2192 | /* If we get passed a null map, this is obviously the |
2152 | /* If we get passed a null map, this is obviously the |
2193 | * case. This generally shouldn't happen, but if the |
2153 | * case. This generally shouldn't happen, but if the |
2194 | * map loads fail below, it could happen. |
2154 | * map loads fail below, it could happen. |
… | |
… | |
2249 | * the map as that the coordinates are really on, and |
2209 | * the map as that the coordinates are really on, and |
2250 | * updates x and y to be the localized coordinates. |
2210 | * updates x and y to be the localized coordinates. |
2251 | * Using this is more efficient of calling out_of_map |
2211 | * Using this is more efficient of calling out_of_map |
2252 | * and then figuring out what the real map is |
2212 | * and then figuring out what the real map is |
2253 | */ |
2213 | */ |
2254 | mapstruct * |
2214 | maptile * |
2255 | get_map_from_coord (mapstruct *m, sint16 * x, sint16 * y) |
2215 | get_map_from_coord (maptile *m, sint16 * x, sint16 * y) |
2256 | { |
2216 | { |
2257 | |
2217 | |
2258 | if (*x < 0) |
2218 | if (*x < 0) |
2259 | { |
2219 | { |
2260 | if (!m->tile_path[3]) |
2220 | if (!m->tile_path[3]) |
… | |
… | |
2306 | /** |
2266 | /** |
2307 | * Return whether map2 is adjacent to map1. If so, store the distance from |
2267 | * Return whether map2 is adjacent to map1. If so, store the distance from |
2308 | * map1 to map2 in dx/dy. |
2268 | * map1 to map2 in dx/dy. |
2309 | */ |
2269 | */ |
2310 | static int |
2270 | static int |
2311 | adjacent_map (const mapstruct *map1, const mapstruct *map2, int *dx, int *dy) |
2271 | adjacent_map (const maptile *map1, const maptile *map2, int *dx, int *dy) |
2312 | { |
2272 | { |
2313 | if (!map1 || !map2) |
2273 | if (!map1 || !map2) |
2314 | return 0; |
2274 | return 0; |
2315 | |
2275 | |
2316 | if (map1 == map2) |
2276 | if (map1 == map2) |
… | |
… | |
2474 | * for something in the future. Also, since no object is pasted, the best |
2434 | * for something in the future. Also, since no object is pasted, the best |
2475 | * field of the rv_vector is set to NULL. |
2435 | * field of the rv_vector is set to NULL. |
2476 | */ |
2436 | */ |
2477 | |
2437 | |
2478 | void |
2438 | void |
2479 | get_rangevector_from_mapcoord (const mapstruct *m, int x, int y, const object *op2, rv_vector * retval, int flags) |
2439 | get_rangevector_from_mapcoord (const maptile *m, int x, int y, const object *op2, rv_vector * retval, int flags) |
2480 | { |
2440 | { |
2481 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
2441 | if (!adjacent_map (m, op2->map, &retval->distance_x, &retval->distance_y)) |
2482 | { |
2442 | { |
2483 | /* be conservative and fill in _some_ data */ |
2443 | /* be conservative and fill in _some_ data */ |
2484 | retval->distance = 100000; |
2444 | retval->distance = 100000; |