--- deliantra/server/random_maps/exit.C 2010/07/04 22:12:26 1.48 +++ deliantra/server/random_maps/exit.C 2010/07/05 00:07:21 1.49 @@ -78,8 +78,8 @@ break; case 3: - /* search from bottom-left up-right */ - for (i = 1; i < maze.w - 1; i++) + /* search from bottom-right up-left */ + for (i = maze.w - 2; i > 0; i--) for (j = maze.h - 2; j > 0; j--) { if (maze[i][j] == target) @@ -90,10 +90,10 @@ } } break; - + case 4: - /* search from bottom-right up-left */ - for (i = maze.w - 2; i > 0; i--) + /* search from bottom-left up-right */ + for (i = 1; i < maze.w - 1; i++) for (j = maze.h - 2; j > 0; j--) { if (maze[i][j] == target) @@ -107,6 +107,16 @@ } } +point +layout::find (char target, int mode) +{ + int x, y; + + find_in_layout (mode, target, x, y, *this); + + return point (x, y); +} + /* orientation: 0 means random, 1 means descending dungeon 2 means ascending dungeon @@ -200,14 +210,10 @@ upy = RP->Ysize - 2; /* find an empty place far from the center */ - if (upx == 1 && upy == 1) - find_in_layout (1, 0, upx, upy, maze); - else if (upx == 1 && upy > 1) - find_in_layout (3, 0, upx, upy, maze); - else if (upx > 1 && upy == 1) - find_in_layout (2, 0, upx, upy, maze); - else if (upx > 1 && upy > 1) - find_in_layout (4, 0, upx, upy, maze); + if (upx == 1 && upy == 1) find_in_layout (1, 0, upx, upy, maze); + else if (upx == 1 && upy > 1) find_in_layout (4, 0, upx, upy, maze); + else if (upx > 1 && upy == 1) find_in_layout (2, 0, upx, upy, maze); + else if (upx > 1 && upy > 1) find_in_layout (3, 0, upx, upy, maze); } /* no indication of where to place the exit, so just place it. */ @@ -261,14 +267,10 @@ downy = RP->Ysize - 2; /* find an empty place far from the entrance */ - if (downx == 1 && downy == 1) - find_in_layout (1, 0, downx, downy, maze); - else if (downx == 1 && downy > 1) - find_in_layout (3, 0, downx, downy, maze); - else if (downx > 1 && downy == 1) - find_in_layout (2, 0, downx, downy, maze); - else if (downx > 1 && downy > 1) - find_in_layout (4, 0, downx, downy, maze); + if (downx == 1 && downy == 1) find_in_layout (1, 0, downx, downy, maze); + else if (downx == 1 && downy > 1) find_in_layout (4, 0, downx, downy, maze); + else if (downx > 1 && downy == 1) find_in_layout (2, 0, downx, downy, maze); + else if (downx > 1 && downy > 1) find_in_layout (3, 0, downx, downy, maze); } /* no indication of where to place the down exit, so just place it */ @@ -278,53 +280,51 @@ if (the_exit_down) { int i = rmg_find_free_spot (the_exit_down, map, downx, downy, 1, SIZEOFFREE1 + 1); + the_exit_down->x = downx + freearr_x[i]; the_exit_down->y = downy + freearr_y[i]; + RP->set ("origin_x", (IV)the_exit_down->x); RP->set ("origin_y", (IV)the_exit_down->y); - the_exit_down->msg = RP->as_shstr (); + the_exit_down->msg = RP->as_shstr (); + the_exit_down->slaying = shstr_random_map_exit; /* the identifier for making a random map. */ if (RP->dungeon_level >= RP->dungeon_depth && final_map) { - maptile *new_map; - object *the_exit_back = the_exit_up->arch->instance (); - - /* load it */ - if (!(new_map = maptile::find_sync (final_map))) - return; - - new_map->load_sync (); - + the_exit_down->msg = 0; the_exit_down->slaying = final_map; - for (object *tmp = new_map->at (new_map->enter_x, new_map->enter_y).bot; tmp; tmp = tmp->above) - /* Remove exit back to previous random map. There should only be one - * which is why we break out. To try to process more than one - * would require keeping a 'next' pointer, ad free_object kills tmp, which - * breaks the for loop. - */ - if (tmp->type == EXIT && EXIT_PATH (tmp).starts_with ("?random/")) + if (final_map_exit) + if (maptile *new_map = maptile::find_sync (final_map)) { - tmp->destroy (); - break; - } + object *the_exit_back = the_exit_up->arch->instance (); - if (final_map_exit) - { - /* setup the exit back */ - the_exit_back->slaying = map->path; - the_exit_back->stats.hp = the_exit_down->x; - the_exit_back->stats.sp = the_exit_down->y; - the_exit_back->x = new_map->enter_x; - the_exit_back->y = new_map->enter_y; + new_map->load_sync (); - insert_ob_in_map (the_exit_back, new_map, NULL, 0); - } + for (object *tmp = new_map->at (new_map->enter_x, new_map->enter_y).bot; tmp; tmp = tmp->above) + /* Remove exit back to previous random map. There should only be one + * which is why we break out. To try to process more than one + * would require keeping a 'next' pointer, ad free_object kills tmp, which + * breaks the for loop. + */ + if (tmp->type == EXIT && EXIT_PATH (tmp).starts_with ("?random/")) + { + tmp->destroy (); + break; + } + + /* setup the exit back */ + the_exit_back->slaying = map->path; + the_exit_back->stats.hp = the_exit_down->x; + the_exit_back->stats.sp = the_exit_down->y; + the_exit_back->x = new_map->enter_x; + the_exit_back->y = new_map->enter_y; + + insert_ob_in_map (the_exit_back, new_map, NULL, 0); + } } - else - the_exit_down->slaying = shstr_random_map_exit; /* Block the exit so things don't get dumped on top of it. */ the_exit_down->move_block = MOVE_ALL;