OSDN Git Service

Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband
[hengband/hengband.git] / src / object-enchant / object-ego.c
1 /*!
2  * @brief エゴアイテムに関する処理
3  * @date 2019/05/02
4  * @author deskull
5  * @details Ego-Item indexes (see "lib/edit/e_info.txt")
6  */
7 #include "object-enchant/object-ego.h"
8
9 /*
10  * The ego-item arrays
11  */
12 ego_item_type *e_info;
13 char *e_name;
14 char *e_text;
15
16 /*
17  * Maximum number of ego-items in e_info.txt
18  */
19 EGO_IDX max_e_idx;
20
21 /*!
22  * @brief アイテムのエゴをレア度の重みに合わせてランダムに選択する
23  * Choose random ego type
24  * @param slot 取得したいエゴの装備部位
25  * @param good TRUEならば通常のエゴ、FALSEならば呪いのエゴが選択対象となる。
26  * @return 選択されたエゴ情報のID、万一選択できなかった場合はmax_e_idxが返る。
27  */
28 byte get_random_ego(byte slot, bool good)
29 {
30     long total = 0L;
31     for (int i = 1; i < max_e_idx; i++) {
32         ego_item_type *e_ptr;
33         e_ptr = &e_info[i];
34         if (e_ptr->slot == slot && ((good && e_ptr->rating) || (!good && !e_ptr->rating))) {
35             if (e_ptr->rarity)
36                 total += (255 / e_ptr->rarity);
37         }
38     }
39
40     int value = randint1(total);
41     int j;
42     for (j = 1; j < max_e_idx; j++) {
43         ego_item_type *e_ptr;
44         e_ptr = &e_info[j];
45         if (e_ptr->slot == slot && ((good && e_ptr->rating) || (!good && !e_ptr->rating))) {
46             if (e_ptr->rarity)
47                 value -= (255 / e_ptr->rarity);
48             if (value <= 0L)
49                 break;
50         }
51     }
52
53     return (byte)j;
54 }