X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=blobdiff_plain;f=bs%2Ffleet.cpp;h=432f16595efadab7d1e8c479fa8cb03678ac7292;hp=3ce2b71344e50574694a6280d54c6c52cd2a899a;hb=e5701c8f3f1199264015c5d6e0f2a32515d5f6f8;hpb=6a5514b426dda24837138301f7bd6f68cb58cb39 diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 3ce2b71..432f165 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -18,6 +18,7 @@ #include "fleet.h" #include +#include using namespace std; //Static variables @@ -260,12 +261,83 @@ 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; + int power = s_Units[unittype].power() * number; + + int gunsleft = guns; + for (vector::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i) + { + + while (gunsleft > 0) + { + + map targets; + + for (UnitList::iterator j = s_Units.begin(); j != s_Units.end(); ++j) + { + if (m_Fleet[j->first].size() == 0) + break; + + if (m_Fleet[j->first].size() == 1) + m_Fleet[j->first].push_back(m_Fleet[j->first][0]); + + if (m_Fleet[j->first][1] > 0 && (*i) == j->second.type()) + targets[j->first] = &m_Fleet[j->first][1]; + } + + int total = 0; + for (map::iterator j = targets.begin(); j != targets.end(); ++j) + total += (*j->second); + + for (map::iterator j = targets.begin(); j != targets.end(); ++j) + { + int maxguns = (*j->second)/total * guns; + + + if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor()) + m_Armor[j->first] = s_Units[j->first].armor(); + int k = maxguns; + while (k > 0) + { + + if (*(j->second) <= 0) + break; + k -= 100/(25+s_Units[unittype].weaponSpeed() - s_Units[j->first].agility()); + m_Armor[j->first] -= s_Units[unittype].power(); + if (m_Armor[j->first] <= 0) + { + m_Armor[j->first] = s_Units[j->first].armor(); + (*j->second)--; + + //There is a chance that we're hitting a blocked ship. + if (m_BlockedFleet[j->first].size() >= 1) + { + int test = rand() % m_BlockedFleet[j->first][0]; + if (test == 1 + && m_BlockedFleet[j->first][0] > 0) + { + if (m_BlockedFleet[j->first].size() == 1) + m_BlockedFleet[j->first].push_back(m_BlockedFleet[j->first][0] - 1); + else if (m_BlockedFleet[j->first][1] > 0) + m_BlockedFleet[j->first][1]--; + } + } + } + } + if (k <= 0) + gunsleft -= maxguns; + else + gunsleft -= maxguns - k; + } + } + } } ////////////////////////////////////////////////////////////////////////// // void Fleet::takeEMP(std::string unittype, int number) { + } //////////////////////////////////////////////////////////////////////////