1 #include "birth/birth-select-realm.h"
2 #include "birth/birth-explanations-table.h"
3 #include "birth/birth-util.h"
4 #include "term/term-color-types.h"
6 static const byte REALM_SELECT_CANCEL = 255;
8 typedef struct birth_realm_type {
12 char sym[VALID_REALM];
14 int picks[VALID_REALM];
20 static byte count_realm_selection(s32b choices, int *count)
22 byte auto_select = REALM_NONE;
23 if (choices & CH_LIFE) {
25 auto_select = REALM_LIFE;
28 if (choices & CH_SORCERY) {
30 auto_select = REALM_SORCERY;
33 if (choices & CH_NATURE) {
35 auto_select = REALM_NATURE;
38 if (choices & CH_CHAOS) {
40 auto_select = REALM_CHAOS;
43 if (choices & CH_DEATH) {
45 auto_select = REALM_DEATH;
48 if (choices & CH_TRUMP) {
50 auto_select = REALM_TRUMP;
53 if (choices & CH_ARCANE) {
55 auto_select = REALM_ARCANE;
58 if (choices & CH_ENCHANT) {
60 auto_select = REALM_CRAFT;
63 if (choices & CH_DAEMON) {
65 auto_select = REALM_DAEMON;
68 if (choices & CH_CRUSADE) {
70 auto_select = REALM_CRUSADE;
73 if (choices & CH_MUSIC) {
75 auto_select = REALM_MUSIC;
78 if (choices & CH_HISSATSU) {
80 auto_select = REALM_HISSATSU;
83 if (choices & CH_HEX) {
85 auto_select = REALM_HEX;
91 static birth_realm_type *initialize_birth_realm_type(birth_realm_type *birth_realm_ptr)
93 birth_realm_ptr->cs = 0;
94 birth_realm_ptr->n = 0;
95 birth_realm_ptr->p2 = ')';
96 for (int i = 0; i < VALID_REALM; i++)
97 birth_realm_ptr->picks[i] = 0;
99 birth_realm_ptr->k = -1;
100 return birth_realm_ptr;
103 static void impose_first_realm(player_type *creature_ptr, s32b choices)
105 if (creature_ptr->realm2 == REALM_SELECT_CANCEL)
108 if (creature_ptr->pclass != CLASS_PRIEST)
111 if (is_good_realm(creature_ptr->realm1)) {
112 choices &= ~(CH_DEATH | CH_DAEMON);
114 choices &= ~(CH_LIFE | CH_CRUSADE);
118 static void analyze_realms(player_type *creature_ptr, s32b choices, birth_realm_type *birth_realm_ptr)
120 for (int i = 0; i < 32; i++) {
121 if ((choices & (1L << i)) == 0)
124 if (creature_ptr->realm1 == i + 1) {
125 if (creature_ptr->realm2 == REALM_SELECT_CANCEL)
126 birth_realm_ptr->cs = birth_realm_ptr->n;
131 if (creature_ptr->realm2 == i + 1)
132 birth_realm_ptr->cs = birth_realm_ptr->n;
134 birth_realm_ptr->sym[birth_realm_ptr->n] = I2A(birth_realm_ptr->n);
136 sprintf(birth_realm_ptr->buf, "%c%c %s", birth_realm_ptr->sym[birth_realm_ptr->n], birth_realm_ptr->p2, realm_names[i + 1]);
137 put_str(birth_realm_ptr->buf, 12 + (birth_realm_ptr->n / 5), 2 + 15 * (birth_realm_ptr->n % 5));
138 birth_realm_ptr->picks[birth_realm_ptr->n++] = i + 1;
142 static void move_birth_realm_cursor(birth_realm_type *birth_realm_ptr)
144 if (birth_realm_ptr->cs == birth_realm_ptr->os)
147 c_put_str(TERM_WHITE, birth_realm_ptr->cur, 12 + (birth_realm_ptr->os / 5), 2 + 15 * (birth_realm_ptr->os % 5));
149 if (birth_realm_ptr->cs == birth_realm_ptr->n) {
150 sprintf(birth_realm_ptr->cur, "%c%c %s", '*', birth_realm_ptr->p2, _("ランダム", "Random"));
152 sprintf(birth_realm_ptr->cur, "%c%c %s", birth_realm_ptr->sym[birth_realm_ptr->cs], birth_realm_ptr->p2,
153 realm_names[birth_realm_ptr->picks[birth_realm_ptr->cs]]);
154 sprintf(birth_realm_ptr->buf, "%s", realm_names[birth_realm_ptr->picks[birth_realm_ptr->cs]]);
155 c_put_str(TERM_L_BLUE, birth_realm_ptr->buf, 3, 40);
156 prt(_("の特徴", ": Characteristic"), 3, 40 + strlen(birth_realm_ptr->buf));
157 prt(realm_subinfo[technic2magic(birth_realm_ptr->picks[birth_realm_ptr->cs]) - 1], 4, 40);
160 c_put_str(TERM_YELLOW, birth_realm_ptr->cur, 12 + (birth_realm_ptr->cs / 5), 2 + 15 * (birth_realm_ptr->cs % 5));
161 birth_realm_ptr->os = birth_realm_ptr->cs;
164 static void interpret_realm_select_key(birth_realm_type *birth_realm_ptr, char c)
170 if (birth_realm_ptr->cs >= 5)
171 birth_realm_ptr->cs -= 5;
175 if (birth_realm_ptr->cs > 0)
176 birth_realm_ptr->cs--;
180 if (birth_realm_ptr->cs < birth_realm_ptr->n)
181 birth_realm_ptr->cs++;
185 if ((birth_realm_ptr->cs + 5) <= birth_realm_ptr->n)
186 birth_realm_ptr->cs += 5;
190 static bool get_a_realm(player_type *creature_ptr, birth_realm_type *birth_realm_ptr)
192 birth_realm_ptr->os = birth_realm_ptr->n;
194 move_birth_realm_cursor(birth_realm_ptr);
195 if (birth_realm_ptr->k >= 0)
198 sprintf(birth_realm_ptr->buf, _("領域を選んで下さい(%c-%c) ('='初期オプション設定): ", "Choose a realm (%c-%c) ('=' for options): "),
199 birth_realm_ptr->sym[0], birth_realm_ptr->sym[birth_realm_ptr->n - 1]);
201 put_str(birth_realm_ptr->buf, 10, 10);
203 interpret_realm_select_key(birth_realm_ptr, c);
207 if (c == ' ' || c == '\r' || c == '\n') {
208 if (birth_realm_ptr->cs == birth_realm_ptr->n) {
209 birth_realm_ptr->k = randint0(birth_realm_ptr->n);
212 birth_realm_ptr->k = birth_realm_ptr->cs;
218 birth_realm_ptr->k = randint0(birth_realm_ptr->n);
222 birth_realm_ptr->k = (islower(c) ? A2I(c) : -1);
223 if ((birth_realm_ptr->k >= 0) && (birth_realm_ptr->k < birth_realm_ptr->n)) {
224 birth_realm_ptr->cs = birth_realm_ptr->k;
228 birth_realm_ptr->k = (isupper(c) ? (26 + c - 'A') : -1);
229 if ((birth_realm_ptr->k >= 26) && (birth_realm_ptr->k < birth_realm_ptr->n)) {
230 birth_realm_ptr->cs = birth_realm_ptr->k;
233 birth_realm_ptr->k = -1;
235 birth_help_option(creature_ptr, c, BK_REALM);
242 * @brief プレイヤーの魔法領域を選択する / Choose from one of the available magical realms
243 * @param choices 選択可能な魔法領域のビット配列
244 * @param count 選択可能な魔法領域を返すポインタ群。
245 * @return 選択した魔法領域のID
246 * @details 領域数が0 (戦士等)or 1 (観光客等)なら自動での値を返す
248 static byte select_realm(player_type *creature_ptr, s32b choices, int *count)
250 byte auto_select = count_realm_selection(choices, count);
255 impose_first_realm(creature_ptr, choices);
256 put_str(_("注意:魔法の領域の選択によりあなたが習得する呪文のタイプが決まります。", "Note: The realm of magic will determine which spells you can learn."),
259 birth_realm_type tmp_birth_realm;
260 birth_realm_type *birth_realm_ptr = initialize_birth_realm_type(&tmp_birth_realm);
261 analyze_realms(creature_ptr, choices, birth_realm_ptr);
262 sprintf(birth_realm_ptr->cur, "%c%c %s", '*', birth_realm_ptr->p2, _("ランダム", "Random"));
263 if (get_a_realm(creature_ptr, birth_realm_ptr))
264 return REALM_SELECT_CANCEL;
267 return (byte)(birth_realm_ptr->picks[birth_realm_ptr->k]);
270 static void cleanup_realm_selection_window(void)
279 * @brief 選んだ魔法領域で本当に良いか問い合わせる
280 * @param count 魔法領域の数
281 * @return 選んだ魔法領域で良ければTRUE、再選択ならばFALSE
283 static bool check_realm_selection(player_type *creature_ptr, int count)
286 prt(_("何かキーを押してください", "Hit any key."), 0, 0);
290 } else if (get_check_strict(creature_ptr, _("よろしいですか?", "Are you sure? "), CHECK_DEFAULT_Y))
297 * @brief 選択した魔法領域の解説を表示する / Choose the magical realms
298 * @return ユーザが魔法領域の確定を選んだらTRUEを返す。
300 bool get_player_realms(player_type *creature_ptr)
302 /* Clean up infomation of modifications */
307 /* Select the first realm */
308 creature_ptr->realm1 = REALM_NONE;
309 creature_ptr->realm2 = REALM_SELECT_CANCEL;
313 creature_ptr->realm1 = select_realm(creature_ptr, realm_choices1[creature_ptr->pclass], &count);
315 if (creature_ptr->realm1 == REALM_SELECT_CANCEL)
317 if (!creature_ptr->realm1)
320 cleanup_realm_selection_window();
321 roff_to_buf(realm_explanations[technic2magic(creature_ptr->realm1) - 1], 74, temp, sizeof(temp));
323 for (int i = 0; i < 10; i++) {
332 if (check_realm_selection(creature_ptr, count))
336 /* Select the second realm */
337 creature_ptr->realm2 = REALM_NONE;
338 if (creature_ptr->realm1 == REALM_NONE)
341 /* Print the realm */
342 put_str(_("魔法 :", "Magic :"), 6, 1);
343 c_put_str(TERM_L_BLUE, realm_names[creature_ptr->realm1], 6, 15);
345 /* Select the second realm */
349 creature_ptr->realm2 = select_realm(creature_ptr, realm_choices2[creature_ptr->pclass], &count);
351 if (creature_ptr->realm2 == REALM_SELECT_CANCEL)
353 if (!creature_ptr->realm2)
356 cleanup_realm_selection_window();
357 roff_to_buf(realm_explanations[technic2magic(creature_ptr->realm2) - 1], 74, temp, sizeof(temp));
359 for (int i = 0; i < A_MAX; i++) {
368 if (check_realm_selection(creature_ptr, count))
372 if (creature_ptr->realm2) {
373 /* Print the realm */
374 c_put_str(TERM_L_BLUE, format("%s, %s", realm_names[creature_ptr->realm1], realm_names[creature_ptr->realm2]), 6, 15);