2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma hdrstop
|
|
|
|
#include "../../idlib/precompiled.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "AAS_local.h"
|
|
|
|
|
|
|
|
#define SUBSAMPLE_WALK_PATH 1
|
|
|
|
#define SUBSAMPLE_FLY_PATH 0
|
|
|
|
|
|
|
|
const int maxWalkPathIterations = 10;
|
|
|
|
const float maxWalkPathDistance = 500.0f;
|
|
|
|
const float walkPathSampleDistance = 8.0f;
|
|
|
|
|
|
|
|
const int maxFlyPathIterations = 10;
|
|
|
|
const float maxFlyPathDistance = 500.0f;
|
|
|
|
const float flyPathSampleDistance = 8.0f;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::EdgeSplitPoint
|
|
|
|
|
|
|
|
calculates split point of the edge with the plane
|
|
|
|
returns true if the split point is between the edge vertices
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAASLocal::EdgeSplitPoint( idVec3& split, int edgeNum, const idPlane& plane ) const
|
|
|
|
{
|
|
|
|
const aasEdge_t* edge;
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 v1, v2;
|
|
|
|
float d1, d2;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
edge = &file->GetEdge( edgeNum );
|
|
|
|
v1 = file->GetVertex( edge->vertexNum[0] );
|
|
|
|
v2 = file->GetVertex( edge->vertexNum[1] );
|
|
|
|
d1 = v1 * plane.Normal() - plane.Dist();
|
|
|
|
d2 = v2 * plane.Normal() - plane.Dist();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//if ( (d1 < CM_CLIP_EPSILON && d2 < CM_CLIP_EPSILON) || (d1 > -CM_CLIP_EPSILON && d2 > -CM_CLIP_EPSILON) ) {
|
2012-11-28 15:47:07 +00:00
|
|
|
if( IEEE_FLT_SIGNBITSET( d1 ) == IEEE_FLT_SIGNBITSET( d2 ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
split = v1 + ( d1 / ( d1 - d2 ) ) * ( v2 - v1 );
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::FloorEdgeSplitPoint
|
|
|
|
|
|
|
|
calculates either the closest or furthest point on the floor of the area which also lies on the pathPlane
|
|
|
|
the point has to be on the front side of the frontPlane to be valid
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAASLocal::FloorEdgeSplitPoint( idVec3& bestSplit, int areaNum, const idPlane& pathPlane, const idPlane& frontPlane, bool closest ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, j, faceNum, edgeNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
const aasArea_t* area;
|
|
|
|
const aasFace_t* face;
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 split;
|
|
|
|
float dist, bestDist;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( closest )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bestDist = maxWalkPathDistance;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bestDist = -0.1f;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
area = &file->GetArea( areaNum );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < area->numFaces; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
faceNum = file->GetFaceIndex( area->firstFace + i );
|
2012-11-28 15:47:07 +00:00
|
|
|
face = &file->GetFace( abs( faceNum ) );
|
|
|
|
|
|
|
|
if( !( face->flags & FACE_FLOOR ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( j = 0; j < face->numEdges; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
edgeNum = file->GetEdgeIndex( face->firstEdge + j );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !EdgeSplitPoint( split, abs( edgeNum ), pathPlane ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dist = frontPlane.Distance( split );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( closest )
|
|
|
|
{
|
|
|
|
if( dist >= -0.1f && dist < bestDist )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bestDist = dist;
|
|
|
|
bestSplit = split;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( dist > bestDist )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bestDist = dist;
|
|
|
|
bestSplit = split;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( closest )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( bestDist < maxWalkPathDistance );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( bestDist > -0.1f );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::WalkPathValid
|
|
|
|
|
|
|
|
returns true if one can walk in a straight line between origin and goalOrigin
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAASLocal::WalkPathValid( int areaNum, const idVec3& origin, int goalAreaNum, const idVec3& goalOrigin, int travelFlags, idVec3& endPos, int& endAreaNum ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int curAreaNum, lastAreaNum, lastAreas[4], lastAreaIndex;
|
|
|
|
idPlane pathPlane, frontPlane, farPlane;
|
2012-11-28 15:47:07 +00:00
|
|
|
idReachability* reach;
|
|
|
|
const aasArea_t* area;
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 p, dir;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( file == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
endPos = goalOrigin;
|
|
|
|
endAreaNum = 0;
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
lastAreas[0] = lastAreas[1] = lastAreas[2] = lastAreas[3] = areaNum;
|
|
|
|
lastAreaIndex = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
pathPlane.SetNormal( ( goalOrigin - origin ).Cross( file->GetSettings().gravityDir ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
pathPlane.Normalize();
|
|
|
|
pathPlane.FitThroughPoint( origin );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
frontPlane.SetNormal( goalOrigin - origin );
|
|
|
|
frontPlane.Normalize();
|
|
|
|
frontPlane.FitThroughPoint( origin );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
farPlane.SetNormal( frontPlane.Normal() );
|
|
|
|
farPlane.FitThroughPoint( goalOrigin );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
curAreaNum = areaNum;
|
|
|
|
lastAreaNum = curAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// find the furthest floor face split point on the path
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !FloorEdgeSplitPoint( endPos, curAreaNum, pathPlane, frontPlane, false ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
endPos = origin;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if we found a point near or further than the goal we're done
|
2012-11-28 15:47:07 +00:00
|
|
|
if( farPlane.Distance( endPos ) > -0.5f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if we reached the goal area we're done
|
2012-11-28 15:47:07 +00:00
|
|
|
if( curAreaNum == goalAreaNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
frontPlane.SetDist( frontPlane.Normal() * endPos );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
area = &file->GetArea( curAreaNum );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( reach = area->reach; reach; reach = reach->next )
|
|
|
|
{
|
|
|
|
if( reach->travelType != TFL_WALK )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if the reachability goes back to a previous area
|
2012-11-28 15:47:07 +00:00
|
|
|
if( reach->toAreaNum == lastAreas[0] || reach->toAreaNum == lastAreas[1] ||
|
|
|
|
reach->toAreaNum == lastAreas[2] || reach->toAreaNum == lastAreas[3] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// if undesired travel flags are required to travel through the area
|
2012-11-28 15:47:07 +00:00
|
|
|
if( file->GetArea( reach->toAreaNum ).travelFlags & ~travelFlags )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// don't optimize through an area near a ledge
|
2012-11-28 15:47:07 +00:00
|
|
|
if( file->GetArea( reach->toAreaNum ).flags & AREA_LEDGE )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// find the closest floor face split point on the path
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !FloorEdgeSplitPoint( p, reach->toAreaNum, pathPlane, frontPlane, true ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// direction parallel to gravity
|
|
|
|
dir = ( file->GetSettings().gravityDir * endPos * file->GetSettings().gravityDir ) -
|
2012-11-28 15:47:07 +00:00
|
|
|
( file->GetSettings().gravityDir * p * file->GetSettings().gravityDir );
|
|
|
|
if( dir.LengthSqr() > Square( file->GetSettings().maxStepHeight ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// direction orthogonal to gravity
|
|
|
|
dir = endPos - p - dir;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( dir.LengthSqr() > Square( 0.2f ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !reach )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
lastAreas[lastAreaIndex] = curAreaNum;
|
|
|
|
lastAreaIndex = ( lastAreaIndex + 1 ) & 3;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
curAreaNum = reach->toAreaNum;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
endAreaNum = curAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::SubSampleWalkPath
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 idAASLocal::SubSampleWalkPath( int areaNum, const idVec3& origin, const idVec3& start, const idVec3& end, int travelFlags, int& endAreaNum ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, numSamples, curAreaNum;
|
|
|
|
idVec3 dir, point, nextPoint, endPos;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
dir = end - start;
|
2012-11-28 15:47:07 +00:00
|
|
|
numSamples = ( int )( dir.Length() / walkPathSampleDistance ) + 1;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
point = start;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 1; i < numSamples; i++ )
|
|
|
|
{
|
|
|
|
nextPoint = start + dir * ( ( float ) i / numSamples );
|
|
|
|
if( ( point - nextPoint ).LengthSqr() > Square( maxWalkPathDistance ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return point;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !idAASLocal::WalkPathValid( areaNum, origin, 0, nextPoint, travelFlags, endPos, curAreaNum ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return point;
|
|
|
|
}
|
|
|
|
point = nextPoint;
|
|
|
|
endAreaNum = curAreaNum;
|
|
|
|
}
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::WalkPathToGoal
|
|
|
|
|
|
|
|
FIXME: don't stop optimizing on first failure ?
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAASLocal::WalkPathToGoal( aasPath_t& path, int areaNum, const idVec3& origin, int goalAreaNum, const idVec3& goalOrigin, int travelFlags ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, travelTime, curAreaNum, lastAreas[4], lastAreaIndex, endAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
idReachability* reach = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 endPos;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
path.type = PATHTYPE_WALK;
|
|
|
|
path.moveGoal = origin;
|
|
|
|
path.moveAreaNum = areaNum;
|
|
|
|
path.secondaryGoal = origin;
|
|
|
|
path.reachability = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( file == NULL || areaNum == goalAreaNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
path.moveGoal = goalOrigin;
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
lastAreas[0] = lastAreas[1] = lastAreas[2] = lastAreas[3] = areaNum;
|
|
|
|
lastAreaIndex = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
curAreaNum = areaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < maxWalkPathIterations; i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !idAASLocal::RouteToGoalArea( curAreaNum, path.moveGoal, goalAreaNum, travelFlags, travelTime, &reach ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !reach )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// no need to check through the first area
|
2012-11-28 15:47:07 +00:00
|
|
|
if( areaNum != curAreaNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// only optimize a limited distance ahead
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ( reach->start - origin ).LengthSqr() > Square( maxWalkPathDistance ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
#if SUBSAMPLE_WALK_PATH
|
|
|
|
path.moveGoal = SubSampleWalkPath( areaNum, origin, path.moveGoal, reach->start, travelFlags, path.moveAreaNum );
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !idAASLocal::WalkPathValid( areaNum, origin, 0, reach->start, travelFlags, endPos, endAreaNum ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
#if SUBSAMPLE_WALK_PATH
|
|
|
|
path.moveGoal = SubSampleWalkPath( areaNum, origin, path.moveGoal, reach->start, travelFlags, path.moveAreaNum );
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
path.moveGoal = reach->start;
|
|
|
|
path.moveAreaNum = curAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( reach->travelType != TFL_WALK )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !idAASLocal::WalkPathValid( areaNum, origin, 0, reach->end, travelFlags, endPos, endAreaNum ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
path.moveGoal = reach->end;
|
|
|
|
path.moveAreaNum = reach->toAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( reach->toAreaNum == goalAreaNum )
|
|
|
|
{
|
|
|
|
if( !idAASLocal::WalkPathValid( areaNum, origin, 0, goalOrigin, travelFlags, endPos, endAreaNum ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
#if SUBSAMPLE_WALK_PATH
|
|
|
|
path.moveGoal = SubSampleWalkPath( areaNum, origin, path.moveGoal, goalOrigin, travelFlags, path.moveAreaNum );
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
path.moveGoal = goalOrigin;
|
|
|
|
path.moveAreaNum = goalAreaNum;
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
lastAreas[lastAreaIndex] = curAreaNum;
|
|
|
|
lastAreaIndex = ( lastAreaIndex + 1 ) & 3;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
curAreaNum = reach->toAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( curAreaNum == lastAreas[0] || curAreaNum == lastAreas[1] ||
|
|
|
|
curAreaNum == lastAreas[2] || curAreaNum == lastAreas[3] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Warning( "idAASLocal::WalkPathToGoal: local routing minimum going from area %d to area %d", areaNum, goalAreaNum );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( reach == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
switch( reach->travelType )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
case TFL_WALKOFFLEDGE:
|
|
|
|
path.type = PATHTYPE_WALKOFFLEDGE;
|
|
|
|
path.secondaryGoal = reach->end;
|
|
|
|
path.reachability = reach;
|
|
|
|
break;
|
|
|
|
case TFL_BARRIERJUMP:
|
|
|
|
path.type |= PATHTYPE_BARRIERJUMP;
|
|
|
|
path.secondaryGoal = reach->end;
|
|
|
|
path.reachability = reach;
|
|
|
|
break;
|
|
|
|
case TFL_JUMP:
|
|
|
|
path.type |= PATHTYPE_JUMP;
|
|
|
|
path.secondaryGoal = reach->end;
|
|
|
|
path.reachability = reach;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::FlyPathValid
|
|
|
|
|
|
|
|
returns true if one can fly in a straight line between origin and goalOrigin
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAASLocal::FlyPathValid( int areaNum, const idVec3& origin, int goalAreaNum, const idVec3& goalOrigin, int travelFlags, idVec3& endPos, int& endAreaNum ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
aasTrace_t trace;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( file == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
endPos = goalOrigin;
|
|
|
|
endAreaNum = 0;
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
file->Trace( trace, origin, goalOrigin );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
endPos = trace.endpos;
|
|
|
|
endAreaNum = trace.lastAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( trace.fraction >= 1.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::SubSampleFlyPath
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 idAASLocal::SubSampleFlyPath( int areaNum, const idVec3& origin, const idVec3& start, const idVec3& end, int travelFlags, int& endAreaNum ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, numSamples, curAreaNum;
|
|
|
|
idVec3 dir, point, nextPoint, endPos;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
dir = end - start;
|
2012-11-28 15:47:07 +00:00
|
|
|
numSamples = ( int )( dir.Length() / flyPathSampleDistance ) + 1;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
point = start;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 1; i < numSamples; i++ )
|
|
|
|
{
|
|
|
|
nextPoint = start + dir * ( ( float ) i / numSamples );
|
|
|
|
if( ( point - nextPoint ).LengthSqr() > Square( maxFlyPathDistance ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return point;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !idAASLocal::FlyPathValid( areaNum, origin, 0, nextPoint, travelFlags, endPos, curAreaNum ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return point;
|
|
|
|
}
|
|
|
|
point = nextPoint;
|
|
|
|
endAreaNum = curAreaNum;
|
|
|
|
}
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::FlyPathToGoal
|
|
|
|
|
|
|
|
FIXME: don't stop optimizing on first failure ?
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idAASLocal::FlyPathToGoal( aasPath_t& path, int areaNum, const idVec3& origin, int goalAreaNum, const idVec3& goalOrigin, int travelFlags ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, travelTime, curAreaNum, lastAreas[4], lastAreaIndex, endAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
idReachability* reach = NULL;
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 endPos;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
path.type = PATHTYPE_WALK;
|
|
|
|
path.moveGoal = origin;
|
|
|
|
path.moveAreaNum = areaNum;
|
|
|
|
path.secondaryGoal = origin;
|
|
|
|
path.reachability = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( file == NULL || areaNum == goalAreaNum )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
path.moveGoal = goalOrigin;
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
lastAreas[0] = lastAreas[1] = lastAreas[2] = lastAreas[3] = areaNum;
|
|
|
|
lastAreaIndex = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
curAreaNum = areaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < maxFlyPathIterations; i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !idAASLocal::RouteToGoalArea( curAreaNum, path.moveGoal, goalAreaNum, travelFlags, travelTime, &reach ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !reach )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// no need to check through the first area
|
2012-11-28 15:47:07 +00:00
|
|
|
if( areaNum != curAreaNum )
|
|
|
|
{
|
|
|
|
if( ( reach->start - origin ).LengthSqr() > Square( maxFlyPathDistance ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
#if SUBSAMPLE_FLY_PATH
|
|
|
|
path.moveGoal = SubSampleFlyPath( areaNum, origin, path.moveGoal, reach->start, travelFlags, path.moveAreaNum );
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !idAASLocal::FlyPathValid( areaNum, origin, 0, reach->start, travelFlags, endPos, endAreaNum ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
#if SUBSAMPLE_FLY_PATH
|
|
|
|
path.moveGoal = SubSampleFlyPath( areaNum, origin, path.moveGoal, reach->start, travelFlags, path.moveAreaNum );
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
path.moveGoal = reach->start;
|
|
|
|
path.moveAreaNum = curAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !idAASLocal::FlyPathValid( areaNum, origin, 0, reach->end, travelFlags, endPos, endAreaNum ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
path.moveGoal = reach->end;
|
|
|
|
path.moveAreaNum = reach->toAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( reach->toAreaNum == goalAreaNum )
|
|
|
|
{
|
|
|
|
if( !idAASLocal::FlyPathValid( areaNum, origin, 0, goalOrigin, travelFlags, endPos, endAreaNum ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
#if SUBSAMPLE_FLY_PATH
|
|
|
|
path.moveGoal = SubSampleFlyPath( areaNum, origin, path.moveGoal, goalOrigin, travelFlags, path.moveAreaNum );
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
path.moveGoal = goalOrigin;
|
|
|
|
path.moveAreaNum = goalAreaNum;
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
lastAreas[lastAreaIndex] = curAreaNum;
|
|
|
|
lastAreaIndex = ( lastAreaIndex + 1 ) & 3;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
curAreaNum = reach->toAreaNum;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( curAreaNum == lastAreas[0] || curAreaNum == lastAreas[1] ||
|
|
|
|
curAreaNum == lastAreas[2] || curAreaNum == lastAreas[3] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
common->Warning( "idAASLocal::FlyPathToGoal: local routing minimum going from area %d to area %d", areaNum, goalAreaNum );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( reach == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
typedef struct wallEdge_s
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int edgeNum;
|
|
|
|
int verts[2];
|
2012-11-28 15:47:07 +00:00
|
|
|
struct wallEdge_s* next;
|
2012-11-26 18:58:24 +00:00
|
|
|
} wallEdge_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::SortWallEdges
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idAASLocal::SortWallEdges( int* edges, int numEdges ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, j, k, numSequences;
|
2012-11-28 15:47:07 +00:00
|
|
|
wallEdge_t** sequenceFirst, **sequenceLast, *wallEdges, *wallEdge;
|
|
|
|
|
|
|
|
wallEdges = ( wallEdge_t* ) _alloca16( numEdges * sizeof( wallEdge_t ) );
|
|
|
|
sequenceFirst = ( wallEdge_t** )_alloca16( numEdges * sizeof( wallEdge_t* ) );
|
|
|
|
sequenceLast = ( wallEdge_t** )_alloca16( numEdges * sizeof( wallEdge_t* ) );
|
|
|
|
|
|
|
|
for( i = 0; i < numEdges; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
wallEdges[i].edgeNum = edges[i];
|
|
|
|
GetEdgeVertexNumbers( edges[i], wallEdges[i].verts );
|
|
|
|
wallEdges[i].next = NULL;
|
|
|
|
sequenceFirst[i] = &wallEdges[i];
|
|
|
|
sequenceLast[i] = &wallEdges[i];
|
|
|
|
}
|
|
|
|
numSequences = numEdges;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < numSequences; i++ )
|
|
|
|
{
|
|
|
|
for( j = i + 1; j < numSequences; j++ )
|
|
|
|
{
|
|
|
|
if( sequenceFirst[i]->verts[0] == sequenceLast[j]->verts[1] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sequenceLast[j]->next = sequenceFirst[i];
|
|
|
|
sequenceFirst[i] = sequenceFirst[j];
|
|
|
|
break;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( sequenceLast[i]->verts[1] == sequenceFirst[j]->verts[0] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
sequenceLast[i]->next = sequenceFirst[j];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( j < numSequences )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
numSequences--;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( k = j; k < numSequences; k++ )
|
|
|
|
{
|
|
|
|
sequenceFirst[k] = sequenceFirst[k + 1];
|
|
|
|
sequenceLast[k] = sequenceLast[k + 1];
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
i = -1;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
k = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( i = 0; i < numSequences; i++ )
|
|
|
|
{
|
|
|
|
for( wallEdge = sequenceFirst[i]; wallEdge; wallEdge = wallEdge->next )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
edges[k++] = wallEdge->edgeNum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
idAASLocal::GetWallEdges
|
|
|
|
============
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
int idAASLocal::GetWallEdges( int areaNum, const idBounds& bounds, int travelFlags, int* edges, int maxEdges ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int i, j, k, l, face1Num, face2Num, edge1Num, edge2Num, numEdges, absEdge1Num;
|
2012-11-28 15:47:07 +00:00
|
|
|
int* areaQueue, curArea, queueStart, queueEnd;
|
|
|
|
byte* areasVisited;
|
|
|
|
const aasArea_t* area;
|
|
|
|
const aasFace_t* face1, *face2;
|
|
|
|
idReachability* reach;
|
|
|
|
|
|
|
|
if( !file )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
numEdges = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
areasVisited = ( byte* ) _alloca16( file->GetNumAreas() );
|
2012-11-26 18:58:24 +00:00
|
|
|
memset( areasVisited, 0, file->GetNumAreas() * sizeof( byte ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
areaQueue = ( int* ) _alloca16( file->GetNumAreas() * sizeof( int ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
queueStart = -1;
|
|
|
|
queueEnd = 0;
|
|
|
|
areaQueue[0] = areaNum;
|
|
|
|
areasVisited[areaNum] = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( curArea = areaNum; queueStart < queueEnd; curArea = areaQueue[++queueStart] )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
area = &file->GetArea( curArea );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( i = 0; i < area->numFaces; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
face1Num = file->GetFaceIndex( area->firstFace + i );
|
2012-11-28 15:47:07 +00:00
|
|
|
face1 = &file->GetFace( abs( face1Num ) );
|
|
|
|
|
|
|
|
if( !( face1->flags & FACE_FLOOR ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( j = 0; j < face1->numEdges; j++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
edge1Num = file->GetEdgeIndex( face1->firstEdge + j );
|
|
|
|
absEdge1Num = abs( edge1Num );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// test if the edge is shared by another floor face of this area
|
2012-11-28 15:47:07 +00:00
|
|
|
for( k = 0; k < area->numFaces; k++ )
|
|
|
|
{
|
|
|
|
if( k == i )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
face2Num = file->GetFaceIndex( area->firstFace + k );
|
2012-11-28 15:47:07 +00:00
|
|
|
face2 = &file->GetFace( abs( face2Num ) );
|
|
|
|
|
|
|
|
if( !( face2->flags & FACE_FLOOR ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
for( l = 0; l < face2->numEdges; l++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
edge2Num = abs( file->GetEdgeIndex( face2->firstEdge + l ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
if( edge2Num == absEdge1Num )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( l < face2->numEdges )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( k < area->numFaces )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// test if the edge is used by a reachability
|
2012-11-28 15:47:07 +00:00
|
|
|
for( reach = area->reach; reach; reach = reach->next )
|
|
|
|
{
|
|
|
|
if( reach->travelType & travelFlags )
|
|
|
|
{
|
|
|
|
if( reach->edgeNum == absEdge1Num )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( reach )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// test if the edge is already in the list
|
2012-11-28 15:47:07 +00:00
|
|
|
for( k = 0; k < numEdges; k++ )
|
|
|
|
{
|
|
|
|
if( edge1Num == edges[k] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( k < numEdges )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// add the edge to the list
|
|
|
|
edges[numEdges++] = edge1Num;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( numEdges >= maxEdges )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return numEdges;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// add new areas to the queue
|
2012-11-28 15:47:07 +00:00
|
|
|
for( reach = area->reach; reach; reach = reach->next )
|
|
|
|
{
|
|
|
|
if( reach->travelType & travelFlags )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// if the area the reachability leads to hasn't been visited yet and the area bounds touch the search bounds
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !areasVisited[reach->toAreaNum] && bounds.IntersectsBounds( file->GetArea( reach->toAreaNum ).bounds ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
areaQueue[queueEnd++] = reach->toAreaNum;
|
|
|
|
areasVisited[reach->toAreaNum] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return numEdges;
|
|
|
|
}
|