… | |
… | |
157 | } |
157 | } |
158 | } |
158 | } |
159 | } |
159 | } |
160 | break; |
160 | break; |
161 | } |
161 | } |
|
|
162 | |
162 | default: |
163 | default: |
163 | { |
164 | { |
164 | int i, j, tries; |
165 | int i, j, tries; |
165 | object *chest; |
166 | object *chest; |
166 | object **doorlist; |
167 | object **doorlist; |
… | |
… | |
264 | |
265 | |
265 | /* stick a trap in the chest if required */ |
266 | /* stick a trap in the chest if required */ |
266 | if (treasureoptions & TRAPPED) |
267 | if (treasureoptions & TRAPPED) |
267 | { |
268 | { |
268 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
269 | maptile *trap_map = find_style ("/styles/trapstyles", "traps", -1); |
269 | object *the_trap; |
|
|
270 | |
270 | |
271 | if (trap_map) |
271 | if (trap_map) |
272 | { |
272 | { |
273 | the_trap = trap_map->pick_random_object (); |
273 | object *the_trap = trap_map->pick_random_object (); |
|
|
274 | |
274 | the_trap->stats.Cha = 10 + RP->difficulty; |
275 | the_trap->stats.Cha = 10 + RP->difficulty; |
275 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
276 | the_trap->level = bc_random ((3 * RP->difficulty) / 2); |
|
|
277 | |
276 | if (the_trap) |
278 | if (the_trap) |
277 | { |
279 | { |
278 | object *new_trap; |
280 | object *new_trap = the_trap->arch->instance ();//TODO: why not clone? |
279 | |
281 | |
280 | new_trap = arch_to_object (the_trap->arch); |
|
|
281 | new_trap->copy_to (the_trap); |
|
|
282 | new_trap->x = x; |
282 | new_trap->x = x; |
283 | new_trap->y = y; |
283 | new_trap->y = y; |
284 | insert_ob_in_ob (new_trap, the_chest); |
284 | insert_ob_in_ob (new_trap, the_chest); |
285 | } |
285 | } |
286 | } |
286 | } |
… | |
… | |
486 | { |
486 | { |
487 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
487 | theMonsterToFind = find_monster_in_room_recursive (layout, map, x + freearr_x[i % 8 + 1], y + freearr_y[i % 8 + 1], RP); |
488 | if (theMonsterToFind != NULL) |
488 | if (theMonsterToFind != NULL) |
489 | return theMonsterToFind; |
489 | return theMonsterToFind; |
490 | } |
490 | } |
|
|
491 | |
491 | return theMonsterToFind; |
492 | return theMonsterToFind; |
492 | } |
493 | } |
493 | |
|
|
494 | |
494 | |
495 | /* sets up some data structures: the _recursive form does the |
495 | /* sets up some data structures: the _recursive form does the |
496 | real work. */ |
496 | real work. */ |
497 | |
|
|
498 | object * |
497 | object * |
499 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
498 | find_monster_in_room (maptile *map, int x, int y, random_map_params *RP) |
500 | { |
499 | { |
501 | char **layout2; |
500 | Layout layout2 (RP); |
502 | int i, j; |
501 | |
|
|
502 | layout2->clear (); |
|
|
503 | |
|
|
504 | /* allocate and copy the layout, converting C to 0. */ |
|
|
505 | for (int i = 0; i < layout2->w; i++) |
|
|
506 | for (int j = 0; j < layout2->h; j++) |
|
|
507 | if (wall_blocked (map, i, j)) |
|
|
508 | layout2[i][j] = '#'; |
503 | |
509 | |
504 | theMonsterToFind = 0; |
510 | theMonsterToFind = 0; |
505 | layout2 = (char **) calloc (sizeof (char *), RP->Xsize); |
|
|
506 | /* allocate and copy the layout, converting C to 0. */ |
|
|
507 | for (i = 0; i < RP->Xsize; i++) |
|
|
508 | { |
|
|
509 | layout2[i] = (char *) calloc (sizeof (char), RP->Ysize); |
|
|
510 | for (j = 0; j < RP->Ysize; j++) |
|
|
511 | if (wall_blocked (map, i, j)) |
|
|
512 | layout2[i][j] = '#'; |
|
|
513 | } |
|
|
514 | |
|
|
515 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
511 | theMonsterToFind = find_monster_in_room_recursive (layout2, map, x, y, RP); |
516 | |
512 | |
517 | /* deallocate the temp. layout */ |
513 | layout2.free (); |
518 | for (i = 0; i < RP->Xsize; i++) |
|
|
519 | free (layout2[i]); |
|
|
520 | |
|
|
521 | free (layout2); |
|
|
522 | |
514 | |
523 | return theMonsterToFind; |
515 | return theMonsterToFind; |
524 | } |
516 | } |
525 | |
517 | |
526 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
518 | /* a datastructure needed by find_spot_in_room and find_spot_in_room_recursive */ |
… | |
… | |
801 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
793 | find_doors_in_room (maptile *map, int x, int y, random_map_params *RP) |
802 | { |
794 | { |
803 | int i, j; |
795 | int i, j; |
804 | int ndoors = 0; |
796 | int ndoors = 0; |
805 | |
797 | |
806 | object **doorlist = (object **) calloc (sizeof (int), 1024); |
798 | object **doorlist = (object **)calloc (sizeof (int), 1024); |
807 | |
799 | |
808 | MazeData layout2 (RP->Xsize, RP->Ysize); |
800 | LayoutData layout2 (RP->Xsize, RP->Ysize); |
|
|
801 | layout2.clear (); |
809 | |
802 | |
810 | /* allocate and copy the layout, converting C to 0. */ |
803 | /* allocate and copy the layout, converting C to 0. */ |
811 | for (i = 0; i < RP->Xsize; i++) |
804 | for (i = 0; i < RP->Xsize; i++) |
812 | for (j = 0; j < RP->Ysize; j++) |
805 | for (j = 0; j < RP->Ysize; j++) |
813 | if (wall_blocked (map, i, j)) |
806 | layout2[i][j] = wall_blocked (map, i, j) ? '#' : 0; |
814 | layout2[i][j] = '#'; |
|
|
815 | |
807 | |
816 | /* setup num_free_spots and room_free_spots */ |
808 | /* setup num_free_spots and room_free_spots */ |
817 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
809 | find_doors_in_room_recursive (layout2, map, x, y, doorlist, &ndoors, RP); |
818 | |
810 | |
819 | return doorlist; |
811 | return doorlist; |
… | |
… | |
863 | { |
855 | { |
864 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
856 | retrofit_joined_wall (map, door->x - 1, door->y, 0, RP); |
865 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
857 | retrofit_joined_wall (map, door->x + 1, door->y, 0, RP); |
866 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
858 | retrofit_joined_wall (map, door->x, door->y - 1, 0, RP); |
867 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
859 | retrofit_joined_wall (map, door->x, door->y + 1, 0, RP); |
|
|
860 | |
868 | door->face = wallface->face; |
861 | door->face = wallface->face; |
|
|
862 | |
869 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
863 | if (!QUERY_FLAG (wallface, FLAG_REMOVED)) |
870 | wallface->remove (); |
864 | wallface->remove (); |
|
|
865 | |
871 | wallface->destroy (); |
866 | wallface->destroy (); |
872 | } |
867 | } |
873 | } |
868 | } |
874 | } |
869 | } |
875 | } |
870 | } |