diff --git a/Engine/source/T3D/AI/AIAimTarget.cpp b/Engine/source/T3D/AI/AIAimTarget.cpp index 35c7d927e..86ea7145b 100644 --- a/Engine/source/T3D/AI/AIAimTarget.cpp +++ b/Engine/source/T3D/AI/AIAimTarget.cpp @@ -194,7 +194,9 @@ DefineEngineMethod(AIController, getAimObject, S32, (), , "@see setAimObject()\n") { - SceneObject* obj = dynamic_cast(object->getAim()->mObj.getPointer()); + SceneObject* obj = NULL; + if (object->getAim()) + obj = dynamic_cast(object->getAim()->mObj.getPointer()); return obj ? obj->getId() : -1; } diff --git a/Engine/source/T3D/AI/AIController.cpp b/Engine/source/T3D/AI/AIController.cpp index 8ace880f1..d38eb4bfd 100644 --- a/Engine/source/T3D/AI/AIController.cpp +++ b/Engine/source/T3D/AI/AIController.cpp @@ -70,7 +70,12 @@ bool AIController::setControllerDataProperty(void* obj, const char* index, const void AIController::setGoal(AIInfo* targ) { - if (mGoal) { delete(mGoal); mGoal = NULL; } + if (mGoal) + { + if (mGoal->mObj.isValid() && targ->mObj.isValid() && mGoal->mObj == targ->mObj) + return; + delete(mGoal); mGoal = NULL; + } if (targ->mObj.isValid()) { @@ -86,26 +91,58 @@ void AIController::setGoal(AIInfo* targ) void AIController::setGoal(Point3F loc, F32 rad) { - if (mGoal) delete(mGoal); + if (mGoal) + { + if (mGoal->mPosSet && mGoal->getPosition() == loc) + { + mGoal->mRadius = rad; + return; + } + delete(mGoal); + } mGoal = new AIGoal(this, loc, rad); } void AIController::setGoal(SimObjectPtr objIn, F32 rad) { - if (mGoal) delete(mGoal); + if (mGoal) + { + if (mGoal->mObj.isValid() && objIn.isValid() && mGoal->mObj == objIn) + { + mGoal->mRadius = rad; + return; + } + delete(mGoal); + } mGoal = new AIGoal(this, objIn, rad); } void AIController::setAim(Point3F loc, F32 rad, Point3F offset) { - if (mAimTarget) delete(mAimTarget); + if (mAimTarget) + { + if (mAimTarget->mPosSet && mAimTarget->getPosition() == loc) + { + mAimTarget->mAimOffset = offset; + return; + } + delete(mAimTarget); + } mAimTarget = new AIAimTarget(this, loc, rad); mAimTarget->mAimOffset = offset; } void AIController::setAim(SimObjectPtr objIn, F32 rad, Point3F offset) { - if (mAimTarget) delete(mAimTarget); + if (mAimTarget) + { + if (mAimTarget->mObj.isValid() && objIn.isValid() && mAimTarget->mObj == objIn) + { + mAimTarget->mAimOffset = offset; + return; + } + delete(mAimTarget); + } mAimTarget = new AIAimTarget(this, objIn, rad); mAimTarget->mAimOffset = offset; }