This is mostly in reply to the following thread which is now too old for me to reply directly to it: http://www.mmowned.com/forums/wow-me...tersect-2.html
I've put together the following implementation:
Code:
#define ADDR_TRACELINE 0x0077D1A0
enum eHitType {
HIT_NONE = 0x0,
HIT_GROUND = 0x1,
HIT_OBJECT = 0x2,
};
#define HIT_LOS 0x100171
unsigned char CActions::TraceLine(WOWPOS &pEnd, WOWPOS &pStart, WOWPOS &pResult, float &fDistance)
{
typedef unsigned char (__cdecl* tTraceLine)(WOWPOS &pointEnd, WOWPOS &pointStart, WOWPOS &pointResult, float &pDistance, unsigned int dwFlag, unsigned int uiOptional);
tTraceLine oTraceLine = (tTraceLine)ADDR_TRACELINE;
return oTraceLine(pEnd, pStart, pResult, fDistance, HIT_LOS, 0);
}
With the following use case:
Code:
bool CSpellMgr::HasLineOfSight(sSpell * pSpell, WOWPOS * pPos)
{
if( pSpell )
{
// If the spell has no range... true of self-cast spells
if( pSpell->uiMinRange == 0 && pSpell->uiMaxRange == 0 )
return true;
WOWPOS posMe;
gpBot->GetCurMgr()->GetLocalPlayer()->GetPosition( &posMe );
posMe.Facing = gpBot->GetCurMgr()->GetLocalPlayer()->GetFacing();
// Increase our z-axis (height) so we check from top of head, not bottom of feet
posMe.Z += gpBot->GetCurMgr()->GetLocalPlayer()->GetHeight();
DBGLOG( "My Position X: " << posMe.X << ", Y: " << posMe.Y << ", Z: " << posMe.Z );
if( pPos == NULL )
{
CGUnit_C * target = gpBot->GetCurMgr()->GetCurrentTarget();
if( target == NULL )
{
DBGLOG( "[HasLineOfSight] Spell Check for '" << pSpell->sName << "' attempted but no target!!!" );
return false;
}
pPos = new WOWPOS();
target->GetPosition( pPos );
pPos->Facing = target->GetFacing();
// Increase target's z-axis (height) so we check from top of our head to their's
//DBGLOG( "Target's Height: " << target->GetHeight() );
pPos->Z += target->GetHeight();
DBGLOG( "Target Position X: " << pPos->X << ", Y: " << pPos->Y << ", Z: " << pPos->Z );
}
WOWPOS posResult;
float fDistance;
eHitType hitResult = (eHitType)gpBot->GetActions()->TraceLine( *pPos, posMe, posResult, fDistance );
DBGLOG( "[HasLineOfSight] 0x" << std::hex << hitResult << std::dec << " " << fDistance << " yards away!" );
DBGLOG( "[HasLineOfSight] pResult X: " << posResult.X << ", Y: " << posResult.Y << ", Z: " << posResult.Z );
if( HIT_NONE == hitResult )
{
return true;
}
else if( HIT_OBJECT == hitResult )
{
//DBGLOG( "[HasLineOfSight] Check failed due to hitting an object " << fDistance << " yards away!" );
return false;
}
else if( HIT_GROUND == hitResult )
{
//DBGLOG( "[HasLineOfSight] Check failed due to hitting the ground " << fDistance << " yards away!" );
return false;
}
else
{
//DBGLOG( "[HasLineOfSight] Check failed due to 0x" << std::hex << hitResult << std::dec << " " << fDistance << " yards away!" );
return false;
}
}
return false;
}
When casting at a target behind a wall of a building I get the following log message:
Code:
[696901184] :: My Position X: 1923.74, Y: 1546.27, Z: 89.3905
[696901184] :: Target Position X: 1939.89, Y: 1545.96, Z: 92.1927
[696901184] :: [HasLineOfSight] 0x0 2.40741E-035 yards away!
[696901184] :: [HasLineOfSight] pResult X: 0, Y: 0, Z: 0
[696901184] :: Casting: CastSpellByName("Immolate") [Rank 1]
[696901376] :: [EVENT]: 'UI_ERROR_MESSAGE' 'Target not in line of sight'
So clearly something isn't working. Any chance for some help?