+Mon Apr 15 22:17:15 CEST 2002:
+ * Implemented scorechange for the planet. All fleets with "Home" in their name is counted.
#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"
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()));
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);
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()
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;
+}
class BattleSum;
class ScanView;
class InfoView;
-class TickView;
+//class TickView;
class FleetView;
//QT forward declarations
void slotInfoCancel();
void slotInfoNew();
void slotInfoRemove();
+ void slotTickChanged(int min, int max);
+ void slotResultModeChanged( int i);
protected:
QSplitter *m_LeftSplit;
ScanView *m_ScanView;
InfoView *m_InfoView;
- TickView *m_TickView;
+ //TickView *m_TickView;
QWidgetStack *m_FleetViews;
FleetView *m_FleetView;
FleetView *m_GenericFleetView;
QString m_sFleet;
bool m_bMoreDocChanges;
+
+ int m_iMaxTick;
+ int m_iMinTick;
+ int m_iResultMode;
+
public slots: // Public slots
/** No descriptions */
# 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.
Planet::Planet()
{
m_sRace = "Planet";
- m_iScore = 0;
}
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
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);*/
}
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;
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);
}
}
+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);
+ }
+ }
+}
+
* \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)
*/
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
*/
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;
};
<rect>
<x>0</x>
<y>0</y>
- <width>726</width>
- <height>519</height>
+ <width>700</width>
+ <height>534</height>
</rect>
</property>
<property name="caption">
<rect>
<x>0</x>
<y>0</y>
- <width>726</width>
- <height>26</height>
+ <width>700</width>
+ <height>24</height>
</rect>
</property>
<item text="&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>
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);
}
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);
+}