]> ruin.nu Git - hbs.git/commitdiff
started to work on the battle report.. almost there =)
authorMichael Andreen <harv@ruin.nu>
Sun, 30 Jun 2002 04:43:28 +0000 (04:43 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 30 Jun 2002 04:43:28 +0000 (04:43 +0000)
bs/bsview.cpp
bs/bsview.h
bs/fleet.cpp
bs/fleet.h
bs/fleetview.cpp
bs/planet.cpp
bs/planet.h
bs/ui/bsappbase.ui
bs/ui/bsappbase.ui.h
bs/ui/scanviewbase.ui

index 9212fb166c4295cad4be300ebe67186993f4a51b..c6fcc46efe831d4f2975572ff26626a0589be94c 100644 (file)
@@ -28,6 +28,8 @@ using namespace std;
 //QT includes
 #include <qlistview.h>
 #include <qwidgetstack.h>
+#include <qtabwidget.h>
+#include <qtextedit.h>
 
 #include "battlesum.h"
 #include "scanview.h"
@@ -51,7 +53,16 @@ BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent)
        m_doc = doc;
        
        m_LeftSplit = new QSplitter(QSplitter::Vertical, this);
-       m_RightSplit = new QSplitter(QSplitter::Vertical, this);
+
+       m_Pages = new QTabWidget(this);
+
+       m_RightSplit = new QSplitter(QSplitter::Vertical);
+       m_Pages->addTab(m_RightSplit, tr("Units"));
+       
+       m_Report = new QTextEdit();
+       m_Report->setReadOnly(true);
+       m_Pages->addTab(m_Report, tr("Report"));
+
 
        //setting up the listview
        m_NumberView = new QListView(m_LeftSplit);
@@ -203,7 +214,13 @@ void BSView::slotFleetSelection(QListViewItem *lvi)
        {
                m_sFleet = lvi->text(0);
                m_sGroup = lvi->parent()->text(0);
-               m_sBattle = lvi->parent()->parent()->text(0);
+               QString temp = lvi->parent()->parent()->text(0);
+
+               if (temp != m_sBattle)
+               {
+                       m_sBattle = temp;
+                       slotGenerateReport();
+               }
 
                updateInfoView();
                updateFleetView();
@@ -449,3 +466,54 @@ void BSView::slotUseScan(int action, QString text, int fleets)
        cerr << "Text: " << text.latin1() << endl;
        cerr << "Fleets: " << fleets << endl;
 }
+
+
+//////////////////////////////////////////////////////////////////////////
+//
+void BSView::slotGenerateReport()
+{
+       const Fleet *fl = m_doc->specificFleet(m_sBattle, "Friendly", "Home Planet");
+       
+       const Planet* pl = dynamic_cast<const Planet*>(fl);
+       if (pl)
+       {
+               ReportList report = pl->report();
+               QString t;
+               
+               t.append("<qt>\n");
+               
+
+               for (ReportList::iterator i = report.begin(); i != report.end(); ++i)
+               {
+                       t.append(QString("Tick number: %0\n").arg(i->first));
+                       t.append("<ul>\n");
+                       for(map<int, map<string, map<string, map<string, int> > > >::iterator j = i->second.begin(); j != i->second.end(); ++j)
+                       {
+                               t.append(QString("<li>Now handling initiative: %0\n").arg(j->first));
+                               t.append("<ul type=circle>\n");
+                               for(map<string, map<string, map<string, int> > >::iterator k = j->second.begin(); k != j->second.end(); ++k)
+                               {
+                                       for(map<string, map<string, int> >::iterator l = k->second.begin(); l != k->second.end(); ++l)
+                                       {
+                                               t.append(QString("<li>%0 %1 %2 killing/blocking at: \n").arg(l->second["000"]).arg(k->first.c_str()).arg(l->first.c_str()));
+                                               t.append("<ul type=square>\n");
+
+                                               t.append("</ul>\n");
+                                               t.append("</li>\n");
+                                       }
+                               }
+                               t.append("</ul>\n");
+                               t.append("</li>\n");
+                       }
+                       t.append("</ul>\n");
+
+                       t.append("<hr>\n");
+               }
+               t.append("</qt>\n");
+               //cerr << t.latin1();
+               m_Report->clear();
+               m_Report->setText(t);
+
+       }
+       //m_Report->append("<b>test\n<b>");
+}
index b87c1c695e4c4cfb753b8a7c7f348ce97e52a57b..86e7b45fc99b9f5e9bb7b00f8597eb34685a8c6d 100644 (file)
@@ -38,6 +38,8 @@ class QListView;
 class QSplitter;
 class QWidgetStack;
 class QListViewItem;
