m_Fleet[unittype][tick] = number;
}
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::addFleet(std::string unittype, int number, int tick = 0)
+{
+ int earlier = 0;
+ int ticks = m_Fleet[unittype].size();
+
+ if (ticks != 0)
+ earlier = m_Fleet[unittype][ticks - 1];
+
+ for (int i = ticks; i <= tick; ++i)
+ {
+ m_Fleet[unittype].push_back(earlier);
+ }
+ m_Fleet[unittype][tick] += number;
+}
+
//////////////////////////////////////////////////////////////////////////
//
int Fleet::fleet(string unittype, int tick = 0)
{
int ticks = m_Resources[type].size();
- int latest = 0;
-
- if (ticks > 0)
- latest = m_Resources[type][ticks - 1];
+ int latest = resource(type, tick - 1);
for (int i = ticks; i <= tick; ++i)
m_Resources[type].push_back(latest);
//
int Fleet::resource(std::string type, int tick = 0) const
{
+ if (tick < 0)
+ return 0;
+
vector<int>const* resource = 0;
for (ResourceList::const_iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
{
return resource->at(tick);
}
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::resetResources()
+{
+ m_Resources.clear() ;
+}
+
//////////////////////////////////////////////////////////////////////////
//
void Fleet::printFleet()
{
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;
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)->setResource(res, (*j)->resource(res,tick-1) + lost, tick);
+
+ //(*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick);
+ (*j)->addResource(res,lost, tick);
}
}
}
//////////////////////////////////////////////////////////////////////////
//
-void Fleet::addPodsForLostRoids(int tick = 1)
+
+void Fleet::addFleet(std::map<string, int> units, int tick = 0)
{
- for (ResourceList::iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
- {
- setFleet("Astro Pod", fleet("Astro Pod", tick) + (resource(i->first, tick) - resource(i->first, tick - 1)), tick);
- }
+ for (map<string, int>::iterator i = units.begin(); i != units.end(); ++i)
+ addFleet(i->first, i->second, tick);
}
* other is hardly used other than inside the engine.
*/
void setFleet(std::string unittype, int number, int tick = 0);
+
+ void addFleet(std::string unittype, int number, int tick = 0);
+
+ void addFleet(std::map<std::string, int> units, int tick = 0);
+
/**Returns the numbers of units fo a specific type at a specific tick.
* \param unittype The shipname, as a std string
* \param tick The tick you want to look at, tick 0 (before battle) is default
*/
void distributeCappedRoids(std::vector<Fleet*> fleets, int tick = 0);
- void addPodsForLostRoids(int tick = 1);
-
/** Checks through the vector with fleets to see who's in time for the
* specified tick and staying long enough so they're not too early.
* \param fleets a vector with Fleet pointers to use for the calculations
*/
int resource(std::string type, int tick = 0)const;
+ void resetResources();
/** This is a little more advanced function. It makes a a number of units
* of a specific unittype shoot at the current fleet and calculates the
* losses.
return;
int skipped = 0;
+
+ for (vector<Fleet*>::iterator i = friendly.begin(); i != friendly.end(); ++i)
+ (*i)->resetResources();
+
+ for (vector<Fleet*>::iterator i = hostile.begin(); i != hostile.end(); ++i)
+ (*i)->resetResources();
+
for(int tick = 1; skipped < 20; ++tick)
{
//See who's in the battle at the current tick
//Reset roids
for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid)
+ {
setRoids(roid->first, roids(roid->first, tick-1), tick);
+ }
setPlanetScore(planetScore(tick - 1), tick);
allFriends.distributeLossesGains(friends, tick);
- allHostiles.addPodsForLostRoids();
allHostiles.distributeLossesGains(hostiles, tick);
allHostiles.distributeCappedRoids(hostiles, tick);
//
void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string, std::map<std::string, int> >& stealfriendly, std::map<std::string, std::map<std::string, int> >& stealhostile, int tick = 1)
{
+ if (planetScore(tick - 1) > 0)
+ setCapping(float(planetScore(tick - 1)) / hostile->score() / 10, tick);
+ else
+ setCapping(0, tick);
+
+ map<string, int> pods;
+
+
map<int, string> unitsinit; // order units after their ininitiative
for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
unitsinit[i->second.initiative()] = i->first;
if (s_Units[unittype].type() == "Pod")
{
- if (planetScore(tick - 1) > 0)
- {
- setCapping(float(planetScore(tick - 1)) / hostile->score() / 10, tick);
-
- cerr << "Capping is: " << capping(tick) << endl;
+ cerr << "Capping is: " << capping(tick) << endl;
- if (capping(tick) > 0)
+ if (capping(tick) > 0)
+ {
+ for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid)
{
- for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid)
- {
- int caproids = capping(tick) * roids(roid->first, tick - 1);
- int freepods = hostiletemp->freeFleet(unittype, 1);
+ int caproids = capping(tick) * roids(roid->first, tick - 1);
+ int freepods = hostiletemp->freeFleet(unittype, 1);
- cerr << "Possible to steal " << caproids << " " << roid->first << " roids\n";
- cerr << freepods << " free pods available\n";
-
- if (freepods <= 0)
- break;
- if (freepods < caproids)
- caproids = freepods;
+ cerr << "Possible to steal " << caproids << " " << roid->first << " roids\n";
+ cerr << freepods << " free pods available\n";
+
+ if (freepods <= 0)
+ break;
+ if (freepods < caproids)
+ caproids = freepods;
- cerr << caproids << " roids stolen\n";
+ cerr << caproids << " roids stolen\n";
- takeRoids(roid->first, caproids, tick);
+ takeRoids(roid->first, caproids, tick);
- //FIXME: Going to move this to the distribute roids section instead.. Not really move, I'll keep this, but "regenerate" the pods in the distribute ships function.
- hostiletemp->killFleet(unittype, caproids, 1);
- //int totroids = caproids + hostiletemp->resource(roid->first, 0);
- hostiletemp->addResource(roid->first, caproids, 1);
+ //FIXME: Going to move this to the distribute roids section instead.. Not really move, I'll keep this, but "regenerate" the pods in the distribute ships function.
+ hostiletemp->killFleet(unittype, caproids, 1);
+ pods[unittype] += caproids;
+ //int totroids = caproids + hostiletemp->resource(roid->first, 0);
+ hostiletemp->addResource(roid->first, caproids, 1);
- cerr << caproids << " stolen " << roid->first << " roids\n";
- }
+ cerr << caproids << " stolen " << roid->first << " roids\n";
}
}
}
*hostile = *hostiletemp;
delete hostiletemp;
}
+ hostile->addFleet(pods, 1);
+
}
//////////////////////////////////////////////////////////////////////////
</widget>
<widget class="QLineEdit" row="1" column="6" rowspan="1" colspan="2">
<property name="name">
- <cstring>EoniumEdit</cstring>
+ <cstring>UninitEdit</cstring>
</property>
<property name="focusPolicy">
<enum>NoFocus</enum>
</widget>
<widget class="QLineEdit" row="1" column="4" rowspan="1" colspan="2">
<property name="name">
- <cstring>UninitEdit</cstring>
+ <cstring>EoniumEdit</cstring>
</property>
<property name="focusPolicy">
<enum>NoFocus</enum>