diff --git a/client/src/panels/unitinfopanel.ts b/client/src/panels/unitinfopanel.ts index 8ca140b0..c6e7d724 100644 --- a/client/src/panels/unitinfopanel.ts +++ b/client/src/panels/unitinfopanel.ts @@ -1,4 +1,5 @@ import { getUnitsManager } from ".."; +import { Ammo } from "../@types/unit"; import { ConvertDDToDMS, rad2deg } from "../other/utils"; import { aircraftDatabase } from "../units/aircraftdatabase"; import { Unit } from "../units/unit"; @@ -77,10 +78,10 @@ export class UnitInfoPanel extends Panel { const ammo = Object.values(unit.getData().ammo); if (ammo.length > 0) { items.replaceChildren(...Object.values(unit.getData().ammo).map( - (ammo: any) => { + (ammo: Ammo) => { var el = document.createElement("div"); - el.dataset.qty = ammo.count; - el.dataset.item = ammo.desc.displayName; + el.dataset.qty = `${ammo.quantity}`; + el.dataset.item = ammo.name; return el; } )); diff --git a/client/src/units/dataextractor.ts b/client/src/units/dataextractor.ts index 7b5eaf32..9390be62 100644 --- a/client/src/units/dataextractor.ts +++ b/client/src/units/dataextractor.ts @@ -109,7 +109,7 @@ export class DataExtractor { for (let idx = 0; idx < size; idx++) { value.push({ quantity: this.extractUInt16(), - name: this.extractString(32), + name: this.extractString(33), guidance: this.extractUInt8(), category: this.extractUInt8(), missileCategory: this.extractUInt8() diff --git a/client/src/units/unit.ts b/client/src/units/unit.ts index 13d7685b..0bc5ee69 100644 --- a/client/src/units/unit.ts +++ b/client/src/units/unit.ts @@ -35,7 +35,7 @@ export class Unit extends CustomMarker { #heading: number = 0; #isTanker: boolean = false; #isAWACS: boolean = false; - #onOff: boolean = false; + #onOff: boolean = true; #followRoads: boolean = false; #fuel: number = 0; #desiredSpeed: number = 0; @@ -60,9 +60,9 @@ export class Unit extends CustomMarker { channel: 0 }; #radio: Radio = { - frequency: 0, - callsign: 0, - callsignNumber: 0 + frequency: 124000000, + callsign: 1, + callsignNumber: 1 }; #generalSettings: GeneralSettings = { prohibitAA: false, @@ -187,10 +187,10 @@ export class Unit extends CustomMarker { this.#updateMarker(); // TODO dont delete the polylines of the detected units - this.#clearDetectedUnits(); + this.#clearContacts(); if (this.getSelected()) { this.#drawPath(); - this.#drawDetectedUnits(); + this.#drawContacts(); this.#drawTarget(); } else { @@ -284,7 +284,7 @@ export class Unit extends CustomMarker { } else { document.dispatchEvent(new CustomEvent("unitDeselection", { detail: this })); - this.#clearDetectedUnits(); + this.#clearContacts(); this.#clearPath(); this.#clearTarget(); } @@ -607,8 +607,7 @@ export class Unit extends CustomMarker { onAdd(map: Map): this { super.onAdd(map); /* If this is the first time adding this unit to the map, remove the temporary marker */ - if (getUnitsManager().getUnitByID(this.ID) == null) - getMap().removeTemporaryMarker(new LatLng(this.#position.lat, this.#position.lng)); + getMap().removeTemporaryMarker(new LatLng(this.#position.lat, this.#position.lng)); return this; } @@ -798,13 +797,13 @@ export class Unit extends CustomMarker { var newHasFox2 = false; var newHasFox3 = false; var newHasOtherAmmo = false; - Object.values(this.#ammo).forEach((ammo: any) => { - if (ammo.desc.category == 1 && ammo.desc.missileCategory == 1) { - if (ammo.desc.guidance == 4 || ammo.desc.guidance == 5) + Object.values(this.#ammo).forEach((ammo: Ammo) => { + if (ammo.category == 1 && ammo.missileCategory == 1) { + if (ammo.guidance == 4 || ammo.guidance == 5) newHasFox1 = true; - else if (ammo.desc.guidance == 2) + else if (ammo.guidance == 2) newHasFox2 = true; - else if (ammo.desc.guidance == 3) + else if (ammo.guidance == 3) newHasFox3 = true; } else @@ -870,31 +869,31 @@ export class Unit extends CustomMarker { this.#pathPolyline.setLatLngs([]); } - #drawDetectedUnits() { + #drawContacts() { for (let index in this.#contacts) { - var targetData = this.#contacts[index]; - var target = getUnitsManager().getUnitByID(targetData.ID) - if (target != null) { + var contactData = this.#contacts[index]; + var contact = getUnitsManager().getUnitByID(contactData.ID) + if (contact != null) { var startLatLng = new LatLng(this.#position.lat, this.#position.lng) - var endLatLng = new LatLng(target.#position.lat, target.#position.lng) + var endLatLng = new LatLng(contact.#position.lat, contact.#position.lng) var color; - if (targetData.detectionMethod === 1) + if (contactData.detectionMethod === 1) color = "#FF00FF"; - else if (targetData.detectionMethod === 4) + else if (contactData.detectionMethod === 4) color = "#FFFF00"; - else if (targetData.detectionMethod === 16) + else if (contactData.detectionMethod === 16) color = "#00FF00"; else color = "#FFFFFF"; - var targetPolyline = new Polyline([startLatLng, endLatLng], { color: color, weight: 3, opacity: 0.4, smoothFactor: 1, dashArray: "4, 8" }); - targetPolyline.addTo(getMap()); - this.#contactsPolylines.push(targetPolyline) + var contactPolyline = new Polyline([startLatLng, endLatLng], { color: color, weight: 3, opacity: 0.4, smoothFactor: 1, dashArray: "4, 8" }); + contactPolyline.addTo(getMap()); + this.#contactsPolylines.push(contactPolyline) } } } - #clearDetectedUnits() { + #clearContacts() { for (let index in this.#contactsPolylines) { getMap().removeLayer(this.#contactsPolylines[index]) } diff --git a/src/core/include/commands.h b/src/core/include/commands.h index 091eac61..5c1769e0 100644 --- a/src/core/include/commands.h +++ b/src/core/include/commands.h @@ -234,7 +234,7 @@ private: const bool explosion; }; -/* Follow command */ +/* SetTask command */ class SetTask : public Command { public: diff --git a/src/core/include/unit.h b/src/core/include/unit.h index df335df9..c380878e 100644 --- a/src/core/include/unit.h +++ b/src/core/include/unit.h @@ -162,43 +162,43 @@ public: virtual void setActivePath(list newValue); /********** Getters **********/ - virtual const string& getCategory() { return category; }; - virtual const bool& getAlive() { return alive; } - virtual const bool& getHuman() { return human; } - virtual const bool& getControlled() { return controlled; } - virtual const unsigned char& getCoalition() { return coalition; } - virtual const unsigned char& getCountry() { return country; } - virtual const string& getName() { return name; } - virtual const string& getUnitName() { return unitName; } - virtual const string& getGroupName() { return groupName; } - virtual const unsigned char& getState() { return state; } - virtual const string& getTask() { return task; } - virtual const bool& getHasTask() { return hasTask; } - virtual const Coords& getPosition() { return position; } - virtual const double& getSpeed() { return speed; } - virtual const double& getHeading() { return heading; } - virtual const bool& getIsTanker() { return isTanker; } - virtual const bool& getIsAWACS() { return isAWACS; } - virtual const bool& getOnOff() { return onOff; }; - virtual const bool& getFollowRoads() { return followRoads; }; - virtual const unsigned short& getFuel() { return fuel; } - virtual const double& getDesiredSpeed() { return desiredSpeed; }; - virtual const bool& getDesiredSpeedType() { return desiredSpeedType; }; - virtual const double& getDesiredAltitude() { return desiredAltitude; }; - virtual const bool& getDesiredAltitudeType() { return desiredAltitudeType; }; - virtual const unsigned int& getLeaderID() { return leaderID; } - virtual const Offset& getFormationoffset() { return formationOffset; } - virtual const unsigned int& getTargetID() { return targetID; } - virtual const Coords& getTargetPosition() { return targetPosition; } - virtual const unsigned char& getROE() { return ROE; } - virtual const unsigned char& getReactionToThreat() { return reactionToThreat; } - virtual const unsigned char& getEmissionsCountermeasures() { return emissionsCountermeasures; }; - virtual const DataTypes::TACAN& getTACAN() { return TACAN; } - virtual const DataTypes::Radio& getRadio() { return radio; } - virtual const DataTypes::GeneralSettings& getGeneralSettings() { return generalSettings; } - virtual const vector& getAmmo() { return ammo; } - virtual const vector& getTargets() { return contacts; } - virtual const list& getActivePath() { return activePath; } + virtual string getCategory() { return category; }; + virtual bool getAlive() { return alive; } + virtual bool getHuman() { return human; } + virtual bool getControlled() { return controlled; } + virtual unsigned char getCoalition() { return coalition; } + virtual unsigned char getCountry() { return country; } + virtual string getName() { return name; } + virtual string getUnitName() { return unitName; } + virtual string getGroupName() { return groupName; } + virtual unsigned char getState() { return state; } + virtual string getTask() { return task; } + virtual bool getHasTask() { return hasTask; } + virtual Coords getPosition() { return position; } + virtual double getSpeed() { return speed; } + virtual double getHeading() { return heading; } + virtual bool getIsTanker() { return isTanker; } + virtual bool getIsAWACS() { return isAWACS; } + virtual bool getOnOff() { return onOff; }; + virtual bool getFollowRoads() { return followRoads; }; + virtual unsigned short getFuel() { return fuel; } + virtual double getDesiredSpeed() { return desiredSpeed; }; + virtual bool getDesiredSpeedType() { return desiredSpeedType; }; + virtual double getDesiredAltitude() { return desiredAltitude; }; + virtual bool getDesiredAltitudeType() { return desiredAltitudeType; }; + virtual unsigned int getLeaderID() { return leaderID; } + virtual Offset getFormationoffset() { return formationOffset; } + virtual unsigned int getTargetID() { return targetID; } + virtual Coords getTargetPosition() { return targetPosition; } + virtual unsigned char getROE() { return ROE; } + virtual unsigned char getReactionToThreat() { return reactionToThreat; } + virtual unsigned char getEmissionsCountermeasures() { return emissionsCountermeasures; }; + virtual DataTypes::TACAN getTACAN() { return TACAN; } + virtual DataTypes::Radio getRadio() { return radio; } + virtual DataTypes::GeneralSettings getGeneralSettings() { return generalSettings; } + virtual vector getAmmo() { return ammo; } + virtual vector getTargets() { return contacts; } + virtual list getActivePath() { return activePath; } protected: unsigned int ID; @@ -220,7 +220,7 @@ protected: double heading = NULL; bool isTanker = false; bool isAWACS = false; - bool onOff = false; + bool onOff = true; bool followRoads = false; unsigned short fuel = 0; double desiredSpeed = 0; @@ -265,7 +265,7 @@ protected: if (newValue != value) { triggerUpdate(datumIndex); - *(&value) = newValue; + value = newValue; } } @@ -280,7 +280,9 @@ protected: const unsigned short size = datumValue.size(); ss.write((const char*)&datumIndex, sizeof(unsigned char)); ss.write((const char*)&size, sizeof(unsigned short)); - ss.write((const char*)&datumValue, size * sizeof(T)); + + for (auto& el : datumValue) + ss.write((const char*)&el, sizeof(T)); } template diff --git a/src/core/src/airunit.cpp b/src/core/src/airunit.cpp index 85eb71fe..9f32981d 100644 --- a/src/core/src/airunit.cpp +++ b/src/core/src/airunit.cpp @@ -113,6 +113,8 @@ void AirUnit::setState(unsigned char newState) log(unitName + " setting state from " + to_string(state) + " to " + to_string(newState)); state = newState; + + triggerUpdate(DataIndex::state); } void AirUnit::AIloop() diff --git a/src/core/src/groundunit.cpp b/src/core/src/groundunit.cpp index 1811565d..e8294d83 100644 --- a/src/core/src/groundunit.cpp +++ b/src/core/src/groundunit.cpp @@ -65,6 +65,8 @@ void GroundUnit::setState(unsigned char newState) log(unitName + " setting state from " + to_string(state) + " to " + to_string(newState)); state = newState; + + triggerUpdate(DataIndex::state); } void GroundUnit::AIloop() diff --git a/src/core/src/scheduler.cpp b/src/core/src/scheduler.cpp index bcfe724e..2346c1ea 100644 --- a/src/core/src/scheduler.cpp +++ b/src/core/src/scheduler.cpp @@ -57,6 +57,7 @@ void Scheduler::handleRequest(string key, json::value value) Command* command = nullptr; log("Received request with ID: " + key); + log(value.serialize()); if (key.compare("setPath") == 0) { unsigned int ID = value[L"ID"].as_integer(); @@ -146,10 +147,10 @@ void Scheduler::handleRequest(string key, json::value value) { unsigned int ID = value[L"ID"].as_integer(); unitsManager->acquireControl(ID); - unsigned int leaderID = value[L"targetID"].as_integer(); - unsigned int offsetX = value[L"offsetX"].as_integer(); - unsigned int offsetY = value[L"offsetY"].as_integer(); - unsigned int offsetZ = value[L"offsetZ"].as_integer(); + unsigned int leaderID = value[L"targetID"].as_double(); + double offsetX = value[L"offsetX"].as_double(); + double offsetY = value[L"offsetY"].as_double(); + double offsetZ = value[L"offsetZ"].as_double(); Unit* unit = unitsManager->getGroupLeader(ID); Unit* leader = unitsManager->getUnit(leaderID); diff --git a/src/core/src/unit.cpp b/src/core/src/unit.cpp index 01cfbc71..4f6212bf 100644 --- a/src/core/src/unit.cpp +++ b/src/core/src/unit.cpp @@ -128,7 +128,6 @@ void Unit::updateMissionData(json::value json) if (json.has_object_field(L"ammo")) { vector ammo; for (auto const& el : json[L"ammo"].as_object()) { - log(el.second.serialize()); DataTypes::Ammo ammoItem; auto ammoJson = el.second; ammoItem.quantity = ammoJson[L"count"].as_number().to_uint32(); @@ -156,12 +155,12 @@ void Unit::updateMissionData(json::value json) contactItem.ID = contactJson[L"object"][L"id_"].as_number().to_uint32(); string detectionMethod = to_string(contactJson[L"detectionMethod"]); - if (detectionMethod.compare("VISUAL")) contactItem.detectionMethod = 1; - else if (detectionMethod.compare("OPTIC")) contactItem.detectionMethod = 2; - else if (detectionMethod.compare("RADAR")) contactItem.detectionMethod = 4; - else if (detectionMethod.compare("IRST")) contactItem.detectionMethod = 8; - else if (detectionMethod.compare("RWR")) contactItem.detectionMethod = 16; - else if (detectionMethod.compare("DLINK")) contactItem.detectionMethod = 32; + if (detectionMethod.compare("VISUAL") == 0) contactItem.detectionMethod = 1; + else if (detectionMethod.compare("OPTIC") == 0) contactItem.detectionMethod = 2; + else if (detectionMethod.compare("RADAR") == 0) contactItem.detectionMethod = 4; + else if (detectionMethod.compare("IRST") == 0) contactItem.detectionMethod = 8; + else if (detectionMethod.compare("RWR") == 0) contactItem.detectionMethod = 16; + else if (detectionMethod.compare("DLINK") == 0) contactItem.detectionMethod = 32; contacts.push_back(contactItem); } setContacts(contacts); @@ -248,7 +247,7 @@ void Unit::setContacts(vector newValue) { if (contacts.size() == newValue.size()) { bool equal = true; - for (int i = 0; i < ammo.size(); i++) { + for (int i = 0; i < contacts.size(); i++) { if (contacts.at(i) != newValue.at(i)) { equal = false;