]> ruin.nu Git - hbs.git/blobdiff - bs/planet.cpp
The work on the combat algorithm is going forward, nothing worth compiling yet though.
[hbs.git] / bs / planet.cpp
index 4fa69786a009e426ae8dd666724965d3aa89465c..9c421ccc4b9b71abe7e58af0d96e7caed2a87f28 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "planet.h"
 
+using namespace std;
+
 Planet::Planet()
 {
        m_sRace = "Planet";
@@ -42,23 +44,70 @@ void Planet::setPlanetScore(unsigned i)
 
 //////////////////////////////////////////////////////////////////////////
 //
-int roids(std::string type, int tick = 0) const
+int Planet::roids(std::string type, int tick = 0) const
 {
-       ticks = m_Roids[type].size();
+       // const... I would like [] as for const types: int ticks = m_Roids[type].size();
+       
+       vector<int>const* roids = 0;
+       for (RoidList::const_iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
+       {
+               if (i->first == type)
+               {
+                       roids = &i->second;
+                       break;
+               }
+       }
+       if (roids == 0)
+               return 0;
+
+       int ticks = roids->size();
+
        if( ticks == 0)
                return 0;
        if (ticks < tick)
-               return m_Roids[type][ticks];
-       return m_Roids[type][tick];
+               return roids->at(ticks);
+       return roids->at(tick);
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-void setRoids(std::string type, int number)
+void Planet::setRoids(std::string type, int number)
 {
        if (m_Roids[type].size() == 0)
-               m_Roids.push_back(number);
+               m_Roids[type].push_back(number);
        m_Roids[type][0] = number;
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile)
+{
+       for(int tick = 1; ; ++tick)
+       {
+               //See who's in the battle at the current tick
+               vector<Fleet*> friends = calculateSide(friendly, 6, tick);
+               vector<Fleet*> hostiles = calcualteSide(hostile, 3, tick);
+
+               // No idea to calculate anything if noone is there.. ;)
+               if (hostiles.size() == 0)
+                       break;
+
+               Planet allFriends;
+               allFriends.addToThis(friends);
+               
+               Fleet allHostiles;
+               allHostiles.addToThis(hostiles);
+
+               calculateOneTick(&allFriends, &allHostiles);
+
+               allFriends.distributeLossesGains(friends, tick);
+               allHostile.distributeLossesGains(friends, tick);
+       }
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void calcOneTick(Planet* friendly, Fleet* Hostile)
+{
+}