]> ruin.nu Git - hbs.git/blob - bs/bsconf.cpp
battle algorithms are getting more and more mature and stats.conf is updated.
[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         UnitList 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].setUnitClass((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                                 QString metal;
110                                 QString crystal;
111                                 QString eonium;
112                                 t1 >> metal;
113                                 t1 >> crystal;
114                                 t1 >> eonium;
115                                 units[race].setTotalResources(metal.toInt() + crystal.toInt() + eonium.toInt());
116                                 t1 >> temp;
117                                 units[race].setFuel(temp.toInt());
118                                 t1 >> temp;
119                                 units[race].setETA(temp.toInt());
120                                 t1 >> temp;
121                                 units[race].setType((const char*) temp);
122                 }
123             }
124                 Fleet::setUnits(units);
125         }
126         return true;
127 }
128
129 /////////////////////////////////////////////////////////////////////
130 //
131 bool BSConf::saveStats()
132 {
133         return true;
134 }
135
136 /////////////////////////////////////////////////////////////////////
137 //
138 bool BSConf::loadRace()
139 {
140         QFile f(m_sRaceFilename);
141         std::map<std::string, std::vector<int> > races;
142
143         if ( f.open(IO_ReadOnly) ) 
144         {    // file opened successfully
145                 QTextStream t( &f );        // use a text stream
146                 QString s;
147                 while ( !t.eof() ) 
148                 {        // until end of file...
149                         s = t.readLine();       // line of text excluding '\n'
150                         QTextStream t1(s,IO_ReadOnly );
151                         t1.skipWhiteSpace();
152                         QString race;
153                         t1 >> race;
154                         while ( !t1.eof() )
155                         {
156                                 QString units;
157                                 t1 >> units;
158                                 races[(const char*)race].push_back(units.toInt());
159                         }
160                 }
161                 Fleet::setRaces(races);
162         }
163         else 
164                 return false;
165         emit configurationChanged();
166         return true;
167 }
168
169 /////////////////////////////////////////////////////////////////////
170 //
171 bool BSConf::saveRace()
172 {
173         return true;
174 }
175
176