OSDN Git Service

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