Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,308 @@
|
||||
/**
|
||||
* Handler for all indirect fire single objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "handler_explosion_single.h"
|
||||
#include "main_handler.h"
|
||||
#include <Services/AreaEffectSimulation/Utils/polygons.h>
|
||||
|
||||
#include <QPolygonF>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
HandlerExplosionSingle::HandlerExplosionSingle(MainHandler *mainHandler)
|
||||
: HandlerBaseTmpl<ObjectExplosionSingle>(mainHandler, QStringLiteral("ExplosionSingle"), s_areaCount[AesType::AtExplosionSingle], s_areaCountCentral[AesType::AtExplosionSingle])
|
||||
, Interface::Fts::ExplosionSingleModifyRequestHandler(mainHandler->dds()->fts())
|
||||
, Interface::Fts::ExplosionSingleRemoveRequestHandler(mainHandler->dds()->fts())
|
||||
{}
|
||||
|
||||
bool HandlerExplosionSingle::init()
|
||||
{
|
||||
QVector<Database::AesExplosionSingle> dataVec;
|
||||
// read all indirect fire single from database
|
||||
if (!m_mainHandler->db()->select(dataVec))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error reading data from database!";
|
||||
return true;
|
||||
}
|
||||
// create indirect fire single objects
|
||||
for (const Database::AesExplosionSingle &dbData : qAsConst(dataVec))
|
||||
{
|
||||
ObjectExplosionSingle *ifs(new ObjectExplosionSingle(m_mainHandler, this));
|
||||
connect(ifs, &ObjectExplosionSingle::effectStateChanged, this, &HandlerExplosionSingle::onEffectStateChanged);
|
||||
Core::FunctionReplyObject ret = ifs->createObject(dbData);
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
return false;
|
||||
}
|
||||
if(!ifs->data().isCentral)
|
||||
{
|
||||
if (totalAreas() >= (s_maxActiveAreas[AesType::AtExplosionArea] + s_maxActiveAreas[AesType::AtExplosionSingle]))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "More active explosion single in database than allowed - ignoring the rest!";
|
||||
ifs->removeObject();
|
||||
delete ifs;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (totalAreasCentral() >= (s_maxActiveAreasCentral[AesType::AtExplosionArea] + s_maxActiveAreasCentral[AesType::AtExplosionSingle]))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "More active explosion single in database than allowed - ignoring the rest!";
|
||||
ifs->removeObject();
|
||||
delete ifs;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
if (ifs->isObjectInTrainingArea())
|
||||
{
|
||||
if (ifs->data().isCentral)
|
||||
++m_areaCountCentral;
|
||||
else
|
||||
++m_areaCount;
|
||||
}
|
||||
m_objectMap.insert(ifs->id(), ifs);
|
||||
connect(ifs, &ObjectExplosionSingle::newAiv, this, &HandlerExplosionSingle::newAiv);
|
||||
connect(ifs, &ObjectExplosionSingle::removeAiv, this, &HandlerExplosionSingle::removeAiv);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int HandlerExplosionSingle::totalAreas() const
|
||||
{
|
||||
return s_areaCount[AesType::AtExplosionArea] + s_areaCount[AesType::AtExplosionSingle];
|
||||
}
|
||||
|
||||
int HandlerExplosionSingle::totalAreasCentral() const
|
||||
{
|
||||
return s_areaCountCentral[AesType::AtExplosionArea] + s_areaCountCentral[AesType::AtExplosionSingle];
|
||||
}
|
||||
|
||||
static void fillGeometryData(const ExplosionSingleModifyRequest &src, Database::AesExplosionSingle &dst)
|
||||
{
|
||||
dst.impactPosition.rx() = src.impactPosition().lon();
|
||||
dst.impactPosition.ry() = src.impactPosition().lat();
|
||||
}
|
||||
|
||||
static void fillData(const ExplosionSingleModifyRequest &src, Database::AesExplosionSingle &dst)
|
||||
{
|
||||
if (src.id() < 0) // is the id given as negative? set id -> used by OC-Laptop
|
||||
dst.id = src.id();
|
||||
|
||||
fillGeometryData(src, dst);
|
||||
dst.name = QString::fromStdString(src.name());
|
||||
dst.effectStart = src.effectStart().is_set() && src.effectStart().get() > 0 ? QDateTime::fromMSecsSinceEpoch(src.effectStart().get()) : QDateTime();
|
||||
dst.effectDuration = 1000; // 1sec
|
||||
dst.effectSourceId = src.effectSourceId();
|
||||
dst.partyId = src.partyId().is_set() ? src.partyId().get() : 0;
|
||||
dst.chargeTypeId = src.chargeTypeId();
|
||||
dst.participantId = src.participantId().is_set() ? src.participantId().get() : 0;
|
||||
dst.altitude = src.altitude();
|
||||
dst.firePurpose = QString::fromStdString(src.purpose());
|
||||
dst.fireRequestTime = QDateTime::fromMSecsSinceEpoch(src.fireRequestTime());
|
||||
dst.effectMarkingInTa = src.effectMarkingInTa();
|
||||
dst.externalId = src.externalId().is_set() ? src.externalId().get() : 0;
|
||||
}
|
||||
|
||||
void HandlerExplosionSingle::onExplosionSingleModifyRequest(const rti::core::SampleIdentity &cookie,
|
||||
const ExplosionSingleModifyRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onExplosionSingleModifyRequest: " << request;
|
||||
Core::FunctionReplyObject ret = explosionSingleModifyRequest(request);
|
||||
if (ret.error())
|
||||
WARNING_LOG(m_logger) << ret();
|
||||
m_mainHandler->dds()->fts()->explosionSingleModifyReply(cookie, ret);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject HandlerExplosionSingle::explosionSingleCreateRequest(const ExplosionSingleModifyRequest &request)
|
||||
{
|
||||
|
||||
Database::AesExplosionSingle newData;
|
||||
fillData(request, newData);
|
||||
|
||||
// check: effectStart > time(NULL) ?
|
||||
|
||||
ObjectExplosionSingle *ifs(new ObjectExplosionSingle(m_mainHandler, this));
|
||||
connect(ifs, &ObjectExplosionSingle::effectStateChanged, this, &HandlerExplosionSingle::onEffectStateChanged);
|
||||
|
||||
const Core::FunctionReplyObject ret = ifs->createObject(newData);
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ifs->data().isCentral)
|
||||
{
|
||||
if (totalAreasCentral() >= (s_maxActiveAreasCentral[AesType::AtExplosionArea] + s_maxActiveAreasCentral[AesType::AtExplosionSingle]) && request.effectStart().is_set())
|
||||
{
|
||||
ifs->removeObject(); //Not finally deleted from db after this,Fallback if DB deletion is not working correct
|
||||
ifs->removeObjectFromDb();
|
||||
delete ifs;
|
||||
return Core::FunctionReplyObject(1, tr_lts("dds", "Too many active central explosion singles and explosion areas."));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (totalAreas() >= (s_maxActiveAreas[AesType::AtExplosionArea] + s_maxActiveAreas[AesType::AtExplosionSingle]) && request.effectStart().is_set())
|
||||
{
|
||||
ifs->removeObject(); //Not finally deleted from db after this,Fallback if DB deletion is not working correct
|
||||
ifs->removeObjectFromDb();
|
||||
delete ifs;
|
||||
return Core::FunctionReplyObject(1, tr_lts("dds", "Too many active explosion singles and explosion areas."));
|
||||
}
|
||||
}
|
||||
|
||||
if (ifs->data().isCentral)
|
||||
{
|
||||
++m_areaCountCentral;
|
||||
DEBUG_LOG(m_logger) << "m_areaCountCentral " << m_areaCountCentral;
|
||||
}
|
||||
else if (ifs->isObjectInTrainingArea())
|
||||
{
|
||||
++m_areaCount;
|
||||
DEBUG_LOG(m_logger) << "s_areaCount[AesType::AtExplosionSingle] = " << m_areaCount;
|
||||
}
|
||||
m_objectMap.insert(ifs->id(), ifs);
|
||||
connect(ifs, &ObjectExplosionSingle::newAiv, this, &HandlerExplosionSingle::newAiv);
|
||||
connect(ifs, &ObjectExplosionSingle::removeAiv, this, &HandlerExplosionSingle::removeAiv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject HandlerExplosionSingle::explosionSingleModifyRequest(const ExplosionSingleModifyRequest &request)
|
||||
{
|
||||
Core::FunctionReplyObject ret;
|
||||
if (request.id() == 0 || ((request.id() < 0) && !getObjectFromMap(m_objectMap, std::abs(request.id()), ret)))
|
||||
return explosionSingleCreateRequest(request);
|
||||
|
||||
ObjectExplosionSingle *ifs = getObjectFromMap(m_objectMap, std::abs(request.id()), ret);
|
||||
if (!ifs)
|
||||
return ret;
|
||||
|
||||
// Anzahl aktiver Areas ist erreicht, der Wirkbeginn ist (soll) gesetzt sein, aber die Area war
|
||||
// vorher noch ohne Wirkbeginn
|
||||
// if (totalAreas() >= (s_maxActiveAreas[AesType::AtExplosionArea] + s_maxActiveAreas[AesType::AtExplosionSingle]) && request.effectStart().is_set())
|
||||
// return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Too many active single explosions."));
|
||||
|
||||
Database::AesExplosionSingle aes(ifs->data());
|
||||
fillData(request, aes);
|
||||
|
||||
// Calculate new polygon here. Not nice, though
|
||||
auto poly = Polygons::explosionSingle(aes, m_mainHandler->dds()->pdmDtc()->impactRadius(aes.chargeTypeId, aes.igniterTypeId, aes.igniterFunctionId));
|
||||
|
||||
std::vector<Core::GeoPosition> _form;
|
||||
ObjectBase::ddsVecFromPoly(poly, _form);
|
||||
bool isCentral = ifs->checkIsCentral(_form);
|
||||
bool wasCentral = ifs->data().isCentral;
|
||||
|
||||
|
||||
if(!ifs->isActivationTimeSet() && request.effectStart().is_set())
|
||||
{
|
||||
if (isCentral)
|
||||
{
|
||||
if (totalAreasCentral() >= (s_maxActiveAreasCentral[AesType::AtExplosionArea] + s_maxActiveAreasCentral[AesType::AtExplosionSingle]))
|
||||
{
|
||||
return Core::FunctionReplyObject(1, tr_lts("dds", "Too many active central explosion singles and explosion areas."));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (totalAreas() >= (s_maxActiveAreas[AesType::AtExplosionArea] + s_maxActiveAreas[AesType::AtExplosionSingle]) )
|
||||
{
|
||||
return Core::FunctionReplyObject(1, tr_lts("dds", "Too many active explosion singles and explosion areas."));
|
||||
}
|
||||
}
|
||||
}
|
||||
// For counting, only Elements being at least prepared are important:
|
||||
if (request.effectStart().is_set() && ifs->isObjectModifiable())
|
||||
{
|
||||
|
||||
DEBUG_LOG(m_logger) << "isCentral: " << isCentral;
|
||||
DEBUG_LOG(m_logger) << "wasCentral: " << wasCentral;
|
||||
|
||||
// only change if element changed from central to training area or vice versa
|
||||
if (isCentral != wasCentral)
|
||||
{
|
||||
// Change from central to training area
|
||||
if (wasCentral)
|
||||
{
|
||||
if (totalAreas() >= (s_maxActiveAreas[AesType::AtExplosionArea] + s_maxActiveAreas[AesType::AtExplosionSingle]))
|
||||
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Too many active explosion singles and explosion areas."));
|
||||
|
||||
m_areaCount++;
|
||||
m_areaCountCentral--;
|
||||
DEBUG_LOG(m_logger) << "s_areaCount[AesType::AtExplosionSingle] = " << m_areaCount;
|
||||
DEBUG_LOG(m_logger) << "s_areaCountCentral[AesType::AtExplosionSingle] = " << m_areaCountCentral;
|
||||
}
|
||||
else // Change from training area to central
|
||||
{
|
||||
if (totalAreasCentral() >= (s_maxActiveAreasCentral[AesType::AtExplosionArea] + s_maxActiveAreasCentral[AesType::AtExplosionSingle]))
|
||||
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Too many active central explosion singles and explosion areas"));
|
||||
m_areaCount--;
|
||||
m_areaCountCentral++;
|
||||
DEBUG_LOG(m_logger) << "s_areaCount[AesType::AtExplosionSingle] = " << m_areaCount;
|
||||
DEBUG_LOG(m_logger) << "s_areaCountCentral[AesType::AtExplosionSingle] = " << m_areaCountCentral;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (request.id() < 0 && checkStateForSfm(ifs))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Overwrite single explostion Effect State for OC";
|
||||
aes.effectStateId = AesEffectState::EsPrepared;
|
||||
}
|
||||
|
||||
return ifs->updateObject(aes);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject HandlerExplosionSingle::explosionSingleModifyGeometryRequest(const ExplosionSingleModifyRequest &request)
|
||||
{
|
||||
Core::FunctionReplyObject ret;
|
||||
ObjectExplosionSingle *ifs = getObjectFromMap(m_objectMap, request.id(), ret);
|
||||
if (!ifs)
|
||||
return ret;
|
||||
|
||||
// Anzahl aktiver Areas ist erreicht, der Wirkbeginn ist (soll) gesetzt sein, aber die Area war
|
||||
// vorher noch ohne Wirkbeginn
|
||||
if (totalAreas() >= (s_maxActiveAreas[AesType::AtExplosionArea] + s_maxActiveAreas[AesType::AtExplosionSingle])
|
||||
&& request.effectStart().is_set()
|
||||
&& !ifs->isActivationTimeSet()
|
||||
&& !ifs->isObjectModifiable())
|
||||
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Too many active single explosions."));
|
||||
|
||||
Database::AesExplosionSingle aes(ifs->data());
|
||||
fillGeometryData(request, aes);
|
||||
|
||||
return ifs->updateObject(aes);
|
||||
}
|
||||
|
||||
void HandlerExplosionSingle::onExplosionSingleRemoveRequest(const rti::core::SampleIdentity &cookie,
|
||||
const Core::RemoveElementRequest &request)
|
||||
{
|
||||
m_mainHandler->dds()->fts()->explosionSingleRemoveReply(cookie, removeReply(&DatabaseInterface::removeAesExplosionSingle, request));
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject HandlerExplosionSingle::modifyPartyParticipant(qint32 itemId, qint32 partyId, qint32 participantId)
|
||||
{
|
||||
ObjectExplosionSingle *ifs = m_objectMap.value(itemId);
|
||||
if (!ifs)
|
||||
return Core::FunctionReplyObject(itemId, tr_lts("dds", "Single Explosion with id %1 not found.")).arg(itemId);
|
||||
AreaEffectSimulation::Database::AesExplosionSingle aea(ifs->data());
|
||||
aea.partyId = partyId;
|
||||
aea.participantId= participantId;
|
||||
return ifs->updateObject(aea);
|
||||
}
|
||||
|
||||
} // namespace AreaEffectSimulation
|
||||
Reference in new issue
Block a user