OSDN Git Service

Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband
[hengband/hengband.git] / src / birth / history-generator.c
1 #include "birth/history-generator.h"
2 #include "birth/history.h"
3 #include "player/player-race-types.h"
4 #include "util/buffer-shaper.h"
5
6 static int get_history_chart(player_type *creature_ptr)
7 {
8     switch (creature_ptr->prace) {
9     case RACE_AMBERITE:
10         return 67;
11     case RACE_HUMAN:
12     case RACE_BARBARIAN:
13     case RACE_DUNADAN:
14         return 1;
15     case RACE_HALF_ELF:
16         return 4;
17     case RACE_ELF:
18     case RACE_HIGH_ELF:
19         return 7;
20     case RACE_HOBBIT:
21         return 10;
22     case RACE_GNOME:
23         return 13;
24     case RACE_DWARF:
25         return 16;
26     case RACE_HALF_ORC:
27         return 19;
28     case RACE_HALF_TROLL:
29         return 22;
30     case RACE_DARK_ELF:
31         return 69;
32     case RACE_HALF_OGRE:
33         return 74;
34     case RACE_HALF_GIANT:
35         return 75;
36     case RACE_HALF_TITAN:
37         return 76;
38     case RACE_CYCLOPS:
39         return 77;
40     case RACE_YEEK:
41         return 78;
42     case RACE_KOBOLD:
43         return 82;
44     case RACE_KLACKON:
45         return 84;
46     case RACE_NIBELUNG:
47         return 87;
48     case RACE_DRACONIAN:
49         return 89;
50     case RACE_MIND_FLAYER:
51         return 92;
52     case RACE_IMP:
53         return 94;
54     case RACE_GOLEM:
55         return 98;
56     case RACE_SKELETON:
57         return 102;
58     case RACE_ZOMBIE:
59         return 107;
60     case RACE_VAMPIRE:
61         return 113;
62     case RACE_SPECTRE:
63         return 118;
64     case RACE_SPRITE:
65         return 124;
66     case RACE_BEASTMAN:
67         return 129;
68     case RACE_ENT:
69         return 137;
70     case RACE_ARCHON:
71         return 142;
72     case RACE_BALROG:
73         return 145;
74     case RACE_S_FAIRY:
75         return 148;
76     case RACE_KUTAR:
77         return 154;
78     case RACE_ANDROID:
79         return 155;
80     case RACE_MERFOLK:
81         return 170;
82     default:
83         return 0;
84     }
85 }
86
87 /*!
88  * @brief 生い立ちを画面に表示しつつ、種族から社会的地位を決定する
89  * @param creature_ptr プレーヤーへの参照ポインタ
90  * @param buf 生い立ち情報のバッファ
91  * @return なし
92  * @details 画面表示と社会的地位の決定が密結合していて分離できない
93  */
94 static void decide_social_class(player_type *creature_ptr, char *buf)
95 {
96     int social_class = randint1(4);
97     int chart = get_history_chart(creature_ptr);
98     while (chart != 0) {
99         int i = 0;
100         int roll = randint1(100);
101         while ((chart != bg[i].chart) || (roll > bg[i].roll)) {
102             i++;
103         }
104
105         (void)strcat(buf, bg[i].info);
106         social_class += (int)(bg[i].bonus) - 50;
107         chart = bg[i].next;
108     }
109
110     if (social_class > 100)
111         social_class = 100;
112     else if (social_class < 1)
113         social_class = 1;
114
115     creature_ptr->sc = (s16b)social_class;
116 }
117
118 /*!
119  * @brief プレイヤーの生い立ちの自動生成を行う。 / Get the racial history, and social class, using the "history charts".
120  * @return なし
121  */
122 void get_history(player_type *creature_ptr)
123 {
124     for (int i = 0; i < 4; i++)
125         creature_ptr->history[i][0] = '\0';
126
127     char buf[240];
128     buf[0] = '\0';
129     decide_social_class(creature_ptr, buf);
130
131     /* loop */
132     char *s;
133     for (s = buf; *s == ' '; s++)
134         ;
135
136     int n = strlen(s);
137     while ((n > 0) && (s[n - 1] == ' '))
138         s[--n] = '\0';
139
140     {
141         char temp[64 * 4];
142         shape_buffer(s, 60, temp, sizeof(temp));
143         char *t;
144         t = temp;
145         for (int i = 0; i < 4; i++) {
146             if (t[0] == 0)
147                 break;
148             else {
149                 strcpy(creature_ptr->history[i], t);
150                 t += strlen(t) + 1;
151             }
152         }
153     }
154 }