Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef PLAY_CONTROLLER_H_INCLUDED
00018 #define PLAY_CONTROLLER_H_INCLUDED
00019
00020 #include "actions.hpp"
00021 #include "controller_base.hpp"
00022 #include "game_end_exceptions.hpp"
00023 #include "help.hpp"
00024 #include "menu_events.hpp"
00025 #include "mouse_events.hpp"
00026 #include "persist_manager.hpp"
00027 #include "statistics.hpp"
00028 #include "tod_manager.hpp"
00029
00030 #include <boost/scoped_ptr.hpp>
00031
00032 class game_display;
00033 class game_state;
00034 class team;
00035 struct wml_menu_item;
00036
00037 namespace game_events {
00038 struct manager;
00039 }
00040
00041 namespace halo {
00042 struct manager;
00043 }
00044
00045 namespace preferences {
00046 struct display_manager;
00047 }
00048
00049 namespace soundsource {
00050 class manager;
00051 }
00052
00053 namespace pathfind {
00054 class manager;
00055 }
00056
00057 namespace tooltips {
00058 struct manager;
00059 }
00060
00061 namespace wb {
00062 class manager;
00063 }
00064
00065 class play_controller : public controller_base, public events::observer, public savegame::savegame_config
00066 {
00067 public:
00068 play_controller(const config& level, game_state& state_of_game,
00069 int ticks, int num_turns, const config& game_config, CVideo& video, bool skip_replay);
00070 virtual ~play_controller();
00071
00072
00073
00074 virtual void handle_generic_event(const std::string& ) {}
00075
00076
00077 virtual void objectives();
00078 virtual void show_statistics();
00079 virtual void unit_list();
00080 virtual void left_mouse_click();
00081 virtual void right_mouse_click();
00082 virtual void status_table();
00083 virtual void save_game();
00084 virtual void save_replay();
00085 virtual void save_map();
00086 virtual void load_game();
00087 virtual void preferences();
00088 virtual void show_chat_log();
00089 virtual void show_help();
00090 virtual void cycle_units();
00091 virtual void cycle_back_units();
00092 virtual void undo();
00093 virtual void redo();
00094 virtual void show_enemy_moves(bool ignore_units);
00095 virtual void goto_leader();
00096 virtual void unit_description();
00097 virtual void toggle_ellipses();
00098 virtual void toggle_grid();
00099 virtual void search();
00100
00101 virtual void maybe_do_init_side(const unsigned int team_index, bool is_replay = false);
00102 virtual void do_init_side(const unsigned int team_index, bool is_replay = false);
00103 virtual void play_side(const unsigned int side_number, bool save) = 0;
00104
00105 virtual void force_end_turn() = 0;
00106 virtual void force_end_level(LEVEL_RESULT res) = 0;
00107 virtual void check_end_level() = 0;
00108
00109
00110
00111
00112 virtual void process_oos(const std::string& msg) const;
00113
00114 void set_victory_when_enemies_defeated(bool e)
00115 { victory_when_enemies_defeated_ = e; }
00116 end_level_data& get_end_level_data() {
00117 return end_level_data_;
00118 }
00119 const end_level_data& get_end_level_data_const() const {
00120 return end_level_data_;
00121 }
00122
00123
00124
00125
00126
00127 void check_victory();
00128
00129 size_t turn() const {return tod_manager_.turn();}
00130
00131
00132 int current_side() const { return player_number_; }
00133
00134 config to_config() const;
00135
00136 bool is_skipping_replay() const { return skip_replay_;}
00137 bool is_linger_mode() const { return linger_; }
00138
00139 events::mouse_handler& get_mouse_handler_base();
00140 events::menu_handler& get_menu_handler() { return menu_handler_; }
00141
00142 std::map< std::string, std::vector<unit_animation> > animation_cache;
00143 protected:
00144 void slice_before_scroll();
00145
00146 game_display& get_display();
00147 bool have_keyboard_focus();
00148 void process_focus_keydown_event(const SDL_Event& event);
00149 void process_keydown_event(const SDL_Event& event);
00150 void process_keyup_event(const SDL_Event& event);
00151 void post_mouse_press(const SDL_Event& event);
00152
00153 virtual std::string get_action_image(hotkey::HOTKEY_COMMAND, int index) const;
00154 virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const;
00155
00156 virtual bool can_execute_command(hotkey::HOTKEY_COMMAND command, int index=-1) const;
00157 virtual bool execute_command(hotkey::HOTKEY_COMMAND command, int index=-1);
00158 void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu);
00159
00160
00161
00162
00163
00164 bool in_context_menu(hotkey::HOTKEY_COMMAND command) const;
00165
00166 void init_managers();
00167 void fire_prestart(bool execute);
00168 void fire_start(bool execute);
00169 virtual void init_gui();
00170 virtual void init_side(const unsigned int team_index, bool is_replay = false);
00171 void place_sides_in_preferred_locations();
00172 virtual void finish_side_turn();
00173 void finish_turn();
00174 bool enemies_visible() const;
00175
00176 void enter_textbox();
00177 void tab();
00178
00179 std::string get_unique_saveid(const config& cfg, std::set<std::string>& seen_save_ids);
00180
00181 team& current_team();
00182 const team& current_team() const;
00183
00184
00185 int find_human_team_before(const size_t team) const;
00186
00187
00188 boost::scoped_ptr<preferences::display_manager> prefs_disp_manager_;
00189 boost::scoped_ptr<tooltips::manager> tooltips_manager_;
00190 boost::scoped_ptr<game_events::manager> events_manager_;
00191 boost::scoped_ptr<halo::manager> halo_manager_;
00192 font::floating_label_context labels_manager_;
00193 help::help_manager help_manager_;
00194 events::mouse_handler mouse_handler_;
00195 events::menu_handler menu_handler_;
00196 boost::scoped_ptr<soundsource::manager> soundsources_manager_;
00197 tod_manager tod_manager_;
00198 boost::scoped_ptr<pathfind::manager> pathfind_manager_;
00199 persist_manager persist_;
00200
00201
00202 boost::scoped_ptr<game_display> gui_;
00203 const statistics::scenario_context statistics_context_;
00204 const config& level_;
00205 std::vector<team> teams_;
00206 game_state& gamestate_;
00207 gamemap map_;
00208 unit_map units_;
00209 undo_list undo_stack_;
00210 undo_list redo_stack_;
00211
00212
00213 boost::scoped_ptr<wb::manager> whiteboard_manager_;
00214
00215 const unit_type::experience_accelerator xp_mod_;
00216
00217
00218 bool loading_game_;
00219
00220 int first_human_team_;
00221 int player_number_;
00222 int first_player_;
00223 unsigned int start_turn_;
00224 bool is_host_;
00225 bool skip_replay_;
00226 bool linger_;
00227 bool it_is_a_new_turn_;
00228 bool init_side_done_;
00229
00230 const std::string& select_victory_music() const;
00231 const std::string& select_defeat_music() const;
00232
00233 void set_victory_music_list(const std::string& list);
00234 void set_defeat_music_list(const std::string& list);
00235
00236
00237
00238
00239 void update_gui_to_player(const int team_index, const bool observe = false);
00240
00241 private:
00242 void init(CVideo &video);
00243
00244 void expand_autosaves(std::vector<std::string>& items);
00245 std::vector<std::string> savenames_;
00246
00247 void expand_wml_commands(std::vector<std::string>& items);
00248 std::vector<wml_menu_item *> wml_commands_;
00249 static const size_t MAX_WML_COMMANDS = 7;
00250
00251 bool victory_when_enemies_defeated_;
00252 end_level_data end_level_data_;
00253 std::vector<std::string> victory_music_;
00254 std::vector<std::string> defeat_music_;
00255 };
00256
00257
00258 #endif