… | |
… | |
109 | freeindex = -1; |
109 | freeindex = -1; |
110 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
110 | for (tries = 0; tries < 15 && freeindex == -1; tries++) |
111 | { |
111 | { |
112 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
112 | kx = rmg_rndm (RP->Xsize - 2) + 1; |
113 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
113 | ky = rmg_rndm (RP->Ysize - 2) + 1; |
114 | freeindex = find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
114 | freeindex = rmg_find_free_spot (the_key, map, kx, ky, 1, SIZEOFFREE1 + 1); |
115 | } |
115 | } |
116 | |
116 | |
117 | // can freeindex ever be < 0? |
117 | // can freeindex ever be < 0? |
118 | if (freeindex >= 0) |
118 | if (freeindex >= 0) |
119 | { |
119 | { |
… | |
… | |
192 | layout, (required) |
192 | layout, (required) |
193 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
193 | treasure style (may be empty or NULL, or "none" to cause no treasure.) |
194 | treasureoptions (may be 0 for random choices or positive) |
194 | treasureoptions (may be 0 for random choices or positive) |
195 | */ |
195 | */ |
196 | void |
196 | void |
197 | place_treasure (maptile *map, char **layout, char *treasure_style, int treasureoptions, random_map_params *RP) |
197 | place_treasure (maptile *map, char **layout, const char *treasure_style, int treasureoptions, random_map_params *RP) |
198 | { |
198 | { |
199 | int num_treasures; |
199 | int num_treasures; |
200 | |
200 | |
201 | /* bail out if treasure isn't wanted. */ |
201 | /* bail out if treasure isn't wanted. */ |
202 | if (treasure_style) |
202 | if (treasure_style) |
… | |
… | |
225 | |
225 | |
226 | if (num_treasures <= 0) |
226 | if (num_treasures <= 0) |
227 | return; |
227 | return; |
228 | |
228 | |
229 | /* get the style map */ |
229 | /* get the style map */ |
230 | maptile *style_map = find_style ("/styles/treasurestyles", treasure_style, -1); |
230 | maptile *style_map = find_style ("/styles/treasurestyles", treasure_style, RP->difficulty); |
231 | |
231 | |
232 | if (!style_map) |
232 | if (!style_map) |
233 | { |
233 | { |
234 | LOG (llevError, "unable to load style map %s %s.\n", "/styles/treasurestyles", treasure_style); |
234 | LOG (llevError, "unable to load style map %s %s.\n", "/styles/treasurestyles", treasure_style); |
235 | return; |
235 | return; |
… | |
… | |
379 | } |
379 | } |
380 | |
380 | |
381 | /* stick a trap in the chest if required */ |
381 | /* stick a trap in the chest if required */ |
382 | if (treasureoptions & TRAPPED) |
382 | if (treasureoptions & TRAPPED) |
383 | { |
383 | { |
384 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
384 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", RP->difficulty); |
385 | |
385 | |
386 | if (trap_map) |
386 | if (trap_map) |
387 | { |
387 | { |
388 | object *the_trap = trap_map->pick_random_object (rmg_rndm); |
388 | object *the_trap = trap_map->pick_random_object (rmg_rndm); |
389 | |
389 | |
… | |
… | |
497 | /* sets up some data structures: the _recursive form does the |
497 | /* sets up some data structures: the _recursive form does the |
498 | real work. */ |
498 | real work. */ |
499 | static object * |
499 | static object * |
500 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
500 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
501 | { |
501 | { |
502 | Layout layout2 (RP); |
502 | Layout layout2 (map->width, map->height); |
503 | |
503 | |
504 | layout2->clear (); |
504 | // find walls |
505 | |
|
|
506 | /* allocate and copy the layout, converting C to 0. */ |
|
|
507 | for (int i = 0; i < layout2->w; i++) |
505 | for (int i = 0; i < layout2.w; i++) |
508 | for (int j = 0; j < layout2->h; j++) |
506 | for (int j = 0; j < layout2.h; j++) |
509 | if (wall_blocked (map, i, j)) |
507 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
510 | layout2[i][j] = '#'; |
|
|
511 | |
508 | |
512 | theMonsterToFind = 0; |
509 | theMonsterToFind = 0; |
513 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
510 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
514 | |
|
|
515 | layout2.free (); |
|
|
516 | |
511 | |
517 | return theMonsterToFind; |
512 | return theMonsterToFind; |
518 | } |
513 | } |
519 | |
514 | |
520 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
515 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
… | |
… | |
609 | { |
604 | { |
610 | int lx, ly, sindex; |
605 | int lx, ly, sindex; |
611 | |
606 | |
612 | lx = x + freearr_x[i]; |
607 | lx = x + freearr_x[i]; |
613 | ly = y + freearr_y[i]; |
608 | ly = y + freearr_y[i]; |
614 | sindex = surround_flag3 (map, lx, ly, RP); |
609 | sindex = surround_flag3 (map, lx, ly); |
615 | /* if it's blocked on 3 sides, it's enclosed */ |
610 | /* if it's blocked on 3 sides, it's enclosed */ |
616 | if (sindex == 7 || sindex == 11 || sindex == 13 || sindex == 14) |
611 | if (sindex == 7 || sindex == 11 || sindex == 13 || sindex == 14) |
617 | { |
612 | { |
618 | *cx = lx; |
613 | *cx = lx; |
619 | *cy = ly; |
614 | *cy = ly; |
… | |
… | |
627 | { |
622 | { |
628 | int lx, ly, sindex; |
623 | int lx, ly, sindex; |
629 | |
624 | |
630 | lx = x + freearr_x[i]; |
625 | lx = x + freearr_x[i]; |
631 | ly = y + freearr_y[i]; |
626 | ly = y + freearr_y[i]; |
632 | sindex = surround_flag3 (map, lx, ly, RP); |
627 | sindex = surround_flag3 (map, lx, ly); |
633 | /* if it's blocked on 3 sides, it's enclosed */ |
628 | /* if it's blocked on 3 sides, it's enclosed */ |
634 | if (sindex == 3 || sindex == 5 || sindex == 9 || sindex == 6 || sindex == 10 || sindex == 12) |
629 | if (sindex == 3 || sindex == 5 || sindex == 9 || sindex == 6 || sindex == 10 || sindex == 12) |
635 | { |
630 | { |
636 | *cx = lx; |
631 | *cx = lx; |
637 | *cy = ly; |
632 | *cy = ly; |
… | |
… | |
644 | { |
639 | { |
645 | int lx, ly, sindex; |
640 | int lx, ly, sindex; |
646 | |
641 | |
647 | lx = x + freearr_x[i]; |
642 | lx = x + freearr_x[i]; |
648 | ly = y + freearr_y[i]; |
643 | ly = y + freearr_y[i]; |
649 | sindex = surround_flag3 (map, lx, ly, RP); |
644 | sindex = surround_flag3 (map, lx, ly); |
650 | /* if it's blocked on 3 sides, it's enclosed */ |
645 | /* if it's blocked on 3 sides, it's enclosed */ |
651 | if (sindex) |
646 | if (sindex) |
652 | { |
647 | { |
653 | *cx = lx; |
648 | *cx = lx; |
654 | *cy = ly; |
649 | *cy = ly; |
655 | return; |
650 | return; |
656 | } |
651 | } |
657 | } |
652 | } |
658 | /* give up and return the closest free spot. */ |
653 | /* give up and return the closest free spot. */ |
659 | i = find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); |
654 | i = rmg_find_free_spot (archetype::find (shstr_chest), map, x, y, 1, SIZEOFFREE1 + 1); |
660 | |
655 | |
661 | if (i != -1) |
656 | if (i != -1) |
662 | { |
657 | { |
663 | *cx = x + freearr_x[i]; |
658 | *cx = x + freearr_x[i]; |
664 | *cy = y + freearr_y[i]; |
659 | *cy = y + freearr_y[i]; |
… | |
… | |
791 | int i, j; |
786 | int i, j; |
792 | int ndoors = 0; |
787 | int ndoors = 0; |
793 | |
788 | |
794 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
789 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
795 | |
790 | |
796 | LayoutData layout2 (RP->Xsize, RP->Ysize); |
791 | Layout layout2 (RP->Xsize, RP->Ysize); |
797 | layout2.clear (); |
792 | layout2.clear (); |
798 | |
793 | |
799 | /* allocate and copy the layout, converting C to 0. */ |
794 | /* allocate and copy the layout, converting C to 0. */ |
800 | for (i = 0; i < RP->Xsize; i++) |
795 | for (i = 0; i < RP->Xsize; i++) |
801 | for (j = 0; j < RP->Ysize; j++) |
796 | for (j = 0; j < RP->Ysize; j++) |