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;
36 //////////////////////////////////////////////////////////////////////////
38 void Fleet::setName(string sName)
43 //////////////////////////////////////////////////////////////////////////
45 string Fleet::name() const
50 //////////////////////////////////////////////////////////////////////////
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.
56 bool Fleet::setRace(string sRace)
59 for (map<string, vector<int> >::iterator i = s_Races.begin(); i != s_Races.end(); i++)
61 if (m_sRace == (*i).first)
67 //////////////////////////////////////////////////////////////////////////
69 string Fleet::race() const
74 //////////////////////////////////////////////////////////////////////////
76 /** This function iterates through m_Fleet and adds all numbers together to
79 int Fleet::numberOfShips() const
83 for (map<string, vector<int> >::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
85 if (i->second.size() != 0)
86 total += i->second[0];
92 //////////////////////////////////////////////////////////////////////////
94 void Fleet::setETA(int eta)
99 //////////////////////////////////////////////////////////////////////////
101 int Fleet::ETA() const
106 //////////////////////////////////////////////////////////////////////////
108 void Fleet::setRaces(map<string, vector<int> >& races)
113 //////////////////////////////////////////////////////////////////////////
115 void Fleet::setUnits(UnitList& units)
121 for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); i++)
123 cerr << s_Units[(*i).first].Name() << "\t\t"
124 << s_Units[(*i).first].race() <<"\t"
125 << s_Units[(*i).first].unitClass() << "\t"
126 << s_Units[(*i).first].target(0) << "\t"
127 << s_Units[(*i).first].target(1) << "\t"
128 << s_Units[(*i).first].target(2) << "\t"
129 << s_Units[(*i).first].initiative() << "\t"
130 << s_Units[(*i).first].agility() << "\t"
131 << s_Units[(*i).first].weaponSpeed() << "\t"
132 << s_Units[(*i).first].guns() << "\t"
133 << s_Units[(*i).first].power() << "\t"
134 << s_Units[(*i).first].armor() << "\t"
135 << s_Units[(*i).first].EMP() << "\t"
136 << s_Units[(*i).first].totRes() << "\t"
137 << s_Units[(*i).first].fuel() << "\t"
138 << s_Units[(*i).first].ETA() << "\t"
139 << s_Units[(*i).first].type() << endl;
144 //////////////////////////////////////////////////////////////////////////
146 const map<string, vector<int> >& Fleet::Races()
151 //////////////////////////////////////////////////////////////////////////
153 const UnitList& Fleet::Units()
158 //////////////////////////////////////////////////////////////////////////
160 vector<int> Fleet::RacesAllowed() const
162 return s_Races[m_sRace];
165 //////////////////////////////////////////////////////////////////////////
167 unsigned Fleet::score(int tick = 0) const
169 unsigned tot_score = 0;
171 for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
173 if (i->second.size() >= tick)
175 tot_score += i->second[tick] * s_Units[i->first].totRes() / 10;
181 //////////////////////////////////////////////////////////////////////////
183 void Fleet::setFleet(string unittype, int number)
185 if (m_Fleet[unittype].size() == 0)
187 m_Fleet[unittype].push_back(number);
190 m_Fleet[unittype][0] = number;
193 //////////////////////////////////////////////////////////////////////////
195 int Fleet::fleet(string unittype, int tick = 0)
197 if (m_Fleet[unittype].size() == 0)
200 return m_Fleet[unittype][tick];
203 //////////////////////////////////////////////////////////////////////////
205 void Fleet::addToThis(std::vector<Fleet*> fleets, int tick = 0)
207 for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
209 if (m_Fleet[i->first].size() == 0)
210 m_Fleet[i->first].push_back(0);
212 for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
214 // FIXTHIS!! m_Fleet[i->first][0] += j->fleet(i->first, tick);
219 //////////////////////////////////////////////////////////////////////////
221 void Fleet::distributeLossesGains(std::vector<Fleet*> fleets, int tick = 0)
225 //////////////////////////////////////////////////////////////////////////
227 std::vector<Fleet*> Fleet::calculateSide(std::vector<Fleet*> fleets, int stays = 0, int tick = 0)
231 //////////////////////////////////////////////////////////////////////////
233 int Fleet::freeFleet(std:: string unittype, int tick = 0)
235 if (m_Fleet[unittype].size() == 0)
237 if (m_BlockedFleet[unittype].size() < tick)
238 return m_Fleet[unittype][tick];
240 return m_Fleet[unittype][tick] - m_BlockedFleet[unittype][tick];
244 //////////////////////////////////////////////////////////////////////////
246 void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits)
250 //////////////////////////////////////////////////////////////////////////
252 void Fleet::takeEMP(std::string unittype, int number)
256 //////////////////////////////////////////////////////////////////////////
258 void Fleet::killFleet(std::string unittype, int number, int tick = 0)
262 //////////////////////////////////////////////////////////////////////////
264 void setResource(std::string type, int number, int tick = 0)
268 //////////////////////////////////////////////////////////////////////////
270 int resource(std::string type, int tick = 0)