From e4a2b6cb357d2a3f97f07e0b28cf246a947c62da Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 28 Apr 2018 18:47:17 +0200 Subject: [PATCH] loading armor with expat. --- src/exparse.c | 33 +++++++++++++++++++++++++++++++-- src/kernel/item.h | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/exparse.c b/src/exparse.c index 8a45e3fe9..e42b1c81a 100644 --- a/src/exparse.c +++ b/src/exparse.c @@ -66,6 +66,10 @@ static int xml_int(const XML_Char *val) { return atoi((const char *)val); } +static double xml_float(const XML_Char *val) { + return atof((const char *)val); +} + static variant xml_fraction(const XML_Char *val) { int num, den = 100; double fval = atof((const char *)val); @@ -176,6 +180,32 @@ static void handle_item(userdata *ud, const XML_Char *el, const XML_Char **attr) itype->flags = flags; } +static void handle_armor(userdata *ud, const XML_Char *el, const XML_Char **attr) { + const char *flag_names[] = { "shield", "laen", NULL }; + resource_type *rtype = (resource_type *)ud->object; + item_type * itype = rtype->itype; + armor_type *atype = new_armortype(itype, 0.0, frac_zero, 0, 0); + int i, flags = 0; + for (i = 0; attr[i]; i += 2) { + if (xml_strcmp(attr[i], "penalty") == 0) { + atype->penalty = xml_float(attr[i + 1]); + } + else if (xml_strcmp(attr[i], "projectile") == 0) { + atype->projectile = xml_float(attr[i + 1]); + } + else if (xml_strcmp(attr[i], "ac") == 0) { + atype->prot = xml_int(attr[i + 1]); + } + else if (xml_strcmp(attr[i], "magres") == 0) { + atype->magres = xml_fraction(attr[i + 1]); + } + else if (!handle_flag(&flags, attr + i, flag_names)) { + handle_bad_input(ud, el, attr[i]); + } + } + atype->flags = flags; +} + static void handle_weapon(userdata *ud, const XML_Char *el, const XML_Char **attr) { const char *flag_names[] = { "missile", "magical", "pierce", "cut", "bash", "siege", "armorpiercing", "horse", "useshield", NULL }; resource_type *rtype = (resource_type *)ud->object; @@ -254,8 +284,7 @@ static void XMLCALL handle_resources(userdata *ud, const XML_Char *el, const XML /* TODO */ } else if (xml_strcmp(el, "armor") == 0) { - /* TODO */ - rtype->atype = new_armortype(itype, 0.0, frac_zero, 0, 0); + handle_armor(ud, el, attr); } else if (xml_strcmp(el, "weapon") == 0) { handle_weapon(ud, el, attr); diff --git a/src/kernel/item.h b/src/kernel/item.h index 9079369e8..802c483a8 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -159,9 +159,9 @@ extern "C" { const item_type *itype; unsigned int flags; double penalty; + double projectile; /* chance, dass ein projektil abprallt */ variant magres; int prot; - float projectile; /* chance, dass ein projektil abprallt */ } armor_type; #define WTF_NONE 0x00