]> ruin.nu Git - hbs.git/blob - bs/fleet.h
b706bbd919bdb03b3a358ed1ee27a9c8a6b52e1c
[hbs.git] / bs / fleet.h
1 /***************************************************************************
2                           fleet.h  -  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 #ifndef FLEET_H
19 #define FLEET_H
20
21 #include <map>
22 #include <ext/hash_map>
23 #include <string>
24 #include <vector>
25
26 #include "unittype.h"
27  template<typename T> class MyComp { public: bool operator()(T,T) { return false; } };
28 typedef std::map<std::string, std::vector<int> > FleetList;
29 typedef std::map<std::string, UnitType> UnitList;
30 typedef std::map<std::string, std::vector<int> > RaceList;
31 typedef std::map<std::string, std::vector<int> > ResourceList;
32 typedef std::map<std::string, int> ArmorList;
33 //! An abstraction of a fleet and the engine for the battle simulation.
34 /**This class and it's derivates is  the engine for the whole battlesystem.
35   *     One of the few parts that I plan make fully portable.
36   *\todo LOTS (I think ;)
37   *@author Michael Andreen
38   */
39 class Fleet 
40 {
41 public: 
42         Fleet();
43         virtual ~Fleet();
44
45         /**Sets the name that represents this fleet. Might be different a name
46          * like foobar or some coordinates like 1:1:1. The name doesn't have to be unique,
47          * since it's up to the rest of the program to handle that part.
48          * \see Name
49          */
50         void   setName(std::string sName);
51         /**Returns the name of this fleet.
52          * \see setName
53          */
54         std::string name() const;
55
56         /**The race string decides what type of ships this fleet can have.
57          * The values must be feeded into this class.
58          * \param sRace This is just the name of the race. It's case-sensitive.
59          * \return If the race is available this function returns true, if not false is returned. The race is set in both cases though.
60          * \see Race
61          */
62         bool   setRace(std::string sRace);
63         /**Just returns what race this fleet belongs to.. 
64          * \return The race, represented as a string.
65          * \see setRace
66          */
67         std::string race() const;
68
69         std::vector<int> RacesAllowed() const;
70
71         /**Returns the total number of ships in this fleet
72          */
73         int numberOfShips() const;
74
75         /**Sets the estimated time of arrival. The time as a single integer,
76          * in relation to the current time. For example if the current time is
77          * 10, and the arrival is at 12, then the eta is 2.
78          */
79         void setETA(int eta);
80         /**Return the estimated time of arrival. It's counted from the current time (tick).
81          */
82         int  ETA() const;
83
84
85         /**Returns the score. This value is the total resources spent on this fleet
86          * devided with 10.
87          * \param tick tells the function what tick you want the score from. 0 is 
88          * initial score before the fleet has landed.
89          */
90         unsigned score(int tick = 0) const;
91
92         void setFleet(std::string unittype, int number, int tick = 0);
93         int      fleet(std::string unittype, int tick = 0);
94
95         int freeFleet(std:: string unittype, int tick = 0);
96         
97         static void setRaces(RaceList& races);
98         static void setUnits(UnitList& units);
99
100         static const RaceList& Races();
101         static const UnitList& Units();
102
103         void addToThis(std::vector<Fleet*> fleets, int tick = 0);
104
105         void distributeLossesGains(std::vector<Fleet*> fleets, int tick = 0);
106
107         std::vector<Fleet*> calculateSide(std::vector<Fleet*> fleets, int stays = 0, int tick = 0);
108
109         void killFleet(std::string unittype, int number, int tick = 0);
110
111         void setResource(std::string type, int number, int tick = 0);
112         int resource(std::string type, int tick = 0)const;
113         
114         void takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits);
115         void takeEMP(std::string unittype, int number);
116 protected:
117
118
119         std::string     m_sName;
120         std::string     m_sRace;
121         int         m_iETA;
122         FleetList       m_Fleet;
123         FleetList       m_BlockedFleet;
124         ResourceList m_Resources;
125         ArmorList       m_Armor;
126         
127
128
129         static UnitList s_Units;
130         static RaceList s_Races;
131 };
132
133 #endif