From ad0f83dcca26add4449264ee8da87d71835ed3e5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 4 May 2018 18:48:14 +0200 Subject: [PATCH] some xmlreader code still required that resources get loaded first. --- src/kernel/item.c | 15 +++++++-------- src/xmlreader.c | 14 ++++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/kernel/item.c b/src/kernel/item.c index 843107737..8afc6a5a9 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -243,17 +243,16 @@ item_type *it_find(const char *zname) } item_type *it_get_or_create(resource_type *rtype) { - item_type * itype; assert(rtype); - itype = it_find(rtype->_name); - if (!itype) { + if (!rtype->itype) { + item_type * itype; itype = (item_type *)calloc(sizeof(item_type), 1); + itype->rtype = rtype; + rtype->uchange = res_changeitem; + rtype->itype = itype; + rtype->flags |= RTF_ITEM; } - itype->rtype = rtype; - rtype->uchange = res_changeitem; - rtype->itype = itype; - rtype->flags |= RTF_ITEM; - return itype; + return rtype->itype; } static void lt_register(luxury_type * ltype) diff --git a/src/xmlreader.c b/src/xmlreader.c index 41b8fef78..48e0717f6 100644 --- a/src/xmlreader.c +++ b/src/xmlreader.c @@ -864,10 +864,12 @@ static void add_items(equipment * eq, xmlNodeSetPtr nsetItems) xmlNodePtr node = nsetItems->nodeTab[i]; xmlChar *propValue; const struct item_type *itype; + struct resource_type *rtype; propValue = xmlGetProp(node, BAD_CAST "name"); assert(propValue != NULL); - itype = it_find((const char *)propValue); + rtype = rt_get_or_create((const char *)propValue); + itype = it_get_or_create(rtype); xmlFree(propValue); if (itype != NULL) { propValue = xmlGetProp(node, BAD_CAST "amount"); @@ -1705,14 +1707,14 @@ 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 */ + xml_register_callback(parse_buildings); + xml_register_callback(parse_ships); #endif xml_register_callback(parse_races); - xml_register_callback(parse_equipment); /* requires resources */ + xml_register_callback(parse_equipment); - xml_register_callback(parse_spells); /* requires resources */ - xml_register_callback(parse_spellbooks); /* requires spells */ + xml_register_callback(parse_spells); + xml_register_callback(parse_spellbooks); xml_register_callback(parse_strings); xml_register_callback(parse_messages);