2025-04-26 08:48:41 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2010-01-29 13:13:18 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-01-29 13:13:18 -08:00
|
|
|
* 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.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-01-29 13:13:18 -08:00
|
|
|
* 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
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-29 13:13:18 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef INCLUDED_ICMPPATHFINDER
|
|
|
|
|
#define INCLUDED_ICMPPATHFINDER
|
|
|
|
|
|
2025-08-07 10:53:23 -07:00
|
|
|
#include "lib/types.h"
|
2013-02-23 16:12:41 -08:00
|
|
|
#include "simulation2/components/ICmpObstruction.h"
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
#include "simulation2/helpers/Pathfinding.h"
|
2025-08-07 10:53:23 -07:00
|
|
|
#include "simulation2/helpers/Position.h"
|
|
|
|
|
#include "simulation2/system/Component.h"
|
|
|
|
|
#include "simulation2/system/Entity.h"
|
|
|
|
|
#include "simulation2/system/Interface.h"
|
2010-01-29 13:13:18 -08:00
|
|
|
|
2025-08-07 10:53:23 -07:00
|
|
|
#include <js/Value.h>
|
2011-02-18 16:46:14 -08:00
|
|
|
#include <map>
|
2025-08-07 10:53:23 -07:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2010-03-28 11:21:48 -07:00
|
|
|
|
2025-08-07 10:53:23 -07:00
|
|
|
class CFixedVector2D;
|
2010-04-29 16:36:05 -07:00
|
|
|
class IObstructionTestFilter;
|
2020-11-21 03:20:29 -08:00
|
|
|
class PathGoal;
|
2025-08-07 10:53:23 -07:00
|
|
|
struct GridUpdateInformation;
|
2011-02-10 08:06:28 -08:00
|
|
|
template<typename T> class Grid;
|
|
|
|
|
|
2019-09-15 02:27:10 -07:00
|
|
|
struct PathResult
|
|
|
|
|
{
|
|
|
|
|
PathResult() = default;
|
|
|
|
|
PathResult(u32 t, entity_id_t n, WaypointPath p) : ticket(t), notify(n), path(p) {};
|
|
|
|
|
|
|
|
|
|
u32 ticket;
|
|
|
|
|
entity_id_t notify;
|
|
|
|
|
WaypointPath path;
|
|
|
|
|
};
|
|
|
|
|
|
2010-01-29 13:13:18 -08:00
|
|
|
/**
|
2010-04-29 16:36:05 -07: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 13:13:18 -08:00
|
|
|
*
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
* Both use the same concept of a PathGoal: either a point, circle or square.
|
2010-04-29 16:36:05 -07:00
|
|
|
* (If the starting point is inside the goal shape then the path will move outwards
|
|
|
|
|
* to reach the shape's outline.)
|
2010-01-29 13:13:18 -08:00
|
|
|
*
|
2010-04-29 16:36:05 -07:00
|
|
|
* The output is a list of waypoints.
|
2010-01-29 13:13:18 -08:00
|
|
|
*/
|
|
|
|
|
class ICmpPathfinder : public IComponent
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2010-05-27 16:31:03 -07:00
|
|
|
/**
|
2011-02-10 08:06:28 -08:00
|
|
|
* Get the list of all known passability classes.
|
2010-05-27 16:31:03 -07:00
|
|
|
*/
|
2015-07-05 12:14:52 -07:00
|
|
|
virtual void GetPassabilityClasses(std::map<std::string, pass_class_t>& passClasses) const = 0;
|
2010-05-27 16:31:03 -07:00
|
|
|
|
2015-06-17 13:19:53 -07:00
|
|
|
/**
|
2015-07-05 12:14:52 -07:00
|
|
|
* Get the list of passability classes, separating pathfinding classes and others.
|
2015-06-17 13:19:53 -07:00
|
|
|
*/
|
2015-07-05 12:14:52 -07:00
|
|
|
virtual void GetPassabilityClasses(
|
2016-11-23 03:18:37 -08:00
|
|
|
std::map<std::string, pass_class_t>& nonPathfindingPassClasses,
|
2015-07-05 12:14:52 -07:00
|
|
|
std::map<std::string, pass_class_t>& pathfindingPassClasses) const = 0;
|
2015-06-17 13:19:53 -07:00
|
|
|
|
2010-05-27 16:31:03 -07:00
|
|
|
/**
|
|
|
|
|
* Get the tag for a given passability class name.
|
|
|
|
|
* Logs an error and returns something acceptable if the name is unrecognised.
|
|
|
|
|
*/
|
2017-01-19 18:25:19 -08:00
|
|
|
virtual pass_class_t GetPassabilityClass(const std::string& name) const = 0;
|
2010-05-27 16:31:03 -07:00
|
|
|
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
virtual entity_pos_t GetClearance(pass_class_t passClass) const = 0;
|
|
|
|
|
|
2010-05-27 16:31:03 -07:00
|
|
|
/**
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
* Get the larger clearance in all passability classes.
|
2010-05-27 16:31:03 -07:00
|
|
|
*/
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
virtual entity_pos_t GetMaximumClearance() const = 0;
|
2011-02-10 08:06:28 -08:00
|
|
|
|
2015-10-03 01:27:19 -07:00
|
|
|
virtual const Grid<NavcellData>& GetPassabilityGrid() = 0;
|
2010-05-27 16:31:03 -07:00
|
|
|
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
/**
|
2017-07-14 03:09:32 -07:00
|
|
|
* Get the accumulated dirtiness information since the last time the AI accessed and flushed it.
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
*/
|
2017-07-14 03:09:32 -07:00
|
|
|
virtual const GridUpdateInformation& GetAIPathfinderDirtinessInformation() const = 0;
|
|
|
|
|
virtual void FlushAIPathfinderDirtinessInformation() = 0;
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
|
2015-05-06 11:47:02 -07:00
|
|
|
/**
|
|
|
|
|
* Get a grid representing the distance to the shore of the terrain tile.
|
|
|
|
|
*/
|
|
|
|
|
virtual Grid<u16> ComputeShoreGrid(bool expandOnWater = false) = 0;
|
|
|
|
|
|
2010-09-03 02:55:14 -07:00
|
|
|
/**
|
|
|
|
|
* Asynchronous version of ComputePath.
|
2019-09-15 02:27:10 -07:00
|
|
|
* Request a long path computation, asynchronously.
|
2010-09-03 02:55:14 -07:00
|
|
|
* The result will be sent as CMessagePathResult to 'notify'.
|
|
|
|
|
* Returns a unique non-zero number, which will match the 'ticket' in the result,
|
|
|
|
|
* so callers can recognise each individual request they make.
|
|
|
|
|
*/
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
virtual u32 ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, entity_id_t notify) = 0;
|
2010-09-03 02:55:14 -07:00
|
|
|
|
2019-09-15 02:27:10 -07:00
|
|
|
/*
|
|
|
|
|
* Request a long-path computation immediately
|
2010-01-30 05:11:58 -08:00
|
|
|
*/
|
2019-09-15 02:27:10 -07:00
|
|
|
virtual void ComputePathImmediate(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass, WaypointPath& ret) const = 0;
|
2010-01-30 05:11:58 -08:00
|
|
|
|
2010-01-29 13:13:18 -08:00
|
|
|
/**
|
2019-09-15 02:27:10 -07:00
|
|
|
* Request a short path computation, asynchronously.
|
2010-09-03 02:55:14 -07:00
|
|
|
* The result will be sent as CMessagePathResult to 'notify'.
|
|
|
|
|
* Returns a unique non-zero number, which will match the 'ticket' in the result,
|
|
|
|
|
* so callers can recognise each individual request they make.
|
|
|
|
|
*/
|
2019-09-15 02:27:10 -07:00
|
|
|
virtual u32 ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal& goal, pass_class_t passClass, bool avoidMovingUnits, entity_id_t controller, entity_id_t notify) = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Request a short-path computation immediately.
|
|
|
|
|
*/
|
|
|
|
|
virtual WaypointPath ComputeShortPathImmediate(const ShortPathRequest& request) const = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the debug overlay is enabled, render the path that will computed by ComputePath.
|
|
|
|
|
*/
|
|
|
|
|
virtual void SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) = 0;
|
2020-08-03 05:02:24 -07:00
|
|
|
|
2025-04-26 08:48:41 -07:00
|
|
|
/**
|
|
|
|
|
* Distribute units around a point, returning a list of positions.
|
|
|
|
|
*/
|
|
|
|
|
virtual std::vector<CFixedVector2D> DistributeAround(std::vector<entity_id_t> units, entity_pos_t x, entity_pos_t z) const = 0;
|
|
|
|
|
|
2020-08-03 05:02:24 -07:00
|
|
|
/**
|
|
|
|
|
* @return true if the goal is reachable from (x0, z0) for the given passClass, false otherwise.
|
|
|
|
|
* Warning: this is synchronous, somewhat expensive and not should not be called too liberally.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool IsGoalReachable(entity_pos_t x0, entity_pos_t z0, const PathGoal& goal, pass_class_t passClass) = 0;
|
2010-11-30 04:31:54 -08:00
|
|
|
|
2010-09-03 02:55:14 -07:00
|
|
|
/**
|
|
|
|
|
* Check whether the given movement line is valid and doesn't hit any obstructions
|
|
|
|
|
* or impassable terrain.
|
|
|
|
|
* Returns true if the movement is okay.
|
|
|
|
|
*/
|
2017-01-19 18:25:19 -08:00
|
|
|
virtual bool CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, pass_class_t passClass) const = 0;
|
2010-09-03 02:55:14 -07:00
|
|
|
|
2013-07-07 15:44:47 -07:00
|
|
|
/**
|
|
|
|
|
* Check whether a unit placed here is valid and doesn't hit any obstructions
|
|
|
|
|
* or impassable terrain.
|
|
|
|
|
* When onlyCenterPoint = true, only check the center tile of the unit
|
|
|
|
|
* @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
|
|
|
|
|
* a value describing the type of failure.
|
|
|
|
|
*/
|
2017-01-19 18:25:19 -08:00
|
|
|
virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass, bool onlyCenterPoint = false) const = 0;
|
2013-07-07 15:44:47 -07:00
|
|
|
|
2011-08-06 01:11:05 -07:00
|
|
|
/**
|
|
|
|
|
* Check whether a building placed here is valid and doesn't hit any obstructions
|
|
|
|
|
* or impassable terrain.
|
2013-02-23 16:12:41 -08:00
|
|
|
* @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
|
|
|
|
|
* a value describing the type of failure.
|
2011-08-06 01:11:05 -07:00
|
|
|
*/
|
2017-01-19 18:25:19 -08:00
|
|
|
virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass) const = 0;
|
2011-08-06 01:11:05 -07:00
|
|
|
|
2013-07-07 15:44:47 -07:00
|
|
|
/**
|
|
|
|
|
* Check whether a building placed here is valid and doesn't hit any obstructions
|
|
|
|
|
* or impassable terrain.
|
|
|
|
|
* when onlyCenterPoint = true, only check the center tile of the building
|
|
|
|
|
* @return ICmpObstruction::FOUNDATION_CHECK_SUCCESS if the placement is okay, else
|
|
|
|
|
* a value describing the type of failure.
|
|
|
|
|
*/
|
2017-01-19 18:25:19 -08:00
|
|
|
virtual ICmpObstruction::EFoundationCheck CheckBuildingPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, entity_id_t id, pass_class_t passClass, bool onlyCenterPoint) const = 0;
|
2013-07-07 15:44:47 -07:00
|
|
|
|
|
|
|
|
|
2010-03-20 12:18:01 -07:00
|
|
|
/**
|
|
|
|
|
* Toggle the storage and rendering of debug info.
|
|
|
|
|
*/
|
|
|
|
|
virtual void SetDebugOverlay(bool enabled) = 0;
|
|
|
|
|
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
/**
|
|
|
|
|
* Toggle the storage and rendering of debug info for the hierarchical pathfinder.
|
|
|
|
|
*/
|
|
|
|
|
virtual void SetHierDebugOverlay(bool enabled) = 0;
|
|
|
|
|
|
2010-09-03 02:55:14 -07:00
|
|
|
/**
|
|
|
|
|
* Finish computing asynchronous path requests and send the CMessagePathResult messages.
|
|
|
|
|
*/
|
2021-04-14 00:23:47 -07:00
|
|
|
virtual void SendRequestedPaths() = 0;
|
2010-09-03 02:55:14 -07:00
|
|
|
|
2011-06-26 00:03:08 -07:00
|
|
|
/**
|
2019-09-15 02:27:10 -07:00
|
|
|
* Tell asynchronous pathfinder threads that they can begin computing paths.
|
2011-06-26 00:03:08 -07:00
|
|
|
*/
|
2019-09-15 02:27:10 -07:00
|
|
|
virtual void StartProcessingMoves(bool useMax) = 0;
|
2011-06-26 00:03:08 -07:00
|
|
|
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
/**
|
|
|
|
|
* Regenerates the grid based on the current obstruction list, if necessary
|
|
|
|
|
*/
|
|
|
|
|
virtual void UpdateGrid() = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns some stats about the last ComputePath.
|
|
|
|
|
*/
|
2017-01-19 18:25:19 -08:00
|
|
|
virtual void GetDebugData(u32& steps, double& time, Grid<u8>& grid) const = 0;
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
|
2015-06-29 12:59:41 -07:00
|
|
|
/**
|
|
|
|
|
* Sets up the pathfinder passability overlay in Atlas.
|
|
|
|
|
*/
|
|
|
|
|
virtual void SetAtlasOverlay(bool enable, pass_class_t passClass = 0) = 0;
|
|
|
|
|
|
2010-01-29 13:13:18 -08:00
|
|
|
DECLARE_INTERFACE_TYPE(Pathfinder)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // INCLUDED_ICMPPATHFINDER
|