From bb4169deef42f91b6afa4c4561f9339fba040f01 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Tue, 16 Apr 2002 01:11:26 +0000 Subject: [PATCH] moving the tick changing to the toolbar instead of CTickView. adding a combobox to set the what to show in the fleetview too. --- ChangeLog | 2 + bs/bsview.cpp | 37 ++++++++++-- bs/bsview.h | 11 +++- bs/docs/api/hbs.doxconf | 2 +- bs/planet.cpp | 64 +++++++++++++++++--- bs/planet.h | 14 ++++- bs/ui/bsappbase.ui | 125 ++++++++++++++++++++++++++++++++++++++-- bs/ui/bsappbase.ui.h | 57 +++++++++++++++++- 8 files changed, 288 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index e69de29..6f675f8 100644 --- 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. diff --git a/bs/bsview.cpp b/bs/bsview.cpp index ccf3341..54f7f48 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -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; +} diff --git a/bs/bsview.h b/bs/bsview.h index 16acc2b..391a777 100644 --- a/bs/bsview.h +++ b/bs/bsview.h @@ -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 */ diff --git a/bs/docs/api/hbs.doxconf b/bs/docs/api/hbs.doxconf index 3250a6b..ed78a97 100644 --- a/bs/docs/api/hbs.doxconf +++ b/bs/docs/api/hbs.doxconf @@ -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. diff --git a/bs/planet.cpp b/bs/planet.cpp index c374a99..1f904f8 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -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 friendly, std::vector 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 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::mapfirst, 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 friendly, int tick = 1) +{ + for (vector::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); + } + } +} + diff --git a/bs/planet.h b/bs/planet.h index c729ebf..486bd60 100644 --- a/bs/planet.h +++ b/bs/planet.h @@ -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 friendly, std::vector hostile); + void calculateScoreLoss(std::vector 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 >& stealfriendly, std::map >& stealhostile, int tick = 0); - unsigned m_iScore; + std::vector m_Score; RoidList m_Roids; }; diff --git a/bs/ui/bsappbase.ui b/bs/ui/bsappbase.ui index ed97f11..651e4d3 100644 --- a/bs/ui/bsappbase.ui +++ b/bs/ui/bsappbase.ui @@ -8,8 +8,8 @@ 0 0 - 726 - 519 + 700 + 534 @@ -24,8 +24,8 @@ 0 0 - 726 - 26 + 700 + 24 @@ -70,6 +70,78 @@ + + + + TextLabel3 + + + Show result as: + + + + + resultModeCombo + + + + Killed units + + + + + Blocked units + + + + + Survived unts + + + + + New (stolen) untis + + + + + + + TextLabel1 + + + From tick: + + + + + minTickSpin + + + 0 + + + + + TextLabel2 + + + to: + + + + + maxTickSpin + + + + + oneTickCheck + + + One tick only + + @@ -471,6 +543,42 @@ BSAppBase battleSimulate() + + oneTickCheck + toggled(bool) + BSAppBase + oneTickCheck_toggled(bool) + + + resultModeCombo + activated(int) + BSAppBase + resultModeCombo_activated(int) + + + minTickSpin + valueChanged(int) + BSAppBase + slotTicksChanged(int) + + + minTickSpin + valueChanged(int) + BSAppBase + minTickSpin_valueChanged(int) + + + maxTickSpin + valueChanged(int) + BSAppBase + slotTicksChanged(int) + + + maxTickSpin + valueChanged(int) + BSAppBase + maxTickSpin_valueChanged(int) + qapplication.h @@ -490,6 +598,10 @@ BSView* view BSDoc* doc + + ticksChanged(int, int); + resultModeChanged(int); + fileNew() fileOpen() @@ -508,6 +620,11 @@ helpAbout() battleNew() battleSimulate() + 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 8d5da68..03b081c 100644 --- a/bs/ui/bsappbase.ui.h +++ b/bs/ui/bsappbase.ui.h @@ -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); +} -- 2.39.2