Files
qt5-legatus-legacy/Lts/Services/CentralEffectSimulation/Plugins/FunctionalAreas/handler_functional_area.h
T
2026-08-13 18:33:10 +02:00

144 lines
6.3 KiB
C++
Executable File

/**
* Handler for player data
* $Id$
* $HeadURL$
* $Author$
* Created by gr, SLSE, 2017-02-20
*/
#pragma once
#include "supplytimer.h"
#include <CentralEffectSimulation/logger.h>
#include <CentralEffectSimulation/dds_handler.h>
#include <CentralEffectSimulation/aes_item_view_utm.h>
#include <CentralEffectSimulation/handler_participant.h>
#include <CentralEffectSimulation/handler_building_data.h>
#include <QtCore/QHash>
#include <QtCore/QObject>
#include <QtCore/QQueue>
#include <QtCore/QPointF>
#include <QtGui/QPolygonF>
// AES-Handling for participants
namespace CES_FUNCTIONAL_AREA
{
enum class EffectType
{
Unknown = 0,
EffectiveMineRangeEnter = 0xf0000 | 1, // AtMineAreaSingleMines = 15 = 0xf
EffectiveMineRangeLeave = 0xf0000 | 2, // AtMineAreaSingleMines = 15 = 0xf
NContaminationLeave = 0x10000 | 0, // AtNContamination = 1
NContaminationEnterArea1 = 0x10000 | 1,
NContaminationEnterArea2 = 0x10000 | 2,
NContaminationDetonation = 0x10000 | 255,
FunctionalAreaLeave = 0xc0000 | 0, // AtReconArea = 12 = 0xc
FunctionalAreaEnter = 0xc0000 | 1,
ExplosionArea = 0x30000 | 2, // AtExplosionArea = 3
ExplosionSingle = 0x40000 | 3, // AtExplosionSingle = 4
BCContaminationLeave = 0x20000 | 0, // AtBCContamination = 2
BCContaminationEnterFloating = 0x20000 | 1,
BCContaminationEnterResident = 0x20000 | 2,
BCContaminationEnterFloatingArea = 0x20000 | 3,
BeStillWarning = 11,
};
QString toString(EffectType et);
struct ParticipantDistance
{
double squareDistance = 0;
CentralEffectSimulation::HandlerParticipant::CesParticipantData participantPosition;
};
struct EnterLeaveType
{
ProjectDataManagement::EventType eventType = ProjectDataManagement::EventType_def::Unknown;
bool isAlreadySupplied = false;
};
class HandlerFunctionalAreas : public QObject
, protected TrainingAreaBase::Interface::Ftc::SendCesHitReplyHandler
, protected TrainingAreaBase::Interface::Ftc::DemandInitReplyHandler
{
Q_OBJECT
public:
explicit HandlerFunctionalAreas(const std::shared_ptr<CentralEffectSimulation::DdsHandler> &ddsHandler,
const std::shared_ptr<CentralEffectSimulation::HandlerParticipant> &participantHandler,
const std::shared_ptr<CentralEffectSimulation::HandlerBuildingData> &handlerBuildingData,
QObject *parent = nullptr);
~HandlerFunctionalAreas();
/**
* Initialize the handler to manage information from player management
*/
bool init();
protected:
void onSendCesHitReply(const Core::FunctionReplyObject &replyObject) override final;
void onDemandInitReply(const Core::FunctionReplyObject &replyObject) override final;
private Q_SLOTS:
/**
* Handle the signals from 'AES'
*/
void onAesItemViewChanged(const AreaEffectSimulation::AesItemView &data, DataModification modType);
private: // methoden
void calculateFunctionalArea(const CentralEffectSimulation::AesItemViewUtm &itemView);
void calculateDangerArea(const CentralEffectSimulation::AesItemViewUtm &itemView);
void deleteDangerArea(const int aesItemId);
void onNewParticipantPosition(const CentralEffectSimulation::HandlerParticipant::CesParticipantData &participantData);
void onNewIndoorParticipantPosition(const CentralEffectSimulation::HandlerParticipant::CesParticipantData &participantData);
void onRestoreRadioReadinessChanged(const int participantId);
bool inCircle(const QPointF &centerUtm, const double radius, const QPointF &pointUtm);
bool inBoundingBoxCheck(const CentralEffectSimulation::AesItemViewUtm &itemView, const CentralEffectSimulation::HandlerParticipant::CesParticipantData &participantData);
bool inFormCheck(const CentralEffectSimulation::AesItemViewUtm &itemView, const CentralEffectSimulation::HandlerParticipant::CesParticipantData &participantData);
void sendCesHitRequest(const CentralEffectSimulation::AesItemViewUtm &itemView,
const CentralEffectSimulation::HandlerParticipant::CesParticipantData &participantData,
ProjectDataManagement::EventType eventType);
void sendParticipantEvent(const CentralEffectSimulation::AesItemViewUtm &itemView,
const CentralEffectSimulation::HandlerParticipant::CesParticipantData &participantData,
const ProjectDataManagement::EventType eventType);
ProjectDataManagement::EventType leaveEventTypeForAesType(AreaEffectSimulation::AesType aesTypeId);
EffectType leaveEffectTypeForAesType(AreaEffectSimulation::AesType aesTypeId);
EffectType effectTypeForNContaminationArea(const CentralEffectSimulation::AesItemViewUtm &itemView, const QPointF &participantPosUtmPoint, qint64 partPosSampleTime);
EffectType effectTypeForBCContaminationArea(const CentralEffectSimulation::AesItemViewUtm &itemView, const QPointF &participantPosUtmPoint);
void aesItemViewRemoved(int aesItemId);
void removeParticipant(int participantId);
void sendEnterLeave(const CentralEffectSimulation::AesItemViewUtm &itemView, int participantId, bool inForm);
void startSupplyTimer(int participantId, int aesId, long time);
void stopSupplyTimer(int participantId);
void on_supplyFinished(int participantId, int aesId);
void sendInitSupplyToTab(int participantId, int aesId);
private: // attributes
std::shared_ptr<CentralEffectSimulation::DdsHandler> m_ddsHandler; ///< Pointer to VOM DDS handler
std::shared_ptr<CentralEffectSimulation::HandlerParticipant> m_handlerParticipant;
std::shared_ptr<CentralEffectSimulation::HandlerBuildingData> m_handlerBuildingData;
QHash<int32_t, int> m_aesItemId2partIdMap;
// AES-Values
QHash<int, CentralEffectSimulation::AesItemViewUtm> m_aesItemViews; // key = aesItemId
QQueue<TrainingAreaBase::SendCesHitRequest> m_sendCesHitRequestQueue;
QQueue<TrainingAreaBase::DemandInitRequest> m_sendInitRequestQueue;
QHash<QPair<int, int>, EnterLeaveType> m_cesEnterLeaveFunctionalArea; // QPair < aesItemId, participantId> Last Event
QHash<int, SupplyTimer *> m_supplyTimers; // participantId
QHash<int, QVector<int>> m_aesPolygonEncloseBuilding; // key = aesItemId value = BuildingIds inside form
int m_requestId = 1;
NGL::INGLLogger &m_logger; ///< Interface to the Logging-Facility
};
} // namespace CES_FUNCTIONAL_AREA