OSDN Git Service

[Refactor] #2141 floor_type *floor_ptrの宣言をautoに差し替えた
[hengbandforosx/hengbandosx.git] / src / room / rooms-trap.cpp
1 #include "room/rooms-trap.h"
2 #include "dungeon/dungeon-flag-types.h"
3 #include "dungeon/dungeon.h"
4 #include "floor/floor-generator.h"
5 #include "game-option/cheat-types.h"
6 #include "grid/feature.h"
7 #include "grid/grid.h"
8 #include "room/space-finder.h"
9 #include "system/dungeon-data-definition.h"
10 #include "system/floor-type-definition.h"
11 #include "system/grid-type-definition.h"
12 #include "system/player-type-definition.h"
13 #include "wizard/wizard-messages.h"
14
15 /*!
16  * @brief タイプ14の部屋…特殊トラップ部屋の生成 / Type 14 -- trapped rooms
17  * @param player_ptr プレイヤーへの参照ポインタ
18  * @details
19  * A special trap is placed at center of the room
20  */
21 bool build_type14(PlayerType *player_ptr, dun_data_type *dd_ptr)
22 {
23     POSITION y, x, y2, x2, yval, xval;
24     POSITION y1, x1, xsize, ysize;
25
26     bool light;
27
28     grid_type *g_ptr;
29     int16_t trap;
30
31     /* Pick a room size */
32     y1 = randint1(4);
33     x1 = randint1(11);
34     y2 = randint1(3);
35     x2 = randint1(11);
36
37     xsize = x1 + x2 + 1;
38     ysize = y1 + y2 + 1;
39
40     /* Find and reserve some space in the dungeon.  Get center of room. */
41     if (!find_space(player_ptr, dd_ptr, &yval, &xval, ysize + 2, xsize + 2))
42         return false;
43
44     /* Choose lite or dark */
45     auto *floor_ptr = player_ptr->current_floor_ptr;
46     light = ((floor_ptr->dun_level <= randint1(25)) && d_info[floor_ptr->dungeon_idx].flags.has_not(DungeonFeatureType::DARKNESS));
47
48     /* Get corner values */
49     y1 = yval - ysize / 2;
50     x1 = xval - xsize / 2;
51     y2 = yval + (ysize - 1) / 2;
52     x2 = xval + (xsize - 1) / 2;
53
54     /* Place a full floor under the room */
55     for (y = y1 - 1; y <= y2 + 1; y++) {
56         for (x = x1 - 1; x <= x2 + 1; x++) {
57             g_ptr = &floor_ptr->grid_array[y][x];
58             place_grid(player_ptr, g_ptr, GB_FLOOR);
59             g_ptr->info |= (CAVE_ROOM);
60             if (light)
61                 g_ptr->info |= (CAVE_GLOW);
62         }
63     }
64
65     /* Walls around the room */
66     for (y = y1 - 1; y <= y2 + 1; y++) {
67         g_ptr = &floor_ptr->grid_array[y][x1 - 1];
68         place_grid(player_ptr, g_ptr, GB_OUTER);
69         g_ptr = &floor_ptr->grid_array[y][x2 + 1];
70         place_grid(player_ptr, g_ptr, GB_OUTER);
71     }
72     for (x = x1 - 1; x <= x2 + 1; x++) {
73         g_ptr = &floor_ptr->grid_array[y1 - 1][x];
74         place_grid(player_ptr, g_ptr, GB_OUTER);
75         g_ptr = &floor_ptr->grid_array[y2 + 1][x];
76         place_grid(player_ptr, g_ptr, GB_OUTER);
77     }
78
79     if (floor_ptr->dun_level < 30 + randint1(30))
80         trap = feat_trap_piranha;
81     else
82         trap = feat_trap_armageddon;
83
84     /* Place a special trap */
85     g_ptr = &floor_ptr->grid_array[rand_spread(yval, ysize / 4)][rand_spread(xval, xsize / 4)];
86     g_ptr->mimic = g_ptr->feat;
87     g_ptr->feat = trap;
88
89     msg_format_wizard(player_ptr, CHEAT_DUNGEON, _("%sの部屋が生成されました。", "Room of %s was generated."), f_info[trap].name.c_str());
90     return true;
91 }