OSDN Git Service

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