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