]> ruin.nu Git - hbs.git/commitdiff
the battlereport works now..
authorMichael Andreen <harv@ruin.nu>
Mon, 1 Jul 2002 04:20:31 +0000 (04:20 +0000)
committerMichael Andreen <harv@ruin.nu>
Mon, 1 Jul 2002 04:20:31 +0000 (04:20 +0000)
bs/bsview.cpp
bs/bsview.h
bs/fleet.cpp
bs/fleet.h
bs/planet.cpp

index c6fcc46efe831d4f2975572ff26626a0589be94c..b5e25b0a2c88fe8d21c46ea1faa9af4c7973625d 100644 (file)
@@ -185,6 +185,7 @@ void BSView::slotDocumentChanged()
        }
        m_InfoView->setBattles(battlenames);
        updateInfoView();
+       setCurrentListViewItem();
        updateFleetView();
 }
 
@@ -196,9 +197,28 @@ void BSView::slotFleetSelection(QListViewItem *lvi)
        if (lvi->parent() == '\0')
        {
                m_FleetViews->raiseWidget(0);
+               m_sFleet = QString::null;
+               m_sGroup = QString::null;
+               QString temp = lvi->text(0);
+
+               if (temp != m_sBattle)
+               {
+                       m_sBattle = temp;
+                       slotGenerateReport();
+               }
        }
        else if (lvi->parent()->parent() == '\0')
        {
+               m_sFleet = QString::null;
+               m_sGroup = lvi->text(0);
+               QString temp = lvi->parent()->text(0);
+
+               if (temp != m_sBattle)
+               {
+                       m_sBattle = temp;
+                       slotGenerateReport();
+               }
+
                if (lvi->text(0) == tr("Friendly"))
                {
        //                      m_FleetView->slotAttacker(false);
@@ -477,6 +497,7 @@ void BSView::slotGenerateReport()
        const Planet* pl = dynamic_cast<const Planet*>(fl);
        if (pl)
        {
+               cerr << "generating....." << endl;
                ReportList report = pl->report();
                QString t;
                
@@ -491,6 +512,7 @@ void BSView::slotGenerateReport()
                        {
                                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)
@@ -498,6 +520,12 @@ void BSView::slotGenerateReport()
                                                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");
 
+                                               for(map<string, int>::iterator m = l->second.begin(); m != l->second.end(); ++m)
+                                               {
+                                                       if (m->first != "000")
+                                                               t.append(QString("<li>%0 %1</li>").arg(m->second).arg(m->first.c_str()));
+                                               }
+
                                                t.append("</ul>\n");
                                                t.append("</li>\n");
                                        }
@@ -511,9 +539,46 @@ void BSView::slotGenerateReport()
                }
                t.append("</qt>\n");
                //cerr << t.latin1();
-               m_Report->clear();
+               //m_Report->clear();
                m_Report->setText(t);
 
        }
        //m_Report->append("<b>test\n<b>");
 }
+
+//////////////////////////////////////////////////////////////////////////
+//
+void BSView::setCurrentListViewItem()
+{
+       QListViewItemIterator i(m_NumberView);
+       while ( i.current() != 0)
+       {
+               QListViewItem* lvi = i.current();
+               if (lvi->parent() == '\0')
+               {
+                       if (m_sFleet.isNull() && m_sGroup.isNull() && m_sBattle == lvi->text(0))
+                       {
+                               m_NumberView->setCurrentItem(lvi);
+                               return;
+                       }
+               }
+               else if (lvi->parent()->parent() == '\0')
+               {
+                       if (m_sFleet.isNull() && m_sGroup == lvi->text(0) && m_sBattle == lvi->parent()->text(0))
+                       {
+                               m_NumberView->setCurrentItem(lvi);
+                               return;
+                       }
+               }
+               else 
+               {
+                       if (m_sFleet == lvi->text(0) && m_sGroup == lvi->parent()->text(0) && m_sBattle == lvi->parent()->parent()->text(0))
+                       {
+                               m_NumberView->setCurrentItem(lvi);
+                               return;
+                       }
+               }
+               ++i;    
+       }
+       m_NumberView->setCurrentItem(m_NumberView->firstChild());
+}
index 86e7b45fc99b9f5e9bb7b00f8597eb34685a8c6d..644dc1d4dc018e0df0abe09970975f83f01b4ee0 100644 (file)
@@ -69,6 +69,7 @@ class BSView : public QSplitter
 
        void updateInfoView();
        void updateFleetView();
