]> ruin.nu Git - hbs.git/blob - bs/fleet.cpp
added comboboxes for the battle and group in the info view
[hbs.git] / bs / fleet.cpp
1 /***************************************************************************
2                           fleet.cpp  -  description
3                              -------------------
4     begin                : Tue Jan 22 2002
5     copyright            : (C) 2002 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 "fleet.h"
19
20 #include <iostream>
21 using namespace std;
22
23 //Static variables
24 map<string, vector<int> > Fleet::s_Races;
25 UnitList Fleet::s_Units;
26
27 Fleet::Fleet()
28 {
29         m_iETA = 0;
30         m_sRace = "Cathaar";
31 }
32
33 Fleet::~Fleet(){
34 }
35
36 //////////////////////////////////////////////////////////////////////////
37 //
38 void Fleet::setName(string sName)
39 {
40         m_sName = sName;
41 }
42
43 //////////////////////////////////////////////////////////////////////////
44 //
45 string Fleet::name() const
46 {
47         return m_sName;
48 }
49
50 //////////////////////////////////////////////////////////////////////////
51 //
52 /** This function first sets the race, then it iterates through the the 
53  * s_Races and checks if it finds the race it returns true, if it reaches
54  * the end without finding it it returns false.
55  */
56 bool Fleet::setRace(string sRace)
57 {
58         m_sRace = sRace;
59         for (map<string, vector<int> >::iterator i = s_Races.begin(); i != s_Races.end(); i++)
60         {
61                 if (m_sRace == (*i).first)
62                         return true;
63         }
64         return false;
65 }
66
67 //////////////////////////////////////////////////////////////////////////
68 //
69 string Fleet::race() const
70 {
71         return m_sRace;
72 }
73
74 //////////////////////////////////////////////////////////////////////////
75 //
76 /** This function iterates through m_Fleet and adds all numbers together to
77  * produce a total.
78  */
79 int Fleet::numberOfShips() const
80 {
81         int total = 0;
82
83         for (map<string, vector<int> >::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
84         {
85                 total += i->second[0];
86         }
87
88         return total;
89 }
90
91 //////////////////////////////////////////////////////////////////////////
92 //
93 void Fleet::setETA(int eta)
94 {
95         m_iETA = eta;
96 }
97
98 //////////////////////////////////////////////////////////////////////////
99 //
100 int  Fleet::ETA() const
101 {
102         return m_iETA;
103 }
104
105 //////////////////////////////////////////////////////////////////////////
106 //
107 void Fleet::setRaces(map<string, vector<int> >& races)
108 {
109         s_Races = races;
110 }
111
112 //////////////////////////////////////////////////////////////////////////
113 //
114 void Fleet::setUnits(UnitList& units)
115 {
116         s_Units = units;
117
118         /*
119
120         for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); i++)
121         {
122                 cerr << s_Units[(*i).first].Name() << "\t\t"
123                         << s_Units[(*i).first].race() <<"\t"
124                         << s_Units[(*i).first].unitClass() << "\t"
125                         << s_Units[(*i).first].target(0) << "\t"
126                         << s_Units[(*i).first].target(1) << "\t"
127                         << s_Units[(*i).first].target(2) << "\t"
128                         << s_Units[(*i).first].initiative() << "\t"
129                         << s_Units[(*i).first].agility() << "\t"
130                         << s_Units[(*i).first].weaponSpeed() << "\t"
131                         << s_Units[(*i).first].guns() << "\t"
132                         << s_Units[(*i).first].power() << "\t"
133                         << s_Units[(*i).first].armor() << "\t"
134                         << s_Units[(*i).first].EMP() << "\t"
135                         << s_Units[(*i).first].totRes() << "\t"
136                         << s_Units[(*i).first].fuel() << "\t"
137                         << s_Units[(*i).first].ETA() << "\t"
138                         << s_Units[(*i).first].type() << endl;
139         }
140         */
141 }
142
143 //////////////////////////////////////////////////////////////////////////
144 //
145 const map<string, vector<int> >& Fleet::Races()
146 {
147         return s_Races;
148 }
149
150 //////////////////////////////////////////////////////////////////////////
151 //
152 const UnitList& Fleet::Units()
153 {
154         return s_Units;
155 }
156
157 //////////////////////////////////////////////////////////////////////////
158 //
159 vector<int> Fleet::RacesAllowed() const
160 {
161         return s_Races[m_sRace];
162 }
163
164 //////////////////////////////////////////////////////////////////////////
165 //
166 unsigned Fleet::score(int tick = 0) const
167 {
168         unsigned tot_score = 0;
169
170         for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
171         {
172                 tot_score += i->second[tick] * s_Units[i->first].totRes() / 10;
173         }
174
175         return tot_score;
176 }
177
178 //////////////////////////////////////////////////////////////////////////
179 //
180 void Fleet::setFleet(string unittype, int number)
181 {
182         if (m_Fleet[unittype].size() == 0)
183         {
184                 m_Fleet[unittype].push_back(number);
185                 return;
186         }
187         m_Fleet[unittype][0] = number;
188 }
189
190 //////////////////////////////////////////////////////////////////////////
191 //
192 int      Fleet::fleet(string unittype, int tick = 0)
193 {
194         if (m_Fleet[unittype].size() == 0)
195                 return 0;
196
197         return m_Fleet[unittype][tick];
198 }
199
200