+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::blockFleet(std::string unittype, int number, int tick)
+{
+ 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);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::distributeCappedRoids(std::vector<Fleet*> fleets, int tick)
+{
+ for (ResourceList::iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
+ {
+ string res = i->first;
+
+
+ cerr << "Distributing type: " << res << endl;
+ for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
+ cout << (*j) << endl;
+
+ if (m_Resources[res].size() < 2)
+ continue;
+ if (m_Resources[res][1] == 0)
+ continue;
+
+
+ int totcapped = resource(res,1) - resource(res, 0);
+
+
+ cerr << "Distributing type: " << res << " with a total gain of " << totcapped << " roids" << endl;
+
+ cerr << "Total number of roids before: " << resource(res, 0) << " and after : " << resource(res, 1) << endl;
+
+ for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
+ {
+ unsigned fl1 = (*j)->score(tick - 1);
+ float part = float(fl1) / score(0) ;
+ int lost = int(totcapped * part);
+
+ cerr << (*j)->name() << " gaining " << lost << " " << res << " since it's " << part * 100 << "% of the whole score, and it had : " << fl1 << " score last tick.. compared to fleet total of: " << score(0) << endl;
+
+ //(*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick);
+ (*j)->addResource(res,lost, tick);
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::addFleet(std::map<string, int> units, int tick)
+{
+ for (map<string, int>::iterator i = units.begin(); i != units.end(); ++i)
+ addFleet(i->first, i->second, tick);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+int Fleet::stays() const
+{
+ return m_iStays;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::setStays(int ticks)
+{
+ m_iStays = ticks;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::calculateLostStealships(string unittype, std::map<std::string, int> stolen, int tick)
+{
+ int stealscore = 0;
+ for (map<string, int>::iterator i = stolen.begin(); i != stolen.end(); ++i)
+ {
+ stealscore += int(stolen[i->first] * (s_Units[i->first].totRes() / 10.0));
+ }
+
+ int lost = int(stealscore / (s_Units[unittype].totRes() / 10.0));
+
+ cerr << "Lost " << lost << " " << unittype << " due to stealing ships worth: " << stealscore << endl;
+ killFleet(unittype, lost, tick);
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::distributeStolenShips(std::map<std::string, std::map<std::string, int> > stolen, std::vector<Fleet*> fleets, int tick)
+{
+ for(map<string, map<string, int> >::iterator i = stolen.begin(); i != stolen.end(); ++i)
+ {
+ int totalstealers = 0;
+ for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
+ totalstealers += (*j)->fleet(i->first, tick - 1);
+
+ for (map<string, int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
+ {
+ for (vector<Fleet*>::iterator k = fleets.begin(); k != fleets.end(); ++k)
+ {
+ int stolen = int(float ((*k)->fleet(i->first, tick - 1)) / totalstealers * j->second);
+ (*k)->addFleet(j->first, stolen, tick);
+ }
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::calculateSalvage()
+{
+ for (FleetList::iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
+ {
+
+ map<string, int> res = s_Units[i->first].resources();
+
+ if (i->second.size() > 0)
+ cerr << endl << i->first << ": ";
+
+ int tick = 0;
+ for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j, ++tick)
+ {
+ int lostunits = fleet(i->first, tick - 1) - fleet(i->first, tick);
+
+ if (lostunits <= 0)
+ continue;
+ cerr << "(" << tick << ":" << fleet(i->first, tick) << ") ";
+ for (map<string, int>::iterator k = res.begin(); k != res.end(); ++k)
+ addResource(k->first, int(lostunits * k->second * 0.25), tick);
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::resetTicks()
+{
+ for (FleetList::iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
+ {
+ if ( i->second.size() < 2)
+ continue;
+
+ int temp = i->second[0];
+ i->second.clear();
+
+ if (temp > 0)
+ i->second.push_back(temp);
+ }
+ resetResources();
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+int Fleet::freePodGuns(int tick)
+{
+ int guns = 0;
+ for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
+ {
+ if (s_Units[i->first].type() == "Pod")
+ {
+ guns += freeFleet(i->first, tick) * s_Units[i->first].guns();
+ }
+ }
+ guns -= usedPodGuns(tick);
+ return guns;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+int Fleet::usedPodGuns(int tick) const
+{
+ int ticks = m_UsedPodGuns.size();
+
+ if (ticks == 0)
+ return 0;
+
+ if (tick < 0)
+ return m_UsedPodGuns[0];
+
+ --ticks;
+
+ if (ticks < tick)
+ return m_UsedPodGuns[ticks];
+
+ return m_UsedPodGuns[tick];
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::usePodGuns(int tick, int guns)
+{
+ int ticks = m_UsedPodGuns.size();
+
+ for (int i = ticks; i <= tick; ++i)
+ {
+ m_UsedPodGuns.push_back(0);
+ }
+ m_UsedPodGuns[tick] += guns;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+std::map<std::string, int*> Fleet::findTargets(std::string targetClass,int& total, int attackerType)
+{
+ map<string, int*> targets;
+
+ for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
+ {
+ if (m_Fleet[i->first].size() == 0)
+ continue;
+
+ if (m_Fleet[i->first].size() == 1 )
+ m_Fleet[i->first].push_back(m_Fleet[i->first][0]);
+
+ if (m_Fleet[i->first][1] > 0 && ( targetClass == i->second.unitClass() || targetClass == "All"))
+ {
+ if (i->second.unitClass() == "PDS" && attackerType == 1)
+ continue;
+ targets[i->first] = &m_Fleet[i->first][1];
+ total += m_Fleet[i->first][1];
+ }
+ }
+ return targets;
+}