]> ruin.nu Git - hbs.git/commitdiff
takeShoot function might work now..
authorMichael Andreen <harv@ruin.nu>
Tue, 9 Apr 2002 21:57:33 +0000 (21:57 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 9 Apr 2002 21:57:33 +0000 (21:57 +0000)
bs/fleet.cpp
bs/fleet.h

index 3ce2b71344e50574694a6280d54c6c52cd2a899a..432f16595efadab7d1e8c479fa8cb03678ac7292 100644 (file)
@@ -18,6 +18,7 @@
 #include "fleet.h"
 
 #include <iostream>
+#include <cstdlib>
 using namespace std;
 
 //Static variables
@@ -260,12 +261,83 @@ int Fleet::freeFleet(std:: string unittype, int tick = 0)
 //
 void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits)
 {
+       int guns = s_Units[unittype].guns() * number;
+       int power = s_Units[unittype].power() * number;
+
+       int gunsleft = guns;
+       for (vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
+       {
+
+               while (gunsleft > 0)
+               {
+       
+                       map<string, int*> targets;
+
+                       for (UnitList::iterator j = s_Units.begin(); j != s_Units.end(); ++j)
+                       {
+                               if (m_Fleet[j->first].size() == 0)
+                                       break;
+
+                               if (m_Fleet[j->first].size() == 1)
+                                       m_Fleet[j->first].push_back(m_Fleet[j->first][0]);
+
+                               if (m_Fleet[j->first][1] > 0 && (*i) == j->second.type())
+                                       targets[j->first] = &m_Fleet[j->first][1];
+                       }
+
+                       int total = 0;
+                       for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
+                               total += (*j->second);
+
+                       for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
+                       {
+                               int maxguns = (*j->second)/total * guns;
+                               
+
+                               if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor())
+                                       m_Armor[j->first] = s_Units[j->first].armor();
+                               int k = maxguns;
+                               while (k > 0)   
+                               {
+
+                                       if (*(j->second) <= 0)
+                                               break;
+                                       k -= 100/(25+s_Units[unittype].weaponSpeed() - s_Units[j->first].agility());
+                                       m_Armor[j->first] -= s_Units[unittype].power();
+                                       if (m_Armor[j->first] <= 0)
+                                       {
+                                               m_Armor[j->first] = s_Units[j->first].armor();
+                                               (*j->second)--;
+                                               
+                                               //There is a chance that we're hitting a blocked ship.
+                                               if (m_BlockedFleet[j->first].size() >= 1)
+                                               {
+                                                       int test = rand() % m_BlockedFleet[j->first][0];
+                                                       if (test == 1
+                                                               && m_BlockedFleet[j->first][0] > 0)
+                                                       {
+                                                               if (m_BlockedFleet[j->first].size() == 1)
+                                                                       m_BlockedFleet[j->first].push_back(m_BlockedFleet[j->first][0] - 1);
+                                                               else if (m_BlockedFleet[j->first][1] > 0)
+                                                                       m_BlockedFleet[j->first][1]--;
+                                                       }
+                                               }
+                                       }
+                               }
+                               if (k <= 0)
+                                       gunsleft -= maxguns;
+                               else
+                                       gunsleft -= maxguns - k;
+                       }
+               }
+       }
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
 void Fleet::takeEMP(std::string unittype, int number)
 {
+
 }
 
 //////////////////////////////////////////////////////////////////////////
index dfc5fdd6657479343f5219474e7dae2b3dcb54d4..b706bbd919bdb03b3a358ed1ee27a9c8a6b52e1c 100644 (file)
@@ -29,6 +29,7 @@ typedef std::map<std::string, std::vector<int> > FleetList;
 typedef std::map<std::string, UnitType>        UnitList;
 typedef std::map<std::string, std::vector<int> > RaceList;
 typedef std::map<std::string, std::vector<int> > ResourceList;
+typedef std::map<std::string, int> ArmorList;
 //! An abstraction of a fleet and the engine for the battle simulation.
 /**This class and it's derivates is  the engine for the whole battlesystem.
   *    One of the few parts that I plan make fully portable.
@@ -105,13 +106,13 @@ public:
 
        std::vector<Fleet*> calculateSide(std::vector<Fleet*> fleets, int stays = 0, int tick = 0);
 
-       void takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits);
-       void takeEMP(std::string unittype, int number);
        void killFleet(std::string unittype, int number, int tick = 0);
 
        void setResource(std::string type, int number, int tick = 0);
        int resource(std::string type, int tick = 0)const;
        
+       void takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits);
+       void takeEMP(std::string unittype, int number);
 protected:
 
 
@@ -121,6 +122,8 @@ protected:
        FleetList       m_Fleet;
        FleetList       m_BlockedFleet;
        ResourceList m_Resources;
+       ArmorList       m_Armor;
+       
 
 
        static UnitList s_Units;