+class QTabWidget;
+class QTextEdit;
 
 /**
  * This class provides an incomplete base for your application view. 
@@ -81,6 +83,8 @@ class BSView : public QSplitter
        FleetView       *m_GenericFleetView;
        BSDoc                   *m_doc;
        std::map<QString, std::map<QString, bool> > m_TreeExpanded;
+       QTabWidget      *m_Pages;
+       QTextEdit       *m_Report;
 
        QString         m_sBattle;
        QString         m_sGroup;
@@ -98,6 +102,7 @@ public slots: // Public slots
   void slotFleetSelection(QListViewItem *lvi);
   void slotItemExpanded(QListViewItem *lvi);
   void slotItemCollapsed(QListViewItem *lvi);
+  void slotGenerateReport();
 };
 
 #endif
index bab852f0bf704b941a00b464771ac7d4fd37960d..cd558a6ae5f2ceff39e69dfa7ef25a0813f908d0 100644 (file)
@@ -449,6 +449,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, in
                                                hitunits[j->first]++;
 
                                                //There is a chance that we're hitting a blocked ship.
+                                               /*Not anymore..
                                                if (m_BlockedFleet[j->first].size() >= 1)
                                                {
                                                        int test = rand() % m_BlockedFleet[j->first][0];
@@ -461,6 +462,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, in
                                                                        m_BlockedFleet[j->first][1]--;
                                                        }
                                                }
+                                               */
                                        }
 
                                }
@@ -477,7 +479,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, in
 
 //////////////////////////////////////////////////////////////////////////
 //
