#define FLEET_H
#include <map>
+#include <ext/hash_map>
#include <string>
#include <vector>
#include "unittype.h"
-
-//!This is the engine for the whole battlesystem.
-/**This is the engine for the whole battlesystem.
+ template<typename T> class MyComp { public: bool operator()(T,T) { return false; } };
+typedef std::map<std::string, std::vector<int> > FleetList;
+typedef std::map<std::string, UnitType> UnitList;
+typedef std::map<std::string, std::vector<int> > RaceList;
+typedef std::map<std::string, std::vector<int> > ResourceList;
+typedef std::map<std::string, int> ArmorList;
+//! An abstraction of a fleet and the engine for the battle simulation.
+/**This class and it's derivates is the engine for the whole battlesystem.
* One of the few parts that I plan make fully portable.
*\todo LOTS (I think ;)
*@author Michael Andreen
{
public:
Fleet();
- ~Fleet();
+ virtual ~Fleet();
/**Sets the name that represents this fleet. Might be different a name
- * like foobar or some coordinates like 1:1:1. The name doesn't have to be unique,
- * since it's up to the rest of the program to handle that part.
+ * like foobar or some coordinates like 1:1:1. The name doesn't have to be
+ * unique, since it's up to the rest of the program to handle that part.
* \see Name
*/
void setName(std::string sName);
+
/**Returns the name of this fleet.
* \see setName
*/
- std::string Name();
+ std::string name() const;
/**The race string decides what type of ships this fleet can have.
* The values must be feeded into this class.
* \param sRace This is just the name of the race. It's case-sensitive.
- * \return If the race is available this function returns true, if not false is returned. The race is set in both cases though.
+ * \return If the race is available this function returns true, if not false
+ * is returned. The race is set in both cases though.
* \see Race
*/
bool setRace(std::string sRace);
+
/**Just returns what race this fleet belongs to..
* \return The race, represented as a string.
* \see setRace
*/
- std::string Race();
+ std::string race() const;
+
+ /**Returns the ship races allowed for this fleet.. This is not a hard limit
+ * it's more a indication to the interface what should be shown or not, the
+ * class can still handle all the different shiptypes.
+ * \return a vector of ints that can be used to compare with Unittype::race()
+ * \see Unittype::race()
+ */
+ std::vector<int> RacesAllowed() const;
+
+ /**Returns the total number of ships in this fleet
+ */
+ int numberOfShips() const;
+
+ /**Sets the estimated time of arrival. The time as a single integer,
+ * in relation to the current time. For example if the current time is
+ * 10, and the arrival is at 12, then the eta is 2.
+ */
+ void setETA(int eta);
+
+ /**Return the estimated time of arrival. It's counted from the current time (tick).
+ */
+ int ETA() const;
+
+
+ /**Returns the score. This value is the total resources spent on this fleet
+ * devided with 10.
+ * \param tick tells the function what tick you want the score from. 0 is
+ * initial score before the fleet has landed.
+ */
+ unsigned score(int tick = 0) const;
+
+ /**This function is used to set the number of units for a specific tic.
+ * \param untitype the unittype's name, as a std string
+ * \param number the number of ships
+ * \param tick what tick to set for. Tick 0 (before battle) is standard, no
+ * other is hardly used other than inside the engine.
+ */
+ void setFleet(std::string unittype, int number, int tick = 0);
+
+ void addFleet(std::string unittype, int number, int tick = 0);
+
+ void addFleet(std::map<std::string, int> units, int tick = 0);
+
+ /**Returns the numbers of units fo a specific type at a specific tick.
+ * \param unittype The shipname, as a std string
+ * \param tick The tick you want to look at, tick 0 (before battle) is default
+ * \return returns the number of units that params specifies.
+ */
+ int fleet(std::string unittype, int tick = 0);
+
+ /**Returns the number of free ships, that is: ships that aren't dead and not
+ * blocked.
+ * \param unittype The shipname, as a std string
+ * \param tick The tick you want to look at, tick 0 (before battle) is default
+ * \return returns the number of units that params specifies.
+ */
+ int freeFleet(std:: string unittype, int tick = 0);
+
+ /** This function is used to see how many ships of a specific type got
+ * blocked at a specific tick.
+ * \param unittype the name of the unittype
+ * \param tick what tick you want to look at
+ * \return the number of ships that got blocked at the specified tick.
+ */
+ int blockedFleet(std::string unittype, int tick = 0);
+
+ void setBlockedFleet(std::string unittype, int number, int tick = 0);
+
+ /** This function takes the vector with fleets and adds all their units of the
+ * specific tick to the current fleet's first tick. Main usage is for battle
+ * calculations.
+ * \param fleets a vector with fleet pointers
+ * \param tick an int to specify what tick to use. tick 0 (before battle)
+ * is default
+ * \todo add another tick parameter to specify what tick to use in the
+ * current fleet.
+ */
+ void addToThis(std::vector<Fleet*> fleets, int tick = 0);
+
+ /** This function takes a vector with fleets and distribute all ship losses
+ * between tick 0 and 1 in the current fleet and adds that to the specified
+ * tick in each fleet.
+ * \param fleets a vector with fleet pointers that holds the fleets that's
+ * going to share the losses.
+ * \param tick the tick to add the losses to for the fleets in the vector.
+ * \todo add another tick parameter to specify what tick to use in the
+ * current fleet.
+ */
+ void distributeLossesGains(std::vector<Fleet*> fleets, int tick = 0);
+
+ /** This functions takes the captured roids between tick 0 and 1 in the
+ * current fleet and divides them between the fleets given as param.
+ * \param fleets a vector with Fleet pointers, points to the fleets that
+ * should get parts of the roids.
+ * \param tick the tick to use in the fleets given as argument, when the
+ * roids are handed out.
+ * \todo add another tick parameter to specify what tick to use in the
+ * current fleet.
+ */
+ void distributeCappedRoids(std::vector<Fleet*> fleets, int tick = 0);
+
+ /** Checks through the vector with fleets to see who's in time for the
+ * specified tick and staying long enough so they're not too early.
+ * \param fleets a vector with Fleet pointers to use for the calculations
+ * \param stays the number of ticks the fleets stays, will be obsolee when
+ * I get the time.
+ * \param tick What the current tick is to use for the calculations
+ * \return returns a vector with the fleet that are in time for the battle
+ * and are staying long enough.
+ * \todo add the stays part as a integrated part of each fleet.
+ */
+ std::vector<Fleet*> calculateSide(std::vector<Fleet*> fleets, int stays = 0, int tick = 0);
+
+ /** Kill some ships of the specified type in the current fleet.
+ * \param unittype the name of the unit to kill
+ * \param number how many ships to kill
+ * \param tick what tick they where killed.
+ */
+ void killFleet(std::string unittype, int number, int tick = 0);
+
+ /**Block some ships of the specified type in the current fleet.
+ * \param unittype the name of the unit to block
+ * \param number how many ships to block
+ * \param tick what tick they where blocked.
+ */
+ void blockFleet(std::string unittype, int number, int tick = 0);
+
+ /** Set the resources of the specified type for the tick.
+ *
+ * \param type The name of the resource (in pa: metal,
+ * crystal and eonium (+ uninit for roids).
+ * \param number just simply the number of the specified resource.
+ * \param tick what tick to set
+ * \sa resource
+ */
+ void setResource(std::string type, int number, int tick = 0);
+
+ /** Adds a number ot the specified resource type.
+ * \param type The name of the resource (in pa: metal,
+ * crystal and eonium (+ uninit for roids).
+ * \param number just simply the number of the specified resource.
+ * \param tick what tick to set
+ * \sa resource
+ */
+ void addResource(std::string type, int number, int tick = 0);
+
+ /** Looks up the how much of a specific resource type the current fleet has.
+ *
+ * Resources is a kinda vague word, in general it's used as roid capping
+ * for hostile fleet and as salvage for friendly.
+ * \param type The name of the resource (in pa: metal,
+ * crystal and eonium (+ uninit for roids).
+ * \param tick what tick to set
+ * \returns simply returns the number of the specific resource this fleet
+ * has.
+ */
+ int resource(std::string type, int tick = 0)const;
+
+ void resetResources();
+
+ /** This function tells how many ticks the fleet stays at it's target.
+ * \returns the number of ticks as an int.
+ */
+ int stays() const;
+ void setStays(int ticks);
+
+ /** This is a little more advanced function. It makes a a number of units
+ * of a specific unittype shoot at the current fleet and calculates the
+ * losses.
+ *
+ * Atm all calculations are done for tick 0/1
+ * \param unittype The name of the unit that shots at the current fleet.
+ * \param number The number of the specific unittype that shoot.
+ * \param hitunits a map to count the number of killed units, just if the
+ * rest of the program needs it.
+ * \todo add a parameter to specify what tick to calc for and move out as
+ * much of the code as possible because it's kinda crowded atm and lots of
+ * very similar stuff in both the take* functions.
+ * \sa takeEMP
+ */
+ void takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits);
+
+ /**This is a little more advanced function. It makes a a number of units
+ * of a specific unittype shoot at the current fleet and calculates how
+ * many got blocked..
+ *
+ * Atm all calculations are done for tick 0/1
+ * \param unittype The name of the unit that shots at the current fleet.
+ * \param number The number of the specific unittype that shoot.
+ * \todo add a parameter to specify what tick to calc for and move out as
+ * much of the code as possible because it's kinda crowded atm and lots of
+ * very similar stuff in both the take* functions.
+ * \sa takeShoot
+ */
+ void takeEMP(std::string unittype, int number);
+
+ void calculateLostStealships(std::string unittype, std::map<std::string, int> stolen, int tick = 1);
+
+ /** This function prints out all the ships in the fleet to stderr,
+ * mainly used for debugging.
+ */
+ void printFleet();
+
+ //static functions
+ //
+ /** This function is used to set the different races used.
+ * \param races a Simple RaceList which holds all the info
+ */
+ static void setRaces(RaceList& races);
+
+ /** This function is used to set all the units used in the game.
+ * \param units This is a simple UnitList holding all info needed.
+ */
+ static void setUnits(UnitList& units);
+
+ /** This function is used to get the list of races used.
+ * \returns it returns a simple RaceList just like the one that set it.
+ */
+ static const RaceList& Races();
+
+ /** This function is used to get the list of all the units in the game
+ * \returns a simple UnitList holding everything.
+ */
+ static const UnitList& Units();
protected:
- std::string m_sName;
- std::string m_sRace;
- std::map<std::string, std::vector<int> > m_Fleet;
- static std::map<std::string, UnitType> s_Units;
- static std::map<std::string, std::vector<int> > s_Races;
+
+ std::string m_sName;
+ std::string m_sRace;
+ int m_iETA;
+ FleetList m_Fleet;
+ FleetList m_BlockedFleet;
+ ResourceList m_Resources;
+ ArmorList m_Armor;
+ int m_iStays;
+
+
+
+ static UnitList s_Units;
+ static RaceList s_Races;
};
#endif