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());
115 units[race].setTotalResources(metal.toInt() + crystal.toInt() + eonium.toInt());
117 units[race].setFuel(temp.toInt());
119 units[race].setETA(temp.toInt());
121 units[race].setType((const char*) temp);
124 Fleet::setUnits(units);
129 /////////////////////////////////////////////////////////////////////
131 bool BSConf::saveStats()
136 /////////////////////////////////////////////////////////////////////
138 bool BSConf::loadRace()
140 QFile f(m_sRaceFilename);
141 std::map<std::string, std::vector<int> > races;
143 if ( f.open(IO_ReadOnly) )
144 { // file opened successfully
145 QTextStream t( &f ); // use a text stream
148 { // until end of file...
149 s = t.readLine(); // line of text excluding '\n'
150 QTextStream t1(s,IO_ReadOnly );
158 races[(const char*)race].push_back(units.toInt());
161 Fleet::setRaces(races);
165 emit configurationChanged();
169 /////////////////////////////////////////////////////////////////////
171 bool BSConf::saveRace()