2 * todo ちょっとギリギリ。後で分割を検討する
3 * @brief フロア生成時にアイテムを配置する
8 #include "floor/floor-object.h"
9 #include "artifact/fixed-art-generator.h"
10 #include "flavor/flavor-describer.h"
11 #include "flavor/object-flavor-types.h"
12 #include "floor/cave.h"
13 #include "game-option/birth-options.h"
14 #include "game-option/cheat-options.h"
15 #include "game-option/cheat-types.h"
16 #include "grid/feature.h"
17 #include "grid/grid.h"
18 #include "inventory/inventory-slot-types.h"
19 #include "inventory/item-getter.h"
20 #include "main/sound-definitions-table.h"
21 #include "main/sound-of-music.h"
22 #include "object-enchant/apply-magic.h"
23 #include "object-enchant/item-apply-magic.h"
24 #include "object-enchant/special-object-flags.h"
25 #include "object-hook/hook-checker.h"
26 #include "object-hook/hook-enchant.h"
27 #include "object/object-generator.h"
28 #include "object/object-info.h"
29 #include "object/object-kind-hook.h"
30 #include "object/object-kind.h"
31 #include "object/object-stack.h"
32 #include "perception/object-perception.h"
33 #include "system/alloc-entries.h"
34 #include "system/artifact-type-definition.h"
35 #include "system/floor-type-definition.h"
36 #include "system/system-variables.h"
37 #include "target/projection-path-calculator.h"
38 #include "util/bit-flags-calculator.h"
39 #include "view/display-messages.h"
40 #include "wizard/wizard-messages.h"
41 #include "world/world-object.h"
42 #include "world/world.h"
44 #define MAX_GOLD 18 /* Number of "gold" entries */
47 * @brief オブジェクト生成テーブルに生成制約を加える /
48 * Apply a "object restriction function" to the "object allocation table"
50 * @details 生成の制約はグローバルのget_obj_num_hook関数ポインタで加える
52 static errr get_obj_num_prep(void)
54 alloc_entry *table = alloc_kind_table;
55 for (OBJECT_IDX i = 0; i < alloc_kind_size; i++) {
56 if (!get_obj_num_hook || (*get_obj_num_hook)(table[i].index)) {
57 table[i].prob2 = table[i].prob1;
67 * @brief デバッグ時にアイテム生成情報をメッセージに出力する / Cheat -- describe a created object for the user
68 * @param owner_ptr プレーヤーへの参照ポインタ
69 * @param o_ptr デバッグ出力するオブジェクトの構造体参照ポインタ
72 static void object_mention(player_type *owner_ptr, object_type *o_ptr)
74 object_aware(owner_ptr, o_ptr);
77 o_ptr->ident |= (IDENT_FULL_KNOWN);
78 GAME_TEXT o_name[MAX_NLEN];
79 describe_flavor(owner_ptr, o_name, o_ptr, 0);
80 msg_format_wizard(owner_ptr, CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), o_name);
84 * @brief 生成階に応じたベースアイテムの生成を行う。
85 * Attempt to make an object (normal or good/great)
86 * @param owner_ptr プレーヤーへの参照ポインタ
87 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
88 * @param mode オプションフラグ
89 * @return 生成に成功したらTRUEを返す。
91 * This routine plays nasty games to generate the "special artifacts".\n
92 * This routine uses "floor_ptr->object_level" for the "generation level".\n
93 * We assume that the given object has been "wiped".\n
95 bool make_object(player_type *owner_ptr, object_type *j_ptr, BIT_FLAGS mode)
97 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
98 PERCENTAGE prob = ((mode & AM_GOOD) ? 10 : 1000);
99 DEPTH base = ((mode & AM_GOOD) ? (floor_ptr->object_level + 10) : floor_ptr->object_level);
100 if (!one_in_(prob) || !make_artifact_special(owner_ptr, j_ptr)) {
101 KIND_OBJECT_IDX k_idx;
102 if ((mode & AM_GOOD) && !get_obj_num_hook) {
103 get_obj_num_hook = kind_is_good;
106 if (get_obj_num_hook)
109 k_idx = get_obj_num(owner_ptr, base, mode);
110 if (get_obj_num_hook) {
111 get_obj_num_hook = NULL;
118 object_prep(owner_ptr, j_ptr, k_idx);
121 apply_magic(owner_ptr, j_ptr, floor_ptr->object_level, mode);
122 switch (j_ptr->tval) {
128 j_ptr->number = (byte)damroll(6, 7);
133 object_mention(owner_ptr, j_ptr);
139 * @brief 生成階に応じた財宝オブジェクトの生成を行う。
140 * Make a treasure object
141 * @param floor_ptr 現在フロアへの参照ポインタ
142 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
143 * @return 生成に成功したらTRUEを返す。
145 * The location must be a legal, clean, floor grid.
147 bool make_gold(player_type *player_ptr, object_type *j_ptr)
149 floor_type *floor_ptr = player_ptr->current_floor_ptr;
150 int i = ((randint1(floor_ptr->object_level + 2) + 2) / 2) - 1;
151 if (one_in_(GREAT_OBJ)) {
152 i += randint1(floor_ptr->object_level + 1);
159 object_prep(player_ptr, j_ptr, OBJ_GOLD_LIST + i);
161 s32b base = k_info[OBJ_GOLD_LIST + i].cost;
162 j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
168 * @brief フロア中のアイテムを全て削除する / Deletes all objects at given location
169 * Delete a dungeon object
170 * @param player_ptr プレーヤーへの参照ポインタ
171 * @param y 削除したフロアマスのY座標
172 * @param x 削除したフロアマスのX座標
175 void delete_all_items_from_floor(player_type *player_ptr, POSITION y, POSITION x)
178 OBJECT_IDX this_o_idx, next_o_idx = 0;
179 floor_type *floor_ptr = player_ptr->current_floor_ptr;
180 if (!in_bounds(floor_ptr, y, x))
183 g_ptr = &floor_ptr->grid_array[y][x];
184 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
186 o_ptr = &floor_ptr->o_list[this_o_idx];
187 next_o_idx = o_ptr->next_o_idx;
193 lite_spot(player_ptr, y, x);
197 * @brief 床上のアイテムの数を増やす /
198 * Increase the "number" of an item on the floor
199 * @param floo_ptr 現在フロアへの参照ポインタ
200 * @param item 増やしたいアイテムの所持スロット
201 * @param num 増やしたいアイテムの数
204 void floor_item_increase(floor_type *floor_ptr, INVENTORY_IDX item, ITEM_NUMBER num)
206 object_type *o_ptr = &floor_ptr->o_list[item];
207 num += o_ptr->number;
213 num -= o_ptr->number;
214 o_ptr->number += num;
218 * @brief 床上の数の無くなったアイテムスロットを消去する /
219 * Optimize an item on the floor (destroy "empty" items)
220 * @param player_ptr プレーヤーへの参照ポインタ
221 * @param item 消去したいアイテムの所持スロット
224 void floor_item_optimize(player_type *owner_ptr, INVENTORY_IDX item)
226 object_type *o_ptr = &owner_ptr->current_floor_ptr->o_list[item];
232 delete_object_idx(owner_ptr, item);
236 * @brief オブジェクトを削除する /
237 * Delete a dungeon object
238 * @param player_ptr プレーヤーへの参照ポインタ
239 * @param o_idx 削除対象のオブジェクト構造体ポインタ
242 * Handle "stacks" of objects correctly.
244 void delete_object_idx(player_type *player_ptr, OBJECT_IDX o_idx)
247 floor_type *floor_ptr = player_ptr->current_floor_ptr;
248 excise_object_idx(floor_ptr, o_idx);
249 j_ptr = &floor_ptr->o_list[o_idx];
250 if (!object_is_held_monster(j_ptr)) {
254 lite_spot(player_ptr, y, x);
262 * @brief 床上、モンスター所持でスタックされたアイテムを削除しスタックを補完する / Excise a dungeon object from any stacks
263 * @param floo_ptr 現在フロアへの参照ポインタ
264 * @param o_idx 削除対象のオブジェクト構造体ポインタ
267 void excise_object_idx(floor_type *floor_ptr, OBJECT_IDX o_idx)
269 OBJECT_IDX this_o_idx, next_o_idx = 0;
270 OBJECT_IDX prev_o_idx = 0;
272 j_ptr = &floor_ptr->o_list[o_idx];
274 if (object_is_held_monster(j_ptr)) {
276 m_ptr = &floor_ptr->m_list[j_ptr->held_m_idx];
277 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) {
279 o_ptr = &floor_ptr->o_list[this_o_idx];
280 next_o_idx = o_ptr->next_o_idx;
281 if (this_o_idx != o_idx) {
282 prev_o_idx = this_o_idx;
286 if (prev_o_idx == 0) {
287 m_ptr->hold_o_idx = next_o_idx;
290 k_ptr = &floor_ptr->o_list[prev_o_idx];
291 k_ptr->next_o_idx = next_o_idx;
294 o_ptr->next_o_idx = 0;
302 POSITION y = j_ptr->iy;
303 POSITION x = j_ptr->ix;
304 g_ptr = &floor_ptr->grid_array[y][x];
305 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
307 o_ptr = &floor_ptr->o_list[this_o_idx];
308 next_o_idx = o_ptr->next_o_idx;
309 if (this_o_idx != o_idx) {
310 prev_o_idx = this_o_idx;
314 if (prev_o_idx == 0) {
315 g_ptr->o_idx = next_o_idx;
318 k_ptr = &floor_ptr->o_list[prev_o_idx];
319 k_ptr->next_o_idx = next_o_idx;
322 o_ptr->next_o_idx = 0;
328 * @brief 生成済のオブジェクトをフロアの所定の位置に落とす。
329 * Let an object fall to the ground at or near a location.
330 * @param owner_ptr プレーヤーへの参照ポインタ
331 * @param j_ptr 落としたいオブジェクト構造体の参照ポインタ
332 * @param chance ドロップの消滅率(%)
333 * @param y 配置したいフロアのY座標
334 * @param x 配置したいフロアのX座標
335 * @return 生成に成功したらオブジェクトのIDを返す。
337 * The initial location is assumed to be "in_bounds(floor_ptr, )".\n
339 * This function takes a parameter "chance". This is the percentage\n
340 * chance that the item will "disappear" instead of drop. If the object\n
341 * has been thrown, then this is the chance of disappearance on contact.\n
343 * Hack -- this function uses "chance" to determine if it should produce\n
344 * some form of "description" of the drop event (under the player).\n
346 * We check several locations to see if we can find a location at which\n
347 * the object can combine, stack, or be placed. Artifacts will try very\n
348 * hard to be placed, including "teleporting" to a useful grid if needed.\n
350 OBJECT_IDX drop_near(player_type *owner_ptr, object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION x)
355 OBJECT_IDX o_idx = 0;
356 OBJECT_IDX this_o_idx, next_o_idx = 0;
358 GAME_TEXT o_name[MAX_NLEN];
363 bool plural = (j_ptr->number != 1);
365 describe_flavor(owner_ptr, o_name, j_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
366 if (!object_is_artifact(j_ptr) && (randint0(100) < chance)) {
368 msg_format("%sは消えた。", o_name);
370 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
372 if (current_world_ptr->wizard)
373 msg_print(_("(破損)", "(breakage)"));
383 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
384 for (dy = -3; dy <= 3; dy++) {
385 for (dx = -3; dx <= 3; dx++) {
387 d = (dy * dy) + (dx * dx);
393 if (!in_bounds(floor_ptr, ty, tx))
395 if (!projectable(owner_ptr, y, x, ty, tx))
398 g_ptr = &floor_ptr->grid_array[ty][tx];
399 if (!cave_drop_bold(floor_ptr, ty, tx))
403 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
405 o_ptr = &floor_ptr->o_list[this_o_idx];
406 next_o_idx = o_ptr->next_o_idx;
407 if (object_similar(o_ptr, j_ptr))
418 s = 1000 - (d + k * 5);
425 if ((++bn >= 2) && !one_in_(bn))
436 if (!flag && !object_is_artifact(j_ptr)) {
438 msg_format("%sは消えた。", o_name);
440 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
442 if (current_world_ptr->wizard)
443 msg_print(_("(床スペースがない)", "(no floor space)"));
448 for (i = 0; !flag && (i < 1000); i++) {
449 ty = rand_spread(by, 1);
450 tx = rand_spread(bx, 1);
452 if (!in_bounds(floor_ptr, ty, tx))
458 if (!cave_drop_bold(floor_ptr, by, bx))
465 int candidates = 0, pick;
466 for (ty = 1; ty < floor_ptr->height - 1; ty++) {
467 for (tx = 1; tx < floor_ptr->width - 1; tx++) {
468 if (cave_drop_bold(floor_ptr, ty, tx))
475 msg_format("%sは消えた。", o_name);
477 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
480 if (current_world_ptr->wizard)
481 msg_print(_("(床スペースがない)", "(no floor space)"));
484 if (object_is_fixed_artifact(j_ptr) && !object_is_known(j_ptr)) {
485 a_info[j_ptr->name1].cur_num = 0;
492 pick = randint1(candidates);
493 for (ty = 1; ty < floor_ptr->height - 1; ty++) {
494 for (tx = 1; tx < floor_ptr->width - 1; tx++) {
495 if (cave_drop_bold(floor_ptr, ty, tx)) {
510 g_ptr = &floor_ptr->grid_array[by][bx];
511 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
513 o_ptr = &floor_ptr->o_list[this_o_idx];
514 next_o_idx = o_ptr->next_o_idx;
515 if (object_similar(o_ptr, j_ptr)) {
516 object_absorb(o_ptr, j_ptr);
523 o_idx = o_pop(floor_ptr);
525 if (!done && !o_idx) {
527 msg_format("%sは消えた。", o_name);
529 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
531 if (current_world_ptr->wizard)
532 msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
534 if (object_is_fixed_artifact(j_ptr)) {
535 a_info[j_ptr->name1].cur_num = 0;
542 object_copy(&floor_ptr->o_list[o_idx], j_ptr);
543 j_ptr = &floor_ptr->o_list[o_idx];
546 j_ptr->held_m_idx = 0;
547 j_ptr->next_o_idx = g_ptr->o_idx;
549 g_ptr->o_idx = o_idx;
553 note_spot(owner_ptr, by, bx);
554 lite_spot(owner_ptr, by, bx);
557 if (chance && player_bold(owner_ptr, by, bx)) {
558 msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
565 * @brief 床上の魔道具の残り残量メッセージを表示する /
566 * Describe the charges on an item on the floor.
567 * @param floo_ptr 現在フロアへの参照ポインタ
568 * @param item メッセージの対象にしたいアイテム所持スロット
571 void floor_item_charges(floor_type *floor_ptr, INVENTORY_IDX item)
573 object_type *o_ptr = &floor_ptr->o_list[item];
574 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND))
576 if (!object_is_known(o_ptr))
580 if (o_ptr->pval <= 0) {
581 msg_print("この床上のアイテムは、もう魔力が残っていない。");
583 msg_format("この床上のアイテムは、あと %d 回分の魔力が残っている。", o_ptr->pval);
586 if (o_ptr->pval != 1) {
587 msg_format("There are %d charges remaining.", o_ptr->pval);
589 msg_format("There is %d charge remaining.", o_ptr->pval);
595 * @brief 床上のアイテムの残り数メッセージを表示する /
596 * Describe the charges on an item on the floor.
597 * @param floo_ptr 現在フロアへの参照ポインタ
598 * @param item メッセージの対象にしたいアイテム所持スロット
601 void floor_item_describe(player_type *owner_ptr, INVENTORY_IDX item)
603 object_type *o_ptr = &owner_ptr->current_floor_ptr->o_list[item];
604 GAME_TEXT o_name[MAX_NLEN];
605 describe_flavor(owner_ptr, o_name, o_ptr, 0);
607 if (o_ptr->number <= 0) {
608 msg_format("床上には、もう%sはない。", o_name);
610 msg_format("床上には、まだ %sがある。", o_name);
613 msg_format("You see %s.", o_name);
618 * Choose an item and get auto-picker entry from it.
620 object_type *choose_object(player_type *owner_ptr, OBJECT_IDX *idx, concptr q, concptr s, BIT_FLAGS option, tval_type tval)
623 if (!get_item(owner_ptr, &item, q, s, option, tval))
629 if (item == INVEN_FORCE)
632 return ref_item(owner_ptr, item);