t1 >> temp;
units[race].setRace(temp.toInt());
t1 >> temp;
- units[race].setClass((const char*) temp);
+ units[race].setUnitClass((const char*) temp);
t1 >> temp;
units[race].addTarget((const char*) temp);
t1 >> temp;
#include "bsdoc.h"
+#include "planet.h"
+
using namespace std;
BSDoc::BSDoc()
bool BSDoc::saveAs(const QString &filename)
{
+ QString test = filename;
return true;
}
bool BSDoc::load(const QString &filename)
{
- emit documentChanged();
+ QString test = filename;
+ emit documentChanged();
return true;
}
int BSDoc::newBattle(QString name)
{
- m_Battles[name]["Friendly"]["Home Planet"].setRace("Planet");
- m_Battles[name]["Friendly"]["Home Fleet"];
+ m_Battles[name]["Friendly"]["Home Planet"] = new Planet();;
+ m_Battles[name]["Friendly"]["Home Fleet"] = new Fleet();
m_Battles[name]["Hostile"];
+ //Planet* pl = dynamic_cast<Planet*>(m_Battles[name]["Friendly"]["Home Planet"]);
modified = true;
emit documentChanged();
return 0;
/////////////////////////////////////////////////////////////////////////
//
-const std::map<QString, std::map<QString, std::map<QString, Fleet> > >& BSDoc::battles() const
+const BattleList& BSDoc::battles() const
{
return m_Battles;
}
//////////////////////////////////////////////////////////////////////////
//
-Fleet BSDoc::specificFleet(QString battle, QString group, QString fleet) const
+const Fleet* BSDoc::specificFleet(QString battle, QString group, QString fleet) const
{
- for (map<QString, map<QString, map<QString, Fleet> > >::const_iterator i = m_Battles.begin(); i != m_Battles.end(); ++i)
+ for (BattleList::const_iterator i = m_Battles.begin(); i != m_Battles.end(); ++i)
{
if (i->first == battle)
{
- for (map<QString, map<QString, Fleet> >::const_iterator j = i->second.begin(); j != i->second.end(); j++)
+ for (map<QString, map<QString, Fleet*> >::const_iterator j = i->second.begin(); j != i->second.end(); j++)
{
if (j->first == group)
{
- for (map<QString, Fleet>::const_iterator k = j->second.begin(); k != j->second.end(); ++k)
+ for (map<QString, Fleet*>::const_iterator k = j->second.begin(); k != j->second.end(); ++k)
{
if (k->first == fleet)
{
}
}
}
- return Fleet();
+ return '\0';
}
// application specific includes
#include "fleet.h"
+typedef std::map<QString, std::map<QString, std::map<QString, Fleet*> > > BattleList;
//! The document class
/** This class is holding all the data, handles the transportation of the
* data to a couple of different mediums and informs users of the data
* change it.
* \todo remove this, and replace it with a better more closed interface.
*/
- const std::map<QString, std::map<QString, std::map<QString, Fleet> > >& battles() const;
+ const BattleList& battles() const;
- Fleet specificFleet(QString battle, QString group, QString fleet) const;
+
+ /**Looks for the fleet with the specified name, in the specified group in the
+ * specified battle.
+ * \return Returns '\0' (NULL) if the fleet isn't found, if it is found it
+ * returns a const pointer to the fleet.
+ */
+ const Fleet* specificFleet(QString battle, QString group, QString fleet) const;
signals:
void documentChanged();
* -# The fleetname (Home Planet, coordinates, irc nicks and so on)
* - and in the end you got the actual Fleet object with it's data.
*/
- std::map<QString, std::map<QString, std::map<QString, Fleet> > > m_Battles;
+ BattleList m_Battles;
};
#endif
m_NumberView->addColumn("Name");
m_NumberView->addColumn("Number");
m_NumberView->addColumn("ETA");
+ m_NumberView->addColumn("Score");
//addBattle("NO BATTLES");
//the widget stack
m_BattleSum = new BattleSum();
m_FleetViews->addWidget(m_BattleSum, 0);
- m_FleetView = new FleetView(fl1, true, true);
+ m_FleetView = new FleetView(&fl1, true);
m_FleetViews->addWidget(m_FleetView, 1);
- m_GenericFleetView = new FleetView(fl2, true, false);
+ m_GenericFleetView = new FleetView(&fl2, true);
m_FleetViews->addWidget(m_GenericFleetView, 2);
//m_FleetViews->raiseWidget(0);
connect(m_NumberView, SIGNAL(selectionChanged(QListViewItem *)), SLOT(slotFleetSelection(QListViewItem *)));
{
m_NumberView->clear();
- const map<QString, map<QString, map<QString, Fleet> > >& battles = m_doc->battles();
+ const BattleList& battles = m_doc->battles();
- for (map<QString, map<QString, map<QString, Fleet> > >::const_iterator i = battles.begin(); i != battles.end(); ++i)
+ for (BattleList::const_iterator i = battles.begin(); i != battles.end(); ++i)
{
QString b = (*i).first;
QListViewItem* battle = new QListViewItem(m_NumberView, b);
battle->setOpen(m_TreeExpanded[b]["--"]);
- for (map<QString, map<QString, Fleet> >::const_iterator j = i->second.begin(); j != i->second.end(); ++j)
+ for (map<QString, map<QString, Fleet*> >::const_iterator j = i->second.begin(); j != i->second.end(); ++j)
{
QString g = (*j).first;
QListViewItem* group = new QListViewItem(battle, g);
int groupShips = 0;
+ unsigned groupScore = 0;
group->setOpen(m_TreeExpanded[b][g]);
- for (map<QString, Fleet>::const_iterator k = j->second.begin(); k != j->second.end(); ++k)
+ for (map<QString, Fleet*>::const_iterator k = j->second.begin(); k != j->second.end(); ++k)
{
- int ships = k->second.NumberOfShips();
+ int ships = k->second->numberOfShips();
+ unsigned score = k->second->score();
groupShips += ships;
- (void) new QListViewItem(group, (*k).first, QString("%1").arg(ships), QString("%1").arg(k->second.ETA()));
+ groupScore += score;
+ (void) new QListViewItem(group, (*k).first, QString("%1").arg(ships), QString("%1").arg(k->second->ETA()), QString("%1").arg(score));
}
group->setText(1, QString("%1").arg(groupShips));
+ group->setText(3, QString("%1").arg(groupScore));
}
}
}
}
else
{
- bool home = false;
bool friendly = false;
+ bool home = false;
QString fleet = lvi->text(0);
QString group = lvi->parent()->text(0);
QString battle = lvi->parent()->parent()->text(0);
if ( group == tr("Friendly"))
{
friendly = true;
- if ( fleet == tr("Home Planet"))
- {
- home = true;
- }
+ if(fleet == tr("Home Planet"))
+ home=true;
}
- Fleet fl = m_doc->specificFleet(battle, group, fleet);
- m_InfoView->setRace(fl.Race().c_str());
+ const Fleet* fl = m_doc->specificFleet(battle, group, fleet);
+ m_InfoView->setRace(fl->race().c_str());
m_InfoView->setFleetName(fleet);
- m_InfoView->setEta(fl.ETA());
- if (fl.Race() == tr("Generic").latin1())
+ m_InfoView->setEta(fl->ETA());
+ if (fl->race() == tr("Generic").latin1())
{
m_GenericFleetView->viewFleet(fl, friendly);
m_FleetViews->raiseWidget(2);
}
else
{
- if (fl.Race() == m_FleetView->fleet().Race() &&
+ if (fl->race() == m_FleetView->fleet()->race() &&
m_FleetView->isHome() == home)
{
m_FleetView->viewFleet(fl, friendly);
else
{
m_FleetViews->removeWidget(m_FleetView);
- m_FleetView = new FleetView(fl, friendly, home);
+ m_FleetView = new FleetView(fl, friendly);
m_FleetViews->addWidget(m_FleetView, 1);
}
m_FleetViews->raiseWidget(1);
//////////////////////////////////////////////////////////////////////////
//
-string Fleet::Name() const
+string Fleet::name() const
{
return m_sName;
}
//////////////////////////////////////////////////////////////////////////
//
-string Fleet::Race() const
+string Fleet::race() const
{
return m_sRace;
}
/** This function iterates through m_Fleet and adds all numbers together to
* produce a total.
*/
-int Fleet::NumberOfShips() const
+int Fleet::numberOfShips() const
{
int total = 0;
{
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].Class() << "\t"
- << s_Units[(*i).first].Target(0) << "\t"
- << s_Units[(*i).first].Target(1) << "\t"
- << s_Units[(*i).first].Target(2) << "\t"
- << s_Units[(*i).first].Initiative() << "\t"
- << s_Units[(*i).first].Agility() << "\t"
- << s_Units[(*i).first].WeaponSpeed() << "\t"
- << s_Units[(*i).first].Guns() << "\t"
- << s_Units[(*i).first].Power() << "\t"
- << s_Units[(*i).first].Armor() << "\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"
+ << s_Units[(*i).first].target(2) << "\t"
+ << s_Units[(*i).first].initiative() << "\t"
+ << s_Units[(*i).first].agility() << "\t"
+ << s_Units[(*i).first].weaponSpeed() << "\t"
+ << s_Units[(*i).first].guns() << "\t"
+ << s_Units[(*i).first].power() << "\t"
+ << s_Units[(*i).first].armor() << "\t"
<< s_Units[(*i).first].EMP() << "\t"
- << s_Units[(*i).first].TotRes() << "\t"
- << s_Units[(*i).first].Fuel() << "\t"
+ << s_Units[(*i).first].totRes() << "\t"
+ << s_Units[(*i).first].fuel() << "\t"
<< s_Units[(*i).first].ETA() << "\t"
- << s_Units[(*i).first].Type() << endl;
+ << s_Units[(*i).first].type() << endl;
}
+ */
}
//////////////////////////////////////////////////////////////////////////
return s_Races[m_sRace];
}
+//////////////////////////////////////////////////////////////////////////
+//
+unsigned Fleet::score(int tick = 0) const
+{
+ unsigned tot_score = 0;
+
+ for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
+ {
+ tot_score += i->second[tick] * s_Units[i->first].totRes() / 10;
+ }
+
+ return tot_score;
+}
+
#include "unittype.h"
template<typename T> class MyComp { public: bool operator()(T,T) { return false; } };
-
+typedef std::map<std::string, std::vector<int> > FleetList;
typedef std::map<std::string, UnitType> UnitList;
+typedef std::map<std::string, std::vector<int> > RaceList;
//!This is the engine for the whole battlesystem.
/**This is the engine for the whole battlesystem.
* One of the few parts that I plan make fully portable.
{
public:
Fleet();
- ~Fleet();
+ virtual ~Fleet();
/**Sets the name that represents this fleet. Might be different a name
* like foobar or some coordinates like 1:1:1. The name doesn't have to be unique,
/**Returns the name of this fleet.
* \see setName
*/
- std::string Name() const;
+ std::string name() const;
/**The race string decides what type of ships this fleet can have.
* The values must be feeded into this class.
* \return The race, represented as a string.
* \see setRace
*/
- std::string Race() const;
+ std::string race() const;
std::vector<int> RacesAllowed() const;
/**Returns the total number of ships in this fleet
*/
- int NumberOfShips() const;
+ int numberOfShips() const;
/**Sets the estimated time of arrival. The time as a single integer,
* in relation to the current time. For example if the current time is
*/
int ETA() const;
- static void setRaces(std::map<std::string, std::vector<int> >& races);
+
+ /**Returns the score. This value is the total resources spent on this fleet
+ * devided with 10.
+ * \param tick tells the function what tick you want the score from. 0 is
+ * initial score before the fleet has landed.
+ */
+ virtual unsigned score(int tick = 0) const;
+
+ static void setRaces(RaceList& races);
static void setUnits(UnitList& units);
- static const std::map<std::string, std::vector<int> >& Races();
+ static const RaceList& Races();
static const UnitList& Units();
protected:
std::string m_sName;
std::string m_sRace;
int m_iETA;
- std::map<std::string, std::vector<int> > m_Fleet;
+ FleetList m_Fleet;
static UnitList s_Units;
- static std::map<std::string, std::vector<int> > s_Races;
+ static RaceList s_Races;
};
#endif
<rect>
<x>0</x>
<y>0</y>
- <width>263</width>
+ <width>293</width>
<height>117</height>
</rect>
</property>
<slot>RemoveButton_clicked()</slot>
</connection>
</connections>
+<tabstops>
+ <tabstop>NameLine</tabstop>
+ <tabstop>EtaSpin</tabstop>
+ <tabstop>RaceCombo</tabstop>
+ <tabstop>ApplyButton</tabstop>
+ <tabstop>CancelButton</tabstop>
+ <tabstop>NewButton</tabstop>
+ <tabstop>RemoveButton</tabstop>
+</tabstops>
<includes>
<include location="global" impldecl="in declaration">vector</include>
<include location="local" impldecl="in implementation">infoview.ui.h</include>
<rect>
<x>0</x>
<y>0</y>
- <width>241</width>
- <height>75</height>
+ <width>222</width>
+ <height>103</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>32767</width>
- <height>90</height>
+ <height>110</height>
</size>
</property>
<property name="caption">
<string>QGroupBoxForm</string>
</property>
<property name="title">
- <string>Resources</string>
+ <string>Resources and Score</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<property name="margin">
- <number>3</number>
+ <number>11</number>
</property>
<property name="spacing">
- <number>0</number>
+ <number>6</number>
</property>
- <widget class="QLabel" row="0" column="3">
- <property name="name">
- <cstring>uninitLabel</cstring>
- </property>
- <property name="text">
- <string>Uninit</string>
- </property>
- </widget>
<widget class="QLabel" row="0" column="1">
<property name="name">
<cstring>crystalLabel</cstring>
<string>Crystal</string>
</property>
</widget>
- <widget class="QLabel" row="0" column="0">
+ <widget class="QLabel" row="0" column="2">
<property name="name">
- <cstring>metalLabel</cstring>
+ <cstring>eoniumLabel</cstring>
</property>
<property name="text">
- <string>Metal</string>
+ <string>Eonium</string>
</property>
</widget>
- <widget class="QLineEdit" row="1" column="0">
+ <widget class="QLineEdit" row="1" column="3">
<property name="name">
- <cstring>MetalLine</cstring>
+ <cstring>EoniumLine</cstring>
</property>
<property name="focusPolicy">
<enum>NoFocus</enum>
<bool>true</bool>
</property>
</widget>
- <widget class="QLabel" row="0" column="2">
+ <widget class="QLabel" row="0" column="0">
<property name="name">
- <cstring>eoniumLabel</cstring>
+ <cstring>metalLabel</cstring>
</property>
<property name="text">
- <string>Eonium</string>
+ <string>Metal</string>
</property>
</widget>
<widget class="QLineEdit" row="1" column="2">
<bool>true</bool>
</property>
</widget>
- <widget class="QLineEdit" row="1" column="3">
+ <widget class="QLineEdit" row="2" column="1">
<property name="name">
- <cstring>EoniumLine</cstring>
+ <cstring>ScoreEdit</cstring>
+ </property>
+ <property name="focusPolicy">
+ <enum>NoFocus</enum>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="1" column="0">
+ <property name="name">
+ <cstring>MetalLine</cstring>
+ </property>
+ <property name="focusPolicy">
+ <enum>NoFocus</enum>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QLabel" row="0" column="3">
+ <property name="name">
+ <cstring>uninitLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Uninit</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="2" column="0">
+ <property name="name">
+ <cstring>ScoreLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Score:</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="2" column="2">
+ <property name="name">
+ <cstring>ScoreLostLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Lost</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="2" column="3">
+ <property name="name">
+ <cstring>ScoreLostEdit</cstring>
</property>
<property name="focusPolicy">
<enum>NoFocus</enum>
<rect>
<x>0</x>
<y>0</y>
- <width>289</width>
- <height>100</height>
+ <width>219</width>
+ <height>103</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>32767</width>
- <height>110</height>
+ <height>119</height>
</size>
</property>
<property name="caption">
<string>Roids</string>
</property>
<property name="title">
- <string>Roids</string>
+ <string>Roids and Score</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<property name="margin">
- <number>3</number>
+ <number>2</number>
</property>
<property name="spacing">
<number>0</number>
<bool>true</bool>
</property>
</widget>
- <widget class="QLabel" row="2" column="0">
- <property name="name">
- <cstring>TextLabel6</cstring>
- </property>
- <property name="text">
- <string>Lost</string>
- </property>
- </widget>
<widget class="QLabel" row="0" column="4">
<property name="name">
<cstring>uninitLabel</cstring>
<bool>true</bool>
</property>
</widget>
+ <widget class="QLabel" row="2" column="0">
+ <property name="name">
+ <cstring>TextLabel6</cstring>
+ </property>
+ <property name="text">
+ <string>Lost</string>
+ </property>
+ </widget>
+ <widget class="QLabel" row="3" column="0">
+ <property name="name">
+ <cstring>ScoreLine</cstring>
+ </property>
+ <property name="text">
+ <string>&Score</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>ScoreEdit</cstring>
+ </property>
+ </widget>
+ <widget class="QLineEdit" row="3" column="1" rowspan="1" colspan="4">
+ <property name="name">
+ <cstring>ScoreEdit</cstring>
+ </property>
+ </widget>
</grid>
</widget>
+<tabstops>
+ <tabstop>LineEdit26</tabstop>
+ <tabstop>LineEdit29</tabstop>
+ <tabstop>LineEdit31</tabstop>
+ <tabstop>LineEdit32</tabstop>
+</tabstops>
<includes>
<include location="local" impldecl="in implementation">roidseditview.ui.h</include>
</includes>
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::Race() const
+int UnitType::race() const
{
return m_iRace;
}
//////////////////////////////////////////////////////////////////////////
//
-void UnitType::setClass(string sClass)
+void UnitType::setUnitClass(string sClass)
{
m_sClass = sClass;
}
//////////////////////////////////////////////////////////////////////////
//
-string UnitType::Class() const
+string UnitType::unitClass() const
{
return m_sClass;
}
//////////////////////////////////////////////////////////////////////////
//
-vector<string> UnitType::Target() const
+vector<string> UnitType::target() const
{
return m_vTarget;
}
//////////////////////////////////////////////////////////////////////////
//
-string UnitType::Target(int index) const
+string UnitType::target(int index) const
{
return m_vTarget[index];
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::Initiative() const
+int UnitType::initiative() const
{
return m_iInitiative;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::Agility() const
+int UnitType::agility() const
{
return m_iAgility;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::WeaponSpeed() const
+int UnitType::weaponSpeed() const
{
return m_iWeaponSpeed;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::Guns() const
+int UnitType::guns() const
{
return m_iGuns;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::Power() const
+int UnitType::power() const
{
return m_iPower;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::Armor() const
+int UnitType::armor() const
{
return m_iArmor;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::TotRes() const
+int UnitType::totRes() const
{
return m_iTotalResources;
}
//////////////////////////////////////////////////////////////////////////
//
-int UnitType::Fuel() const
+int UnitType::fuel() const
{
return m_iFuel;
}
//////////////////////////////////////////////////////////////////////////
//
-string UnitType::Type() const
+string UnitType::type() const
{
return m_sType;
}
/** This functions sets which race this unittype is, the race is represented with a integer. */
void setRace(int iRace);
/** Returns the race this unittype belongs to*/
- int Race() const;
+ int race() const;
/** Sets the class for the unittype, it's represented as a integer */
- void setClass(std::string sClass);
- std::string Class() const;
+ void setUnitClass(std::string sClass);
+ std::string unitClass() const;
/** Sets the classes that this unittype targets. a vector is used. */
void setTarget(std::vector<std::string> Target);
* \param index where to place the target. 0 being the default and first place. */
void insTarget(std::string iTarget, int index = 0);
/** Returns all targets from the target list */
- std::vector<std::string> Target() const;
+ std::vector<std::string> target() const;
/** Returns a specific target
* \param index An index value that represents the target. 0 being the first*/
- std::string Target(int index) const;
+ std::string target(int index) const;
/** Sets the initiatve, the lower it is the earlier the unit shots */
void setInitiative(int iInit);
- int Initiative() const;
+ int initiative() const;
/** Sets the agility, the higher it is the harder it is to hit the unit */
void setAgility (int iAgil);
- int Agility() const;
+ int agility() const;
/** Sets the weaponspeed.. just a simple integer that shows how good it is at hitting things */
void setWeaponSpeed(int iWPSP);
- int WeaponSpeed() const;
+ int weaponSpeed() const;
/** Sets the number of guns. */
void setGuns(int iGuns);
- int Guns() const;
+ int guns() const;
/** Sets the how much power the guns have.. or in other words: the damage they do. */
void setPower(int iPower);
- int Power() const;
+ int power() const;
/** Sets the armor, this is how much damage the unittype can take before it's destroyed */
void setArmor(int iArmor);
- int Armor() const;
+ int armor() const;
/** Sets the emp resistance, the lower value the easier it is to block it */
void setEMP(int iEMP);
/** Sets the resource cost for this unittype. Used for example for score calculation and so on. */
void setTotalResources(int iTR);
/** Returns the number of total resources this unittype cost. */
- int TotRes() const;
+ int totRes() const;
/** Sets the fuelcost for this unittype */
void setFuel(int iFuel);
/** Returns the fuelcost */
- int Fuel() const;
+ int fuel() const;
/** Sets the ETA, the speed in a sort of inverted form.. the lower ETA, the faster is the unit */
void setETA(int iETA);
* \param iType An integer to symbolise the type. */
void setType(std::string type);
/** What type of ship this is. */
- std::string Type() const;
+ std::string type() const;
+
protected:
std::string m_sName;
int m_iRace; //!< Not really the race, but an indiaction on what race can use it..