paths.h

Go to the documentation of this file.
00001 /*
00002  *  Paths.h - Various pathfinding clients.
00003  *
00004  *  Copyright (C) 2000-2001  The Exult Team
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifndef PATHS_H
00022 #define PATHS_H 1
00023 
00024 #include "PathFinder.h"
00025 #include "tiles.h"
00026 #include "rect.h"
00027 #include "chunks.h"
00028 
00029 class Actor;
00030 class Game_object;
00031 class Game_window;
00032 
00033 /*
00034  *  This class provides A* cost methods.
00035  */
00036 class Actor_pathfinder_client : public Pathfinder_client
00037   {
00038   int dist;     // Distance for success.
00039   Actor *npc;     // Who this represents.
00040 public:
00041 //  Actor_pathfinder_client(Actor *npc, int d = 0) : dist(d)
00042 //    { set_move_flags(mf); }
00043   Actor_pathfinder_client(Actor *npc, int d = 0);
00044           // Figure when to give up.
00045   virtual int get_max_cost(int cost_to_goal);
00046           // Figure cost for a single step.
00047   virtual int get_step_cost(Tile_coord from, Tile_coord& to);
00048           // Estimate cost between two points.
00049   virtual int estimate_cost(Tile_coord& from, Tile_coord& to);
00050           // Is tile at the goal?
00051   virtual int at_goal(Tile_coord& tile, Tile_coord& goal);
00052   };
00053 
00054 /*
00055  *  This client succeeds when the path makes it to just one X/Y coord.
00056  *  It assumes that a -1 was placed in the coord. that we should ignore.
00057  */
00058 class Onecoord_pathfinder_client : public Actor_pathfinder_client
00059   {
00060 public:
00061   Onecoord_pathfinder_client(Actor *n) : Actor_pathfinder_client(n)
00062     {  }
00063           // Estimate cost between two points.
00064   virtual int estimate_cost(Tile_coord& from, Tile_coord& to);
00065           // Is tile at the goal?
00066   virtual int at_goal(Tile_coord& tile, Tile_coord& goal);
00067   };
00068 
00069 /*
00070  *  This client succeeds when the path makes it offscreen.
00071  *  Only the tz coord. of the dest. is used.
00072  */
00073 class Offscreen_pathfinder_client : public Actor_pathfinder_client
00074   {
00075   Rectangle screen;   // Screen rect. in tiles.
00076   Tile_coord best;    // Best offscreen pt. to aim for.
00077 public:
00078   Offscreen_pathfinder_client(Actor *n);
00079   Offscreen_pathfinder_client(Actor *n, Tile_coord b);
00080           // Figure cost for a single step.
00081   virtual int get_step_cost(Tile_coord from, Tile_coord& to);
00082           // Estimate cost between two points.
00083   virtual int estimate_cost(Tile_coord& from, Tile_coord& to);
00084           // Is tile at the goal?
00085   virtual int at_goal(Tile_coord& tile, Tile_coord& goal);
00086   };
00087 
00088 /*
00089  *  This client is supposed to fail quickly, so that it can be used to
00090  *  test for when an object can be grabbed.
00091  */
00092 class Fast_pathfinder_client : public Pathfinder_client
00093   {
00094   int dist;     // Succeeds at this distance from goal.
00095 public:
00096   Fast_pathfinder_client(int d = 0, int mf = 1 << 5) : dist(d)
00097     { set_move_flags(mf); }
00098           // Figure when to give up.
00099   virtual int get_max_cost(int cost_to_goal);
00100           // Figure cost for a single step.
00101   virtual int get_step_cost(Tile_coord from, Tile_coord& to);
00102           // Estimate cost between two points.
00103   virtual int estimate_cost(Tile_coord& from, Tile_coord& to);
00104           // Is tile at the goal?
00105   virtual int at_goal(Tile_coord& tile, Tile_coord& goal);
00106   static int is_grabable(Tile_coord from, Tile_coord to);
00107           // Check for unblocked straight path.
00108   static int is_straight_path(Tile_coord from, Tile_coord to);
00109   };
00110 
00111 /*
00112  *  Pathfinding for monsters, who may be bigger than 1x1:
00113  */
00114 class Monster_pathfinder_client : public Fast_pathfinder_client
00115   {
00116   Rectangle destbox;    // Got to intersect this box.
00117   int intelligence;   // NPC's intelligence.
00118   int axtiles, aytiles, aztiles;  // NPC's dims. in tiles.
00119 public:
00120   Monster_pathfinder_client(Actor *npc, Tile_coord dest, int dist);
00121           // For combat:
00122   Monster_pathfinder_client(Actor *attacker, int reach,
00123             Game_object *opponent);
00124           // Figure when to give up.
00125   virtual int get_max_cost(int cost_to_goal);
00126           // Is tile at the goal?
00127   virtual int at_goal(Tile_coord& tile, Tile_coord& goal);
00128           // Figure cost for a single step.
00129   virtual int get_step_cost(Tile_coord from, Tile_coord& to);
00130   };
00131 
00132 
00133 #endif  /* INCL_PATHS */
00134 

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