diff --git a/src/plugins/simulator/fsxcommon/simconnectobject.cpp b/src/plugins/simulator/fsxcommon/simconnectobject.cpp index 9dce9bbf0..77efc04a5 100644 --- a/src/plugins/simulator/fsxcommon/simconnectobject.cpp +++ b/src/plugins/simulator/fsxcommon/simconnectobject.cpp @@ -204,6 +204,18 @@ namespace BlackSimPlugin return CSimConnectObject(); } + CSimConnectObject CSimConnectObjects::markObjectAsAdded(DWORD objectId) + { + for (const CCallsign &cs : this->keys()) + { + CSimConnectObject &simObject = (*this)[cs]; + if (simObject.getObjectId() != objectId) { continue; } + simObject.setConfirmedAdded(true); + return simObject; + } + return CSimConnectObject(); + } + CSimConnectObject CSimConnectObjects::getSimObjectForRequestId(DWORD requestId) const { for (const CSimConnectObject &simObject : this->values()) @@ -215,10 +227,17 @@ namespace BlackSimPlugin bool CSimConnectObjects::isKnownSimObjectId(DWORD objectId) const { - const CSimConnectObject simObject(getSimObjectForObjectId(objectId)); + const CSimConnectObject simObject(this->getSimObjectForObjectId(objectId)); return simObject.hasValidRequestAndObjectId() && objectId == simObject.getObjectId(); } + bool CSimConnectObjects::removeByObjectId(DWORD objectId) + { + const CSimConnectObject simObject(this->getSimObjectForObjectId(objectId)); + const int c = this->remove(simObject.getCallsign()); + return c > 0; + } + bool CSimConnectObjects::containsPendingAdded() const { for (const CSimConnectObject &simObject : this->values()) @@ -257,6 +276,16 @@ namespace BlackSimPlugin return c; } + int CSimConnectObjects::countConfirmedAdded() + { + int c = 0; + for (const CSimConnectObject &simObject : this->values()) + { + if (simObject.isConfirmedAdded()) { c++; } + } + return c; + } + CCallsignSet CSimConnectObjects::getPendingAddedCallsigns() const { CCallsignSet callsigns; @@ -277,6 +306,25 @@ namespace BlackSimPlugin return callsigns; } + QList CSimConnectObjects::getByType(CSimConnectObject::SimObjectType type) const + { + QList objs; + for (const CSimConnectObject &simObject : this->values()) + { + if (simObject.getType() == type) { objs.push_back(simObject); } + } + return objs; + } + + bool CSimConnectObjects::containsType(CSimConnectObject::SimObjectType type) const + { + for (const CSimConnectObject &simObject : this->values()) + { + if (simObject.getType() == type) { return true; } + } + return false; + } + void CSimConnectObjects::toggleInterpolatorModes() { for (const CCallsign &cs : this->keys()) diff --git a/src/plugins/simulator/fsxcommon/simconnectobject.h b/src/plugins/simulator/fsxcommon/simconnectobject.h index 3f201eaf5..7762cd031 100644 --- a/src/plugins/simulator/fsxcommon/simconnectobject.h +++ b/src/plugins/simulator/fsxcommon/simconnectobject.h @@ -26,9 +26,19 @@ namespace BlackSimPlugin class CSimConnectObject { public: + //! Type + enum SimObjectType + { + Aircraft, + Probe + }; + //! Constructor CSimConnectObject(); + //! Constructor + CSimConnectObject(SimObjectType type) : m_type(type) {} + //! Constructor providing initial situation/parts CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, DWORD requestId, @@ -48,6 +58,12 @@ namespace BlackSimPlugin //! Simulated aircraft model string const QString &getAircraftModelString() const { return m_aircraft.getModelString(); } + //! Object type + SimObjectType getType() const { return m_type; } + + //! Set the type + void setType(SimObjectType type) { m_type = type; } + //! Set the aircraft void setAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) { m_aircraft = aircraft; } @@ -179,6 +195,7 @@ namespace BlackSimPlugin private: BlackMisc::Simulation::CSimulatedAircraft m_aircraft; //!< corresponding aircraft + SimObjectType m_type = Aircraft; DWORD m_requestId = 0; DWORD m_objectId = 0; bool m_validRequestId = false; @@ -207,12 +224,18 @@ namespace BlackSimPlugin //! Get object per object id CSimConnectObject getSimObjectForObjectId(DWORD objectId) const; + //! Mark as added if existing + CSimConnectObject markObjectAsAdded(DWORD objectId); + //! Get object per request id CSimConnectObject getSimObjectForRequestId(DWORD requestId) const; //! Is the object id one of our AI objects? bool isKnownSimObjectId(DWORD objectId) const; + //! Remove by id + bool removeByObjectId(DWORD objectId); + //! Pending add condition bool containsPendingAdded() const; @@ -225,6 +248,9 @@ namespace BlackSimPlugin //! Number of pending removed int countPendingRemoved() const; + //! Objects not pending + int countConfirmedAdded(); + //! Get all callsigns BlackMisc::Aviation::CCallsignSet getAllCallsigns() const; @@ -240,6 +266,12 @@ namespace BlackSimPlugin //! Callsigns of pending removed callsigns BlackMisc::Aviation::CCallsignSet getPendingRemovedCallsigns() const; + //! Get by type + QList getByType(CSimConnectObject::SimObjectType type) const; + + //! Contains object of type + bool containsType(CSimConnectObject::SimObjectType type) const; + //! Toggle interpolator modes void toggleInterpolatorModes();