]> ruin.nu Git - hbs.git/blobdiff - bs/bsdoc.cpp
adding, removing and chaning fleets now works.
[hbs.git] / bs / bsdoc.cpp
index e5504f93d16d9e5c70cf8151b3effb44e91b3910..d7e04ce336f0e3253c04af305ae94952b0942d1b 100644 (file)
@@ -17,6 +17,9 @@
 
 #include "bsdoc.h"
 
+#include "planet.h"
+
+using namespace std;
 
 BSDoc::BSDoc()
 {
@@ -38,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;
 }
 
@@ -57,9 +62,11 @@ bool BSDoc::isModified() const
 
 int BSDoc::newBattle(QString name)
 {
-       m_Battles[name]["Friendly"]["Home Planet"];
+       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;
@@ -68,8 +75,77 @@ int BSDoc::newBattle(QString name)
 /////////////////////////////////////////////////////////////////////////
 //
 
-const std::map<QString, std::map<QString, std::map<QString, Fleet> > >& BSDoc::Battles() const
+const BattleList& BSDoc::battles() const
 {
        return m_Battles;
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+const Fleet* BSDoc::specificFleet(QString battle, QString group, QString fleet) const
+{
+       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++)
+                       {
+                               if (j->first == group)
+                               {
+                                       for (map<QString, Fleet*>::const_iterator k = j->second.begin(); k != j->second.end(); ++k)
+                                       {
+                                               if (k->first == fleet)
+                                               {
+                                                       return k->second;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       return '\0';
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void BSDoc::changeFleet(QString battle, QString group, QString fleet, const Fleet* fl)
+{
+       delete m_Battles[battle][group][fleet];
+
+       const Planet* planet = 0;
+       if((planet = dynamic_cast<const Planet*>(fl)))
+       {
+                       m_Battles[battle][group][fleet] = new Planet(*planet);
+       }
+       else
+       {
+               m_Battles[battle][group][fleet] = new Fleet(*fl);
+       }
+       emit documentChanged();
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+//
+void BSDoc::newFleet(QString battle, QString group, QString fleet, Fleet* fl)
+{
+       m_Battles[battle][group][fleet] = fl;
+       emit documentChanged();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void BSDoc::removeFleet(QString battle, QString group, QString fleet)
+{
+       delete m_Battles[battle][group][fleet];
+       m_Battles[battle][group].erase(fleet);
+       emit documentChanged();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void BSDoc::runBattleSimulation()
+{
+
+       emit documentChanged();
+}