* *
***************************************************************************/
+
+
+#include <qsettings.h>
+#include <qfile.h>
+#include <qtextstream.h>
+
+#include <iostream>
+#include <map>
+#include <vector>
+using namespace std;
+
#include "bsconf.h"
+#include "fleet.h"
+
+BSConf::BSConf()
+{
+ QSettings settings;
+
+ m_sRaceFilename = settings.readEntry("/hbs/RaceFilename", "/usr/share/hbs/race.conf");
+ m_sStatsFilename = settings.readEntry("/hbs/StatsFilename", "/usr/share/hbs/stats.conf");
+
+ loadRace();
+ loadStats();
+}
+
+BSConf::~BSConf()
+{
+}
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::load()
+{
+ return true;
+}
-BSConf::BSConf(){
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::save()
+{
+ return true;
}
-BSConf::~BSConf(){
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::loadStats()
+{
+ UnitList units;
+ QFile f(m_sStatsFilename);
+
+ if ( f.open(IO_ReadOnly) )
+ { // file opened successfully
+ QTextStream t( &f ); // use a text stream
+ QString s;
+ QString r;
+ string race;
+ while ( !t.eof() )
+ {
+ r = t.readLine(); // line of text excluding '\n'
+ race = (const char*) r;
+ s = t.readLine(); // line of text excluding '\n'
+ QTextStream t1(s,IO_ReadOnly );
+ t1.skipWhiteSpace();
+ while ( !t1.eof() )
+ {
+ QString temp;
+ units[race].setName(race);
+ t1 >> temp;
+ units[race].setRace(temp.toInt());
+ t1 >> temp;
+ units[race].setUnitClass((const char*) temp);
+ t1 >> temp;
+ units[race].addTarget((const char*) temp);
+ t1 >> temp;
+ units[race].addTarget((const char*) temp);
+ t1 >> temp;
+ units[race].addTarget((const char*) temp);
+ t1 >> temp;
+ units[race].setInitiative(temp.toInt());
+ t1 >> temp;
+ units[race].setAgility(temp.toInt());
+ t1 >> temp;
+ units[race].setWeaponSpeed(temp.toInt());
+ t1 >> temp;
+ units[race].setGuns(temp.toInt());
+ t1 >> temp;
+ units[race].setPower(temp.toInt());
+ t1 >> temp;
+ units[race].setArmor(temp.toInt());
+ t1 >> temp;
+ units[race].setEMP(temp.toInt());
+ QString metal;
+ QString crystal;
+ QString eonium;
+ t1 >> metal;
+ t1 >> crystal;
+ t1 >> eonium;
+ units[race].setTotalResources(metal.toInt() + crystal.toInt() + eonium.toInt());
+ t1 >> temp;
+ units[race].setFuel(temp.toInt());
+ t1 >> temp;
+ units[race].setETA(temp.toInt());
+ t1 >> temp;
+ units[race].setType((const char*) temp);
+ }
+ }
+ Fleet::setUnits(units);
+ }
+ return true;
+}
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::saveStats()
+{
+ return true;
}
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::loadRace()
+{
+ QFile f(m_sRaceFilename);
+ std::map<std::string, std::vector<int> > races;
+
+ if ( f.open(IO_ReadOnly) )
+ { // file opened successfully
+ QTextStream t( &f ); // use a text stream
+ QString s;
+ while ( !t.eof() )
+ { // until end of file...
+ s = t.readLine(); // line of text excluding '\n'
+ QTextStream t1(s,IO_ReadOnly );
+ t1.skipWhiteSpace();
+ QString race;
+ t1 >> race;
+ while ( !t1.eof() )
+ {
+ QString units;
+ t1 >> units;
+ races[(const char*)race].push_back(units.toInt());
+ }
+ }
+ Fleet::setRaces(races);
+ }
+ else
+ return false;
+ emit configurationChanged();
+ return true;
+}
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::saveRace()
+{
+ return true;
+}
+
+