2010-01-29 22:13:18 +01:00
|
|
|
/* Copyright (C) 2010 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_ICMPPATHFINDER
|
|
|
|
#define INCLUDED_ICMPPATHFINDER
|
|
|
|
|
|
|
|
#include "simulation2/system/Interface.h"
|
|
|
|
|
2010-03-18 00:01:12 +01:00
|
|
|
#include "simulation2/helpers/Position.h"
|
2010-01-29 22:13:18 +01:00
|
|
|
|
2010-04-30 01:36:05 +02:00
|
|
|
#include "maths/FixedVector2D.h"
|
|
|
|
|
2010-03-28 20:21:48 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2010-04-30 01:36:05 +02:00
|
|
|
class IObstructionTestFilter;
|
|
|
|
|
2010-01-29 22:13:18 +01:00
|
|
|
/**
|
2010-04-30 01:36:05 +02:00
|
|
|
* Pathfinder algorithms.
|
|
|
|
*
|
|
|
|
* There are two different modes: a tile-based pathfinder that works over long distances and
|
|
|
|
* accounts for terrain costs but ignore units, and a 'short' vertex-based pathfinder that
|
|
|
|
* provides precise paths and avoids other units.
|
2010-01-29 22:13:18 +01:00
|
|
|
*
|
2010-04-30 01:36:05 +02:00
|
|
|
* Both use the same concept of a Goal: either a point, circle or square.
|
|
|
|
* (If the starting point is inside the goal shape then the path will move outwards
|
|
|
|
* to reach the shape's outline.)
|
2010-01-29 22:13:18 +01:00
|
|
|
*
|
2010-04-30 01:36:05 +02:00
|
|
|
* The output is a list of waypoints.
|
2010-01-29 22:13:18 +01:00
|
|
|
*/
|
|
|
|
class ICmpPathfinder : public IComponent
|
|
|
|
{
|
|
|
|
public:
|
2010-02-06 21:58:48 +01:00
|
|
|
struct Goal
|
|
|
|
{
|
2010-04-30 01:36:05 +02:00
|
|
|
enum {
|
|
|
|
POINT,
|
|
|
|
CIRCLE,
|
|
|
|
SQUARE
|
|
|
|
} type;
|
|
|
|
entity_pos_t x, z; // position of center
|
|
|
|
CFixedVector2D u, v; // if SQUARE, then orthogonal unit axes
|
|
|
|
entity_pos_t hw, hh; // if SQUARE, then half width & height; if CIRCLE, then hw is radius
|
2010-02-06 21:58:48 +01:00
|
|
|
};
|
|
|
|
|
2010-01-29 22:13:18 +01:00
|
|
|
struct Waypoint
|
|
|
|
{
|
|
|
|
entity_pos_t x, z;
|
|
|
|
};
|
|
|
|
|
2010-01-30 14:11:58 +01:00
|
|
|
/**
|
|
|
|
* Returned path.
|
|
|
|
* Waypoints are in *reverse* order (the earliest is at the back of the list)
|
|
|
|
*/
|
2010-01-29 22:13:18 +01:00
|
|
|
struct Path
|
|
|
|
{
|
|
|
|
std::vector<Waypoint> m_Waypoints;
|
|
|
|
};
|
|
|
|
|
2010-01-30 14:11:58 +01:00
|
|
|
/**
|
2010-04-30 01:36:05 +02:00
|
|
|
* Compute a tile-based path from the given point to the goal, and return the set of waypoints.
|
|
|
|
* The waypoints correspond to the centers of horizontally/vertically adjacent tiles
|
|
|
|
* along the path.
|
2010-01-30 14:11:58 +01:00
|
|
|
*/
|
2010-04-30 01:36:05 +02:00
|
|
|
virtual void ComputePath(entity_pos_t x0, entity_pos_t z0, const Goal& goal, Path& ret) = 0;
|
2010-01-30 14:11:58 +01:00
|
|
|
|
|
|
|
/**
|
2010-04-30 01:36:05 +02:00
|
|
|
* If the debug overlay is enabled, render the path that will computed by ComputePath.
|
2010-01-30 14:11:58 +01:00
|
|
|
*/
|
2010-04-30 01:36:05 +02:00
|
|
|
virtual void SetDebugPath(entity_pos_t x0, entity_pos_t z0, const Goal& goal) = 0;
|
2010-01-30 14:11:58 +01:00
|
|
|
|
2010-01-29 22:13:18 +01:00
|
|
|
/**
|
2010-04-30 01:36:05 +02:00
|
|
|
* Compute a precise path from the given point to the goal, and return the set of waypoints.
|
|
|
|
* The path is based on the full set of obstructions that pass the filter, such that
|
|
|
|
* a unit of radius 'r' will be able to follow the path with no collisions.
|
|
|
|
* The path is restricted to a box of radius 'range' from the starting point.
|
2010-01-29 22:13:18 +01:00
|
|
|
*/
|
2010-04-30 01:36:05 +02:00
|
|
|
virtual void ComputeShortPath(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t r, entity_pos_t range, const Goal& goal, Path& ret) = 0;
|
2010-01-29 22:13:18 +01:00
|
|
|
|
2010-03-20 20:18:01 +01:00
|
|
|
/**
|
|
|
|
* Toggle the storage and rendering of debug info.
|
|
|
|
*/
|
|
|
|
virtual void SetDebugOverlay(bool enabled) = 0;
|
|
|
|
|
2010-01-29 22:13:18 +01:00
|
|
|
DECLARE_INTERFACE_TYPE(Pathfinder)
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDED_ICMPPATHFINDER
|