00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef PATHFIND_H_INCLUDED
00019 #define PATHFIND_H_INCLUDED
00020
00021 class gamestatus;
00022 class unit;
00023 class unit_map;
00024
00025 #include "array.hpp"
00026 #include "map.hpp"
00027 #include "pathutils.hpp"
00028 #include "team.hpp"
00029
00030 #include <map>
00031 #include <list>
00032 #include <set>
00033 #include <vector>
00034 #include <functional>
00035
00036
00037
00038
00039 typedef util::array<gamemap::location,6> adjacent_tiles_array;
00040
00041 class xy_pred : public std::unary_function<gamemap::location const&, bool>
00042 {
00043 public:
00044 virtual bool operator()(gamemap::location const&) = 0;
00045 protected:
00046 virtual ~xy_pred() {}
00047 };
00048
00049
00050 void get_tiles_radius(const gamemap::location& a, size_t radius,
00051 std::set<gamemap::location>& res);
00052
00053
00054 void get_tiles_radius(const gamemap& map, const std::vector<gamemap::location>& locs, size_t radius,
00055 std::set<gamemap::location>& res, xy_pred *pred=NULL);
00056
00057 enum VACANT_TILE_TYPE { VACANT_CASTLE, VACANT_ANY };
00058
00059
00060
00061
00062
00063
00064 gamemap::location find_vacant_tile(const gamemap& map,
00065 const unit_map& un,
00066 const gamemap::location& loc,
00067 VACANT_TILE_TYPE vacancy=VACANT_ANY);
00068
00069
00070 bool enemy_zoc(gamemap const &map,
00071 unit_map const &units,
00072 std::vector<team> const &teams, gamemap::location const &loc,
00073 team const &viewing_team, unsigned int side, bool see_all=false);
00074
00075 struct cost_calculator
00076 {
00077 virtual double cost(const gamemap::location& src, const gamemap::location& loc, const double so_far) const = 0;
00078 virtual ~cost_calculator() {}
00079 inline double getNoPathValue(void) const { return (42424242.0); }
00080 };
00081
00082
00083
00084 struct paths
00085 {
00086 paths() : routes() {}
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 paths(gamemap const &map,
00097 unit_map const &units,
00098 gamemap::location const &loc, std::vector<team> const &teams,
00099 bool force_ignore_zocs,bool allow_teleport,
00100 const team &viewing_team,int additional_turns = 0,
00101 bool see_all = false, bool ignore_units = false);
00102
00103
00104 struct route
00105 {
00106 route() : steps(), move_left(0), waypoints() {}
00107 std::vector<gamemap::location> steps;
00108 int move_left;
00109 struct waypoint
00110 {
00111 waypoint(int turns_number = 0, bool in_zoc = false,
00112 bool do_capture = false, bool is_invisible = false)
00113 : turns(turns_number), zoc(in_zoc),
00114 capture(do_capture), invisible(is_invisible) {}
00115 int turns;
00116 bool zoc;
00117 bool capture;
00118 bool invisible;
00119 };
00120 std::map<gamemap::location, waypoint> waypoints;
00121 };
00122
00123 typedef std::map<gamemap::location,route> routes_map;
00124 routes_map routes;
00125 };
00126
00127 paths::route a_star_search(gamemap::location const &src, gamemap::location const &dst,
00128 double stop_at, cost_calculator const *costCalculator,
00129 const size_t parWidth, const size_t parHeight,
00130 std::set<gamemap::location> const *teleports = NULL);
00131
00132
00133
00134
00135
00136 int route_turns_to_complete(const unit& u, paths::route& rt, const team &viewing_team,
00137 const unit_map& units, const std::vector<team>& teams, const gamemap& map);
00138
00139 struct shortest_path_calculator : cost_calculator
00140 {
00141 shortest_path_calculator(const unit& u, const team& t, const unit_map& units,
00142 const std::vector<team>& teams, const gamemap& map,
00143 bool ignore_unit = false, bool ignore_defense_ = false);
00144 virtual double cost(const gamemap::location& src, const gamemap::location& loc, const double so_far) const;
00145
00146 private:
00147 unit const &unit_;
00148 team const &viewing_team_;
00149 unit_map const &units_;
00150 std::vector<team> const &teams_;
00151 gamemap const &map_;
00152 int const movement_left_;
00153 int const total_movement_;
00154 bool const ignore_unit_;
00155 bool const ignore_defense_;
00156 };
00157
00158
00159
00160 struct emergency_path_calculator : cost_calculator
00161 {
00162 emergency_path_calculator(const unit& u, const gamemap& map);
00163 virtual double cost(const gamemap::location& src, const gamemap::location& loc, const double so_far) const;
00164
00165 private:
00166 unit const &unit_;
00167 gamemap const &map_;
00168 };
00169
00170 #endif