From 5940cfda3be2c7b4ecbd64c814948b29139177c0 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 4 Apr 2002 20:00:56 +0000 Subject: [PATCH] changed my internal structure from Fleet to Fleet* --- bs/bsconf.cpp | 2 +- bs/bsdoc.cpp | 23 ++++++----- bs/bsdoc.h | 13 +++++-- bs/bsview.cpp | 41 ++++++++++---------- bs/fleet.cpp | 51 ++++++++++++++++--------- bs/fleet.h | 27 ++++++++----- bs/ui/infoview.ui | 11 +++++- bs/ui/resourceview.ui | 86 ++++++++++++++++++++++++++++++------------ bs/ui/roidseditview.ui | 48 ++++++++++++++++------- bs/unittype.cpp | 28 +++++++------- bs/unittype.h | 29 +++++++------- 11 files changed, 235 insertions(+), 124 deletions(-) diff --git a/bs/bsconf.cpp b/bs/bsconf.cpp index 97e3c7c..874d6b9 100644 --- a/bs/bsconf.cpp +++ b/bs/bsconf.cpp @@ -85,7 +85,7 @@ bool BSConf::loadStats() 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; diff --git a/bs/bsdoc.cpp b/bs/bsdoc.cpp index 47688a7..5bf5f46 100644 --- a/bs/bsdoc.cpp +++ b/bs/bsdoc.cpp @@ -17,6 +17,8 @@ #include "bsdoc.h" +#include "planet.h" + using namespace std; BSDoc::BSDoc() @@ -39,12 +41,14 @@ bool BSDoc::save() 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; } @@ -58,10 +62,11 @@ bool BSDoc::isModified() const 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(m_Battles[name]["Friendly"]["Home Planet"]); modified = true; emit documentChanged(); return 0; @@ -70,24 +75,24 @@ int BSDoc::newBattle(QString name) ///////////////////////////////////////////////////////////////////////// // -const std::map > >& 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 > >::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 >::const_iterator j = i->second.begin(); j != i->second.end(); j++) + for (map >::const_iterator j = i->second.begin(); j != i->second.end(); j++) { if (j->first == group) { - for (map::const_iterator k = j->second.begin(); k != j->second.end(); ++k) + for (map::const_iterator k = j->second.begin(); k != j->second.end(); ++k) { if (k->first == fleet) { @@ -98,7 +103,7 @@ Fleet BSDoc::specificFleet(QString battle, QString group, QString fleet) const } } } - return Fleet(); + return '\0'; } diff --git a/bs/bsdoc.h b/bs/bsdoc.h index b790dc6..977491d 100644 --- a/bs/bsdoc.h +++ b/bs/bsdoc.h @@ -26,6 +26,7 @@ // application specific includes #include "fleet.h" +typedef std::map > > 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 @@ -58,9 +59,15 @@ class BSDoc : public QObject * change it. * \todo remove this, and replace it with a better more closed interface. */ - const std::map > >& 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(); @@ -75,7 +82,7 @@ class BSDoc : public QObject * -# 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 > > m_Battles; + BattleList m_Battles; }; #endif diff --git a/bs/bsview.cpp b/bs/bsview.cpp index 5ae7703..2dfe3f3 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -52,6 +52,7 @@ BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent) m_NumberView->addColumn("Name"); m_NumberView->addColumn("Number"); m_NumberView->addColumn("ETA"); + m_NumberView->addColumn("Score"); //addBattle("NO BATTLES"); @@ -83,9 +84,9 @@ BSView::BSView(QWidget *parent, BSDoc *doc) : QSplitter(parent) //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 *))); @@ -114,29 +115,33 @@ void BSView::slotDocumentChanged() { m_NumberView->clear(); - const map > >& battles = m_doc->battles(); + const BattleList& battles = m_doc->battles(); - for (map > >::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 >::const_iterator j = i->second.begin(); j != i->second.end(); ++j) + for (map >::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::const_iterator k = j->second.begin(); k != j->second.end(); ++k) + for (map::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)); } } } @@ -170,24 +175,22 @@ void BSView::slotFleetSelection(QListViewItem *lvi) } 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); @@ -195,7 +198,7 @@ void BSView::slotFleetSelection(QListViewItem *lvi) } else { - if (fl.Race() == m_FleetView->fleet().Race() && + if (fl->race() == m_FleetView->fleet()->race() && m_FleetView->isHome() == home) { m_FleetView->viewFleet(fl, friendly); @@ -203,7 +206,7 @@ void BSView::slotFleetSelection(QListViewItem *lvi) 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); diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 2bd245b..cb15df5 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -41,7 +41,7 @@ void Fleet::setName(string sName) ////////////////////////////////////////////////////////////////////////// // -string Fleet::Name() const +string Fleet::name() const { return m_sName; } @@ -65,7 +65,7 @@ bool Fleet::setRace(string sRace) ////////////////////////////////////////////////////////////////////////// // -string Fleet::Race() const +string Fleet::race() const { return m_sRace; } @@ -75,7 +75,7 @@ string Fleet::Race() const /** 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; @@ -114,26 +114,29 @@ 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].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; } + */ } ////////////////////////////////////////////////////////////////////////// @@ -157,3 +160,17 @@ vector Fleet::RacesAllowed() const 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; +} + diff --git a/bs/fleet.h b/bs/fleet.h index ca2fddf..c156545 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -25,8 +25,9 @@ #include "unittype.h" template class MyComp { public: bool operator()(T,T) { return false; } }; - +typedef std::map > FleetList; typedef std::map UnitList; +typedef std::map > 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. @@ -37,7 +38,7 @@ class Fleet { 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, @@ -48,7 +49,7 @@ public: /**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. @@ -61,13 +62,13 @@ public: * \return The race, represented as a string. * \see setRace */ - std::string Race() const; + std::string race() const; std::vector 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 @@ -78,20 +79,28 @@ public: */ int ETA() const; - static void setRaces(std::map >& 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 >& Races(); + static const RaceList& Races(); static const UnitList& Units(); protected: std::string m_sName; std::string m_sRace; int m_iETA; - std::map > m_Fleet; + FleetList m_Fleet; static UnitList s_Units; - static std::map > s_Races; + static RaceList s_Races; }; #endif diff --git a/bs/ui/infoview.ui b/bs/ui/infoview.ui index 6354911..b435577 100644 --- a/bs/ui/infoview.ui +++ b/bs/ui/infoview.ui @@ -8,7 +8,7 @@ 0 0 - 263 + 293 117 @@ -194,6 +194,15 @@ RemoveButton_clicked() + + NameLine + EtaSpin + RaceCombo + ApplyButton + CancelButton + NewButton + RemoveButton + vector infoview.ui.h diff --git a/bs/ui/resourceview.ui b/bs/ui/resourceview.ui index 6221366..4bc7624 100644 --- a/bs/ui/resourceview.ui +++ b/bs/ui/resourceview.ui @@ -10,40 +10,32 @@ 0 0 - 241 - 75 + 222 + 103 32767 - 90 + 110 QGroupBoxForm - Resources + Resources and Score unnamed - 3 + 11 - 0 + 6 - - - uninitLabel - - - Uninit - - crystalLabel @@ -52,17 +44,17 @@ Crystal - + - metalLabel + eoniumLabel - Metal + Eonium - + - MetalLine + EoniumLine NoFocus @@ -82,12 +74,12 @@ true - + - eoniumLabel + metalLabel - Eonium + Metal @@ -101,9 +93,55 @@ true - + - EoniumLine + ScoreEdit + + + NoFocus + + + true + + + + + MetalLine + + + NoFocus + + + true + + + + + uninitLabel + + + Uninit + + + + + ScoreLabel + + + Score: + + + + + ScoreLostLabel + + + Lost + + + + + ScoreLostEdit NoFocus diff --git a/bs/ui/roidseditview.ui b/bs/ui/roidseditview.ui index 3199fdd..c968a8e 100644 --- a/bs/ui/roidseditview.ui +++ b/bs/ui/roidseditview.ui @@ -9,28 +9,28 @@ 0 0 - 289 - 100 + 219 + 103 32767 - 110 + 119 Roids - Roids + Roids and Score unnamed - 3 + 2 0 @@ -109,14 +109,6 @@ true - - - TextLabel6 - - - Lost - - uninitLabel @@ -147,8 +139,38 @@ true + + + TextLabel6 + + + Lost + + + + + ScoreLine + + + &Score + + + ScoreEdit + + + + + ScoreEdit + + + + LineEdit26 + LineEdit29 + LineEdit31 + LineEdit32 + roidseditview.ui.h diff --git a/bs/unittype.cpp b/bs/unittype.cpp index 6f3ef82..20c30a3 100644 --- a/bs/unittype.cpp +++ b/bs/unittype.cpp @@ -54,21 +54,21 @@ void UnitType::setRace(int iRace) ////////////////////////////////////////////////////////////////////////// // -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; } @@ -112,14 +112,14 @@ void UnitType::insTarget(string target, int index = 0) ////////////////////////////////////////////////////////////////////////// // -vector UnitType::Target() const +vector UnitType::target() const { return m_vTarget; } ////////////////////////////////////////////////////////////////////////// // -string UnitType::Target(int index) const +string UnitType::target(int index) const { return m_vTarget[index]; } @@ -133,7 +133,7 @@ void UnitType::setInitiative(int iInit) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Initiative() const +int UnitType::initiative() const { return m_iInitiative; } @@ -147,7 +147,7 @@ void UnitType::setAgility (int iAgil) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Agility() const +int UnitType::agility() const { return m_iAgility; } @@ -161,7 +161,7 @@ void UnitType::setWeaponSpeed(int iWPSP) ////////////////////////////////////////////////////////////////////////// // -int UnitType::WeaponSpeed() const +int UnitType::weaponSpeed() const { return m_iWeaponSpeed; } @@ -175,7 +175,7 @@ void UnitType::setGuns(int iGuns) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Guns() const +int UnitType::guns() const { return m_iGuns; } @@ -189,7 +189,7 @@ void UnitType::setPower(int iPower) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Power() const +int UnitType::power() const { return m_iPower; } @@ -203,7 +203,7 @@ void UnitType::setArmor(int iArmor) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Armor() const +int UnitType::armor() const { return m_iArmor; } @@ -231,7 +231,7 @@ void UnitType::setTotalResources(int iTR) ////////////////////////////////////////////////////////////////////////// // -int UnitType::TotRes() const +int UnitType::totRes() const { return m_iTotalResources; } @@ -245,7 +245,7 @@ void UnitType::setFuel(int iFuel) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Fuel() const +int UnitType::fuel() const { return m_iFuel; } @@ -273,7 +273,7 @@ void UnitType::setType(string type) ////////////////////////////////////////////////////////////////////////// // -string UnitType::Type() const +string UnitType::type() const { return m_sType; } diff --git a/bs/unittype.h b/bs/unittype.h index 9bf008e..cbb73ba 100644 --- a/bs/unittype.h +++ b/bs/unittype.h @@ -46,11 +46,11 @@ public: /** 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 Target); @@ -61,34 +61,34 @@ public: * \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 Target() const; + std::vector 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); @@ -97,12 +97,12 @@ public: /** 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); @@ -112,7 +112,8 @@ public: * \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.. -- 2.39.2