]> ruin.nu Git - hbs.git/commitdiff
code cleenup..
authorMichael Andreen <harv@ruin.nu>
Sun, 7 Jul 2002 23:07:01 +0000 (23:07 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 7 Jul 2002 23:07:01 +0000 (23:07 +0000)
bs/fleet.cpp
bs/fleet.h

index 01ceb2b930e0cc70c3c6e24077822b18f892bd00..0b8598c1c6e916cd262bc2c87771c192efc2b8ce 100644 (file)
@@ -389,35 +389,12 @@ void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, in
                //cerr << "Shooting at target class: " << ta << endl;
                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)
-                                       continue;
-
-
-                               if (m_Fleet[j->first].size() == 1 )
-                                       m_Fleet[j->first].push_back(m_Fleet[j->first][0]);
-
-                               //cerr << "Target is class: " << j->second.type() << endl;
-
-                               if (m_Fleet[j->first][1] > 0  && ( ta == j->second.unitClass() || ta == "All"))
-                               {
-
-                                       //      cerr << "Looking at target: " << j->first << endl;
-                                       targets[j->first] = &m_Fleet[j->first][1];
-                               }
-                       }
+                       int total = 0;
+                       map<string, int*> targets = findTargets(ta,total, 0);
 
                        if (targets.size() == 0)
                                break;
 
-                       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)
                        {
                                float maxguns = float((*j->second))/total * guns;
@@ -495,44 +472,15 @@ void Fleet::takeEMP(std::string unittype, int number, std::map<std::string, int>
                //cerr << "Shooting at target class: " << ta << endl;
                while (gunsleft > 0)
                {
-
-                       map<string, int*> targets;
-
-                       for (UnitList::iterator j = s_Units.begin(); j != s_Units.end(); ++j)
-                       {
-                               if (j->second.type() == "PDS")
-                                       continue;
-
-                               if (freeFleet(j->first, 1) <= 0)
-                                       continue;
-
-                               if (m_Fleet[j->first].size() == 0)
-                                       continue;
-
-                               if (m_Fleet[j->first].size() == 1)
-                                       m_Fleet[j->first].push_back(m_Fleet[j->first][0]);
-
-                               //cerr << "Target is class: " << j->second.type() << endl;
-
-                               if (m_Fleet[j->first][1] > 0  && ( ta == j->second.unitClass() || ta == "All"))
-                               {
-
-                                       //      cerr << "Looking at target: " << j->first << endl;
-                                       targets[j->first] = &m_Fleet[j->first][1];
-                               }
-
-                       }
+                       int total = 0;
+                       map<string, int*> targets = findTargets(ta, total, 1);
 
                        if (targets.size() == 0)
                                break;
 
-                       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)
                        {
-                               float maxguns = float((*j->second))/total * guns;
+                               float maxguns = float((*j->second))/total * gunsleft;
                                //cerr << "Now shooting at target: " << j->first << endl;
 
                                double k = maxguns;
@@ -870,3 +818,33 @@ void Fleet::usePodGuns(int tick, int guns)
        }
        m_UsedPodGuns[tick] += guns;
 }
+
+//////////////////////////////////////////////////////////////////////////
+//
+std::map<std::string, int*> Fleet::findTargets(std::string targetClass,int& total, int attackerType)
+{
+       map<string, int*> targets;
+
+       for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
+       {
+               if (m_Fleet[i->first].size() == 0)
+                       continue;
+
+
+               if (m_Fleet[i->first].size() == 1 )
+                       m_Fleet[i->first].push_back(m_Fleet[i->first][0]);
+
+               //cerr << "Target is class: " << j->second.type() << endl;
+
+               if (m_Fleet[i->first][1] > 0  && ( targetClass == i->second.unitClass() || targetClass == "All"))
+               {
+                       if (i->second.unitClass() == "PDS" && attackerType == 1)
+                               continue;
+                       //      cerr << "Looking at target: " << j->first << endl;
+                       targets[i->first] = &m_Fleet[i->first][1];
+                       total += m_Fleet[i->first][1];
+               }
+       }
+
+       return targets;
+}
index 6946d3c5ae9521ae8c7da30662684705ce47d33c..2ae03e7c01683a34d1321a99db3073bed3f905fd 100644 (file)
@@ -282,6 +282,8 @@ public:
 
        void usePodGuns(int tick = 0, int guns = 1);
 
+       std::map<std::string, int*> findTargets(std::string targetClass,int& total, int attackerType = 0);
+
        //static functions
        //
        /** This function is used to set the different races used.