OSDN Git Service

a5c3b71f196cd29f8874d546c14382556dc3a238
[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/tval-types.h"
9 #include "system/baseitem-info.h"
10 #include "system/floor-type-definition.h"
11 #include "system/item-entity.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(PlayerType *player_ptr, ItemEntity *o_ptr)
24 {
25     if (!o_ptr->inscription) {
26         return;
27     }
28
29     concptr s = angband_strchr(quark_str(o_ptr->inscription), '!');
30     while (s) {
31         if (s[1] == '!') {
32             GAME_TEXT o_name[MAX_NLEN];
33             describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
34 #ifdef JP
35             msg_format("%sは再充填された。", o_name);
36 #else
37             if (o_ptr->number > 1) {
38                 msg_format("Your %s are recharged.", o_name);
39             } else {
40                 msg_format("Your %s is recharged.", o_name);
41             }
42 #endif
43             disturb(player_ptr, false, false);
44             return;
45         }
46
47         s = angband_strchr(s + 1, '!');
48     }
49 }
50
51 /*!
52  * @brief 10ゲームターンが進行するごとに魔道具の自然充填を行う処理
53  * / Handle recharging objects once every 10 game turns
54  */
55 void recharge_magic_items(PlayerType *player_ptr)
56 {
57     int i;
58     bool changed;
59
60     for (changed = false, i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
61         auto *o_ptr = &player_ptr->inventory_list[i];
62         if (!o_ptr->bi_id) {
63             continue;
64         }
65
66         if (o_ptr->timeout > 0) {
67             o_ptr->timeout--;
68             if (!o_ptr->timeout) {
69                 recharged_notice(player_ptr, o_ptr);
70                 changed = true;
71             }
72         }
73     }
74
75     if (changed) {
76         player_ptr->window_flags |= (PW_EQUIP);
77         wild_regen = 20;
78     }
79
80     /*
81      * Recharge rods.  Rods now use timeout to control charging status,
82      * and each charging rod in a stack decreases the stack's timeout by
83      * one per turn. -LM-
84      */
85     for (changed = false, i = 0; i < INVEN_PACK; i++) {
86         auto *o_ptr = &player_ptr->inventory_list[i];
87         auto *k_ptr = &baseitems_info[o_ptr->bi_id];
88         if (!o_ptr->bi_id) {
89             continue;
90         }
91
92         if ((o_ptr->bi_key.tval() == ItemKindType::ROD) && (o_ptr->timeout)) {
93             TIME_EFFECT temp = (o_ptr->timeout + (k_ptr->pval - 1)) / k_ptr->pval;
94             if (temp > o_ptr->number) {
95                 temp = (TIME_EFFECT)o_ptr->number;
96             }
97
98             o_ptr->timeout -= temp;
99             if (o_ptr->timeout < 0) {
100                 o_ptr->timeout = 0;
101             }
102
103             if (!(o_ptr->timeout)) {
104                 recharged_notice(player_ptr, o_ptr);
105                 changed = true;
106             } else if (o_ptr->timeout % k_ptr->pval) {
107                 changed = true;
108             }
109         }
110     }
111
112     if (changed) {
113         player_ptr->window_flags |= (PW_INVEN);
114         wild_regen = 20;
115     }
116
117     for (i = 1; i < player_ptr->current_floor_ptr->o_max; i++) {
118         auto *o_ptr = &player_ptr->current_floor_ptr->o_list[i];
119         if (!o_ptr->is_valid()) {
120             continue;
121         }
122
123         if ((o_ptr->bi_key.tval() == ItemKindType::ROD) && (o_ptr->timeout)) {
124             o_ptr->timeout -= (TIME_EFFECT)o_ptr->number;
125             if (o_ptr->timeout < 0) {
126                 o_ptr->timeout = 0;
127             }
128         }
129     }
130 }