]> ruin.nu Git - hbs.git/commitdiff
moving the tick changing to the toolbar instead of CTickView. adding a combobox to...
authorMichael Andreen <harv@ruin.nu>
Tue, 16 Apr 2002 01:11:26 +0000 (01:11 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 16 Apr 2002 01:11:26 +0000 (01:11 +0000)
ChangeLog
bs/bsview.cpp
bs/bsview.h
bs/docs/api/hbs.doxconf
bs/planet.cpp
bs/planet.h
bs/ui/bsappbase.ui
bs/ui/bsappbase.ui.h

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6f675f8b41e1b867b252728176406751bcaf3b01 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -0,0 +1,2 @@
+Mon Apr 15 22:17:15 CEST 2002:
+       * Implemented scorechange for the planet. All fleets with "Home" in their name is counted.
index ccf334158c714641a2eaac86a39c32794364ccc4..54f7f4832edb1aec60a23ef2a35d376b889fd8c0 100644 (file)
@@ -32,7 +32,7 @@ using namespace std;
 #include "battlesum.h"
 #include "scanview.h"
 #include "ui/infoview.h"
-#include "tickview.h"
+//#include "tickview.h"
 #include "fleetview.h"
 #include "fleet.h"
 #include "planet.h"
@@ -40,6 +40,10 @@ using namespace std;
 BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent)
 {
   /** connect doc with the view*/
+
+       m_iMaxTick = 0;
+       m_iMinTick = 0;
+       m_iResultMode = 0;
        
        m_bMoreDocChanges = false;
        connect(doc, SIGNAL(documentChanged()), this, SLOT(slotDocumentChanged()));
@@ -79,7 +83,7 @@ BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent)
        m_InfoView->setRaces(raceNames);
        
        //the right side
-       m_TickView = new TickView(m_RightSplit);
+       //m_TickView = new TickView(m_RightSplit);
        m_FleetViews = new QWidgetStack(m_RightSplit);
        m_ScanView = new ScanView(m_RightSplit);
        
@@ -96,12 +100,13 @@ BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent)
        m_FleetViews->addWidget(m_FleetView, 1);
        m_GenericFleetView = new FleetView(&fl2, true);
        m_FleetViews->addWidget(m_GenericFleetView, 2);
+       m_FleetView->slotViewTickRange(m_iMinTick, m_iMaxTick);
+       m_GenericFleetView->slotViewTickRange(m_iMinTick, m_iMaxTick);
+
        //m_FleetViews->raiseWidget(0);
        connect(m_NumberView, SIGNAL(selectionChanged(QListViewItem *)), SLOT(slotFleetSelection(QListViewItem *)));
        connect(m_FleetView, SIGNAL(fleetChanged(const Fleet*)), SLOT(slotFleetChanged(const Fleet*)));
        connect(m_GenericFleetView, SIGNAL(fleetChanged(const Fleet*)), SLOT(slotFleetChanged(const Fleet*)));
-       connect(m_TickView, SIGNAL(ticksChanged(int,int)), m_FleetView, SLOT(slotViewTickRange(int,int)));
-       connect(m_TickView, SIGNAL(ticksChanged(int,int)), m_GenericFleetView, SLOT(slotViewTickRange(int,int)));
 }
 
 BSView::~BSView()
@@ -402,10 +407,32 @@ void BSView::updateFleetView()
                        delete m_FleetView;
                        m_FleetView = new FleetView(fl, friendly);
                        connect(m_FleetView, SIGNAL(fleetChanged(const Fleet*)), SLOT(slotFleetChanged(const Fleet*)));
-                       connect(m_TickView, SIGNAL(ticksChanged(int,int)), m_FleetView, SLOT(slotViewTickRange(int,int)));
+                       m_FleetView->slotViewTickRange(m_iMinTick, m_iMaxTick);
                        m_FleetViews->addWidget(m_FleetView, 1);
                }
                m_FleetViews->raiseWidget(2);
                m_FleetViews->raiseWidget(1);
        }
 }
