PathFinder.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef PATHFINDER_H
00020 #define PATHFINDER_H
00021 
00022 #include "tiles.h"
00023 
00024 /*
00025  *  This class provides A* cost methods.
00026  */
00027 class Pathfinder_client
00028   {
00029 private:
00030   int   move_flags;
00031 public:
00032           // Figure when to give up.
00033   virtual int get_max_cost(int cost_to_goal);
00034           // Figure cost for a single step.
00035   virtual int get_step_cost(Tile_coord from, Tile_coord& to) = 0;
00036           // Estimate cost between two points.
00037   virtual int estimate_cost(Tile_coord& from, Tile_coord& to) = 0;
00038           // Is tile at the goal?
00039   virtual int at_goal(Tile_coord& tile, Tile_coord& goal);
00040 
00041   int get_move_flags() { return move_flags; }
00042   void set_move_flags(int m) { move_flags = m;}
00043   };
00044 
00045 /*
00046  *  Base class for all PathFinders.
00047  */
00048 class PathFinder
00049   {
00050 protected:
00051   Tile_coord src;     // Source tile.
00052   Tile_coord dest;    // Destination.
00053 public:
00054   // Find a path from sx,sy,sz to dx,dy,dz
00055   // Return 0 if no path can be traced.
00056   // Return !0 if path found
00057   PathFinder() : src(),dest()
00058     {  }
00059   virtual int NewPath(Tile_coord s, Tile_coord d, 
00060           Pathfinder_client *client)=0;
00061   // Retrieve starting point (set by subclasses).
00062   Tile_coord get_src()
00063     { return src; }
00064   // Retrieve current destination (set by subclasses).
00065   Tile_coord get_dest()
00066     { return dest; }
00067   // Retrieve the coordinates of the next step on the path
00068   virtual int GetNextStep(Tile_coord& n, bool& done)=0;
00069   int GetNextStep(Tile_coord& n)
00070     {     // If you don't care about last step.
00071     bool d;
00072     return GetNextStep(n, d);
00073     }
00074   // Set to retrieve in opposite order.
00075   virtual int set_backwards()
00076     { return 0; }   // Default: Can't do it.
00077   virtual int following_smart_path()  // Astar?
00078     { return 0; }
00079   virtual int get_num_steps() = 0;// # of steps left to take.
00080   virtual ~PathFinder();
00081   };
00082 
00083 #endif

Generated on Mon Jul 9 14:42:49 2007 for ExultEngine by  doxygen 1.5.1