#include "fleet.h"
#include <iostream>
+#include <cstdlib>
using namespace std;
//Static variables
//
void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits)
{
+ int guns = s_Units[unittype].guns() * number;
+ int power = s_Units[unittype].power() * number;
+
+ int gunsleft = guns;
+ for (vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
+ {
+
+ while (gunsleft > 0)
+ {
+
+ map<string, int*> targets;
+
+ for (UnitList::iterator j = s_Units.begin(); j != s_Units.end(); ++j)
+ {
+ if (m_Fleet[j->first].size() == 0)
+ break;
+
+ if (m_Fleet[j->first].size() == 1)
+ m_Fleet[j->first].push_back(m_Fleet[j->first][0]);
+
+ if (m_Fleet[j->first][1] > 0 && (*i) == j->second.type())
+ targets[j->first] = &m_Fleet[j->first][1];
+ }
+
+ int total = 0;
+ for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
+ total += (*j->second);
+
+ for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
+ {
+ int maxguns = (*j->second)/total * guns;
+
+
+ if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor())
+ m_Armor[j->first] = s_Units[j->first].armor();
+ int k = maxguns;
+ while (k > 0)
+ {
+
+ if (*(j->second) <= 0)
+ break;
+ k -= 100/(25+s_Units[unittype].weaponSpeed() - s_Units[j->first].agility());
+ m_Armor[j->first] -= s_Units[unittype].power();
+ if (m_Armor[j->first] <= 0)
+ {
+ m_Armor[j->first] = s_Units[j->first].armor();
+ (*j->second)--;
+
+ //There is a chance that we're hitting a blocked ship.
+ if (m_BlockedFleet[j->first].size() >= 1)
+ {
+ int test = rand() % m_BlockedFleet[j->first][0];
+ if (test == 1
+ && m_BlockedFleet[j->first][0] > 0)
+ {
+ if (m_BlockedFleet[j->first].size() == 1)
+ m_BlockedFleet[j->first].push_back(m_BlockedFleet[j->first][0] - 1);
+ else if (m_BlockedFleet[j->first][1] > 0)
+ m_BlockedFleet[j->first][1]--;
+ }
+ }
+ }
+ }
+ if (k <= 0)
+ gunsleft -= maxguns;
+ else
+ gunsleft -= maxguns - k;
+ }
+ }
+ }
}
//////////////////////////////////////////////////////////////////////////
//
void Fleet::takeEMP(std::string unittype, int number)
{
+
}
//////////////////////////////////////////////////////////////////////////
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.
std::vector<Fleet*> calculateSide(std::vector<Fleet*> fleets, int stays = 0, int tick = 0);
- void takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits);
- void takeEMP(std::string unittype, int number);
void killFleet(std::string unittype, int number, int tick = 0);
void setResource(std::string type, int number, int tick = 0);
int resource(std::string type, int tick = 0)const;
+ void takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits);
+ void takeEMP(std::string unittype, int number);
protected:
FleetList m_Fleet;
FleetList m_BlockedFleet;
ResourceList m_Resources;
+ ArmorList m_Armor;
+
static UnitList s_Units;