From 9fa0d25038087d8417c0849a495eeae1abcb9504 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sun, 7 Jul 2002 23:07:01 +0000 Subject: [PATCH] code cleenup.. --- bs/fleet.cpp | 92 ++++++++++++++++++++-------------------------------- bs/fleet.h | 2 ++ 2 files changed, 37 insertions(+), 57 deletions(-) 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; +} diff --git a/bs/fleet.h b/bs/fleet.h index 6946d3c..2ae03e7 100644 --- a/bs/fleet.h +++ b/bs/fleet.h @@ -282,6 +282,8 @@ public: void usePodGuns(int tick = 0, int guns = 1); + std::map findTargets(std::string targetClass,int& total, int attackerType = 0); + //static functions // /** This function is used to set the different races used. -- 2.39.2