bool CConfiger::LoadShopList( const char *file ) { CRFile *prfile = rfOpen( file ); if( prfile == NULL ) { PutoutLog( LOG_FILE, LT_ERROR, "Load file %s failed.", file ); return false; } TiXmlDocument doc; if( !doc.LoadData( prfile->GetData(), prfile->GetDatalen() ) ) { PutoutLog( LOG_FILE, LT_ERROR, "Parse %s failed, invalid xml format.", file ); rfClose( prfile ); return false; } rfClose( prfile ); TiXmlElement *root = doc.RootElement(); { // global config TiXmlElement *node = root->FirstChildElement( "Global" ); QUERY_NUM( "goods_update_interval", m_GlobalCfg.uGoodsUpdateInter, node, unsigned long ); QUERY_NUM( "buy_count", m_GlobalCfg.lBuyCount, node, long ); QUERY_NUM( "enable", m_GlobalCfg.lEnable, node, long ); QUERY_NUM( "player_buy_count", m_GlobalCfg.lPlayerBuyCount, node, long ); char strCoinGoods[64]; QUERY_STR( "coin_goods", strCoinGoods, node ); m_GlobalCfg.lCoinGoodsIndex = CGoodsFactory::QueryGoodsIDByOriginalName( strCoinGoods ); } { // shop list TiXmlElement *shoplist_node = root->FirstChildElement( "ShopList" ); for( TiXmlElement *shop_node = shoplist_node->FirstChildElement(); shop_node != NULL; shop_node = shop_node->NextSiblingElement() ) { long id; QUERY_NUM( "id", id, shop_node, long ); if( m_ShopTable.find( id ) != m_ShopTable.end() ) { // more than 1 shop with the same id, ignore it. PutoutLog( LOG_FILE, LT_WARNING, "More than 1 shop with the same id [%d].", id ); continue; } Shop shop; QUERY_STR( "npc_orig_name", shop.npcOrigName, shop_node ); SellGoodsListT *pSellGoodsList = new SellGoodsListT(); shop.SellList = pSellGoodsList; for( TiXmlElement *goods_node = shop_node->FirstChildElement(); goods_node != NULL; goods_node = goods_node->NextSiblingElement() ) { SellGoods goods; char strOrigName[64]; QUERY_STR( "orig_name", strOrigName, goods_node ); goods.lIndex = CGoodsFactory::QueryGoodsIDByOriginalName( strOrigName ); pSellGoodsList->push_back( goods ); } m_ShopTable.insert( std::make_pair( id, shop ) ); } } return true; }