X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=blobdiff_plain;f=bs%2Ffleet.cpp;h=f0fb8e1dee9d07d45c42c8d0784d65d6f8b5c907;hp=432f16595efadab7d1e8c479fa8cb03678ac7292;hb=2fd4fff0f5eef1d64527b202924f16f2242691dc;hpb=e5701c8f3f1199264015c5d6e0f2a32515d5f6f8 diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 432f165..f0fb8e1 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -117,7 +117,7 @@ void Fleet::setUnits(UnitList& units) { s_Units = units; - /* + for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); i++) { @@ -139,7 +139,7 @@ void Fleet::setUnits(UnitList& units) << s_Units[(*i).first].ETA() << "\t" << s_Units[(*i).first].type() << endl; } - */ + } ////////////////////////////////////////////////////////////////////////// @@ -183,10 +183,15 @@ unsigned Fleet::score(int tick = 0) const // void Fleet::setFleet(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(number); - return; + m_Fleet[unittype].push_back(earlier); } m_Fleet[unittype][tick] = number; } @@ -202,7 +207,7 @@ int Fleet::fleet(string unittype, int tick = 0) --ticks; if (ticks < tick) - m_Fleet[unittype][ticks]; + return m_Fleet[unittype][ticks]; return m_Fleet[unittype][tick]; } @@ -218,7 +223,7 @@ void Fleet::addToThis(std::vector fleets, int tick = 0) for (vector::iterator j = fleets.begin(); j != fleets.end(); ++j) { - // FIXTHIS!! m_Fleet[i->first][0] += j->fleet(i->first, tick); + m_Fleet[i->first][0] += (*j)->fleet(i->first, tick); } } } @@ -227,6 +232,22 @@ void Fleet::addToThis(std::vector fleets, int tick = 0) // void Fleet::distributeLossesGains(std::vector fleets, int tick = 0) { + for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) + { + string unittype = i->first; + if (m_Fleet[unittype].size() < 1) + break; + if (m_Fleet[unittype][0] == 0) + break; + + int totallost = m_Fleet[unittype][1] - m_Fleet[unittype][0]; + + for (vector::iterator j = fleets.begin(); j != fleets.end(); ++j) + { + int lost = totallost * ( (*j)->fleet(unittype, tick - 1) / m_Fleet[unittype][0] ); + (*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick); + } + } } ////////////////////////////////////////////////////////////////////////// @@ -248,12 +269,18 @@ std::vector Fleet::calculateSide(std::vector fleets, int stays = // int Fleet::freeFleet(std:: string unittype, int tick = 0) { - if (m_Fleet[unittype].size() == 0) - return 0; - if (m_BlockedFleet[unittype].size() < tick) - return m_Fleet[unittype][tick]; + int bticks = m_BlockedFleet[unittype].size(); + + --bticks; + + if (bticks < tick) + return fleet(unittype, tick); - return m_Fleet[unittype][tick] - m_BlockedFleet[unittype][tick]; + + int free = fleet(unittype,tick) - m_BlockedFleet[unittype][tick]; + if (free < 0) + return 0; + return free; } @@ -261,13 +288,19 @@ int Fleet::freeFleet(std:: string unittype, int tick = 0) // void Fleet::takeShoot(std::string unittype, int number, std::map& hitunits) { + + cerr << unittype << ": " << number << " in number\n"; int guns = s_Units[unittype].guns() * number; - int power = s_Units[unittype].power() * number; + if (guns == 0) + return; + + cerr << unittype << " with " << guns << " guns\n"; int gunsleft = guns; - for (vector::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i) + 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); + cerr << "Shooting at target class: " << ta << endl; while (gunsleft > 0) { @@ -275,16 +308,27 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst].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()) + //cerr << "Target is class: " << j->second.type() << endl; + + if (m_Fleet[j->first][1] > 0 && ( ta == j->second.unitClass() || ta == "All")) + { + + cerr << "Looking at target: " << j->first << endl; targets[j->first] = &m_Fleet[j->first][1]; + } + } + if (targets.size() == 0) + break; + int total = 0; for (map::iterator j = targets.begin(); j != targets.end(); ++j) total += (*j->second); @@ -292,11 +336,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; 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; + float k = maxguns; + + int blaha = 0; + cerr << "Targets agility: " << s_Units[j->first].agility() << endl; + cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl; while (k > 0) { @@ -308,6 +356,7 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst] = s_Units[j->first].armor(); (*j->second)--; + hitunits[j->first]++; //There is a chance that we're hitting a blocked ship. if (m_BlockedFleet[j->first].size() >= 1) @@ -323,7 +372,10 @@ void Fleet::takeShoot(std::string unittype, int number, std::mapfirst] << " units of type: " << j->first << "killed\n"; if (k <= 0) gunsleft -= maxguns; else