156 lines
7.1 KiB
C++
Executable File
156 lines
7.1 KiB
C++
Executable File
/**
|
|
* Geopairing Ammu Config
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Gerlinde Rudolphus, ESZS, 2016-04-14
|
|
*/
|
|
|
|
#include "ammuconfig.h"
|
|
#include <QStringList>
|
|
|
|
namespace N_ConfigSystem
|
|
{
|
|
|
|
AmmuConfig *AmmuConfig::getInstance()
|
|
{
|
|
static AmmuConfig ammuConfig;
|
|
return &ammuConfig;
|
|
}
|
|
|
|
void AmmuConfig::initFilename(const QString &fileName)
|
|
{
|
|
ConfigSettings::initFilename(fileName);
|
|
loadAmmunitions();
|
|
}
|
|
|
|
// ---------------------------------------------------------------
|
|
N_Ballistic::Ammunition AmmuConfig::loadAmmunition(QString a_group)
|
|
{
|
|
N_Ballistic::Ammunition p_ammu;
|
|
|
|
p_ammu.m_AmmunInfo.m_Name = getString(a_group, QStringLiteral("Name"), QStringLiteral("<unknown>"));
|
|
p_ammu.m_AmmunInfo.m_Range = getFloat(a_group, QStringLiteral("Range"), 0);
|
|
p_ammu.m_AmmunInfo.m_Caliber = getFloat(a_group, QStringLiteral("Caliber"), 0);
|
|
p_ammu.m_AmmunInfo.m_Speed = getFloat(a_group, QStringLiteral("Speed"), 0);
|
|
p_ammu.m_AmmunInfo.m_TimeOut = getFloat(a_group, QStringLiteral("TimeOut"), 0);
|
|
p_ammu.m_AmmunInfo.m_ReasonToDetonate = getString(a_group, QStringLiteral("ReasonToDetonate"), QStringLiteral("OnImpact"));
|
|
p_ammu.m_AmmunInfo.m_Algorithm = getString(a_group, QStringLiteral("Algorithm"), QStringLiteral("DAntonio"));
|
|
p_ammu.m_AmmunInfo.m_Deviation = getFloat(a_group, QStringLiteral("Deviation"), 0.0);
|
|
//INFO_LOG(m_logger) << a_group << " m_Deviation : " << p_ammu.m_AmmunInfo.m_Deviation ;
|
|
p_ammu.m_AmmunInfo.m_Derivation = getFloat(a_group, QStringLiteral("Derivation"), 0.0);
|
|
//INFO_LOG(m_logger) << a_group << " m_Derivation : " << p_ammu.m_AmmunInfo.m_Derivation ;
|
|
|
|
QString s_paramtype = getString(a_group, QStringLiteral("ParamType"), QString());
|
|
a_group += QLatin1Char('/') + s_paramtype;
|
|
|
|
if (s_paramtype == QStringLiteral("PolygonParams"))
|
|
{
|
|
p_ammu.m_PolygonParams.m_InitialAX = getFloat(a_group, QStringLiteral("InitialAX"), 0);
|
|
|
|
QVector<int> l_axindex = getIntegerVector(a_group, QStringLiteral("AXIndex"));
|
|
QVector<double> l_axcoeff = getFloatVector(a_group, QStringLiteral("AXCoeff"));
|
|
for (int i = 0; i < l_axcoeff.size(); i++)
|
|
{
|
|
N_Ballistic::PolygonParamType::PolyCoefficientType o_coeff;
|
|
o_coeff.m_Index = l_axindex[i];
|
|
o_coeff.m_Coeff = l_axcoeff[i];
|
|
p_ammu.m_PolygonParams.m_AX.push_back(std::move(o_coeff));
|
|
}
|
|
|
|
QVector<int> l_ayindex = getIntegerVector(a_group, QStringLiteral("AYIndex"));
|
|
QVector<double> l_aycoeff = getFloatVector(a_group, QStringLiteral("AYCoeff"));
|
|
for (int i = 0; i < l_aycoeff.size(); i++)
|
|
{
|
|
N_Ballistic::PolygonParamType::PolyCoefficientType o_coeff;
|
|
o_coeff.m_Index = l_ayindex[i];
|
|
o_coeff.m_Coeff = l_aycoeff[i];
|
|
p_ammu.m_PolygonParams.m_AY.push_back(std::move(o_coeff));
|
|
}
|
|
|
|
p_ammu.m_PolygonParams.m_Valid = true;
|
|
}
|
|
else if (s_paramtype == QStringLiteral("StandardParams"))
|
|
{
|
|
p_ammu.m_StandardParams.m_Time.m_CRhoT = getFloat(a_group, QStringLiteral("Time_CRhoT"), 0);
|
|
p_ammu.m_StandardParams.m_Time.m_CT = getFloat(a_group, QStringLiteral("Time_CT"), 0);
|
|
p_ammu.m_StandardParams.m_Time.m_CV0T = getFloat(a_group, QStringLiteral("Time_CV0T"), 0);
|
|
p_ammu.m_StandardParams.m_Time.m_ConstT = getFloat(a_group, QStringLiteral("Time_ConstT"), 0);
|
|
|
|
p_ammu.m_StandardParams.m_Angle.m_CRhoA = getFloat(a_group, QStringLiteral("Angle_CRhoA"), 0);
|
|
p_ammu.m_StandardParams.m_Angle.m_CGammaA = getFloat(a_group, QStringLiteral("Angle_CGammaA"), 0);
|
|
p_ammu.m_StandardParams.m_Angle.m_CA = getFloat(a_group, QStringLiteral("Angle_CA"), 0);
|
|
p_ammu.m_StandardParams.m_Angle.m_CV0A = getFloat(a_group, QStringLiteral("Angle_CV0A"), 0);
|
|
p_ammu.m_StandardParams.m_Angle.m_ConstA = getFloat(a_group, QStringLiteral("Angle_ConstA"), 0);
|
|
|
|
p_ammu.m_StandardParams.m_CrossWind.m_ConstX3 = getFloat(a_group, QStringLiteral("CrossWind_ConstX3"), 0);
|
|
p_ammu.m_StandardParams.m_CrossWind.m_ConstX2 = getFloat(a_group, QStringLiteral("CrossWind_ConstX2"), 0);
|
|
p_ammu.m_StandardParams.m_CrossWind.m_ConstX1 = getFloat(a_group, QStringLiteral("CrossWind_ConstX1"), 0);
|
|
p_ammu.m_StandardParams.m_CrossWind.m_ConstX0 = getFloat(a_group, QStringLiteral("CrossWind_ConstX0"), 0);
|
|
|
|
p_ammu.m_StandardParams.m_Speed.m_V0ConstX0 = getFloat(a_group, QStringLiteral("Speed_V0ConstX0"), 0);
|
|
p_ammu.m_StandardParams.m_Speed.m_V0ConstX1 = getFloat(a_group, QStringLiteral("Speed_V0ConstX1"), 0);
|
|
|
|
//INFO_LOG(m_logger) << a_group << " Speed_V0Const0 : " << p_ammu.m_StandardParams.m_Speed.m_V0ConstX0 ;
|
|
//INFO_LOG(m_logger) << a_group << " Speed_V0Const1 : " << p_ammu.m_StandardParams.m_Speed.m_V0ConstX1 ;
|
|
p_ammu.m_StandardParams.m_Valid = true;
|
|
}
|
|
else if (s_paramtype == QStringLiteral("CWParams"))
|
|
{
|
|
QString l_groupp = a_group.replace(QStringLiteral("Ammunition"), QStringLiteral("AmmunitionP"));
|
|
p_ammu.m_CWParams.m_V0 = getFloatVector(l_groupp, QStringLiteral("V0"));
|
|
p_ammu.m_CWParams.m_CW = getFloatVector(l_groupp, QStringLiteral("CW"));
|
|
p_ammu.m_CWParams.m_XW = getFloatVector(l_groupp, QStringLiteral("XW"));
|
|
p_ammu.m_CWParams.m_Weight = getFloat(l_groupp, QStringLiteral("Weight"), 1);
|
|
|
|
for (int i = 0; i < p_ammu.m_CWParams.m_CW.size(); i++)
|
|
{
|
|
//INFO_LOG(m_logger) << "CWParams V0 " << i << " : " << p_ammu.m_CWParams.m_V0[i] ;
|
|
//INFO_LOG(m_logger) << "CWParams CW " << i << " : " << p_ammu.m_CWParams.m_CW[i] ;
|
|
//INFO_LOG(m_logger) << "CWParams XW " << i << " : " << p_ammu.m_CWParams.m_XW[i] ;
|
|
}
|
|
//INFO_LOG(m_logger) << "CWParams read, V0 count=" << p_ammu.m_CWParams.m_V0.size() ;
|
|
//INFO_LOG(m_logger) << "CWParams read, CW count=" << p_ammu.m_CWParams.m_CW.size() ;
|
|
//INFO_LOG(m_logger) << "CWParams read, XW count=" << p_ammu.m_CWParams.m_XW.size() ;
|
|
//INFO_LOG(m_logger) << "CWParams read, Weight = " << p_ammu.m_CWParams.m_Weight ;
|
|
|
|
p_ammu.m_CWParams.m_Valid = true;
|
|
}
|
|
else if (s_paramtype == QStringLiteral("DiscreteParams"))
|
|
{
|
|
//ERROR_LOG(m_logger) << "not yet implemented : " << s_paramtype ;
|
|
}
|
|
else
|
|
{
|
|
//ERROR_LOG(m_logger) << "Unknown ParamType : " << s_paramtype ;
|
|
}
|
|
return p_ammu;
|
|
}
|
|
|
|
|
|
//bool AmmuConfig::loadAmmunitions(const QString &a_configFilename, QVector<Ammunition *> &a_ammunitions)
|
|
void AmmuConfig::loadAmmunitions()
|
|
{
|
|
m_ammunitions.clear();
|
|
|
|
int l_numberOfAmmunitions = getInteger(QStringLiteral("Ammunitions"), QStringLiteral("NumberOfEntries"), 0);
|
|
//INFO_LOG(m_logger) << "d_numberOfEntries : " << d_numberOfEntries ;
|
|
for (int i = 0; i < l_numberOfAmmunitions; i++)
|
|
{
|
|
QString s_ammu_group = QStringLiteral("Ammunition") + QString::number(i + 1);
|
|
m_ammunitions.push_back(loadAmmunition(s_ammu_group));
|
|
// INFO_LOG(m_logger) << "Ammunition " << p_ammu.m_AmmunInfo.m_Name << " added to list" ;
|
|
}
|
|
|
|
bool l_RandomizerOff = existsKey(QStringLiteral("Ammunitions"), QStringLiteral("DisableRandomSeed"));
|
|
if (!l_RandomizerOff)
|
|
srand(time(nullptr));
|
|
//else
|
|
// WARNING_LOG(m_logger) << "Randomizer is NOT seeded with Time..." ;
|
|
|
|
//INFO_LOG(m_logger) << "Total Ammunition count : " << m_ammunitions.size() ;
|
|
|
|
}
|
|
|
|
} // namespace N_ConfigSystem
|