From cb2fabf93c2f6ba8b57833309038adb972f58925 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sun, 30 Jun 2002 04:43:28 +0000 Subject: [PATCH] started to work on the battle report.. almost there =) --- bs/bsview.cpp | 72 +++++++++++++++++++++++++++++++++++++++++-- bs/bsview.h | 5 +++ bs/fleet.cpp | 4 ++- bs/fleet.h | 2 +- bs/fleetview.cpp | 1 + bs/planet.cpp | 44 +++++++++++++++++++++----- bs/planet.h | 4 +++ bs/ui/bsappbase.ui | 10 +++--- bs/ui/bsappbase.ui.h | 1 + bs/ui/scanviewbase.ui | 4 +-- 10 files changed, 128 insertions(+), 19 deletions(-) diff --git a/bs/bsview.cpp b/bs/bsview.cpp index 9212fb1..c6fcc46 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -28,6 +28,8 @@ using namespace std; //QT includes #include #include +#include +#include #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(fl); + if (pl) + { + ReportList report = pl->report(); + QString t; + + t.append("\n"); + + + for (ReportList::iterator i = report.begin(); i != report.end(); ++i) + { + t.append(QString("Tick number: %0\n").arg(i->first)); + t.append("
    \n"); + for(map > > >::iterator j = i->second.begin(); j != i->second.end(); ++j) + { + t.append(QString("
  • Now handling initiative: %0\n").arg(j->first)); + t.append("
      \n"); + for(map > >::iterator k = j->second.begin(); k != j->second.end(); ++k) + { + for(map >::iterator l = k->second.begin(); l != k->second.end(); ++l) + { + t.append(QString("
    • %0 %1 %2 killing/blocking at: \n").arg(l->second["000"]).arg(k->first.c_str()).arg(l->first.c_str())); + t.append("
        \n"); + + t.append("
      \n"); + t.append("
    • \n"); + } + } + t.append("
    \n"); + t.append("
  • \n"); + } + t.append("
\n"); + + t.append("
\n"); + } + t.append("
\n"); + //cerr << t.latin1(); + m_Report->clear(); + m_Report->setText(t); + + } + //m_Report->append("test\n"); +} diff --git a/bs/bsview.h b/bs/bsview.h index b87c1c6..86e7b45 100644 --- a/bs/bsview.h +++ b/bs/bsview.h @@ -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 > 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 diff --git a/bs/fleet.cpp b/bs/fleet.cpp index bab852f..cd558a6 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -449,6 +449,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst]++; //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::mapfirst][1]--; } } + */ } } @@ -477,7 +479,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::map& hitunits) { int guns = s_Units[unittype].guns() * number; if (guns == 0) diff --git a/bs/fleet.h b/bs/fleet.h index 673eb42..9aea01c 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -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& hitunits); void calculateLostStealships(std::string unittype, std::map stolen, int tick = 1); diff --git a/bs/fleetview.cpp b/bs/fleetview.cpp index 03a24c9..e3290a6 100644 --- a/bs/fleetview.cpp +++ b/bs/fleetview.cpp @@ -82,6 +82,7 @@ FleetView::~FleetView(){ // void FleetView::viewFleet(const Fleet* fleet, bool friendly) { + friendly = true; if (m_Fleet->race() != fleet->race()) { findNames(); diff --git a/bs/planet.cpp b/bs/planet.cpp index c819323..e5aba85 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -154,6 +154,8 @@ void Planet::runBattle(std::vector friendly, std::vector hostile for (vector::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::mapsecond.initiative()] = i->first; + + for (map::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 friendlyhits; + map 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 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::mapfirst, 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 > RoidList; +typedef std::map > > > > 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 m_Score; std::vector m_Capping; RoidList m_Roids; + ReportList m_Report; }; diff --git a/bs/ui/bsappbase.ui b/bs/ui/bsappbase.ui index ed313f6..9615c0f 100644 --- a/bs/ui/bsappbase.ui +++ b/bs/ui/bsappbase.ui @@ -615,11 +615,11 @@ helpAbout() battleNew() battleSimulate() - oneTickCheck_toggled( bool b ) - minTickSpin_valueChanged( int i ) - maxTickSpin_valueChanged( int i ) - slotTicksChanged( int i ) - resultModeCombo_activated( int i ) + oneTickCheck_toggled(bool b) + minTickSpin_valueChanged(int i) + maxTickSpin_valueChanged(int i) + slotTicksChanged(int i) + resultModeCombo_activated(int i) diff --git a/bs/ui/bsappbase.ui.h b/bs/ui/bsappbase.ui.h index 305a4ca..2f30bb9 100644 --- a/bs/ui/bsappbase.ui.h +++ b/bs/ui/bsappbase.ui.h @@ -108,6 +108,7 @@ void BSAppBase::battleSimulate() QApplication::setOverrideCursor( Qt::WaitCursor ); doc->runBattleSimulation(); + view->slotGenerateReport(); QApplication::restoreOverrideCursor(); } diff --git a/bs/ui/scanviewbase.ui b/bs/ui/scanviewbase.ui index 87f63d8..33594f1 100644 --- a/bs/ui/scanviewbase.ui +++ b/bs/ui/scanviewbase.ui @@ -8,8 +8,8 @@ 0 0 - 719 - 320 + 518 + 371 -- 2.39.2