forked from github/server
loading armor with expat.
This commit is contained in:
parent
16cebed013
commit
e4a2b6cb35
2 changed files with 32 additions and 3 deletions
|
@ -66,6 +66,10 @@ static int xml_int(const XML_Char *val) {
|
||||||
return atoi((const 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) {
|
static variant xml_fraction(const XML_Char *val) {
|
||||||
int num, den = 100;
|
int num, den = 100;
|
||||||
double fval = atof((const char *)val);
|
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;
|
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) {
|
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 };
|
const char *flag_names[] = { "missile", "magical", "pierce", "cut", "bash", "siege", "armorpiercing", "horse", "useshield", NULL };
|
||||||
resource_type *rtype = (resource_type *)ud->object;
|
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 */
|
/* TODO */
|
||||||
}
|
}
|
||||||
else if (xml_strcmp(el, "armor") == 0) {
|
else if (xml_strcmp(el, "armor") == 0) {
|
||||||
/* TODO */
|
handle_armor(ud, el, attr);
|
||||||
rtype->atype = new_armortype(itype, 0.0, frac_zero, 0, 0);
|
|
||||||
}
|
}
|
||||||
else if (xml_strcmp(el, "weapon") == 0) {
|
else if (xml_strcmp(el, "weapon") == 0) {
|
||||||
handle_weapon(ud, el, attr);
|
handle_weapon(ud, el, attr);
|
||||||
|
|
|
@ -159,9 +159,9 @@ extern "C" {
|
||||||
const item_type *itype;
|
const item_type *itype;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
double penalty;
|
double penalty;
|
||||||
|
double projectile; /* chance, dass ein projektil abprallt */
|
||||||
variant magres;
|
variant magres;
|
||||||
int prot;
|
int prot;
|
||||||
float projectile; /* chance, dass ein projektil abprallt */
|
|
||||||
} armor_type;
|
} armor_type;
|
||||||
|
|
||||||
#define WTF_NONE 0x00
|
#define WTF_NONE 0x00
|
||||||
|
|
Loading…
Reference in a new issue