/** * Handler for player data * $Id: handler_functional_area.cpp 64453 2025-01-31 12:06:15Z fritsche_h $ * $HeadURL: svn://slssvn/TDS/branches/product/features/25_03_etb_uas/Lts/Services/CentralEffectSimulation/Plugins/FunctionalAreas/handler_functional_area.cpp $ * $Author: fritsche_h $ * Created by gr, SLSE, 2017-02-20 */ #include "handler_jamming.h" #include #include #include #include #include #include #include "LtsUtils/LtsUtilsCore/outdated_position.h" namespace dds { namespace core { inline uint qHash(ProjectDataManagement::EventType et) { return ::qHash(et.underlying()); } } } namespace CES_JAMMING { HandlerJamming::HandlerJamming(const std::shared_ptr &ddsHandler, const std::shared_ptr &participantHandler, const std::shared_ptr &handlerBuildingData, QObject *parent) : QObject(parent) , m_ddsHandler(ddsHandler) , m_handlerParticipant(participantHandler) , m_handlerBuildingData(handlerBuildingData) , m_logger(CentralEffectSimulation::getLogger("Plugin.Jamming.HandlerJamming")) { } // end of ctor() //----------------------------------------------------------------------------- HandlerJamming::~HandlerJamming() { } // end of dtor() //----------------------------------------------------------------------------- bool HandlerJamming::init() { // TAB FTC m_ddsHandler->ftcTab()->enableDemandInit(); // m_ddsHandler->dtcAes()->enableJammingArea(); // connect (m_ddsHandler->dtcAes().get(), &AreaEffectSimulation::Interface::Dtc::jammingAreaChanged, // this, &HandlerJamming::onJammingChanged); // m_ddsHandler->dtcAes()->enableAesItemView(); // connect (m_ddsHandler->dtcAes().get(), &AreaEffectSimulation::Interface::Dtc::aesItemViewChanged, // this, &HandlerJamming::onAesItemViewChanged); m_ddsHandler->dtcPpm()->enableParticipantGearEvent(); connect (m_ddsHandler->dtcPpm().get(), &ParticipantManagement::Interface::Dtc::participantGearEventChanged, this, &HandlerJamming::onParticipantGearEventChanged); DEBUG_LOG(m_logger) << "HandlerJamming::init() finished."; return true; } // end of init() //----------------------------------------------------------------------------- void HandlerJamming::onParticipantGearEventChanged(const ParticipantManagement::ParticipantGearEvent &data, DataModification modType) { ERROR_LOG(m_logger) << "onParticipantGearEventChanged << modType=" << modType << " originatorId=" << data.participantId() << " chargeTypeId=" << data.charge().chargeTypeId() << " gearTypeId=" << data.charge().gearTypeId() << " isJamming=" << m_ddsHandler->isJamming({data.charge().chargeTypeId(),0,0}); // Check, if Munition isJamming // NOTE: igniterType/IgniterFunciton = 0 as long as ParticipantGearEvent does not contain values if (!m_ddsHandler->isJamming({data.charge().chargeTypeId(),0,0})) return; QVector uasIds = m_ddsHandler->dtcPpm()->getUasIds(); QVector jammedUasIds; int jammedUasId = 0; double radius = m_ddsHandler->dtcPdm()->getMaxRange(data.charge().chargeTypeId(), data.charge().gearTypeId()); // int radius = 15; DEBUG_LOG(m_logger) << "Radius=" << radius; for ( int uasId : uasIds) { DEBUG_LOG(m_logger) << "uasId=" << uasId; CentralEffectSimulation::HandlerParticipant::CesParticipantData cesParticipantData = m_handlerParticipant->position(uasId); if (!cesParticipantData.positionValid) { DEBUG_LOG(m_logger) << "continue !positionValid participantId=" << uasId; continue; } if (LtsUtils::isPositionTimeOutdated(QDateTime::currentMSecsSinceEpoch(), cesParticipantData.sampleTime())) { DEBUG_LOG(m_logger) << "continue positionTime outdated participantId=" << uasId; continue; } long distance = m_handlerParticipant->getDistance(data.participantId(), uasId); DEBUG_LOG(m_logger) << "distance = " << distance; if ( distance < radius) { DEBUG_LOG(m_logger) << " Send Jamming to TAB and destroy uasId"; //sendCesHitRequest(data.charge().chargeTypeId(), data.participantId(),cesParticipantData); if (cesParticipantData.vulnerabilityState != ProjectDataManagement::VulnerabilityState_def::CatastrophicKill) jammedUasIds.append(uasId); } else DEBUG_LOG(m_logger) << "Not in Radius distance=" << distance << " radius=" << radius; } // [ETB UASETBUAS-33] Equal distribution of jamming failures // Extension of the CES plugin for jamming to randomly drop out exactly one random drone per shot. // the equal distribution refers to the participant ID of the drone if ( jammedUasIds.size() == 0) return; else { // search for an id from the list with an algorithm that contains an equal distribution jammedUasId = jammedUasIds.at(QRandomGenerator::global()->bounded(jammedUasIds.size() - 1)); DEBUG_LOG(m_logger) << "jammedUasId=" << jammedUasId << " jammedUasIds.size()=" << jammedUasIds.size(); } CentralEffectSimulation::HandlerParticipant::CesParticipantData cesParticipantData = m_handlerParticipant->position(jammedUasId); sendCesHitRequest(data.charge().chargeTypeId(), data.participantId(),cesParticipantData); } void HandlerJamming::onSendCesHitReply(const Core::FunctionReplyObject &replyObject) { DEBUG_LOG(m_logger) << "onSendCesHitReply for id " << replyObject.id() << " success= " << replyObject.error(); if (replyObject.error()) WARNING_LOG(m_logger) << "Can not send enter/leave Area to participant in training area: " << replyObject(); // Send next Request, if available if (!m_sendCesHitRequestQueue.isEmpty()) { DEBUG_LOG(m_logger) << "m_sendCesAreaActionRequestQueue.size()=" << m_sendCesHitRequestQueue.size(); m_sendCesHitRequestQueue.dequeue(); // Send next Message if (!m_sendCesHitRequestQueue.isEmpty()) { const auto &hr = m_sendCesHitRequestQueue.head(); DEBUG_LOG(m_logger) << "sendCesHitRequest: " << hr; m_ddsHandler->ftcTab()->sendCesHitRequest(hr, this); } } } // Send via TAB-Proxy to UAS-Proxy void HandlerJamming::sendCesHitRequest(const int chargeTypeId, const int originatorId, const CentralEffectSimulation::HandlerParticipant::CesParticipantData &participantData) { qint64 effectTime = m_ddsHandler->currentPartitionTime(); int remaining = 0; if (remaining < 0) return; DEBUG_LOG(m_logger) << "sendCesHitRequest Settings::calculateCentralAes=" << " insideWlsArea=" << std::boolalpha << participantData.insideWlsArea() << " participantId=" << participantData.participantId(); const int equipNo = m_ddsHandler->participantId2EquipNo(participantData.participantId()); const int originatorEquimentNumber = m_ddsHandler->participantId2EquipNo(originatorId); const int originatorPartyId = m_handlerParticipant->getParticipantPosition(originatorId).partyId(); DEBUG_LOG(m_logger) << " ftc sendCESHit to Participant participantId = " << participantData.participantId() << " equipNo = " << equipNo << " chargeTypeId =" << chargeTypeId; if (participantData.vulnerabilityState == ProjectDataManagement::VulnerabilityState_def::CatastrophicKill) { DEBUG_LOG(m_logger) << "participantPosition.participantId == 0 CatastrophicKill)"; return; } const TrainingAreaBase::TabPosition pos(participantData.pos(), Core::PositionReportingSource_def::Gps, // irrelevant participantData.buildingId(), participantData.roomId()); const int aesId = 0; // not used const int mineId = 0; // not used TrainingAreaBase::SendCesHitRequest requestTab( equipNo, // equipmentNumber participantData.participantId(), // participantId chargeTypeId, // chargeTypeId aesId, // aesId originatorEquimentNumber, // originatorEquipmentNumber remaining, // remainEffectPercent ( no protection outside Building ) pos, effectTime, // effectTime ProjectDataManagement::EventType::Jamming, // EventType originatorPartyId, // originPartyId mineId ); DEBUG_LOG(m_logger) << " participantId=" << participantData.participantId() << " chargeTypeId=" << chargeTypeId; m_sendCesHitRequestQueue.enqueue(requestTab); if (m_sendCesHitRequestQueue.size() == 1) { DEBUG_LOG(m_logger) << "SendCesHitRequest: " << requestTab; m_ddsHandler->ftcTab()->sendCesHitRequest(requestTab, this); } } // sendCesHitRequest } // namespace CES_JAMMING