From: Michael Andreen Date: Mon, 11 Mar 2002 22:53:16 +0000 (+0000) Subject: Can now load the stats and race configurations.. X-Git-Tag: HBS_0_1_0~41 X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=commitdiff_plain;h=dc90594097a886eee49e9bfe45da6d4f9765179a Can now load the stats and race configurations.. --- diff --git a/bs/bsconf.cpp b/bs/bsconf.cpp index 45a2f44..1ee7da5 100644 --- a/bs/bsconf.cpp +++ b/bs/bsconf.cpp @@ -15,9 +15,157 @@ * * ***************************************************************************/ + + +#include +#include +#include + +#include +#include +#include +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 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 > 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; +} + + diff --git a/bs/bsconf.h b/bs/bsconf.h index 49a1d75..9711c69 100644 --- a/bs/bsconf.h +++ b/bs/bsconf.h @@ -19,6 +19,7 @@ #define BSCONF_H #include +#include /** *@author Michael Andreen @@ -26,10 +27,27 @@ 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 diff --git a/bs/bsdoc.h b/bs/bsdoc.h index 3cca9c3..5cf0001 100644 --- a/bs/bsdoc.h +++ b/bs/bsdoc.h @@ -40,7 +40,7 @@ class BSDoc : public QObject Q_OBJECT public: - BSDoc(); + BSDoc(); ~BSDoc(); void newDoc(); bool save(); diff --git a/bs/bsview.cpp b/bs/bsview.cpp index 4f050c0..ac969a3 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -33,7 +33,7 @@ using namespace std; #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) @@ -64,7 +64,7 @@ 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); @@ -133,14 +133,14 @@ void BSView::slotFleetSelection(QListViewItem *lvi) } 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); @@ -149,17 +149,17 @@ void BSView::slotFleetSelection(QListViewItem *lvi) { 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); diff --git a/bs/bsview.h b/bs/bsview.h index 86f277e..d706e59 100644 --- a/bs/bsview.h +++ b/bs/bsview.h @@ -28,7 +28,7 @@ class BattleSum; class ScanView; class InfoView; class TickView; -class FleetViewBase; +class FleetView; //QT forward declarations class QListView; @@ -61,7 +61,7 @@ class BSView : public QSplitter InfoView *m_InfoView; TickView *m_TickView; QWidgetStack *m_FleetViews; - FleetViewBase *m_FleetView; + FleetView *m_FleetView; BSDoc *m_doc; public slots: // Public slots diff --git a/bs/fleet.cpp b/bs/fleet.cpp index c2bf40e..a7ebe5c 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -17,6 +17,7 @@ #include "fleet.h" +#include using namespace std; //Static variables @@ -26,6 +27,7 @@ map Fleet::s_Units; Fleet::Fleet() { m_iETA = 0; + m_sRace = "Generic"; } Fleet::~Fleet(){ } @@ -99,4 +101,38 @@ int Fleet::ETA() return m_iETA; } +////////////////////////////////////////////////////////////////////////// +// +void Fleet::setRaces(std::map >& races) +{ + s_Races = races; +} + +////////////////////////////////////////////////////////////////////////// +// +void Fleet::setUnits(map& units) +{ + s_Units = units; + + for (map::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; + } +} diff --git a/bs/fleet.h b/bs/fleet.h index 7fb4f44..b6aaecd 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -73,6 +73,8 @@ public: */ int ETA(); + static void setRaces(std::map >& races); + static void setUnits(std::map& units); protected: std::string m_sName; diff --git a/bs/ui/bsappbase.ui b/bs/ui/bsappbase.ui index 363fc7e..e6baafa 100644 --- a/bs/ui/bsappbase.ui +++ b/bs/ui/bsappbase.ui @@ -455,18 +455,21 @@ - ../bsdoc.h - ../bsview.h + ../bsconf.h qinputdialog.h + ../bsview.h + ../bsdoc.h bsappbase.ui.h - class BSDoc + class BSConf class BSView + class BSDoc - BSDoc* doc + BSConf* conf BSView* view + BSDoc* doc fileNew() diff --git a/bs/ui/bsappbase.ui.h b/bs/ui/bsappbase.ui.h index e725744..0787e81 100644 --- a/bs/ui/bsappbase.ui.h +++ b/bs/ui/bsappbase.ui.h @@ -55,6 +55,7 @@ void BSAppBase::editCut() void BSAppBase::init() { + conf = new BSConf(); doc = new BSDoc(); view = new BSView(this,doc); setCentralWidget(view); diff --git a/bs/unittype.cpp b/bs/unittype.cpp index 69b2d2d..27b3cd4 100644 --- a/bs/unittype.cpp +++ b/bs/unittype.cpp @@ -61,30 +61,30 @@ int UnitType::Race() ////////////////////////////////////////////////////////////////////////// // -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 Target) +void UnitType::setTarget(vector Target) { m_vTarget = Target; } ////////////////////////////////////////////////////////////////////////// // -void UnitType::addTarget(int iTarget) +void UnitType::addTarget(string target) { - m_vTarget.push_back(iTarget); + m_vTarget.push_back(target); } ////////////////////////////////////////////////////////////////////////// @@ -93,33 +93,33 @@ void UnitType::addTarget(int iTarget) * 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::iterator i = m_vTarget.begin(); + vector::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 UnitType::Target() +vector UnitType::Target() { return m_vTarget; } ////////////////////////////////////////////////////////////////////////// // -int UnitType::Target(int index) +string UnitType::Target(int index) { return m_vTarget[index]; } @@ -266,15 +266,15 @@ int UnitType::ETA() ////////////////////////////////////////////////////////////////////////// // -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; } diff --git a/bs/unittype.h b/bs/unittype.h index dc34516..3357671 100644 --- a/bs/unittype.h +++ b/bs/unittype.h @@ -49,22 +49,22 @@ public: 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 Target); + void setTarget(std::vector 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 Target(); + std::vector 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); @@ -110,14 +110,14 @@ public: /** 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 m_vTarget; + std::string m_sClass; + std::vector m_vTarget; int m_iInitiative; int m_iAgility; int m_iWeaponSpeed; @@ -126,7 +126,7 @@ protected: 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; };