From: Michael Andreen Date: Tue, 12 Mar 2002 19:51:38 +0000 (+0000) Subject: fleetview now generates the correct "unit table" when it's created. X-Git-Tag: HBS_0_1_0~39 X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=commitdiff_plain;h=15d92b3097a80faf26b8ce4cb4a6b957d17bc092 fleetview now generates the correct "unit table" when it's created. --- diff --git a/bs/bsdoc.cpp b/bs/bsdoc.cpp index e5504f9..c65903b 100644 --- a/bs/bsdoc.cpp +++ b/bs/bsdoc.cpp @@ -17,6 +17,7 @@ #include "bsdoc.h" +using namespace std; BSDoc::BSDoc() { @@ -68,8 +69,34 @@ int BSDoc::newBattle(QString name) ///////////////////////////////////////////////////////////////////////// // -const std::map > >& BSDoc::Battles() const +const std::map > >& BSDoc::battles() const { return m_Battles; } +////////////////////////////////////////////////////////////////////////// +// +Fleet BSDoc::specificFleet(QString battle, QString group, QString fleet) const +{ + for (map > >::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++) + { + if (j->first == group) + { + for (map::const_iterator k = j->second.begin(); k != j->second.end(); ++k) + { + if (k->first == fleet) + { + return k->second; + } + } + } + } + } + } +} + + diff --git a/bs/bsdoc.h b/bs/bsdoc.h index d113f5b..b790dc6 100644 --- a/bs/bsdoc.h +++ b/bs/bsdoc.h @@ -58,7 +58,9 @@ class BSDoc : public QObject * change it. * \todo remove this, and replace it with a better more closed interface. */ - const std::map > >& Battles() const; + const std::map > >& battles() const; + + Fleet specificFleet(QString battle, QString group, QString fleet) const; signals: void documentChanged(); diff --git a/bs/bsview.cpp b/bs/bsview.cpp index 78f8340..f7f3aa8 100644 --- a/bs/bsview.cpp +++ b/bs/bsview.cpp @@ -64,7 +64,7 @@ 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(); + m_FleetView = new FleetView(Fleet(), true, true); m_FleetViews->addWidget(m_FleetView, 1); //m_FleetViews->raiseWidget(0); @@ -94,7 +94,7 @@ void BSView::slotDocumentChanged() { m_NumberView->clear(); - const map > >& battles = m_doc->Battles(); + const map > >& battles = m_doc->battles(); for (map > >::const_iterator i = battles.begin(); i != battles.end(); ++i) { @@ -147,22 +147,32 @@ void BSView::slotFleetSelection(QListViewItem *lvi) } else { - if (lvi->parent()->text(0) == tr("Friendly")) + bool home = false; + bool friendly = false; + QString fleet = lvi->text(0); + QString group = lvi->parent()->text(0); + QString battle = lvi->parent()->parent()->text(0); + if ( group == tr("Friendly")) { -// m_FleetView->slotAttacker(false); -// m_FleetView->slotHomePlanet(false); - if (lvi->text(0) == tr("Home Planet")) + friendly = true; + if ( fleet == tr("Home Planet")) { -// m_FleetView->slotHomePlanet(true); + home = true; } } + Fleet fl = m_doc->specificFleet(battle, group, fleet); + if (fl.Race() == m_FleetView->fleet().Race() && + m_FleetView->isHome() == home) + { + m_FleetView->viewFleet(fl, friendly); + } else { -// m_FleetView->slotAttacker(true); -// m_FleetView->slotHomePlanet(false); + m_FleetViews->removeWidget(m_FleetView); + m_FleetView = new FleetView(fl, friendly, home); + m_FleetViews->addWidget(m_FleetView, 1); } m_FleetViews->raiseWidget(1); - } diff --git a/bs/fleet.cpp b/bs/fleet.cpp index a46a50a..117ce39 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -150,5 +150,10 @@ const map& Fleet::Units() return s_Units; } - +////////////////////////////////////////////////////////////////////////// +// +vector Fleet::RacesAllowed() const +{ + return s_Races[m_sRace]; +} diff --git a/bs/fleet.h b/bs/fleet.h index 95c0c88..047fc13 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -60,6 +60,8 @@ public: */ std::string Race() const; + std::vector RacesAllowed() const; + /**Returns the total number of ships in this fleet */ int NumberOfShips() const; diff --git a/bs/unittype.cpp b/bs/unittype.cpp index 27b3cd4..6f3ef82 100644 --- a/bs/unittype.cpp +++ b/bs/unittype.cpp @@ -40,7 +40,7 @@ void UnitType::setName(string sName) ////////////////////////////////////////////////////////////////////////// // -string UnitType::Name() +string UnitType::Name() const { return m_sName; } @@ -54,7 +54,7 @@ void UnitType::setRace(int iRace) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Race() +int UnitType::Race() const { return m_iRace; } @@ -68,7 +68,7 @@ void UnitType::setClass(string sClass) ////////////////////////////////////////////////////////////////////////// // -string UnitType::Class() +string UnitType::Class() const { return m_sClass; } @@ -112,14 +112,14 @@ void UnitType::insTarget(string target, int index = 0) ////////////////////////////////////////////////////////////////////////// // -vector UnitType::Target() +vector UnitType::Target() const { return m_vTarget; } ////////////////////////////////////////////////////////////////////////// // -string UnitType::Target(int index) +string UnitType::Target(int index) const { return m_vTarget[index]; } @@ -133,7 +133,7 @@ void UnitType::setInitiative(int iInit) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Initiative() +int UnitType::Initiative() const { return m_iInitiative; } @@ -147,7 +147,7 @@ void UnitType::setAgility (int iAgil) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Agility() +int UnitType::Agility() const { return m_iAgility; } @@ -161,7 +161,7 @@ void UnitType::setWeaponSpeed(int iWPSP) ////////////////////////////////////////////////////////////////////////// // -int UnitType::WeaponSpeed() +int UnitType::WeaponSpeed() const { return m_iWeaponSpeed; } @@ -175,7 +175,7 @@ void UnitType::setGuns(int iGuns) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Guns() +int UnitType::Guns() const { return m_iGuns; } @@ -189,7 +189,7 @@ void UnitType::setPower(int iPower) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Power() +int UnitType::Power() const { return m_iPower; } @@ -203,7 +203,7 @@ void UnitType::setArmor(int iArmor) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Armor() +int UnitType::Armor() const { return m_iArmor; } @@ -217,7 +217,7 @@ void UnitType::setEMP(int iEMP) ////////////////////////////////////////////////////////////////////////// // -int UnitType::EMP() +int UnitType::EMP() const { return m_iEMP; } @@ -231,7 +231,7 @@ void UnitType::setTotalResources(int iTR) ////////////////////////////////////////////////////////////////////////// // -int UnitType::TotRes() +int UnitType::TotRes() const { return m_iTotalResources; } @@ -245,7 +245,7 @@ void UnitType::setFuel(int iFuel) ////////////////////////////////////////////////////////////////////////// // -int UnitType::Fuel() +int UnitType::Fuel() const { return m_iFuel; } @@ -259,7 +259,7 @@ void UnitType::setETA(int iETA) ////////////////////////////////////////////////////////////////////////// // -int UnitType::ETA() +int UnitType::ETA() const { return m_iETA; } @@ -273,7 +273,7 @@ void UnitType::setType(string type) ////////////////////////////////////////////////////////////////////////// // -string UnitType::Type() +string UnitType::Type() const { return m_sType; } diff --git a/bs/unittype.h b/bs/unittype.h index 3357671..9bf008e 100644 --- a/bs/unittype.h +++ b/bs/unittype.h @@ -41,16 +41,16 @@ public: /*! This function sets the name for this unittype (ie. interceptor) */ void setName(std::string sName); /** Returns the name of this unittype */ - std::string Name(); + std::string Name() const; /** 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(); + int Race() const; /** Sets the class for the unittype, it's represented as a integer */ void setClass(std::string sClass); - std::string Class(); + std::string Class() const; /** Sets the classes that this unittype targets. a vector is used. */ void setTarget(std::vector Target); @@ -61,58 +61,58 @@ 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(); + 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); + std::string Target(int index) const; /** Sets the initiatve, the lower it is the earlier the unit shots */ void setInitiative(int iInit); - int Initiative(); + int Initiative() const; /** Sets the agility, the higher it is the harder it is to hit the unit */ void setAgility (int iAgil); - int Agility(); + 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(); + int WeaponSpeed() const; /** Sets the number of guns. */ void setGuns(int iGuns); - int Guns(); + 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(); + 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(); + int Armor() const; /** Sets the emp resistance, the lower value the easier it is to block it */ void setEMP(int iEMP); - int EMP(); + int EMP() const; /** 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(); + int TotRes() const; /** Sets the fuelcost for this unittype */ void setFuel(int iFuel); /** Returns the fuelcost */ - int Fuel(); + 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); - int ETA(); + int ETA() const; /** Sets the type of the unit. What the types do must be specified in the real battle engine (Fleet) though. * \param iType An integer to symbolise the type. */ void setType(std::string type); /** What type of ship this is. */ - std::string Type(); + 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..