X-Git-Url: https://ruin.nu/git/?p=hbs.git;a=blobdiff_plain;f=bs%2Ffleet.cpp;fp=bs%2Ffleet.cpp;h=0b8598c1c6e916cd262bc2c87771c192efc2b8ce;hp=01ceb2b930e0cc70c3c6e24077822b18f892bd00;hb=9fa0d25038087d8417c0849a495eeae1abcb9504;hpb=a4366efa718d0f6a883cb5ef9cf1ed9c1bdede4c diff --git a/bs/fleet.cpp b/bs/fleet.cpp index 01ceb2b..0b8598c 100644 --- a/bs/fleet.cpp +++ b/bs/fleet.cpp @@ -389,35 +389,12 @@ void Fleet::takeShoot(std::string unittype, int number, std::map 0) { - - map targets; - - for (UnitList::iterator j = s_Units.begin(); j != s_Units.end(); ++j) - { - if (m_Fleet[j->first].size() == 0) - continue; - - - if (m_Fleet[j->first].size() == 1 ) - m_Fleet[j->first].push_back(m_Fleet[j->first][0]); - - //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]; - } - } + int total = 0; + map targets = findTargets(ta,total, 0); if (targets.size() == 0) break; - 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) { float maxguns = float((*j->second))/total * guns; @@ -495,44 +472,15 @@ void Fleet::takeEMP(std::string unittype, int number, std::map //cerr << "Shooting at target class: " << ta << endl; while (gunsleft > 0) { - - map targets; - - for (UnitList::iterator j = s_Units.begin(); j != s_Units.end(); ++j) - { - if (j->second.type() == "PDS") - continue; - - if (freeFleet(j->first, 1) <= 0) - continue; - - if (m_Fleet[j->first].size() == 0) - continue; - - if (m_Fleet[j->first].size() == 1) - m_Fleet[j->first].push_back(m_Fleet[j->first][0]); - - //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]; - } - - } + int total = 0; + map targets = findTargets(ta, total, 1); if (targets.size() == 0) break; - 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) { - float maxguns = float((*j->second))/total * guns; + float maxguns = float((*j->second))/total * gunsleft; //cerr << "Now shooting at target: " << j->first << endl; double k = maxguns; @@ -870,3 +818,33 @@ void Fleet::usePodGuns(int tick, int guns) } m_UsedPodGuns[tick] += guns; } + +////////////////////////////////////////////////////////////////////////// +// +std::map Fleet::findTargets(std::string targetClass,int& total, int attackerType) +{ + map targets; + + for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i) + { + if (m_Fleet[i->first].size() == 0) + continue; + + + if (m_Fleet[i->first].size() == 1 ) + m_Fleet[i->first].push_back(m_Fleet[i->first][0]); + + //cerr << "Target is class: " << j->second.type() << endl; + + if (m_Fleet[i->first][1] > 0 && ( targetClass == i->second.unitClass() || targetClass == "All")) + { + if (i->second.unitClass() == "PDS" && attackerType == 1) + continue; + // cerr << "Looking at target: " << j->first << endl; + targets[i->first] = &m_Fleet[i->first][1]; + total += m_Fleet[i->first][1]; + } + } + + return targets; +}