1 /***************************************************************************
2 bsconf.cpp - description
5 copyright : (C) 2002 by Michael Andreen
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
20 #include <qsettings.h>
22 #include <qtextstream.h>
35 //settings.insertSearchPath(QSettings::Unix);
37 m_sRaceFilename = settings.readEntry("/hbs/ConfFiles/RaceFilename", "/usr/share/hbs/race.conf");
38 m_sStatsFilename = settings.readEntry("/hbs/ConfFiles/StatsFilename", "/usr/share/hbs/stats.conf");
48 /////////////////////////////////////////////////////////////////////
55 /////////////////////////////////////////////////////////////////////
62 /////////////////////////////////////////////////////////////////////
64 bool BSConf::loadStats()
67 QFile f(m_sStatsFilename);
69 if ( f.open(IO_ReadOnly) )
70 { // file opened successfully
71 QTextStream t( &f ); // use a text stream
77 r = t.readLine(); // line of text excluding '\n'
78 race = (const char*) r;
79 s = t.readLine(); // line of text excluding '\n'
80 QTextStream t1(s,IO_ReadOnly );
85 units[race].setName(race);
87 units[race].setRace(temp.toInt());
89 units[race].setUnitClass((const char*) temp);
91 units[race].addTarget((const char*) temp);
93 units[race].addTarget((const char*) temp);
95 units[race].addTarget((const char*) temp);
97 units[race].setInitiative(temp.toInt());
99 units[race].setAgility(temp.toInt());
101 units[race].setWeaponSpeed(temp.toInt());
103 units[race].setGuns(temp.toInt());
105 units[race].setPower(temp.toInt());
107 units[race].setArmor(temp.toInt());
109 units[race].setEMP(temp.toInt());
116 units[race].setResources(tr("metal").latin1(), metal.toInt());
117 units[race].setResources(tr("crystal").latin1(), crystal.toInt());
118 units[race].setResources(tr("eonium").latin1(), eonium.toInt());
119 //units[race].setTotalResources(metal.toInt() + crystal.toInt() + eonium.toInt());
121 units[race].setFuel(temp.toInt());
123 units[race].setETA(temp.toInt());
125 units[race].setType((const char*) temp);
128 Fleet::setUnits(units);
133 /////////////////////////////////////////////////////////////////////
135 bool BSConf::saveStats()
140 /////////////////////////////////////////////////////////////////////
142 bool BSConf::loadRace()
144 QFile f(m_sRaceFilename);
145 std::map<std::string, std::vector<int> > races;
147 if ( f.open(IO_ReadOnly) )
148 { // file opened successfully
149 QTextStream t( &f ); // use a text stream
152 { // until end of file...
153 s = t.readLine(); // line of text excluding '\n'
154 QTextStream t1(s,IO_ReadOnly );
162 races[(const char*)race].push_back(units.toInt());
165 Fleet::setRaces(races);
169 emit configurationChanged();
173 /////////////////////////////////////////////////////////////////////
175 bool BSConf::saveRace()