]> ruin.nu Git - hbs.git/blobdiff - bs/bsconf.cpp
Can now load the stats and race configurations..
[hbs.git] / bs / bsconf.cpp
index 45a2f44c81cb595fcf501cbb611390e587478d17..1ee7da5ca02c4f65ca7d02aa24a6c3d51fd8710b 100644 (file)
  *                                                                         *
  ***************************************************************************/
 
+
+
+#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()
+{
+       std::map<std::string, UnitType> 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].setClass((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());
+                               t1 >> temp;
+                               units[race].setTotalResources(temp.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;
+}
+
+