]> ruin.nu Git - hbs.git/commitdiff
a couple of bugs solved..
authorMichael Andreen <harv@ruin.nu>
Thu, 25 Apr 2002 19:41:17 +0000 (19:41 +0000)
committerMichael Andreen <harv@ruin.nu>
Thu, 25 Apr 2002 19:41:17 +0000 (19:41 +0000)
bs/fleet.cpp
bs/fleet.h
bs/planet.cpp
bs/ui/resourceview.ui

index 13bafb7aa071ace95640bb0e84dca2840aeb3cef..136ad22ac8a77860265672eae5db422a012eb978 100644 (file)
@@ -201,6 +201,23 @@ void Fleet::setFleet(string unittype, int number, int tick = 0)
        m_Fleet[unittype][tick] = number;
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::addFleet(std::string unittype, int number, int tick = 0)
+{
+       int earlier = 0;
+       int ticks = m_Fleet[unittype].size();
+
+       if (ticks != 0)
+               earlier = m_Fleet[unittype][ticks - 1];
+
+       for (int i = ticks; i <= tick; ++i)
+       {
+               m_Fleet[unittype].push_back(earlier);
+       }
+       m_Fleet[unittype][tick] += number;
+}
+
 //////////////////////////////////////////////////////////////////////////
 //
 int     Fleet::fleet(string unittype, int tick = 0)
@@ -572,10 +589,7 @@ void Fleet::addResource(std::string type, int number, int tick = 0)
 {
 
        int ticks = m_Resources[type].size();
-       int latest = 0;
-
-       if (ticks > 0)
-               latest = m_Resources[type][ticks - 1];
+       int latest = resource(type, tick - 1);
 
        for (int i = ticks; i <= tick; ++i)
                m_Resources[type].push_back(latest);
@@ -586,6 +600,9 @@ void Fleet::addResource(std::string type, int number, int tick = 0)
 //
 int Fleet::resource(std::string type, int tick = 0) const
 {
+       if (tick < 0)
+               return 0;
+
        vector<int>const* resource = 0;
        for (ResourceList::const_iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
        {
@@ -610,6 +627,13 @@ int Fleet::resource(std::string type, int tick = 0) const
        return resource->at(tick);
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::resetResources()
+{
+       m_Resources.clear() ;   
+}
+
 //////////////////////////////////////////////////////////////////////////
 //
 void Fleet::printFleet()
@@ -654,6 +678,7 @@ void Fleet::distributeCappedRoids(std::vector<Fleet*> fleets, int tick = 0)
        {
                string res = i->first;
 
+
                cerr << "Distributing type: " << res << endl;
                for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
                        cout << (*j) << endl;
@@ -678,17 +703,18 @@ void Fleet::distributeCappedRoids(std::vector<Fleet*> fleets, int tick = 0)
                        int lost =  totcapped * part;
 
                        cerr << (*j)->name() << " gaining " << lost << " " << res  << " since it's " << part * 100 << "% of the whole score, and it had : " << fl1 << " score last tick.. compared to fleet total of: " << score(0) <<  endl;
-                       (*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick);
+
+                       //(*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick);
+                       (*j)->addResource(res,lost, tick);
                }
        }
 }
 
 //////////////////////////////////////////////////////////////////////////
 //
-void Fleet::addPodsForLostRoids(int tick = 1)
+
+void Fleet::addFleet(std::map<string, int> units, int tick = 0)
 {
-       for (ResourceList::iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
-       {
-               setFleet("Astro Pod", fleet("Astro Pod", tick) + (resource(i->first, tick) - resource(i->first, tick - 1)), tick);
-       }
+       for (map<string, int>::iterator i = units.begin(); i != units.end(); ++i)
+               addFleet(i->first, i->second, tick);
 }
index 448d4de66bbfdadbb2634f0e3c96e3c4a9fd7b3b..93bdee74a247d04ad4c75db9b173a515ce8707aa 100644 (file)
@@ -106,6 +106,11 @@ public:
         * other is hardly used other than inside the engine.
         */
        void setFleet(std::string unittype, int number, int tick = 0);
+
+       void addFleet(std::string unittype, int number, int tick = 0);
+
+       void addFleet(std::map<std::string, int> units, int tick = 0);
+
        /**Returns the numbers of units fo a specific type at a specific tick.
         * \param unittype The shipname, as a std string
         * \param tick The tick you want to look at, tick 0 (before battle) is default
@@ -164,8 +169,6 @@ public:
         */
        void distributeCappedRoids(std::vector<Fleet*> fleets, int tick = 0);
 
-       void addPodsForLostRoids(int tick = 1);
-
        /** Checks through the vector with fleets to see who's in time for the
         * specified tick and staying long enough so they're not too early.
         * \param fleets a vector with Fleet pointers to use for the calculations
@@ -223,6 +226,7 @@ public:
         */
        int resource(std::string type, int tick = 0)const;
        
+       void resetResources();
        /** This is a little more advanced function. It makes a a number of units
         * of a specific unittype shoot at the current fleet and calculates the 
         * losses.
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);
+       
 }
 
 //////////////////////////////////////////////////////////////////////////
index 376a60a53f4d11f126615f961445b50fc3794107..971f0060790e94e82ff40b0363a221907f253e09 100644 (file)
@@ -62,7 +62,7 @@
         </widget>
         <widget class="QLineEdit" row="1" column="6" rowspan="1" colspan="2">
             <property name="name">
-                <cstring>EoniumEdit</cstring>
+                <cstring>UninitEdit</cstring>
             </property>
             <property name="focusPolicy">
                 <enum>NoFocus</enum>
@@ -92,7 +92,7 @@
         </widget>
         <widget class="QLineEdit" row="1" column="4" rowspan="1" colspan="2">
             <property name="name">
-                <cstring>UninitEdit</cstring>
+                <cstring>EoniumEdit</cstring>
             </property>
             <property name="focusPolicy">
                 <enum>NoFocus</enum>