+
+//////////////////////////////////////////////////////////////////////////
+//
+void BSView::slotTickChanged(int min, int max)
+{
+       m_FleetView->slotViewTickRange(min, max);
+       m_GenericFleetView->slotViewTickRange(min, max);
+
+       m_iMinTick = min;
+       m_iMaxTick = max;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void BSView::slotResultModeChanged( int i)
+{
+       //FIXME
+       /*m_FleetView->slotSetResultMode(i);
+       m_GenericFleetView->slotSetResultMode(i);
+       */
+       m_iResultMode = i;
+}
index 16acc2b6ce767966d6e466f5d1818611ecc43ccb..391a777658f67c7827bd95576d0d0926c1125629 100644 (file)
@@ -30,7 +30,7 @@
 class BattleSum;
 class ScanView;
 class InfoView;
-class TickView;
+//class TickView;
 class FleetView;
 
 //QT forward declarations
@@ -59,6 +59,8 @@ class BSView : public QSplitter
        void slotInfoCancel();
        void slotInfoNew();
        void slotInfoRemove();
+       void slotTickChanged(int min, int max);
+       void slotResultModeChanged( int i);
 
   protected:
 
@@ -72,7 +74,7 @@ class BSView : public QSplitter
        QSplitter               *m_LeftSplit;
        ScanView                *m_ScanView;
        InfoView                *m_InfoView;
-       TickView                *m_TickView;
+       //TickView              *m_TickView;
        QWidgetStack    *m_FleetViews;
        FleetView       *m_FleetView;
        FleetView       *m_GenericFleetView;
@@ -84,6 +86,11 @@ class BSView : public QSplitter
        QString         m_sFleet;
 
        bool m_bMoreDocChanges;
+
+       int m_iMaxTick;
+       int m_iMinTick;
+       int m_iResultMode;
+       
   
 public slots: // Public slots
   /** No descriptions */
index 3250a6bb6f84ca75d12225395a87cc108f53d33e..ed78a974349ec21bf0f258f32864224fb0e1b069 100644 (file)
@@ -311,7 +311,7 @@ INPUT                  = ../../
 # and *.h) to filter out the source-files in the directories. If left 
 # blank all files are included.
 
-FILE_PATTERNS          = *.cpp *.h *.doc
+FILE_PATTERNS          = *.cpp *.h 
 
 # The RECURSIVE tag can be used to turn specify whether or not subdirectories 
 # should be searched for input files as well. Possible values are YES and NO. 
index c374a99ff9cc7f726fd18392cad21aeb0890a5b2..1f904f82685ff101d4d392c644a6f269801089c4 100644 (file)
@@ -23,7 +23,6 @@ using namespace std;
 Planet::Planet()
 {
        m_sRace = "Planet";
-       m_iScore = 0;
 }
 
 Planet::~Planet(){
@@ -31,18 +30,53 @@ Planet::~Planet(){
 
 //////////////////////////////////////////////////////////////////////////
 //
-unsigned Planet::planetScore() const
+unsigned Planet::planetScore(int tick = 0) const
 {
-       return m_iScore;
+       int ticks = m_Score.size();
+       if (ticks == 0)
+               return 0;
+
+       --ticks;
+
+       if (ticks < tick)
+               return m_Score[ticks];
+
+       return m_Score[tick];
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-void Planet::setPlanetScore(unsigned i)
+void Planet::setPlanetScore(unsigned number, int tick = 0)
 {
-       m_iScore = i;
+       int earlier = 0;
+       int ticks = m_Score.size();
+
+       if (ticks != 0)
+               earlier = m_Score[ticks - 1];
+
+       for (int i = ticks; i <= tick; ++i)
+       {
+               m_Score.push_back(earlier);
+       }
+       m_Score[tick] = number;
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+void Planet::addPlanetScore(unsigned number, int tick = 0)
+{
+       int earlier = 0;
+       int ticks = m_Score.size();
+
+       if (ticks != 0)
+               earlier = m_Score[ticks - 1];
+
+       for (int i = ticks; i <= tick; ++i)
+       {
+               m_Score.push_back(earlier);
+       }
+       m_Score[tick] += number;
+}
 //////////////////////////////////////////////////////////////////////////
 //
 int Planet::roids(std::string type, int tick = 0) const
@@ -146,6 +180,8 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
                allHostiles.distributeLossesGains(hostiles, tick);
                allHostiles.distributeCappedRoids(hostiles, tick);
 
+               calculateScoreLoss(friends, tick);
+
        /*      for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
                        setRoids(i->first, roids(i->first, 1), tick);*/
        }
@@ -193,9 +229,9 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
 
                if (s_Units[unittype].type() == "Pod")
                {
-                       if (m_iScore > 0)
+                       if (planetScore(tick - 1) > 0)
                        {
-                               float capping = float(m_iScore) / hostile->score() /  10;
+                               float capping = float(planetScore(tick - 1)) / hostile->score() /  10;
                        
                                cerr << "Capping is: " << capping << endl;
        
@@ -220,7 +256,7 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
                                                        
                                                takeRoids(roid->first, caproids, tick);
                
-                                               //FIXME: Going to move this to the distribute roids section instead..
+                                               //FIXME: Going to move this to the distribute roids section instead.. Not really move, I'll keep this, but "regenerate" the pods in the distribute ships function.
                                                hostiletemp->killFleet(unittype, caproids, 1);
                                                //int totroids = caproids + hostiletemp->resource(roid->first, 0);
                                                hostiletemp->addResource(roid->first, caproids, 1);
@@ -239,3 +275,15 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
        }
 }
 
+void Planet::calculateScoreLoss(std::vector<Fleet*> friendly, int tick = 1)
+{
+       for (vector<Fleet*>::iterator i = friendly.begin(); i != friendly.end(); ++i)
+       {
+               if ((*i)->name().find("Home") != string::npos)
+               {
+                       int scorechange = (*i)->score(tick) - (*i)->score(tick - 1);
+                       addPlanetScore(scorechange, tick);
+               }
+       }
+}
+
index c729ebf6d634e781ac76467d1d416e389f6d6dba..486bd60f50191fe185af5e34132bf51ab34e5b63 100644 (file)
@@ -43,13 +43,19 @@ public:
         * \returns the score as an unsigned int. 
         * \todo add a param to specify what tick to use.
         */
-       unsigned planetScore() const;
+       unsigned planetScore(int tick = 0) const;
 
        /** Sets the score for the current fleet. 
         * \param score this param is a unsigned int holding the score
         * \todo add a param to specify what tick to use.
         */
-       void setPlanetScore(unsigned score);
+       void setPlanetScore(unsigned score, int tick = 0);
+
+       /** Adds score to the current fleet. 
+        * \param score this param is a unsigned int holding the score
+        * \todo add a param to specify what tick to use.
+        */
+       void addPlanetScore(unsigned score, int tick = 0);
 
        /** This function is used to get the number of roids of a specific type.
         * \param type the for this roid (for pa: metal, crystal, eonium, uninit)
@@ -79,6 +85,8 @@ public:
         */
        void runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile);
 
+       void calculateScoreLoss(std::vector<Fleet*> friendly, int tick = 1);
+
 protected:
        /** This function is used to start the calculations of a single tick of the
         * battle on the current planet. It's protected because it's not really meant
@@ -92,7 +100,7 @@ protected:
         */
        void calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string, std::map<std::string, int> >& stealfriendly, std::map<std::string, std::map<std::string, int> >&  stealhostile, int tick = 0);
 
-       unsigned m_iScore;
+       std::vector <unsigned> m_Score;
        RoidList m_Roids;
        
 };
index ed97f11419cc03ac1adc535d6e9c8ced7c193dc2..651e4d3f81dd794845c04700f79ce1614bc5c6db 100644 (file)
@@ -8,8 +8,8 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>726</width>
-            <height>519</height>
+            <width>700</width>
+            <height>534</height>
         </rect>
     </property>
     <property name="caption">
@@ -24,8 +24,8 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>726</width>
-            <height>26</height>
+            <width>700</width>
+            <height>24</height>
         </rect>
     </property>
     <item text="&amp;File" name="fileMenu">
         <action name="fileNewAction"/>
         <action name="fileOpenAction"/>
         <action name="fileSaveAction"/>
+        <separator/>
+        <widget class="QLabel">
+            <property name="name">
+                <cstring>TextLabel3</cstring>
+            </property>
+            <property name="text">
+                <string>Show result as:</string>
+            </property>
+        </widget>
+        <widget class="QComboBox">
+            <property name="name">
+                <cstring>resultModeCombo</cstring>
+            </property>
+            <item>
+                <property name="text">
+                    <string>Killed units</string>
+                </property>
+            </item>
+            <item>
+                <property name="text">
+                    <string>Blocked units</string>
+                </property>
+            </item>
+            <item>
+                <property name="text">
+                    <string>Survived unts</string>
+                </property>
+            </item>
+            <item>
+                <property name="text">
+                    <string>New (stolen) untis</string>
+                </property>
+            </item>
+        </widget>
+        <separator/>
+        <widget class="QLabel">
+            <property name="name">
+                <cstring>TextLabel1</cstring>
+            </property>
+            <property name="text">
+                <string>From tick:</string>
+            </property>
+        </widget>
+        <widget class="QSpinBox">
+            <property name="name">
+                <cstring>minTickSpin</cstring>
+            </property>
+            <property name="maxValue">
+                <number>0</number>
+            </property>
+        </widget>
+        <widget class="QLabel">
+            <property name="name">
+                <cstring>TextLabel2</cstring>
+            </property>
+            <property name="text">
+                <string>to:</string>
+            </property>
+        </widget>
+        <widget class="QSpinBox">
+            <property name="name">
+                <cstring>maxTickSpin</cstring>
+            </property>
+        </widget>
+        <widget class="QCheckBox">
+            <property name="name">
+                <cstring>oneTickCheck</cstring>
+            </property>
+            <property name="text">
+                <string>One tick only</string>
+            </property>
+        </widget>
     </toolbar>
 </toolbars>
 <actions>
         <receiver>BSAppBase</receiver>
         <slot>battleSimulate()</slot>
     </connection>
+    <connection>
+        <sender>oneTickCheck</sender>
+        <signal>toggled(bool)</signal>
+        <receiver>BSAppBase</receiver>
+        <slot>oneTickCheck_toggled(bool)</slot>
+    </connection>
+    <connection>
+        <sender>resultModeCombo</sender>
+        <signal>activated(int)</signal>
+        <receiver>BSAppBase</receiver>
+        <slot>resultModeCombo_activated(int)</slot>
+    </connection>
+    <connection>
+        <sender>minTickSpin</sender>
+        <signal>valueChanged(int)</signal>
+        <receiver>BSAppBase</receiver>
+        <slot>slotTicksChanged(int)</slot>
+    </connection>
+    <connection>
+        <sender>minTickSpin</sender>
+        <signal>valueChanged(int)</signal>
+        <receiver>BSAppBase</receiver>
+        <slot>minTickSpin_valueChanged(int)</slot>
+    </connection>
+    <connection>
+        <sender>maxTickSpin</sender>
+        <signal>valueChanged(int)</signal>
+        <receiver>BSAppBase</receiver>
+        <slot>slotTicksChanged(int)</slot>
+    </connection>
+    <connection>
+        <sender>maxTickSpin</sender>
+        <signal>valueChanged(int)</signal>
+        <receiver>BSAppBase</receiver>
+        <slot>maxTickSpin_valueChanged(int)</slot>
+    </connection>
 </connections>
 <includes>
     <include location="global" impldecl="in implementation">qapplication.h</include>
     <variable>BSView* view</variable>
     <variable>BSDoc* doc</variable>
 </variables>
+<signals>
+    <signal>ticksChanged(int, int);</signal>
+    <signal>resultModeChanged(int);</signal>
+</signals>
 <slots>
     <slot>fileNew()</slot>
     <slot>fileOpen()</slot>
     <slot>helpAbout()</slot>
     <slot>battleNew()</slot>
     <slot>battleSimulate()</slot>
+    <slot>oneTickCheck_toggled( bool b )</slot>
+    <slot>minTickSpin_valueChanged( int i )</slot>
+    <slot>maxTickSpin_valueChanged( int i )</slot>
+    <slot>slotTicksChanged( int i )</slot>
+    <slot>resultModeCombo_activated( int i )</slot>
 </slots>
 <layoutdefaults spacing="6" margin="11"/>
 </UI>
index 8d5da689d32821851a4ae957eb4f9feb92d8460a..03b081c8eeeb79aa0ba438906a3273ca73791dd9 100644 (file)
@@ -58,6 +58,8 @@ void BSAppBase::init()
     conf = new BSConf();
     doc = new BSDoc();
     view = new BSView(this,doc);
+    connect(this, SIGNAL(ticksChanged(int, int) ), view, SLOT(slotTickChanged(int, int)));
+    connect(this, SIGNAL(resultModeChanged(int) ), view, SLOT(slotResultModeChanged(int)));
     setCentralWidget(view);
 }
 