-void Fleet::takeEMP(std::string unittype, int number)
+void Fleet::takeEMP(std::string unittype, int number, std::map<std::string, int>& hitunits)
 {
        int guns = s_Units[unittype].guns() * number;
        if (guns == 0)
index 673eb42037aa9ef965782ff4e1f81f194aedc0c9..9aea01cc6b3a4ab744118eec5b36830f69b7eb52 100644 (file)
@@ -262,7 +262,7 @@ public:
         * very similar stuff in both the take* functions.
         * \sa takeShoot
         */
-       void takeEMP(std::string unittype, int number);
+       void takeEMP(std::string unittype, int number, std::map<std::string, int>& hitunits);
 
        void calculateLostStealships(std::string unittype, std::map<std::string, int> stolen, int tick = 1);
 
index 03a24c9cb995722443080633d7e656f44ec67336..e3290a62d7c4a39d0c25780a13a282cd30012f1f 100644 (file)
@@ -82,6 +82,7 @@ FleetView::~FleetView(){
 //
 void FleetView::viewFleet(const Fleet* fleet, bool friendly)
 {
+       friendly = true;
        if (m_Fleet->race() != fleet->race())
        {
                findNames();
index c819323d76bde827bde8414b7b8c3b620ef2355c..e5aba8575eaed8c659ecc58a4818ec31d2debc2c 100644 (file)
@@ -154,6 +154,8 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
        for (vector<Fleet*>::iterator i = hostile.begin(); i != hostile.end(); ++i)
                (*i)->resetTicks();
 
+       m_Report.clear();
+
        for(int tick = 1; skipped < 20; ++tick)
        {
                //See who's in the battle at the current tick
@@ -237,35 +239,50 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
        for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
                unitsinit[i->second.initiative()] = i->first;
 
+       
+
        for (map<int, string>::iterator i = unitsinit.begin(); i != unitsinit.end(); ++i)
        {
                Fleet* hostiletemp = new Fleet(*hostile);
                Planet* friendlytemp = new Planet(*friendly);
                
                string unittype = i->second;
+               int init = i->first;
+
+               int freefriendly = friendly->freeFleet(unittype, 1);
+               int freehostile = hostile->freeFleet(unittype, 1);
+
+               if ( freefriendly <= 0 && freehostile <= 0)
+                       continue;
 
                //cerr << "Initiative: " << s_Units[unittype].initiative() << " with unit: " << unittype << endl;
+       
+               map<string, int> friendlyhits;
+               map<string, int> hostilehits;
 
                if (s_Units[unittype].type() == "EMP")  
                {
-                       hostiletemp->takeEMP(unittype, friendly->freeFleet(unittype, 1));
-                       friendlytemp->takeEMP(unittype, hostile->freeFleet(unittype, 1));
+                       hostiletemp->takeEMP(unittype, freefriendly, friendlyhits);
+                       friendlytemp->takeEMP(unittype, freehostile, hostilehits);
                }
                else if (s_Units[unittype].type() == "Steal")
                {
-                       hostiletemp->takeShoot(unittype, friendly->freeFleet(unittype, 1), stealfriendly[unittype]);
-                       friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), stealhostile[unittype]);
+                       hostiletemp->takeShoot(unittype, freefriendly, stealfriendly[unittype]);
+                       friendlytemp->takeShoot(unittype, freehostile, stealhostile[unittype]);
+                       
+                       friendlyhits = stealfriendly[unittype];
+                       hostilehits = stealhostile[unittype];
 
                        friendlytemp->calculateLostStealships(unittype, stealfriendly[unittype], 1);
                        hostiletemp->calculateLostStealships(unittype, stealhostile[unittype], 1);
                }
                else
                {
-                       map<string, int> temp;
-                       hostiletemp->takeShoot(unittype, friendly->freeFleet(unittype, 1), temp);
-                       friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), temp);
+                       hostiletemp->takeShoot(unittype, freefriendly, friendlyhits);
+                       friendlytemp->takeShoot(unittype, freehostile, hostilehits);
                }
 
+
                if (s_Units[unittype].type() == "Pod")
                {
                        //FIXME: Prolly need to recode the whole capping section for r7, due to multiple pods thingy
@@ -275,7 +292,7 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
                        {
                                for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid)
                                {
-                                       int caproids = capping(tick) * roids(roid->first, tick - 1);
+                                       int caproids = int(capping(tick) * roids(roid->first, tick - 1));
                                        //int freepods = hostiletemp->freeFleet(unittype, 1);
                
                                        cerr << "Possible to steal " << caproids << " " << roid->first << " roids\n";
@@ -310,6 +327,10 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
 
                        return;
                }
+               m_Report[tick][init]["Friendly"][unittype] = friendlyhits;
+               m_Report[tick][init]["Friendly"][unittype]["000"] = freefriendly;
+               m_Report[tick][init]["Hostile"][unittype] = hostilehits;
+               m_Report[tick][init]["Hostile"][unittype]["000"] = freehostile;
 
                //set the the objects so they point at the modified objects
                *friendly = *friendlytemp;
@@ -367,3 +388,10 @@ void Planet::setCapping(float capping, int tick)
        else
                m_Capping[tick] = 0;
 }
+
+//////////////////////////////////////////////////////////////////////////
+//
+ReportList Planet::report() const
+{
+       return m_Report;
+}
index 95b38936f0ad09da634ecf38c778bbccc188b541..78c00b94531305a2a144227f363b604b821b79fe 100644 (file)
@@ -21,6 +21,7 @@
 #include "fleet.h"
 
 typedef std::map<std::string, std::vector<int> > RoidList;
+typedef std::map<int, std::map<int, std::map<std::string, std::map<std::string, std::map<std::string, int> > > > > ReportList;
 
 /**This class is the implementation of a planet.
  *
@@ -90,6 +91,8 @@ public:
        float capping(int tick = 0);
        void setCapping(float capping, int tick = 0);
 
+       ReportList report() const;
+
 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
@@ -106,6 +109,7 @@ protected:
        std::vector <unsigned> m_Score;
        std::vector <float> m_Capping;
        RoidList m_Roids;
+       ReportList m_Report;
        
 };
 
index ed313f63a5184da2a039d751d82c294b30890d5d..9615c0fcf6b2a780e07df9ab97bbf583234aba65 100644 (file)
     <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>
+    <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 305a4cabf25fa09d254db056f4a30d7c07c20bf6..2f30bb96b58054bf5e6125bae7154eff18602106 100644 (file)
@@ -108,6 +108,7 @@ void BSAppBase::battleSimulate()
        QApplication::setOverrideCursor( Qt::WaitCursor );
 
        doc->runBattleSimulation();
+       view->slotGenerateReport();
        QApplication::restoreOverrideCursor();
 }
 
index 87f63d81e44a8ece1a9097ccf0f7e7afd0e4190a..33594f1bd03e7f109b499a22cd977cce1f0f488f 100644 (file)
@@ -8,8 +8,8 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>719</width>
-            <height>320</height>
+            <width>518</width>
+            <height>371</height>
         </rect>
     </property>
     <property name="caption">