]> ruin.nu Git - hbs.git/blobdiff - bs/fleet.cpp
added the possibility to watch blocked and survived fleet.
[hbs.git] / bs / fleet.cpp
index 545ffa2e43d094fe09a3490d85d13dacebc29e49..1cdc04fb9d1a3e49e022d2a8ca4fc68175f81090 100644 (file)
@@ -217,6 +217,38 @@ int         Fleet::fleet(string unittype, int tick = 0)
        return m_Fleet[unittype][tick];
 }
 
+//////////////////////////////////////////////////////////////////////////
+//
+int Fleet::blockedFleet(std::string unittype, int tick = 0)
+{
+       int ticks = m_BlockedFleet[unittype].size();
+       if (ticks == 0)
+               return 0;
+
+       --ticks;
+
+       if (ticks < tick)
+               return 0;
+
+       return m_BlockedFleet[unittype][tick];
+}
+
+//////////////////////////////////////////////////////////////////////////
+//
+void Fleet::setBlockedFleet(std::string unittype, int number, int tick = 0)
+{
+       int ticks = m_BlockedFleet[unittype].size();
+
+       for (int i = ticks; i <= tick; ++i)
+       {
+               m_BlockedFleet[unittype].push_back(0);
+       }
+       m_BlockedFleet[unittype][tick] = number;
+
+       cerr << "This fleet got " << m_BlockedFleet[unittype][tick] << " blocked units tick: " << tick << endl;
+
+}
+
 //////////////////////////////////////////////////////////////////////////
 //FIXME
 void Fleet::addToThis(std::vector<Fleet*> fleets, int tick = 0)
@@ -263,8 +295,15 @@ void Fleet::distributeLossesGains(std::vector<Fleet*> fleets, int tick = 0)
                        int fl1 = (*j)->fleet(unittype, tick - 1);
                        float part = float(fl1) / fleet(unittype, 0) ;
                        int lost =  totallost * part;
-                       cerr << (*j)->name() << " gaining " << lost << " " << unittype  << " since it's " << part * 100 << "% of the whole fleet, and it had : " << fl1 << " units last tick.." <<  endl;
                        (*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick);
+
+                       cerr << (*j)->name() << " gaining " << lost << " " << unittype  << " since it's " << part * 100 << "% of the whole fleet, and it had : " << fl1 << " units last tick.." <<  endl;
+
+                       lost = part * blockedFleet(unittype, 0);
+
+                       cerr << (*j)->name() << " got " << lost << " blocked " << unittype  << ", the total number of blocked ships was: " << blockedFleet(unittype, 0) << endl; 
+
+                       (*j)->setBlockedFleet(unittype, lost, tick);
                }
        }
 }
@@ -465,7 +504,7 @@ void Fleet::takeEMP(std::string unittype, int number)
 
                        for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
                        {
-                               int maxguns = (*j->second)/total * guns;
+                               float maxguns = float((*j->second))/total * guns;
                                cerr << "Now shooting at target: " << j->first << endl;
 
                                double k = maxguns;
@@ -635,7 +674,7 @@ 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)->addResource(res, lost, tick);
+                       (*j)->setResource(res, (*j)->resource(res,tick-1) + lost, tick);
                }
        }
 }