/**
 *	Bind any waypoints with external references to the given chunk
 */
void WaypointSet::bind( WaypointChunk & achunk )
{
	Waypoints::iterator wit;
	Waypoint* pWaypoint;

	for(wit = waypoints_.begin(); wit != waypoints_.end(); wit++)
	{
		pWaypoint = *wit;
		if (pWaypoint == NULL) continue;

		int vc = pWaypoint->vertexCount();
		for (int i = 0; i < vc; i++)
		{
			if (pWaypoint->adjacentChunkID(i) == achunk.chunkID())
			{
				// find what waypoint set it should connect to
				Vector2 midPos = (pWaypoint->vertexPosition(i) +
					pWaypoint->vertexPosition((i+1)%vc)) * 0.5f;
				Vector3 lookPos( midPos[0], pWaypoint->height(), midPos[1] );
				WPSpec wpspec;
				if (!achunk.findEnclosingWaypoint( lookPos, wpspec ) &&
					!achunk.findClosestWaypoint( lookPos, wpspec ))
				{
					WARNING_MSG( "Waypoint %lu in chunk %s set %d "
						"can find no set in chunk %s for edge %d\n",
						pWaypoint->id(),
						chunk_.chunkID().c_str(),
						setNum_,
						achunk.chunkID().c_str(),
						i );
				}
				else
				{
					pWaypoint->adjacentWaypointSet( i, wpspec.pWPSet );
				}
			}
		}
	}

	adjacentSetsCurrent_ = false;
}
void FvWaypointSet::Bind( FvWaypointZone &kAZone )
{
	Waypoints::iterator wit;
	FvWaypoint* pWaypoint;

	for(wit = m_kWaypoints.begin(); wit != m_kWaypoints.end(); wit++)
	{
		pWaypoint = *wit;
		if (pWaypoint == NULL) continue;

		int vc = pWaypoint->VertexCount();
		for (int i = 0; i < vc; i++)
		{
			if (pWaypoint->AdjacentZoneID(i) == kAZone.GetZoneID())
			{
				FvVector2 midPos = (pWaypoint->VertexPosition(i) +
					pWaypoint->VertexPosition((i+1)%vc)) * 0.5f;
				FvVector3 lookPos( midPos[0], pWaypoint->Height(), midPos[1] );
				FvWPSpec wpspec;
				if (!kAZone.FindEnclosingWaypoint( lookPos, wpspec ) &&
					!kAZone.FindClosestWaypoint( lookPos, wpspec ))
				{
					FV_WARNING_MSG( "Waypoint %lu in zone %s set %d "
						"can find no set in zone %s for edge %d\n",
						pWaypoint->GetID(),
						m_kZone.GetZoneID().c_str(),
						m_iSetNum,
						kAZone.GetZoneID().c_str(),
						i );
				}
				else
				{
					pWaypoint->AdjacentWaypointSet( i, wpspec.pWPSet );
				}
			}
		}
	}

	m_bAdjacentSetsCurrent = false;
}