Files
qt5-legatus-legacy/Lts/Services/AreaEffectSimulation/EffectorFiringStrategy/smart_firing_strategy.cpp
T
torstenandCopilot 3028302f7b Qt6 Migration: Merge latest Qt5 devel content and apply migration fixes
- Merged 292 changed files from dlbo snapshot
- Fixed IDL enum collisions (PortType, PdmEventType)
- Fixed Grantlee template for C++11 scoped enums
- Fixed CMake VERSION_GREATER syntax
- Added missing directories (THP, LtsRestClient, etc.)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-15 18:20:51 +00:00

114 lines
3.7 KiB
C++
Executable File

/**
* Effector Firing Strategy for SMart
* $Id$
* $HeadURL$
* $Author$
* Created by Norbert Thoden, ESVG, 2026-05-20
*/
#include "smart_firing_strategy.h"
#include "object_effector.h"
#include <LtsCoordTrans/lts_coord_trans.h>
#include <TrainingAreaBase/Plugins/AdlerJson/telegrams.h>
#include <TrajectorySplitter/trajectory_splitter.h>
#include <QJsonDocument>
#include <QJsonObject>
namespace AreaEffectSimulation
{
SmartFiringStrategy::SmartFiringStrategy(ObjectEffector *effector)
: BaseClass(effector)
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
DEBUG_LOG(m_logger) << "using SmartFiringStrategy";
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
}
SmartFiringStrategy::~SmartFiringStrategy()
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
}
bool SmartFiringStrategy::doFiring()
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
// by default, following is done
// - calculateDispersionTrajectory
// - calc new target
// - calc matching trajectory
// (intendendTrajectory -> m_transformedTrajectory)
// - sendChargeEffect
// - emit signalFired
// for SMArt, calculateDispersionTrajectory is not necessary
// But we have to split the tow-in-one trajectory:
const qint64 trajectoryStartTime = getStartTime();
//
// first check, if trajectory is a tow-in-one trajectory:
//
// convert from intendendTrajectory (relativ) to TRAJECTORY_TYPE (absolute)
// The TrajectorySplitter needs TRAJECTORY_TYPE
// using TRAJECTORY_TYPE = std::vector<Core::GeoPositionRelativeTime>;
const auto intendendTrajectory = m_effector->intendendTrajectory();
const auto trajGeometry = buildTrajectoryGeometry(intendendTrajectory);
if (trajGeometry.size() < 2)
{
ERROR_LOG(m_logger) << LOGFUNCTION << " transformedTrajectory is not sufficiant"
<< ", size=" << trajGeometry.size();
return false;
}
// split and avoid copying:
const TrajectorySplitter<std::vector<Core::GeoPositionRelativeTime>> splitter(trajGeometry);
const auto trajGeo1 = splitter.getTrajectory1();
const auto trajGeo2 = splitter.getTrajectory2();
DEBUG_LOG(m_logger) << "splitter: " << " intendendTrajectory.size = " << intendendTrajectory.size();
DEBUG_LOG(m_logger) << "splitter: " << " trajGeometry.size = " << trajGeometry.size();
DEBUG_LOG(m_logger) << "splitter: " << " rawTrajectorySize = " << splitter.rawTrajectorySize();
DEBUG_LOG(m_logger) << "splitter: " << " trajGeo1 = " << trajGeo1.size();
DEBUG_LOG(m_logger) << "splitter: " << " trajGeo2 = " << trajGeo2.size();
//
// and second, process both Trajectories/Impacts
//
QVector<int> chargeEffectIds;
if (trajGeo1.size() > 2)
{
const auto trajTimeAware = buildTrajectoryTimeAware(trajGeo1, trajectoryStartTime, 0);
const int chargeEffectId = sendChargeEffect(trajTimeAware);
if (chargeEffectId < 0)
WARNING_LOG(m_logger) << LOGFUNCTION << " sendChargeEffect failed";
else
chargeEffectIds << chargeEffectId;
DEBUG_LOG(m_logger) << "Trajectory1 - created ChargeEffectId: " << chargeEffectId;
}
if (trajGeo2.size() > 2)
{
const auto trajTimeAware = buildTrajectoryTimeAware(trajGeo2, trajectoryStartTime, 1);
const int chargeEffectId = sendChargeEffect(trajTimeAware);
if (chargeEffectId < 0)
WARNING_LOG(m_logger) << LOGFUNCTION << " sendChargeEffect failed";
else
chargeEffectIds << chargeEffectId;
DEBUG_LOG(m_logger) << "Trajectory2 - created ChargeEffectId: " << chargeEffectId;
}
if (!chargeEffectIds.empty())
emit signalFired(m_effector->participantId(), m_effector->aesItemId(), chargeEffectIds);
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
return true;
}
} // namespace AreaEffectSimulation