WSF
WsfSA_Perceive.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI//REL TO USA ONLY
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2020 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFSA_PERCEIVE_HPP
13#define WSFSA_PERCEIVE_HPP
14
15#include "wsf_air_combat_export.h"
16
17#include <random>
18#include <set>
19
21#include "WsfSA_Module.hpp"
23class WsfSA_Processor;
24#include <unordered_map>
25#include <unordered_set>
26
27#include "WsfTrackId.hpp"
28
30class WSF_AIR_COMBAT_EXPORT WsfSA_Perceive : WsfSA_Module
31{
32public:
33 friend class WsfSA_Processor;
35
44
48
52 void AddExtraCognitiveLoading(double aTimeDelay);
53
58
62 void MarkAssetAsImportant(size_t aIndex);
63
67 void MarkAssetTypeAsImportant(const std::string& aType);
68
72 void MarkAssetTypeAsUnimportant(const std::string& aType);
73
78
82 void MarkAssetAsUnimportant(size_t aIndex);
83
88
93
97 void MarkThreatTypeAsImportant(const std::string& aType);
98
102 void MarkThreatTypeAsUnimportant(const std::string& aType);
103
105 int MaxAssetLoad() { return mDataPtr->mMaxAssetLoad; }
106
108 int MaxThreatLoad() { return mDataPtr->mMaxThreatLoad; }
109
114 const WsfSA_EntityPerception* PerceivedAsset(size_t aPlatformIndex) const;
115
120 const std::vector<WsfSA_EntityPerception*>& PerceivedAssets(double aSimTime);
121
126 const std::vector<WsfSA_EntityPerception*>& PerceivedAircraftAssets(double aSimTime);
127
132 const std::vector<WsfSA_EntityPerception*>& PerceivedMissileAssets(double aSimTime);
133
138 const std::vector<WsfSA_EntityPerception*>& PerceivedBogies(double aSimTime);
139
144 const std::vector<WsfSA_EntityPerception*>& PerceivedAircraftBogies(double aSimTime);
145
150 const std::vector<WsfSA_EntityPerception*>& PerceivedMissileBogies(double aSimTime);
151
156 const std::vector<WsfSA_EntityPerception*>& PerceivedBandits(double aSimTime);
157
162 const std::vector<WsfSA_EntityPerception*>& PerceivedAircraftBandits(double aSimTime);
163
168 const std::vector<WsfSA_EntityPerception*>& PerceivedMissileBandits(double aSimTime);
169
174 WsfLocalTrack* PerceivedThreat(WsfStringId aTargetNameId);
175
180 WsfLocalTrack* PerceivedThreat(const WsfTrackId& aTrackId);
181
185 bool PossibleEnemy(WsfLocalTrack* aTrackPtr);
186
190 bool ProcessInput(UtInput& aInput);
191
196 bool ProcessMessage(double aSimTime, const WsfMessage& aMessage);
197
202 void Initialize(double aSimTime);
203
204 // Asset functions --------------------------------------------------------------------------------------
205
209 void SetMaxAssetLoad(int aLoad) { mDataPtr->mMaxAssetLoad = aLoad; }
210
212 void ResetMaxAssetLoad() { mDataPtr->mMaxAssetLoad = mDataPtr->mMaxAssetLoadInitial; }
213
219 bool AssetScore(double aSimTime, WsfSA_EntityPerception* aEntityPtr, double& aScore);
220
221 // Returns true if the entity is contained in the current asset list
222 bool EntityIsInAssetGroup(const WsfSA_EntityPerception* aEntity) const;
223
224 // Returns true if the entity index is contained in the current asset list
225 bool EntityIsInAssetGroup(size_t aEntityIndex) const;
226
227 // Purges old assets based on lifetime
228 void PurgeOldAssets(double aSimTime);
229
234 WsfSA_EntityPerception* NearestAsset(double aSimTime);
235
240 WsfSA_EntityPerception* NearestAircraftAsset(double aSimTime);
241
246 WsfSA_EntityPerception* NearestMissileAsset(double aSimTime);
247
248 // Threat (Bogie and Bandit) functions ------------------------------------------------------------------
249
253 void SetMaxThreatLoad(int aLoad) { mDataPtr->mMaxThreatLoad = aLoad; }
254
256 void ResetMaxThreatLoad() { mDataPtr->mMaxThreatLoad = mDataPtr->mMaxThreatLoadInitial; }
257
264 bool ThreatScore(double aSimTime, WsfLocalTrack* aThreatPtr, bool aIsMissile, double& aScore);
265
270 double DefaultThreatScore(double aSimTime, WsfSA_PerceivedItem* aThreatPtr);
271
275 WsfSA_EntityPerception* NearestBogie() const;
276
280 WsfSA_EntityPerception* NearestAircraftBogie() const;
281
285 WsfSA_EntityPerception* NearestMissileBogie() const;
286
290 WsfSA_EntityPerception* NearestBandit() const;
291
295 WsfSA_EntityPerception* NearestAircraftBandit() const;
296
300 WsfSA_EntityPerception* NearestMissileBandit() const;
301
302 // Miscellaneous functions ------------------------------------------------------------------------------
303
306 std::set<WsfPlatform*> TruthAssets();
307
309
311 std::string SelectedWeaponName() const;
312
314 const WsfExplicitWeapon* SelectedWeapon() const;
315
317 int QuantityOfSelectedWeapon() const;
318
322 bool SetSelectedWeapon(const std::string& aWeaponName);
323
325 const std::vector<WsfExplicitWeapon*> GetWeaponList() const { return mDataPtr->mWeaponList; }
326
330 void SetMasterArm(bool aArmed);
331
333 bool GetMasterArm() const;
334
336 bool MasterWarningActive() const;
337
339 bool MasterCautionActive() const;
340
342 bool WeaponBayDoorsAreOpen() const;
343
345 bool ShootCueActive() const;
346
348 bool ShootCueBlinking() const;
349
351 bool JammingDetected() const;
352
356 void SetMasterWarningActive(bool aActive);
357
361 void SetMasterCautionActive(bool aActive);
362
366 void SetWeaponBayDoorsAreOpen(bool aOpen);
367
371 void SetShootCueActive(bool aActive);
372
376 void SetShootCueBlinking(bool aBlinking);
377
381 void SetJammingDetected(bool aJammingDetected);
382
384
386 bool EngagedTargetValid() const { return mDataPtr->mEngagedTarget.isValid; }
387
390
395 {
396 mDataPtr->mEngagedTarget = aEngagedTarget;
397 }
398
400
402 int QuantityOfChaff() const;
403
405 int QuantityOfFlares() const;
406
408 int QuantityOfDecoys() const;
409
411 bool DispenseChaff(double aSimTime);
412
414 bool DispenseFlare(double aSimTime);
415
417 bool DispenseDecoy(double aSimTime);
418
419 // Group functions
420
426 bool RenameGroup(WsfSA_Group* aGroup, const std::string& aName);
427
437 WsfSA_Group* CreateGroup(const std::list<WsfSA_EntityPerception*>& aElements, bool aProtect = false);
438
448 bool DisbandGroup(WsfSA_Group* aGroup, bool aProtect = false);
449
460 WsfSA_Group* MergeGroups(const std::list<WsfSA_Group*>& aGroups, bool aProtect = false);
461
474 std::pair<WsfSA_Group*, WsfSA_Group*>
475 SplitGroup(WsfSA_Group* aGroup, int aNumElements, int aCriterion, bool aProtect = false);
476
488 bool TransferEntity(WsfSA_EntityPerception* aEntity, WsfSA_Group* aGroup, bool aProtect = false);
489
497 bool RemoveEntityFromGroup(WsfSA_EntityPerception* aEntity, bool aProtect = false);
498
507 bool SetFocus(WsfSA_Group* aGroup, bool aFocus, bool aProtect = false);
508
515 void SetImportant(WsfSA_PerceivedItem* aItem, bool aIsImportant);
516
521 bool GetFocus(WsfSA_Group* aGroup);
522
527 bool GetImportant(WsfSA_PerceivedItem* aItem);
528
529protected:
530 WsfSA_Perceive(const WsfSA_Perceive& aSrc);
531
535 WsfSA_EntityPerception* NearestEntity(const std::vector<WsfSA_EntityPerception*>& aDataList) const;
536
540 bool Important(WsfLocalTrack* aThreatPtr);
541
545 bool Important(WsfPlatform* aAssetPtr);
546
550 bool Important(size_t aPlatformIndex);
551
555 bool Unimportant(WsfLocalTrack* aThreatPtr);
556
560 bool Unimportant(WsfPlatform* aAssetPtr);
561
565 bool Unimportant(size_t aPlatformIndex);
566
571 void LocalTrackDropped(double aSimTime, const WsfLocalTrack* aLocalTrackPtr);
572
576 double TryUpdateStatus(double aSimTime);
577
582 double TryUpdateAssets(double aSimTime);
583
588 double TryUpdatePerceivedItemData(double aSimTime);
589
595 double TryUpdatePerceivedItemCalculation(double aSimTime);
596
600 double UpdateStatus(double aSimTime);
601
605 void UpdateAssets(double aSimTime);
606
610 void UpdateAssetsData(double aSimTime);
611
616 void UpdateGroupsData(double aSimTime);
617
621 void UpdatePerceivedItemsCalculation(double aSimTime);
622
624 void RemoveAnyInvalidEntitiesInBogiesAndBandits();
625
629 void Prune(double aSimTime);
630
632 void FindExpenableCountermeasures();
633
635 void FindWeapons();
636
643 void CreateAssetsList(double aSimTime, std::list<WsfSA_EntityPerception*>& aTempAssetsList, bool aUnlimitedAssets);
644
652 void CreateBanditsList(double aSimTime, std::list<WsfSA_EntityPerception*>& aTrackedEntitiesList, bool aUnlimitedBandits);
653
661 void CreateBogiesList(double aSimTime, std::list<WsfSA_EntityPerception*>& aTrackedEntitiesList, bool aUnlimitedBogies);
662
668 double GetThreatScore(double aSimTime, WsfSA_EntityPerception* aThreatPtr, bool aIsMissile);
669
671 void CreateAssetSublists();
672
674 void CreateSublists();
675
682 void RemoveExpiredCoastingPerceptions(std::vector<WsfSA_EntityPerception*>& aPerceptionList,
683 double aCoastTime,
684 double aSimTime);
685
686 void SetOldPerceptionsAsCoasting(const std::vector<WsfSA_EntityPerception*>& aPerceptionList, double aSimTime);
687
697 void UpdateCoastingPerceptions(const std::vector<WsfSA_EntityPerception*>& aPerceptionList,
698 const std::list<WsfSA_EntityPerception*>& aNewPerceptionList,
699 double aSimTime);
700
708 void AddOrUpdatePerception(std::vector<WsfSA_EntityPerception*>& aPerceptionList,
709 WsfSA_EntityPerception& aPerception,
710 double aSimTime);
711
719 void JoinInitialGroups(std::vector<WsfSA_EntityPerception*>& aPerceptionList,
720 std::list<WsfSA_Group*>& aGroupList,
721 double aSimTime);
722
727 void DropEntity(WsfSA_EntityPerception* aOldEntity);
728
733 void DeleteLater(WsfSA_EntityPerception* aOldEntity);
734
736 void DeferredDelete();
737
738private:
739 std::list<WsfSA_EntityPerception*> mDeferredForDeletion;
740
741 double mConsiderationRandomness{0.0};
742
743 std::default_random_engine mRandom{};
747 struct TrackDelayData
748 {
749 double mTimeAdded;
750 bool mIsVisual;
751 bool mIsDone;
752 };
757 std::unordered_map<WsfTrackId, TrackDelayData, WsfTrackId> mTrackDelayQueue;
758
759 // Groups data
760 // ......................................................................................................................
761
762 WsfSA_GroupManager mGroupManager;
763
764 double mMaxGroupingDistanceCentroid{8.0 * UtMath::cM_PER_NM};
765 double mMaxGroupingDistanceNeighbor{4.0 * UtMath::cM_PER_NM};
766 double mMaxGroupingHeadingDifference{10.0 * UtMath::cRAD_PER_DEG};
767 double mMaxGroupingSpeedDifference{100.0};
768 double mMinGroupRadius{1.0 * UtMath::cM_PER_NM};
769 bool mUseCentroidGrouping{true};
770 bool mUseNeighborGrouping{true};
771 bool mUseHeadingGrouping{true};
772 bool mUseSpeedGrouping{true};
773 bool mUseTypeGrouping{false};
774 bool mIgnoreBogiesWhenGrouping{false};
775};
776
777#endif
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
A specialization of WsfWeapon for weapons modeled as separate platforms.
Definition WsfExplicitWeapon.hpp:30
Definition WsfLocalTrack.hpp:32
A base class for messages sent among simulation communication objects, processors and sensors.
Definition WsfMessage.hpp:33
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
Definition WsfSA_EntityPerception.hpp:37
Definition WsfSA_Group.hpp:24
WsfSA_Processor::PerceiveData * mDataPtr
Perceived data container used by multiple SAP classes and lives in the SA Processor.
Definition WsfSA_Module.hpp:56
WsfSA_Module(WsfSA_Processor *aSA_ProcPtr, WsfSA_Processor::PerceiveData *aDataPtr)
Definition WsfSA_Module.cpp:14
This is the perceive module of the SA Processor.
Definition WsfSA_Perceive.hpp:31
WsfSA_Perceive(WsfSA_Processor *aSA_ProcPtr, WsfSA_Processor::PerceiveData *aDataPtr)
Definition WsfSA_Perceive.cpp:32
void SetEngagedTarget(const WsfSA_Processor::SA_EngagedTarget &aEngagedTarget)
Sets the engaged target using the specified engaged target data.
Definition WsfSA_Perceive.hpp:394
void AddExtraCognitiveLoading(double aTimeDelay)
Add a cognitive loading time (delay).
Definition WsfSA_Perceive.cpp:63
void SetMaxAssetLoad(int aLoad)
Set the max asset load.
Definition WsfSA_Perceive.hpp:209
WsfSA_Perceive & operator=(const WsfSA_Perceive &)=delete
const std::vector< WsfExplicitWeapon * > GetWeaponList() const
Returns the current list of weapons.
Definition WsfSA_Perceive.hpp:325
friend class WsfSA_Processor
Definition WsfSA_Perceive.hpp:33
RecipientType
Definition WsfSA_Perceive.hpp:37
@ cPEERS
Definition WsfSA_Perceive.hpp:39
@ cALLSUBORDINATES
Definition WsfSA_Perceive.hpp:42
@ cSUBORDINATES
Definition WsfSA_Perceive.hpp:40
@ cALLCOMMANDERS
Definition WsfSA_Perceive.hpp:41
@ cCOMMANDER
Definition WsfSA_Perceive.hpp:38
void MarkThreatTypeAsImportant(const std::string &aType)
Mark a threat type as important.
Definition WsfSA_Perceive.cpp:287
friend class WsfSA_ProcessorUpdateEvent
Definition WsfSA_Perceive.hpp:34
void MarkAssetAsImportant(WsfPlatform &aAsset)
Mark an asset as important.
Definition WsfSA_Perceive.cpp:241
void SetMaxThreatLoad(int aLoad)
Set the max asset load.
Definition WsfSA_Perceive.hpp:253
int MaxAssetLoad()
Return the max asset load the platform can handle.
Definition WsfSA_Perceive.hpp:105
bool EngagedTargetValid() const
These functions provide data related to the primary target being engaged.
Definition WsfSA_Perceive.hpp:386
void MarkAssetAsUnimportant(WsfPlatform &aAsset)
Mark an asset as unimportant.
Definition WsfSA_Perceive.cpp:252
void MarkAssetTypeAsImportant(const std::string &aType)
Mark an asset type as important.
Definition WsfSA_Perceive.cpp:263
void ResetMaxAssetLoad()
Set the max asset load to the value provided during initialization (default is -1 where not provided)...
Definition WsfSA_Perceive.hpp:212
void ResetMaxThreatLoad()
Set the max threat load to the value provided during initialization (default is -1 where not provided...
Definition WsfSA_Perceive.hpp:256
void MarkAssetTypeAsUnimportant(const std::string &aType)
Mark an asset type as unimportant.
Definition WsfSA_Perceive.cpp:269
WsfSA_Processor::SA_EngagedTarget GetEngagedTarget() const
Returns an EngagedTarget struct for the primary engaged target.
Definition WsfSA_Perceive.hpp:389
void MarkThreatTypeAsUnimportant(const std::string &aType)
Mark a threat type as unimportant.
Definition WsfSA_Perceive.cpp:293
void MarkThreatAsUnimportant(WsfLocalTrack &aThreat)
Mark a threat as unimportant.
Definition WsfSA_Perceive.cpp:281
int MaxThreatLoad()
Return the max threat load the platform can handle.
Definition WsfSA_Perceive.hpp:108
void MarkThreatAsImportant(WsfLocalTrack &aThreat)
Mark a threat as important.
Definition WsfSA_Perceive.cpp:275
The WsfSA_PerceivedItem class is used as a base class for WsfSA_EntityPerception and WsfSA_Group,...
Definition WsfSA_PerceivedItem.hpp:38
Definition WsfSA_Processor.hpp:60
Definition WsfTrackId.hpp:33
Definition WsfSA_Processor.hpp:86
Definition WsfSA_Processor.hpp:69
Copyrights Multiple, All Rights Reserved