OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Fix-saved-floor-exceed' into...
[hengband/hengband.git] / src / inventory / recharge-processor.c
1 #include "inventory/recharge-processor.h"
2 #include "core/disturbance.h"
3 #include "core/hp-mp-regenerator.h"
4 #include "core/window-redrawer.h"
5 #include "flavor/flavor-describer.h"
6 #include "flavor/object-flavor-types.h"
7 #include "inventory/inventory-slot-types.h"
8 #include "object-hook/hook-checker.h"
9 #include "object/object-kind.h"
10 #include "system/floor-type-definition.h"
11 #include "util/quarks.h"
12 #include "util/string-processor.h"
13 #include "view/display-messages.h"
14
15 /*!
16  * @brief
17  * !!を刻んだ魔道具の時間経過による再充填を知らせる処理 /
18  * If player has inscribed the object with "!!", let him know when it's recharged. -LM-
19  * @param o_ptr 対象オブジェクトの構造体参照ポインタ
20  * @return なし
21  */
22 static void recharged_notice(player_type *owner_ptr, object_type *o_ptr)
23 {
24     if (!o_ptr->inscription)
25         return;
26
27     concptr s = angband_strchr(quark_str(o_ptr->inscription), '!');
28     while (s) {
29         if (s[1] == '!') {
30             GAME_TEXT o_name[MAX_NLEN];
31             describe_flavor(owner_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
32 #ifdef JP
33             msg_format("%sは再充填された。", o_name);
34 #else
35             if (o_ptr->number > 1)
36                 msg_format("Your %s are recharged.", o_name);
37             else
38                 msg_format("Your %s is recharged.", o_name);
39 #endif
40             disturb(owner_ptr, FALSE, FALSE);
41             return;
42         }
43
44         s = angband_strchr(s + 1, '!');
45     }
46 }
47
48 /*!
49  * @brief 10ゲームターンが進行するごとに魔道具の自然充填を行う処理
50  * / Handle recharging objects once every 10 game turns
51  * @return なし
52  */
53 void recharge_magic_items(player_type *creature_ptr)
54 {
55     int i;
56     bool changed;
57
58     for (changed = FALSE, i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
59         object_type *o_ptr = &creature_ptr->inventory_list[i];
60         if (!o_ptr->k_idx)
61             continue;
62
63         if (o_ptr->timeout > 0) {
64             o_ptr->timeout--;
65             if (!o_ptr->timeout) {
66                 recharged_notice(creature_ptr, o_ptr);
67                 changed = TRUE;
68             }
69         }
70     }
71
72     if (changed) {
73         creature_ptr->window |= (PW_EQUIP);
74         wild_regen = 20;
75     }
76
77     /*
78      * Recharge rods.  Rods now use timeout to control charging status,
79      * and each charging rod in a stack decreases the stack's timeout by
80      * one per turn. -LM-
81      */
82     for (changed = FALSE, i = 0; i < INVEN_PACK; i++) {
83         object_type *o_ptr = &creature_ptr->inventory_list[i];
84         object_kind *k_ptr = &k_info[o_ptr->k_idx];
85         if (!o_ptr->k_idx)
86             continue;
87
88         if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout)) {
89             TIME_EFFECT temp = (o_ptr->timeout + (k_ptr->pval - 1)) / k_ptr->pval;
90             if (temp > o_ptr->number)
91                 temp = (TIME_EFFECT)o_ptr->number;
92
93             o_ptr->timeout -= temp;
94             if (o_ptr->timeout < 0)
95                 o_ptr->timeout = 0;
96
97             if (!(o_ptr->timeout)) {
98                 recharged_notice(creature_ptr, o_ptr);
99                 changed = TRUE;
100             } else if (o_ptr->timeout % k_ptr->pval) {
101                 changed = TRUE;
102             }
103         }
104     }
105
106     if (changed) {
107         creature_ptr->window |= (PW_INVEN);
108         wild_regen = 20;
109     }
110
111     for (i = 1; i < creature_ptr->current_floor_ptr->o_max; i++) {
112         object_type *o_ptr = &creature_ptr->current_floor_ptr->o_list[i];
113         if (!object_is_valid(o_ptr))
114             continue;
115
116         if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout)) {
117             o_ptr->timeout -= (TIME_EFFECT)o_ptr->number;
118             if (o_ptr->timeout < 0)
119                 o_ptr->timeout = 0;
120         }
121     }
122 }