00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef AI_INTERFACE_HPP_INCLUDED
00019 #define AI_INTERFACE_HPP_INCLUDED
00020
00021 class game_display;
00022 class gamemap;
00023
00024 #include "formula_callable.hpp"
00025 #include "generic_event.hpp"
00026 #include "pathfind.hpp"
00027 #include "gamestatus.hpp"
00028
00029 class ai_interface : public game_logic::formula_callable {
00030 public:
00031
00032
00033 typedef gamemap::location location;
00034
00035
00036 typedef std::multimap<location,location> move_map;
00037
00038
00039
00040 struct info {
00041 info(game_display& disp, const gamemap& map, unit_map& units,
00042 std::vector<team>& teams, unsigned int team_num, const gamestatus& state, class turn_info& turn_data, class game_state& game_state)
00043 : disp(disp), map(map), units(units), teams(teams),
00044 team_num(team_num), state(state), turn_data_(turn_data), game_state_(game_state) {}
00045
00046
00047 game_display& disp;
00048
00049
00050 const gamemap& map;
00051
00052
00053 unit_map& units;
00054
00055
00056 std::vector<team>& teams;
00057
00058
00059
00060
00061 unsigned int team_num;
00062
00063
00064 const gamestatus& state;
00065
00066
00067
00068 class turn_info& turn_data_;
00069
00070
00071 class game_state& game_state_;
00072 };
00073
00074
00075
00076
00077 ai_interface(info& arg) : info_(arg), last_interact_(0), user_interact_("ai_user_interact"),
00078 unit_recruited_("ai_unit_recruited"), unit_moved_("ai_unit_moved"),
00079 enemy_attacked_("ai_enemy_attacked") {}
00080 virtual ~ai_interface() {}
00081
00082
00083
00084 virtual void play_turn() = 0;
00085
00086
00087 team& current_team() { return info_.teams[info_.team_num-1]; }
00088 const team& current_team() const { return info_.teams[info_.team_num-1]; }
00089
00090
00091 void diagnostic(const std::string& msg);
00092
00093
00094 void log_message(const std::string& msg);
00095
00096
00097 events::generic_event& user_interact() { return user_interact_; }
00098 events::generic_event& unit_recruited() { return unit_recruited_; }
00099 events::generic_event& unit_moved() { return unit_moved_; }
00100 events::generic_event& enemy_attacked() { return enemy_attacked_; }
00101
00102 protected:
00103
00104 void attack_enemy(const location u, const location target, int att_weapon, int def_weapon);
00105
00106
00107
00108
00109
00110
00111 location move_unit(location from, location to, std::map<location,paths>& possible_moves);
00112
00113
00114
00115 location move_unit_partial(location from, location t, std::map<location,paths>& possible_moves);
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 void calculate_possible_moves(std::map<location,paths>& possible_moves, move_map& srcdst, move_map& dstsrc, bool enemy, bool assume_full_movement=false,
00130 const std::set<location>* remove_destinations=NULL) const;
00131
00132
00133
00134 void calculate_moves(const unit_map& units, std::map<location,paths>& possible_moves, move_map& srcdst, move_map& dstsrc, bool enemy, bool assume_full_movement=false,
00135 const std::set<location>* remove_destinations=NULL, bool see_all=false) const;
00136
00137
00138
00139
00140
00141
00142
00143
00144 bool recruit(const std::string& unit_name, location loc=location());
00145
00146
00147
00148 info& get_info() { return info_; }
00149 const info& get_info() const { return info_; }
00150
00151
00152
00153
00154
00155 void raise_user_interact();
00156
00157
00158 void raise_unit_recruited() { unit_recruited_.notify_observers(); }
00159 void raise_unit_moved() { unit_moved_.notify_observers(); }
00160 void raise_enemy_attacked() { enemy_attacked_.notify_observers(); }
00161 protected:
00162 virtual void get_inputs(std::vector<game_logic::formula_input>* inputs) const;
00163 virtual variant get_value(const std::string& key) const;
00164 private:
00165 info info_;
00166 int last_interact_;
00167 events::generic_event user_interact_;
00168 events::generic_event unit_recruited_;
00169 events::generic_event unit_moved_;
00170 events::generic_event enemy_attacked_;
00171 };
00172
00173
00174 std::vector<std::string> get_available_ais();
00175
00176 ai_interface* create_ai(const std::string& algorithm_name, ai_interface::info& info);
00177
00178 #endif