]> ruin.nu Git - hbs.git/blob - bs/bsdoc.cpp
Started the work to split up the pods better..
[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"]["Evil guy"] = new Fleet();
68
69         m_Battles[name]["Friendly"]["Home Planet"]->setName("Home Planet");
70         m_Battles[name]["Friendly"]["Home Fleet"]->setName("Home Fleet");
71         m_Battles[name]["Friendly"]["Home Fleet"]->setRace("Terran");
72         m_Battles[name]["Hostile"]["Evil guy"]->setName("Evil guy");
73         m_Battles[name]["Hostile"]["Evil guy"]->setETA(1);
74
75         modified = true;
76         emit documentChanged();
77         return 0;
78 }
79
80 /////////////////////////////////////////////////////////////////////////
81 //
82
83 const BattleList& BSDoc::battles() const
84 {
85         return m_Battles;
86 }
87
88 //////////////////////////////////////////////////////////////////////////
89 //
90 const Fleet* BSDoc::specificFleet(QString battle, QString group, QString fleet) const
91 {
92         for (BattleList::const_iterator i = m_Battles.begin(); i != m_Battles.end(); ++i)
93         {
94                 if (i->first == battle)
95                 {
96                         for (map<QString, map<QString, Fleet*> >::const_iterator j = i->second.begin(); j != i->second.end(); j++)
97                         {
98                                 if (j->first == group)
99                                 {
100                                         for (map<QString, Fleet*>::const_iterator k = j->second.begin(); k != j->second.end(); ++k)
101                                         {
102                                                 if (k->first == fleet)
103                                                 {
104                                                         return k->second;
105                                                 }
106                                         }
107                                 }
108                         }
109                 }
110         }
111         return '\0';
112 }
113
114 //////////////////////////////////////////////////////////////////////////
115 //
116 void BSDoc::changeFleet(QString battle, QString group, QString fleet, const Fleet* fl)
117 {
118         delete m_Battles[battle][group][fleet];
119
120         const Planet* planet = 0;
121         if((planet = dynamic_cast<const Planet*>(fl)))
122         {
123                         m_Battles[battle][group][fleet] = new Planet(*planet);
124         }
125         else
126         {
127                 m_Battles[battle][group][fleet] = new Fleet(*fl);
128         }
129         emit documentChanged();
130 }
131
132
133 //////////////////////////////////////////////////////////////////////////
134 //
135 void BSDoc::newFleet(QString battle, QString group, QString fleet, Fleet* fl)
136 {
137         m_Battles[battle][group][fleet] = fl;
138         emit documentChanged();
139 }
140
141 //////////////////////////////////////////////////////////////////////////
142 //
143 void BSDoc::removeFleet(QString battle, QString group, QString fleet)
144 {
145         delete m_Battles[battle][group][fleet];
146         m_Battles[battle][group].erase(fleet);
147         emit documentChanged();
148 }
149
150 //////////////////////////////////////////////////////////////////////////
151 //
152 void BSDoc::runBattleSimulation()
153 {
154         for(BattleList::iterator i = m_Battles.begin(); i != m_Battles.end(); ++i)
155         {
156                 map<QString, vector<Fleet*> > battle;
157                 for (map<QString, map<QString, Fleet*> >::iterator j = i->second.begin(); j != i->second.end(); ++j)
158                 {
159                         for (map<QString, Fleet*>::iterator k = j->second.begin(); k != j->second.end(); ++k)
160                                 battle[j->first].push_back(k->second);
161                 }
162
163                 Planet* pl = dynamic_cast<Planet*>(i->second["Friendly"]["Home Planet"]);
164
165                 if (pl)
166                 {
167                         pl->runBattle(battle["Friendly"], battle["Hostile"]);
168                 }
169         }
170
171         emit documentChanged();
172 }