<< s_Units[(*i).first].ETA() << "\t"
<< s_Units[(*i).first].type() << endl;
}
-
- */
+*/
}
//////////////////////////////////////////////////////////////////////////
for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
{
- if (i->second.size() >= tick)
- break;
+ int ticks = i->second.size();
+ if (ticks == 0)
+ continue;
+ --ticks;
+ if ( ticks < tick)
+ tot_score += i->second[ticks] * s_Units[i->first].totRes() / 10;
+ else
tot_score += i->second[tick] * s_Units[i->first].totRes() / 10;
}
float guns = s_Units[unittype].guns() * number;
- cerr << number << " " << unittype << ": with " << guns << " guns\n";
if (guns == 0)
return;
- cerr << unittype << ": with " << guns << " guns\n";
+ 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)
for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
{
- int maxguns = (*j->second)/total * guns;
+ float maxguns = float((*j->second))/total * guns;
cerr << "Now shooting at target: " << j->first << endl;
double k = maxguns;
void Fleet::setResource(std::string type, int number, int tick = 0)
{
- if (m_Resources[type].size() <= tick)
+ int ticks = m_Resources[type].size();
+ for (int i = ticks; i <= tick; ++i)
m_Resources[type].push_back(number);
m_Resources[type][tick] = number;
}
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::addResource(std::string type, int number, int tick = 0)
+{
+
+ int ticks = m_Resources[type].size();
+ int latest = 0;
+
+ if (ticks > 0)
+ latest = m_Resources[type][ticks - 1];
+
+ for (int i = ticks; i <= tick; ++i)
+ m_Resources[type].push_back(latest);
+ m_Resources[type][tick] += number;
+}
+
//////////////////////////////////////////////////////////////////////////
//
int Fleet::resource(std::string type, int tick = 0) const
m_BlockedFleet[unittype].push_back(number);
}
}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::distributeCappedRoids(std::vector<Fleet*> fleets, int tick = 0)
+{
+ 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 = 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)->addResource(res, lost, tick);
+ }
+ }
+}
+
+