]> ruin.nu Git - hbs.git/commitdiff
Can now load the stats and race configurations..
authorMichael Andreen <harv@ruin.nu>
Mon, 11 Mar 2002 22:53:16 +0000 (22:53 +0000)
committerMichael Andreen <harv@ruin.nu>
Mon, 11 Mar 2002 22:53:16 +0000 (22:53 +0000)
bs/bsconf.cpp
bs/bsconf.h
bs/bsdoc.h
bs/bsview.cpp
bs/bsview.h
bs/fleet.cpp
bs/fleet.h
bs/ui/bsappbase.ui
bs/ui/bsappbase.ui.h
bs/unittype.cpp
bs/unittype.h

index 45a2f44c81cb595fcf501cbb611390e587478d17..1ee7da5ca02c4f65ca7d02aa24a6c3d51fd8710b 100644 (file)
  *                                                                         *
  ***************************************************************************/
 
  *                                                                         *
  ***************************************************************************/
 
+
+
+#include <qsettings.h>
+#include <qfile.h>
+#include <qtextstream.h>
+
+#include <iostream>
+#include <map>
+#include <vector>
+using namespace std;
+
 #include "bsconf.h"
 #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;
+}
+
+
index 49a1d75b509e258f8f274dd83f4da16253e751f4..9711c698a73046e11a4fea94305301ddd6bca577 100644 (file)
@@ -19,6 +19,7 @@
 #define BSCONF_H
 
 #include <qobject.h>
 #define BSCONF_H
 
 #include <qobject.h>
+#include <qstring.h>
 
 /**
   *@author Michael Andreen
 
 /**
   *@author Michael Andreen
 
 class BSConf : public QObject
 {
 
 class BSConf : public QObject
 {
-       Q_Object
-public: 
+       Q_OBJECT
+
+       public:
        BSConf();
        ~BSConf();
        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
 };
 
 #endif
index 3cca9c34290db51fdbe32578c210e48c21e44787..5cf0001e33716fd8b5f7012bd88f6028ccbcdb2d 100644 (file)
@@ -40,7 +40,7 @@ class BSDoc : public QObject
   Q_OBJECT
 
   public:
   Q_OBJECT
 
   public:
-    BSDoc();
+       BSDoc();
     ~BSDoc();
     void newDoc();
     bool save();
     ~BSDoc();
     void newDoc();
     bool save();
index 4f050c03601967fa42c1eb43a362dc8d84c220cb..ac969a3506c38bac22a96ac137fc45ed5bd4dc69 100644 (file)
@@ -33,7 +33,7 @@ using namespace std;
 #include "scanview.h"
 #include "ui/infoview.h"
 #include "tickview.h"
 #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)
 #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);
        //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);
        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')
        {
        }
        else if (lvi->parent()->parent() == '\0')
        {
-                       m_FleetView->slotHomePlanet(false);
+//                     m_FleetView->slotHomePlanet(false);
                if (lvi->text(0) == tr("Friendly"))
                {
                if (lvi->text(0) == tr("Friendly"))
                {
-                       m_FleetView->slotAttacker(false);
+//                     m_FleetView->slotAttacker(false);
                }
                else
                {
                }
                else
                {
-                       m_FleetView->slotAttacker(true);
+//                     m_FleetView->slotAttacker(true);
                }
                m_FleetViews->raiseWidget(1);
                
                }
                m_FleetViews->raiseWidget(1);
                
@@ -149,17 +149,17 @@ void BSView::slotFleetSelection(QListViewItem *lvi)
        {
                if (lvi->parent()->text(0) == tr("Friendly"))
                {
        {
                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"))
                        {
                        if (lvi->text(0) == tr("Home Planet"))
                        {
-                               m_FleetView->slotHomePlanet(true);
+//                             m_FleetView->slotHomePlanet(true);
                        }
                }
                else
                {
                        }
                }
                else
                {
-                       m_FleetView->slotAttacker(true);
-                       m_FleetView->slotHomePlanet(false);
+//                     m_FleetView->slotAttacker(true);
+//                     m_FleetView->slotHomePlanet(false);
                }
                m_FleetViews->raiseWidget(1);
                                
                }
                m_FleetViews->raiseWidget(1);
                                
index 86f277ede218543f1f20c33c5d074bd1a6ab4f9a..d706e59bc15f92a6370be096837a0776522e72db 100644 (file)
@@ -28,7 +28,7 @@ class BattleSum;
 class ScanView;
 class InfoView;
 class TickView;
 class ScanView;
 class InfoView;
 class TickView;
-class FleetViewBase;
+class FleetView;
 
 //QT forward declarations
 class QListView;
 
 //QT forward declarations
 class QListView;
@@ -61,7 +61,7 @@ class BSView : public QSplitter
        InfoView                *m_InfoView;
        TickView                *m_TickView;
        QWidgetStack    *m_FleetViews;
        InfoView                *m_InfoView;
        TickView                *m_TickView;
        QWidgetStack    *m_FleetViews;
-       FleetViewBase   *m_FleetView;
+       FleetView   *m_FleetView;
        BSDoc                   *m_doc;
   
 public slots: // Public slots
        BSDoc                   *m_doc;
   
 public slots: // Public slots
index c2bf40ed4b634e5399f2f08e03bc7b1a8669ac64..a7ebe5cf0f7b610550b6c759ab1a0ea66aabe350 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "fleet.h"
 
 
 #include "fleet.h"
 
+#include <iostream>
 using namespace std;
 
 //Static variables
 using namespace std;
 
 //Static variables
@@ -26,6 +27,7 @@ map<string, UnitType > Fleet::s_Units;
 Fleet::Fleet()
 {
        m_iETA = 0;
 Fleet::Fleet()
 {
        m_iETA = 0;
+       m_sRace = "Generic";
 }
 Fleet::~Fleet(){
 }
 }
 Fleet::~Fleet(){
 }
@@ -99,4 +101,38 @@ int  Fleet::ETA()
        return m_iETA;
 }
 
        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;
+       }
+}
 
 
index 7fb4f44d182a884119dd9e8773450c49310e91e1..b6aaecd429ab85d31775f5777fba78feb9545a39 100644 (file)
@@ -73,6 +73,8 @@ public:
         */
        int  ETA();
 
         */
        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;
 
 protected:
        std::string     m_sName;
