]> ruin.nu Git - hbs.git/blobdiff - bs/fleet.cpp
A few more bugs killed.. still a few left before 0.1 release..
[hbs.git] / bs / fleet.cpp
index 95ae6d35789a4ca360c794e71d2670a2947e7f3f..ed5efb9fd16881f48f127302f9a92f1437c68f95 100644 (file)
@@ -224,7 +224,10 @@ void Fleet::addToThis(std::vector<Fleet*> fleets, int tick = 0)
 
                for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
                {
-                       m_Fleet[i->first][0] += (*j)->fleet(i->first, tick);
+                       int num = (*j)->fleet(i->first, tick);
+                       m_Fleet[i->first][0] += num;
+                       if (num > 0)
+                               cerr << (*j)->name() <<  " adding " << num << " units of type " << i->first << endl;
                }
        }
 }
@@ -248,11 +251,15 @@ void Fleet::distributeLossesGains(std::vector<Fleet*> fleets, int tick = 0)
 
 
                cerr << "Distributing type: " << unittype << " with a total loss of " << totallost << " units" << endl;
+
+               cerr << "Total number of units before: " << fleet(unittype, 0)  << " and after : " << fleet(unittype, 1) << endl;
                
                for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
                {
-                       int lost =  totallost * ( (*j)->fleet(unittype, tick - 1) / m_Fleet[unittype][0] );
-                       cerr << (*j)->name() << " gaining " << lost << " " << unittype << endl;
+                       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);
                }
        }
@@ -300,13 +307,16 @@ 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;
+       float guns = s_Units[unittype].guns() * number;
+
+       cerr << number << " " << unittype << ": with " << guns << " guns\n";
+       
        if (guns == 0)
                return;
 
        cerr << unittype << ": with " << guns << " guns\n";
 
-       int gunsleft = guns;
+       float gunsleft = guns;
        for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
        {
                string ta = s_Units[unittype].target(count);
@@ -345,15 +355,15 @@ void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, in
 
                        for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
                        {
-                               int maxguns = (*j->second)/total * guns;
-                               cerr << "Now shooting at target: " << j->first << endl;
+                               float maxguns = float((*j->second))/total * guns;
+                               //cerr << "Now shooting at target: " << j->first << endl;
 
                                if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor())
                                        m_Armor[j->first] = s_Units[j->first].armor();
                                double k = maxguns;
 
-                               cerr << "Targets agility: " << s_Units[j->first].agility() << endl;
-                               cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl;
+                               //cerr << "Targets agility: " << s_Units[j->first].agility() << endl;
+                               //cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl;
                                while (k > 0)   
                                {
 
@@ -411,7 +421,7 @@ void Fleet::takeEMP(std::string unittype, int number)
 
        cerr << unittype << ": with " << guns << " guns\n";
 
-       int gunsleft = guns;
+       float gunsleft = guns;
        for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
        {
                string ta = s_Units[unittype].target(count);
@@ -486,10 +496,15 @@ void Fleet::takeEMP(std::string unittype, int number)
 //
 void Fleet::killFleet(std::string unittype, int number, int tick = 0)
 {
-       if (m_Fleet[unittype].size() <= tick)
+       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(m_Fleet[unittype][m_Fleet[unittype].size()] - number);
-               return;
+               m_Fleet[unittype].push_back(earlier);
        }
        m_Fleet[unittype][tick] -= number;
 }