[wpdev-commits] wolfpack basics.h,1.33,1.34 commands.cpp,1.258,1.259
Brought to you by:
rip,
thiagocorrea
From: Richard M. <dr...@us...> - 2004-08-21 15:37:16
|
Update of /cvsroot/wpdev/wolfpack In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4045 Modified Files: basics.h commands.cpp Log Message: warning fix for basics.h that coding standard stuff for commands.cpp Index: basics.h =================================================================== RCS file: /cvsroot/wpdev/wolfpack/basics.h,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** basics.h 21 Aug 2004 14:18:34 -0000 1.33 --- basics.h 21 Aug 2004 15:37:02 -0000 1.34 *************** *** 267,271 **** unsigned int pos = 0; ! while ( d->bufferpos + size >= buffersize ) { unsigned int bspace = buffersize - d->bufferpos; --- 267,271 ---- unsigned int pos = 0; ! while ( d->bufferpos + size >= ( unsigned int ) buffersize ) { unsigned int bspace = buffersize - d->bufferpos; Index: commands.cpp =================================================================== RCS file: /cvsroot/wpdev/wolfpack/commands.cpp,v retrieving revision 1.258 retrieving revision 1.259 diff -C2 -d -r1.258 -r1.259 *** commands.cpp 21 Aug 2004 14:18:34 -0000 1.258 --- commands.cpp 21 Aug 2004 15:37:02 -0000 1.259 *************** *** 678,688 **** Recursive processing function to get neccesary information about items. */ ! static void processItem(QMap<QCString, QString> &item, const cElement *node) { // If there is an inherit tag, inherit a parent item definition. ! QString inherit = node->getAttribute("inherit"); ! if (inherit != QString::null) { ! const cElement *parent = Definitions::instance()->getDefinition(WPDT_ITEM, inherit); ! if (parent) { ! processItem(item, parent); } } --- 678,691 ---- Recursive processing function to get neccesary information about items. */ ! static void processItem( QMap<QCString, QString> &item, const cElement *node ) ! { // If there is an inherit tag, inherit a parent item definition. ! QString inherit = node->getAttribute( "inherit" ); ! if ( inherit != QString::null ) ! { ! const cElement *parent = Definitions::instance()->getDefinition( WPDT_ITEM, inherit ); ! if ( parent ) ! { ! processItem( item, parent ); } } *************** *** 690,717 **** int count = node->childCount(); int i; ! for (i = 0; i < count; ++i) { ! const cElement *child = node->getChild(i); ! // Inherit properties from another item definition ! if (child->name() == "inherit") { const cElement *parent = 0; ! if (child->hasAttribute("id")) { ! parent = Definitions::instance()->getDefinition(WPDT_ITEM, child->getAttribute("id")); ! } else { ! parent = Definitions::instance()->getDefinition(WPDT_ITEM, child->text()); } ! ! if (parent) { ! processItem(item, parent); } ! } else if (child->name() == "id") { ! item["dispid"] = child->value(); ! } else if (child->name() == "name") { ! item["name"] = child->text(); ! } else if (child->name() == "color") { ! item["color"] = child->value(); ! } else if (child->name() == "category") { ! item["categoryname"] = child->text(); } } --- 693,734 ---- int count = node->childCount(); int i; ! for ( i = 0; i < count; ++i ) ! { ! const cElement *child = node->getChild( i ); ! // Inherit properties from another item definition ! if ( child->name() == "inherit" ) ! { const cElement *parent = 0; ! if ( child->hasAttribute("id") ) ! { ! parent = Definitions::instance()->getDefinition( WPDT_ITEM, child->getAttribute( "id" ) ); } ! else ! { ! parent = Definitions::instance()->getDefinition( WPDT_ITEM, child->text() ); ! } ! ! if ( parent ) ! { ! processItem( item, parent ); } ! } ! else if ( child->name() == "id" ) ! { ! item[ "dispid" ] = child->value(); ! } ! else if ( child->name() == "name" ) ! { ! item[ "name" ] = child->text(); ! } ! else if ( child->name() == "color" ) ! { ! item[ "color" ] = child->value(); ! } ! else if ( child->name() == "category" ) ! { ! item[ "categoryname" ] = child->text(); } } *************** *** 723,733 **** Recursive processing function to get neccesary information about npcs. */ ! static void processNpc(QMap<QCString, QString> &item, const cElement *node, EquipmentContainer &equipment) { // If there is an inherit tag, inherit a parent item definition. ! QString inherit = node->getAttribute("inherit"); ! if (inherit != QString::null) { ! const cElement *parent = Definitions::instance()->getDefinition(WPDT_NPC, inherit); ! if (parent) { ! processNpc(item, parent, equipment); } } --- 740,753 ---- Recursive processing function to get neccesary information about npcs. */ ! static void processNpc( QMap<QCString, QString> &item, const cElement *node, EquipmentContainer &equipment ) ! { // If there is an inherit tag, inherit a parent item definition. ! QString inherit = node->getAttribute( "inherit" ); ! if ( inherit != QString::null ) ! { ! const cElement *parent = Definitions::instance()->getDefinition( WPDT_NPC, inherit ); ! if ( parent ) ! { ! processNpc( item, parent, equipment ); } } *************** *** 735,784 **** int count = node->childCount(); int i; ! for (i = 0; i < count; ++i) { ! const cElement *child = node->getChild(i); ! // Inherit properties from another item definition ! if (child->name() == "inherit") { const cElement *parent = 0; ! if (child->hasAttribute("id")) { ! parent = Definitions::instance()->getDefinition(WPDT_NPC, child->getAttribute("id")); ! } else { ! parent = Definitions::instance()->getDefinition(WPDT_NPC, child->text()); } ! ! if (parent) { ! processNpc(item, parent, equipment); } ! } else if (child->name() == "id") { ! item["bodyid"] = child->value(); ! } else if (child->name() == "skin") { ! item["skin"] = child->value(); ! } else if (child->name() == "category") { ! item["categoryname"] = child->text(); ! } else if (child->name() == "equipped") { int j; ! for (j = 0; j < child->childCount(); ++j) { const cElement *subchild = child->getChild(j); ! if (subchild->name() == "item") { QString id; ! if (subchild->hasAttribute("id")) { ! id = subchild->getAttribute("id"); ! } else if (subchild->hasAttribute("list")) { ! id = Definitions::instance()->getRandomListEntry(subchild->getAttribute("list")); } ! const cElement *itemNode = Definitions::instance()->getDefinition(WPDT_ITEM, id); ! if (itemNode) { QMap<QCString, QString> item; ! processItem(item, itemNode); ! ! unsigned int id = item["dispid"].toInt(); ! tile_st tile = TileCache::instance()->getTile(id); ! if (tile.layer != 0 && tile.layer <= 0x19 && tile.animation != 0) { ! item["anim"] = QString::number(tile.animation); ! equipment.insert(tile.layer, item); } } --- 755,825 ---- int count = node->childCount(); int i; ! for ( i = 0; i < count; ++i ) ! { ! const cElement *child = node->getChild( i ); ! // Inherit properties from another item definition ! if ( child->name() == "inherit" ) ! { const cElement *parent = 0; ! if ( child->hasAttribute( "id" ) ) ! { ! parent = Definitions::instance()->getDefinition( WPDT_NPC, child->getAttribute( "id" ) ); } ! else ! { ! parent = Definitions::instance()->getDefinition( WPDT_NPC, child->text() ); } ! ! if ( parent ) ! { ! processNpc( item, parent, equipment ); ! } ! } ! else if ( child->name() == "id" ) ! { ! item[ "bodyid" ] = child->value(); ! } ! else if ( child->name() == "skin" ) ! { ! item[ "skin" ] = child->value(); ! } ! else if ( child->name() == "category" ) ! { ! item[ "categoryname" ] = child->text(); ! } ! else if ( child->name() == "equipped" ) ! { int j; ! for ( j = 0; j < child->childCount(); ++j ) ! { const cElement *subchild = child->getChild(j); ! if ( subchild->name() == "item" ) ! { QString id; ! if ( subchild->hasAttribute( "id" ) ) ! { ! id = subchild->getAttribute( "id" ); ! } ! else if ( subchild->hasAttribute( "list" ) ) ! { ! id = Definitions::instance()->getRandomListEntry( subchild->getAttribute( "list" ) ); } ! const cElement *itemNode = Definitions::instance()->getDefinition( WPDT_ITEM, id ); ! if ( itemNode ) ! { QMap<QCString, QString> item; ! processItem( item, itemNode ); ! ! unsigned int id = item[ "dispid" ].toInt(); ! tile_st tile = TileCache::instance()->getTile( id ); ! if ( tile.layer != 0 && tile.layer <= 0x19 && tile.animation != 0 ) ! { ! item[ "anim" ] = QString::number( tile.animation ); ! equipment.insert( tile.layer, item ); } } *************** *** 789,801 **** } ! static void ensureCategory(QMap<QString, unsigned int> &categories, unsigned int &lastcategory, QString category) { ! int pos = category.findRev('\\'); ! if (pos != -1) { ! QString parentCategory = category.left(pos); ! ensureCategory(categories, lastcategory, parentCategory); } ! if (!categories.contains(category)) { ! categories.insert(category, ++lastcategory); } } --- 830,845 ---- } ! static void ensureCategory( QMap<QString, unsigned int> &categories, unsigned int &lastcategory, QString category ) ! { ! int pos = category.findRev( '\\' ); ! if ( pos != -1 ) ! { ! QString parentCategory = category.left( pos ); ! ensureCategory( categories, lastcategory, parentCategory ); } ! if ( !categories.contains( category ) ) ! { ! categories.insert( category, ++lastcategory ); } } *************** *** 804,829 **** \command exportdefinitions \description Export the definitions used by the WPGM utility. ! \notes This command will export the definitions used by the WPGM utility to a file called categories.db in your wolfpack directory. */ void commandExportDefinitions( cUOSocket *socket, const QString &command, const QStringList &args) throw() { ! if (QFile::exists("categories.db") && !QFile::remove("categories.db")) { ! socket->sysMessage("Unable to remove existing categories.db."); return; } cSQLiteDriver driver; ! driver.setDatabaseName("categories.db"); ! ! if (!driver.open()) { ! socket->sysMessage("Unable to open categories.db in your wolfpack directory."); return; } ! Console::instance()->log(LOG_MESSAGE, QString("Exporting definitions to %1.\n").arg("categories.db")); ! try { // Create Tables ! driver.exec("CREATE TABLE items (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ --- 848,875 ---- \command exportdefinitions \description Export the definitions used by the WPGM utility. ! \notes This command will export the definitions used by the WPGM utility to a file called categories.db in your wolfpack directory. */ void commandExportDefinitions( cUOSocket *socket, const QString &command, const QStringList &args) throw() { ! if ( QFile::exists( "categories.db" ) && !QFile::remove( "categories.db" ) ) { ! socket->sysMessage( "Unable to remove existing categories.db." ); return; } cSQLiteDriver driver; ! driver.setDatabaseName( "categories.db" ); ! ! if ( !driver.open() ) ! { ! socket->sysMessage( "Unable to open categories.db in your wolfpack directory." ); return; } ! Console::instance()->log( LOG_MESSAGE, QString( "Exporting definitions to %1.\n" ).arg( "categories.db" ) ); ! try ! { // Create Tables ! driver.exec( "CREATE TABLE items (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ *************** *** 832,852 **** color int,\ addid varchar(255)\ ! );"); ! driver.exec("CREATE TABLE categories (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ parent int NOT NULL,\ type int\ ! );"); ! driver.exec("CREATE TABLE locationcategories (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ parent int NOT NULL,\ type int\ ! );"); ! driver.exec("CREATE TABLE locations (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ --- 878,898 ---- color int,\ addid varchar(255)\ ! );" ); ! driver.exec( "CREATE TABLE categories (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ parent int NOT NULL,\ type int\ ! );" ); ! driver.exec( "CREATE TABLE locationcategories (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ parent int NOT NULL,\ type int\ ! );" ); ! driver.exec( "CREATE TABLE locations (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ *************** *** 857,864 **** posmap INT NOT NULL,\ location varchar(255)\ ! );"); ! // Create Tables ! driver.exec("CREATE TABLE npcs (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ --- 903,909 ---- posmap INT NOT NULL,\ location varchar(255)\ ! );" ); ! driver.exec( "CREATE TABLE npcs (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ *************** *** 867,885 **** skin int,\ addid varchar(255)\ ! );"); ! driver.exec("CREATE TABLE npccategories (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ parent int NOT NULL,\ type int\ ! );"); ! driver.exec("CREATE TABLE npcequipment (\ id int NOT NULL,\ artid int NOT NULL,\ layer int NOT NULL,\ color int NOT NULL\ ! );"); unsigned int lastcategory = 0; --- 912,930 ---- skin int,\ addid varchar(255)\ ! );" ); ! driver.exec( "CREATE TABLE npccategories (\ id INTEGER PRIMARY KEY,\ name varchar(255) NULL,\ parent int NOT NULL,\ type int\ ! );" ); ! driver.exec( "CREATE TABLE npcequipment (\ id int NOT NULL,\ artid int NOT NULL,\ layer int NOT NULL,\ color int NOT NULL\ ! );" ); unsigned int lastcategory = 0; *************** *** 895,953 **** item.clear(); ! item.insert("name", QString::null); ! item.insert("color", "0"); ! item.insert("dispid", "0"); ! item.insert("category", "0"); ! item.insert("categoryname", QString::null); ! processItem(item, element); ! QString category = item["categoryname"]; ! if (category.isNull()) { continue; } ! // Strip out the portion after the last slash ! int pos = category.findRev('\\'); ! if (pos != -1) { ! category = category.left(pos); } // Create an id for the category ! if (!categories.contains(category)) { ! ensureCategory(categories, lastcategory, category); ! item["category"] = QString::number(lastcategory); ! } else { ! item["category"] = QString::number(categories[category]); } // See if there has been a custom name definition ! QString categoryname = item["categoryname"]; ! if (pos != -1) { ! item["name"] = categoryname.right(categoryname.length() - (pos + 1)); ! } else { ! item["name"] = categoryname; } // Insert the item into the table. QString section = *sectionIt; ! QString sql = QString("INSERT INTO items VALUES(NULL,'%1',%2,%3,%4,'%5');") ! .arg(item["name"].replace("'", "''")) ! .arg(item["category"]) ! .arg(item["dispid"]) ! .arg(item["color"]) ! .arg(section.replace("'", "''")); ! driver.exec(sql); } // Ensure that all categories are in the list ! for (categoriesIt = categories.begin(); categoriesIt != categories.end(); ++categoriesIt) { unsigned int parent = 0; ! int pos = categoriesIt.key().findRev('\\'); ! if (pos != -1) { ! QString parentName = categoriesIt.key().left(pos); ! if (categories.contains(parentName)) { ! parent = categories[parentName]; } } --- 940,1009 ---- item.clear(); ! item.insert( "name", QString::null ); ! item.insert( "color", "0" ); ! item.insert( "dispid", "0" ); ! item.insert( "category", "0" ); ! item.insert( "categoryname", QString::null ); ! processItem( item, element ); ! QString category = item[ "categoryname" ]; ! if ( category.isNull() ) ! { continue; } ! // Strip out the portion after the last slash ! int pos = category.findRev( '\\' ); ! if ( pos != -1 ) ! { ! category = category.left( pos ); } // Create an id for the category ! if ( !categories.contains( category ) ) ! { ! ensureCategory( categories, lastcategory, category ); ! item[ "category" ] = QString::number( lastcategory ); ! } ! else ! { ! item[ "category" ] = QString::number( categories[ category ] ); } // See if there has been a custom name definition ! QString categoryname = item[ "categoryname" ]; ! if ( pos != -1 ) ! { ! item[ "name" ] = categoryname.right( categoryname.length() - ( pos + 1 ) ); ! } ! else ! { ! item[ "name" ] = categoryname; } // Insert the item into the table. QString section = *sectionIt; ! QString sql = QString( "INSERT INTO items VALUES(NULL,'%1',%2,%3,%4,'%5');" ) ! .arg( item[ "name" ].replace( "'", "''" ) ) ! .arg( item[ "category" ] ) ! .arg( item[ "dispid" ] ) ! .arg( item[ "color" ] ) ! .arg( section.replace( "'", "''" ) ); ! driver.exec( sql ); } // Ensure that all categories are in the list ! for ( categoriesIt = categories.begin(); categoriesIt != categories.end(); ++categoriesIt ) ! { unsigned int parent = 0; ! int pos = categoriesIt.key().findRev( '\\' ); ! if ( pos != -1 ) ! { ! QString parentName = categoriesIt.key().left( pos ); ! if ( categories.contains( parentName ) ) ! { ! parent = categories[ parentName ]; } } *************** *** 956,1031 **** name = name.right(name.length() - (pos + 1)); ! QString sql = QString("INSERT INTO categories VALUES(%1,'%2',%3,0);") ! .arg(categoriesIt.data()) ! .arg(name.replace("'", "''")) ! .arg(parent); ! driver.exec(sql); } categories.clear(); lastcategory = 0; - - sections = Definitions::instance()->getSections(WPDT_LOCATION); - for (sectionIt = sections.begin(); sectionIt != sections.end(); ++sectionIt) { - const cElement *element = Definitions::instance()->getDefinition(WPDT_LOCATION, *sectionIt); ! QString category = element->getAttribute("category"); ! if (category.isNull()) { continue; } - - int pos = category.findRev('\\'); ! if (pos == -1) { continue; } ! QString name = category.right(category.length() - (pos + 1)); ! category = category.left(pos); // Create an id for the category unsigned int categoryId; ! if (!categories.contains(category)) { ! ensureCategory(categories, lastcategory, category); categoryId = lastcategory; ! } else { ! categoryId = categories[category]; } Coord_cl coord; ! parseCoordinates(element->text(), coord); QString id = *sectionIt; ! ! QString sql = QString("INSERT INTO locations VALUES(NULL,'%1',%2,%3,%4,%5,%6,'%7');") ! .arg(name.replace("'", "''")) ! .arg(categoryId) ! .arg(coord.x) ! .arg(coord.y) ! .arg(coord.z) ! .arg(coord.map) ! .arg(id.replace("'", "''")); ! ! driver.exec(sql); } // Ensure that all categories are in the list ! for (categoriesIt = categories.begin(); categoriesIt != categories.end(); ++categoriesIt) { unsigned int parent = 0; ! int pos = categoriesIt.key().findRev('\\'); ! if (pos != -1) { ! QString parentName = categoriesIt.key().left(pos); ! if (categories.contains(parentName)) { ! parent = categories[parentName]; } } QString name = categoriesIt.key(); ! name = name.right(name.length() - (pos + 1)); ! QString sql = QString("INSERT INTO locationcategories VALUES(%1,'%2',%3,0);") ! .arg(categoriesIt.data()) ! .arg(name.replace("'", "''")) ! .arg(parent); ! driver.exec(sql); } --- 1012,1096 ---- name = name.right(name.length() - (pos + 1)); ! QString sql = QString( "INSERT INTO categories VALUES(%1,'%2',%3,0);" ) ! .arg( categoriesIt.data() ) ! .arg( name.replace( "'", "''" ) ) ! .arg( parent ); ! driver.exec( sql ); } categories.clear(); lastcategory = 0; ! sections = Definitions::instance()->getSections( WPDT_LOCATION ); ! for ( sectionIt = sections.begin(); sectionIt != sections.end(); ++sectionIt ) ! { ! const cElement *element = Definitions::instance()->getDefinition( WPDT_LOCATION, *sectionIt ); ! ! QString category = element->getAttribute( "category" ); ! if ( category.isNull() ) ! { continue; } ! int pos = category.findRev( '\\' ); ! ! if ( pos == -1 ) ! { continue; } ! QString name = category.right( category.length() - ( pos + 1 ) ); ! category = category.left( pos ); // Create an id for the category unsigned int categoryId; ! if ( !categories.contains( category ) ) ! { ! ensureCategory( categories, lastcategory, category ); categoryId = lastcategory; ! } ! else ! { ! categoryId = categories[ category ]; } Coord_cl coord; ! parseCoordinates( element->text(), coord ); QString id = *sectionIt; ! ! QString sql = QString( "INSERT INTO locations VALUES(NULL,'%1',%2,%3,%4,%5,%6,'%7');" ) ! .arg( name.replace( "'", "''" ) ) ! .arg( categoryId ) ! .arg( coord.x ) ! .arg( coord.y ) ! .arg( coord.z ) ! .arg( coord.map ) ! .arg( id.replace( "'", "''" ) ); ! ! driver.exec( sql ); } // Ensure that all categories are in the list ! for ( categoriesIt = categories.begin(); categoriesIt != categories.end(); ++categoriesIt ) ! { unsigned int parent = 0; ! int pos = categoriesIt.key().findRev( '\\' ); ! if ( pos != -1 ) ! { ! QString parentName = categoriesIt.key().left( pos ); ! if ( categories.contains( parentName ) ) ! { ! parent = categories[ parentName ]; } } QString name = categoriesIt.key(); ! name = name.right( name.length() - ( pos + 1 ) ); ! QString sql = QString( "INSERT INTO locationcategories VALUES(%1,'%2',%3,0);" ) ! .arg( categoriesIt.data() ) ! .arg( name.replace( "'", "''" ) ) ! .arg( parent ); ! driver.exec( sql ); } *************** *** 1033,1129 **** lastcategory = 0; categories.clear(); ! sections = Definitions::instance()->getSections(WPDT_NPC); EquipmentContainer equipment; ! for (sectionIt = sections.begin(); sectionIt != sections.end(); ++sectionIt) { ! const cElement *element = Definitions::instance()->getDefinition(WPDT_NPC, *sectionIt); equipment.clear(); item.clear(); ! item.insert("name", QString::null); ! item.insert("skin", "0"); ! item.insert("bodyid", "0"); ! item.insert("category", "0"); ! item.insert("categoryname", QString::null); ! processNpc(item, element, equipment); ! QString category = item["categoryname"]; ! if (category.isNull()) { continue; } ! // Strip out the portion after the last slash ! int pos = category.findRev('\\'); ! if (pos != -1) { ! category = category.left(pos); } // Create an id for the category ! if (!categories.contains(category)) { ! ensureCategory(categories, lastcategory, category); ! item["category"] = QString::number(lastcategory); ! } else { ! item["category"] = QString::number(categories[category]); } ! QString categoryname = item["categoryname"]; ! if (pos != -1) { ! item["name"] = categoryname.right(categoryname.length() - (pos + 1)); ! } else { ! item["name"] = categoryname; } // Insert the item into the table. QString section = *sectionIt; ! QString sql = QString("INSERT INTO npcs VALUES(NULL,'%1',%2,%3,%4,'%5');") ! .arg(item["name"].replace("'", "''")) ! .arg(item["category"]) ! .arg(item["bodyid"]) ! .arg(item["skin"]) ! .arg(section.replace("'", "''")); ! driver.exec(sql); int lastInsertId = driver.lastInsertId(); EquipmentContainer::iterator eIt; ! for (eIt = equipment.begin(); eIt != equipment.end(); ++eIt) { ! QString sql = QString("INSERT INTO npcequipment VALUES(%1,%2,%3,%4);") ! .arg(lastInsertId) ! .arg(eIt.data()["anim"].toInt()) ! .arg(eIt.key()) ! .arg(eIt.data()["color"].toInt()); ! driver.exec(sql); } } // Ensure that all categories are in the list ! for (categoriesIt = categories.begin(); categoriesIt != categories.end(); ++categoriesIt) { unsigned int parent = 0; ! int pos = categoriesIt.key().findRev('\\'); ! if (pos != -1) { ! QString parentName = categoriesIt.key().left(pos); ! if (categories.contains(parentName)) { ! parent = categories[parentName]; } } QString name = categoriesIt.key(); ! name = name.right(name.length() - (pos + 1)); ! QString sql = QString("INSERT INTO npccategories VALUES(%1,'%2',%3,0);") ! .arg(categoriesIt.data()) ! .arg(name.replace("'", "''")) ! .arg(parent); ! driver.exec(sql); } ! socket->sysMessage("Finished exporting definitions to categories.db."); ! } catch(const QString &e) { ! socket->sysMessage(e); ! } catch(const wpException &e) { ! socket->sysMessage(e.error()); } --- 1098,1211 ---- lastcategory = 0; categories.clear(); ! sections = Definitions::instance()->getSections( WPDT_NPC ); EquipmentContainer equipment; ! for ( sectionIt = sections.begin(); sectionIt != sections.end(); ++sectionIt ) ! { ! const cElement *element = Definitions::instance()->getDefinition( WPDT_NPC, *sectionIt ); equipment.clear(); item.clear(); ! item.insert( "name", QString::null ); ! item.insert( "skin", "0" ); ! item.insert( "bodyid", "0" ); ! item.insert( "category", "0" ); ! item.insert( "categoryname", QString::null ); ! processNpc( item, element, equipment ); ! QString category = item[ "categoryname" ]; ! if ( category.isNull() ) ! { continue; } ! // Strip out the portion after the last slash ! int pos = category.findRev( '\\' ); ! if ( pos != -1 ) ! { ! category = category.left( pos ); } // Create an id for the category ! if ( !categories.contains( category ) ) ! { ! ensureCategory( categories, lastcategory, category ); ! item[ "category" ] = QString::number( lastcategory ); ! } ! else ! { ! item[ "category" ] = QString::number( categories[ category ] ); } ! QString categoryname = item[ "categoryname" ]; ! if ( pos != -1 ) ! { ! item[ "name" ] = categoryname.right( categoryname.length() - ( pos + 1 ) ); ! } ! else ! { ! item[ "name" ] = categoryname; } // Insert the item into the table. QString section = *sectionIt; ! QString sql = QString( "INSERT INTO npcs VALUES(NULL,'%1',%2,%3,%4,'%5');" ) ! .arg( item[ "name" ].replace( "'", "''" ) ) ! .arg( item[ "category" ] ) ! .arg( item[ "bodyid" ] ) ! .arg( item[ "skin" ] ) ! .arg( section.replace( "'", "''" ) ); ! driver.exec( sql ); int lastInsertId = driver.lastInsertId(); EquipmentContainer::iterator eIt; ! for ( eIt = equipment.begin(); eIt != equipment.end(); ++eIt ) ! { ! QString sql = QString( "INSERT INTO npcequipment VALUES(%1,%2,%3,%4);" ) ! .arg( lastInsertId ) ! .arg( eIt.data()[ "anim" ].toInt() ) ! .arg( eIt.key() ) ! .arg( eIt.data()[ "color" ].toInt() ); ! driver.exec( sql ); } } // Ensure that all categories are in the list ! for ( categoriesIt = categories.begin(); categoriesIt != categories.end(); ++categoriesIt ) ! { unsigned int parent = 0; ! int pos = categoriesIt.key().findRev( '\\' ); ! if ( pos != -1 ) ! { ! QString parentName = categoriesIt.key().left( pos ); ! if ( categories.contains( parentName ) ) ! { ! parent = categories[ parentName ]; } } QString name = categoriesIt.key(); ! name = name.right( name.length() - ( pos + 1 ) ); ! QString sql = QString( "INSERT INTO npccategories VALUES(%1,'%2',%3,0);" ) ! .arg( categoriesIt.data() ) ! .arg( name.replace( "'", "''" ) ) ! .arg( parent ); ! driver.exec( sql ); } ! socket->sysMessage( "Finished exporting definitions to categories.db." ); ! } ! catch( const QString &e ) ! { ! socket->sysMessage( e ); ! } ! catch( const wpException &e ) ! { ! socket->sysMessage( e.error() ); } |