00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef AI_PYTHON_HPP_INCLUDED
00019 #define AI_PYTHON_HPP_INCLUDED
00020
00021 #include "ai_interface.hpp"
00022 #include "menu_events.hpp"
00023 #undef _POSIX_C_SOURCE // avoids a spurious compiler warning
00024 #include <Python.h>
00025
00026 typedef struct {
00027 PyObject_HEAD
00028 const unit_type* unit_type_;
00029 } wesnoth_unittype;
00030
00031 typedef struct {
00032 PyObject_HEAD
00033 const team* team_;
00034 } wesnoth_team;
00035
00036 typedef struct {
00037 PyObject_HEAD
00038 const unit* unit_;
00039 } wesnoth_unit;
00040
00041 #define W(name) static PyObject *wrapper_##name(PyObject* self, PyObject* args)
00042 class python_ai : public ai_interface
00043 {
00044 public:
00045 python_ai(ai_interface::info& info);
00046 virtual ~python_ai();
00047 virtual void play_turn();
00048
00049 static PyObject* wrapper_unit_movement_cost(wesnoth_unit*, PyObject* args);
00050 static PyObject* wrapper_unit_defense_modifier(wesnoth_unit*, PyObject* args);
00051 static PyObject* wrapper_unittype_movement_cost(wesnoth_unittype*, PyObject* args);
00052 static PyObject* wrapper_unittype_defense_modifier(wesnoth_unittype*, PyObject* args);
00053
00054 W(team_targets);
00055 W(get_units);
00056 W(log_message);
00057 W(log);
00058 W(get_location);
00059 W(get_map);
00060 W(get_teams);
00061 W(get_current_team);
00062 W(get_src_dst);
00063 W(get_dst_src);
00064 W(get_enemy_src_dst);
00065 W(get_enemy_dst_src);
00066 W(move_unit);
00067 W(attack_unit);
00068 W(get_adjacent_tiles);
00069 W(recruit_unit);
00070 W(get_gamestatus);
00071 W(set_variable);
00072 W(get_variable);
00073 W(get_version);
00074 W(raise_user_interact);
00075 W(test_move);
00076
00077 static PyObject* unittype_advances_to( wesnoth_unittype* type, PyObject* args );
00078 static PyObject* wrapper_team_recruits( wesnoth_team* team, PyObject* args );
00079 static PyObject* wrapper_unit_find_path( wesnoth_unit* unit, PyObject* args );
00080 static PyObject* wrapper_unit_attack_statistics(wesnoth_unit* unit, PyObject* args);
00081
00082 static bool is_unit_valid(const unit* unit);
00083 std::vector<team>& get_teams() { return get_info().teams; }
00084 static std::vector<std::string> get_available_scripts();
00085 static void initialize_python();
00086 static void invoke(std::string name);
00087
00088 friend void recalculate_movemaps();
00089 private:
00090 static bool init_;
00091
00092 end_level_exception exception;
00093 ai_interface::move_map src_dst_;
00094 ai_interface::move_map dst_src_;
00095 std::map<location,paths> possible_moves_;
00096 ai_interface::move_map enemy_src_dst_;
00097 ai_interface::move_map enemy_dst_src_;
00098 std::map<location,paths> enemy_possible_moves_;
00099 };
00100 #undef W
00101
00102 #endif