]> ruin.nu Git - hbs.git/blob - bs/bsdoc.cpp
70cfd899ba4459461f10ea3cc9e3ed7ebea0f420
[hbs.git] / bs / bsdoc.cpp
1 /***************************************************************************
2                           bcdoc.cpp  -  description
3                              -------------------
4     begin                : Sun May 27 22:13:58 CEST 2001
5     copyright            : (C) 2001 by Michael Andreen
6     email                : whale@linux.nu
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "bsdoc.h"
19
20 #include "planet.h"
21
22 using namespace std;
23
24 BSDoc::BSDoc()
25 {
26   modified = false;
27 }
28
29 BSDoc::~BSDoc()
30 {
31 }
32
33 void BSDoc::newDoc()
34 {
35 }
36
37 bool BSDoc::save()
38 {
39   return true;
40 }
41
42 bool BSDoc::saveAs(const QString &filename)
43 {
44         QString test = filename;
45   return true;
46 }
47
48 bool BSDoc::load(const QString &filename)
49 {
50   QString test = filename;
51         emit documentChanged();
52   return true;
53 }
54
55 bool BSDoc::isModified() const
56 {
57   return modified;
58 }
59
60 ///////////////////////////////////////////////////////////////////////////
61 //
62
63 int BSDoc::newBattle(QString name)
64 {
65         m_Battles[name]["Friendly"]["Home Planet"] = new Planet();;
66         m_Battles[name]["Friendly"]["Home Fleet"] = new Fleet();
67         m_Battles[name]["Hostile"];
68
69         //Planet* pl = dynamic_cast<Planet*>(m_Battles[name]["Friendly"]["Home Planet"]);
70         modified = true;
71         emit documentChanged();
72         return 0;
73 }
74
75 /////////////////////////////////////////////////////////////////////////
76 //
77
78 const BattleList& BSDoc::battles() const
79 {
80         return m_Battles;
81 }
82
83 //////////////////////////////////////////////////////////////////////////
84 //
85 const Fleet* BSDoc::specificFleet(QString battle, QString group, QString fleet) const
86 {
87         for (BattleList::const_iterator i = m_Battles.begin(); i != m_Battles.end(); ++i)
88         {
89                 if (i->first == battle)
90                 {
91                         for (map<QString, map<QString, Fleet*> >::const_iterator j = i->second.begin(); j != i->second.end(); j++)
92                         {
93                                 if (j->first == group)
94                                 {
95                                         for (map<QString, Fleet*>::const_iterator k = j->second.begin(); k != j->second.end(); ++k)
96                                         {
97                                                 if (k->first == fleet)
98                                                 {
99                                                         return k->second;
100                                                 }
101                                         }
102                                 }
103                         }
104                 }
105         }
106         return '\0';
107 }
108
109 //////////////////////////////////////////////////////////////////////////
110 //
111 void BSDoc::changeFleet(QString battle, QString group, QString fleet, const Fleet* fl)
112 {
113         delete m_Battles[battle][group][fleet];
114
115         const Planet* planet = 0;
116         if((planet = dynamic_cast<const Planet*>(fl)))
117         {
118                         m_Battles[battle][group][fleet] = new Planet(*planet);
119         }
120         else
121         {
122                 m_Battles[battle][group][fleet] = new Fleet(*fl);
123         }
124         emit documentChanged();
125 }
126
127
128 //////////////////////////////////////////////////////////////////////////
129 //
130 void BSDoc::newFleet(QString battle, QString group, QString fleet, Fleet* fl)
131 {
132         m_Battles[battle][group][fleet] = fl;
133         emit documentChanged();
134 }
135