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.
This commit is contained in:
Azaezel 2014-07-11 06:58:19 -05:00
parent 8aebb67aa1
commit ae55ad2b50
2 changed files with 44 additions and 21 deletions

View file

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

View file

@ -80,9 +80,9 @@ public:
void setAimLocation( const Point3F &location ); void setAimLocation( const Point3F &location );
Point3F getAimLocation() const { return mAimLocation; } Point3F getAimLocation() const { return mAimLocation; }
void clearAim(); void clearAim();
bool checkInLos(GameBase* target, bool _checkEnabled); bool checkInLos(GameBase* target = NULL, bool _useMuzzle = false, bool _checkEnabled = false);
bool checkLosClear(Point3F _pos); 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 // Movement sets/gets
void setMoveSpeed( const F32 speed ); void setMoveSpeed( const F32 speed );