eliminate terrain parsing from xmlreader.c, it's all in JSON now!

This commit is contained in:
Enno Rehling 2015-09-11 22:46:47 +02:00
parent 23b19d3dfa
commit bd51ac7dd7
1 changed files with 0 additions and 126 deletions

View File

@ -1883,131 +1883,6 @@ static int parse_races(xmlDocPtr doc)
return 0; return 0;
} }
static int parse_terrains(xmlDocPtr doc)
{
xmlXPathContextPtr xpath;
xmlXPathObjectPtr terrains;
xmlNodeSetPtr nodes;
int i;
xpath = xmlXPathNewContext(doc);
/* reading eressea/terrains/terrain */
terrains =
xmlXPathEvalExpression(BAD_CAST "/eressea/terrains/terrain", xpath);
nodes = terrains->nodesetval;
for (i = 0; i != nodes->nodeNr; ++i) {
xmlNodePtr node = nodes->nodeTab[i];
terrain_type *terrain;
xmlChar *propValue;
xmlXPathObjectPtr xpathChildren;
xmlNodeSetPtr children;
propValue = xmlGetProp(node, BAD_CAST "name");
assert(propValue != NULL);
terrain = get_or_create_terrain((const char *)propValue);
xmlFree(propValue);
terrain->max_road = (short)xml_ivalue(node, "road", 0);
assert(terrain->max_road >= 0);
terrain->size = xml_ivalue(node, "size", 0);
if (xml_bvalue(node, "forbidden", false))
terrain->flags |= FORBIDDEN_REGION;
else {
if (xml_bvalue(node, "fly", true))
terrain->flags |= FLY_INTO;
if (xml_bvalue(node, "sail", true))
terrain->flags |= SAIL_INTO;
if (xml_bvalue(node, "walk", true))
terrain->flags |= WALK_INTO;
if (xml_bvalue(node, "swim", false))
terrain->flags |= SWIM_INTO;
if (xml_bvalue(node, "cavalry", false))
terrain->flags |= CAVALRY_REGION;
}
if (xml_bvalue(node, "sea", false))
terrain->flags |= SEA_REGION;
if (xml_bvalue(node, "arctic", false))
terrain->flags |= ARCTIC_REGION;
if (xml_bvalue(node, "land", true))
terrain->flags |= LAND_REGION;
if (xml_bvalue(node, "forest", false))
terrain->flags |= FOREST_REGION;
terrain->distribution = (short)xml_ivalue(node, "seed", 0);
xpath->node = node;
xpathChildren = xmlXPathEvalExpression(BAD_CAST "herb", xpath);
children = xpathChildren->nodesetval;
if (children->nodeNr > 0) {
int k;
terrain->herbs = malloc((children->nodeNr + 1) * sizeof(item_type *));
terrain->herbs[children->nodeNr] = NULL;
for (k = 0; k != children->nodeNr; ++k) {
xmlNodePtr nodeHerb = children->nodeTab[k];
const struct resource_type *rtype;
propValue = xmlGetProp(nodeHerb, BAD_CAST "name");
assert(propValue != NULL);
rtype = rt_find((const char *)propValue);
assert(rtype != NULL && rtype->itype != NULL
&& fval(rtype->itype, ITF_HERB));
terrain->herbs[k] = rtype->itype;
xmlFree(propValue);
}
}
xmlXPathFreeObject(xpathChildren);
xpath->node = node;
xpathChildren = xmlXPathEvalExpression(BAD_CAST "resource", xpath);
children = xpathChildren->nodesetval;
if (children->nodeNr > 0) {
int k;
terrain->production =
malloc((children->nodeNr + 1) * sizeof(terrain_production));
terrain->production[children->nodeNr].type = NULL;
for (k = 0; k != children->nodeNr; ++k) {
xmlNodePtr nodeProd = children->nodeTab[k];
propValue = xmlGetProp(nodeProd, BAD_CAST "name");
assert(propValue != NULL);
terrain->production[k].type = rt_find((const char *)propValue);
assert(terrain->production[k].type);
xmlFree(propValue);
propValue = xmlGetProp(nodeProd, BAD_CAST "level");
assert(propValue);
terrain->production[k].startlevel = _strdup((const char *)propValue);
xmlFree(propValue);
propValue = xmlGetProp(nodeProd, BAD_CAST "base");
assert(propValue);
terrain->production[k].base = _strdup((const char *)propValue);
xmlFree(propValue);
propValue = xmlGetProp(nodeProd, BAD_CAST "div");
assert(propValue);
terrain->production[k].divisor = _strdup((const char *)propValue);
xmlFree(propValue);
terrain->production[k].chance =
(float)xml_fvalue(nodeProd, "chance", 1.0);
}
}
xmlXPathFreeObject(xpathChildren);
}
xmlXPathFreeObject(terrains);
xmlXPathFreeContext(xpath);
init_terrains();
return 0;
}
static int parse_messages(xmlDocPtr doc) static int parse_messages(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath; xmlXPathContextPtr xpath;
@ -2287,7 +2162,6 @@ void register_xmlreader(void)
xml_register_callback(parse_resources); xml_register_callback(parse_resources);
xml_register_callback(parse_rules); xml_register_callback(parse_rules);
xml_register_callback(parse_terrains); /* requires resources */
xml_register_callback(parse_buildings); /* requires resources */ xml_register_callback(parse_buildings); /* requires resources */
xml_register_callback(parse_ships); /* requires terrains */ xml_register_callback(parse_ships); /* requires terrains */
xml_register_callback(parse_spells); /* requires resources */ xml_register_callback(parse_spells); /* requires resources */