2007-01-15 12:09:25 -08:00
/*
This file is part of Warzone 2100.
Copyright ( C ) 1999 - 2004 Eidos Interactive
2013-01-16 12:34:57 -08:00
Copyright ( C ) 2005 - 2013 Warzone 2100 Project
2007-01-15 12:09:25 -08:00
Warzone 2100 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 .
Warzone 2100 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 Warzone 2100 ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
*/
2008-03-21 14:37:01 -07:00
/** @file
* Interface to the routing functions
2007-06-28 10:47:08 -07:00
*/
2008-03-21 14:37:01 -07:00
# ifndef __INCLUDED_SRC_FPATH_H__
# define __INCLUDED_SRC_FPATH_H__
2007-06-28 10:47:08 -07:00
2008-04-15 15:54:37 -07:00
# include "droiddef.h"
2008-04-20 17:12:10 -07:00
/** Return values for routing
*
* @ ingroup pathfinding
2008-09-07 14:44:06 -07:00
* @ {
2008-04-20 17:12:10 -07:00
*/
2009-05-13 13:05:33 -07:00
2011-01-07 09:17:01 -08:00
enum FPATH_MOVETYPE
2009-05-26 11:55:12 -07:00
{
FMT_MOVE , ///< Move around all obstacles
FMT_ATTACK , ///< Assume that we will destroy enemy obstacles
2011-02-28 13:58:19 -08:00
FMT_BLOCK , ///< Don't go through obstacles, not even gates.
2011-01-07 09:17:01 -08:00
} ;
2009-05-26 11:55:12 -07:00
2011-01-07 09:17:01 -08:00
struct PathBlockingMap ;
struct PATHJOB
2009-05-13 13:05:33 -07:00
{
PROPULSION_TYPE propulsion ;
DROID_TYPE droidType ;
int destX , destY ;
int origX , origY ;
2011-12-24 11:07:31 -08:00
StructureBounds dstStructure ;
2009-05-13 13:05:33 -07:00
UDWORD droidID ;
2009-05-26 11:55:12 -07:00
FPATH_MOVETYPE moveType ;
int owner ; ///< Player owner
2011-01-07 09:17:01 -08:00
PathBlockingMap * blockingMap ; ///< Map of blocking tiles.
2010-08-15 02:09:29 -07:00
bool acceptNearest ;
2011-01-07 09:17:01 -08:00
bool deleted ; ///< Droid was deleted, so throw away result when complete. Must still process this PATHJOB, since processing order can affect resulting paths (but can't affect the path length).
} ;
2009-05-13 13:05:33 -07:00
2011-01-07 09:17:01 -08:00
enum FPATH_RETVAL
2007-06-28 10:47:08 -07:00
{
2008-04-20 17:12:10 -07:00
FPR_OK , ///< found a route
FPR_FAILED , ///< failed to find a route
2008-08-02 07:37:53 -07:00
FPR_WAIT , ///< route is being calculated by the path-finding thread
2011-01-07 09:17:01 -08:00
} ;
2007-06-28 10:47:08 -07:00
2008-04-20 17:12:10 -07:00
/** Initialise the path-finding module.
*/
2011-03-12 17:32:15 -08:00
extern bool fpathInitialise ( void ) ;
2007-06-28 10:47:08 -07:00
2008-05-09 12:57:51 -07:00
/** Shutdown the path-finding module.
*/
extern void fpathShutdown ( void ) ;
2007-06-28 10:47:08 -07:00
extern void fpathUpdate ( void ) ;
2008-04-20 17:12:10 -07:00
/** Find a route for a droid to a location.
*/
2010-02-09 14:35:23 -08:00
extern FPATH_RETVAL fpathDroidRoute ( DROID * psDroid , SDWORD targetX , SDWORD targetY , FPATH_MOVETYPE moveType ) ;
2007-06-28 10:47:08 -07:00
2010-07-12 07:17:55 -07:00
/// Returns true iff the parameters have equivalent behaviour in fpathBaseBlockingTile.
bool fpathIsEquivalentBlocking ( PROPULSION_TYPE propulsion1 , int player1 , FPATH_MOVETYPE moveType1 ,
PROPULSION_TYPE propulsion2 , int player2 , FPATH_MOVETYPE moveType2 ) ;
2008-04-20 17:12:10 -07:00
/** Function pointer to the currently in-use blocking tile check function.
*
2010-11-02 13:30:39 -07:00
* This function will check if the map tile at the given location should be considered to block droids
* with the currently selected propulsion type . This is not identical to whether it will actually block ,
* which can depend on hostilities and open / closed attributes .
*
* fpathBlockingTile - - when it is irrelevant who owns what buildings , they all block unless propulsion is right
* fpathDroidBlockingTile - - when you may want to factor the above into account
* fpathBaseBlockingTile - - set all parameters ; the others are convenience functions for this one
2008-04-20 17:12:10 -07:00
*
* @ return true if the given tile is blocking for this droid
*/
2011-03-12 17:32:15 -08:00
bool fpathBlockingTile ( SDWORD x , SDWORD y , PROPULSION_TYPE propulsion ) ;
bool fpathDroidBlockingTile ( DROID * psDroid , int x , int y , FPATH_MOVETYPE moveType ) ;
bool fpathBaseBlockingTile ( SDWORD x , SDWORD y , PROPULSION_TYPE propulsion , int player , FPATH_MOVETYPE moveType ) ;
2007-06-28 10:47:08 -07:00
2011-12-30 08:43:49 -08:00
static inline bool fpathBlockingTile ( Vector2i tile , PROPULSION_TYPE propulsion ) { return fpathBlockingTile ( tile . x , tile . y , propulsion ) ; }
2008-04-20 17:12:10 -07:00
/** Set a direct path to position.
*
* Plan a path from @ c psDroid ' s current position to given position without
* taking obstructions into consideration .
*
2008-08-02 07:37:53 -07:00
* Used for instance by VTOLs . Function is thread - safe .
2008-01-12 10:04:39 -08:00
*/
2008-04-15 15:54:37 -07:00
extern void fpathSetDirectRoute ( DROID * psDroid , SDWORD targetX , SDWORD targetY ) ;
2007-06-28 10:47:08 -07:00
2008-08-02 07:37:53 -07:00
/** Clean up path jobs and results for a droid. Function is thread-safe. */
extern void fpathRemoveDroidData ( int id ) ;
2009-05-28 13:06:39 -07:00
/** Quick O(1) test of whether it is theoretically possible to go from origin to destination
2010-03-03 11:19:48 -08:00
* using the given propulsion type . orig and dest are in world coordinates . */
bool fpathCheck ( Position orig , Position dest , PROPULSION_TYPE propulsion ) ;
2009-05-28 13:06:39 -07:00
2008-09-07 14:44:06 -07:00
/** Unit testing. */
2008-08-02 07:37:53 -07:00
void fpathTest ( int x , int y , int x2 , int y2 ) ;
2008-09-07 14:44:06 -07:00
/** @} */
2008-03-21 14:37:01 -07:00
# endif // __INCLUDED_SRC_FPATH_H__