+void Planet::setRoids(std::string type, int number, int tick)
+{
+ int ticks = m_Roids[type].size();
+ int roids = 0;
+ if (m_Roids[type].size() > 0)
+ roids = m_Roids[type][m_Roids[type].size() - 1];
+
+ for (int i = ticks; i <= tick; ++i )
+ m_Roids[type].push_back(roids);
+ m_Roids[type][tick] = number;
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Planet::takeRoids(std::string type, int number, int tick)
+{
+ int ticks = m_Roids[type].size();
+ int roids = 0;
+ if (m_Roids[type].size() > 0)
+ roids = m_Roids[type][m_Roids[type].size() - 1];
+
+ for (int i = ticks; i <= tick; ++i )
+ m_Roids[type].push_back(roids);
+ m_Roids[type][tick] -= number;
+
+ if (type != "uninit")
+ addPlanetScore(-3000*number, tick);
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile)
+{
+ if (hostile.size() == 0)
+ return;
+
+ int skipped = 0;
+
+ for (vector<Fleet*>::iterator i = friendly.begin(); i != friendly.end(); ++i)
+ (*i)->resetTicks();
+
+ for (vector<Fleet*>::iterator i = hostile.begin(); i != hostile.end(); ++i)
+ (*i)->resetTicks();
+
+ for(int tick = 1; skipped < 20; ++tick)
+ {
+ //See who's in the battle at the current tick
+ vector<Fleet*> friends = calculateSide(friendly, 6, tick);
+ vector<Fleet*> hostiles = calculateSide(hostile, 3, tick);
+
+ // No idea to calculate anything if noone is there.. ;)
+ if (hostiles.size() == 0)
+ {
+ skipped++;
+ continue;
+ }
+ else
+ skipped = 0;
+
+ Planet allFriends;
+ allFriends.addToThis(friends, tick - 1);
+
+ /*for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
+ allFriends.setRoids(i->first, roids(i->first, tick));
+
+ allFriends.setPlanetScore(m_iScore);*/
+
+ Fleet allHostiles;
+ allHostiles.addToThis(hostiles, tick - 1);
+
+ map<string, map<string, int> > stealfriendly;
+ map<string, map<string, int> > stealhostile;
+
+ //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);
+
+
+ calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile, tick );
+
+ //allFriends.printFleet();
+
+ allFriends.distributeLossesGains(friends, tick);
+ allFriends.distributeStolenShips(stealfriendly, friends, tick);
+
+ allHostiles.distributeLossesGains(hostiles, tick);
+ allHostiles.distributeCappedRoids(hostiles, tick);
+ allHostiles.distributeStolenShips(stealhostile, hostiles, tick);
+
+ calculateScoreLoss(friends, tick);
+
+ /* for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
+ setRoids(i->first, roids(i->first, 1), tick);*/
+ }
+
+ for (vector<Fleet*>::iterator i = friendly.begin(); i != friendly.end(); ++i)
+ (*i)->calculateSalvage();
+
+ for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
+ {
+ for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
+ cout << i->first << " roids : " << (*j) << endl;
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+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)