]> ruin.nu Git - hbs.git/commitdiff
fleetview now generates the correct "unit table" when it's created.
authorMichael Andreen <harv@ruin.nu>
Tue, 12 Mar 2002 19:51:38 +0000 (19:51 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 12 Mar 2002 19:51:38 +0000 (19:51 +0000)
bs/bsdoc.cpp
bs/bsdoc.h
bs/bsview.cpp
bs/fleet.cpp
bs/fleet.h
bs/unittype.cpp
bs/unittype.h

index e5504f93d16d9e5c70cf8151b3effb44e91b3910..c65903bc728a5644013f85cd464d275bef764c22 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "bsdoc.h"
 
+using namespace std;
 
 BSDoc::BSDoc()
 {
@@ -68,8 +69,34 @@ int BSDoc::newBattle(QString name)
 /////////////////////////////////////////////////////////////////////////
 //
 
-const std::map<QString, std::map<QString, std::map<QString, Fleet> > >& BSDoc::Battles() const
+const std::map<QString, std::map<QString, std::map<QString, Fleet> > >& BSDoc::battles() const
 {
        return m_Battles;
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+Fleet BSDoc::specificFleet(QString battle, QString group, QString fleet) const
+{
+       for (map<QString, map<QString, map<QString, Fleet> > >::const_iterator i = m_Battles.begin(); i != m_Battles.end(); ++i)
+       {
+               if (i->first == battle)
+               {
+                       for (map<QString, map<QString, Fleet> >::const_iterator j = i->second.begin(); j != i->second.end(); j++)
+                       {
+                               if (j->first == group)
+                               {
+                                       for (map<QString, Fleet>::const_iterator k = j->second.begin(); k != j->second.end(); ++k)
+                                       {
+                                               if (k->first == fleet)
+                                               {
+                                                       return k->second;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+
index d113f5bc3df0effd22428ce91108654478778244..b790dc628f4c06b454d8eeea198d3101249f4f57 100644 (file)
@@ -58,7 +58,9 @@ class BSDoc : public QObject
         * change it.
         * \todo remove this, and replace it with a better more closed interface.
         */
-       const std::map<QString, std::map<QString, std::map<QString, Fleet> > >& Battles() const;
+       const std::map<QString, std::map<QString, std::map<QString, Fleet> > >& battles() const;
+
+       Fleet specificFleet(QString battle, QString group, QString fleet) const;
 
   signals:
     void documentChanged();
index 78f8340fe185bcc7568415518b190a0784e5cc7c..f7f3aa8a771b30783c4058810d2f987a7fa14f75 100644 (file)
@@ -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 FleetView();
+       m_FleetView = new FleetView(Fleet(), true, true);
        m_FleetViews->addWidget(m_FleetView, 1);
 
        //m_FleetViews->raiseWidget(0);
@@ -94,7 +94,7 @@ void BSView::slotDocumentChanged()
 {
        m_NumberView->clear();
        
-       const map<QString, map<QString, map<QString, Fleet> > >& battles = m_doc->Battles();    
+       const map<QString, map<QString, map<QString, Fleet> > >& battles = m_doc->battles();    
 
        for (map<QString, map<QString, map<QString, Fleet> > >::const_iterator i = battles.begin(); i != battles.end(); ++i)
        {
@@ -147,22 +147,32 @@ void BSView::slotFleetSelection(QListViewItem *lvi)
        }
        else
        {
-               if (lvi->parent()->text(0) == tr("Friendly"))
+               bool home = false;
+               bool friendly = false;
+               QString fleet = lvi->text(0);
+               QString group = lvi->parent()->text(0);
+               QString battle = lvi->parent()->parent()->text(0);
+               if ( group == tr("Friendly"))
                {
-//                     m_FleetView->slotAttacker(false);
-//                     m_FleetView->slotHomePlanet(false);
-                       if (lvi->text(0) == tr("Home Planet"))
+                       friendly = true;
+                       if ( fleet == tr("Home Planet"))
                        {
-//                             m_FleetView->slotHomePlanet(true);
+                               home = true;
                        }
                }
+               Fleet fl = m_doc->specificFleet(battle, group, fleet);
+               if (fl.Race() == m_FleetView->fleet().Race() &&
+                       m_FleetView->isHome() == home)
+               {
+                       m_FleetView->viewFleet(fl, friendly);
+               }
                else
                {
-//                     m_FleetView->slotAttacker(true);
-//                     m_FleetView->slotHomePlanet(false);
+                       m_FleetViews->removeWidget(m_FleetView);
+                       m_FleetView = new FleetView(fl, friendly, home);
+                       m_FleetViews->addWidget(m_FleetView, 1);
                }
                m_FleetViews->raiseWidget(1);
-                               
        }
 
        
index a46a50a2ad51944c28a979e45992f99748deecfa..117ce39cb74e61b5b7e233cdc8db991f5b85b622 100644 (file)
@@ -150,5 +150,10 @@ const map<string, UnitType>& Fleet::Units()
        return s_Units;
 }
 
-
+//////////////////////////////////////////////////////////////////////////
+//
+vector<int> Fleet::RacesAllowed() const
+{
+       return s_Races[m_sRace];
+}
 
index 95c0c88dffbe53a779afd3557951cc24df045b3e..047fc131844588dc03c3f2b97ec56073f1abb5e7 100644 (file)
@@ -60,6 +60,8 @@ public:
         */
        std::string Race() const;
 
+       std::vector<int> RacesAllowed() const;
+
        /**Returns the total number of ships in this fleet
         */
        int NumberOfShips() const;
index 27b3cd4affdeb107355804dc97afb551f283db02..6f3ef82ed8b071c5c858b601fac94556555f16c8 100644 (file)
@@ -40,7 +40,7 @@ void UnitType::setName(string sName)
 
 //////////////////////////////////////////////////////////////////////////
 //
-string UnitType::Name()
+string UnitType::Name() const
 {
        return m_sName;
 }
@@ -54,7 +54,7 @@ void UnitType::setRace(int iRace)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int UnitType::Race()
+int UnitType::Race() const
 {
        return m_iRace;
 }
@@ -68,7 +68,7 @@ void UnitType::setClass(string sClass)
 
 //////////////////////////////////////////////////////////////////////////
 //
-string UnitType::Class()
+string UnitType::Class() const
 {
        return m_sClass;
 }
@@ -112,14 +112,14 @@ void UnitType::insTarget(string target, int index = 0)
 
 //////////////////////////////////////////////////////////////////////////
 //
-vector<string> UnitType::Target()
+vector<string> UnitType::Target() const
 {
        return m_vTarget;
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-string UnitType::Target(int index)
+string UnitType::Target(int index) const
 {
        return m_vTarget[index];
 }
@@ -133,7 +133,7 @@ void UnitType::setInitiative(int iInit)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int     UnitType::Initiative()
+int     UnitType::Initiative() const
 {
        return m_iInitiative;
 }
@@ -147,7 +147,7 @@ void UnitType::setAgility (int iAgil)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int  UnitType::Agility()
+int  UnitType::Agility() const
 {
        return m_iAgility;
 }
@@ -161,7 +161,7 @@ void UnitType::setWeaponSpeed(int iWPSP)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int  UnitType::WeaponSpeed()
+int  UnitType::WeaponSpeed() const
 {
        return m_iWeaponSpeed;
 }
@@ -175,7 +175,7 @@ void UnitType::setGuns(int iGuns)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int UnitType::Guns()
+int UnitType::Guns() const
 {
        return m_iGuns;
 }
@@ -189,7 +189,7 @@ void UnitType::setPower(int iPower)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int  UnitType::Power()
+int  UnitType::Power() const
 {
        return m_iPower;
 }
@@ -203,7 +203,7 @@ void UnitType::setArmor(int iArmor)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int  UnitType::Armor()
+int  UnitType::Armor() const
 {
        return m_iArmor;
 }
@@ -217,7 +217,7 @@ void UnitType::setEMP(int iEMP)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int  UnitType::EMP()
+int  UnitType::EMP() const
 {
        return m_iEMP;
 }
@@ -231,7 +231,7 @@ void UnitType::setTotalResources(int iTR)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int UnitType::TotRes()
+int UnitType::TotRes() const
 {
        return m_iTotalResources;
 }
@@ -245,7 +245,7 @@ void UnitType::setFuel(int iFuel)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int  UnitType::Fuel()
+int  UnitType::Fuel() const
 {
        return m_iFuel;
 }
@@ -259,7 +259,7 @@ void UnitType::setETA(int iETA)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int  UnitType::ETA()
+int  UnitType::ETA() const
 {
        return m_iETA;
 }
@@ -273,7 +273,7 @@ void UnitType::setType(string type)
 
 //////////////////////////////////////////////////////////////////////////
 //
-string  UnitType::Type()
+string  UnitType::Type() const
 {
        return m_sType;
 }
index 3357671df7816b31341e4cf6b9846e77d6918122..9bf008e83eeeb8e1294aa94b5f595db4f3b21e90 100644 (file)
@@ -41,16 +41,16 @@ public:
        /*! This function sets the name for this unittype (ie. interceptor) */
        void setName(std::string sName);
        /** Returns the name of this unittype */
-       std::string Name();
+       std::string Name() const;
 
        /** This functions sets which race this unittype is, the race is represented with a integer. */
        void setRace(int iRace);
        /** Returns the race this unittype belongs to*/
-       int Race();
+       int Race() const;
 
        /** Sets the class for the unittype, it's represented as a integer */
        void setClass(std::string sClass);
-       std::string Class();
+       std::string Class() const;
 
        /** Sets the classes that this unittype targets. a vector is used. */
        void setTarget(std::vector<std::string> Target);
@@ -61,58 +61,58 @@ public:
         * \param index where to place the target. 0 being the default and first place. */
        void insTarget(std::string iTarget, int index = 0);
        /** Returns all targets from the target list */
-       std::vector<std::string> Target();
+       std::vector<std::string> Target() const;
        /** Returns a specific target 
         * \param index An index value that represents the target. 0 being the first*/
-       std::string     Target(int index);
+       std::string     Target(int index) const;
 
        /** Sets the initiatve, the lower it is the earlier the unit shots */
        void setInitiative(int iInit);
-       int      Initiative();
+       int      Initiative() const;
 
        /** Sets the agility, the higher it is the harder it is to hit the unit */
        void setAgility (int iAgil);
-       int  Agility();
+       int  Agility() const;
 
        /** Sets the weaponspeed.. just a simple integer that shows how good it is at hitting things */
        void setWeaponSpeed(int iWPSP);
-       int  WeaponSpeed();
+       int  WeaponSpeed() const;
 
        /** Sets the number of guns. */
        void setGuns(int iGuns);
-       int Guns();
+       int Guns() const;
 
        /** Sets the how much power the guns have.. or in other words: the damage they do. */
        void setPower(int iPower);
-       int  Power();
+       int  Power() const;
 
        /** Sets the armor, this is how much damage the unittype can take before it's destroyed */
        void setArmor(int iArmor);
-       int  Armor();
+       int  Armor() const;
 
        /** Sets the emp resistance, the lower value the easier it is to block it */
        void setEMP(int iEMP);
-       int  EMP();
+       int  EMP() const;
 
        /** Sets the resource cost for this unittype. Used for example for score calculation and so on. */
        void setTotalResources(int iTR);
        /** Returns the number of total resources this unittype cost. */
-       int TotRes();
+       int TotRes() const;
 
        /** Sets the fuelcost for this unittype */
        void setFuel(int iFuel);
        /** Returns the fuelcost */
-       int  Fuel();
+       int  Fuel() const;
 
        /** Sets the ETA, the speed in a sort of inverted form.. the lower ETA, the faster is the unit */
        void setETA(int iETA);
-       int  ETA(); 
+       int  ETA() const
 
        /** 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(std::string type);
        /** What type of ship this is. */
-       std::string  Type();    
+       std::string  Type() const;      
 protected:
        std::string             m_sName;
        int                     m_iRace;            //!< Not really the race, but an indiaction on what race can use it..