1 /***************************************************************************
2 fleet.cpp - description
4 begin : Tue Jan 22 2002
5 copyright : (C) 2002 by Michael Andreen
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
24 map<string, vector<int> > Fleet::s_Races;
25 UnitList Fleet::s_Units;
35 //////////////////////////////////////////////////////////////////////////
37 void Fleet::setName(string sName)
42 //////////////////////////////////////////////////////////////////////////
44 string Fleet::name() const
49 //////////////////////////////////////////////////////////////////////////
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.
55 bool Fleet::setRace(string sRace)
58 for (map<string, vector<int> >::iterator i = s_Races.begin(); i != s_Races.end(); i++)
60 if (m_sRace == (*i).first)
66 //////////////////////////////////////////////////////////////////////////
68 string Fleet::race() const
73 //////////////////////////////////////////////////////////////////////////
75 /** This function iterates through m_Fleet and adds all numbers together to
78 int Fleet::numberOfShips() const
82 for (map<string, vector<int> >::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
84 total += i->second[0];
90 //////////////////////////////////////////////////////////////////////////
92 void Fleet::setETA(int eta)
97 //////////////////////////////////////////////////////////////////////////
99 int Fleet::ETA() const
104 //////////////////////////////////////////////////////////////////////////
106 void Fleet::setRaces(map<string, vector<int> >& races)
111 //////////////////////////////////////////////////////////////////////////
113 void Fleet::setUnits(UnitList& units)
119 for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); i++)
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;
142 //////////////////////////////////////////////////////////////////////////
144 const map<string, vector<int> >& Fleet::Races()
149 //////////////////////////////////////////////////////////////////////////
151 const UnitList& Fleet::Units()
156 //////////////////////////////////////////////////////////////////////////
158 vector<int> Fleet::RacesAllowed() const
160 return s_Races[m_sRace];
163 //////////////////////////////////////////////////////////////////////////
165 unsigned Fleet::score(int tick = 0) const
167 unsigned tot_score = 0;
169 for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
171 tot_score += i->second[tick] * s_Units[i->first].totRes() / 10;