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>
36 m_sRaceFilename = settings.readEntry("/hbs/RaceFilename", "/usr/share/hbs/race.conf");
37 m_sStatsFilename = settings.readEntry("/hbs/StatsFilename", "/usr/share/hbs/stats.conf");
47 /////////////////////////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////////
61 /////////////////////////////////////////////////////////////////////
63 bool BSConf::loadStats()
66 QFile f(m_sStatsFilename);
68 if ( f.open(IO_ReadOnly) )
69 { // file opened successfully
70 QTextStream t( &f ); // use a text stream
76 r = t.readLine(); // line of text excluding '\n'
77 race = (const char*) r;
78 s = t.readLine(); // line of text excluding '\n'
79 QTextStream t1(s,IO_ReadOnly );
84 units[race].setName(race);
86 units[race].setRace(temp.toInt());
88 units[race].setUnitClass((const char*) temp);
90 units[race].addTarget((const char*) temp);
92 units[race].addTarget((const char*) temp);
94 units[race].addTarget((const char*) temp);
96 units[race].setInitiative(temp.toInt());
98 units[race].setAgility(temp.toInt());
100 units[race].setWeaponSpeed(temp.toInt());
102 units[race].setGuns(temp.toInt());
104 units[race].setPower(temp.toInt());
106 units[race].setArmor(temp.toInt());
108 units[race].setEMP(temp.toInt());
110 units[race].setTotalResources(temp.toInt());
112 units[race].setFuel(temp.toInt());
114 units[race].setETA(temp.toInt());
116 units[race].setType((const char*) temp);
119 Fleet::setUnits(units);
124 /////////////////////////////////////////////////////////////////////
126 bool BSConf::saveStats()
131 /////////////////////////////////////////////////////////////////////
133 bool BSConf::loadRace()
135 QFile f(m_sRaceFilename);
136 std::map<std::string, std::vector<int> > races;
138 if ( f.open(IO_ReadOnly) )
139 { // file opened successfully
140 QTextStream t( &f ); // use a text stream
143 { // until end of file...
144 s = t.readLine(); // line of text excluding '\n'
145 QTextStream t1(s,IO_ReadOnly );
153 races[(const char*)race].push_back(units.toInt());
156 Fleet::setRaces(races);
160 emit configurationChanged();
164 /////////////////////////////////////////////////////////////////////
166 bool BSConf::saveRace()