]> ruin.nu Git - hbs.git/blob - bs/fleet.cpp
Can now load the stats and race configurations..
[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 map<string, UnitType > Fleet::s_Units;
26
27 Fleet::Fleet()
28 {
29         m_iETA = 0;
30         m_sRace = "Generic";
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()
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(std::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()
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()
79 {
80         int total = 0;
81
82         for (map<string, vector<int> >::iterator i = m_Fleet.begin(); i != m_Fleet.end(); i++)
83         {
84                 total += m_Fleet[(*i).first][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()
100 {
101         return m_iETA;
102 }
103
104 //////////////////////////////////////////////////////////////////////////
105 //
106 void Fleet::setRaces(std::map<std::string, std::vector<int> >& races)
107 {
108         s_Races = races;
109 }
110
111 //////////////////////////////////////////////////////////////////////////
112 //
113 void Fleet::setUnits(map<std::string, UnitType>& units)
114 {
115         s_Units = units;
116
117         for (map<string, UnitType >::iterator i = s_Units.begin(); i != s_Units.end(); i++)
118         {
119                 cerr << s_Units[(*i).first].Name() << "\t"
120                         << s_Units[(*i).first].Race() <<"\t"
121                         << s_Units[(*i).first].Class() << "\t"
122                         << s_Units[(*i).first].Target(0) << "\t"
123                         << s_Units[(*i).first].Target(1) << "\t"
124                         << s_Units[(*i).first].Target(2) << "\t"
125                         << s_Units[(*i).first].Initiative() << "\t"
126                         << s_Units[(*i).first].Agility() << "\t"
127                         << s_Units[(*i).first].WeaponSpeed() << "\t"
128                         << s_Units[(*i).first].Guns() << "\t"
129                         << s_Units[(*i).first].Power() << "\t"
130                         << s_Units[(*i).first].Armor() << "\t"
131                         << s_Units[(*i).first].EMP() << "\t"
132                         << s_Units[(*i).first].TotRes() << "\t"
133                         << s_Units[(*i).first].Fuel() << "\t"
134                         << s_Units[(*i).first].ETA() << "\t"
135                         << s_Units[(*i).first].Type() << endl;
136         }
137 }
138