]> ruin.nu Git - hbs.git/blobdiff - bs/planet.cpp
battle algorithms are getting closer.. ;)
[hbs.git] / bs / planet.cpp
index 9c421ccc4b9b71abe7e58af0d96e7caed2a87f28..4ae9c59e4d517e87b9047c7eb9b00dee837e3dad 100644 (file)
@@ -86,7 +86,7 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
        {
                //See who's in the battle at the current tick
                vector<Fleet*> friends = calculateSide(friendly, 6, tick);
-               vector<Fleet*> hostiles = calcualteSide(hostile, 3, tick);
+               vector<Fleet*> hostiles = calculateSide(hostile, 3, tick);
 
                // No idea to calculate anything if noone is there.. ;)
                if (hostiles.size() == 0)
@@ -98,16 +98,71 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
                Fleet allHostiles;
                allHostiles.addToThis(hostiles);
 
-               calculateOneTick(&allFriends, &allHostiles);
+               map<string, map<string, int> > stealfriendly;
+               map<string, map<string, int> > stealhostile;
+               
+               calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile );
 
                allFriends.distributeLossesGains(friends, tick);
-               allHostile.distributeLossesGains(friends, tick);
+               allHostiles.distributeLossesGains(friends, tick);
        }
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-void calcOneTick(Planet* friendly, 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 )
 {
+       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;
+
+       for (map<int, string>::iterator i = unitsinit.begin(); i != unitsinit.end(); ++i)
+       {
+               Fleet* hostiletemp = new Fleet(*hostile);
+               Planet* friendlytemp = new Planet(*friendly);
+               
+               string unittype = i->second;
+
+               if (s_Units[unittype].type() == "EMP")  
+               {
+                       hostiletemp->takeEMP(unittype, friendly->freeFleet(unittype, 1));
+                       friendlytemp->takeEMP(unittype, hostile->freeFleet(unittype, 1));
+               }
+               else if (s_Units[unittype].type() == "Steal")
+               {
+                       hostiletemp->takeShoot(unittype, friendly->freeFleet(unittype, 1), stealfriendly[unittype]);
+                       friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), stealhostile[unittype]);
+               }
+               else
+               {
+                       map<string, int> temp;
+                       hostiletemp->takeShoot(unittype, friendly->freeFleet(unittype, 1), temp);
+                       friendlytemp->takeShoot(unittype, hostile->freeFleet(unittype, 1), temp);
+               }
+
+               if (s_Units[unittype].type() == "Pod")
+               {
+                       float capping = friendly->m_iScore / hostile->score() /  10;
+      for (RoidList::iterator roids = m_Roids.begin(); roids != m_Roids.end(); ++roids)
+                       {
+                               int caproids = capping * roids->second[0];
+                               int freepods = hostiletemp->freeFleet(unittype, 1);
+                               
+                               if (freepods == 0)
+                                       break;
+                               if (freepods < caproids)
+                                       caproids = caproids - freepods;
+                                       
+                               roids->second.push_back(roids->second[0] - caproids);
+                               hostiletemp->killFleet(unittype, caproids, 1);
+                       }
+               }
+
+               //set the the objects so they point at the modified objects
+               delete friendly;
+               friendly = friendlytemp;
+               delete hostile;
+               hostile = hostiletemp;
+       }
 }