134 lines
3.5 KiB
C++
134 lines
3.5 KiB
C++
/*
|
|
* @RDE_HEADER@
|
|
* Worker for Tetra Simulation
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <QtCore/QByteArray>
|
|
#include <QtCore/QMap>
|
|
#include <QtCore/QObject>
|
|
#include <QtCore/QPointF>
|
|
#include <QtCore/QMap>
|
|
#include <NGLLogger/INGLLogger.h>
|
|
#include <CoPrtCnv/CoPrtCnvCentralTelegram.hpp>
|
|
#include <CoPrtCnv/CoPrtCnvRadioTelegram.hpp>
|
|
#include <CoPrtCnv/CoPrtCnvTelegramConverter.hpp>
|
|
#include <TrainingAreaBase/training_area_telegrams.h>
|
|
#include "server.h"
|
|
|
|
|
|
class QTcpSocket;
|
|
class QTimer;
|
|
|
|
class Player
|
|
{
|
|
private:
|
|
void randomizeDeathTicks()
|
|
{
|
|
deathTicks = ((qrand() % (maximumDeathTicks - minimumDeathTicks + 1)) + minimumDeathTicks);
|
|
}
|
|
|
|
public:
|
|
// PU simulation vars:
|
|
uint32_t eqId;
|
|
uint32_t issi;
|
|
QPointF posUTM;
|
|
|
|
// PU login-state vars:
|
|
bool isLogin;
|
|
bool isValidBITE;
|
|
TrainingAreaBase::TetraIcd::VulnerabilityState vbg;
|
|
|
|
// pattern vars:
|
|
int patternInList; // >-| which pattern to take from the pattern list
|
|
int stepInPattern; // <-| which step we have in the current pattern (see "patternInList" above)
|
|
|
|
// x seconds, for a Player to respawn [maximum / mininum]
|
|
uint32_t deathTicks;
|
|
uint32_t minimumDeathTicks;
|
|
uint32_t maximumDeathTicks;
|
|
|
|
Player(int eqId_, int issi_, uint32_t minimumDeathTicks_, uint32_t maximumDeathTicks_, const QPointF &posUTM_)
|
|
: eqId(eqId_)
|
|
, issi(issi_)
|
|
, posUTM(posUTM_)
|
|
, isLogin(false)
|
|
, isValidBITE(false)
|
|
, vbg(TrainingAreaBase::TetraIcd::VulnerabilityState::CombatReady)
|
|
, patternInList(0)
|
|
, stepInPattern(1)
|
|
, deathTicks(0)
|
|
, minimumDeathTicks(minimumDeathTicks_)
|
|
, maximumDeathTicks(maximumDeathTicks_)
|
|
{
|
|
randomizeDeathTicks();
|
|
}
|
|
|
|
bool isEndOfTicks() // gives TRUE if deathTicks is lower than 1 and randomizes deathTicks again, so this function can be reused everytime
|
|
{
|
|
deathTicks--;
|
|
if (deathTicks < 1)
|
|
{
|
|
randomizeDeathTicks(); // randomize again
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
|
|
class TTWorker : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit TTWorker(QTcpSocket *socket, const TTSArgs &ttsArgs);
|
|
|
|
bool init();
|
|
|
|
private Q_SLOTS:
|
|
void onReadyRead();
|
|
void onSendPlayerPositions(); // -> nur senden, wenn isLogin & isValidBite für tln ok
|
|
// wenn LoginOk von PrtCnv -> onSendBite(eqId)
|
|
void onSocketError();
|
|
void onSendNachforderungBroadcastTelegramm();
|
|
void onSendDeaktivierungEinzelminen();
|
|
|
|
protected:
|
|
void startExecution();
|
|
QVector<runningPattern> interpretPattern(QString pattern) const;
|
|
void movePlayer(Player *p);
|
|
void handleReceivedTelegram(const QByteArray &data);
|
|
void handleRegisterInd();
|
|
void handleDataIndReq(const QByteArray &data);
|
|
|
|
void sendTelegram(N_CoPrtCnv::CoPrtCnvRadioTelegram *radioTelegram, uint32_t issi);
|
|
template <typename T>
|
|
void sendTelegram(const T &tele, uint32_t issi)
|
|
{
|
|
N_CoPrtCnv::CoPrtCnvCentralTelegram ct(tele);
|
|
sendTelegram(N_CoPrtCnv::CoPrtCnvTelegramConverter::convertToRadio(&ct), issi);
|
|
}
|
|
void sendLogin(uint32_t eqId, uint32_t issi);
|
|
void sendBITE(uint32_t eqId, uint32_t issi);
|
|
void sendTaktischerStatus(uint32_t eqId, uint32_t issi, TrainingAreaBase::TetraIcd::VulnerabilityState vbg);
|
|
void sendSanitationReport(uint32_t eqId, uint32_t issi);
|
|
//void sendSanitation(uint32_t eqId, uint32_t issi);
|
|
private:
|
|
QTcpSocket *m_socket;
|
|
QTimer *m_timer;
|
|
QByteArray m_buffer;
|
|
unsigned int m_counter;
|
|
bool m_toogle;
|
|
|
|
TTSArgs m_ttsArgs;
|
|
|
|
QVector<Player *> m_playerList;
|
|
QVector<runningPattern> m_patternList;
|
|
QPointF m_generalPosition;
|
|
NGL::INGLLogger &m_logger;
|
|
};
|