2015-02-20 17:41:24 -08:00
/* Copyright (C) 2015 Wildfire Games.
2010-01-09 11:20:14 -08:00
* 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/>.
*/
# include "precompiled.h"
# include "simulation2/system/Component.h"
# include "ICmpUnitMotion.h"
2011-08-06 01:11:05 -07:00
# include "simulation2/components/ICmpObstruction.h"
# include "simulation2/components/ICmpObstructionManager.h"
# include "simulation2/components/ICmpOwnership.h"
# include "simulation2/components/ICmpPosition.h"
# include "simulation2/components/ICmpPathfinder.h"
# include "simulation2/components/ICmpRangeManager.h"
2013-10-30 09:12:53 -07:00
# include "simulation2/components/ICmpValueModificationManager.h"
2010-04-29 16:36:05 -07:00
# include "simulation2/helpers/Geometry.h"
# include "simulation2/helpers/Render.h"
2011-08-06 01:11:05 -07:00
# include "simulation2/MessageTypes.h"
2010-09-17 10:53:26 -07:00
# include "simulation2/serialization/SerializeTemplates.h"
2010-04-29 16:36:05 -07:00
# include "graphics/Overlay.h"
# include "graphics/Terrain.h"
# include "maths/FixedVector2D.h"
2010-09-03 02:55:14 -07:00
# include "ps/CLogger.h"
2010-04-29 16:36:05 -07:00
# include "ps/Profile.h"
# include "renderer/Scene.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
// For debugging; units will start going straight to the target
// instead of calling the pathfinder
# define DISABLE_PATHFINDER 0
2010-11-30 04:31:54 -08:00
/**
* When advancing along the long path , and picking a new waypoint to move
* towards , we ' ll pick one that ' s up to this far from the unit ' s current
* position ( to minimise the effects of grid - constrained movement )
*/
2012-01-12 04:51:10 -08:00
static const entity_pos_t WAYPOINT_ADVANCE_MAX = entity_pos_t : : FromInt ( TERRAIN_TILE_SIZE * 8 ) ;
2010-11-30 04:31:54 -08:00
2010-11-30 06:48:04 -08:00
/**
* When advancing along the long path , we ' ll pick a new waypoint to move
* towards if we expect to reach the end of our current short path within
* this many turns ( assuming constant speed and turn length ) .
* ( This could typically be 1 , but we need some tolerance in case speeds
* or turn lengths change . )
*/
static const int WAYPOINT_ADVANCE_LOOKAHEAD_TURNS = 4 ;
2010-11-30 04:31:54 -08:00
/**
* Maximum range to restrict short path queries to . ( Larger ranges are slower ,
* smaller ranges might miss some legitimate routes around large obstacles . )
*/
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
static const entity_pos_t SHORT_PATH_SEARCH_RANGE = entity_pos_t : : FromInt ( TERRAIN_TILE_SIZE * 6 ) ;
2010-11-30 04:31:54 -08:00
/**
* When short - pathing to an intermediate waypoint , we aim for a circle of this radius
* around the waypoint rather than expecting to reach precisely the waypoint itself
* ( since it might be inside an obstacle ) .
*/
2012-01-12 04:51:10 -08:00
static const entity_pos_t SHORT_PATH_GOAL_RADIUS = entity_pos_t : : FromInt ( TERRAIN_TILE_SIZE * 3 / 2 ) ;
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
/**
* If we are this close to our target entity / point , then think about heading
* for it in a straight line instead of pathfinding .
*/
2012-01-12 04:51:10 -08:00
static const entity_pos_t DIRECT_PATH_RANGE = entity_pos_t : : FromInt ( TERRAIN_TILE_SIZE * 4 ) ;
2010-11-30 04:31:54 -08:00
/**
* If we ' re following a target entity ,
* we will recompute our path if the target has moved
* more than this distance from where we last pathed to .
*/
2012-01-12 04:51:10 -08:00
static const entity_pos_t CHECK_TARGET_MOVEMENT_MIN_DELTA = entity_pos_t : : FromInt ( TERRAIN_TILE_SIZE * 4 ) ;
2010-11-30 04:31:54 -08:00
/**
* If we ' re following as part of a formation ,
* but can ' t move to our assigned target point in a straight line ,
* we will recompute our path if the target has moved
* more than this distance from where we last pathed to .
*/
2012-01-12 04:51:10 -08:00
static const entity_pos_t CHECK_TARGET_MOVEMENT_MIN_DELTA_FORMATION = entity_pos_t : : FromInt ( TERRAIN_TILE_SIZE * 1 ) ;
2010-11-30 04:31:54 -08:00
/**
* If we ' re following something but it ' s more than this distance away along
* our path , then don ' t bother trying to repath regardless of how much it has
* moved , until we get this close to the end of our old path .
*/
2012-01-12 04:51:10 -08:00
static const entity_pos_t CHECK_TARGET_MOVEMENT_AT_MAX_DIST = entity_pos_t : : FromInt ( TERRAIN_TILE_SIZE * 16 ) ;
2010-11-30 04:31:54 -08:00
2013-11-13 23:25:56 -08:00
/**
* If we ' re following something and the angle between the ( straight - line ) directions to its previous target
* position and its present target position is greater than a given angle , recompute the path even far away
* ( i . e . even if CHECK_TARGET_MOVEMENT_AT_MAX_DIST condition is not fulfilled ) . The actual check is done
* on the cosine of this angle , with a PI / 6 angle .
*/
static const fixed CHECK_TARGET_MOVEMENT_MIN_COS = fixed : : FromInt ( 866 ) / 1000 ;
2015-03-15 16:59:48 -07:00
static const CColor OVERLAY_COLOR_LONG_PATH ( 1 , 1 , 1 , 1 ) ;
static const CColor OVERLAY_COLOR_SHORT_PATH ( 1 , 0 , 0 , 1 ) ;
2010-11-30 04:31:54 -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
static const entity_pos_t g_GoalDelta = Pathfinding : : NAVCELL_SIZE ; // for extending the goal outwards/inwards a little bit
struct SUnitMotionPlanning
{
WaypointPath nextStepShortPath ; // if !nextStepClean, store a short path for the next step here
u32 expectedPathTicket ;
bool nextStepClean ; // is there any obstruction between the next two long waypoints?
SUnitMotionPlanning ( ) : expectedPathTicket ( 0 ) , nextStepClean ( true ) { }
} ;
/**
* Serialization helper template for SUnitMotionPlanning
*/
struct SerializeUnitMotionPlanning
{
template < typename S >
void operator ( ) ( S & serialize , const char * UNUSED ( name ) , SUnitMotionPlanning & value )
{
SerializeVector < SerializeWaypoint > ( ) ( serialize , " next step short path " , value . nextStepShortPath . m_Waypoints ) ;
serialize . NumberU32_Unbounded ( " expected path ticket " , value . expectedPathTicket ) ;
serialize . Bool ( " next step clean " , value . nextStepClean ) ;
}
} ;
2010-01-09 11:20:14 -08:00
class CCmpUnitMotion : public ICmpUnitMotion
{
public :
static void ClassInit ( CComponentManager & componentManager )
{
2010-09-03 02:55:14 -07:00
componentManager . SubscribeToMessageType ( MT_Update_MotionFormation ) ;
componentManager . SubscribeToMessageType ( MT_Update_MotionUnit ) ;
componentManager . SubscribeToMessageType ( MT_PathResult ) ;
2013-10-30 09:12:53 -07:00
componentManager . SubscribeToMessageType ( MT_ValueModification ) ;
2015-02-20 17:41:24 -08:00
componentManager . SubscribeToMessageType ( MT_Deserialized ) ;
2010-01-09 11:20:14 -08:00
}
DEFAULT_COMPONENT_ALLOCATOR ( UnitMotion )
2010-04-29 16:36:05 -07:00
bool m_DebugOverlayEnabled ;
2010-11-30 04:31:54 -08:00
std : : vector < SOverlayLine > m_DebugOverlayLongPathLines ;
2010-04-29 16:36:05 -07:00
std : : vector < SOverlayLine > m_DebugOverlayShortPathLines ;
2010-01-09 11:20:14 -08:00
// Template state:
2010-02-10 11:28:46 -08:00
2010-09-03 02:55:14 -07:00
bool m_FormationController ;
2013-10-30 09:12:53 -07:00
fixed m_WalkSpeed , m_OriginalWalkSpeed ; // in metres per second
fixed m_RunSpeed , m_OriginalRunSpeed ;
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
pass_class_t m_PassClass ;
2014-05-18 00:59:43 -07:00
std : : string m_PassClassName ;
2010-01-09 11:20:14 -08:00
// Dynamic state:
2010-02-10 11:28:46 -08:00
2015-07-18 01:37:49 -07:00
entity_pos_t m_Clearance ;
2012-09-03 20:57:22 -07:00
bool m_Moving ;
2013-09-30 16:52:22 -07:00
bool m_FacePointAfterMove ;
2010-01-09 11:20:14 -08:00
2010-09-17 10:53:26 -07:00
enum State
2010-02-10 11:28:46 -08:00
{
2010-11-30 04:31:54 -08:00
/*
* Not moving at all .
*/
STATE_IDLE ,
/*
* Not moving at all . Will go to IDLE next turn .
* ( This one - turn delay is a hack to fix animation timings . )
*/
STATE_STOPPING ,
/*
* Member of a formation .
* Pathing to the target ( depending on m_PathState ) .
* Target is m_TargetEntity plus m_TargetOffset .
*/
STATE_FORMATIONMEMBER_PATH ,
/*
* Individual unit or formation controller .
* Pathing to the target ( depending on m_PathState ) .
* Target is m_TargetPos , m_TargetMinRange , m_TargetMaxRange ;
* if m_TargetEntity is not INVALID_ENTITY then m_TargetPos is tracking it .
*/
STATE_INDIVIDUAL_PATH ,
2010-09-17 10:53:26 -07:00
STATE_MAX
2010-02-10 11:28:46 -08:00
} ;
2010-11-30 04:31:54 -08:00
u8 m_State ;
enum PathState
{
/*
* There is no path .
* ( This should only happen in IDLE and STOPPING . )
*/
PATHSTATE_NONE ,
/*
* We have an outstanding long path request .
* No paths are usable yet , so we can ' t move anywhere .
*/
PATHSTATE_WAITING_REQUESTING_LONG ,
/*
* We have an outstanding short path request .
* m_LongPath is valid .
* m_ShortPath is not yet valid , so we can ' t move anywhere .
*/
PATHSTATE_WAITING_REQUESTING_SHORT ,
/*
* We are following our path , and have no path requests .
* m_LongPath and m_ShortPath are valid .
*/
PATHSTATE_FOLLOWING ,
/*
* We are following our path , and have an outstanding long path request .
* ( This is because our target moved a long way and we need to recompute
* the whole path ) .
* m_LongPath and m_ShortPath are valid .
*/
PATHSTATE_FOLLOWING_REQUESTING_LONG ,
/*
* We are following our path , and have an outstanding short path request .
* ( This is because our target moved and we ' ve got a new long path
* which we need to follow ) .
* m_LongPath is valid ; m_ShortPath is valid but obsolete .
*/
PATHSTATE_FOLLOWING_REQUESTING_SHORT ,
PATHSTATE_MAX
} ;
u8 m_PathState ;
2010-02-10 11:28:46 -08:00
2010-09-03 02:55:14 -07:00
u32 m_ExpectedPathTicket ; // asynchronous request ID we're waiting for, or 0 if none
entity_id_t m_TargetEntity ;
2010-11-30 04:31:54 -08:00
CFixedVector2D m_TargetPos ;
CFixedVector2D m_TargetOffset ;
entity_pos_t m_TargetMinRange ;
entity_pos_t m_TargetMaxRange ;
2010-09-03 02:55:14 -07:00
fixed m_Speed ;
2012-12-06 11:46:13 -08:00
// Current mean speed (over the last turn).
fixed m_CurSpeed ;
2010-11-30 04:31:54 -08:00
// Currently active paths (storing waypoints in reverse order).
// The last item in each path is the point we're currently heading towards.
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
WaypointPath m_LongPath ;
WaypointPath m_ShortPath ;
// Motion planning
SUnitMotionPlanning m_Planning ;
2010-11-30 04:31:54 -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
PathGoal m_FinalGoal ;
2010-09-03 02:55:14 -07:00
2010-04-09 12:02:39 -07:00
static std : : string GetSchema ( )
{
return
2010-04-23 09:09:03 -07:00
" <a:help>Provides the unit with the ability to move around the world by itself.</a:help> "
" <a:example> "
" <WalkSpeed>7.0</WalkSpeed> "
2010-05-27 16:31:03 -07:00
" <PassabilityClass>default</PassabilityClass> "
2010-04-23 09:09:03 -07:00
" </a:example> "
2010-09-03 02:55:14 -07:00
" <element name='FormationController'> "
" <data type='boolean'/> "
" </element> "
2010-04-23 09:09:03 -07:00
" <element name='WalkSpeed' a:help='Basic movement speed (in metres per second)'> "
2010-04-09 12:02:39 -07:00
" <ref name='positiveDecimal'/> "
2010-05-15 14:07:52 -07:00
" </element> "
" <optional> "
" <element name='Run'> "
" <interleave> "
" <element name='Speed'><ref name='positiveDecimal'/></element> "
" <element name='Range'><ref name='positiveDecimal'/></element> "
" <element name='RangeMin'><ref name='nonNegativeDecimal'/></element> "
" <element name='RegenTime'><ref name='positiveDecimal'/></element> "
" <element name='DecayTime'><ref name='positiveDecimal'/></element> "
" </interleave> "
" </element> "
2010-05-27 16:31:03 -07:00
" </optional> "
" <element name='PassabilityClass' a:help='Identifies the terrain passability class (values are defined in special/pathfinder.xml)'> "
" <text/> "
" </element> " ;
2010-04-09 12:02:39 -07:00
}
2010-04-23 09:09:03 -07:00
2010-05-15 14:07:52 -07:00
/*
* TODO : the running / charging thing needs to be designed and implemented
*/
2011-01-16 06:08:38 -08:00
virtual void Init ( const CParamNode & paramNode )
2010-01-09 11:20:14 -08:00
{
2010-09-03 02:55:14 -07:00
m_FormationController = paramNode . GetChild ( " FormationController " ) . ToBool ( ) ;
2010-02-07 12:06:16 -08:00
2012-09-03 20:57:22 -07:00
m_Moving = false ;
2013-09-30 16:52:22 -07:00
m_FacePointAfterMove = true ;
2013-10-30 09:12:53 -07:00
m_WalkSpeed = m_OriginalWalkSpeed = paramNode . GetChild ( " WalkSpeed " ) . ToFixed ( ) ;
2010-07-18 08:19:49 -07:00
m_Speed = m_WalkSpeed ;
2012-12-06 11:46:13 -08:00
m_CurSpeed = fixed : : Zero ( ) ;
2010-02-10 11:28:46 -08:00
2010-06-04 17:49:14 -07:00
if ( paramNode . GetChild ( " Run " ) . IsOk ( ) )
2013-10-30 09:12:53 -07:00
m_RunSpeed = m_OriginalRunSpeed = paramNode . GetChild ( " Run " ) . GetChild ( " Speed " ) . ToFixed ( ) ;
2010-06-04 17:49:14 -07:00
else
2013-10-30 09:12:53 -07:00
m_RunSpeed = m_OriginalRunSpeed = m_WalkSpeed ;
2010-06-04 17:49:14 -07:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSystemEntity ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( cmpPathfinder )
2010-05-27 16:31:03 -07:00
{
2014-05-18 00:59:43 -07:00
m_PassClassName = paramNode . GetChild ( " PassabilityClass " ) . ToUTF8 ( ) ;
m_PassClass = cmpPathfinder - > GetPassabilityClass ( m_PassClassName ) ;
2015-07-18 01:37:49 -07:00
m_Clearance = cmpPathfinder - > GetClearance ( m_PassClass ) ;
CmpPtr < ICmpObstruction > cmpObstruction ( GetEntityHandle ( ) ) ;
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
if ( cmpObstruction )
2015-07-18 01:37:49 -07:00
cmpObstruction - > SetUnitClearance ( m_Clearance ) ;
2010-05-27 16:31:03 -07:00
}
2010-09-03 02:55:14 -07:00
m_State = STATE_IDLE ;
2010-11-30 04:31:54 -08:00
m_PathState = PATHSTATE_NONE ;
2010-09-03 02:55:14 -07:00
m_ExpectedPathTicket = 0 ;
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
m_TargetEntity = INVALID_ENTITY ;
2010-09-17 10:53:26 -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
m_FinalGoal . type = PathGoal : : POINT ;
2010-09-17 10:53:26 -07:00
2010-04-29 16:36:05 -07:00
m_DebugOverlayEnabled = false ;
2010-01-09 11:20:14 -08:00
}
2011-01-16 06:08:38 -08:00
virtual void Deinit ( )
2010-01-09 11:20:14 -08:00
{
}
2010-11-30 04:31:54 -08:00
template < typename S >
void SerializeCommon ( S & serialize )
2010-01-09 11:20:14 -08:00
{
2010-09-17 10:53:26 -07:00
serialize . NumberU8 ( " state " , m_State , 0 , STATE_MAX - 1 ) ;
2010-11-30 04:31:54 -08:00
serialize . NumberU8 ( " path state " , m_PathState , 0 , PATHSTATE_MAX - 1 ) ;
2010-09-17 10:53:26 -07:00
2014-05-18 00:59:43 -07:00
serialize . StringASCII ( " pass class " , m_PassClassName , 0 , 64 ) ;
2010-09-17 10:53:26 -07:00
serialize . NumberU32_Unbounded ( " ticket " , m_ExpectedPathTicket ) ;
2010-02-10 11:28:46 -08:00
2010-09-17 10:53:26 -07:00
serialize . NumberU32_Unbounded ( " target entity " , m_TargetEntity ) ;
2010-11-30 04:31:54 -08:00
serialize . NumberFixed_Unbounded ( " target pos x " , m_TargetPos . X ) ;
serialize . NumberFixed_Unbounded ( " target pos y " , m_TargetPos . Y ) ;
serialize . NumberFixed_Unbounded ( " target offset x " , m_TargetOffset . X ) ;
serialize . NumberFixed_Unbounded ( " target offset y " , m_TargetOffset . Y ) ;
serialize . NumberFixed_Unbounded ( " target min range " , m_TargetMinRange ) ;
serialize . NumberFixed_Unbounded ( " target max range " , m_TargetMaxRange ) ;
2010-09-17 10:53:26 -07:00
serialize . NumberFixed_Unbounded ( " speed " , m_Speed ) ;
2012-12-04 08:59:08 -08:00
serialize . Bool ( " moving " , m_Moving ) ;
2013-09-30 16:52:22 -07:00
serialize . Bool ( " facePointAfterMove " , m_FacePointAfterMove ) ;
2012-12-04 08:59:08 -08:00
2010-09-17 10:53:26 -07:00
SerializeVector < SerializeWaypoint > ( ) ( serialize , " long path " , m_LongPath . m_Waypoints ) ;
SerializeVector < SerializeWaypoint > ( ) ( serialize , " short path " , m_ShortPath . m_Waypoints ) ;
2010-11-30 04:31:54 -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
SerializeUnitMotionPlanning ( ) ( serialize , " planning " , m_Planning ) ;
2010-09-17 10:53:26 -07:00
SerializeGoal ( ) ( serialize , " goal " , m_FinalGoal ) ;
2010-01-09 11:20:14 -08:00
}
2010-11-30 04:31:54 -08:00
virtual void Serialize ( ISerializer & serialize )
{
SerializeCommon ( serialize ) ;
}
2011-01-16 06:08:38 -08:00
virtual void Deserialize ( const CParamNode & paramNode , IDeserializer & deserialize )
2010-01-09 11:20:14 -08:00
{
2011-01-16 06:08:38 -08:00
Init ( paramNode ) ;
2010-01-09 11:20:14 -08:00
2010-11-30 04:31:54 -08:00
SerializeCommon ( deserialize ) ;
2014-05-18 00:59:43 -07:00
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSystemEntity ( ) ) ;
if ( cmpPathfinder )
m_PassClass = cmpPathfinder - > GetPassabilityClass ( m_PassClassName ) ;
2010-01-09 11:20:14 -08:00
}
2011-01-16 06:08:38 -08:00
virtual void HandleMessage ( const CMessage & msg , bool UNUSED ( global ) )
2010-01-09 11:20:14 -08:00
{
switch ( msg . GetType ( ) )
{
2010-09-03 02:55:14 -07:00
case MT_Update_MotionFormation :
2010-01-09 11:20:14 -08:00
{
2010-09-03 02:55:14 -07:00
if ( m_FormationController )
2010-02-10 11:28:46 -08:00
{
2010-09-03 02:55:14 -07:00
fixed dt = static_cast < const CMessageUpdate_MotionFormation & > ( msg ) . turnLength ;
Move ( dt ) ;
}
break ;
}
case MT_Update_MotionUnit :
{
if ( ! m_FormationController )
{
fixed dt = static_cast < const CMessageUpdate_MotionUnit & > ( msg ) . turnLength ;
Move ( dt ) ;
2010-02-10 11:28:46 -08:00
}
2010-01-09 11:20:14 -08:00
break ;
}
2010-04-29 16:36:05 -07:00
case MT_RenderSubmit :
{
2014-06-19 16:20:12 -07:00
PROFILE3 ( " UnitMotion::RenderSubmit " ) ;
2010-04-29 16:36:05 -07:00
const CMessageRenderSubmit & msgData = static_cast < const CMessageRenderSubmit & > ( msg ) ;
2010-05-01 02:48:39 -07:00
RenderSubmit ( msgData . collector ) ;
2010-04-29 16:36:05 -07:00
break ;
}
2010-09-03 02:55:14 -07:00
case MT_PathResult :
{
const CMessagePathResult & msgData = static_cast < const CMessagePathResult & > ( msg ) ;
PathResult ( msgData . ticket , msgData . path ) ;
break ;
}
2013-10-30 09:12:53 -07:00
case MT_ValueModification :
{
const CMessageValueModification & msgData = static_cast < const CMessageValueModification & > ( msg ) ;
if ( msgData . component ! = L " UnitMotion " )
break ;
2015-02-20 17:41:24 -08:00
}
// fall-through
case MT_Deserialized :
{
CmpPtr < ICmpValueModificationManager > cmpValueModificationManager ( GetSystemEntity ( ) ) ;
if ( ! cmpValueModificationManager )
break ;
2013-10-30 09:12:53 -07:00
fixed newWalkSpeed = cmpValueModificationManager - > ApplyModifications ( L " UnitMotion/WalkSpeed " , m_OriginalWalkSpeed , GetEntityId ( ) ) ;
fixed newRunSpeed = cmpValueModificationManager - > ApplyModifications ( L " UnitMotion/Run/Speed " , m_OriginalRunSpeed , GetEntityId ( ) ) ;
// update m_Speed (the actual speed) if set to one of the variables
if ( m_Speed = = m_WalkSpeed )
m_Speed = newWalkSpeed ;
else if ( m_Speed = = m_RunSpeed )
m_Speed = newRunSpeed ;
m_WalkSpeed = newWalkSpeed ;
m_RunSpeed = newRunSpeed ;
2015-02-20 17:41:24 -08:00
break ;
2013-10-30 09:12:53 -07:00
}
2010-01-09 11:20:14 -08:00
}
}
2014-06-19 16:20:12 -07:00
void UpdateMessageSubscriptions ( )
{
bool needRender = m_DebugOverlayEnabled ;
GetSimContext ( ) . GetComponentManager ( ) . DynamicSubscriptionNonsync ( MT_RenderSubmit , this , needRender ) ;
}
2012-08-31 01:20:36 -07:00
virtual bool IsMoving ( )
{
2012-09-03 20:57:22 -07:00
return m_Moving ;
2012-08-31 01:20:36 -07:00
}
2010-07-18 08:19:49 -07:00
virtual fixed GetWalkSpeed ( )
2010-02-10 11:28:46 -08:00
{
2010-07-18 08:19:49 -07:00
return m_WalkSpeed ;
2010-04-29 16:36:05 -07:00
}
2010-02-10 11:28:46 -08:00
2010-06-04 17:49:14 -07:00
virtual fixed GetRunSpeed ( )
{
return m_RunSpeed ;
}
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 pass_class_t GetPassabilityClass ( )
2011-08-06 01:11:05 -07:00
{
return m_PassClass ;
}
2014-05-18 00:59:43 -07:00
virtual std : : string GetPassabilityClassName ( )
{
return m_PassClassName ;
}
virtual void SetPassabilityClassName ( std : : string passClassName )
{
m_PassClassName = passClassName ;
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSystemEntity ( ) ) ;
if ( cmpPathfinder )
m_PassClass = cmpPathfinder - > GetPassabilityClass ( passClassName ) ;
}
2012-12-06 11:46:13 -08:00
virtual fixed GetCurrentSpeed ( )
{
return m_CurSpeed ;
}
2010-07-20 01:45:09 -07:00
virtual void SetSpeed ( fixed speed )
2010-07-18 08:19:49 -07:00
{
2010-07-20 01:45:09 -07:00
m_Speed = speed ;
2010-07-18 08:19:49 -07:00
}
2013-09-30 16:52:22 -07:00
virtual void SetFacePointAfterMove ( bool facePointAfterMove )
{
m_FacePointAfterMove = facePointAfterMove ;
}
2010-04-29 16:36:05 -07:00
virtual void SetDebugOverlay ( bool enabled )
{
m_DebugOverlayEnabled = enabled ;
2014-06-19 16:20:12 -07:00
UpdateMessageSubscriptions ( ) ;
2010-04-29 16:36:05 -07:00
}
2010-07-18 08:19:49 -07:00
virtual bool MoveToPointRange ( entity_pos_t x , entity_pos_t z , entity_pos_t minRange , entity_pos_t maxRange ) ;
2012-12-02 09:25:23 -08:00
virtual bool IsInPointRange ( entity_pos_t x , entity_pos_t z , entity_pos_t minRange , entity_pos_t maxRange ) ;
2010-11-30 04:31:54 -08:00
virtual bool MoveToTargetRange ( entity_id_t target , entity_pos_t minRange , entity_pos_t maxRange ) ;
virtual bool IsInTargetRange ( entity_id_t target , entity_pos_t minRange , entity_pos_t maxRange ) ;
2010-09-03 02:55:14 -07:00
virtual void MoveToFormationOffset ( entity_id_t target , entity_pos_t x , entity_pos_t z ) ;
2010-07-18 08:19:49 -07:00
2011-06-09 12:44:40 -07:00
virtual void FaceTowardsPoint ( entity_pos_t x , entity_pos_t z ) ;
2010-07-18 08:19:49 -07:00
virtual void StopMoving ( )
{
2012-09-03 20:57:22 -07:00
m_Moving = false ;
2010-10-06 15:17:34 -07:00
m_ExpectedPathTicket = 0 ;
2010-09-03 02:55:14 -07:00
m_State = STATE_STOPPING ;
2010-11-30 04:31:54 -08:00
m_PathState = PATHSTATE_NONE ;
m_LongPath . m_Waypoints . clear ( ) ;
m_ShortPath . m_Waypoints . clear ( ) ;
2010-09-03 02:55:14 -07:00
}
2015-07-18 01:37:49 -07:00
virtual entity_pos_t GetUnitClearance ( )
2010-09-03 02:55:14 -07:00
{
2015-07-18 01:37:49 -07:00
return m_Clearance ;
2010-07-18 08:19:49 -07:00
}
2010-04-29 16:36:05 -07:00
private :
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
bool ShouldAvoidMovingUnits ( ) const
2010-09-03 02:55:14 -07:00
{
return ! m_FormationController ;
}
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
bool IsFormationMember ( ) const
2010-11-30 04:31:54 -08:00
{
return m_State = = STATE_FORMATIONMEMBER_PATH ;
}
void StartFailed ( )
2010-09-03 02:55:14 -07:00
{
2010-11-30 04:31:54 -08:00
StopMoving ( ) ;
m_State = STATE_IDLE ; // don't go through the STOPPING state since we never even started
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpObstruction > cmpObstruction ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( cmpObstruction )
2010-09-03 02:55:14 -07:00
cmpObstruction - > SetMovingFlag ( false ) ;
CMessageMotionChanged msg ( true , true ) ;
GetSimContext ( ) . GetComponentManager ( ) . PostMessage ( GetEntityId ( ) , msg ) ;
}
2010-11-30 04:31:54 -08:00
void MoveFailed ( )
{
StopMoving ( ) ;
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpObstruction > cmpObstruction ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( cmpObstruction )
2010-11-30 04:31:54 -08:00
cmpObstruction - > SetMovingFlag ( false ) ;
CMessageMotionChanged msg ( false , true ) ;
GetSimContext ( ) . GetComponentManager ( ) . PostMessage ( GetEntityId ( ) , msg ) ;
}
void StartSucceeded ( )
2010-09-03 02:55:14 -07:00
{
CMessageMotionChanged msg ( true , false ) ;
GetSimContext ( ) . GetComponentManager ( ) . PostMessage ( GetEntityId ( ) , msg ) ;
}
2010-11-30 04:31:54 -08:00
void MoveSucceeded ( )
2010-09-03 02:55:14 -07:00
{
2012-09-03 20:57:22 -07:00
m_Moving = false ;
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpObstruction > cmpObstruction ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( cmpObstruction )
2010-09-03 02:55:14 -07:00
cmpObstruction - > SetMovingFlag ( false ) ;
2012-12-06 11:46:13 -08:00
// No longer moving, so speed is 0.
m_CurSpeed = fixed : : Zero ( ) ;
2010-09-03 02:55:14 -07:00
CMessageMotionChanged msg ( false , false ) ;
GetSimContext ( ) . GetComponentManager ( ) . PostMessage ( GetEntityId ( ) , msg ) ;
}
2010-04-29 16:36:05 -07:00
2013-11-13 23:25:56 -08:00
bool MoveToPointRange ( entity_pos_t x , entity_pos_t z , entity_pos_t minRange , entity_pos_t maxRange , entity_id_t target ) ;
2010-04-29 16:36:05 -07:00
/**
2010-11-30 04:31:54 -08:00
* Handle the result of an asynchronous path query .
*/
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
void PathResult ( u32 ticket , const WaypointPath & path ) ;
2010-11-30 04:31:54 -08:00
/**
* Do the per - turn movement and other updates .
2010-04-29 16:36:05 -07:00
*/
2010-05-02 13:32:37 -07:00
void Move ( fixed dt ) ;
2010-04-29 16:36:05 -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
/**
* Analyse the next long path step ( if any ) and precompute a short path if needed .
* Then use the previous computed short path , if present , for the current step .
*/
void PlanNextStep ( const CFixedVector2D & pos ) ;
2010-11-30 04:31:54 -08:00
/**
* Decide whether to approximate the given range from a square target as a circle ,
* rather than as a square .
*/
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
bool ShouldTreatTargetAsCircle ( entity_pos_t range , entity_pos_t hw , entity_pos_t hh , entity_pos_t circleRadius ) const ;
2010-11-30 04:31:54 -08:00
/**
* Computes the current location of our target entity ( plus offset ) .
* Returns false if no target entity or no valid position .
*/
bool ComputeTargetPosition ( CFixedVector2D & out ) ;
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
/**
* Attempts to replace the current path with a straight line to the goal ,
* if this goal is a point , is close enough and the route is not obstructed .
*/
bool TryGoingStraightToGoalPoint ( const CFixedVector2D & from ) ;
2010-11-30 04:31:54 -08:00
/**
* Attempts to replace the current path with a straight line to the target
* entity , if it ' s close enough and the route is not obstructed .
*/
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
bool TryGoingStraightToTargetEntity ( const CFixedVector2D & from ) ;
2010-11-30 04:31:54 -08:00
/**
* Returns whether the target entity has moved more than minDelta since our
* last path computations , and we ' re close enough to it to care .
*/
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
bool CheckTargetMovement ( const CFixedVector2D & from , entity_pos_t minDelta ) ;
2010-11-30 04:31:54 -08:00
/**
* Returns whether the length of the given path , plus the distance from
* ' from ' to the first waypoints , it shorter than minDistance .
*/
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
bool PathIsShort ( const WaypointPath & path , const CFixedVector2D & from , entity_pos_t minDistance ) const ;
2010-04-29 16:36:05 -07:00
/**
* Rotate to face towards the target point , given the current pos
*/
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
void FaceTowardsPointFromPos ( const CFixedVector2D & pos , entity_pos_t x , entity_pos_t z ) ;
2010-04-29 16:36:05 -07:00
/**
2010-11-30 04:31:54 -08:00
* Returns an appropriate obstruction filter for use with path requests .
2010-04-29 16:36:05 -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
ControlGroupMovementObstructionFilter GetObstructionFilter ( bool forceAvoidMovingUnits = false ) const ;
2010-09-03 02:55:14 -07:00
2010-11-30 04:31:54 -08:00
/**
* Start moving to the given goal , from our current position ' from ' .
* Might go in a straight line immediately , or might start an asynchronous
* path request .
*/
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
void BeginPathing ( const CFixedVector2D & from , const PathGoal & goal ) ;
2010-04-29 16:36:05 -07:00
/**
2010-11-30 04:31:54 -08:00
* Start an asynchronous long path query .
2010-04-29 16:36:05 -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
void RequestLongPath ( const CFixedVector2D & from , const PathGoal & goal ) ;
2010-04-29 16:36:05 -07:00
/**
2010-11-30 04:31:54 -08:00
* Start an asynchronous short path query .
2010-04-29 16:36:05 -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
void RequestShortPath ( const CFixedVector2D & from , const PathGoal & goal , bool avoidMovingUnits ) ;
2010-04-29 16:36:05 -07:00
/**
* Convert a path into a renderable list of lines
*/
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
void RenderPath ( const WaypointPath & path , std : : vector < SOverlayLine > & lines , CColor color ) ;
2010-04-29 16:36:05 -07:00
2010-05-01 02:48:39 -07:00
void RenderSubmit ( SceneCollector & collector ) ;
2010-04-29 16:36:05 -07:00
} ;
REGISTER_COMPONENT_TYPE ( UnitMotion )
2010-02-10 11:28:46 -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
void CCmpUnitMotion : : PathResult ( u32 ticket , const WaypointPath & path )
2010-04-29 16:36:05 -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
if ( ticket = = m_Planning . expectedPathTicket )
{
// If no path was found, better cancel the planning
if ( path . m_Waypoints . empty ( ) )
m_Planning = SUnitMotionPlanning ( ) ;
m_Planning . nextStepShortPath = path ;
return ;
}
2010-09-03 02:55:14 -07:00
// Ignore obsolete path requests
if ( ticket ! = m_ExpectedPathTicket )
return ;
2010-04-29 16:36:05 -07:00
2010-09-03 02:55:14 -07:00
m_ExpectedPathTicket = 0 ; // we don't expect to get this result again
2010-11-30 04:31:54 -08:00
if ( m_PathState = = PATHSTATE_WAITING_REQUESTING_LONG )
2010-04-29 16:36:05 -07:00
{
2010-11-30 04:31:54 -08:00
m_LongPath = path ;
m_ShortPath . m_Waypoints . clear ( ) ;
2010-09-03 02:55:14 -07:00
2011-05-06 14:52:15 -07:00
// If there's no waypoints then we couldn't get near the target.
// Sort of hack: Just try going directly to the goal point instead
// (via the short pathfinder), so if we're stuck and the user clicks
// close enough to the unit then we can probably get unstuck
2010-11-30 04:31:54 -08:00
if ( m_LongPath . m_Waypoints . empty ( ) )
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
m_LongPath . m_Waypoints . emplace_back ( Waypoint { m_FinalGoal . x , m_FinalGoal . z } ) ;
2010-09-03 02:55:14 -07:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2010-11-30 04:31:54 -08:00
{
StartFailed ( ) ;
2010-09-03 02:55:14 -07:00
return ;
2010-11-30 04:31:54 -08:00
}
2010-09-03 02:55:14 -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
m_PathState = PATHSTATE_FOLLOWING ;
StartSucceeded ( ) ;
2010-11-30 04:31:54 -08:00
}
else if ( m_PathState = = PATHSTATE_WAITING_REQUESTING_SHORT )
{
m_ShortPath = path ;
// If there's no waypoints then we couldn't get near the target
if ( m_ShortPath . m_Waypoints . empty ( ) )
{
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
// If we're globally following a long path, try to remove the next waypoint, it might be obstructed
if ( m_LongPath . m_Waypoints . size ( ) > 1 )
m_LongPath . m_Waypoints . pop_back ( ) ;
else if ( ! IsFormationMember ( ) )
2012-09-02 19:59:15 -07:00
{
StartFailed ( ) ;
return ;
}
else
{
2012-09-03 20:57:22 -07:00
m_Moving = false ;
2012-09-02 19:59:15 -07:00
CMessageMotionChanged msg ( true , true ) ;
GetSimContext ( ) . GetComponentManager ( ) . PostMessage ( GetEntityId ( ) , msg ) ;
}
2010-11-30 04:31:54 -08:00
}
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2010-11-30 04:31:54 -08:00
{
StartFailed ( ) ;
return ;
}
2010-09-03 02:55:14 -07:00
2010-11-30 04:31:54 -08:00
// Now we've got a short path that we can follow
m_PathState = PATHSTATE_FOLLOWING ;
2010-09-03 02:55:14 -07:00
2010-11-30 04:31:54 -08:00
StartSucceeded ( ) ;
2010-04-29 16:36:05 -07:00
}
2010-11-30 04:31:54 -08:00
else if ( m_PathState = = PATHSTATE_FOLLOWING_REQUESTING_LONG )
2010-09-03 02:55:14 -07:00
{
m_LongPath = path ;
2010-11-30 04:31:54 -08:00
// Leave the old m_ShortPath - we'll carry on following it until the
// new short path has been computed
2010-04-29 16:36:05 -07:00
2011-06-28 00:27:03 -07:00
// If there's no waypoints then we couldn't get near the target.
// Sort of hack: Just try going directly to the goal point instead
// (via the short pathfinder), so if we're stuck and the user clicks
// close enough to the unit then we can probably get unstuck
2010-09-03 02:55:14 -07:00
if ( m_LongPath . m_Waypoints . empty ( ) )
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
m_LongPath . m_Waypoints . emplace_back ( Waypoint { m_FinalGoal . x , m_FinalGoal . z } ) ;
2010-11-30 04:31:54 -08:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2010-09-03 02:55:14 -07:00
{
2010-11-30 04:31:54 -08:00
StopMoving ( ) ;
return ;
}
2010-09-03 02:55:14 -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
m_PathState = PATHSTATE_FOLLOWING ;
2010-11-30 04:31:54 -08:00
// (TODO: is this entirely safe? We might continue moving along our
// old path while this request is active, so it'll be slightly incorrect
// by the time the request has completed)
}
else if ( m_PathState = = PATHSTATE_FOLLOWING_REQUESTING_SHORT )
{
// Replace the current path with the new one
m_ShortPath = path ;
// If there's no waypoints then we couldn't get near the target
if ( m_ShortPath . m_Waypoints . empty ( ) )
{
// We should stop moving (unless we're in a formation, in which
// case we should continue following it)
if ( ! IsFormationMember ( ) )
2010-09-03 02:55:14 -07:00
{
2010-11-30 04:31:54 -08:00
MoveFailed ( ) ;
return ;
2010-09-03 02:55:14 -07:00
}
2012-09-02 19:59:15 -07:00
else
{
2012-09-03 20:57:22 -07:00
m_Moving = false ;
2012-09-02 19:59:15 -07:00
CMessageMotionChanged msg ( false , true ) ;
GetSimContext ( ) . GetComponentManager ( ) . PostMessage ( GetEntityId ( ) , msg ) ;
}
2010-09-03 02:55:14 -07:00
}
2010-11-30 04:31:54 -08:00
m_PathState = PATHSTATE_FOLLOWING ;
}
2010-09-03 02:55:14 -07:00
else
{
2015-01-22 12:31:30 -08:00
LOGWARNING ( " unexpected PathResult (%u %d %d) " , GetEntityId ( ) , m_State , m_PathState ) ;
2010-09-03 02:55:14 -07:00
}
2010-04-29 16:36:05 -07:00
}
2010-05-02 13:32:37 -07:00
void CCmpUnitMotion : : Move ( fixed dt )
2010-04-29 16:36:05 -07:00
{
PROFILE ( " Move " ) ;
2010-11-30 04:31:54 -08:00
if ( m_State = = STATE_STOPPING )
2010-09-03 02:55:14 -07:00
{
m_State = STATE_IDLE ;
2010-11-30 04:31:54 -08:00
MoveSucceeded ( ) ;
return ;
}
if ( m_State = = STATE_IDLE )
return ;
switch ( m_PathState )
{
case PATHSTATE_NONE :
{
// If we're not pathing, do nothing
2010-05-27 16:31:03 -07:00
return ;
2010-11-30 04:31:54 -08:00
}
2010-05-27 16:31:03 -07:00
2010-11-30 04:31:54 -08:00
case PATHSTATE_WAITING_REQUESTING_LONG :
case PATHSTATE_WAITING_REQUESTING_SHORT :
{
// If we're waiting for a path and don't have one yet, do nothing
2010-04-29 16:36:05 -07:00
return ;
2010-11-30 04:31:54 -08:00
}
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
case PATHSTATE_FOLLOWING :
case PATHSTATE_FOLLOWING_REQUESTING_SHORT :
case PATHSTATE_FOLLOWING_REQUESTING_LONG :
2010-09-03 02:55:14 -07:00
{
2010-11-30 04:31:54 -08:00
// TODO: there's some asymmetry here when units look at other
// units' positions - the result will depend on the order of execution.
// Maybe we should split the updates into multiple phases to minimise
// that problem.
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSystemEntity ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPathfinder )
2010-09-03 02:55:14 -07:00
return ;
2010-04-29 16:36:05 -07:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2010-09-03 02:55:14 -07:00
return ;
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
CFixedVector2D initialPos = cmpPosition - > GetPosition2D ( ) ;
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
// If we're chasing a potentially-moving unit and are currently close
// enough to its current position, and we can head in a straight line
// to it, then throw away our current path and go straight to it
if ( m_PathState = = PATHSTATE_FOLLOWING )
TryGoingStraightToTargetEntity ( initialPos ) ;
2010-02-10 11:28:46 -08:00
2010-11-30 04:31:54 -08:00
// Keep track of the current unit's position during the update
CFixedVector2D pos = initialPos ;
2010-05-27 16:31:03 -07:00
2010-11-30 04:31:54 -08:00
// If in formation, run to keep up; otherwise just walk
// (TODO: support stamina, charging, etc)
fixed basicSpeed ;
if ( IsFormationMember ( ) )
basicSpeed = GetRunSpeed ( ) ;
else
basicSpeed = m_Speed ; // (typically but not always WalkSpeed)
2010-04-29 16:36:05 -07:00
2010-11-30 06:48:04 -08:00
// Find the speed factor of the underlying terrain
// (We only care about the tile we start on - it doesn't matter if we're moving
// partially onto a much slower/faster tile)
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
// TODO: Terrain-dependent speeds are not currently supported
fixed terrainSpeed = fixed : : FromInt ( 1 ) ;
2010-11-30 06:48:04 -08:00
fixed maxSpeed = basicSpeed . Multiply ( terrainSpeed ) ;
2010-09-03 02:55:14 -07:00
2010-11-30 04:31:54 -08:00
bool wasObstructed = false ;
2010-11-30 06:48:04 -08:00
// We want to move (at most) maxSpeed*dt units from pos towards the next waypoint
2010-11-30 04:31:54 -08:00
fixed timeLeft = dt ;
2013-12-04 09:38:46 -08:00
fixed zero = fixed : : Zero ( ) ;
while ( timeLeft > zero )
2010-11-30 04:31:54 -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
// If we ran out of path, we have to stop
if ( m_ShortPath . m_Waypoints . empty ( ) & & m_LongPath . m_Waypoints . empty ( ) )
2010-11-30 04:31:54 -08:00
break ;
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
CFixedVector2D target ;
if ( m_ShortPath . m_Waypoints . empty ( ) )
target = CFixedVector2D ( m_LongPath . m_Waypoints . back ( ) . x , m_LongPath . m_Waypoints . back ( ) . z ) ;
else
target = CFixedVector2D ( m_ShortPath . m_Waypoints . back ( ) . x , m_ShortPath . m_Waypoints . back ( ) . z ) ;
2010-09-03 02:55:14 -07:00
CFixedVector2D offset = target - pos ;
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
// Work out how far we can travel in timeLeft
fixed maxdist = maxSpeed . Multiply ( timeLeft ) ;
2010-09-03 02:55:14 -07:00
// If the target is close, we can move there directly
fixed offsetLength = offset . Length ( ) ;
if ( offsetLength < = maxdist )
{
2015-07-18 01:37:49 -07:00
if ( cmpPathfinder - > CheckMovement ( GetObstructionFilter ( ) , pos . X , pos . Y , target . X , target . Y , m_Clearance , m_PassClass ) )
2010-09-03 02:55:14 -07:00
{
pos = target ;
2010-11-30 04:31:54 -08:00
// Spend the rest of the time heading towards the next waypoint
timeLeft = timeLeft - ( offsetLength / maxSpeed ) ;
2010-09-03 02:55:14 -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
if ( m_ShortPath . m_Waypoints . empty ( ) )
{
m_LongPath . m_Waypoints . pop_back ( ) ;
PlanNextStep ( pos ) ;
}
else
m_ShortPath . m_Waypoints . pop_back ( ) ;
2010-11-30 04:31:54 -08:00
continue ;
}
else
{
// Error - path was obstructed
wasObstructed = true ;
break ;
2010-09-03 02:55:14 -07:00
}
}
else
{
// Not close enough, so just move in the right direction
offset . Normalize ( maxdist ) ;
target = pos + offset ;
2015-07-18 01:37:49 -07:00
if ( cmpPathfinder - > CheckMovement ( GetObstructionFilter ( ) , pos . X , pos . Y , target . X , target . Y , m_Clearance , m_PassClass ) )
2010-09-03 02:55:14 -07:00
{
pos = target ;
2010-11-30 04:31:54 -08:00
break ;
}
else
{
// Error - path was obstructed
wasObstructed = true ;
break ;
2010-09-03 02:55:14 -07:00
}
}
2010-11-30 04:31:54 -08:00
}
2010-09-03 02:55:14 -07:00
2010-11-30 04:31:54 -08:00
// Update the Position component after our movement (if we actually moved anywhere)
if ( pos ! = initialPos )
2013-12-04 09:38:46 -08:00
{
CFixedVector2D offset = pos - initialPos ;
// Face towards the target
entity_angle_t angle = atan2_approx ( offset . X , offset . Y ) ;
cmpPosition - > MoveAndTurnTo ( pos . X , pos . Y , angle ) ;
2012-12-06 11:46:13 -08:00
2013-12-04 09:38:46 -08:00
// Calculate the mean speed over this past turn.
m_CurSpeed = cmpPosition - > GetDistanceTravelled ( ) / dt ;
}
2010-11-30 04:31:54 -08:00
if ( wasObstructed )
{
// Oops, we hit something (very likely another unit).
// Stop, and recompute the whole path.
// TODO: if the target has UnitMotion and is higher priority,
// we should wait a little bit.
2010-04-29 16:36:05 -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
// Recompute our path
// If we are following a long path
if ( ! m_LongPath . m_Waypoints . empty ( ) )
{
m_ShortPath . m_Waypoints . clear ( ) ;
PathGoal goal = { PathGoal : : POINT , m_LongPath . m_Waypoints . back ( ) . x , m_LongPath . m_Waypoints . back ( ) . z } ;
RequestShortPath ( pos , goal , true ) ;
m_PathState = PATHSTATE_WAITING_REQUESTING_SHORT ;
return ;
}
// Else, just entirely recompute
BeginPathing ( pos , m_FinalGoal ) ;
// TODO: check where the collision was and move slightly.
2010-02-10 11:28:46 -08:00
return ;
}
2010-09-03 02:55:14 -07:00
2010-11-30 04:31:54 -08:00
// We successfully moved along our path, until running out of
// waypoints or time.
2010-09-03 02:55:14 -07:00
2010-11-30 04:31:54 -08:00
if ( m_PathState = = PATHSTATE_FOLLOWING )
2010-02-10 11:28:46 -08:00
{
2010-11-30 04:31:54 -08:00
// If we're not currently computing any new paths:
2010-09-03 02:55:14 -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
if ( m_LongPath . m_Waypoints . empty ( ) & & m_ShortPath . m_Waypoints . empty ( ) )
2010-09-03 02:55:14 -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
if ( IsFormationMember ( ) )
2010-11-30 04:31:54 -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
// We've reached our assigned position. If the controller
// is idle, send a notification in case it should disband,
// otherwise continue following the formation next turn.
CmpPtr < ICmpUnitMotion > cmpUnitMotion ( GetSimContext ( ) , m_TargetEntity ) ;
if ( cmpUnitMotion & & ! cmpUnitMotion - > IsMoving ( ) )
{
m_Moving = false ;
CMessageMotionChanged msg ( false , false ) ;
GetSimContext ( ) . GetComponentManager ( ) . PostMessage ( GetEntityId ( ) , msg ) ;
}
2010-09-03 02:55:14 -07:00
}
2010-11-30 04:31:54 -08:00
else
2010-09-03 02:55:14 -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
// check if target was reached in case of a moving target
CmpPtr < ICmpUnitMotion > cmpUnitMotion ( GetSimContext ( ) , m_TargetEntity ) ;
if ( cmpUnitMotion & & cmpUnitMotion - > IsMoving ( ) & &
MoveToTargetRange ( m_TargetEntity , m_TargetMinRange , m_TargetMaxRange ) )
return ;
// Not in formation, so just finish moving
StopMoving ( ) ;
m_State = STATE_IDLE ;
MoveSucceeded ( ) ;
if ( m_FacePointAfterMove )
FaceTowardsPointFromPos ( pos , m_FinalGoal . x , m_FinalGoal . z ) ;
// TODO: if the goal was a square building, we ought to point towards the
// nearest point on the square, not towards its center
2010-09-03 02:55:14 -07:00
}
}
2010-11-30 04:31:54 -08:00
}
2010-09-03 02:55:14 -07:00
2010-11-30 04:31:54 -08:00
// If we have a target entity, and we're not miles away from the end of
// our current path, and the target moved enough, then recompute our
// whole path
if ( m_PathState = = PATHSTATE_FOLLOWING )
{
if ( IsFormationMember ( ) )
CheckTargetMovement ( pos , CHECK_TARGET_MOVEMENT_MIN_DELTA_FORMATION ) ;
else
CheckTargetMovement ( pos , CHECK_TARGET_MOVEMENT_MIN_DELTA ) ;
2010-02-10 11:28:46 -08:00
}
}
2010-09-03 02:55:14 -07:00
}
2010-04-29 16:36:05 -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
void CCmpUnitMotion : : PlanNextStep ( const CFixedVector2D & pos )
{
if ( m_LongPath . m_Waypoints . empty ( ) )
return ;
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSystemEntity ( ) ) ;
const Waypoint & nextPoint = m_LongPath . m_Waypoints . back ( ) ;
// The next step was obstructed the last time we checked; also check that
// the step is still obstructed (maybe the units in our way moved in the meantime)
if ( ! m_Planning . nextStepClean & &
2015-07-18 01:37:49 -07:00
! cmpPathfinder - > CheckMovement ( GetObstructionFilter ( ) , pos . X , pos . Y , nextPoint . x , nextPoint . z , m_Clearance , m_PassClass ) )
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
{
// If the short path computation is over, use it, else just forget about it
if ( ! m_Planning . nextStepShortPath . m_Waypoints . empty ( ) )
{
m_PathState = PATHSTATE_FOLLOWING ;
m_ShortPath = m_Planning . nextStepShortPath ;
}
}
m_Planning = SUnitMotionPlanning ( ) ;
if ( m_LongPath . m_Waypoints . size ( ) = = 1 )
return ;
const Waypoint & followingPoint = m_LongPath . m_Waypoints . rbegin ( ) [ 1 ] ; // penultimate element
m_Planning . nextStepClean = cmpPathfinder - > CheckMovement (
2015-07-18 01:37:49 -07:00
GetObstructionFilter ( ) , nextPoint . x , nextPoint . z , followingPoint . x , followingPoint . z , m_Clearance , m_PassClass ) ;
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
if ( ! m_Planning . nextStepClean )
{
PathGoal goal = { PathGoal : : POINT , followingPoint . x , followingPoint . z } ;
m_Planning . expectedPathTicket = cmpPathfinder - > ComputeShortPathAsync (
2015-07-18 01:37:49 -07:00
nextPoint . x , nextPoint . z , m_Clearance , SHORT_PATH_SEARCH_RANGE , goal , m_PassClass , false , m_TargetEntity , GetEntityId ( ) ) ;
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
}
}
2010-11-30 04:31:54 -08:00
bool CCmpUnitMotion : : ComputeTargetPosition ( CFixedVector2D & out )
2010-04-29 16:36:05 -07:00
{
2010-11-30 04:31:54 -08:00
if ( m_TargetEntity = = INVALID_ENTITY )
return false ;
CmpPtr < ICmpPosition > cmpPosition ( GetSimContext ( ) , m_TargetEntity ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2010-11-30 04:31:54 -08:00
return false ;
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
if ( m_TargetOffset . IsZero ( ) )
{
// No offset, just return the position directly
out = cmpPosition - > GetPosition2D ( ) ;
}
else
{
// There is an offset, so compute it relative to orientation
entity_angle_t angle = cmpPosition - > GetRotation ( ) . Y ;
CFixedVector2D offset = m_TargetOffset . Rotate ( angle ) ;
out = cmpPosition - > GetPosition2D ( ) + offset ;
}
return true ;
2010-04-29 16:36:05 -07:00
}
2010-02-10 11:28:46 -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
bool CCmpUnitMotion : : TryGoingStraightToGoalPoint ( const CFixedVector2D & from )
{
// Make sure the goal is a point
if ( m_FinalGoal . type ! = PathGoal : : POINT )
return false ;
// Fail if the goal is too far away
CFixedVector2D goalPos ( m_FinalGoal . x , m_FinalGoal . z ) ;
if ( ( goalPos - from ) . CompareLength ( DIRECT_PATH_RANGE ) > 0 )
return false ;
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSystemEntity ( ) ) ;
if ( ! cmpPathfinder )
return false ;
// Check if there's any collisions on that route
2015-07-18 01:37:49 -07:00
if ( ! cmpPathfinder - > CheckMovement ( GetObstructionFilter ( ) , from . X , from . Y , goalPos . X , goalPos . Y , m_Clearance , m_PassClass ) )
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
return false ;
// That route is okay, so update our path
m_LongPath . m_Waypoints . clear ( ) ;
m_ShortPath . m_Waypoints . clear ( ) ;
m_ShortPath . m_Waypoints . emplace_back ( Waypoint { goalPos . X , goalPos . Y } ) ;
return true ;
}
bool CCmpUnitMotion : : TryGoingStraightToTargetEntity ( const CFixedVector2D & from )
2010-04-29 16:36:05 -07:00
{
2010-11-30 04:31:54 -08:00
CFixedVector2D targetPos ;
if ( ! ComputeTargetPosition ( targetPos ) )
return false ;
// Fail if the target is too far away
if ( ( targetPos - from ) . CompareLength ( DIRECT_PATH_RANGE ) > 0 )
return false ;
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSystemEntity ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPathfinder )
2010-11-30 04:31:54 -08:00
return false ;
// Move the goal to match the target entity's new position
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
PathGoal goal = m_FinalGoal ;
2010-11-30 04:31:54 -08:00
goal . x = targetPos . X ;
goal . z = targetPos . Y ;
// (we ignore changes to the target's rotation, since only buildings are
// square and buildings don't move)
// Find the point on the goal shape that we should head towards
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
CFixedVector2D goalPos = goal . NearestPointOnGoal ( from ) ;
2010-11-30 04:31:54 -08:00
// Check if there's any collisions on that route
2015-07-18 01:37:49 -07:00
if ( ! cmpPathfinder - > CheckMovement ( GetObstructionFilter ( ) , from . X , from . Y , goalPos . X , goalPos . Y , m_Clearance , m_PassClass ) )
2010-11-30 04:31:54 -08:00
return false ;
// That route is okay, so update our path
m_FinalGoal = goal ;
m_LongPath . m_Waypoints . clear ( ) ;
m_ShortPath . m_Waypoints . clear ( ) ;
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
m_ShortPath . m_Waypoints . emplace_back ( Waypoint { goalPos . X , goalPos . Y } ) ;
2010-11-30 04:31:54 -08:00
return true ;
}
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
bool CCmpUnitMotion : : CheckTargetMovement ( const CFixedVector2D & from , entity_pos_t minDelta )
2010-11-30 04:31:54 -08:00
{
CFixedVector2D targetPos ;
if ( ! ComputeTargetPosition ( targetPos ) )
return false ;
// Fail unless the target has moved enough
CFixedVector2D oldTargetPos ( m_FinalGoal . x , m_FinalGoal . z ) ;
if ( ( targetPos - oldTargetPos ) . CompareLength ( minDelta ) < 0 )
return false ;
2013-11-13 23:25:56 -08:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
return false ;
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
CFixedVector2D oldDir = ( oldTargetPos - pos ) ;
CFixedVector2D newDir = ( targetPos - pos ) ;
oldDir . Normalize ( ) ;
newDir . Normalize ( ) ;
2010-11-30 04:31:54 -08:00
// Fail unless we're close enough to the target to care about its movement
2013-11-13 23:25:56 -08:00
// and the angle between the (straight-line) directions of the previous and new target positions is small
if ( oldDir . Dot ( newDir ) > CHECK_TARGET_MOVEMENT_MIN_COS & & ! PathIsShort ( m_LongPath , from , CHECK_TARGET_MOVEMENT_AT_MAX_DIST ) )
2010-11-30 04:31:54 -08:00
return false ;
2011-06-24 05:35:15 -07:00
// Fail if the target is no longer visible to this entity's owner
// (in which case we'll continue moving to its last known location,
// unless it comes back into view before we reach that location)
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpOwnership > cmpOwnership ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( cmpOwnership )
2011-06-24 05:35:15 -07:00
{
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpRangeManager > cmpRangeManager ( GetSystemEntity ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( cmpRangeManager )
2011-06-24 05:35:15 -07:00
{
if ( cmpRangeManager - > GetLosVisibility ( m_TargetEntity , cmpOwnership - > GetOwner ( ) ) = = ICmpRangeManager : : VIS_HIDDEN )
return false ;
}
}
2010-11-30 04:31:54 -08:00
// The target moved and we need to update our current path;
// change the goal here and expect our caller to start the path request
m_FinalGoal . x = targetPos . X ;
m_FinalGoal . z = targetPos . Y ;
RequestLongPath ( from , m_FinalGoal ) ;
m_PathState = PATHSTATE_FOLLOWING_REQUESTING_LONG ;
return true ;
}
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
bool CCmpUnitMotion : : PathIsShort ( const WaypointPath & path , const CFixedVector2D & from , entity_pos_t minDistance ) const
2010-11-30 04:31:54 -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
CFixedVector2D prev = from ;
2010-11-30 04:31:54 -08:00
entity_pos_t distLeft = minDistance ;
2011-08-16 04:18:32 -07:00
for ( ssize_t i = ( ssize_t ) path . m_Waypoints . size ( ) - 1 ; i > = 0 ; - - i )
2010-11-30 04:31:54 -08:00
{
// Check if the next path segment is longer than the requested minimum
CFixedVector2D waypoint ( path . m_Waypoints [ i ] . x , path . m_Waypoints [ i ] . z ) ;
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
CFixedVector2D delta = waypoint - prev ;
2010-11-30 04:31:54 -08:00
if ( delta . CompareLength ( distLeft ) > 0 )
return false ;
// Still short enough - prepare to check the next segment
distLeft - = delta . Length ( ) ;
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
prev = waypoint ;
2010-11-30 04:31:54 -08:00
}
// Reached the end of the path before exceeding minDistance
return true ;
}
2011-06-09 12:44:40 -07:00
void CCmpUnitMotion : : FaceTowardsPoint ( entity_pos_t x , entity_pos_t z )
{
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2011-06-09 12:44:40 -07:00
return ;
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
FaceTowardsPointFromPos ( pos , x , z ) ;
}
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
void CCmpUnitMotion : : FaceTowardsPointFromPos ( const CFixedVector2D & pos , entity_pos_t x , entity_pos_t z )
2010-11-30 04:31:54 -08:00
{
CFixedVector2D target ( x , z ) ;
CFixedVector2D offset = target - pos ;
if ( ! offset . IsZero ( ) )
2010-01-09 11:20:14 -08:00
{
2010-04-29 16:36:05 -07:00
entity_angle_t angle = atan2_approx ( offset . X , offset . Y ) ;
2010-01-30 05:11:58 -08:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition )
2010-01-30 05:11:58 -08:00
return ;
2010-04-29 16:36:05 -07:00
cmpPosition - > TurnTo ( angle ) ;
}
}
2010-01-30 05:11:58 -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
ControlGroupMovementObstructionFilter CCmpUnitMotion : : GetObstructionFilter ( bool forceAvoidMovingUnits ) const
2010-04-29 16:36:05 -07:00
{
2010-11-30 04:31:54 -08:00
entity_id_t group ;
if ( IsFormationMember ( ) )
group = m_TargetEntity ;
else
group = GetEntityId ( ) ;
2011-02-10 08:06:28 -08:00
return ControlGroupMovementObstructionFilter ( forceAvoidMovingUnits | | ShouldAvoidMovingUnits ( ) , group ) ;
2010-11-30 04:31:54 -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
void CCmpUnitMotion : : BeginPathing ( const CFixedVector2D & from , const PathGoal & goal )
2010-11-30 04:31:54 -08:00
{
// Cancel any pending path requests
m_ExpectedPathTicket = 0 ;
2012-09-03 20:57:22 -07:00
// Update the unit's movement status.
m_Moving = true ;
2010-11-30 04:31:54 -08:00
// Set our 'moving' flag, so other units pathfinding now will ignore us
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpObstruction > cmpObstruction ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( cmpObstruction )
2010-11-30 04:31:54 -08:00
cmpObstruction - > SetMovingFlag ( true ) ;
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
# if DISABLE_PATHFINDER
{
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSimContext ( ) , SYSTEM_ENTITY ) ;
CFixedVector2D goalPos = cmpPathfinder - > GetNearestPointOnGoal ( from , m_FinalGoal ) ;
m_LongPath . m_Waypoints . clear ( ) ;
m_ShortPath . m_Waypoints . clear ( ) ;
m_ShortPath . m_Waypoints . emplace_back ( Waypoint { goalPos . X , goalPos . Y } ) ;
m_PathState = PATHSTATE_FOLLOWING ;
return ;
}
# endif
2010-11-30 04:31:54 -08:00
// If we're aiming at a target entity and it's close and we can reach
// it in a straight line, then we'll just go along the straight line
// instead of computing a path.
if ( TryGoingStraightToTargetEntity ( from ) )
{
m_PathState = PATHSTATE_FOLLOWING ;
return ;
}
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
// Same thing applies to non-entity points
if ( TryGoingStraightToGoalPoint ( from ) )
{
m_PathState = PATHSTATE_FOLLOWING ;
return ;
}
2010-11-30 04:31:54 -08:00
// Otherwise we need to compute a path.
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
// If it's close then just do a short path, not a long path
// TODO: If it's close on the opposite side of a river then we really
// need a long path, so we shouldn't simply check linear distance
if ( goal . DistanceToPoint ( from ) < SHORT_PATH_SEARCH_RANGE )
{
m_LongPath . m_Waypoints . clear ( ) ;
m_PathState = PATHSTATE_WAITING_REQUESTING_SHORT ;
RequestShortPath ( from , goal , true ) ;
}
else
{
m_PathState = PATHSTATE_WAITING_REQUESTING_LONG ;
RequestLongPath ( from , goal ) ;
}
2010-11-30 04:31:54 -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
void CCmpUnitMotion : : RequestLongPath ( const CFixedVector2D & from , const PathGoal & goal )
2010-11-30 04:31:54 -08:00
{
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSystemEntity ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPathfinder )
2010-11-30 04:31:54 -08:00
return ;
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
PathGoal improvedGoal = goal ;
improvedGoal . maxdist = SHORT_PATH_SEARCH_RANGE / 2 ;
2010-11-30 04:31:54 -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
cmpPathfinder - > SetDebugPath ( from . X , from . Y , improvedGoal , m_PassClass ) ;
m_ExpectedPathTicket = cmpPathfinder - > ComputePathAsync ( from . X , from . Y , improvedGoal , m_PassClass , GetEntityId ( ) ) ;
2010-11-30 04:31:54 -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
void CCmpUnitMotion : : RequestShortPath ( const CFixedVector2D & from , const PathGoal & goal , bool avoidMovingUnits )
2010-11-30 04:31:54 -08:00
{
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPathfinder > cmpPathfinder ( GetSystemEntity ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPathfinder )
2010-11-30 04:31:54 -08:00
return ;
2015-07-18 01:37:49 -07:00
m_ExpectedPathTicket = cmpPathfinder - > ComputeShortPathAsync ( from . X , from . Y , m_Clearance , SHORT_PATH_SEARCH_RANGE , goal , m_PassClass , avoidMovingUnits , m_TargetEntity , GetEntityId ( ) ) ;
2010-11-30 04:31:54 -08:00
}
bool CCmpUnitMotion : : MoveToPointRange ( entity_pos_t x , entity_pos_t z , entity_pos_t minRange , entity_pos_t maxRange )
2013-11-13 23:25:56 -08:00
{
return MoveToPointRange ( x , z , minRange , maxRange , INVALID_ENTITY ) ;
}
bool CCmpUnitMotion : : MoveToPointRange ( entity_pos_t x , entity_pos_t z , entity_pos_t minRange , entity_pos_t maxRange , entity_id_t target )
2010-11-30 04:31:54 -08:00
{
PROFILE ( " MoveToPointRange " ) ;
2010-01-09 11:20:14 -08:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2010-04-29 16:36:05 -07:00
return false ;
2010-07-29 13:39:23 -07:00
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
2010-11-30 04:31:54 -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
PathGoal goal ;
goal . x = x ;
goal . z = z ;
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
if ( minRange . IsZero ( ) & & maxRange . IsZero ( ) )
{
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
// Non-ranged movement:
2010-07-31 14:22:39 -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
// Head directly for the goal
goal . type = PathGoal : : POINT ;
2010-04-29 16:36:05 -07:00
}
else
{
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
// Ranged movement:
2010-11-30 04:31:54 -08:00
entity_pos_t distance = ( pos - CFixedVector2D ( x , z ) ) . Length ( ) ;
if ( distance < minRange )
{
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
// Too close to target - move outwards to a circle
// that's slightly larger than the min range
goal . type = PathGoal : : CIRCLE ; // TODO: INVERTED_CIRCLE;
goal . hw = minRange + g_GoalDelta ;
2010-11-30 04:31:54 -08:00
}
2011-03-04 06:36:41 -08:00
else if ( maxRange > = entity_pos_t : : Zero ( ) & & distance > maxRange )
2010-11-30 04:31:54 -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
// Too far from target - move inwards to a circle
// that's slightly smaller than the max range
goal . type = PathGoal : : CIRCLE ;
goal . hw = maxRange - g_GoalDelta ;
// If maxRange was abnormally small,
// collapse the circle into a point
if ( goal . hw < = entity_pos_t : : Zero ( ) )
goal . type = PathGoal : : POINT ;
2010-11-30 04:31:54 -08:00
}
else
{
// We're already in range - no need to move anywhere
2013-09-30 16:52:22 -07:00
if ( m_FacePointAfterMove )
FaceTowardsPointFromPos ( pos , x , z ) ;
2010-11-30 04:31:54 -08:00
return false ;
}
2010-04-29 16:36:05 -07:00
}
2010-11-30 04:31:54 -08:00
m_State = STATE_INDIVIDUAL_PATH ;
2013-11-13 23:25:56 -08:00
m_TargetEntity = target ;
2010-11-30 04:31:54 -08:00
m_TargetOffset = CFixedVector2D ( ) ;
m_TargetMinRange = minRange ;
m_TargetMaxRange = maxRange ;
2010-04-29 16:36:05 -07:00
m_FinalGoal = goal ;
2010-11-30 04:31:54 -08:00
BeginPathing ( pos , goal ) ;
2010-04-29 16:36:05 -07:00
return true ;
}
2012-12-02 09:25:23 -08:00
bool CCmpUnitMotion : : IsInPointRange ( entity_pos_t x , entity_pos_t z , entity_pos_t minRange , entity_pos_t maxRange )
{
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-12-02 09:25:23 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
return false ;
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
bool hasObstruction = false ;
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSystemEntity ( ) ) ;
2012-12-02 09:25:23 -08:00
ICmpObstructionManager : : ObstructionSquare obstruction ;
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
//TODO if (cmpObstructionManager)
// hasObstruction = cmpObstructionManager->FindMostImportantObstruction(GetObstructionFilter(true), x, z, m_Radius, obstruction);
2012-12-02 09:25:23 -08:00
if ( minRange . IsZero ( ) & & maxRange . IsZero ( ) & & hasObstruction )
{
// Handle the non-ranged mode:
CFixedVector2D halfSize ( obstruction . hw , obstruction . hh ) ;
entity_pos_t distance = Geometry : : DistanceToSquare ( pos - CFixedVector2D ( obstruction . x , obstruction . z ) , obstruction . u , obstruction . v , halfSize ) ;
// See if we're too close to the target square
if ( distance < minRange )
return false ;
// See if we're close enough to the target square
if ( maxRange < entity_pos_t : : Zero ( ) | | distance < = maxRange )
return true ;
return false ;
}
else
{
entity_pos_t distance = ( pos - CFixedVector2D ( x , z ) ) . Length ( ) ;
if ( distance < minRange )
return false ;
else if ( maxRange > = entity_pos_t : : Zero ( ) & & distance > maxRange )
return false ;
else
return true ;
}
}
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
bool CCmpUnitMotion : : ShouldTreatTargetAsCircle ( entity_pos_t range , entity_pos_t hw , entity_pos_t hh , entity_pos_t circleRadius ) const
2010-01-09 11:20:14 -08:00
{
2010-04-29 16:36:05 -07:00
// Given a square, plus a target range we should reach, the shape at that distance
// is a round-cornered square which we can approximate as either a circle or as a square.
// Choose the shape that will minimise the worst-case error:
2010-01-09 11:20:14 -08:00
2010-04-29 16:36:05 -07:00
// For a square, error is (sqrt(2)-1) * range at the corners
entity_pos_t errSquare = ( entity_pos_t : : FromInt ( 4142 ) / 10000 ) . Multiply ( range ) ;
2010-01-09 11:20:14 -08:00
2010-04-29 16:36:05 -07:00
// For a circle, error is radius-hw at the sides and radius-hh at the top/bottom
entity_pos_t errCircle = circleRadius - std : : min ( hw , hh ) ;
2010-01-09 11:20:14 -08:00
2010-04-29 16:36:05 -07:00
return ( errCircle < errSquare ) ;
}
2010-01-09 11:20:14 -08:00
2010-11-30 04:31:54 -08:00
bool CCmpUnitMotion : : MoveToTargetRange ( entity_id_t target , entity_pos_t minRange , entity_pos_t maxRange )
2010-04-29 16:36:05 -07:00
{
2010-11-30 04:31:54 -08:00
PROFILE ( " MoveToTargetRange " ) ;
2010-04-29 16:36:05 -07:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2010-04-29 16:36:05 -07:00
return false ;
2010-07-29 13:39:23 -07:00
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
2010-04-29 16:36:05 -07:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSystemEntity ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpObstructionManager )
2010-04-29 16:36:05 -07:00
return false ;
2011-02-10 08:06:28 -08:00
bool hasObstruction = false ;
ICmpObstructionManager : : ObstructionSquare obstruction ;
2010-05-01 02:48:39 -07:00
CmpPtr < ICmpObstruction > cmpObstruction ( GetSimContext ( ) , target ) ;
2012-02-07 18:46:15 -08:00
if ( cmpObstruction )
2011-02-10 08:06:28 -08:00
hasObstruction = cmpObstruction - > GetObstructionSquare ( obstruction ) ;
2010-04-29 16:36:05 -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
if ( ! hasObstruction )
2010-01-30 05:11:58 -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
// The target didn't have an obstruction or obstruction shape, so treat it as a point instead
2010-04-29 16:36:05 -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
CmpPtr < ICmpPosition > cmpTargetPosition ( GetSimContext ( ) , target ) ;
if ( ! cmpTargetPosition | | ! cmpTargetPosition - > IsInWorld ( ) )
2010-04-29 16:36:05 -07:00
return false ;
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
CFixedVector2D targetPos = cmpTargetPosition - > GetPosition2D ( ) ;
2010-04-29 16:36:05 -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
return MoveToPointRange ( targetPos . X , targetPos . Y , minRange , maxRange ) ;
}
2010-02-12 14:46:53 -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
/*
* If we ' re starting outside the maxRange , we need to move closer in .
* If we ' re starting inside the minRange , we need to move further out .
* These ranges are measured from the center of this entity to the edge of the target ;
* we add the goal range onto the size of the target shape to get the goal shape .
* ( Then we extend it outwards / inwards by a little bit to be sure we ' ll end up
* within the right range , in case of minor numerical inaccuracies . )
*
* There ' s a bit of a problem with large square targets :
* the pathfinder only lets us move to goals that are squares , but the points an equal
* distance from the target make a rounded square shape instead .
*
* When moving closer , we could shrink the goal radius to 1 / sqrt ( 2 ) so the goal shape fits entirely
* within the desired rounded square , but that gives an unfair advantage to attackers who approach
* the target diagonally .
*
* If the target is small relative to the range ( e . g . archers attacking anything ) ,
* then we cheat and pretend the target is actually a circle .
* ( TODO : that probably looks rubbish for things like walls ? )
*
* If the target is large relative to the range ( e . g . melee units attacking buildings ) ,
* then we multiply maxRange by approx 1 / sqrt ( 2 ) to guarantee they ' ll always aim close enough .
* ( Those units should set minRange to 0 so they ' ll never be considered * too * close . )
*/
CFixedVector2D halfSize ( obstruction . hw , obstruction . hh ) ;
PathGoal goal ;
goal . x = obstruction . x ;
goal . z = obstruction . z ;
entity_pos_t distance = Geometry : : DistanceToSquare ( pos - CFixedVector2D ( obstruction . x , obstruction . z ) , obstruction . u , obstruction . v , halfSize ) ;
if ( distance < minRange )
{
// Too close to the square - need to move away
2010-04-29 16:36:05 -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
// TODO: maybe we should do the ShouldTreatTargetAsCircle thing here?
2010-02-12 14:46:53 -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
entity_pos_t goalDistance = minRange + g_GoalDelta ;
2013-12-30 08:07:19 -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
goal . type = PathGoal : : SQUARE ;
goal . u = obstruction . u ;
goal . v = obstruction . v ;
2015-07-18 01:37:49 -07:00
entity_pos_t delta = std : : max ( goalDistance , m_Clearance + entity_pos_t : : FromInt ( TERRAIN_TILE_SIZE ) / 16 ) ; // ensure it's far enough to not intersect the building itself
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
goal . hw = obstruction . hw + delta ;
goal . hh = obstruction . hh + delta ;
}
else if ( maxRange < entity_pos_t : : Zero ( ) | | distance < maxRange )
{
// We're already in range - no need to move anywhere
FaceTowardsPointFromPos ( pos , goal . x , goal . z ) ;
return false ;
}
else
{
// We might need to move closer:
2013-12-30 08:07:19 -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
// Circumscribe the square
entity_pos_t circleRadius = halfSize . Length ( ) ;
2013-12-30 08:07:19 -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
if ( ShouldTreatTargetAsCircle ( maxRange , obstruction . hw , obstruction . hh , circleRadius ) )
{
// The target is small relative to our range, so pretend it's a circle
2010-04-29 16:36:05 -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
// Note that the distance to the circle will always be less than
// the distance to the square, so the previous "distance < maxRange"
// check is still valid (though not sufficient)
entity_pos_t circleDistance = ( pos - CFixedVector2D ( obstruction . x , obstruction . z ) ) . Length ( ) - circleRadius ;
if ( circleDistance < maxRange )
2010-04-29 16:36:05 -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
// We're already in range - no need to move anywhere
if ( m_FacePointAfterMove )
FaceTowardsPointFromPos ( pos , goal . x , goal . z ) ;
return false ;
}
2010-01-30 05:11:58 -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
entity_pos_t goalDistance = maxRange - g_GoalDelta ;
2010-04-29 16:36:05 -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
goal . type = PathGoal : : CIRCLE ;
goal . hw = circleRadius + goalDistance ;
2010-04-29 16:36:05 -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
else
{
// The target is large relative to our range, so treat it as a square and
// get close enough that the diagonals come within range
2010-07-18 08:19:49 -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
entity_pos_t goalDistance = ( maxRange - g_GoalDelta ) * 2 / 3 ; // multiply by slightly less than 1/sqrt(2)
2010-11-30 04:31:54 -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
goal . type = PathGoal : : SQUARE ;
goal . u = obstruction . u ;
goal . v = obstruction . v ;
2015-07-18 01:37:49 -07:00
entity_pos_t delta = std : : max ( goalDistance , m_Clearance + entity_pos_t : : FromInt ( TERRAIN_TILE_SIZE ) / 16 ) ; // ensure it's far enough to not intersect the building itself
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
goal . hw = obstruction . hw + delta ;
goal . hh = obstruction . hh + delta ;
}
2010-04-29 16:36:05 -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
m_State = STATE_INDIVIDUAL_PATH ;
m_TargetEntity = target ;
m_TargetOffset = CFixedVector2D ( ) ;
m_TargetMinRange = minRange ;
m_TargetMaxRange = maxRange ;
m_FinalGoal = goal ;
2010-04-29 16:36:05 -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
BeginPathing ( pos , goal ) ;
2010-04-29 16:36:05 -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
return true ;
2010-07-18 08:19:49 -07:00
}
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
bool CCmpUnitMotion : : IsInTargetRange ( entity_id_t target , entity_pos_t minRange , entity_pos_t maxRange )
2010-07-18 08:19:49 -07:00
{
2010-11-30 04:31:54 -08:00
// This function closely mirrors MoveToTargetRange - it needs to return true
2010-04-29 16:36:05 -07:00
// after that Move has completed
2010-01-30 05:11:58 -08:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2010-04-29 16:36:05 -07:00
return false ;
2010-07-29 13:39:23 -07:00
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
2010-04-29 16:36:05 -07:00
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpObstructionManager > cmpObstructionManager ( GetSystemEntity ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpObstructionManager )
2010-04-29 16:36:05 -07:00
return false ;
2011-02-10 08:06:28 -08:00
bool hasObstruction = false ;
ICmpObstructionManager : : ObstructionSquare obstruction ;
2010-05-01 02:48:39 -07:00
CmpPtr < ICmpObstruction > cmpObstruction ( GetSimContext ( ) , target ) ;
2012-02-07 18:46:15 -08:00
if ( cmpObstruction )
2011-02-10 08:06:28 -08:00
hasObstruction = cmpObstruction - > GetObstructionSquare ( obstruction ) ;
2010-04-29 16:36:05 -07:00
2011-02-10 08:06:28 -08:00
if ( hasObstruction )
2010-04-29 16:36:05 -07:00
{
CFixedVector2D halfSize ( obstruction . hw , obstruction . hh ) ;
entity_pos_t distance = Geometry : : DistanceToSquare ( pos - CFixedVector2D ( obstruction . x , obstruction . z ) , obstruction . u , obstruction . v , halfSize ) ;
2013-12-30 08:07:19 -08:00
// compare with previous obstruction
ICmpObstructionManager : : ObstructionSquare previousObstruction ;
cmpObstruction - > GetPreviousObstructionSquare ( previousObstruction ) ;
entity_pos_t previousDistance = Geometry : : DistanceToSquare ( pos - CFixedVector2D ( previousObstruction . x , previousObstruction . z ) , obstruction . u , obstruction . v , halfSize ) ;
2010-04-29 16:36:05 -07:00
// See if we're too close to the target square
2013-12-30 08:07:19 -08:00
if ( distance < minRange & & previousDistance < minRange )
2010-04-29 16:36:05 -07:00
return false ;
// See if we're close enough to the target square
2013-12-30 08:07:19 -08:00
if ( maxRange < entity_pos_t : : Zero ( ) | | distance < = maxRange | | previousDistance < = maxRange )
2010-04-29 16:36:05 -07:00
return true ;
entity_pos_t circleRadius = halfSize . Length ( ) ;
if ( ShouldTreatTargetAsCircle ( maxRange , obstruction . hw , obstruction . hh , circleRadius ) )
{
// The target is small relative to our range, so pretend it's a circle
// and see if we're close enough to that
entity_pos_t circleDistance = ( pos - CFixedVector2D ( obstruction . x , obstruction . z ) ) . Length ( ) - circleRadius ;
2013-12-30 08:07:19 -08:00
if ( circleDistance < = maxRange )
return true ;
// also check circle around previous position
circleDistance = ( pos - CFixedVector2D ( previousObstruction . x , previousObstruction . z ) ) . Length ( ) - circleRadius ;
2010-04-29 16:36:05 -07:00
if ( circleDistance < = maxRange )
return true ;
}
2010-01-30 05:11:58 -08:00
2010-04-29 16:36:05 -07:00
return false ;
}
else
{
2010-05-01 02:48:39 -07:00
CmpPtr < ICmpPosition > cmpTargetPosition ( GetSimContext ( ) , target ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpTargetPosition | | ! cmpTargetPosition - > IsInWorld ( ) )
2010-04-29 16:36:05 -07:00
return false ;
2013-12-30 08:07:19 -08:00
CFixedVector2D targetPos = cmpTargetPosition - > GetPreviousPosition2D ( ) ;
2010-04-29 16:36:05 -07:00
2010-07-29 13:39:23 -07:00
entity_pos_t distance = ( pos - targetPos ) . Length ( ) ;
2010-04-29 16:36:05 -07:00
2013-12-30 08:07:19 -08:00
return minRange < = distance & &
( maxRange < entity_pos_t : : Zero ( ) | | distance < = maxRange ) ;
2010-04-29 16:36:05 -07:00
}
}
2010-09-03 02:55:14 -07:00
void CCmpUnitMotion : : MoveToFormationOffset ( entity_id_t target , entity_pos_t x , entity_pos_t z )
2010-04-29 16:36:05 -07:00
{
2012-08-31 01:20:36 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetSimContext ( ) , target ) ;
2012-02-07 18:46:15 -08:00
if ( ! cmpPosition | | ! cmpPosition - > IsInWorld ( ) )
2010-01-30 05:11:58 -08:00
return ;
2010-01-29 13:13:18 -08:00
2010-11-30 04:31:54 -08:00
CFixedVector2D pos = cmpPosition - > GetPosition2D ( ) ;
2010-04-29 16:36:05 -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
PathGoal goal ;
goal . type = PathGoal : : POINT ;
2010-11-30 04:31:54 -08:00
goal . x = pos . X ;
goal . z = pos . Y ;
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
m_State = STATE_FORMATIONMEMBER_PATH ;
m_TargetEntity = target ;
m_TargetOffset = CFixedVector2D ( x , z ) ;
m_TargetMinRange = entity_pos_t : : Zero ( ) ;
m_TargetMaxRange = entity_pos_t : : Zero ( ) ;
m_FinalGoal = goal ;
2010-04-29 16:36:05 -07:00
2010-11-30 04:31:54 -08:00
BeginPathing ( pos , goal ) ;
2010-04-29 16:36:05 -07:00
}
2010-11-30 04:31:54 -08:00
2010-04-29 16:36:05 -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
void CCmpUnitMotion : : RenderPath ( const WaypointPath & path , std : : vector < SOverlayLine > & lines , CColor color )
2010-04-29 16:36:05 -07:00
{
2010-05-27 16:23:53 -07:00
bool floating = false ;
2013-09-11 13:41:53 -07:00
CmpPtr < ICmpPosition > cmpPosition ( GetEntityHandle ( ) ) ;
2012-02-07 18:46:15 -08:00
if ( cmpPosition )
2010-05-27 16:23:53 -07:00
floating = cmpPosition - > IsFloating ( ) ;
2010-04-29 16:36:05 -07:00
lines . clear ( ) ;
std : : vector < float > waypointCoords ;
for ( size_t i = 0 ; i < path . m_Waypoints . size ( ) ; + + i )
{
float x = path . m_Waypoints [ i ] . x . ToFloat ( ) ;
float z = path . m_Waypoints [ i ] . z . ToFloat ( ) ;
waypointCoords . push_back ( x ) ;
waypointCoords . push_back ( z ) ;
lines . push_back ( SOverlayLine ( ) ) ;
lines . back ( ) . m_Color = color ;
2010-05-27 16:23:53 -07:00
SimRender : : ConstructSquareOnGround ( GetSimContext ( ) , x , z , 1.0f , 1.0f , 0.0f , lines . back ( ) , floating ) ;
2010-04-29 16:36:05 -07:00
}
lines . push_back ( SOverlayLine ( ) ) ;
lines . back ( ) . m_Color = color ;
2010-05-27 16:23:53 -07:00
SimRender : : ConstructLineOnGround ( GetSimContext ( ) , waypointCoords , lines . back ( ) , floating ) ;
2010-04-29 16:36:05 -07:00
}
2010-05-01 02:48:39 -07:00
void CCmpUnitMotion : : RenderSubmit ( SceneCollector & collector )
2010-04-29 16:36:05 -07:00
{
if ( ! m_DebugOverlayEnabled )
return ;
2015-03-15 16:59:48 -07:00
RenderPath ( m_LongPath , m_DebugOverlayLongPathLines , OVERLAY_COLOR_LONG_PATH ) ;
RenderPath ( m_ShortPath , m_DebugOverlayShortPathLines , OVERLAY_COLOR_SHORT_PATH ) ;
2010-11-30 04:31:54 -08:00
for ( size_t i = 0 ; i < m_DebugOverlayLongPathLines . size ( ) ; + + i )
collector . Submit ( & m_DebugOverlayLongPathLines [ i ] ) ;
2010-04-29 16:36:05 -07:00
for ( size_t i = 0 ; i < m_DebugOverlayShortPathLines . size ( ) ; + + i )
collector . Submit ( & m_DebugOverlayShortPathLines [ i ] ) ;
2010-01-09 11:20:14 -08:00
}