OSDN Git Service

[feature] ソースファイルをC++に対応
[hengbandforosx/hengbandosx.git] / src / lore / lore-calculator.c
1 #include "lore/lore-calculator.h"
2 #include "game-option/cheat-options.h"
3 #include "monster-race/monster-race.h"
4 #include "monster-race/race-flags1.h"
5 #include "mspell/mspell-damage-calculator.h"
6
7 /*!
8  * @brief ダイス目を文字列に変換する
9  * @param base_damage 固定値
10  * @param dice_num ダイス数
11  * @param dice_side ダイス面
12  * @param dice_mult ダイス倍率
13  * @param dice_div ダイス除数
14  * @param msg 文字列を格納するポインタ
15  * @return なし
16  */
17 void dice_to_string(int base_damage, int dice_num, int dice_side, int dice_mult, int dice_div, char *msg)
18 {
19     char base[80] = "", dice[80] = "", mult[80] = "";
20
21     if (dice_num == 0) {
22         sprintf(msg, "%d", base_damage);
23         return;
24     }
25
26     if (base_damage != 0)
27         sprintf(base, "%d+", base_damage);
28
29     if (dice_num == 1)
30         sprintf(dice, "d%d", dice_side);
31     else
32         sprintf(dice, "%dd%d", dice_num, dice_side);
33
34     if (dice_mult != 1 || dice_div != 1) {
35         if (dice_div == 1)
36             sprintf(mult, "*%d", dice_mult);
37         else
38             sprintf(mult, "*(%d/%d)", dice_mult, dice_div);
39     }
40
41     sprintf(msg, "%s%s%s", base, dice, mult);
42 }
43
44 /*!
45  * @brief モンスターのAC情報を得ることができるかを返す / Determine if the "armor" is known
46  * @param r_idx モンスターの種族ID
47  * @param know_everything 全知フラグ。TRUEを渡すとTRUEが返る。
48  * @return 敵のACを知る条件が満たされているならTRUEを返す
49  * @details
50  * The higher the level, the fewer kills needed.
51  */
52 bool know_armour(MONRACE_IDX r_idx, const bool know_everything)
53 {
54     monster_race *r_ptr = &r_info[r_idx];
55     DEPTH level = r_ptr->level;
56     MONSTER_NUMBER kills = r_ptr->r_tkills;
57
58     bool known = (r_ptr->r_cast_spell == MAX_UCHAR) ? TRUE : FALSE;
59
60     if (know_everything || known)
61         return TRUE;
62     if (kills > 304 / (4 + level))
63         return TRUE;
64     if (!(r_ptr->flags1 & RF1_UNIQUE))
65         return FALSE;
66     if (kills > 304 / (38 + (5 * level) / 4))
67         return TRUE;
68     return FALSE;
69 }
70
71 /*!
72  * @brief モンスターの打撃威力を知ることができるかどうかを返す
73  * Determine if the "damage" of the given attack is known
74  * @param r_idx モンスターの種族ID
75  * @param i 確認したい攻撃手番
76  * @return 敵のダメージダイスを知る条件が満たされているならTRUEを返す
77  * @details
78  * <pre>
79  * the higher the level of the monster, the fewer the attacks you need,
80  * the more damage an attack does, the more attacks you need
81  * </pre>
82  */
83 bool know_damage(MONRACE_IDX r_idx, int i)
84 {
85     monster_race *r_ptr = &r_info[r_idx];
86     DEPTH level = r_ptr->level;
87     s32b a = r_ptr->r_blows[i];
88
89     s32b d1 = r_ptr->blow[i].d_dice;
90     s32b d2 = r_ptr->blow[i].d_side;
91     s32b d = d1 * d2;
92
93     if (d >= ((4 + level) * MAX_UCHAR) / 80)
94         d = ((4 + level) * MAX_UCHAR - 1) / 80;
95     if ((4 + level) * a > 80 * d)
96         return TRUE;
97     if (!(r_ptr->flags1 & RF1_UNIQUE))
98         return FALSE;
99     if ((4 + level) * (2 * a) > 80 * d)
100         return TRUE;
101
102     return FALSE;
103 }
104
105 /*!
106  * @brief 文字列にモンスターの攻撃力を加える
107  * @param r_idx モンスターの種族ID
108  * @param SPELL_NUM 呪文番号
109  * @param msg 表示する文字列
110  * @return なし
111  */
112 void set_damage(player_type *player_ptr, lore_type *lore_ptr, monster_spell_type ms_type, concptr msg)
113 {
114     MONRACE_IDX r_idx = lore_ptr->r_idx;
115     int base_damage = monspell_race_damage(player_ptr, ms_type, r_idx, BASE_DAM);
116     int dice_num = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_NUM);
117     int dice_side = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_SIDE);
118     int dice_mult = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_MULT);
119     int dice_div = monspell_race_damage(player_ptr, ms_type, r_idx, DICE_DIV);
120     char dmg_str[80], dice_str[sizeof(dmg_str) + 10];
121     char *tmp = lore_ptr->tmp_msg[lore_ptr->vn];
122     dice_to_string(base_damage, dice_num, dice_side, dice_mult, dice_div, dmg_str);
123     sprintf(dice_str, "(%s)", dmg_str);
124
125     if (know_armour(r_idx, lore_ptr->know_everything))
126         sprintf(tmp, msg, dice_str);
127     else
128         sprintf(tmp, msg, "");
129 }
130
131 void set_drop_flags(lore_type *lore_ptr)
132 {
133     if (!lore_ptr->know_everything)
134         return;
135
136     lore_ptr->drop_gold = lore_ptr->drop_item = (((lore_ptr->r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) + ((lore_ptr->r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0)
137         + ((lore_ptr->r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) + ((lore_ptr->r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0)
138         + ((lore_ptr->r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) + ((lore_ptr->r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
139
140     if (lore_ptr->r_ptr->flags1 & RF1_ONLY_GOLD)
141         lore_ptr->drop_item = 0;
142
143     if (lore_ptr->r_ptr->flags1 & RF1_ONLY_ITEM)
144         lore_ptr->drop_gold = 0;
145
146     lore_ptr->flags1 = lore_ptr->r_ptr->flags1;
147     lore_ptr->flags2 = lore_ptr->r_ptr->flags2;
148     lore_ptr->flags3 = lore_ptr->r_ptr->flags3;
149     lore_ptr->flags4 = lore_ptr->r_ptr->flags4;
150     lore_ptr->a_ability_flags1 = lore_ptr->r_ptr->a_ability_flags1;
151     lore_ptr->a_ability_flags2 = lore_ptr->r_ptr->a_ability_flags2;
152     lore_ptr->flagsr = lore_ptr->r_ptr->flagsr;
153 }