]> ruin.nu Git - hbs.git/blob - bs/fleet.cpp
cb15df528c6bce726a0f7dd52db026f7d57f5a31
[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 Fleet::~Fleet(){
33 }
34
35 //////////////////////////////////////////////////////////////////////////
36 //
37 void Fleet::setName(string sName)
38 {
39         m_sName = sName;
40 }
41
42 //////////////////////////////////////////////////////////////////////////
43 //
44 string Fleet::name() const
45 {
46         return m_sName;
47 }
48
49 //////////////////////////////////////////////////////////////////////////
50 //
51 /** This function first sets the race, then it iterates through the the 
52  * s_Races and checks if it finds the race it returns true, if it reaches
53  * the end without finding it it returns false.
54  */
55 bool Fleet::setRace(string sRace)
56 {
57         m_sRace = sRace;
58         for (map<string, vector<int> >::iterator i = s_Races.begin(); i != s_Races.end(); i++)
59         {
60                 if (m_sRace == (*i).first)
61                         return true;
62         }
63         return false;
64 }
65
66 //////////////////////////////////////////////////////////////////////////
67 //
68 string Fleet::race() const
69 {
70         return m_sRace;
71 }
72
73 //////////////////////////////////////////////////////////////////////////
74 //
75 /** This function iterates through m_Fleet and adds all numbers together to
76  * produce a total.
77  */
78 int Fleet::numberOfShips() const
79 {
80         int total = 0;
81
82         for (map<string, vector<int> >::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
83         {
84                 total += i->second[0];
85         }
86
87         return total;
88 }
89
90 //////////////////////////////////////////////////////////////////////////
91 //
92 void Fleet::setETA(int eta)
93 {
94         m_iETA = eta;
95 }
96
97 //////////////////////////////////////////////////////////////////////////
98 //
99 int  Fleet::ETA() const
100 {
101         return m_iETA;
102 }
103
104 //////////////////////////////////////////////////////////////////////////
105 //
106 void Fleet::setRaces(map<string, vector<int> >& races)
107 {
108         s_Races = races;
109 }
110
111 //////////////////////////////////////////////////////////////////////////
112 //
113 void Fleet::setUnits(UnitList& units)
114 {
115         s_Units = units;
116
117         /*
118
119         for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); i++)
120         {
121                 cerr << s_Units[(*i).first].Name() << "\t\t"
122                         << s_Units[(*i).first].race() <<"\t"
123                         << s_Units[(*i).first].unitClass() << "\t"
124                         << s_Units[(*i).first].target(0) << "\t"
125                         << s_Units[(*i).first].target(1) << "\t"
126                         << s_Units[(*i).first].target(2) << "\t"
127                         << s_Units[(*i).first].initiative() << "\t"
128                         << s_Units[(*i).first].agility() << "\t"
129                         << s_Units[(*i).first].weaponSpeed() << "\t"
130                         << s_Units[(*i).first].guns() << "\t"
131                         << s_Units[(*i).first].power() << "\t"
132                         << s_Units[(*i).first].armor() << "\t"
133                         << s_Units[(*i).first].EMP() << "\t"
134                         << s_Units[(*i).first].totRes() << "\t"
135                         << s_Units[(*i).first].fuel() << "\t"
136                         << s_Units[(*i).first].ETA() << "\t"
137                         << s_Units[(*i).first].type() << endl;
138         }
139         */
140 }
141
142 //////////////////////////////////////////////////////////////////////////
143 //
144 const map<string, vector<int> >& Fleet::Races()
145 {
146         return s_Races;
147 }
148
149 //////////////////////////////////////////////////////////////////////////
150 //
151 const UnitList& Fleet::Units()
152 {
153         return s_Units;
154 }
155
156 //////////////////////////////////////////////////////////////////////////
157 //
158 vector<int> Fleet::RacesAllowed() const
159 {
160         return s_Races[m_sRace];
161 }
162
163 //////////////////////////////////////////////////////////////////////////
164 //
165 unsigned Fleet::score(int tick = 0) const
166 {
167         unsigned tot_score = 0;
168
169         for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
170         {
171                 tot_score += i->second[tick] * s_Units[i->first].totRes() / 10;
172         }
173
174         return tot_score;
175 }
176