refactor construction list.

This commit is contained in:
Enno Rehling 2018-05-01 10:53:12 +02:00
parent bddf4bff39
commit dddbf5287a

View file

@ -214,15 +214,11 @@ xml_readrequirements(xmlNodePtr * nodeTab, int nodeNr, requirement ** reqArray)
} }
} }
static void static construction *
xml_readconstruction(xmlXPathContextPtr xpath, xmlNodeSetPtr nodeSet, xml_readconstruction(xmlXPathContextPtr xpath, xmlNodePtr node, bool is_building)
construction **consPtr, bool is_building)
{ {
int k;
for (k = 0; k != nodeSet->nodeNr; ++k) {
xmlNodePtr node = nodeSet->nodeTab[k];
xmlChar *propValue;
construction *con; construction *con;
xmlChar *propValue;
xmlXPathObjectPtr req; xmlXPathObjectPtr req;
skill_t sk = NOSKILL; skill_t sk = NOSKILL;
@ -232,15 +228,12 @@ xml_readconstruction(xmlXPathContextPtr xpath, xmlNodeSetPtr nodeSet,
if (sk == NOSKILL) { if (sk == NOSKILL) {
log_error("construction requires skill '%s' that does not exist.\n", (const char *)propValue); log_error("construction requires skill '%s' that does not exist.\n", (const char *)propValue);
xmlFree(propValue); xmlFree(propValue);
continue; return NULL;
} }
xmlFree(propValue); xmlFree(propValue);
} }
assert(*consPtr == NULL); con = (construction *)calloc(sizeof(construction), 1);
*consPtr = con = (construction *)calloc(sizeof(construction), 1);
consPtr = &con->improvement;
con->skill = sk; con->skill = sk;
con->maxsize = xml_ivalue(node, "maxsize", -1); con->maxsize = xml_ivalue(node, "maxsize", -1);
@ -261,6 +254,23 @@ xml_readconstruction(xmlXPathContextPtr xpath, xmlNodeSetPtr nodeSet,
xml_readrequirements(req->nodesetval->nodeTab, xml_readrequirements(req->nodesetval->nodeTab,
req->nodesetval->nodeNr, &con->materials); req->nodesetval->nodeNr, &con->materials);
xmlXPathFreeObject(req); xmlXPathFreeObject(req);
return con;
}
static void
xml_readconstructions(xmlXPathContextPtr xpath, xmlNodeSetPtr nodeSet,
construction **consPtr, bool is_building)
{
int k;
for (k = 0; k != nodeSet->nodeNr; ++k) {
xmlNodePtr node = nodeSet->nodeTab[k];
construction *con = xml_readconstruction(xpath, node, is_building);
if (con) {
*consPtr = con;
consPtr = &con->improvement;
}
} }
} }
@ -339,7 +349,7 @@ static int parse_buildings(xmlDocPtr doc)
/* reading eressea/buildings/building/construction */ /* reading eressea/buildings/building/construction */
xpath->node = node; xpath->node = node;
result = xmlXPathEvalExpression(BAD_CAST "construction", xpath); result = xmlXPathEvalExpression(BAD_CAST "construction", xpath);
xml_readconstruction(xpath, result->nodesetval, &btype->construction, true); xml_readconstructions(xpath, result->nodesetval, &btype->construction, true);
xmlXPathFreeObject(result); xmlXPathFreeObject(result);
/* reading eressea/buildings/building/function */ /* reading eressea/buildings/building/function */
@ -439,7 +449,7 @@ static int parse_ships(xmlDocPtr doc)
/* reading eressea/ships/ship/construction */ /* reading eressea/ships/ship/construction */
xpath->node = node; xpath->node = node;
result = xmlXPathEvalExpression(BAD_CAST "construction", xpath); result = xmlXPathEvalExpression(BAD_CAST "construction", xpath);
xml_readconstruction(xpath, result->nodesetval, &st->construction, false); xml_readconstructions(xpath, result->nodesetval, &st->construction, false);
xmlXPathFreeObject(result); xmlXPathFreeObject(result);
for (child = node->children; child; child = child->next) { for (child = node->children; child; child = child->next) {
@ -685,7 +695,7 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
/* reading item/construction */ /* reading item/construction */
xpath->node = node; xpath->node = node;
result = xmlXPathEvalExpression(BAD_CAST "construction", xpath); result = xmlXPathEvalExpression(BAD_CAST "construction", xpath);
xml_readconstruction(xpath, result->nodesetval, &itype->construction, false); xml_readconstructions(xpath, result->nodesetval, &itype->construction, false);
xmlXPathFreeObject(result); xmlXPathFreeObject(result);
/* reading item/weapon */ /* reading item/weapon */