OSDN Git Service

[feature] ソースファイルをC++に対応
[hengbandforosx/hengbandosx.git] / src / info-reader / magic-reader.c
1 #include "info-reader/magic-reader.h"
2 #include "main/angband-headers.h"
3 #include "player/player-class.h"
4 #include "util/string-processor.h"
5
6 /*!
7  * @brief 職業魔法情報(m_info)のパース関数 /
8  * Initialize the "m_info" array, by parsing an ascii "template" file
9  * @param buf テキスト列
10  * @param head ヘッダ構造体
11  * @return エラーコード
12  */
13 errr parse_m_info(char *buf, angband_header *head)
14 {
15     static player_magic *m_ptr = NULL;
16     static int realm, magic_idx = 0, readable = 0;
17
18     if (buf[0] == 'N') {
19         int i = atoi(buf + 2);
20
21         if (i <= error_idx)
22             return 4;
23         if (i >= head->info_num)
24             return 2;
25
26         error_idx = i;
27         m_ptr = &m_info[i];
28     } else if (!m_ptr) {
29         return 3;
30     } else if (buf[0] == 'I') {
31         char *book, *stat;
32         int xtra, type, first, weight;
33         char *s;
34         s = angband_strchr(buf + 2, ':');
35
36         /* Verify that colon */
37         if (!s)
38             return 1;
39
40         /* Nuke the colon, advance to the name */
41         *s++ = '\0';
42
43         book = buf + 2;
44
45         if (streq(book, "SORCERY"))
46             m_ptr->spell_book = TV_SORCERY_BOOK;
47         else if (streq(book, "LIFE"))
48             m_ptr->spell_book = TV_LIFE_BOOK;
49         else if (streq(book, "MUSIC"))
50             m_ptr->spell_book = TV_MUSIC_BOOK;
51         else if (streq(book, "HISSATSU"))
52             m_ptr->spell_book = TV_HISSATSU_BOOK;
53         else if (streq(book, "NONE"))
54             m_ptr->spell_book = TV_NONE;
55         else
56             return 5;
57
58         stat = s;
59         s = angband_strchr(s, ':');
60         if (!s)
61             return 1;
62         *s++ = '\0';
63
64         if (streq(stat, "STR"))
65             m_ptr->spell_stat = A_STR;
66         else if (streq(stat, "INT"))
67             m_ptr->spell_stat = A_INT;
68         else if (streq(stat, "WIS"))
69             m_ptr->spell_stat = A_WIS;
70         else if (streq(stat, "DEX"))
71             m_ptr->spell_stat = A_DEX;
72         else if (streq(stat, "CON"))
73             m_ptr->spell_stat = A_CON;
74         else if (streq(stat, "CHR"))
75             m_ptr->spell_stat = A_CHR;
76         else
77             return 5;
78
79         if (4 != sscanf(s, "%x:%d:%d:%d", (uint *)&xtra, &type, &first, &weight))
80             return 1;
81
82         m_ptr->spell_xtra = xtra;
83         m_ptr->spell_type = type;
84         m_ptr->spell_first = first;
85         m_ptr->spell_weight = weight;
86     } else if (buf[0] == 'R') {
87         if (2 != sscanf(buf + 2, "%d:%d", &realm, &readable))
88             return 1;
89
90         magic_idx = 0;
91     } else if (buf[0] == 'T') {
92         int level, mana, fail, exp;
93
94         if (!readable)
95             return 1;
96         if (4 != sscanf(buf + 2, "%d:%d:%d:%d", &level, &mana, &fail, &exp))
97             return 1;
98
99         m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
100         m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
101         m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
102         m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
103         magic_idx++;
104     } else
105         return 6;
106
107     return 0;
108 }