Browse Source

aiinfo subclass inheritance cleanups, and default constructor removals for safeties

AzaezelX 5 months ago
parent
commit
c72c3068f8

+ 2 - 1
Engine/source/T3D/AI/AIAimTarget.h

@@ -23,7 +23,7 @@
 #define _AIAIMTARGET_H_
 
 #include "AIInfo.h"
-struct AIAimTarget : AIInfo
+struct AIAimTarget : public AIInfo
 {
    typedef AIInfo Parent;
    Point3F mAimOffset;
@@ -32,6 +32,7 @@ struct AIAimTarget : AIInfo
    bool checkInLos(SceneObject* target = NULL, bool _useMuzzle = false, bool _checkEnabled = false);
    bool checkInFoV(SceneObject* target = NULL, F32 camFov = 45.0f, bool _checkEnabled = false);
    F32 getTargetDistance(SceneObject* target, bool _checkEnabled);
+   AIAimTarget() = delete;
    AIAimTarget(AIController* controller) : Parent(controller) { mTargetInLOS = false; };
    AIAimTarget(AIController* controller, SimObjectPtr<SceneObject> objIn, F32 radIn) : Parent(controller, objIn, radIn) { mTargetInLOS = false; };
    AIAimTarget(AIController* controller, Point3F pointIn, F32 radIn) : Parent(controller, pointIn, radIn) { mTargetInLOS = false; };

+ 43 - 1
Engine/source/T3D/AI/AIController.cpp

@@ -64,6 +64,48 @@ bool AIController::setControllerDataProperty(void* obj, const char* index, const
    return false;
 }
 
+void AIController::setGoal(AIInfo* targ)
+{
+   if (mGoal) { delete(mGoal); mGoal = NULL; }
+
+   if (targ->mObj.isValid())
+   {
+      delete(mGoal);
+      mGoal = new AIGoal(this, targ->mObj, targ->mRadius);
+   }
+   else if (targ->mPosSet)
+   {
+      delete(mGoal);
+      mGoal = new AIGoal(this, targ->mPosition, targ->mRadius);
+   }
+}
+
+void AIController::setGoal(Point3F loc, F32 rad)
+{
+   if (mGoal) delete(mGoal);
+   mGoal = new AIGoal(this, loc, rad);
+}
+
+void AIController::setGoal(SimObjectPtr<SceneObject> objIn, F32 rad)
+{
+   if (mGoal) delete(mGoal);
+   mGoal = new AIGoal(this, objIn, rad);
+}
+
+void AIController::setAim(Point3F loc, F32 rad, Point3F offset)
+{
+   if (mAimTarget) delete(mAimTarget);
+   mAimTarget = new AIAimTarget(this, loc, rad);
+   mAimTarget->mAimOffset = offset;
+}
+
+void AIController::setAim(SimObjectPtr<SceneObject> objIn, F32 rad, Point3F offset)
+{
+   if (mAimTarget) delete(mAimTarget);
+   mAimTarget = new AIAimTarget(this, objIn, rad);
+   mAimTarget->mAimOffset = offset;
+}
+
 #ifdef TORQUE_NAVIGATION_ENABLED
 bool AIController::getAIMove(Move* movePtr)
 {
@@ -89,7 +131,7 @@ bool AIController::getAIMove(Move* movePtr)
          {
             if (getGoal()->mObj.isValid())
                getNav()->followObject(getGoal()->mObj, mControllerData->mFollowTolerance);
-            else
+            else if (getGoal()->mPosSet)
                getNav()->setPathDestination(getGoal()->getPosition());
          }
       }

+ 5 - 5
Engine/source/T3D/AI/AIController.h

@@ -55,16 +55,16 @@ public:
 private:
    AIGoal* mGoal;
 public:
-   void setGoal(AIInfo* targ) { mGoal = (targ) ? new AIGoal(this, targ->getPosition(), targ->mRadius) : NULL; }
-   void setGoal(Point3F loc, F32 rad = 0.0f) { delete(mGoal); mGoal = new AIGoal(this, loc, rad); }
-   void setGoal(SimObjectPtr<SceneObject> objIn, F32 rad = 0.0f) { delete(mGoal); mGoal = new AIGoal(this, objIn, rad); }
+   void setGoal(AIInfo* targ);
+   void setGoal(Point3F loc, F32 rad = 0.0f);
+   void setGoal(SimObjectPtr<SceneObject> objIn, F32 rad = 0.0f);
    AIGoal* getGoal() { return mGoal; }
    void clearGoal() { SAFE_DELETE(mGoal); }
 private:
    AIAimTarget* mAimTarget;
 public:
-   void setAim(Point3F loc, F32 rad = 0.0f, Point3F offset = Point3F(0.0f,0.0f,0.0f)) { delete(mAimTarget);  mAimTarget = new AIAimTarget(this, loc, rad); mAimTarget->mAimOffset = offset; }
-   void setAim(SimObjectPtr<SceneObject> objIn, F32 rad = 0.0f, Point3F offset = Point3F(0.0f, 0.0f, 0.0f)) { delete(mAimTarget); mAimTarget = new AIAimTarget(this, objIn, rad); mAimTarget->mAimOffset = offset; }
+   void setAim(Point3F loc, F32 rad = 0.0f, Point3F offset = Point3F(0.0f, 0.0f, 0.0f));
+   void setAim(SimObjectPtr<SceneObject> objIn, F32 rad = 0.0f, Point3F offset = Point3F(0.0f, 0.0f, 0.0f));
    AIAimTarget* getAim() { return mAimTarget; }
    void clearAim() { SAFE_DELETE(mAimTarget); }
 private:

+ 2 - 1
Engine/source/T3D/AI/AICover.h

@@ -27,11 +27,12 @@
 
 
 
-struct AICover : AIInfo
+struct AICover : public AIInfo
 {
    typedef AIInfo Parent;
    /// Pointer to a cover point.
    SimObjectPtr<CoverPoint> mCoverPoint;
+   AICover() = delete;
    AICover(AIController* controller) : Parent(controller) {};
    AICover(AIController* controller, SimObjectPtr<SceneObject> objIn, F32 radIn) : Parent(controller, objIn, radIn) { mCoverPoint = dynamic_cast<CoverPoint*>(objIn.getPointer());};
    AICover(AIController* controller, Point3F pointIn, F32 radIn) : Parent(controller, pointIn, radIn) {};

+ 2 - 1
Engine/source/T3D/AI/AIGoal.h

@@ -24,9 +24,10 @@
 
 #include "AIInfo.h"
 
-struct AIGoal : AIInfo
+struct AIGoal : public AIInfo
 {
    typedef AIInfo Parent;
+   AIGoal() = delete;
    AIGoal(AIController* controller): Parent(controller) {};
    AIGoal(AIController* controller, SimObjectPtr<SceneObject> objIn, F32 radIn) : Parent(controller, objIn, radIn) {};
    AIGoal(AIController* controller, Point3F pointIn, F32 radIn) : Parent(controller, pointIn, radIn) {};

+ 9 - 4
Engine/source/T3D/AI/AINavigation.cpp

@@ -64,6 +64,7 @@ NavMesh* AINavigation::findNavMesh() const
 void AINavigation::updateNavMesh()
 {
    GameBase* gbo = dynamic_cast<GameBase*>(mControllerRef->getAIInfo()->mObj.getPointer());
+   NavMesh* old = mNavMesh;
    if (mNavMesh.isNull())
       mNavMesh = findNavMesh();
    else
@@ -72,9 +73,9 @@ void AINavigation::updateNavMesh()
          mNavMesh = findNavMesh();
    }
    // See if we need to update our path.
-   if (mNavMesh)
+   if (mNavMesh != old && !mPathData.path.isNull())
    {
-      setPathDestination(getCtrl()->getGoal()->getPosition());
+      setPathDestination(mPathData.path->mTo);
    }
 }
 
@@ -175,7 +176,11 @@ void AINavigation::onReachDestination()
 
 bool AINavigation::setPathDestination(const Point3F& pos)
 {
-   if (!getCtrl()->getGoal()) getCtrl()->setGoal(pos, getCtrl()->mControllerData->mMoveTolerance);
+   AIGoal* curgoal = getCtrl()->getGoal();
+
+   if (!curgoal || !curgoal->mObj.isValid())
+      getCtrl()->setGoal(pos, getCtrl()->mControllerData->mMoveTolerance);
+
    if (!mNavMesh)
       updateNavMesh();
    // If we can't find a mesh, just move regularly.
@@ -191,7 +196,7 @@ bool AINavigation::setPathDestination(const Point3F& pos)
 
    path->mMesh = mNavMesh;
    path->mFrom = getCtrl()->getAIInfo()->getPosition();
-   path->mTo = pos;
+   path->mTo = getCtrl()->getGoal()->getPosition();
    path->mFromSet = path->mToSet = true;
    path->mAlwaysRender = true;
    path->mLinkTypes = getCtrl()->mControllerData->mLinkTypes;