X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=blobdiff_plain;f=bs%2Fbsconf.cpp;h=1ee7da5ca02c4f65ca7d02aa24a6c3d51fd8710b;hp=45a2f44c81cb595fcf501cbb611390e587478d17;hb=dc90594097a886eee49e9bfe45da6d4f9765179a;hpb=f1e79e13d76a63700e6345503e338afaa93c102d diff --git a/bs/bsconf.cpp b/bs/bsconf.cpp index 45a2f44..1ee7da5 100644 --- a/bs/bsconf.cpp +++ b/bs/bsconf.cpp @@ -15,9 +15,157 @@ * * ***************************************************************************/ + + +#include +#include +#include + +#include +#include +#include +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 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 > 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; +} + +