X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=blobdiff_plain;f=bs%2Ffleet.cpp;h=ed5efb9fd16881f48f127302f9a92f1437c68f95;hp=95ae6d35789a4ca360c794e71d2670a2947e7f3f;hb=8589e08e508806885b737682ed25b6f711d0fdee;hpb=9f0513b48fbafa876159812f638019c6b47eae33 diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 95ae6d3..ed5efb9 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -224,7 +224,10 @@ void Fleet::addToThis(std::vector fleets, int tick = 0) for (vector::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 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::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& 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::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::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::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; }