s_Units = units;
-
+/*
for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); i++)
{
cerr << s_Units[(*i).first].Name() << "\t\t"
<< s_Units[(*i).first].type() << endl;
}
+ */
}
//////////////////////////////////////////////////////////////////////////
for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
{
string unittype = i->first;
+
+
if (m_Fleet[unittype].size() < 1)
- break;
- if (m_Fleet[unittype][0] == 0)
- break;
+ continue;
+ if (m_Fleet[unittype][0] == 0)
+ continue;
+
+
+ int totallost = fleet(unittype,1) - fleet(unittype, 0);
- int totallost = m_Fleet[unittype][1] - m_Fleet[unittype][0];
+
+ cerr << "Distributing type: " << unittype << " with a total loss of " << totallost << " units" << endl;
for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
{
int lost = totallost * ( (*j)->fleet(unittype, tick - 1) / m_Fleet[unittype][0] );
+ cerr << (*j)->name() << " gaining " << lost << " " << unittype << endl;
(*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick);
}
}
for (vector<Fleet*>::iterator i = fleets.begin(); i != fleets.end(); ++i)
{
if (( tick - (*i)->ETA()) >= 0 && (tick - (*i)->ETA()) < stays)
+ {
fl.push_back((*i));
+ cerr << "Using fleet " << (*i)->name() << " for tick " << tick << endl;
+ }
else if ((*i)->name() == "Home Planet")
fl.push_back((*i));
}
void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits)
{
- cerr << unittype << ": " << number << " in number\n";
int guns = s_Units[unittype].guns() * number;
if (guns == 0)
return;
- cerr << unittype << " with " << guns << " guns\n";
+ cerr << unittype << ": with " << guns << " guns\n";
int gunsleft = guns;
for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
{
string ta = s_Units[unittype].target(count);
- cerr << "Shooting at target class: " << ta << endl;
+ cerr << "Shooting at target class: " << ta << endl;
while (gunsleft > 0)
{
{
if (m_Fleet[j->first].size() == 0)
- break;
+ continue;
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 && ( ta == j->second.unitClass() || ta == "All"))
{
- cerr << "Looking at target: " << j->first << endl;
+ // cerr << "Looking at target: " << j->first << endl;
targets[j->first] = &m_Fleet[j->first][1];
}
if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor())
m_Armor[j->first] = s_Units[j->first].armor();
- float k = maxguns;
+ double k = maxguns;
- int blaha = 0;
cerr << "Targets agility: " << s_Units[j->first].agility() << endl;
cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl;
while (k > 0)
if (*(j->second) <= 0)
break;
- k -= 100/(25+s_Units[unittype].weaponSpeed() - s_Units[j->first].agility());
+
+ int wpsp = s_Units[unittype].weaponSpeed();
+ int agil = s_Units[j->first].agility();
+
+ k -= float(100)/(25 + wpsp - agil);
+ //cout << "Used " << blaha << " guns to hit with one shot.\n";
+ //cout << "WPSP: " << wpsp << "\nAgil: " << agil << endl;
+
m_Armor[j->first] -= s_Units[unittype].power();
if (m_Armor[j->first] <= 0)
{
//
void Fleet::takeEMP(std::string unittype, int number)
{
+ int guns = s_Units[unittype].guns() * number;
+ if (guns == 0)
+ return;
+ cerr << unittype << ": with " << guns << " guns\n";
+
+ int gunsleft = guns;
+ for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
+ {
+ string ta = s_Units[unittype].target(count);
+ cerr << "Shooting at target class: " << ta << endl;
+ while (gunsleft > 0)
+ {
+
+ map<string, int*> targets;
+
+ for (UnitList::iterator j = s_Units.begin(); j != s_Units.end(); ++j)
+ {
+ if (j->second.type() == "PDS")
+ continue;
+
+ if (m_Fleet[j->first].size() == 0)
+ continue;
+
+ if (m_Fleet[j->first].size() == 1)
+ m_Fleet[j->first].push_back(m_Fleet[j->first][0]);
+
+ //cerr << "Target is class: " << j->second.type() << endl;
+
+ if (m_Fleet[j->first][1] > 0 && ( ta == j->second.unitClass() || ta == "All"))
+ {
+
+ // cerr << "Looking at target: " << j->first << endl;
+ targets[j->first] = &m_Fleet[j->first][1];
+ }
+
+ }
+
+ if (targets.size() == 0)
+ break;
+
+ 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;
+ cerr << "Now shooting at target: " << j->first << endl;
+
+ double k = maxguns;
+
+ int hits = 0;
+
+ while (k > 0)
+ {
+
+ if (*(j->second) <= 0)
+ break;
+
+ int eres = s_Units[j->first].EMP();
+
+ k -= float(100)/(100-eres);
+ hits++;
+ blockFleet(j->first, 1);
+ }
+
+ cerr << hits << " units of type: " << j->first << " blocked\n";
+ if (k <= 0)
+ gunsleft -= maxguns;
+ else
+ gunsleft -= maxguns - k;
+ }
+ }
+ }
}
//////////////////////////////////////////////////////////////////////////
return resource->at(tick);
}
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::printFleet()
+{
+ for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
+ {
+ for (int tick = 0; tick < 5 ;++tick)
+ {
+ int num = fleet(i->first, tick);
+
+ if (num <= 0)
+ break;
+ cerr << num << " " << i->first << " during tick: " << tick << endl;
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::blockFleet(std::string unittype, int number, int tick = 0)
+{
+ if (m_BlockedFleet[unittype].size() >= 1)
+ {
+ m_BlockedFleet[unittype][0] += number;
+ if (m_BlockedFleet[unittype].size() > 1)
+ m_BlockedFleet[unittype][1] += number;
+ else
+ m_BlockedFleet[unittype].push_back(m_BlockedFleet[unittype][0]);
+ }
+ else
+ {
+ m_BlockedFleet[unittype].push_back(number);
+ m_BlockedFleet[unittype].push_back(number);
+ }
+}