1
0
Fork 0

AIManager: Maintenance

ensure all members are initialized
std::transform with back_inserter
std:find_if for collection crawl
This commit is contained in:
Scott Giese 2022-01-15 20:06:11 -06:00
parent 4dce923ef3
commit 1816e3e551
2 changed files with 27 additions and 14 deletions

View file

@ -18,8 +18,8 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <cstring>
#include <algorithm> #include <algorithm>
#include <cstring>
#include <simgear/debug/ErrorReportingCallback.hxx> #include <simgear/debug/ErrorReportingCallback.hxx>
#include <simgear/math/sg_geodesy.hxx> #include <simgear/math/sg_geodesy.hxx>
@ -197,9 +197,16 @@ void FGAIManager::registerScenarios(SGPropertyNode_ptr root)
// add-on scenario directories // add-on scenario directories
const auto& addonsManager = flightgear::addons::AddonManager::instance(); const auto& addonsManager = flightgear::addons::AddonManager::instance();
if (addonsManager) { if (addonsManager) {
auto coll = addonsManager->registeredAddons();
std::transform(coll.begin(), coll.end(), std::back_inserter(scenarioSearchPaths),
[](flightgear::addons::AddonRef a) {
return a->getBasePath() / "Scenarios";
});
#if 0
for (auto a : addonsManager->registeredAddons()) { for (auto a : addonsManager->registeredAddons()) {
scenarioSearchPaths.push_back(a->getBasePath() / "Scenarios"); scenarioSearchPaths.push_back(a->getBasePath() / "Scenarios");
} }
#endif
} }
SGPropertyNode_ptr scenariosNode = root->getNode("/sim/ai/scenarios", true); SGPropertyNode_ptr scenariosNode = root->getNode("/sim/ai/scenarios", true);
@ -583,12 +590,21 @@ bool FGAIManager::removeObjectCommand(const SGPropertyNode* arg, const SGPropert
bool FGAIManager::removeObject(const SGPropertyNode* args) bool FGAIManager::removeObject(const SGPropertyNode* args)
{ {
int id = args->getIntValue("id"); int id = args->getIntValue("id");
auto coll = get_ai_list();
auto it_ai = std::find_if(coll.begin(), coll.end(), [id](FGAIBasePtr ai) {
return ai->getID() == id;
});
if (it_ai != coll.end())
(*it_ai)->setDie(true);
#if 0
for (FGAIBase* ai : get_ai_list()) { for (FGAIBase* ai : get_ai_list()) {
if (ai->getID() == id) { if (ai->getID() == id) {
ai->setDie(true); ai->setDie(true);
break; break;
} }
} }
#endif
return false; return false;
} }

View file

@ -20,8 +20,7 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef _FG_AIMANAGER_HXX #pragma once
#define _FG_AIMANAGER_HXX
#include <list> #include <list>
#include <map> #include <map>
@ -145,19 +144,19 @@ private:
ai_list_type ai_list; ai_list_type ai_list;
double user_altitude_agl; double user_altitude_agl = 0.0;
double user_heading; double user_heading = 0.0;
double user_pitch; double user_pitch = 0.0;
double user_roll; double user_roll = 0.0;
double user_speed; double user_speed = 0.0;
double wind_from_east; double wind_from_east = 0.0;
double wind_from_north; double wind_from_north = 0.0;
void fetchUserState( double dt ); void fetchUserState( double dt );
// used by thermals // used by thermals
double range_nearest; double range_nearest = 0.0;
double strength; double strength = 0.0;
void processThermal( double dt, FGAIThermal* thermal ); void processThermal( double dt, FGAIThermal* thermal );
SGPropertyChangeCallback<FGAIManager> cb_ai_bare; SGPropertyChangeCallback<FGAIManager> cb_ai_bare;
@ -176,5 +175,3 @@ private:
_radarDebugMode = false; _radarDebugMode = false;
double _radarRangeM = 0.0; double _radarRangeM = 0.0;
}; };
#endif // _FG_AIMANAGER_HXX