]> ruin.nu Git - hbs.git/commitdiff
fixed a score bug..
authorMichael Andreen <harv@ruin.nu>
Fri, 12 Apr 2002 16:14:26 +0000 (16:14 +0000)
committerMichael Andreen <harv@ruin.nu>
Fri, 12 Apr 2002 16:14:26 +0000 (16:14 +0000)
bs/fleet.cpp
bs/fleet.h
bs/planet.cpp

index b4e4335a4c71486f7db35b461765b8ba31566f16..8ca9c7e2c4c366d91a73b507f89bdfb1c1d3fd16 100644 (file)
@@ -139,8 +139,7 @@ void Fleet::setUnits(UnitList& units)
                        << s_Units[(*i).first].ETA() << "\t"
                        << s_Units[(*i).first].type() << endl;
        }
-       
-       */
+*/     
 }
 
 //////////////////////////////////////////////////////////////////////////
@@ -172,8 +171,13 @@ unsigned Fleet::score(int tick = 0) const
 
        for (FleetList::const_iterator i = m_Fleet.begin(); i != m_Fleet.end(); ++i)
        {
-                 if (i->second.size() >= tick)
-                               break;
+               int ticks =     i->second.size();
+               if (ticks == 0)
+                       continue;
+               --ticks;
+               if ( ticks < tick)
+                       tot_score += i->second[ticks] * s_Units[i->first].totRes() / 10;
+               else
                        tot_score += i->second[tick] * s_Units[i->first].totRes() / 10;
        }
 
@@ -513,11 +517,23 @@ void Fleet::killFleet(std::string unittype, int number, int tick = 0)
 void Fleet::setResource(std::string type, int number, int tick = 0)
 {
 
-       if (m_Resources[type].size() <= tick)
+       int ticks = m_Resources[type].size();
+       for (int i = ticks; i <= tick; ++i)
                m_Resources[type].push_back(number);
        m_Resources[type][tick] = number;
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::addResource(std::string type, int number, int tick = 0)
+{
+
+       int ticks = m_Resources[type].size();
+       for (int i = ticks; i <= tick; ++i)
+               m_Resources[type].push_back(number);
+       m_Resources[type][tick] += number;
+}
+
 //////////////////////////////////////////////////////////////////////////
 //
 int Fleet::resource(std::string type, int tick = 0) const
@@ -581,3 +597,42 @@ void Fleet::blockFleet(std::string unittype, int number, int tick = 0)
                m_BlockedFleet[unittype].push_back(number);
        }
 }
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::distributeCappedRoids(std::vector<Fleet*> fleets, int tick = 0)
+{
+       for (ResourceList::iterator i = m_Resources.begin(); i != m_Resources.end(); ++i)
+       {
+               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;
+
+               if (m_Resources[res].size() < 2)
+                       continue;
+               if (m_Resources[res][1] == 0)
+                       continue;
+
+                
+               int totcapped = resource(res,1) - resource(res, 0);
+
+
+               cerr << "Distributing type: " << res << " with a total gain of " << totcapped << " roids" << endl;
+
+               cerr << "Total number of roids before: " << resource(res, 0)  << " and after : " << resource(res, 1) << endl;
+               
+               for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
+               {
+                       unsigned fl1 = (*j)->score(tick - 1);
+                       float part = float(fl1) / score(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);
+               }
+       }
+}
+
+
index c4f26524cd81ef5d9e45ffcc05fd556e3127b7a7..10517318708288c545380d3a96b82f5783cbc6c2 100644 (file)
@@ -104,6 +104,8 @@ public:
 
        void distributeLossesGains(std::vector<Fleet*> fleets, int tick = 0);
 
+       void distributeCappedRoids(std::vector<Fleet*> fleets, int tick = 0);
+
        std::vector<Fleet*> calculateSide(std::vector<Fleet*> fleets, int stays = 0, int tick = 0);
 
        void killFleet(std::string unittype, int number, int tick = 0);
@@ -111,6 +113,7 @@ public:
        void blockFleet(std::string unittype, int number, int tick = 0);
 
        void setResource(std::string type, int number, int tick = 0);
+       void addResource(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);
index 0da7d97a30ddc30b733ec8069470021f1472c0c1..0e4de71300db0651919b5b36549e5537dbf61dba 100644 (file)
@@ -144,6 +144,7 @@ void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile
 
                allFriends.distributeLossesGains(friends, tick);
                allHostiles.distributeLossesGains(hostiles, tick);
+               allHostiles.distributeCappedRoids(hostiles, tick);
 
        /*      for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
                        setRoids(i->first, roids(i->first, 1), tick);*/
@@ -221,10 +222,10 @@ void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string,
                
                                                //FIXME: Going to move this to the distribute roids section instead..
                                                hostiletemp->killFleet(unittype, caproids, 1);
-                                               int totroids = caproids + hostiletemp->resource(roid->first, 0);
-                                               hostiletemp->setResource(roid->first, totroids, 1);
+                                               //int totroids = caproids + hostiletemp->resource(roid->first, 0);
+                                               hostiletemp->addResource(roid->first, caproids, 1);
                                                
-                                               cerr << totroids << " stolen " << roid->first << " roids\n";
+                                               cerr << caproids << " stolen " << roid->first << " roids\n";
                                        }
                                }
                        }