2 * @brief フロア生成時にアイテムを配置する
7 #include "floor/floor-object.h"
8 #include "main/sound-definitions-table.h"
9 #include "object/artifact.h"
10 #include "object/item-apply-magic.h"
11 #include "object/object-appraiser.h"
12 #include "object/object-flavor.h"
13 #include "object/object-generator.h"
14 #include "object/object-hook.h"
15 #include "object/object-kind-hook.h"
16 #include "object/object-kind.h"
17 #include "object/object2.h"
18 #include "object/special-object-flags.h"
19 #include "view/object-describer.h"
20 #include "world/world-object.h"
21 #include "world/world.h"
23 #define MAX_GOLD 18 /* Number of "gold" entries */
26 * @brief オブジェクト生成テーブルに生成制約を加える /
27 * Apply a "object restriction function" to the "object allocation table"
29 * @details 生成の制約はグローバルのget_obj_num_hook関数ポインタで加える
31 static errr get_obj_num_prep(void)
33 alloc_entry *table = alloc_kind_table;
34 for (OBJECT_IDX i = 0; i < alloc_kind_size; i++) {
35 if (!get_obj_num_hook || (*get_obj_num_hook)(table[i].index)) {
36 table[i].prob2 = table[i].prob1;
46 * @brief デバッグ時にアイテム生成情報をメッセージに出力する / Cheat -- describe a created object for the user
47 * @param owner_ptr プレーヤーへの参照ポインタ
48 * @param o_ptr デバッグ出力するオブジェクトの構造体参照ポインタ
51 static void object_mention(player_type *owner_ptr, object_type *o_ptr)
53 object_aware(owner_ptr, o_ptr);
56 o_ptr->ident |= (IDENT_FULL_KNOWN);
57 GAME_TEXT o_name[MAX_NLEN];
58 object_desc(owner_ptr, o_name, o_ptr, 0);
59 msg_format_wizard(CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), o_name);
63 * @brief 生成階に応じたベースアイテムの生成を行う。
64 * Attempt to make an object (normal or good/great)
65 * @param owner_ptr プレーヤーへの参照ポインタ
66 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
67 * @param mode オプションフラグ
68 * @return 生成に成功したらTRUEを返す。
70 * This routine plays nasty games to generate the "special artifacts".\n
71 * This routine uses "floor_ptr->object_level" for the "generation level".\n
72 * We assume that the given object has been "wiped".\n
74 bool make_object(player_type *owner_ptr, object_type *j_ptr, BIT_FLAGS mode)
76 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
77 PERCENTAGE prob = ((mode & AM_GOOD) ? 10 : 1000);
78 DEPTH base = ((mode & AM_GOOD) ? (floor_ptr->object_level + 10) : floor_ptr->object_level);
79 if (!one_in_(prob) || !make_artifact_special(owner_ptr, j_ptr)) {
80 KIND_OBJECT_IDX k_idx;
81 if ((mode & AM_GOOD) && !get_obj_num_hook) {
82 get_obj_num_hook = kind_is_good;
88 k_idx = get_obj_num(owner_ptr, base, mode);
89 if (get_obj_num_hook) {
90 get_obj_num_hook = NULL;
97 object_prep(j_ptr, k_idx);
100 apply_magic(owner_ptr, j_ptr, floor_ptr->object_level, mode);
101 switch (j_ptr->tval) {
107 j_ptr->number = (byte)damroll(6, 7);
112 object_mention(owner_ptr, j_ptr);
118 * @brief 生成階に応じた財宝オブジェクトの生成を行う。
119 * Make a treasure object
120 * @param floor_ptr 現在フロアへの参照ポインタ
121 * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
122 * @return 生成に成功したらTRUEを返す。
124 * The location must be a legal, clean, floor grid.
126 bool make_gold(floor_type *floor_ptr, object_type *j_ptr)
128 int i = ((randint1(floor_ptr->object_level + 2) + 2) / 2) - 1;
129 if (one_in_(GREAT_OBJ)) {
130 i += randint1(floor_ptr->object_level + 1);
137 object_prep(j_ptr, OBJ_GOLD_LIST + i);
139 s32b base = k_info[OBJ_GOLD_LIST + i].cost;
140 j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
146 * @brief フロア中のアイテムを全て削除する / Deletes all objects at given location
147 * Delete a dungeon object
148 * @param player_ptr プレーヤーへの参照ポインタ
149 * @param y 削除したフロアマスのY座標
150 * @param x 削除したフロアマスのX座標
153 void delete_all_items_from_floor(player_type *player_ptr, POSITION y, POSITION x)
156 OBJECT_IDX this_o_idx, next_o_idx = 0;
157 floor_type *floor_ptr = player_ptr->current_floor_ptr;
158 if (!in_bounds(floor_ptr, y, x))
161 g_ptr = &floor_ptr->grid_array[y][x];
162 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
164 o_ptr = &floor_ptr->o_list[this_o_idx];
165 next_o_idx = o_ptr->next_o_idx;
171 lite_spot(player_ptr, y, x);
175 * @brief 床上のアイテムの数を増やす /
176 * Increase the "number" of an item on the floor
177 * @param floo_ptr 現在フロアへの参照ポインタ
178 * @param item 増やしたいアイテムの所持スロット
179 * @param num 増やしたいアイテムの数
182 void floor_item_increase(floor_type *floor_ptr, INVENTORY_IDX item, ITEM_NUMBER num)
184 object_type *o_ptr = &floor_ptr->o_list[item];
185 num += o_ptr->number;
191 num -= o_ptr->number;
192 o_ptr->number += num;
196 * @brief 床上の数の無くなったアイテムスロットを消去する /
197 * Optimize an item on the floor (destroy "empty" items)
198 * @param player_ptr プレーヤーへの参照ポインタ
199 * @param item 消去したいアイテムの所持スロット
202 void floor_item_optimize(player_type *owner_ptr, INVENTORY_IDX item)
204 object_type *o_ptr = &owner_ptr->current_floor_ptr->o_list[item];
210 delete_object_idx(owner_ptr, item);
214 * @brief オブジェクトを削除する /
215 * Delete a dungeon object
216 * @param player_ptr プレーヤーへの参照ポインタ
217 * @param o_idx 削除対象のオブジェクト構造体ポインタ
220 * Handle "stacks" of objects correctly.
222 void delete_object_idx(player_type *player_ptr, OBJECT_IDX o_idx)
225 floor_type *floor_ptr = player_ptr->current_floor_ptr;
226 excise_object_idx(floor_ptr, o_idx);
227 j_ptr = &floor_ptr->o_list[o_idx];
228 if (!OBJECT_IS_HELD_MONSTER(j_ptr)) {
232 lite_spot(player_ptr, y, x);
240 * @brief 床上、モンスター所持でスタックされたアイテムを削除しスタックを補完する / Excise a dungeon object from any stacks
241 * @param floo_ptr 現在フロアへの参照ポインタ
242 * @param o_idx 削除対象のオブジェクト構造体ポインタ
245 void excise_object_idx(floor_type *floor_ptr, OBJECT_IDX o_idx)
247 OBJECT_IDX this_o_idx, next_o_idx = 0;
248 OBJECT_IDX prev_o_idx = 0;
250 j_ptr = &floor_ptr->o_list[o_idx];
252 if (OBJECT_IS_HELD_MONSTER(j_ptr)) {
254 m_ptr = &floor_ptr->m_list[j_ptr->held_m_idx];
255 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx) {
257 o_ptr = &floor_ptr->o_list[this_o_idx];
258 next_o_idx = o_ptr->next_o_idx;
259 if (this_o_idx != o_idx) {
260 prev_o_idx = this_o_idx;
264 if (prev_o_idx == 0) {
265 m_ptr->hold_o_idx = next_o_idx;
268 k_ptr = &floor_ptr->o_list[prev_o_idx];
269 k_ptr->next_o_idx = next_o_idx;
272 o_ptr->next_o_idx = 0;
280 POSITION y = j_ptr->iy;
281 POSITION x = j_ptr->ix;
282 g_ptr = &floor_ptr->grid_array[y][x];
283 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
285 o_ptr = &floor_ptr->o_list[this_o_idx];
286 next_o_idx = o_ptr->next_o_idx;
287 if (this_o_idx != o_idx) {
288 prev_o_idx = this_o_idx;
292 if (prev_o_idx == 0) {
293 g_ptr->o_idx = next_o_idx;
296 k_ptr = &floor_ptr->o_list[prev_o_idx];
297 k_ptr->next_o_idx = next_o_idx;
300 o_ptr->next_o_idx = 0;
306 * @brief 生成済のオブジェクトをフロアの所定の位置に落とす。
307 * Let an object fall to the ground at or near a location.
308 * @param owner_ptr プレーヤーへの参照ポインタ
309 * @param j_ptr 落としたいオブジェクト構造体の参照ポインタ
310 * @param chance ドロップの消滅率(%)
311 * @param y 配置したいフロアのY座標
312 * @param x 配置したいフロアのX座標
313 * @return 生成に成功したらオブジェクトのIDを返す。
315 * The initial location is assumed to be "in_bounds(floor_ptr, )".\n
317 * This function takes a parameter "chance". This is the percentage\n
318 * chance that the item will "disappear" instead of drop. If the object\n
319 * has been thrown, then this is the chance of disappearance on contact.\n
321 * Hack -- this function uses "chance" to determine if it should produce\n
322 * some form of "description" of the drop event (under the player).\n
324 * We check several locations to see if we can find a location at which\n
325 * the object can combine, stack, or be placed. Artifacts will try very\n
326 * hard to be placed, including "teleporting" to a useful grid if needed.\n
328 OBJECT_IDX drop_near(player_type *owner_ptr, object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION x)
333 OBJECT_IDX o_idx = 0;
334 OBJECT_IDX this_o_idx, next_o_idx = 0;
336 GAME_TEXT o_name[MAX_NLEN];
341 bool plural = (j_ptr->number != 1);
343 object_desc(owner_ptr, o_name, j_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
344 if (!object_is_artifact(j_ptr) && (randint0(100) < chance)) {
346 msg_format("%sは消えた。", o_name);
348 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
350 if (current_world_ptr->wizard)
351 msg_print(_("(破損)", "(breakage)"));
361 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
362 for (dy = -3; dy <= 3; dy++) {
363 for (dx = -3; dx <= 3; dx++) {
365 d = (dy * dy) + (dx * dx);
371 if (!in_bounds(floor_ptr, ty, tx))
373 if (!projectable(owner_ptr, y, x, ty, tx))
376 g_ptr = &floor_ptr->grid_array[ty][tx];
377 if (!cave_drop_bold(floor_ptr, ty, tx))
381 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
383 o_ptr = &floor_ptr->o_list[this_o_idx];
384 next_o_idx = o_ptr->next_o_idx;
385 if (object_similar(o_ptr, j_ptr))
396 s = 1000 - (d + k * 5);
403 if ((++bn >= 2) && !one_in_(bn))
414 if (!flag && !object_is_artifact(j_ptr)) {
416 msg_format("%sは消えた。", o_name);
418 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
420 if (current_world_ptr->wizard)
421 msg_print(_("(床スペースがない)", "(no floor space)"));
426 for (i = 0; !flag && (i < 1000); i++) {
427 ty = rand_spread(by, 1);
428 tx = rand_spread(bx, 1);
430 if (!in_bounds(floor_ptr, ty, tx))
436 if (!cave_drop_bold(floor_ptr, by, bx))
443 int candidates = 0, pick;
444 for (ty = 1; ty < floor_ptr->height - 1; ty++) {
445 for (tx = 1; tx < floor_ptr->width - 1; tx++) {
446 if (cave_drop_bold(floor_ptr, ty, tx))
453 msg_format("%sは消えた。", o_name);
455 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
458 if (current_world_ptr->wizard)
459 msg_print(_("(床スペースがない)", "(no floor space)"));
462 if (object_is_fixed_artifact(j_ptr) && !object_is_known(j_ptr)) {
463 a_info[j_ptr->name1].cur_num = 0;
470 pick = randint1(candidates);
471 for (ty = 1; ty < floor_ptr->height - 1; ty++) {
472 for (tx = 1; tx < floor_ptr->width - 1; tx++) {
473 if (cave_drop_bold(floor_ptr, ty, tx)) {
488 g_ptr = &floor_ptr->grid_array[by][bx];
489 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
491 o_ptr = &floor_ptr->o_list[this_o_idx];
492 next_o_idx = o_ptr->next_o_idx;
493 if (object_similar(o_ptr, j_ptr)) {
494 object_absorb(o_ptr, j_ptr);
501 o_idx = o_pop(floor_ptr);
503 if (!done && !o_idx) {
505 msg_format("%sは消えた。", o_name);
507 msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
509 if (current_world_ptr->wizard)
510 msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
512 if (object_is_fixed_artifact(j_ptr)) {
513 a_info[j_ptr->name1].cur_num = 0;
520 object_copy(&floor_ptr->o_list[o_idx], j_ptr);
521 j_ptr = &floor_ptr->o_list[o_idx];
524 j_ptr->held_m_idx = 0;
525 j_ptr->next_o_idx = g_ptr->o_idx;
527 g_ptr->o_idx = o_idx;
531 note_spot(owner_ptr, by, bx);
532 lite_spot(owner_ptr, by, bx);
535 if (chance && player_bold(owner_ptr, by, bx)) {
536 msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
543 * @brief 床上の魔道具の残り残量メッセージを表示する /
544 * Describe the charges on an item on the floor.
545 * @param floo_ptr 現在フロアへの参照ポインタ
546 * @param item メッセージの対象にしたいアイテム所持スロット
549 void floor_item_charges(floor_type *floor_ptr, INVENTORY_IDX item)
551 object_type *o_ptr = &floor_ptr->o_list[item];
552 if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND))
554 if (!object_is_known(o_ptr))
558 if (o_ptr->pval <= 0) {
559 msg_print("この床上のアイテムは、もう魔力が残っていない。");
561 msg_format("この床上のアイテムは、あと %d 回分の魔力が残っている。", o_ptr->pval);
564 if (o_ptr->pval != 1) {
565 msg_format("There are %d charges remaining.", o_ptr->pval);
567 msg_format("There is %d charge remaining.", o_ptr->pval);