mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Added code to update ammo and contacts
This commit is contained in:
@@ -157,48 +157,48 @@ public:
|
|||||||
virtual void setTACAN(DataTypes::TACAN newValue, bool force = false);
|
virtual void setTACAN(DataTypes::TACAN newValue, bool force = false);
|
||||||
virtual void setRadio(DataTypes::Radio newValue, bool force = false);
|
virtual void setRadio(DataTypes::Radio newValue, bool force = false);
|
||||||
virtual void setGeneralSettings(DataTypes::GeneralSettings newValue, bool force = false);
|
virtual void setGeneralSettings(DataTypes::GeneralSettings newValue, bool force = false);
|
||||||
virtual void setAmmo(vector<DataTypes::Ammo> newValue) { updateValue(ammo, newValue, DataIndex::ammo); }
|
virtual void setAmmo(vector<DataTypes::Ammo> newValue);
|
||||||
virtual void setContacts(vector<DataTypes::Contact> newValue) { updateValue(contacts, newValue, DataIndex::contacts); }
|
virtual void setContacts(vector<DataTypes::Contact> newValue);
|
||||||
virtual void setActivePath(list<Coords> newValue);
|
virtual void setActivePath(list<Coords> newValue);
|
||||||
|
|
||||||
/********** Getters **********/
|
/********** Getters **********/
|
||||||
virtual string getCategory() { return category; };
|
virtual const string& getCategory() { return category; };
|
||||||
virtual bool getAlive() { return alive; }
|
virtual const bool& getAlive() { return alive; }
|
||||||
virtual bool getHuman() { return human; }
|
virtual const bool& getHuman() { return human; }
|
||||||
virtual bool getControlled() { return controlled; }
|
virtual const bool& getControlled() { return controlled; }
|
||||||
virtual unsigned int getCoalition() { return coalition; }
|
virtual const unsigned char& getCoalition() { return coalition; }
|
||||||
virtual unsigned char getCountry() { return country; }
|
virtual const unsigned char& getCountry() { return country; }
|
||||||
virtual string getName() { return name; }
|
virtual const string& getName() { return name; }
|
||||||
virtual string getUnitName() { return unitName; }
|
virtual const string& getUnitName() { return unitName; }
|
||||||
virtual string getGroupName() { return groupName; }
|
virtual const string& getGroupName() { return groupName; }
|
||||||
virtual unsigned char getState() { return state; }
|
virtual const unsigned char& getState() { return state; }
|
||||||
virtual string getTask() { return task; }
|
virtual const string& getTask() { return task; }
|
||||||
virtual bool getHasTask() { return hasTask; }
|
virtual const bool& getHasTask() { return hasTask; }
|
||||||
virtual Coords getPosition() { return position; }
|
virtual const Coords& getPosition() { return position; }
|
||||||
virtual double getSpeed() { return speed; }
|
virtual const double& getSpeed() { return speed; }
|
||||||
virtual double getHeading() { return heading; }
|
virtual const double& getHeading() { return heading; }
|
||||||
virtual bool getIsTanker() { return isTanker; }
|
virtual const bool& getIsTanker() { return isTanker; }
|
||||||
virtual bool getIsAWACS() { return isAWACS; }
|
virtual const bool& getIsAWACS() { return isAWACS; }
|
||||||
virtual bool getOnOff() { return onOff; };
|
virtual const bool& getOnOff() { return onOff; };
|
||||||
virtual bool getFollowRoads() { return followRoads; };
|
virtual const bool& getFollowRoads() { return followRoads; };
|
||||||
virtual double getFuel() { return fuel; }
|
virtual const unsigned short& getFuel() { return fuel; }
|
||||||
virtual double getDesiredSpeed() { return desiredSpeed; };
|
virtual const double& getDesiredSpeed() { return desiredSpeed; };
|
||||||
virtual bool getDesiredSpeedType() { return desiredSpeedType; };
|
virtual const bool& getDesiredSpeedType() { return desiredSpeedType; };
|
||||||
virtual double getDesiredAltitude() { return desiredAltitude; };
|
virtual const double& getDesiredAltitude() { return desiredAltitude; };
|
||||||
virtual bool getDesiredAltitudeType() { return desiredAltitudeType; };
|
virtual const bool& getDesiredAltitudeType() { return desiredAltitudeType; };
|
||||||
virtual unsigned int getLeaderID() { return leaderID; }
|
virtual const unsigned int& getLeaderID() { return leaderID; }
|
||||||
virtual Offset getFormationoffset() { return formationOffset; }
|
virtual const Offset& getFormationoffset() { return formationOffset; }
|
||||||
virtual unsigned int getTargetID() { return targetID; }
|
virtual const unsigned int& getTargetID() { return targetID; }
|
||||||
virtual Coords getTargetPosition() { return targetPosition; }
|
virtual const Coords& getTargetPosition() { return targetPosition; }
|
||||||
virtual unsigned char getROE() { return ROE; }
|
virtual const unsigned char& getROE() { return ROE; }
|
||||||
virtual unsigned char getReactionToThreat() { return reactionToThreat; }
|
virtual const unsigned char& getReactionToThreat() { return reactionToThreat; }
|
||||||
virtual unsigned char getEmissionsCountermeasures() { return emissionsCountermeasures; };
|
virtual const unsigned char& getEmissionsCountermeasures() { return emissionsCountermeasures; };
|
||||||
virtual DataTypes::TACAN getTACAN() { return TACAN; }
|
virtual const DataTypes::TACAN& getTACAN() { return TACAN; }
|
||||||
virtual DataTypes::Radio getRadio() { return radio; }
|
virtual const DataTypes::Radio& getRadio() { return radio; }
|
||||||
virtual DataTypes::GeneralSettings getGeneralSettings() { return generalSettings; }
|
virtual const DataTypes::GeneralSettings& getGeneralSettings() { return generalSettings; }
|
||||||
virtual vector<DataTypes::Ammo> getAmmo() { return ammo; }
|
virtual const vector<DataTypes::Ammo>& getAmmo() { return ammo; }
|
||||||
virtual vector<DataTypes::Contact> getTargets() { return contacts; }
|
virtual const vector<DataTypes::Contact>& getTargets() { return contacts; }
|
||||||
virtual list<Coords> getActivePath() { return activePath; }
|
virtual const list<Coords>& getActivePath() { return activePath; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int ID;
|
unsigned int ID;
|
||||||
@@ -251,6 +251,13 @@ protected:
|
|||||||
/********** Private methods **********/
|
/********** Private methods **********/
|
||||||
virtual void AIloop() = 0;
|
virtual void AIloop() = 0;
|
||||||
|
|
||||||
|
void appendString(stringstream& ss, const unsigned char& datumIndex, const string& datumValue) {
|
||||||
|
const unsigned short size = datumValue.size();
|
||||||
|
ss.write((const char*)&datumIndex, sizeof(unsigned char));
|
||||||
|
ss.write((const char*)&size, sizeof(unsigned short));
|
||||||
|
ss << datumValue;
|
||||||
|
}
|
||||||
|
|
||||||
/********** Template methods **********/
|
/********** Template methods **********/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void updateValue(T& value, T& newValue, unsigned char datumIndex)
|
void updateValue(T& value, T& newValue, unsigned char datumIndex)
|
||||||
@@ -268,13 +275,6 @@ protected:
|
|||||||
ss.write((const char*)&datumValue, sizeof(T));
|
ss.write((const char*)&datumValue, sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendString(stringstream& ss, const unsigned char& datumIndex, string& datumValue) {
|
|
||||||
const unsigned short size = datumValue.size();
|
|
||||||
ss.write((const char*)&datumIndex, sizeof(unsigned char));
|
|
||||||
ss.write((const char*)&size, sizeof(unsigned short));
|
|
||||||
ss << datumValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void appendVector(stringstream& ss, const unsigned char& datumIndex, vector<T>& datumValue) {
|
void appendVector(stringstream& ss, const unsigned char& datumIndex, vector<T>& datumValue) {
|
||||||
const unsigned short size = datumValue.size();
|
const unsigned short size = datumValue.size();
|
||||||
|
|||||||
@@ -174,64 +174,94 @@ void Unit::updateMissionData(json::value json)
|
|||||||
|
|
||||||
void Unit::getData(stringstream& ss, unsigned long long time, bool refresh)
|
void Unit::getData(stringstream& ss, unsigned long long time, bool refresh)
|
||||||
{
|
{
|
||||||
/* Prepare the data packet and copy it to memory */
|
Unit* sourceUnit = this;
|
||||||
/* If the unit is in a group, get the update data from the group leader and only replace the position: speed and heading */
|
if (unitsManager->isUnitInGroup(this) && !unitsManager->isUnitGroupLeader(this))
|
||||||
//if (unitsManager->isUnitInGroup(this) && !unitsManager->isUnitGroupLeader(this)) {
|
sourceUnit = unitsManager->getGroupLeader(this);
|
||||||
// DataTypes::DataPacket* p = (DataTypes::DataPacket*)data;
|
|
||||||
// p->position = position;
|
|
||||||
// p->speed = speed;
|
|
||||||
// p->heading = heading;
|
|
||||||
//}
|
|
||||||
|
|
||||||
const unsigned char endOfData = DataIndex::endOfData;
|
const unsigned char endOfData = DataIndex::endOfData;
|
||||||
|
|
||||||
ss.write((const char*)&ID, sizeof(ID));
|
ss.write((const char*)&ID, sizeof(ID));
|
||||||
for (auto d : updateTimeMap) {
|
for (auto d : updateTimeMap) {
|
||||||
if (d.second > time) {
|
if (d.second > time) {
|
||||||
switch (d.first) {
|
switch (d.first) {
|
||||||
case DataIndex::category: appendString(ss, d.first, category); break;
|
case DataIndex::category: appendString(ss, d.first, category); break;
|
||||||
case DataIndex::alive: appendNumeric(ss, d.first, alive); break;
|
case DataIndex::alive: appendNumeric(ss, d.first, alive); break;
|
||||||
case DataIndex::human: appendNumeric(ss, d.first, human); break;
|
case DataIndex::human: appendNumeric(ss, d.first, sourceUnit->human); break;
|
||||||
case DataIndex::controlled: appendNumeric(ss, d.first, controlled); break;
|
case DataIndex::controlled: appendNumeric(ss, d.first, sourceUnit->controlled); break;
|
||||||
case DataIndex::coalition: appendNumeric(ss, d.first, coalition); break;
|
case DataIndex::coalition: appendNumeric(ss, d.first, sourceUnit->coalition); break;
|
||||||
case DataIndex::country: appendNumeric(ss, d.first, country); break;
|
case DataIndex::country: appendNumeric(ss, d.first, sourceUnit->country); break;
|
||||||
case DataIndex::name: appendString(ss, d.first, name); break;
|
case DataIndex::name: appendString(ss, d.first, name); break;
|
||||||
case DataIndex::unitName: appendString(ss, d.first, unitName); break;
|
case DataIndex::unitName: appendString(ss, d.first, unitName); break;
|
||||||
case DataIndex::groupName: appendString(ss, d.first, groupName); break;
|
case DataIndex::groupName: appendString(ss, d.first, sourceUnit->groupName); break;
|
||||||
case DataIndex::state: appendNumeric(ss, d.first, state); break;
|
case DataIndex::state: appendNumeric(ss, d.first, sourceUnit->state); break;
|
||||||
case DataIndex::task: appendString(ss, d.first, task); break;
|
case DataIndex::task: appendString(ss, d.first, sourceUnit->task); break;
|
||||||
case DataIndex::hasTask: appendNumeric(ss, d.first, hasTask); break;
|
case DataIndex::hasTask: appendNumeric(ss, d.first, sourceUnit->hasTask); break;
|
||||||
case DataIndex::position: appendNumeric(ss, d.first, position); break;
|
case DataIndex::position: appendNumeric(ss, d.first, position); break;
|
||||||
case DataIndex::speed: appendNumeric(ss, d.first, speed); break;
|
case DataIndex::speed: appendNumeric(ss, d.first, speed); break;
|
||||||
case DataIndex::heading: appendNumeric(ss, d.first, heading); break;
|
case DataIndex::heading: appendNumeric(ss, d.first, heading); break;
|
||||||
case DataIndex::isTanker: appendNumeric(ss, d.first, isTanker); break;
|
case DataIndex::isTanker: appendNumeric(ss, d.first, sourceUnit->isTanker); break;
|
||||||
case DataIndex::isAWACS: appendNumeric(ss, d.first, isAWACS); break;
|
case DataIndex::isAWACS: appendNumeric(ss, d.first, sourceUnit->isAWACS); break;
|
||||||
case DataIndex::onOff: appendNumeric(ss, d.first, onOff); break;
|
case DataIndex::onOff: appendNumeric(ss, d.first, sourceUnit->onOff); break;
|
||||||
case DataIndex::followRoads: appendNumeric(ss, d.first, followRoads); break;
|
case DataIndex::followRoads: appendNumeric(ss, d.first, sourceUnit->followRoads); break;
|
||||||
case DataIndex::fuel: appendNumeric(ss, d.first, fuel); break;
|
case DataIndex::fuel: appendNumeric(ss, d.first, fuel); break;
|
||||||
case DataIndex::desiredSpeed: appendNumeric(ss, d.first, desiredSpeed); break;
|
case DataIndex::desiredSpeed: appendNumeric(ss, d.first, sourceUnit->desiredSpeed); break;
|
||||||
case DataIndex::desiredSpeedType: appendNumeric(ss, d.first, desiredSpeedType); break;
|
case DataIndex::desiredSpeedType: appendNumeric(ss, d.first, sourceUnit->desiredSpeedType); break;
|
||||||
case DataIndex::desiredAltitude: appendNumeric(ss, d.first, desiredAltitude); break;
|
case DataIndex::desiredAltitude: appendNumeric(ss, d.first, sourceUnit->desiredAltitude); break;
|
||||||
case DataIndex::desiredAltitudeType: appendNumeric(ss, d.first, desiredAltitudeType); break;
|
case DataIndex::desiredAltitudeType: appendNumeric(ss, d.first, sourceUnit->desiredAltitudeType); break;
|
||||||
case DataIndex::leaderID: appendNumeric(ss, d.first, leaderID); break;
|
case DataIndex::leaderID: appendNumeric(ss, d.first, sourceUnit->leaderID); break;
|
||||||
case DataIndex::formationOffset: appendNumeric(ss, d.first, formationOffset); break;
|
case DataIndex::formationOffset: appendNumeric(ss, d.first, sourceUnit->formationOffset); break;
|
||||||
case DataIndex::targetID: appendNumeric(ss, d.first, targetID); break;
|
case DataIndex::targetID: appendNumeric(ss, d.first, sourceUnit->targetID); break;
|
||||||
case DataIndex::targetPosition: appendNumeric(ss, d.first, targetPosition); break;
|
case DataIndex::targetPosition: appendNumeric(ss, d.first, sourceUnit->targetPosition); break;
|
||||||
case DataIndex::ROE: appendNumeric(ss, d.first, ROE); break;
|
case DataIndex::ROE: appendNumeric(ss, d.first, sourceUnit->ROE); break;
|
||||||
case DataIndex::reactionToThreat: appendNumeric(ss, d.first, reactionToThreat); break;
|
case DataIndex::reactionToThreat: appendNumeric(ss, d.first, sourceUnit->reactionToThreat); break;
|
||||||
case DataIndex::emissionsCountermeasures: appendNumeric(ss, d.first, emissionsCountermeasures); break;
|
case DataIndex::emissionsCountermeasures: appendNumeric(ss, d.first, sourceUnit->emissionsCountermeasures); break;
|
||||||
case DataIndex::TACAN: appendNumeric(ss, d.first, TACAN); break;
|
case DataIndex::TACAN: appendNumeric(ss, d.first, sourceUnit->TACAN); break;
|
||||||
case DataIndex::radio: appendNumeric(ss, d.first, radio); break;
|
case DataIndex::radio: appendNumeric(ss, d.first, sourceUnit->radio); break;
|
||||||
case DataIndex::generalSettings: appendNumeric(ss, d.first, generalSettings); break;
|
case DataIndex::generalSettings: appendNumeric(ss, d.first, sourceUnit->generalSettings); break;
|
||||||
case DataIndex::ammo: appendVector(ss, d.first, ammo); break;
|
case DataIndex::ammo: appendVector(ss, d.first, ammo); break;
|
||||||
case DataIndex::contacts: appendVector(ss, d.first, contacts); break;
|
case DataIndex::contacts: appendVector(ss, d.first, contacts); break;
|
||||||
case DataIndex::activePath: appendList(ss, d.first, activePath); break;
|
case DataIndex::activePath: appendList(ss, d.first, sourceUnit->activePath); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ss.write((const char*)&endOfData, sizeof(endOfData));
|
ss.write((const char*)&endOfData, sizeof(endOfData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Unit::setAmmo(vector<DataTypes::Ammo> newValue)
|
||||||
|
{
|
||||||
|
if (ammo.size() == newValue.size()) {
|
||||||
|
bool equal = true;
|
||||||
|
for (int i = 0; i < ammo.size(); i++) {
|
||||||
|
if (ammo.at(i) != newValue.at(i))
|
||||||
|
{
|
||||||
|
equal = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (equal)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ammo = newValue;
|
||||||
|
triggerUpdate(DataIndex::ammo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unit::setContacts(vector<DataTypes::Contact> newValue)
|
||||||
|
{
|
||||||
|
if (contacts.size() == newValue.size()) {
|
||||||
|
bool equal = true;
|
||||||
|
for (int i = 0; i < ammo.size(); i++) {
|
||||||
|
if (contacts.at(i) != newValue.at(i))
|
||||||
|
{
|
||||||
|
equal = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (equal)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
contacts = newValue;
|
||||||
|
triggerUpdate(DataIndex::contacts);
|
||||||
|
}
|
||||||
|
|
||||||
void Unit::setActivePath(list<Coords> newPath)
|
void Unit::setActivePath(list<Coords> newPath)
|
||||||
{
|
{
|
||||||
activePath = newPath;
|
activePath = newPath;
|
||||||
|
|||||||
Reference in New Issue
Block a user