123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #include "pch.h"
- #include "ObjectWithinRadiusCondition.h"
- #include "TypeIDTarget.h"
- namespace Training
- {
-
-
-
- ObjectWithinRadiusCondition::ObjectWithinRadiusCondition (ImodelIGC* pObject, ImodelIGC* pTarget, float fRadius) :
- m_pObject (new TypeIDTarget (pObject->GetObjectType (), pObject->GetObjectID ())),
- m_pTarget (new TypeIDTarget (pTarget->GetObjectType (), pTarget->GetObjectID ())),
- m_fRadiusSquared (fRadius),
- m_bConditionInitialized (false)
- {
- }
-
- ObjectWithinRadiusCondition::ObjectWithinRadiusCondition (ImodelIGC* pObject, ObjectType targetType, ObjectID targetID, float fRadius) :
- m_pObject (new TypeIDTarget (pObject->GetObjectType (), pObject->GetObjectID ())),
- m_pTarget (new TypeIDTarget (targetType, targetID)),
- m_fRadiusSquared (fRadius),
- m_bConditionInitialized (false)
- {
- }
-
- ObjectWithinRadiusCondition::ObjectWithinRadiusCondition (ImodelIGC* pObject, AbstractTarget* pTarget, float fRadius) :
- m_pObject (new TypeIDTarget (pObject->GetObjectType (), pObject->GetObjectID ())),
- m_pTarget (pTarget),
- m_fRadiusSquared (fRadius),
- m_bConditionInitialized (false)
- {
- }
-
- ObjectWithinRadiusCondition::ObjectWithinRadiusCondition (ObjectType objectType, ObjectID objectID, ObjectType targetType, ObjectID targetID, float fRadius) :
- m_pObject (new TypeIDTarget (objectType, objectID)),
- m_pTarget (new TypeIDTarget (targetType, targetID)),
- m_fRadiusSquared (fRadius),
- m_bConditionInitialized (false)
- {
- }
-
- ObjectWithinRadiusCondition::~ObjectWithinRadiusCondition (void)
- {
- delete m_pObject;
- delete m_pTarget;
- }
-
- bool ObjectWithinRadiusCondition::Evaluate (void)
- {
- if (Initialized ())
- {
-
-
-
-
- assert (*m_pObject and *m_pTarget);
- if (*m_pObject and *m_pTarget)
- {
-
-
-
- Vector delta = (*m_pObject)->GetPosition () - (*m_pTarget)->GetPosition ();
- float fLengthSquared = delta.LengthSquared ();
- return (fLengthSquared > m_fRadiusSquared) ? false : true;
- }
- }
- return false;
- }
-
- float ObjectWithinRadiusCondition::GetRadarRadius (void) const
- {
-
- const_cast<ObjectWithinRadiusCondition*> (this) ->Initialized ();
-
-
-
- return m_bConditionInitialized ? sqrtf (m_fRadiusSquared) : (*m_pObject)->GetRadius () + m_fRadiusSquared;
- }
-
- bool ObjectWithinRadiusCondition::Initialized (void)
- {
- if (not m_bConditionInitialized)
- {
-
- if (*m_pTarget)
- {
-
-
- m_fRadiusSquared += (*m_pObject)->GetRadius () + (*m_pTarget)->GetRadius ();
- m_fRadiusSquared *= m_fRadiusSquared;
- m_bConditionInitialized = true;
- }
- }
- return m_bConditionInitialized;
- }
-
- }
|