]> ruin.nu Git - hbs.git/blob - bs/bsconf.cpp
Can now load the stats and race configurations..
[hbs.git] / bs / bsconf.cpp
1 /***************************************************************************
2                           bsconf.cpp  -  description
3                              -------------------
4     begin                : Sat Mar 9 2002
5     copyright            : (C) 2002 by Michael Andreen
6     email                : whale@linux.nu
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
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.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18
19
20 #include <qsettings.h>
21 #include <qfile.h>
22 #include <qtextstream.h>
23
24 #include <iostream>
25 #include <map>
26 #include <vector>
27 using namespace std;
28
29 #include "bsconf.h"
30 #include "fleet.h"
31
32 BSConf::BSConf()
33 {
34         QSettings settings;
35
36         m_sRaceFilename = settings.readEntry("/hbs/RaceFilename", "/usr/share/hbs/race.conf");
37         m_sStatsFilename = settings.readEntry("/hbs/StatsFilename", "/usr/share/hbs/stats.conf");
38         
39         loadRace();
40         loadStats();
41 }
42
43 BSConf::~BSConf()
44 {
45 }
46
47 /////////////////////////////////////////////////////////////////////
48 //
49 bool BSConf::load()
50 {
51         return true;
52 }
53
54 /////////////////////////////////////////////////////////////////////
55 //
56 bool BSConf::save()
57 {
58         return true;
59 }
60
61 /////////////////////////////////////////////////////////////////////
62 //
63 bool BSConf::loadStats()
64 {
65         std::map<std::string, UnitType> units;
66         QFile f(m_sStatsFilename);
67
68         if ( f.open(IO_ReadOnly) )
69     {    // file opened successfully
70         QTextStream t( &f );        // use a text stream
71         QString s;
72                 QString r;
73                 string race;
74                 while ( !t.eof() )
75             {
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 );
80                         t1.skipWhiteSpace();
81                         while ( !t1.eof() )
82                 {
83                                 QString temp;
84                                 units[race].setName(race);
85                                 t1 >> temp;
86                                 units[race].setRace(temp.toInt());
87                                 t1 >> temp;
88                                 units[race].setClass((const char*) temp);
89                                 t1 >> temp;
90                                 units[race].addTarget((const char*) temp);
91                                 t1 >> temp;
92                                 units[race].addTarget((const char*) temp);
93                                 t1 >> temp;
94                                 units[race].addTarget((const char*) temp);
95                                 t1 >> temp;
96                                 units[race].setInitiative(temp.toInt());
97                                 t1 >> temp;
98                                 units[race].setAgility(temp.toInt());
99                                 t1 >> temp;
100                                 units[race].setWeaponSpeed(temp.toInt());
101                                 t1 >> temp;
102                                 units[race].setGuns(temp.toInt());
103                                 t1 >> temp;
104                                 units[race].setPower(temp.toInt());
105                                 t1 >> temp;
106                                 units[race].setArmor(temp.toInt());
107                                 t1 >> temp;
108                                 units[race].setEMP(temp.toInt());
109                                 t1 >> temp;
110                                 units[race].setTotalResources(temp.toInt());
111                                 t1 >> temp;
112                                 units[race].setFuel(temp.toInt());
113                                 t1 >> temp;
114                                 units[race].setETA(temp.toInt());
115                                 t1 >> temp;
116                                 units[race].setType((const char*) temp);
117                 }
118             }
119                 Fleet::setUnits(units);
120         }
121         return true;
122 }
123
124 /////////////////////////////////////////////////////////////////////
125 //
126 bool BSConf::saveStats()
127 {
128         return true;
129 }
130
131 /////////////////////////////////////////////////////////////////////
132 //
133 bool BSConf::loadRace()
134 {
135         QFile f(m_sRaceFilename);
136         std::map<std::string, std::vector<int> > races;
137
138         if ( f.open(IO_ReadOnly) ) 
139         {    // file opened successfully
140                 QTextStream t( &f );        // use a text stream
141                 QString s;
142                 while ( !t.eof() ) 
143                 {        // until end of file...
144                         s = t.readLine();       // line of text excluding '\n'
145                         QTextStream t1(s,IO_ReadOnly );
146                         t1.skipWhiteSpace();
147                         QString race;
148                         t1 >> race;
149                         while ( !t1.eof() )
150                         {
151                                 QString units;
152                                 t1 >> units;
153                                 races[(const char*)race].push_back(units.toInt());
154                         }
155                 }
156                 Fleet::setRaces(races);
157         }
158         else 
159                 return false;
160         emit configurationChanged();
161         return true;
162 }
163
164 /////////////////////////////////////////////////////////////////////
165 //
166 bool BSConf::saveRace()
167 {
168         return true;
169 }
170
171