… | |
… | |
49 | * and doors but not monsters. |
49 | * and doors but not monsters. |
50 | * This function is not map tile aware. |
50 | * This function is not map tile aware. |
51 | */ |
51 | */ |
52 | |
52 | |
53 | int |
53 | int |
54 | wall_blocked (mapstruct *m, int x, int y) |
54 | wall_blocked (maptile *m, int x, int y) |
55 | { |
55 | { |
56 | int r; |
56 | int r; |
57 | |
57 | |
58 | if (OUT_OF_REAL_MAP (m, x, y)) |
58 | if (OUT_OF_REAL_MAP (m, x, y)) |
59 | return 1; |
59 | return 1; |
… | |
… | |
67 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
67 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
68 | treasureoptions (may be 0 for random choices or positive) |
68 | treasureoptions (may be 0 for random choices or positive) |
69 | */ |
69 | */ |
70 | |
70 | |
71 | void |
71 | void |
72 | place_treasure (mapstruct *map, char **layout, char *treasure_style, int treasureoptions, RMParms * RP) |
72 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, RMParms * RP) |
73 | { |
73 | { |
74 | char styledirname[256]; |
74 | char styledirname[256]; |
75 | char stylefilepath[256]; |
75 | char stylefilepath[256]; |
76 | mapstruct *style_map = 0; |
76 | maptile *style_map = 0; |
77 | int num_treasures; |
77 | int num_treasures; |
78 | |
78 | |
79 | /* bail out if treasure isn't wanted. */ |
79 | /* bail out if treasure isn't wanted. */ |
80 | if (treasure_style) |
80 | if (treasure_style) |
81 | if (!strcmp (treasure_style, "none")) |
81 | if (!strcmp (treasure_style, "none")) |
… | |
… | |
198 | /* put a chest into the map, near x and y, with the treasure style |
198 | /* put a chest into the map, near x and y, with the treasure style |
199 | determined (may be null, or may be a treasure list from lib/treasures, |
199 | determined (may be null, or may be a treasure list from lib/treasures, |
200 | if the global variable "treasurestyle" is set to that treasure list's name */ |
200 | if the global variable "treasurestyle" is set to that treasure list's name */ |
201 | |
201 | |
202 | object * |
202 | object * |
203 | place_chest (int treasureoptions, int x, int y, mapstruct *map, mapstruct *style_map, int n_treasures, RMParms * RP) |
203 | place_chest (int treasureoptions, int x, int y, maptile *map, maptile *style_map, int n_treasures, RMParms * RP) |
204 | { |
204 | { |
205 | object *the_chest; |
205 | object *the_chest; |
206 | int i, xl, yl; |
206 | int i, xl, yl; |
207 | |
207 | |
208 | the_chest = get_archetype ("chest"); /* was "chest_2" */ |
208 | the_chest = get_archetype ("chest"); /* was "chest_2" */ |
209 | |
209 | |
210 | /* first, find a place to put the chest. */ |
210 | /* first, find a place to put the chest. */ |
211 | i = find_first_free_spot (the_chest, map, x, y); |
211 | i = find_first_free_spot (the_chest, map, x, y); |
212 | if (i == -1) |
212 | if (i == -1) |
213 | { |
213 | { |
214 | free_object (the_chest); |
214 | the_chest->destroy (); |
215 | return NULL; |
215 | return NULL; |
216 | } |
216 | } |
217 | xl = x + freearr_x[i]; |
217 | xl = x + freearr_x[i]; |
218 | yl = y + freearr_y[i]; |
218 | yl = y + freearr_y[i]; |
219 | |
219 | |
… | |
… | |
252 | } |
252 | } |
253 | |
253 | |
254 | /* stick a trap in the chest if required */ |
254 | /* stick a trap in the chest if required */ |
255 | if (treasureoptions & TRAPPED) |
255 | if (treasureoptions & TRAPPED) |
256 | { |
256 | { |
257 | mapstruct *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
257 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
258 | object *the_trap; |
258 | object *the_trap; |
259 | |
259 | |
260 | if (trap_map) |
260 | if (trap_map) |
261 | { |
261 | { |
262 | the_trap = pick_random_object (trap_map); |
262 | the_trap = pick_random_object (trap_map); |
… | |
… | |
265 | if (the_trap) |
265 | if (the_trap) |
266 | { |
266 | { |
267 | object *new_trap; |
267 | object *new_trap; |
268 | |
268 | |
269 | new_trap = arch_to_object (the_trap->arch); |
269 | new_trap = arch_to_object (the_trap->arch); |
270 | copy_object (new_trap, the_trap); |
270 | new_trap->copy_to (the_trap); |
271 | new_trap->x = x; |
271 | new_trap->x = x; |
272 | new_trap->y = y; |
272 | new_trap->y = y; |
273 | insert_ob_in_ob (new_trap, the_chest); |
273 | insert_ob_in_ob (new_trap, the_chest); |
274 | } |
274 | } |
275 | } |
275 | } |
… | |
… | |
297 | |
297 | |
298 | |
298 | |
299 | /* finds the closest monster and returns him, regardless of doors |
299 | /* finds the closest monster and returns him, regardless of doors |
300 | or walls */ |
300 | or walls */ |
301 | object * |
301 | object * |
302 | find_closest_monster (mapstruct *map, int x, int y, RMParms * RP) |
302 | find_closest_monster (maptile *map, int x, int y, RMParms * RP) |
303 | { |
303 | { |
304 | int i; |
304 | int i; |
305 | |
305 | |
306 | for (i = 0; i < SIZEOFFREE; i++) |
306 | for (i = 0; i < SIZEOFFREE; i++) |
307 | { |
307 | { |
… | |
… | |
336 | The idea is that you call keyplace on x,y where a door is, and it'll make |
336 | The idea is that you call keyplace on x,y where a door is, and it'll make |
337 | sure a key is placed on both sides of the door. |
337 | sure a key is placed on both sides of the door. |
338 | */ |
338 | */ |
339 | |
339 | |
340 | int |
340 | int |
341 | keyplace (mapstruct *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms * RP) |
341 | keyplace (maptile *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms * RP) |
342 | { |
342 | { |
343 | int i, j; |
343 | int i, j; |
344 | int kx, ky; |
344 | int kx, ky; |
345 | object *the_keymaster; /* the monster that gets the key. */ |
345 | object *the_keymaster; /* the monster that gets the key. */ |
346 | object *the_key; |
346 | object *the_key; |
… | |
… | |
432 | |
432 | |
433 | /* a recursive routine which will return a monster, eventually,if there is one. |
433 | /* a recursive routine which will return a monster, eventually,if there is one. |
434 | it does a check-off on the layout, converting 0's to 1's */ |
434 | it does a check-off on the layout, converting 0's to 1's */ |
435 | |
435 | |
436 | object * |
436 | object * |
437 | find_monster_in_room_recursive (char **layout, mapstruct *map, int x, int y, RMParms * RP) |
437 | find_monster_in_room_recursive (char **layout, maptile *map, int x, int y, RMParms * RP) |
438 | { |
438 | { |
439 | int i, j; |
439 | int i, j; |
440 | |
440 | |
441 | /* if we've found a monster already, leave */ |
441 | /* if we've found a monster already, leave */ |
442 | if (theMonsterToFind != NULL) |
442 | if (theMonsterToFind != NULL) |
… | |
… | |
479 | |
479 | |
480 | /* sets up some data structures: the _recursive form does the |
480 | /* sets up some data structures: the _recursive form does the |
481 | real work. */ |
481 | real work. */ |
482 | |
482 | |
483 | object * |
483 | object * |
484 | find_monster_in_room (mapstruct *map, int x, int y, RMParms * RP) |
484 | find_monster_in_room (maptile *map, int x, int y, RMParms * RP) |
485 | { |
485 | { |
486 | char **layout2; |
486 | char **layout2; |
487 | int i, j; |
487 | int i, j; |
488 | |
488 | |
489 | theMonsterToFind = 0; |
489 | theMonsterToFind = 0; |
… | |
… | |
550 | |
550 | |
551 | } |
551 | } |
552 | |
552 | |
553 | /* find a random non-blocked spot in this room to drop a key. */ |
553 | /* find a random non-blocked spot in this room to drop a key. */ |
554 | void |
554 | void |
555 | find_spot_in_room (mapstruct *map, int x, int y, int *kx, int *ky, RMParms * RP) |
555 | find_spot_in_room (maptile *map, int x, int y, int *kx, int *ky, RMParms * RP) |
556 | { |
556 | { |
557 | char **layout2; |
557 | char **layout2; |
558 | int i, j; |
558 | int i, j; |
559 | |
559 | |
560 | number_of_free_spots_in_room = 0; |
560 | number_of_free_spots_in_room = 0; |
… | |
… | |
597 | /* searches the map for a spot with walls around it. The more |
597 | /* searches the map for a spot with walls around it. The more |
598 | walls the better, but it'll settle for 1 wall, or even 0, but |
598 | walls the better, but it'll settle for 1 wall, or even 0, but |
599 | it'll return 0 if no FREE spots are found.*/ |
599 | it'll return 0 if no FREE spots are found.*/ |
600 | |
600 | |
601 | void |
601 | void |
602 | find_enclosed_spot (mapstruct *map, int *cx, int *cy, RMParms * RP) |
602 | find_enclosed_spot (maptile *map, int *cx, int *cy, RMParms * RP) |
603 | { |
603 | { |
604 | int x, y; |
604 | int x, y; |
605 | int i; |
605 | int i; |
606 | |
606 | |
607 | x = *cx; |
607 | x = *cx; |
… | |
… | |
669 | *cx = *cy = -1; |
669 | *cx = *cy = -1; |
670 | } |
670 | } |
671 | |
671 | |
672 | |
672 | |
673 | void |
673 | void |
674 | remove_monsters (int x, int y, mapstruct *map) |
674 | remove_monsters (int x, int y, maptile *map) |
675 | { |
675 | { |
676 | object *tmp; |
676 | object *tmp; |
677 | |
677 | |
678 | for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) |
678 | for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) |
679 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
679 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
680 | { |
680 | { |
681 | if (tmp->head) |
681 | if (tmp->head) |
682 | tmp = tmp->head; |
682 | tmp = tmp->head; |
683 | remove_ob (tmp); |
683 | tmp->remove (); |
684 | free_object (tmp); |
684 | tmp->destroy (); |
685 | tmp = get_map_ob (map, x, y); |
685 | tmp = get_map_ob (map, x, y); |
686 | if (tmp == NULL) |
686 | if (tmp == NULL) |
687 | break; |
687 | break; |
688 | }; |
688 | }; |
689 | } |
689 | } |
… | |
… | |
692 | /* surrounds the point x,y by doors, so as to enclose something, like |
692 | /* surrounds the point x,y by doors, so as to enclose something, like |
693 | a chest. It only goes as far as the 8 squares surrounding, and |
693 | a chest. It only goes as far as the 8 squares surrounding, and |
694 | it'll remove any monsters it finds.*/ |
694 | it'll remove any monsters it finds.*/ |
695 | |
695 | |
696 | object ** |
696 | object ** |
697 | surround_by_doors (mapstruct *map, char **layout, int x, int y, int opts) |
697 | surround_by_doors (maptile *map, char **layout, int x, int y, int opts) |
698 | { |
698 | { |
699 | int i; |
699 | int i; |
700 | char *doors[2]; |
700 | char *doors[2]; |
701 | object **doorlist; |
701 | object **doorlist; |
702 | int ndoors_made = 0; |
702 | int ndoors_made = 0; |
… | |
… | |
735 | } |
735 | } |
736 | |
736 | |
737 | |
737 | |
738 | /* returns the first door in this square, or NULL if there isn't a door. */ |
738 | /* returns the first door in this square, or NULL if there isn't a door. */ |
739 | object * |
739 | object * |
740 | door_in_square (mapstruct *map, int x, int y) |
740 | door_in_square (maptile *map, int x, int y) |
741 | { |
741 | { |
742 | object *tmp; |
742 | object *tmp; |
743 | |
743 | |
744 | for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) |
744 | for (tmp = get_map_ob (map, x, y); tmp != NULL; tmp = tmp->above) |
745 | if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) |
745 | if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) |
… | |
… | |
748 | } |
748 | } |
749 | |
749 | |
750 | |
750 | |
751 | /* the workhorse routine, which finds the doors in a room */ |
751 | /* the workhorse routine, which finds the doors in a room */ |
752 | void |
752 | void |
753 | find_doors_in_room_recursive (char **layout, mapstruct *map, int x, int y, object **doorlist, int *ndoors, RMParms * RP) |
753 | find_doors_in_room_recursive (char **layout, maptile *map, int x, int y, object **doorlist, int *ndoors, RMParms * RP) |
754 | { |
754 | { |
755 | int i, j; |
755 | int i, j; |
756 | object *door; |
756 | object *door; |
757 | |
757 | |
758 | /* bounds check x and y */ |
758 | /* bounds check x and y */ |
… | |
… | |
790 | } |
790 | } |
791 | } |
791 | } |
792 | |
792 | |
793 | /* find a random non-blocked spot in this room to drop a key. */ |
793 | /* find a random non-blocked spot in this room to drop a key. */ |
794 | object ** |
794 | object ** |
795 | find_doors_in_room (mapstruct *map, int x, int y, RMParms * RP) |
795 | find_doors_in_room (maptile *map, int x, int y, RMParms * RP) |
796 | { |
796 | { |
797 | char **layout2; |
797 | char **layout2; |
798 | object **doorlist; |
798 | object **doorlist; |
799 | int i, j; |
799 | int i, j; |
800 | int ndoors = 0; |
800 | int ndoors = 0; |
… | |
… | |
830 | |
830 | |
831 | /* locks and/or hides all the doors in doorlist, or does nothing if |
831 | /* locks and/or hides all the doors in doorlist, or does nothing if |
832 | opts doesn't say to lock/hide doors. */ |
832 | opts doesn't say to lock/hide doors. */ |
833 | |
833 | |
834 | void |
834 | void |
835 | lock_and_hide_doors (object **doorlist, mapstruct *map, int opts, RMParms * RP) |
835 | lock_and_hide_doors (object **doorlist, maptile *map, int opts, RMParms * RP) |
836 | { |
836 | { |
837 | object *door; |
837 | object *door; |
838 | int i; |
838 | int i; |
839 | |
839 | |
840 | /* lock the doors and hide the keys. */ |
840 | /* lock the doors and hide the keys. */ |
… | |
… | |
848 | |
848 | |
849 | door = doorlist[i]; |
849 | door = doorlist[i]; |
850 | new_door->face = door->face; |
850 | new_door->face = door->face; |
851 | new_door->x = door->x; |
851 | new_door->x = door->x; |
852 | new_door->y = door->y; |
852 | new_door->y = door->y; |
853 | remove_ob (door); |
853 | door->remove (); |
854 | free_object (door); |
854 | door->destroy (); |
855 | doorlist[i] = new_door; |
855 | doorlist[i] = new_door; |
856 | insert_ob_in_map (new_door, map, NULL, 0); |
856 | insert_ob_in_map (new_door, map, NULL, 0); |
857 | sprintf (keybuf, "%d", (int) RANDOM ()); |
857 | sprintf (keybuf, "%d", (int) RANDOM ()); |
858 | new_door->slaying = keybuf; |
858 | new_door->slaying = keybuf; |
859 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
859 | keyplace (map, new_door->x, new_door->y, keybuf, NO_PASS_DOORS, 2, RP); |
… | |
… | |
875 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
875 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
876 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
876 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
877 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
877 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
878 | door->face = wallface->face; |
878 | door->face = wallface->face; |
879 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
879 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
880 | remove_ob (wallface); |
880 | wallface->remove (); |
881 | free_object (wallface); |
881 | wallface->destroy (); |
882 | } |
882 | } |
883 | } |
883 | } |
884 | } |
884 | } |
885 | } |
885 | } |