* *
***************************************************************************/
+
+
+#include <qsettings.h>
+#include <qfile.h>
+#include <qtextstream.h>
+
+#include <iostream>
+#include <map>
+#include <vector>
+using namespace std;
+
#include "bsconf.h"
+#include "fleet.h"
+
+BSConf::BSConf()
+{
+ QSettings settings;
+
+ m_sRaceFilename = settings.readEntry("/hbs/RaceFilename", "/usr/share/hbs/race.conf");
+ m_sStatsFilename = settings.readEntry("/hbs/StatsFilename", "/usr/share/hbs/stats.conf");
+
+ loadRace();
+ loadStats();
+}
+
+BSConf::~BSConf()
+{
+}
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::load()
+{
+ return true;
+}
-BSConf::BSConf(){
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::save()
+{
+ return true;
}
-BSConf::~BSConf(){
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::loadStats()
+{
+ std::map<std::string, UnitType> units;
+ QFile f(m_sStatsFilename);
+
+ if ( f.open(IO_ReadOnly) )
+ { // file opened successfully
+ QTextStream t( &f ); // use a text stream
+ QString s;
+ QString r;
+ string race;
+ while ( !t.eof() )
+ {
+ r = t.readLine(); // line of text excluding '\n'
+ race = (const char*) r;
+ s = t.readLine(); // line of text excluding '\n'
+ QTextStream t1(s,IO_ReadOnly );
+ t1.skipWhiteSpace();
+ while ( !t1.eof() )
+ {
+ QString temp;
+ units[race].setName(race);
+ t1 >> temp;
+ units[race].setRace(temp.toInt());
+ t1 >> temp;
+ units[race].setClass((const char*) temp);
+ t1 >> temp;
+ units[race].addTarget((const char*) temp);
+ t1 >> temp;
+ units[race].addTarget((const char*) temp);
+ t1 >> temp;
+ units[race].addTarget((const char*) temp);
+ t1 >> temp;
+ units[race].setInitiative(temp.toInt());
+ t1 >> temp;
+ units[race].setAgility(temp.toInt());
+ t1 >> temp;
+ units[race].setWeaponSpeed(temp.toInt());
+ t1 >> temp;
+ units[race].setGuns(temp.toInt());
+ t1 >> temp;
+ units[race].setPower(temp.toInt());
+ t1 >> temp;
+ units[race].setArmor(temp.toInt());
+ t1 >> temp;
+ units[race].setEMP(temp.toInt());
+ t1 >> temp;
+ units[race].setTotalResources(temp.toInt());
+ t1 >> temp;
+ units[race].setFuel(temp.toInt());
+ t1 >> temp;
+ units[race].setETA(temp.toInt());
+ t1 >> temp;
+ units[race].setType((const char*) temp);
+ }
+ }
+ Fleet::setUnits(units);
+ }
+ return true;
+}
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::saveStats()
+{
+ return true;
}
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::loadRace()
+{
+ QFile f(m_sRaceFilename);
+ std::map<std::string, std::vector<int> > races;
+
+ if ( f.open(IO_ReadOnly) )
+ { // file opened successfully
+ QTextStream t( &f ); // use a text stream
+ QString s;
+ while ( !t.eof() )
+ { // until end of file...
+ s = t.readLine(); // line of text excluding '\n'
+ QTextStream t1(s,IO_ReadOnly );
+ t1.skipWhiteSpace();
+ QString race;
+ t1 >> race;
+ while ( !t1.eof() )
+ {
+ QString units;
+ t1 >> units;
+ races[(const char*)race].push_back(units.toInt());
+ }
+ }
+ Fleet::setRaces(races);
+ }
+ else
+ return false;
+ emit configurationChanged();
+ return true;
+}
+
+/////////////////////////////////////////////////////////////////////
+//
+bool BSConf::saveRace()
+{
+ return true;
+}
+
+
#define BSCONF_H
#include <qobject.h>
+#include <qstring.h>
/**
*@author Michael Andreen
class BSConf : public QObject
{
- Q_Object
-public:
+ Q_OBJECT
+
+ public:
BSConf();
~BSConf();
+
+ bool load();
+ bool save();
+
+signals:
+ void configurationChanged();
+
+protected:
+ bool m_modified;
+ QString m_sRaceFilename;
+ QString m_sStatsFilename;
+
+ bool loadStats();
+ bool saveStats();
+ bool loadRace();
+ bool saveRace();
};
#endif
Q_OBJECT
public:
- BSDoc();
+ BSDoc();
~BSDoc();
void newDoc();
bool save();
#include "scanview.h"
#include "ui/infoview.h"
#include "tickview.h"
-#include "ui/fleetviewbase.h"
+#include "fleetview.h"
#include "fleet.h"
BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent)
//the widget stack
m_BattleSum = new BattleSum();
m_FleetViews->addWidget(m_BattleSum, 0);
- m_FleetView = new FleetViewBase();
+ m_FleetView = new FleetView();
m_FleetViews->addWidget(m_FleetView, 1);
//m_FleetViews->raiseWidget(0);
}
else if (lvi->parent()->parent() == '\0')
{
- m_FleetView->slotHomePlanet(false);
+// m_FleetView->slotHomePlanet(false);
if (lvi->text(0) == tr("Friendly"))
{
- m_FleetView->slotAttacker(false);
+// m_FleetView->slotAttacker(false);
}
else
{
- m_FleetView->slotAttacker(true);
+// m_FleetView->slotAttacker(true);
}
m_FleetViews->raiseWidget(1);
{
if (lvi->parent()->text(0) == tr("Friendly"))
{
- m_FleetView->slotAttacker(false);
- m_FleetView->slotHomePlanet(false);
+// m_FleetView->slotAttacker(false);
+// m_FleetView->slotHomePlanet(false);
if (lvi->text(0) == tr("Home Planet"))
{
- m_FleetView->slotHomePlanet(true);
+// m_FleetView->slotHomePlanet(true);
}
}
else
{
- m_FleetView->slotAttacker(true);
- m_FleetView->slotHomePlanet(false);
+// m_FleetView->slotAttacker(true);
+// m_FleetView->slotHomePlanet(false);
}
m_FleetViews->raiseWidget(1);
class ScanView;
class InfoView;
class TickView;
-class FleetViewBase;
+class FleetView;
//QT forward declarations
class QListView;
InfoView *m_InfoView;
TickView *m_TickView;
QWidgetStack *m_FleetViews;
- FleetViewBase *m_FleetView;
+ FleetView *m_FleetView;
BSDoc *m_doc;
public slots: // Public slots
#include "fleet.h"
+#include <iostream>
using namespace std;
//Static variables
Fleet::Fleet()
{
m_iETA = 0;
+ m_sRace = "Generic";
}
Fleet::~Fleet(){
}
return m_iETA;
}
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::setRaces(std::map<std::string, std::vector<int> >& races)
+{
+ s_Races = races;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::setUnits(map<std::string, UnitType>& units)
+{
+ s_Units = units;
+
+ for (map<string, UnitType >::iterator i = s_Units.begin(); i != s_Units.end(); i++)
+ {
+ cerr << s_Units[(*i).first].Name() << "\t"
+ << s_Units[(*i).first].Race() <<"\t"
+ << s_Units[(*i).first].Class() << "\t"
+ << s_Units[(*i).first].Target(0) << "\t"
+ << s_Units[(*i).first].Target(1) << "\t"
+ << s_Units[(*i).first].Target(2) << "\t"
+ << s_Units[(*i).first].Initiative() << "\t"
+ << s_Units[(*i).first].Agility() << "\t"
+ << s_Units[(*i).first].WeaponSpeed() << "\t"
+ << s_Units[(*i).first].Guns() << "\t"
+ << s_Units[(*i).first].Power() << "\t"
+ << s_Units[(*i).first].Armor() << "\t"
+ << s_Units[(*i).first].EMP() << "\t"
+ << s_Units[(*i).first].TotRes() << "\t"
+ << s_Units[(*i).first].Fuel() << "\t"
+ << s_Units[(*i).first].ETA() << "\t"
+ << s_Units[(*i).first].Type() << endl;
+ }
+}
*/
int ETA();
+ static void setRaces(std::map<std::string, std::vector<int> >& races);
+ static void setUnits(std::map<std::string, UnitType>& units);
protected:
std::string m_sName;
</connection>
</connections>
<includes>
- <include location="local" impldecl="in implementation">../bsdoc.h</include>
- <include location="local" impldecl="in implementation">../bsview.h</include>
+ <include location="local" impldecl="in implementation">../bsconf.h</include>
<include location="global" impldecl="in implementation">qinputdialog.h</include>
+ <include location="local" impldecl="in implementation">../bsview.h</include>
+ <include location="local" impldecl="in implementation">../bsdoc.h</include>
<include location="local" impldecl="in implementation">bsappbase.ui.h</include>
</includes>
<forwards>
- <forward>class BSDoc</forward>
+ <forward>class BSConf</forward>
<forward>class BSView</forward>
+ <forward>class BSDoc</forward>
</forwards>
<variables>
- <variable>BSDoc* doc</variable>
+ <variable>BSConf* conf</variable>
<variable>BSView* view</variable>
+ <variable>BSDoc* doc</variable>
</variables>
<slots>
<slot>fileNew()</slot>
void BSAppBase::init()
{
+ conf = new BSConf();
doc = new BSDoc();
view = new BSView(this,doc);
setCentralWidget(view);
//////////////////////////////////////////////////////////////////////////
//
-void UnitType::setClass(int iClass)
+void UnitType::setClass(string sClass)
{
- m_iClass = iClass;
+ m_sClass = sClass;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::iClass()
+string UnitType::Class()
{
- return m_iClass;
+ return m_sClass;
}
//////////////////////////////////////////////////////////////////////////
//
-void UnitType::setTarget(vector<int> Target)
+void UnitType::setTarget(vector<string> Target)
{
m_vTarget = Target;
}
//////////////////////////////////////////////////////////////////////////
//
-void UnitType::addTarget(int iTarget)
+void UnitType::addTarget(string target)
{
- m_vTarget.push_back(iTarget);
+ m_vTarget.push_back(target);
}
//////////////////////////////////////////////////////////////////////////
* If it finds the position it inserts the target there, if it reaches the end
* before it finds the correct possition it adds the target to the end.
*/
-void UnitType::insTarget(int iTarget, int index = 0)
+void UnitType::insTarget(string target, int index = 0)
{
- vector<int>::iterator i = m_vTarget.begin();
+ vector<string>::iterator i = m_vTarget.begin();
for (int j = 0; j < index; j++, i++)
{
if (i == m_vTarget.end())
{
- m_vTarget.push_back(iTarget);
+ m_vTarget.push_back(target);
return;
}
}
- m_vTarget.insert(i, iTarget);
+ m_vTarget.insert(i, target);
}
//////////////////////////////////////////////////////////////////////////
//
-vector<int> UnitType::Target()
+vector<string> UnitType::Target()
{
return m_vTarget;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::Target(int index)
+string UnitType::Target(int index)
{
return m_vTarget[index];
}
//////////////////////////////////////////////////////////////////////////
//
-void UnitType::setType(int iType)
+void UnitType::setType(string type)
{
- m_iType = iType;
+ m_sType = type;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::Type()
+string UnitType::Type()
{
- return m_iType;
+ return m_sType;
}
int Race();
/** Sets the class for the unittype, it's represented as a integer */
- void setClass(int iClass);
- int iClass();
+ void setClass(std::string sClass);
+ std::string Class();
/** Sets the classes that this unittype targets. a vector is used. */
- void setTarget(std::vector<int> Target);
+ void setTarget(std::vector<std::string> Target);
/** This function adds a target class to the end of the target list. */
- void addTarget(int iTarget);
+ void addTarget(std::string target);
/** This function inserts a target class into the target list. The default is in the beginning.
* \param iTarget an integer that represents the target's class.
* \param index where to place the target. 0 being the default and first place. */
- void insTarget(int iTarget, int index = 0);
+ void insTarget(std::string iTarget, int index = 0);
/** Returns all targets from the target list */
- std::vector<int> Target();
+ std::vector<std::string> Target();
/** Returns a specific target
* \param index An index value that represents the target. 0 being the first*/
- int Target(int index);
+ std::string Target(int index);
/** Sets the initiatve, the lower it is the earlier the unit shots */
void setInitiative(int iInit);
/** Sets the type of the unit. What the types do must be specified in the real battle engine (Fleet) though.
* \param iType An integer to symbolise the type. */
- void setType(int iType);
+ void setType(std::string type);
/** What type of ship this is. */
- int Type();
+ std::string Type();
protected:
std::string m_sName;
int m_iRace; //!< Not really the race, but an indiaction on what race can use it..
- int m_iClass;
- std::vector<int> m_vTarget;
+ std::string m_sClass;
+ std::vector<std::string> m_vTarget;
int m_iInitiative;
int m_iAgility;
int m_iWeaponSpeed;
int m_iArmor;
int m_iEMP;
int m_iTotalResources;
- int m_iType; //!< normal,emp,cloak,steal,pod
+ std::string m_sType; //!< normal,emp,cloak,steal,pod
int m_iETA;
int m_iFuel;
};