2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2006-05-13 20:50:58 +02:00
|
|
|
#include "Profile.h"
|
2006-04-19 07:30:02 +02:00
|
|
|
|
2006-05-13 20:50:58 +02:00
|
|
|
#include "EntityOrders.h"
|
|
|
|
#include "Entity.h"
|
2004-05-29 05:32:33 +02:00
|
|
|
#include "PathfindEngine.h"
|
2006-04-11 00:05:21 +02:00
|
|
|
|
2004-07-23 12:56:52 +02:00
|
|
|
|
|
|
|
CPathfindEngine::CPathfindEngine()
|
|
|
|
{
|
|
|
|
}
|
2004-05-29 05:32:33 +02:00
|
|
|
|
|
|
|
void CPathfindEngine::requestPath( HEntity entity, const CVector2D& destination )
|
|
|
|
{
|
2006-04-09 02:36:52 +02:00
|
|
|
/* TODO: Add code to generate high level path
|
|
|
|
For now, just the one high level waypoint to the final
|
|
|
|
destination is added
|
|
|
|
*/
|
|
|
|
CEntityOrder waypoint;
|
|
|
|
waypoint.m_type = CEntityOrder::ORDER_GOTO_WAYPOINT;
|
|
|
|
waypoint.m_data[0].location = destination;
|
|
|
|
entity->m_orderQueue.push_front( waypoint );
|
|
|
|
}
|
|
|
|
|
2006-04-11 00:05:21 +02:00
|
|
|
void CPathfindEngine::requestLowLevelPath( HEntity entity, const CVector2D& destination, bool contact )
|
2006-04-09 02:36:52 +02:00
|
|
|
{
|
2006-05-13 20:50:58 +02:00
|
|
|
PROFILE_START("Pathfinding");
|
2006-04-11 00:05:21 +02:00
|
|
|
|
2006-05-13 20:50:58 +02:00
|
|
|
CVector2D source( entity->m_position.X, entity->m_position.Z );
|
2006-04-11 00:05:21 +02:00
|
|
|
|
2006-05-13 20:50:58 +02:00
|
|
|
if ( mLowPathfinder.findPath(source, destination, entity->m_player) )
|
2006-04-11 00:05:21 +02:00
|
|
|
{
|
2006-05-13 20:50:58 +02:00
|
|
|
std::vector<CVector2D> path = mLowPathfinder.getLastPath();
|
2006-05-14 00:11:46 +02:00
|
|
|
if( path.size() > 0 )
|
2006-04-11 00:05:21 +02:00
|
|
|
{
|
2006-05-14 00:11:46 +02:00
|
|
|
std::vector<CVector2D>::iterator it;
|
|
|
|
CEntityOrder node;
|
|
|
|
for( it = path.begin(); (it+1) != path.end(); it++ )
|
2006-04-11 00:05:21 +02:00
|
|
|
{
|
2006-05-14 00:11:46 +02:00
|
|
|
if ( !contact )
|
|
|
|
{
|
|
|
|
node.m_type = CEntityOrder::ORDER_GOTO_NOPATHING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: Is this right?
|
|
|
|
node.m_type = CEntityOrder::ORDER_GOTO_NOPATHING;
|
|
|
|
}
|
|
|
|
node.m_data[0].location = *it;
|
|
|
|
entity->m_orderQueue.push_back(node);
|
2006-04-11 00:05:21 +02:00
|
|
|
}
|
2006-05-14 00:11:46 +02:00
|
|
|
node.m_type = CEntityOrder::ORDER_PATH_END_MARKER;
|
2006-05-13 20:50:58 +02:00
|
|
|
node.m_data[0].location = *it;
|
|
|
|
entity->m_orderQueue.push_back(node);
|
2006-04-11 00:05:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If no path was found, then unsolvable
|
|
|
|
// TODO: Figure out what to do in this case
|
|
|
|
}
|
|
|
|
|
2006-05-13 20:50:58 +02:00
|
|
|
PROFILE_END("Pathfinding");
|
2004-06-02 18:11:32 +02:00
|
|
|
}
|
2004-11-11 08:09:32 +01:00
|
|
|
|
2005-12-29 09:42:44 +01:00
|
|
|
void CPathfindEngine::requestContactPath( HEntity entity, CEntityOrder* current )
|
2004-11-11 08:09:32 +01:00
|
|
|
{
|
2006-04-11 00:05:21 +02:00
|
|
|
/* TODO: Same as non-contact: need high-level planner */
|
|
|
|
CEntityOrder waypoint;
|
|
|
|
waypoint.m_type = CEntityOrder::ORDER_GOTO_WAYPOINT_CONTACT;
|
|
|
|
waypoint.m_data[0].location = current->m_data[0].entity->m_position;
|
|
|
|
entity->m_orderQueue.push_front( waypoint );
|
|
|
|
|
|
|
|
//pathSparse( entity, current->m_data[0].entity->m_position );
|
|
|
|
//// For attack orders, do some additional postprocessing (replace goto/nopathing
|
|
|
|
//// with attack/nopathing, up until the attack order marker)
|
|
|
|
//std::deque<CEntityOrder>::iterator it;
|
|
|
|
//for( it = entity->m_orderQueue.begin(); it != entity->m_orderQueue.end(); it++ )
|
|
|
|
//{
|
|
|
|
// if( it->m_type == CEntityOrder::ORDER_PATH_END_MARKER )
|
|
|
|
// break;
|
|
|
|
// if( it->m_type == CEntityOrder::ORDER_GOTO_NOPATHING )
|
|
|
|
// {
|
|
|
|
// *it = *current;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
}
|