]> ruin.nu Git - hbs.git/blobdiff - bs/planet.cpp
battle algorithms are getting more and more mature and stats.conf is updated.
[hbs.git] / bs / planet.cpp
index 4ae9c59e4d517e87b9047c7eb9b00dee837e3dad..41d92ac51eb2ed6004bab3b01c8009a46b8fdefb 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "planet.h"
 
+#include <iostream>
 using namespace std;
 
 Planet::Planet()
@@ -82,7 +83,11 @@ void Planet::setRoids(std::string type, int number)
 //
 void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile)
 {
-       for(int tick = 1; ; ++tick)
+       if (hostile.size() == 0)
+                       return;
+
+       int skipped = 0;
+       for(int tick = 1; skipped < 20; ++tick)
        {
                //See who's in the battle at the current tick
                vector<Fleet*> friends = calculateSide(friendly, 6, tick);
@@ -90,7 +95,12 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
 
                // No idea to calculate anything if noone is there.. ;)
                if (hostiles.size() == 0)
-                       break;
+               {
+                       skipped++;
+                       continue;
+               }
+               else
+                       skipped = 0;
 
                Planet allFriends;
                allFriends.addToThis(friends);
@@ -104,7 +114,7 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
                calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile );
 
                allFriends.distributeLossesGains(friends, tick);
-               allHostiles.distributeLossesGains(friends, tick);
+               allHostiles.distributeLossesGains(hostiles, tick);
        }
 }
 
@@ -114,7 +124,7 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
 {
        map<int, string> unitsinit; // order units after their ininitiative
        for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
-               unitsinit[i->second.ETA()] = i->first;
+               unitsinit[i->second.initiative()] = i->first;
 
        for (map<int, string>::iterator i = unitsinit.begin(); i != unitsinit.end(); ++i)
        {
@@ -123,6 +133,8 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
                
                string unittype = i->second;
 
+               cerr << "Initiative: " << s_Units[unittype].initiative() << " with unit: " << unittype << endl;
+
                if (s_Units[unittype].type() == "EMP")  
                {
                        hostiletemp->takeEMP(unittype, friendly->freeFleet(unittype, 1));
@@ -159,10 +171,10 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
                }
 
                //set the the objects so they point at the modified objects
-               delete friendly;
-               friendly = friendlytemp;
-               delete hostile;
-               hostile = hostiletemp;
+               *friendly = *friendlytemp;
+               delete friendlytemp;
+               *hostile = *hostiletemp;
+               delete hostiletemp;
        }
 }