]> ruin.nu Git - hbs.git/blobdiff - bs/planet.cpp
a couple of bugs solved..
[hbs.git] / bs / planet.cpp
index 3c4404f800d4dee61ae9a968b6015f8eb27dde4a..f57d20877ed5455f262c495271204c4daa1f6795 100644 (file)
@@ -146,6 +146,13 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
                        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
@@ -177,7 +184,9 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
 
                //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);
                
@@ -188,7 +197,6 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
 
                allFriends.distributeLossesGains(friends, tick);
 
-               allHostiles.addPodsForLostRoids();
                allHostiles.distributeLossesGains(hostiles, tick);
                allHostiles.distributeCappedRoids(hostiles, tick);
 
@@ -209,6 +217,14 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
 //
 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;
@@ -241,38 +257,34 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
 
                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";
                                }
                        }
                }
@@ -283,6 +295,8 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
                *hostile = *hostiletemp;
                delete hostiletemp;
        }
+       hostile->addFleet(pods, 1);
+       
 }
 
 //////////////////////////////////////////////////////////////////////////