/** * @brief Adds an item to a tech. */ int tech_addItem( const char *name, const char *value ) { int id, ret; tech_group_t *tech; /* Get ID. */ id = tech_getID( name ); if (id < 0) { WARN("Trying to add item '%s' to non-existant tech '%s'.", value, name ); return -1; } /* Comfort. */ tech = &tech_groups[id]; /* Try to add the tech. */ ret = tech_addItemGroup( tech, value ); if (ret) ret = tech_addItemOutfit( tech, value ); if (ret) ret = tech_addItemShip( tech, value ); if (ret) ret = tech_addItemCommodity( tech, value ); if (ret) { WARN("Generic item '%s' not found in tech group '%s'", value, name ); return -1; } return 0; }
/** * @brief Adds an item to a tech. */ int tech_addItemTech( tech_group_t *tech, const char *value ) { int ret; /* Try to add the tech. */ ret = tech_addItemGroup( tech, value ); if (ret) ret = tech_addItemOutfit( tech, value ); if (ret) ret = tech_addItemShip( tech, value ); if (ret) ret = tech_addItemCommodity( tech, value ); if (ret) { WARN("Generic item '%s' not found in tech group", value ); return -1; } return 0; }
/** * @brief Parses an XML tech node. */ static int tech_parseNodeData( tech_group_t *tech, xmlNodePtr parent ) { xmlNodePtr node; char *buf, *name; int ret; /* Parse the data. */ node = parent->xmlChildrenNode; do { xml_onlyNodes(node); if (xml_isNode(node,"item")) { /* Must have name. */ name = xml_get( node ); if (name == NULL) { WARN("Tech group '%s' has an item without a value.", tech->name); continue; } /* Try to find hardcoded type. */ buf = xml_nodeProp( node, "type" ); if (buf == NULL) { ret = 1; if (ret) ret = tech_addItemGroup( tech, name ); if (ret) ret = tech_addItemOutfit( tech, name ); if (ret) ret = tech_addItemShip( tech, name ); if (ret) ret = tech_addItemCommodity( tech, name ); if (ret) { WARN("Generic item '%s' not found in tech group '%s'", name, tech->name ); continue; } } else if (strcmp(buf,"group")==0) { if (!tech_addItemGroup( tech, name )) { WARN("Group item '%s' not found in tech group '%s'.", name, tech->name ); continue; } } else if (strcmp(buf,"outfit")==0) { if (!tech_addItemGroup( tech, name )) { WARN("Outfit item '%s' not found in tech group '%s'.", name, tech->name ); continue; } } else if (strcmp(buf,"ship")==0) { if (!tech_addItemGroup( tech, name )) { WARN("Ship item '%s' not found in tech group '%s'.", name, tech->name ); continue; } } else if (strcmp(buf,"commodity")==0) { if (!tech_addItemGroup( tech, name )) { WARN("Commodity item '%s' not found in tech group '%s'.", name, tech->name ); continue; } } continue; } WARN("Tech group '%s' has unknown node '%s'.", tech->name, node->name); } while (xml_nextNode( node )); return 0; }