Explorar o código

revised checkInLos and CheckFoV. boith now take all parameters as optional as suggested, with a target value of NULL resulting in checking the present one.
cleaned up internal usage of checkInLos, tightened the typemask used, and provided further documentation.

Azaezel %!s(int64=11) %!d(string=hai) anos
pai
achega
ae55ad2b50
Modificáronse 2 ficheiros con 44 adicións e 21 borrados
  1. 42 19
      Engine/source/T3D/aiPlayer.cpp
  2. 2 2
      Engine/source/T3D/aiPlayer.h

+ 42 - 19
Engine/source/T3D/aiPlayer.cpp

@@ -29,8 +29,7 @@
 #include "console/engineAPI.h"
 
 static U32 sAIPlayerLoSMask = TerrainObjectType | WaterObjectType |
-                              ShapeBaseObjectType | StaticShapeObjectType | 
-                              PlayerObjectType | ItemObjectType;
+                              ShapeBaseObjectType | StaticShapeObjectType;
 
 IMPLEMENT_CO_NETOBJECT_V1(AIPlayer);
 
@@ -423,13 +422,15 @@ bool AIPlayer::getAIMove(Move *movePtr)
    // which is not very accurate.
    if (mAimObject)
    {
-      mTargetInLOS = checkInLos(mAimObject.getPointer(), false);
-      if (mTargetInLOS)
+      if (checkInLos(mAimObject.getPointer()))
       {
-         throwCallback("onTargetEnterLOS");
-         mTargetInLOS = true;
+         if (!mTargetInLOS)
+         {
+            throwCallback("onTargetEnterLOS");
+            mTargetInLOS = true;
+         }
       }
-      else
+      else if (mTargetInLOS)
       {
          throwCallback("onTargetExitLOS");
          mTargetInLOS = false;
@@ -605,11 +606,16 @@ DefineEngineMethod( AIPlayer, getAimObject, S32, (),,
 	GameBase* obj = object->getAimObject();
    return obj? obj->getId(): -1;
 }
- 
-bool AIPlayer::checkInLos(GameBase* target, bool _checkEnabled = false)
+
+bool AIPlayer::checkInLos(GameBase* target, bool _useMuzzle, bool _checkEnabled)
 {
    if (!isServerObject()) return false;
-   if (!(bool(target))) return false;
+   if (!(bool(target)))
+   {
+      target = mAimObject.getPointer();
+      if (!(bool(target)))
+         return false;
+   }
    if (_checkEnabled)
    {
       ShapeBase *shapeBaseCheck = dynamic_cast<ShapeBase *>(target);
@@ -626,9 +632,18 @@ bool AIPlayer::checkInLos(GameBase* target, bool _checkEnabled = false)
    {
       target->getMountedObject(i)->disableCollision();
    }
-   Point3F muzzlePoint;
-   getMuzzlePointAI(0, &muzzlePoint);
-   bool hit = gServerContainer.castRay(muzzlePoint, target->getBoxCenter(), sAIPlayerLoSMask, &ri);
+
+   Point3F checkPoint ;
+   if (_useMuzzle)
+      getMuzzlePointAI(0, &checkPoint );
+   else
+   {
+      MatrixF eyeMat;
+      getEyeTransform(&eyeMat);
+      eyeMat.getColumn(3, &checkPoint );
+   }
+
+   bool hit = gServerContainer.castRay(checkPoint , target->getBoxCenter(), sAIPlayerLoSMask, &ri);
    enableCollision();
 
    for (S32 i = 0; i < mountCount; i++)
@@ -644,6 +659,7 @@ bool AIPlayer::checkInLos(GameBase* target, bool _checkEnabled = false)
    return hit;
 }
 
+
 bool AIPlayer::checkLosClear(Point3F _pos)
 {
    if (!isServerObject()) return false;
@@ -660,13 +676,17 @@ bool AIPlayer::checkLosClear(Point3F _pos)
    return emptySpace;
 }
 
-DefineEngineMethod(AIPlayer, checkInLos, bool, (ShapeBase* obj, bool checkEnabled), (0, false),
-   "@brief Check for an object in line of sight.\n")
+DefineEngineMethod(AIPlayer, checkInLos, bool, (ShapeBase* obj,  bool useMuzzle, bool checkEnabled),(NULL, false, false),
+   "@brief Check for an object in line of sight.\n"
+   "@obj Object to check. if blank it will check the current target.\n"
+   "@useMuzzle Use muzzle position (otherwise use eye position).\n"
+   "@checkEnabled check if the object is not disabled.\n")
 {
-   return object->checkInLos(obj, checkEnabled);
+   return object->checkInLos(obj, useMuzzle, checkEnabled);
 }
 
-bool AIPlayer::checkInFoV(GameBase* target, F32 camFov, bool _checkEnabled = false)
+
+bool AIPlayer::checkInFoV(GameBase* target, F32 camFov, bool _checkEnabled)
 {
    if (!isServerObject()) return false;
    if (!(bool(target))) return false;
@@ -700,8 +720,11 @@ bool AIPlayer::checkInFoV(GameBase* target, F32 camFov, bool _checkEnabled = fal
    return (dot > camFov);
 }
 
-DefineEngineMethod(AIPlayer, checkInFoV, bool, (ShapeBase* obj, F32 fov, bool checkEnabled), (0, 45, false),
-   "@brief Check for an object within a specified veiw cone.\n")
+DefineEngineMethod(AIPlayer, checkInFoV, bool, (ShapeBase* obj, F32 fov, bool checkEnabled), (NULL, 45.0f, false),
+   "@brief Check for an object within a specified veiw cone.\n"
+   "@obj Object to check. if blank it will check the current target.\n"
+   "@fov view angle (in degrees)\n"
+   "@checkEnabled check if the object is not disabled.\n")
 {
    return object->checkInFoV(obj, fov, checkEnabled);
 }

+ 2 - 2
Engine/source/T3D/aiPlayer.h

@@ -80,9 +80,9 @@ public:
    void setAimLocation( const Point3F &location );
    Point3F getAimLocation() const { return mAimLocation; }
    void clearAim();
-   bool checkInLos(GameBase* target, bool _checkEnabled);
+   bool checkInLos(GameBase* target = NULL, bool _useMuzzle = false, bool _checkEnabled = false);
    bool checkLosClear(Point3F _pos);
-   bool checkInFoV(GameBase* target, F32 camFov, bool _checkEnabled);
+   bool checkInFoV(GameBase* target = NULL, F32 camFov = 45.0f, bool _checkEnabled = false);
 
    // Movement sets/gets
    void setMoveSpeed( const F32 speed );