OSDN Git Service

df8c04b260edd9b12c97d79c34124c98ddf9d89b
[hengbandforosx/hengbandosx.git] / src / inventory / recharge-processor.cpp
1 #include "inventory/recharge-processor.h"
2 #include "core/disturbance.h"
3 #include "core/window-redrawer.h"
4 #include "flavor/flavor-describer.h"
5 #include "flavor/object-flavor-types.h"
6 #include "hpmp/hp-mp-regenerator.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 "system/object-type-definition.h"
12 #include "system/player-type-definition.h"
13 #include "util/quarks.h"
14 #include "util/string-processor.h"
15 #include "view/display-messages.h"
16
17 /*!
18  * @brief
19  * !!を刻んだ魔道具の時間経過による再充填を知らせる処理 /
20  * If player has inscribed the object with "!!", let him know when it's recharged. -LM-
21  * @param o_ptr 対象オブジェクトの構造体参照ポインタ
22  */
23 static void recharged_notice(player_type *owner_ptr, object_type *o_ptr)
24 {
25     if (!o_ptr->inscription)
26         return;
27
28     concptr s = angband_strchr(quark_str(o_ptr->inscription), '!');
29     while (s) {
30         if (s[1] == '!') {
31             GAME_TEXT o_name[MAX_NLEN];
32             describe_flavor(owner_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
33 #ifdef JP
34             msg_format("%sは再充填された。", o_name);
35 #else
36             if (o_ptr->number > 1)
37                 msg_format("Your %s are recharged.", o_name);
38             else
39                 msg_format("Your %s is recharged.", o_name);
40 #endif
41             disturb(owner_ptr, FALSE, FALSE);
42             return;
43         }
44
45         s = angband_strchr(s + 1, '!');
46     }
47 }
48
49 /*!
50  * @brief 10ゲームターンが進行するごとに魔道具の自然充填を行う処理
51  * / Handle recharging objects once every 10 game turns
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_flags |= (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_flags |= (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 }