+
+ float guns = s_Units[unittype].guns() * number;
+
+
+ if (guns == 0)
+ return;
+
+ cerr << number << " " << unittype << ": with " << guns << " guns\n";
+
+ float 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 (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)
+ {
+ float maxguns = float((*j->second))/total * guns;
+ //cerr << "Now shooting at target: " << j->first << endl;
+
+ if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor())
+ m_Armor[j->first] = s_Units[j->first].armor();
+ double k = maxguns;
+
+ //cerr << "Targets agility: " << s_Units[j->first].agility() << endl;
+ //cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl;
+ while (k > 0)
+ {
+
+ if (*(j->second) <= 0)
+ break;
+
+ 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)
+ {
+ m_Armor[j->first] = s_Units[j->first].armor();
+ (*j->second)--;
+ hitunits[j->first]++;
+
+ //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]--;
+ }
+ }
+ }
+
+ }
+
+ cerr << hitunits[j->first] << " units of type: " << j->first << "killed\n";
+ if (k <= 0)
+ gunsleft -= maxguns;
+ else
+ gunsleft -= maxguns - k;
+ }
+ }
+ }