00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef PATHFIND_H_INCLUDED
00022 #define PATHFIND_H_INCLUDED
00023
00024 class gamemap;
00025 class team;
00026 class unit;
00027 class unit_map;
00028 class unit_movement_type;
00029
00030 #include "map_location.hpp"
00031
00032 #include <map>
00033 #include <list>
00034 #include <functional>
00035
00036 namespace pathfind {
00037
00038 class teleport_map;
00039
00040 enum VACANT_TILE_TYPE { VACANT_CASTLE, VACANT_ANY };
00041 enum PATH_TYPE { MOVE, VISION, JAMMING };
00042
00043
00044
00045
00046
00047
00048 map_location find_vacant_tile(const gamemap& map,
00049 const unit_map& un,
00050 const map_location& loc,
00051 VACANT_TILE_TYPE vacancy=VACANT_ANY,
00052 const unit* pass_check=NULL);
00053
00054
00055 bool enemy_zoc(team const ¤t_team, map_location const &loc,
00056 team const &viewing_team, bool see_all=false);
00057
00058
00059 struct cost_calculator
00060 {
00061 cost_calculator() {}
00062
00063 virtual double cost(const map_location& loc, const double so_far) const = 0;
00064 virtual ~cost_calculator() {}
00065
00066 static double getNoPathValue() { return (42424242.0); }
00067 };
00068
00069
00070
00071
00072
00073 struct paths
00074 {
00075 paths()
00076 : destinations()
00077 {
00078 }
00079
00080
00081 paths(gamemap const &map,
00082 unit_map const &,
00083 const unit& u, std::vector<team> const &teams,
00084 bool force_ignore_zocs, bool allow_teleport,
00085 const team &viewing_team, int additional_turns = 0,
00086 bool see_all = false, bool ignore_units = false);
00087
00088 virtual ~paths();
00089
00090 struct step
00091 {
00092 map_location curr, prev;
00093 int move_left;
00094 };
00095
00096
00097 struct dest_vect : std::vector<step>
00098 {
00099 const_iterator find(const map_location &) const;
00100 bool contains(const map_location &) const;
00101 void insert(const map_location &);
00102 std::vector<map_location> get_path(const const_iterator &) const;
00103 };
00104 dest_vect destinations;
00105 };
00106
00107
00108
00109
00110 struct vision_path : public paths
00111 {
00112
00113 vision_path(gamemap const &map, const unit& viewer,
00114 map_location const &loc, const std::map<map_location, int>& jamming_map);
00115 virtual ~vision_path();
00116
00117
00118 std::set<map_location> edges;
00119 };
00120
00121
00122
00123
00124 struct jamming_path : public paths
00125 {
00126
00127 jamming_path(gamemap const &map, const unit& jammer,
00128 map_location const &loc);
00129 virtual ~jamming_path();
00130
00131
00132
00133 };
00134
00135
00136
00137 struct plain_route
00138 {
00139 plain_route() : steps(), move_cost(0) {}
00140 std::vector<map_location> steps;
00141
00142 int move_cost;
00143 };
00144
00145
00146 struct marked_route
00147 {
00148 marked_route()
00149 : route()
00150 , steps(route.steps)
00151 , move_cost(route.move_cost)
00152 , marks()
00153 {
00154 }
00155
00156 marked_route(const marked_route& rhs)
00157 : route(rhs.route)
00158 , steps(route.steps)
00159 , move_cost(route.move_cost)
00160 , marks(rhs.marks)
00161 {
00162 }
00163
00164 marked_route& operator=(const marked_route& rhs)
00165 {
00166 this->route = rhs.route;
00167 this->steps = this->route.steps;
00168 this->move_cost = this->route.move_cost;
00169 this->marks = rhs.marks;
00170 return *this;
00171 }
00172
00173 struct mark
00174 {
00175 mark(int turns_number = 0, bool in_zoc = false,
00176 bool do_capture = false, bool is_invisible = false)
00177 : turns(turns_number), zoc(in_zoc),
00178 capture(do_capture), invisible(is_invisible) {}
00179 int turns;
00180 bool zoc;
00181 bool capture;
00182 bool invisible;
00183
00184 bool operator==(const mark& m) const {
00185 return turns == m.turns && zoc == m.zoc && capture == m.capture && invisible == m.invisible;
00186 }
00187 };
00188 typedef std::map<map_location, mark> mark_map;
00189 plain_route route;
00190
00191
00192 std::vector<map_location>& steps;
00193 int& move_cost;
00194
00195 mark_map marks;
00196 };
00197
00198 plain_route a_star_search(map_location const &src, map_location const &dst,
00199 double stop_at, const cost_calculator* costCalculator,
00200 const size_t parWidth, const size_t parHeight,
00201 const teleport_map* teleports = NULL);
00202
00203
00204
00205
00206
00207 marked_route mark_route(const plain_route &rt);
00208
00209 struct shortest_path_calculator : cost_calculator
00210 {
00211 shortest_path_calculator(const unit& u, const team& t, const unit_map& units,
00212 const std::vector<team> &teams, const gamemap &map,
00213 bool ignore_unit = false, bool ignore_defense_ = false,
00214 bool see_all = false);
00215 virtual double cost(const map_location& loc, const double so_far) const;
00216
00217 private:
00218 unit const &unit_;
00219 team const &viewing_team_;
00220 unit_map const &units_;
00221 std::vector<team> const &teams_;
00222 gamemap const &map_;
00223 int const movement_left_;
00224 int const total_movement_;
00225 bool const ignore_unit_;
00226 bool const ignore_defense_;
00227 bool see_all_;
00228 };
00229
00230 struct move_type_path_calculator : cost_calculator
00231 {
00232 move_type_path_calculator(const unit_movement_type& mt, int movement_left, int total_movement, const team& t, const gamemap& map);
00233 virtual double cost(const map_location& loc, const double so_far) const;
00234
00235 private:
00236 const unit_movement_type &movement_type_;
00237 const int movement_left_;
00238 const int total_movement_;
00239 team const &viewing_team_;
00240 gamemap const &map_;
00241 };
00242
00243
00244
00245
00246
00247 struct emergency_path_calculator : cost_calculator
00248 {
00249 emergency_path_calculator(const unit& u, const gamemap& map);
00250 virtual double cost(const map_location& loc, const double so_far) const;
00251
00252 private:
00253 unit const &unit_;
00254 gamemap const &map_;
00255 };
00256
00257
00258
00259
00260
00261 struct dummy_path_calculator : cost_calculator
00262 {
00263 dummy_path_calculator(const unit& u, const gamemap& map);
00264 virtual double cost(const map_location& loc, const double so_far) const;
00265 };
00266
00267 }
00268
00269 #endif