X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Ffloor-save.c;h=a4db8aff55252676333ab657a74eef71d255202e;hb=faa97d03269c2d684d047d5c0d67e4fc4132fbd8;hp=90ce4b98dc0e8bebb96d441d8c1542d087945586;hpb=9b6497cb053839e0b632be11ab666474c4780a1e;p=hengband%2Fhengband.git diff --git a/src/floor-save.c b/src/floor-save.c index 90ce4b98d..a4db8aff5 100644 --- a/src/floor-save.c +++ b/src/floor-save.c @@ -11,14 +11,51 @@ */ #include "angband.h" -#include "generate.h" +#include "bldg.h" +#include "core.h" +#include "load.h" +#include "util.h" + +#include "artifact.h" +#include "dungeon.h" +#include "floor.h" +#include "floor-events.h" +#include "floor-generate.h" +#include "feature.h" #include "grid.h" +#include "monster.h" +#include "quest.h" +#include "wild.h" +#include "spells-floor.h" +#include "monster-status.h" +#include "object-hook.h" +#include "cmd-pet.h" +#include "cmd-basic.h" +#include "files.h" +#include "player-effects.h" +#include "player-class.h" +#include "player-personality.h" +#include "world.h" +#include "spells.h" +#include "cmd-dump.h" +#include "save.h" + +#include "view-mainwindow.h" static FLOOR_IDX new_floor_id; /*!<次のフロアのID / floor_id of the destination */ -static u32b change_floor_mode; /*!<フロア移行処理に関するフラグ / Mode flags for changing floor */ static u32b latest_visit_mark; /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */ +/* + * Number of floor_id used from birth + */ +FLOOR_IDX max_floor_id; + +/* + * Sign for current process used in temporal files. + * Actually it is the start time of current process. + */ +u32b saved_floor_file_sign; /*! * @brief 保存フロア配列を初期化する / Initialize saved_floors array. @@ -101,7 +138,7 @@ void init_saved_floors(bool force) new_floor_id = 0; /* No change floor mode yet */ - change_floor_mode = 0; + p_ptr->change_floor_mode = 0; #ifdef SET_UID # ifdef SECURE @@ -189,8 +226,6 @@ saved_floor_type *get_sf_ptr(FLOOR_IDX floor_id) static void kill_saved_floor(saved_floor_type *sf_ptr) { char floor_savefile[1024]; - - /* Paranoia */ if (!sf_ptr) return; /* Already empty */ @@ -280,7 +315,7 @@ FLOOR_IDX get_new_floor_id(void) sf_ptr->visit_mark = latest_visit_mark++; /* sf_ptr->dun_level may be changed later */ - sf_ptr->dun_level = dun_level; + sf_ptr->dun_level = p_ptr->current_floor_ptr->dun_level; /* Increment number of floor_id */ @@ -300,26 +335,25 @@ FLOOR_IDX get_new_floor_id(void) */ void prepare_change_floor_mode(BIT_FLAGS mode) { - change_floor_mode |= mode; + p_ptr->change_floor_mode |= mode; } /*! * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / Builds the dead end * @return なし */ -static void build_dead_end(void) +static void build_dead_end(floor_type *floor_ptr) { POSITION x, y; - /* Clear and empty the cave */ - clear_cave(); + clear_cave(floor_ptr); /* Fill the arrays of floors and walls in the good proportions */ set_floor_and_wall(0); /* Smallest area */ - cur_hgt = SCREEN_HGT; - cur_wid = SCREEN_WID; + floor_ptr->height = SCREEN_HGT; + floor_ptr->width = SCREEN_WID; /* Filled with permanent walls */ for (y = 0; y < MAX_HGT; y++) @@ -332,13 +366,13 @@ static void build_dead_end(void) } /* Place at center of the floor */ - p_ptr->y = cur_hgt / 2; - p_ptr->x = cur_wid / 2; + p_ptr->y = floor_ptr->height / 2; + p_ptr->x = floor_ptr->width / 2; /* Give one square */ place_floor_bold(p_ptr->y, p_ptr->x); - wipe_generate_cave_flags(); + wipe_generate_random_floor_flags(floor_ptr); } @@ -362,7 +396,7 @@ static void preserve_pet(void) if (p_ptr->riding) { - monster_type *m_ptr = &m_list[p_ptr->riding]; + monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[p_ptr->riding]; /* Pet of other pet don't follow. */ if (m_ptr->parent_m_idx) @@ -385,13 +419,13 @@ static void preserve_pet(void) * If player is in wild mode, no pets are preserved * except a monster whom player riding */ - if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle) + if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->phase_out) { - for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--) + for (i = p_ptr->current_floor_ptr->m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--) { - monster_type *m_ptr = &m_list[i]; + monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i]; - if (!m_ptr->r_idx) continue; + if (!monster_is_valid(m_ptr)) continue; if (!is_pet(m_ptr)) continue; if (i == p_ptr->riding) continue; @@ -425,7 +459,7 @@ static void preserve_pet(void) } } - (void)COPY(&party_mon[num], &m_list[i], monster_type); + (void)COPY(&party_mon[num], &p_ptr->current_floor_ptr->m_list[i], monster_type); num++; @@ -436,29 +470,29 @@ static void preserve_pet(void) if (record_named_pet) { - for (i = m_max - 1; i >=1; i--) + for (i = p_ptr->current_floor_ptr->m_max - 1; i >=1; i--) { - monster_type *m_ptr = &m_list[i]; + monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i]; GAME_TEXT m_name[MAX_NLEN]; - if (!m_ptr->r_idx) continue; + if (!monster_is_valid(m_ptr)) continue; if (!is_pet(m_ptr)) continue; if (!m_ptr->nickname) continue; if (p_ptr->riding == i) continue; monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE); - do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name); + exe_write_diary(p_ptr, NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name); } } /* Pet of other pet may disappear. */ - for (i = m_max - 1; i >=1; i--) + for (i = p_ptr->current_floor_ptr->m_max - 1; i >=1; i--) { - monster_type *m_ptr = &m_list[i]; + monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i]; /* Are there its parent? */ - if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx) + if (m_ptr->parent_m_idx && !p_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx) { /* Its parent have gone, it also goes away. */ @@ -492,7 +526,7 @@ void precalc_cur_num_of_pet(void) m_ptr = &party_mon[i]; /* Skip empty monsters */ - if (!m_ptr->r_idx) continue; + if (!monster_is_valid(m_ptr)) continue; /* Hack -- Increase the racial counter */ real_r_ptr(m_ptr)->cur_num++; @@ -503,10 +537,10 @@ void precalc_cur_num_of_pet(void) * @brief 移動先のフロアに伴ったペットを配置する / Place preserved pet monsters on new floor * @return なし */ -static void place_pet(void) +static void place_pet(player_type *master_ptr) { int i; - int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON; + int max_num = master_ptr->wild_mode ? 1 : MAX_PARTY_MON; for (i = 0; i < max_num; i++) { @@ -518,11 +552,11 @@ static void place_pet(void) if (i == 0) { m_idx = m_pop(); - p_ptr->riding = m_idx; + master_ptr->riding = m_idx; if (m_idx) { - cy = p_ptr->y; - cx = p_ptr->x; + cy = master_ptr->y; + cx = master_ptr->x; } } else @@ -534,7 +568,7 @@ static void place_pet(void) { for (j = 1000; j > 0; j--) { - scatter(&cy, &cx, p_ptr->y, p_ptr->x, d, 0); + scatter(&cy, &cx, master_ptr->y, master_ptr->x, d, 0); if (monster_can_enter(cy, cx, &r_info[party_mon[i].r_idx], 0)) break; } if (j) break; @@ -544,10 +578,10 @@ static void place_pet(void) if (m_idx) { - monster_type *m_ptr = &m_list[m_idx]; + monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx]; monster_race *r_ptr; - cave[cy][cx].m_idx = m_idx; + p_ptr->current_floor_ptr->grid_array[cy][cx].m_idx = m_idx; m_ptr->r_idx = party_mon[i].r_idx; @@ -559,8 +593,6 @@ static void place_pet(void) m_ptr->fx = cx; m_ptr->ml = TRUE; m_ptr->mtimed[MTIMED_CSLEEP] = 0; - - /* Paranoia */ m_ptr->hold_o_idx = 0; m_ptr->target_y = 0; @@ -579,14 +611,8 @@ static void place_pet(void) /* r_ptr->cur_num++; */ /* Hack -- Count the number of "reproducers" */ - if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++; + if (r_ptr->flags2 & RF2_MULTIPLY) p_ptr->current_floor_ptr->num_repro++; - /* Hack -- Notice new multi-hued monsters */ - { - monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx]; - if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER)) - shimmer_monsters = TRUE; - } } else { @@ -599,7 +625,7 @@ static void place_pet(void) if (record_named_pet && m_ptr->nickname) { monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE); - do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name); + exe_write_diary(master_ptr, NIKKI_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name); } /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */ @@ -626,13 +652,12 @@ static void update_unique_artifact(s16b cur_floor_id) int i; /* Maintain unique monsters */ - for (i = 1; i < m_max; i++) + for (i = 1; i < p_ptr->current_floor_ptr->m_max; i++) { monster_race *r_ptr; - monster_type *m_ptr = &m_list[i]; + monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i]; - /* Skip dead monsters */ - if (!m_ptr->r_idx) continue; + if (!monster_is_valid(m_ptr)) continue; /* Extract real monster race */ r_ptr = real_r_ptr(m_ptr); @@ -646,12 +671,11 @@ static void update_unique_artifact(s16b cur_floor_id) } /* Maintain artifatcs */ - for (i = 1; i < o_max; i++) + for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++) { - object_type *o_ptr = &o_list[i]; + object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[i]; - /* Skip dead objects */ - if (!o_ptr->k_idx) continue; + if (!OBJECT_IS_VALID(o_ptr)) continue; /* Memorize location of the artifact */ if (object_is_fixed_artifact(o_ptr)) @@ -666,13 +690,13 @@ static void update_unique_artifact(s16b cur_floor_id) * @brief フロア移動時、プレイヤーの移動先モンスターが既にいた場合ランダムな近隣に移動させる / When a monster is at a place where player will return, * @return なし */ -static void get_out_monster(void) +static void get_out_monster(floor_type *floor_ptr, player_type *protected_ptr) { int tries = 0; POSITION dis = 1; - POSITION oy = p_ptr->y; - POSITION ox = p_ptr->x; - MONSTER_IDX m_idx = cave[oy][ox].m_idx; + POSITION oy = protected_ptr->y; + POSITION ox = protected_ptr->x; + MONSTER_IDX m_idx = floor_ptr->grid_array[oy][ox].m_idx; /* Nothing to do if no monster */ if (!m_idx) return; @@ -698,27 +722,27 @@ static void get_out_monster(void) if (tries > 20 * dis * dis) dis++; /* Ignore illegal locations */ - if (!in_bounds(ny, nx)) continue; + if (!in_bounds(floor_ptr, ny, nx)) continue; /* Require "empty" floor space */ if (!cave_empty_bold(ny, nx)) continue; /* Hack -- no teleport onto glyph of warding */ - if (is_glyph_grid(&cave[ny][nx])) continue; - if (is_explosive_rune_grid(&cave[ny][nx])) continue; + if (is_glyph_grid(&floor_ptr->grid_array[ny][nx])) continue; + if (is_explosive_rune_grid(&floor_ptr->grid_array[ny][nx])) continue; /* ...nor onto the Pattern */ if (pattern_tile(ny, nx)) continue; /*** It's a good place ***/ - m_ptr = &m_list[m_idx]; + m_ptr = &floor_ptr->m_list[m_idx]; /* Update the old location */ - cave[oy][ox].m_idx = 0; + floor_ptr->grid_array[oy][ox].m_idx = 0; /* Update the new location */ - cave[ny][nx].m_idx = m_idx; + floor_ptr->grid_array[ny][nx].m_idx = m_idx; /* Move the monster */ m_ptr->fy = ny; @@ -732,17 +756,11 @@ static void get_out_monster(void) } /*! - * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with c_ptr->special? - */ -#define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL)) - - -/*! * @brief 新フロアに移動元フロアに繋がる階段を配置する / Virtually teleport onto the stairs that is connecting between two floors. * @param sf_ptr 移動元の保存フロア構造体参照ポインタ * @return なし */ -static void locate_connected_stairs(saved_floor_type *sf_ptr) +static void locate_connected_stairs(saved_floor_type *sf_ptr, BIT_FLAGS floor_mode) { POSITION x, y, sx = 0, sy = 0; POSITION x_table[20]; @@ -751,15 +769,15 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr) int i; /* Search usable stairs */ - for (y = 0; y < cur_hgt; y++) + for (y = 0; y < p_ptr->current_floor_ptr->height; y++) { - for (x = 0; x < cur_wid; x++) + for (x = 0; x < p_ptr->current_floor_ptr->width; x++) { - cave_type *c_ptr = &cave[y][x]; - feature_type *f_ptr = &f_info[c_ptr->feat]; + grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x]; + feature_type *f_ptr = &f_info[g_ptr->feat]; bool ok = FALSE; - if (change_floor_mode & CFM_UP) + if (floor_mode & CFM_UP) { if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) && !have_flag(f_ptr->flags, FF_SPECIAL)) @@ -767,8 +785,8 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr) ok = TRUE; /* Found fixed stairs? */ - if (c_ptr->special && - c_ptr->special == sf_ptr->upper_floor_id) + if (g_ptr->special && + g_ptr->special == sf_ptr->upper_floor_id) { sx = x; sy = y; @@ -776,7 +794,7 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr) } } - else if (change_floor_mode & CFM_DOWN) + else if (floor_mode & CFM_DOWN) { if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) && !have_flag(f_ptr->flags, FF_SPECIAL)) @@ -784,8 +802,8 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr) ok = TRUE; /* Found fixed stairs */ - if (c_ptr->special && - c_ptr->special == sf_ptr->lower_floor_id) + if (g_ptr->special && + g_ptr->special == sf_ptr->lower_floor_id) { sx = x; sy = y; @@ -822,7 +840,7 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr) prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN); /* Mega Hack -- It's not the stairs you enter. Disable it. */ - if (!feat_uses_special(cave[p_ptr->y][p_ptr->x].feat)) cave[p_ptr->y][p_ptr->x].special = 0; + if (!feat_uses_special(p_ptr->current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].feat)) p_ptr->current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].special = 0; } else { @@ -840,32 +858,33 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr) * / Maintain quest monsters, mark next floor_id at stairs, save current floor, and prepare to enter next floor. * @return なし */ -void leave_floor(void) +void leave_floor(player_type *creature_ptr) { - cave_type *c_ptr = NULL; + grid_type *g_ptr = NULL; feature_type *f_ptr; saved_floor_type *sf_ptr; MONRACE_IDX quest_r_idx = 0; DUNGEON_IDX i; - + FLOOR_IDX tmp_floor_idx = 0; + /* Preserve pets and prepare to take these to next floor */ preserve_pet(); /* Remove all mirrors without explosion */ remove_all_mirrors(FALSE); - if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE); + if (creature_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(creature_ptr, FALSE); /* New floor is not yet prepared */ new_floor_id = 0; /* Temporary get a floor_id (for Arena) */ - if (!p_ptr->floor_id && - (change_floor_mode & CFM_SAVE_FLOORS) && - !(change_floor_mode & CFM_NO_RETURN)) + if (!creature_ptr->floor_id && + (creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) && + !(creature_ptr->change_floor_mode & CFM_NO_RETURN)) { /* Get temporal floor_id */ - p_ptr->floor_id = get_new_floor_id(); + tmp_floor_idx = get_new_floor_id(); } /* Search the quest monster index */ @@ -874,8 +893,8 @@ void leave_floor(void) if ((quest[i].status == QUEST_STATUS_TAKEN) && ((quest[i].type == QUEST_TYPE_KILL_LEVEL) || (quest[i].type == QUEST_TYPE_RANDOM)) && - (quest[i].level == dun_level) && - (dungeon_type == quest[i].dungeon) && + (quest[i].level == p_ptr->current_floor_ptr->dun_level) && + (creature_ptr->dungeon_idx == quest[i].dungeon) && !(quest[i].flags & QUEST_FLAG_PRESET)) { quest_r_idx = quest[i].r_idx; @@ -883,13 +902,12 @@ void leave_floor(void) } /* Maintain quest monsters */ - for (i = 1; i < m_max; i++) + for (i = 1; i < p_ptr->current_floor_ptr->m_max; i++) { monster_race *r_ptr; - monster_type *m_ptr = &m_list[i]; + monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i]; - /* Skip dead monsters */ - if (!m_ptr->r_idx) continue; + if (!monster_is_valid(m_ptr)) continue; /* Only maintain quest monsters */ if (quest_r_idx != m_ptr->r_idx) continue; @@ -908,10 +926,9 @@ void leave_floor(void) /* Check if there is a same item */ for (i = 0; i < INVEN_PACK; i++) { - object_type *o_ptr = &inventory[i]; + object_type *o_ptr = &creature_ptr->inventory_list[i]; - /* Skip dead objects */ - if (!o_ptr->k_idx) continue; + if (!OBJECT_IS_VALID(o_ptr)) continue; /* Delete old memorized location of the artifact */ if (object_is_fixed_artifact(o_ptr)) @@ -921,26 +938,26 @@ void leave_floor(void) } /* Extract current floor info or NULL */ - sf_ptr = get_sf_ptr(p_ptr->floor_id); + sf_ptr = get_sf_ptr(tmp_floor_idx); /* Choose random stairs */ - if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id) + if ((creature_ptr->change_floor_mode & CFM_RAND_CONNECT) && tmp_floor_idx) { - locate_connected_stairs(sf_ptr); + locate_connected_stairs(sf_ptr, creature_ptr->change_floor_mode); } /* Extract new dungeon level */ - if (change_floor_mode & CFM_SAVE_FLOORS) + if (creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) { /* Extract stair position */ - c_ptr = &cave[p_ptr->y][p_ptr->x]; - f_ptr = &f_info[c_ptr->feat]; + g_ptr = &p_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x]; + f_ptr = &f_info[g_ptr->feat]; /* Get back to old saved floor? */ - if (c_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(c_ptr->special)) + if (g_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(g_ptr->special)) { /* Saved floor is exist. Use it. */ - new_floor_id = c_ptr->special; + new_floor_id = g_ptr->special; } /* Mark shaft up/down */ @@ -951,51 +968,51 @@ void leave_floor(void) } /* Climb up/down some sort of stairs */ - if (change_floor_mode & (CFM_DOWN | CFM_UP)) + if (creature_ptr->change_floor_mode & (CFM_DOWN | CFM_UP)) { int move_num = 0; /* Extract level movement number */ - if (change_floor_mode & CFM_DOWN) move_num = 1; - else if (change_floor_mode & CFM_UP) move_num = -1; + if (creature_ptr->change_floor_mode & CFM_DOWN) move_num = 1; + else if (creature_ptr->change_floor_mode & CFM_UP) move_num = -1; /* Shafts are deeper than normal stairs */ - if (change_floor_mode & CFM_SHAFT) + if (creature_ptr->change_floor_mode & CFM_SHAFT) move_num += SGN(move_num); /* Get out from or Enter the dungeon */ - if (change_floor_mode & CFM_DOWN) + if (creature_ptr->change_floor_mode & CFM_DOWN) { - if (!dun_level) - move_num = d_info[dungeon_type].mindepth; + if (!p_ptr->current_floor_ptr->dun_level) + move_num = d_info[creature_ptr->dungeon_idx].mindepth; } - else if (change_floor_mode & CFM_UP) + else if (creature_ptr->change_floor_mode & CFM_UP) { - if (dun_level + move_num < d_info[dungeon_type].mindepth) - move_num = -dun_level; + if (p_ptr->current_floor_ptr->dun_level + move_num < d_info[creature_ptr->dungeon_idx].mindepth) + move_num = -p_ptr->current_floor_ptr->dun_level; } - dun_level += move_num; + p_ptr->current_floor_ptr->dun_level += move_num; } /* Leaving the dungeon to town */ - if (!dun_level && dungeon_type) + if (!p_ptr->current_floor_ptr->dun_level && creature_ptr->dungeon_idx) { - p_ptr->leaving_dungeon = TRUE; + creature_ptr->leaving_dungeon = TRUE; if (!vanilla_town && !lite_town) { - p_ptr->wilderness_y = d_info[dungeon_type].dy; - p_ptr->wilderness_x = d_info[dungeon_type].dx; + creature_ptr->wilderness_y = d_info[creature_ptr->dungeon_idx].dy; + creature_ptr->wilderness_x = d_info[creature_ptr->dungeon_idx].dx; } - p_ptr->recall_dungeon = dungeon_type; - dungeon_type = 0; + creature_ptr->recall_dungeon = creature_ptr->dungeon_idx; + creature_ptr->dungeon_idx = 0; /* Reach to the surface -- Clear all saved floors */ - change_floor_mode &= ~CFM_SAVE_FLOORS; + creature_ptr->change_floor_mode &= ~CFM_SAVE_FLOORS; // TODO } /* Kill some old saved floors */ - if (!(change_floor_mode & CFM_SAVE_FLOORS)) + if (!(creature_ptr->change_floor_mode & CFM_SAVE_FLOORS)) { /* Kill all saved floors */ for (i = 0; i < MAX_SAVED_FLOORS; i++) @@ -1004,20 +1021,19 @@ void leave_floor(void) /* Reset visit_mark count */ latest_visit_mark = 1; } - else if (change_floor_mode & CFM_NO_RETURN) + else if (creature_ptr->change_floor_mode & CFM_NO_RETURN) { /* Kill current floor */ kill_saved_floor(sf_ptr); } /* No current floor -- Left/Enter dungeon etc... */ - if (!p_ptr->floor_id) + if (!tmp_floor_idx) { /* No longer need to save current floor */ return; } - /* Mark next floor_id on the previous floor */ if (!new_floor_id) { @@ -1025,34 +1041,34 @@ void leave_floor(void) new_floor_id = get_new_floor_id(); /* Connect from here */ - if (c_ptr && !feat_uses_special(c_ptr->feat)) + if (g_ptr && !feat_uses_special(g_ptr->feat)) { - c_ptr->special = new_floor_id; + g_ptr->special = tmp_floor_idx; } } /* Fix connection -- level teleportation or trap door */ - if (change_floor_mode & CFM_RAND_CONNECT) + if (creature_ptr->change_floor_mode & CFM_RAND_CONNECT) { - if (change_floor_mode & CFM_UP) + if (creature_ptr->change_floor_mode & CFM_UP) sf_ptr->upper_floor_id = new_floor_id; - else if (change_floor_mode & CFM_DOWN) + else if (creature_ptr->change_floor_mode & CFM_DOWN) sf_ptr->lower_floor_id = new_floor_id; } /* If you can return, you need to save previous floor */ - if ((change_floor_mode & CFM_SAVE_FLOORS) && - !(change_floor_mode & CFM_NO_RETURN)) + if ((creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) && + !(creature_ptr->change_floor_mode & CFM_NO_RETURN)) { /* Get out of the my way! */ - get_out_monster(); + get_out_monster(p_ptr->current_floor_ptr, creature_ptr); - /* Record the last visit turn of current floor */ - sf_ptr->last_visit = turn; + /* Record the last visit current_world_ptr->game_turn of current floor */ + sf_ptr->last_visit = current_world_ptr->game_turn; - forget_lite(); + forget_lite(p_ptr->current_floor_ptr); forget_view(); - clear_mon_lite(); + clear_mon_lite(p_ptr->current_floor_ptr); /* Save current floor */ if (!save_floor(sf_ptr, 0)) @@ -1061,7 +1077,7 @@ void leave_floor(void) prepare_change_floor_mode(CFM_NO_RETURN); /* Kill current floor */ - kill_saved_floor(get_sf_ptr(p_ptr->floor_id)); + kill_saved_floor(get_sf_ptr(creature_ptr->floor_id)); } } } @@ -1072,19 +1088,19 @@ void leave_floor(void) * @return なし * @details * If the floor is an old saved floor, it will be\n - * restored from the temporal file. If the floor is new one, new cave\n + * restored from the temporal file. If the floor is new one, new p_ptr->current_floor_ptr->grid_array\n * will be generated.\n */ -void change_floor(void) +void change_floor(player_type *creature_ptr) { saved_floor_type *sf_ptr; bool loaded = FALSE; /* The dungeon is not ready */ - character_dungeon = FALSE; + current_world_ptr->character_dungeon = FALSE; /* No longer in the trap detecteded region */ - p_ptr->dtrap = FALSE; + creature_ptr->dtrap = FALSE; /* Mega-Hack -- no panel yet */ panel_row_min = 0; @@ -1093,14 +1109,14 @@ void change_floor(void) panel_col_max = 0; /* Mega-Hack -- not ambushed on the wildness? */ - ambush_flag = FALSE; + creature_ptr->ambush_flag = FALSE; /* No saved floors (On the surface etc.) */ - if (!(change_floor_mode & CFM_SAVE_FLOORS) && - !(change_floor_mode & CFM_FIRST_FLOOR)) + if (!(creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) && + !(creature_ptr->change_floor_mode & CFM_FIRST_FLOOR)) { - /* Create cave */ - generate_cave(); + /* Create creature_ptr->current_floor_ptr->grid_array */ + generate_random_floor(creature_ptr->current_floor_ptr); /* Paranoia -- No new saved floor */ new_floor_id = 0; @@ -1128,19 +1144,19 @@ void change_floor(void) loaded = TRUE; /* Forbid return stairs */ - if (change_floor_mode & CFM_NO_RETURN) + if (creature_ptr->change_floor_mode & CFM_NO_RETURN) { - cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x]; + grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x]; - if (!feat_uses_special(c_ptr->feat)) + if (!feat_uses_special(g_ptr->feat)) { - if (change_floor_mode & (CFM_DOWN | CFM_UP)) + if (creature_ptr->change_floor_mode & (CFM_DOWN | CFM_UP)) { /* Reset to floor */ - c_ptr->feat = floor_type[randint0(100)]; + g_ptr->feat = feat_ground_type[randint0(100)]; } - c_ptr->special = 0; + g_ptr->special = 0; } } } @@ -1153,53 +1169,52 @@ void change_floor(void) * Stair creation/Teleport level/Trap door will take * you the same floor when you used it later again. */ - if (p_ptr->floor_id) + if (creature_ptr->floor_id) { - saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id); + saved_floor_type *cur_sf_ptr = get_sf_ptr(creature_ptr->floor_id); - if (change_floor_mode & CFM_UP) + if (creature_ptr->change_floor_mode & CFM_UP) { /* New floor is right-above */ if (cur_sf_ptr->upper_floor_id == new_floor_id) - sf_ptr->lower_floor_id = p_ptr->floor_id; + sf_ptr->lower_floor_id = creature_ptr->floor_id; } - else if (change_floor_mode & CFM_DOWN) + else if (creature_ptr->change_floor_mode & CFM_DOWN) { /* New floor is right-under */ if (cur_sf_ptr->lower_floor_id == new_floor_id) - sf_ptr->upper_floor_id = p_ptr->floor_id; + sf_ptr->upper_floor_id = creature_ptr->floor_id; } } /* Break connection to killed floor */ else { - if (change_floor_mode & CFM_UP) + if (creature_ptr->change_floor_mode & CFM_UP) sf_ptr->lower_floor_id = 0; - else if (change_floor_mode & CFM_DOWN) + else if (creature_ptr->change_floor_mode & CFM_DOWN) sf_ptr->upper_floor_id = 0; } /* Maintain monsters and artifacts */ if (loaded) { - IDX i; - s32b tmp_last_visit = sf_ptr->last_visit; - s32b absence_ticks; - int alloc_chance = d_info[dungeon_type].max_m_alloc_chance; - int alloc_times; + MONSTER_IDX i; + GAME_TURN tmp_last_visit = sf_ptr->last_visit; + GAME_TURN absence_ticks; + int alloc_chance = d_info[creature_ptr->dungeon_idx].max_m_alloc_chance; + GAME_TURN alloc_times; - while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN; - absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK; + while (tmp_last_visit > current_world_ptr->game_turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN; + absence_ticks = (current_world_ptr->game_turn - tmp_last_visit) / TURNS_PER_TICK; /* Maintain monsters */ - for (i = 1; i < m_max; i++) + for (i = 1; i < creature_ptr->current_floor_ptr->m_max; i++) { monster_race *r_ptr; - monster_type *m_ptr = &m_list[i]; + monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i]; - /* Skip dead monsters */ - if (!m_ptr->r_idx) continue; + if (!monster_is_valid(m_ptr)) continue; if (!is_pet(m_ptr)) { @@ -1231,12 +1246,11 @@ void change_floor(void) } /* Maintain artifatcs */ - for (i = 1; i < o_max; i++) + for (i = 1; i < creature_ptr->current_floor_ptr->o_max; i++) { - object_type *o_ptr = &o_list[i]; + object_type *o_ptr = &creature_ptr->current_floor_ptr->o_list[i]; - /* Skip dead objects */ - if (!o_ptr->k_idx) continue; + if (!OBJECT_IS_VALID(o_ptr)) continue; /* Ignore non-artifact */ if (!object_is_fixed_artifact(o_ptr)) continue; @@ -1279,69 +1293,68 @@ void change_floor(void) msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end...")); /* Create simple dead end */ - build_dead_end(); + build_dead_end(creature_ptr->current_floor_ptr); /* Break connection */ - if (change_floor_mode & CFM_UP) + if (creature_ptr->change_floor_mode & CFM_UP) { sf_ptr->upper_floor_id = 0; } - else if (change_floor_mode & CFM_DOWN) + else if (creature_ptr->change_floor_mode & CFM_DOWN) { sf_ptr->lower_floor_id = 0; } } else { - /* Newly create cave */ - generate_cave(); + /* Newly create creature_ptr->current_floor_ptr->grid_array */ + generate_random_floor(creature_ptr->current_floor_ptr); } - /* Record last visit turn */ - sf_ptr->last_visit = turn; + /* Record last visit current_world_ptr->game_turn */ + sf_ptr->last_visit = current_world_ptr->game_turn; - /* Set correct dun_level value */ - sf_ptr->dun_level = dun_level; + /* Set correct creature_ptr->current_floor_ptr->dun_level value */ + sf_ptr->dun_level = creature_ptr->current_floor_ptr->dun_level; /* Create connected stairs */ - if (!(change_floor_mode & CFM_NO_RETURN)) + if (!(creature_ptr->change_floor_mode & CFM_NO_RETURN)) { /* Extract stair position */ - cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x]; + grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x]; /*** Create connected stairs ***/ /* No stairs down from Quest */ - if ((change_floor_mode & CFM_UP) && !quest_number(dun_level)) + if ((creature_ptr->change_floor_mode & CFM_UP) && !quest_number(creature_ptr->current_floor_ptr->dun_level)) { - c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair; + g_ptr->feat = (creature_ptr->change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair; } /* No stairs up when ironman_downward */ - else if ((change_floor_mode & CFM_DOWN) && !ironman_downward) + else if ((creature_ptr->change_floor_mode & CFM_DOWN) && !ironman_downward) { - c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair; + g_ptr->feat = (creature_ptr->change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair; } /* Paranoia -- Clear mimic */ - c_ptr->mimic = 0; + g_ptr->mimic = 0; /* Connect to previous floor */ - c_ptr->special = p_ptr->floor_id; + g_ptr->special = creature_ptr->floor_id; } } /* Arrive at random grid */ - if (change_floor_mode & (CFM_RAND_PLACE)) + if (creature_ptr->change_floor_mode & (CFM_RAND_PLACE)) { (void)new_player_spot(); } /* You see stairs blocked */ - else if ((change_floor_mode & CFM_NO_RETURN) && - (change_floor_mode & (CFM_DOWN | CFM_UP))) + else if ((creature_ptr->change_floor_mode & CFM_NO_RETURN) && (creature_ptr->change_floor_mode & (CFM_DOWN | CFM_UP))) { - if (!p_ptr->blind) + if (!creature_ptr->blind) { msg_print(_("突然階段が塞がれてしまった。", "Suddenly the stairs is blocked!")); } @@ -1354,16 +1367,16 @@ void change_floor(void) /* * Update visit mark * - * The "turn" is not always different number because - * the level teleport doesn't take any turn. Use - * visit mark instead of last visit turn to find the + * The "current_world_ptr->game_turn" is not always different number because + * the level teleport doesn't take any current_world_ptr->game_turn. Use + * visit mark instead of last visit current_world_ptr->game_turn to find the * oldest saved floor. */ sf_ptr->visit_mark = latest_visit_mark++; } /* Place preserved pet monsters */ - place_pet(); + place_pet(creature_ptr); /* Reset travel target place */ forget_travel_flow(); @@ -1372,151 +1385,25 @@ void change_floor(void) update_unique_artifact(new_floor_id); /* Now the player is in new floor */ - p_ptr->floor_id = new_floor_id; + creature_ptr->floor_id = new_floor_id; /* The dungeon is ready */ - character_dungeon = TRUE; + current_world_ptr->character_dungeon = TRUE; /* Hack -- Munchkin characters always get whole map */ - if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) - wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA)); + if (creature_ptr->pseikaku == SEIKAKU_MUNCHKIN) + wiz_lite(creature_ptr, (bool)(creature_ptr->pclass == CLASS_NINJA)); /* Remember when this level was "created" */ - old_turn = turn; + creature_ptr->current_floor_ptr->generated_turn = current_world_ptr->game_turn; /* No dungeon feeling yet */ - p_ptr->feeling_turn = old_turn; - p_ptr->feeling = 0; + creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn; + creature_ptr->feeling = 0; /* Clear all flags */ - change_floor_mode = 0L; - - select_floor_music(); -} - -/*! - * @brief プレイヤーの手による能動的な階段生成処理 / - * Create stairs at or move previously created stairs into the player location. - * @return なし - */ -void stair_creation(void) -{ - saved_floor_type *sf_ptr; - saved_floor_type *dest_sf_ptr; - - bool up = TRUE; - bool down = TRUE; - s16b dest_floor_id = 0; - - - /* Forbid up staircases on Ironman mode */ - if (ironman_downward) up = FALSE; - - /* Forbid down staircases on quest level */ - if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE; - - /* No effect out of standard dungeon floor */ - if (!dun_level || (!up && !down) || - (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || - p_ptr->inside_arena || p_ptr->inside_battle) - { - /* arena or quest */ - msg_print(_("効果がありません!", "There is no effect!")); - return; - } - - /* Artifacts resists */ - if (!cave_valid_bold(p_ptr->y, p_ptr->x)) - { - msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell.")); - return; - } - - /* Destroy all objects in the grid */ - delete_object(p_ptr->y, p_ptr->x); - - /* Extract current floor data */ - sf_ptr = get_sf_ptr(p_ptr->floor_id); - - /* Paranoia */ - if (!sf_ptr) - { - /* No floor id? -- Create now! */ - p_ptr->floor_id = get_new_floor_id(); - sf_ptr = get_sf_ptr(p_ptr->floor_id); - } - - /* Choose randomly */ - if (up && down) - { - if (randint0(100) < 50) up = FALSE; - else down = FALSE; - } - - /* Destination is already fixed */ - if (up) - { - if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id; - } - else - { - if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id; - } - - - /* Search old stairs leading to the destination */ - if (dest_floor_id) - { - POSITION x, y; - - for (y = 0; y < cur_hgt; y++) - { - for (x = 0; x < cur_wid; x++) - { - cave_type *c_ptr = &cave[y][x]; - - if (!c_ptr->special) continue; - if (feat_uses_special(c_ptr->feat)) continue; - if (c_ptr->special != dest_floor_id) continue; - - /* Remove old stairs */ - c_ptr->special = 0; - cave_set_feat(y, x, floor_type[randint0(100)]); - } - } - } - - /* No old destination -- Get new one now */ - else - { - dest_floor_id = get_new_floor_id(); - - /* Fix it */ - if (up) - sf_ptr->upper_floor_id = dest_floor_id; - else - sf_ptr->lower_floor_id = dest_floor_id; - } - - /* Extract destination floor data */ - dest_sf_ptr = get_sf_ptr(dest_floor_id); - - - /* Create a staircase */ - if (up) - { - cave_set_feat(p_ptr->y, p_ptr->x, - (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= dun_level - 2)) ? - feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair); - } - else - { - cave_set_feat(p_ptr->y, p_ptr->x, - (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= dun_level + 2)) ? - feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair); - } - + creature_ptr->change_floor_mode = 0L; - /* Connect this stairs to the destination */ - cave[p_ptr->y][p_ptr->x].special = dest_floor_id; + select_floor_music(creature_ptr); + creature_ptr->change_floor_mode = 0; }