index 363fc7e16b44f1f3d1003c04367dc77052f97a48..e6baafab460f1bbf2755bb49acf2fe3375db9c48 100644 (file)
     </connection>
 </connections>
 <includes>
     </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="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>
     <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 BSView</forward>
+    <forward>class BSDoc</forward>
 </forwards>
 <variables>
 </forwards>
 <variables>
-    <variable>BSDoc* doc</variable>
+    <variable>BSConf* conf</variable>
     <variable>BSView* view</variable>
     <variable>BSView* view</variable>
+    <variable>BSDoc* doc</variable>
 </variables>
 <slots>
     <slot>fileNew()</slot>
 </variables>
 <slots>
     <slot>fileNew()</slot>
index e7257447f284070aea24529ba78c00b8e8f2ed8f..0787e81d3563357ca824bd91598b5e18894348a4 100644 (file)
@@ -55,6 +55,7 @@ void BSAppBase::editCut()
 
 void BSAppBase::init()
 {
 
 void BSAppBase::init()
 {
+    conf = new BSConf();
     doc = new BSDoc();
     view = new BSView(this,doc);
     setCentralWidget(view);
     doc = new BSDoc();
     view = new BSView(this,doc);
     setCentralWidget(view);
index 69b2d2d9c09b3f9b20cb2b36c7223437fc6c43ee..27b3cd4affdeb107355804dc97afb551f283db02 100644 (file)
@@ -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<int> Target)
+void UnitType::setTarget(vector<string> Target)
 {
        m_vTarget = 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. 
  */
  * 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())
                {
 
        for (int j = 0; j < index; j++, i++)
        {
                if (i == m_vTarget.end())
                {
-                       m_vTarget.push_back(iTarget);
+                       m_vTarget.push_back(target);
                        return;
                }
        }
 
                        return;
                }
        }
 
-       m_vTarget.insert(i, iTarget);
+       m_vTarget.insert(i, target);
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-vector<int> UnitType::Target()
+vector<string> UnitType::Target()
 {
        return m_vTarget;
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
 {
        return m_vTarget;
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-int    UnitType::Target(int index)
+string UnitType::Target(int index)
 {
        return m_vTarget[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;
 }
 
 }
 
index dc34516bb8562a318b655487b602a76a9ea868b4..3357671df7816b31341e4cf6b9846e77d6918122 100644 (file)
@@ -49,22 +49,22 @@ public:
        int Race();
 
        /** Sets the class for the unittype, it's represented as a integer */
        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. */
 
        /** 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. */
        /** 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. */
        /** 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 */
        /** 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*/
        /** 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 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. */
 
        /** 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. */
        /** 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.. 
 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_iInitiative;
        int                     m_iAgility;
        int                     m_iWeaponSpeed;
@@ -126,7 +126,7 @@ protected:
        int                     m_iArmor;
        int                     m_iEMP;
        int                     m_iTotalResources;
        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;
 };
        int                     m_iETA;
        int                     m_iFuel;
 };