+       void setCurrentListViewItem();
 
 
        BattleSum       *m_BattleSum;
index cd558a6ae5f2ceff39e69dfa7ef25a0813f908d0..01ceb2b930e0cc70c3c6e24077822b18f892bd00 100644 (file)
@@ -119,11 +119,11 @@ void Fleet::setUnits(UnitList& units)
        s_Units = units;
 
 
-       
+/*     
           for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); i++)
           {
                   cerr << s_Units[(*i).first].Name() << "\t\t"
-/*                << s_Units[(*i).first].race() <<"\t"
+                  << s_Units[(*i).first].race() <<"\t"
                   << s_Units[(*i).first].unitClass() << "\t"
                   << s_Units[(*i).first].target(0) << "\t"
                   << s_Units[(*i).first].target(1) << "\t"
@@ -137,9 +137,10 @@ void Fleet::setUnits(UnitList& units)
                   << 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].ETA() << "\t"
                   << s_Units[(*i).first].type() << endl;
           }
+          */
 }
 
 //////////////////////////////////////////////////////////////////////////
@@ -315,12 +316,12 @@ void Fleet::distributeLossesGains(std::vector<Fleet*> fleets, int tick)
                {
                        int fl1 = (*j)->fleet(unittype, tick - 1);
                        float part = float(fl1) / fleet(unittype, 0) ;
-                       int lost =  totallost * part;
+                       int lost =  int(totallost * part);
                        (*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick);
 
                        cerr << (*j)->name() << " gaining " << lost << " " << unittype  << " since it's " << part * 100 << "% of the whole fleet, and it had : " << fl1 << " units last tick.." <<  endl;
 
-                       lost = part * blockedFleet(unittype, 0);
+                       lost = int(part * blockedFleet(unittype, 0));
 
                        cerr << (*j)->name() << " got " << lost << " blocked " << unittype  << ", the total number of blocked ships was: " << blockedFleet(unittype, 0) << endl; 
 
@@ -331,7 +332,7 @@ void Fleet::distributeLossesGains(std::vector<Fleet*> fleets, int tick)
 
 //////////////////////////////////////////////////////////////////////////
 //
-std::vector<Fleet*> Fleet::calculateSide(std::vector<Fleet*> fleets, int stays, int tick)
+std::vector<Fleet*> Fleet::calculateSide(std::vector<Fleet*> fleets, int tick)
 {
        vector<Fleet*> fl;
        for (vector<Fleet*>::iterator i = fleets.begin(); i != fleets.end(); ++i)
@@ -379,13 +380,13 @@ void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, in
        if (guns == 0)
                return;
 
-       cerr << number << " " << unittype << ": with " << guns << " guns\n";
+       //cerr << number << " " << unittype << ": with " << guns << " guns\n";
 
        float gunsleft = guns;
        for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
        {
                string ta = s_Units[unittype].target(count);
-               cerr << "Shooting at target class: " << ta << endl;
+               //cerr << "Shooting at target class: " << ta << endl;
                while (gunsleft > 0)
                {
 
@@ -467,7 +468,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, in
 
                                }
 
-                               cerr << hitunits[j->first] << " units of type: " << j->first << "killed\n";
+                               //cerr << hitunits[j->first] << " units of type: " << j->first << "killed\n";
                                if (k <= 0)
                                        gunsleft -= maxguns;
                                else
@@ -485,13 +486,13 @@ void Fleet::takeEMP(std::string unittype, int number, std::map<std::string, int>
        if (guns == 0)
                return;
 
-       cerr << unittype << ": with " << guns << " guns\n";
+       //cerr << unittype << ": with " << guns << " guns\n";
 
        float gunsleft = guns;
        for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
        {
                string ta = s_Units[unittype].target(count);
-               cerr << "Shooting at target class: " << ta << endl;
+               //cerr << "Shooting at target class: " << ta << endl;
                while (gunsleft > 0)
                {
 
@@ -532,7 +533,7 @@ void Fleet::takeEMP(std::string unittype, int number, std::map<std::string, int>
                        for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
                        {
                                float maxguns = float((*j->second))/total * guns;
-                               cerr << "Now shooting at target: " << j->first << endl;
+                               //cerr << "Now shooting at target: " << j->first << endl;
 
                                double k = maxguns;
 
@@ -548,10 +549,11 @@ void Fleet::takeEMP(std::string unittype, int number, std::map<std::string, int>
 
                                        k -= float(100)/(100-eres);
                                        hits++;
+                                       hitunits[j->first]++;
                                        blockFleet(j->first, 1);
                                }
 
-                               cerr << hits << " units of type: " << j->first << " blocked\n";
+                               //cerr << hits << " units of type: " << j->first << " blocked\n";
                                if (k <= 0)
                                        gunsleft -= maxguns;
                                else
@@ -706,7 +708,7 @@ void Fleet::distributeCappedRoids(std::vector<Fleet*> fleets, int tick)
                {
                        unsigned fl1 = (*j)->score(tick - 1);
                        float part = float(fl1) / score(0) ;
-                       int lost =  totcapped * part;
+                       int lost =  int(totcapped * part);
 
                        cerr << (*j)->name() << " gaining " << lost << " " << res  << " since it's " << part * 100 << "% of the whole score, and it had : " << fl1 << " score last tick.. compared to fleet total of: " << score(0) <<  endl;
 
@@ -745,10 +747,10 @@ void Fleet::calculateLostStealships(string unittype, std::map<std::string, int>
        int stealscore = 0;
        for (map<string, int>::iterator i = stolen.begin(); i != stolen.end(); ++i)
        {
-               stealscore += stolen[i->first] * (s_Units[i->first].totRes() / 10.0);   
+               stealscore += int(stolen[i->first] * (s_Units[i->first].totRes() / 10.0));      
        }
 
-       int lost = stealscore / (s_Units[unittype].totRes() / 10.0);
+       int lost = int(stealscore / (s_Units[unittype].totRes() / 10.0));
 
        cerr << "Lost " << lost << " " << unittype << " due to stealing ships worth: " << stealscore << endl; 
        killFleet(unittype, lost, tick);
@@ -768,7 +770,7 @@ void Fleet::distributeStolenShips(std::map<std::string, std::map<std::string, in
                {
                        for (vector<Fleet*>::iterator k = fleets.begin(); k != fleets.end(); ++k)
                        {
-                               int stolen = float ((*k)->fleet(i->first, tick - 1)) / totalstealers * j->second;
+                               int stolen = int(float ((*k)->fleet(i->first, tick - 1)) / totalstealers * j->second);
                                (*k)->addFleet(j->first, stolen, tick);
                        }
                }
@@ -796,7 +798,7 @@ void Fleet::calculateSalvage()
                                continue;
                        cerr << "(" << tick << ":" << fleet(i->first, tick) << ") ";
                        for (map<string, int>::iterator k = res.begin(); k != res.end(); ++k)
-                               addResource(k->first, lostunits * k->second * 0.25, tick);
+                               addResource(k->first, int(lostunits * k->second * 0.25), tick);
                }
        }
 }
index 9aea01cc6b3a4ab744118eec5b36830f69b7eb52..6946d3c5ae9521ae8c7da30662684705ce47d33c 100644 (file)
@@ -179,7 +179,7 @@ public:
         * and are staying long enough.
         * \todo add the stays part as a integrated part of each fleet.
         */
-       std::vector<Fleet*> calculateSide(std::vector<Fleet*> fleets, int stays = 0, int tick = 0);
+       std::vector<Fleet*> calculateSide(std::vector<Fleet*> fleets, int tick = 0);
 
        /** Kill some ships of the specified type in the current fleet.
         * \param unittype the name of the unit to kill
index e5aba8575eaed8c659ecc58a4818ec31d2debc2c..94fa4325c2bcea641bbe984942caba991ca13e77 100644 (file)
@@ -159,8 +159,8 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
        for(int tick = 1; skipped < 20; ++tick)
        {
                //See who's in the battle at the current tick
-               vector<Fleet*> friends = calculateSide(friendly, 6, tick);
-               vector<Fleet*> hostiles = calculateSide(hostile, 3, tick);
+               vector<Fleet*> friends = calculateSide(friendly, tick);
+               vector<Fleet*> hostiles = calculateSide(hostile, tick);
 
                // No idea to calculate anything if noone is there.. ;)
                if (hostiles.size() == 0)
@@ -327,10 +327,16 @@ 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;
+               if (freefriendly > 0)
+               {
+                       m_Report[tick][init]["Friendly"][unittype] = friendlyhits;
+                       m_Report[tick][init]["Friendly"][unittype]["000"] = freefriendly;
+               }
+               if (freehostile > 0)
+               {
+                       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;