@@ -107,4 +109,57 @@ void BSAppBase::battleSimulate()
      
      doc->runBattleSimulation();
      QApplication::restoreOverrideCursor();
-}
\ No newline at end of file
+}
+
+void BSAppBase::oneTickCheck_toggled( bool b)
+{
+     if(b)
+    {
+       maxTickSpin->setMinValue(0);
+       minTickSpin->setDisabled(true);
+       minTickSpin->setMaxValue(99);
+    }
+    else
+    {
+       minTickSpin->setEnabled(true);
+       minTickSpin->setMaxValue( maxTickSpin->value());
+       if (minTickSpin->value() < maxTickSpin->value())
+           maxTickSpin->setMinValue( minTickSpin->value());
+       else
+       {
+               maxTickSpin->setMinValue( maxTickSpin->value());
+               minTickSpin->setValue(maxTickSpin->value());
+       }
+    }
+}
+
+void BSAppBase::minTickSpin_valueChanged( int i )
+{
+         if ( !oneTickCheck->isChecked())
+        maxTickSpin->setMinValue(i);
+}
+
+void BSAppBase::maxTickSpin_valueChanged( int i )
+{
+         if ( !oneTickCheck->isChecked())
+        minTickSpin->setMaxValue(i);
+}
+
+void BSAppBase::slotTicksChanged( int i )
+{
+   if ( oneTickCheck->isChecked())
+    {
+       maxTickSpin->setValue(i);
+       //minTickSpin->setValue(i-1);
+       emit ticksChanged( maxTickSpin->value() - 1, maxTickSpin->value());
+       return;
+    }
+   emit ticksChanged( minTickSpin->value(), maxTickSpin->value());
+}
+
+
+
+void BSAppBase::resultModeCombo_activated( int i )
+{
+    emit resultModeChanged(i);
+}