OSDN Git Service

[Refactor] #1172 Changed '(TRUE)', 'TRUE;' and 'FALSE;' to '(true)', 'true;' and...
[hengbandforosx/hengbandosx.git] / src / room / treasure-deployment.cpp
1 /*!
2  * @brief 部屋にアイテム・モンスター・罠を配置する処理
3  * @date 2020/07/24
4  * @author Hourier
5  */
6
7 #include "room/treasure-deployment.h"
8 #include "floor/cave.h"
9 #include "floor/geometry.h"
10 #include "grid/feature-flag-types.h"
11 #include "grid/grid.h"
12 #include "grid/object-placer.h"
13 #include "grid/trap.h"
14 #include "monster-floor/monster-generator.h"
15 #include "monster-floor/place-monster-types.h"
16 #include "object-enchant/item-apply-magic.h"
17 #include "system/floor-type-definition.h"
18 #include "system/player-type-definition.h"
19
20 /*
21  * Routine that fills the empty areas of a room with treasure and monsters.
22  */
23 void fill_treasure(player_type *player_ptr, POSITION x1, POSITION x2, POSITION y1, POSITION y2, int difficulty)
24 {
25     POSITION cx = (x1 + x2) / 2;
26     POSITION cy = (y1 + y2) / 2;
27     POSITION size = abs(x2 - x1) + abs(y2 - y1);
28     floor_type *floor_ptr = player_ptr->current_floor_ptr;
29     for (POSITION x = x1; x <= x2; x++) {
30         for (POSITION y = y1; y <= y2; y++) {
31             s32b value = ((((s32b)(distance(cx, cy, x, y))) * 100) / size) + randint1(10) - difficulty;
32             if ((randint1(100) - difficulty * 3) > 50)
33                 value = 20;
34
35             if (!is_floor_bold(floor_ptr, y, x) && (!cave_has_flag_bold(floor_ptr, y, x, FF_PLACE) || !cave_has_flag_bold(floor_ptr, y, x, FF_DROP)))
36                 continue;
37
38             if (value < 0) {
39                 floor_ptr->monster_level = floor_ptr->base_level + 40;
40                 place_monster(player_ptr, y, x, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
41                 floor_ptr->monster_level = floor_ptr->base_level;
42                 floor_ptr->object_level = floor_ptr->base_level + 20;
43                 place_object(player_ptr, y, x, AM_GOOD);
44                 floor_ptr->object_level = floor_ptr->base_level;
45             } else if (value < 5) {
46                 floor_ptr->monster_level = floor_ptr->base_level + 20;
47                 place_monster(player_ptr, y, x, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
48                 floor_ptr->monster_level = floor_ptr->base_level;
49                 floor_ptr->object_level = floor_ptr->base_level + 10;
50                 place_object(player_ptr, y, x, AM_GOOD);
51                 floor_ptr->object_level = floor_ptr->base_level;
52             } else if (value < 10) {
53                 floor_ptr->monster_level = floor_ptr->base_level + 9;
54                 place_monster(player_ptr, y, x, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
55                 floor_ptr->monster_level = floor_ptr->base_level;
56             } else if (value < 17) {
57             } else if (value < 23) {
58                 if (randint0(100) < 25) {
59                     place_object(player_ptr, y, x, 0L);
60                 } else {
61                     place_trap(player_ptr, y, x);
62                 }
63             } else if (value < 30) {
64                 floor_ptr->monster_level = floor_ptr->base_level + 5;
65                 place_monster(player_ptr, y, x, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
66                 floor_ptr->monster_level = floor_ptr->base_level;
67                 place_trap(player_ptr, y, x);
68             } else if (value < 40) {
69                 if (randint0(100) < 50) {
70                     floor_ptr->monster_level = floor_ptr->base_level + 3;
71                     place_monster(player_ptr, y, x, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
72                     floor_ptr->monster_level = floor_ptr->base_level;
73                 }
74
75                 if (randint0(100) < 50) {
76                     floor_ptr->object_level = floor_ptr->base_level + 7;
77                     place_object(player_ptr, y, x, 0L);
78                     floor_ptr->object_level = floor_ptr->base_level;
79                 }
80             } else if (value < 50) {
81                 place_trap(player_ptr, y, x);
82             } else {
83                 if (randint0(100) < 20) {
84                     place_monster(player_ptr, y, x, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
85                 } else if (randint0(100) < 50) {
86                     place_trap(player_ptr, y, x);
87                 } else if (randint0(100) < 50) {
88                     place_object(player_ptr, y, x, 0L);
89                 }
90             }
91         }
92     }
93 }