fix some bugs in reading weapons.

This commit is contained in:
Enno Rehling 2018-05-04 18:41:59 +02:00
parent 4e2171ace9
commit 85509cdf65
4 changed files with 32 additions and 13 deletions

View File

@ -6,8 +6,8 @@
<item weight="200" score="200">
<construction skill="mining" minskill="8"/>
</item>
<modifier building="mine" type="skill" value="1"/>
<modifier type="require" building="mine"/>
<modifier building="mine" type="skill" value="1"/>
<modifier type="require" building="mine"/>
</resource>
<resource name="adamantiumaxe">

View File

@ -2,9 +2,9 @@
<eressea>
<resources>
<resource name="laen" limited="yes" material="yes">
<item weight="200" score="100">
<construction skill="mining" minskill="7"/>
</item>
<item weight="200" score="100">
<construction skill="mining" minskill="7"/>
</item>
<modifier building="mine" type="skill" value="1"/>
<modifier type="require" building="mine"/>
</resource>

View File

@ -277,7 +277,27 @@ static void XMLCALL start_weapon(parseinfo *pi, const XML_Char *el, const XML_Ch
assert(rtype && rtype->wtype);
if (xml_strcmp(el, "function") == 0) {
++pi->errors;
const XML_Char *name = NULL, *type = NULL;
int i;
for (i = 0; attr[i]; i += 2) {
if (xml_strcmp(attr[i], "name") == 0) {
type = attr[i + 1];
}
else if (xml_strcmp(attr[i], "value") == 0) {
name = attr[i + 1];
}
else {
handle_bad_input(pi, el, attr[i]);
}
}
if (type && xml_strcmp(type, "attack") == 0) {
pf_generic fun = get_function(name);
rtype->wtype->attack = (wtype_attack)fun;
}
else {
handle_bad_input(pi, el, attr[i]);
}
}
else if (xml_strcmp(el, "modifier") == 0) {
const XML_Char *type = NULL;
@ -354,7 +374,7 @@ static void XMLCALL start_weapon(parseinfo *pi, const XML_Char *el, const XML_Ch
mod->race_mask = race_mask;
}
else {
++pi->errors;
handle_bad_input(pi, el, NULL);
}
}
else if (xml_strcmp(el, "damage") == 0) {
@ -566,14 +586,14 @@ static void start_resources(parseinfo *pi, const XML_Char *el, const XML_Char **
}
}
}
else if (xml_strcmp(el, "modifier") == 0) {
handle_modifier(pi, el, attr);
}
else if (rtype->itype) {
item_type *itype = rtype->itype;
if (xml_strcmp(el, "construction") == 0) {
itype->construction = parse_construction(pi, el, attr);
}
else if (xml_strcmp(el, "modifier") == 0) {
handle_modifier(pi, el, attr);
}
else if (xml_strcmp(el, "requirement") == 0) {
assert(itype->construction);
handle_requirement(pi, el, attr);
@ -866,9 +886,6 @@ static void end_weapon(parseinfo *pi, const XML_Char *el) {
nwmods = 0;
}
}
else {
handle_bad_input(pi, el, NULL);
}
}
static void end_resources(parseinfo *pi, const XML_Char *el) {

View File

@ -1703,9 +1703,11 @@ static int parse_strings(xmlDocPtr doc)
void register_xmlreader(void)
{
#if 0
xml_register_callback(parse_resources);
xml_register_callback(parse_buildings); /* requires resources */
xml_register_callback(parse_ships); /* requires resources, terrains */
#endif
xml_register_callback(parse_races);
xml_register_callback(parse_equipment); /* requires resources */