00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef GAME_DISPLAY_H_INCLUDED
00019 #define GAME_DISPLAY_H_INCLUDED
00020
00021 class config;
00022 class gamestatus;
00023 class team;
00024 class unit;
00025 class unit_map;
00026
00027 #include "display.hpp"
00028 #include "image.hpp"
00029 #include "pathfind.hpp"
00030
00031 #include "SDL.h"
00032
00033 #include <map>
00034 #include <set>
00035 #include <string>
00036
00037
00038
00039
00040
00041 class game_display : public display
00042 {
00043 public:
00044 game_display(unit_map& units, CVideo& video,
00045 const gamemap& map, const gamestatus& status,
00046 const std::vector<team>& t, const config& theme_cfg,
00047 const config& cfg, const config& level);
00048 ~game_display();
00049 static game_display* get_singleton() { return singleton_ ;}
00050
00051
00052
00053 void new_turn();
00054
00055
00056
00057 void adjust_colours(int r, int g, int b);
00058
00059
00060
00061 void scroll_to_leader(unit_map& units, int side, SCROLL_TYPE scroll_type = ONSCREEN);
00062
00063
00064 void draw(bool update=true,bool force=false);
00065
00066
00067
00068
00069
00070 virtual void select_hex(gamemap::location hex);
00071
00072
00073
00074
00075
00076 virtual void highlight_hex(gamemap::location hex);
00077
00078
00079
00080 void display_unit_hex(gamemap::location hex);
00081
00082
00083
00084
00085 void highlight_reach(const paths &paths_list);
00086
00087
00088
00089 void highlight_another_reach(const paths &paths_list);
00090
00091
00092 void unhighlight_reach();
00093
00094
00095
00096 void set_route(const paths::route* route);
00097
00098
00099 void float_label(const gamemap::location& loc, const std::string& text,
00100 int red, int green, int blue);
00101
00102
00103
00104 std::vector<surface> footsteps_images(const gamemap::location& loc);
00105
00106
00107 void draw_movement_info(const gamemap::location& loc);
00108
00109
00110 void invalidate(const gamemap::location& loc);
00111
00112 const gamestatus &get_game_status() { return status_; }
00113 void draw_report(reports::TYPE report_num);
00114
00115
00116 void invalidate_unit() { invalidateUnit_ = true; }
00117
00118
00119 void invalidate_unit_after_move(const gamemap::location& src, const gamemap::location& dst);
00120
00121 private:
00122
00123 void invalidate_animations();
00124
00125 virtual void draw_minimap_units();
00126
00127 public:
00128
00129 void place_temporary_unit(unit &u, const gamemap::location& loc);
00130 void remove_temporary_unit();
00131
00132
00133 void set_attack_indicator(const gamemap::location& src, const gamemap::location& dst);
00134 void clear_attack_indicator();
00135
00136 const std::string attack_indicator_direction() const
00137 { return gamemap::location::write_direction(
00138 attack_indicator_src_.get_relative_dir(attack_indicator_dst_)); }
00139
00140
00141
00142
00143 void add_overlay(const gamemap::location& loc, const std::string& image, const std::string& halo="");
00144
00145 void remove_overlay(const gamemap::location& loc);
00146
00147 void remove_single_overlay(const gamemap::location& loc, const std::string& toDelete);
00148
00149
00150 void write_overlays(config& cfg) const;
00151
00152
00153
00154
00155
00156 t_translation::t_terrain get_terrain_on(int palx, int paly, int x, int y);
00157
00158
00159
00160
00161 void set_team(size_t team, bool observe=false);
00162 void set_playing_team(size_t team);
00163 size_t get_playing_team() const {return activeTeam_;};
00164 const std::vector<team>& get_teams() {return teams_;};
00165
00166 unit_map& get_units() {return units_;};
00167 const unit_map& get_const_units() const {return units_;};
00168
00169
00170
00171 static void debug_highlight(const gamemap::location& loc, fixed_t amount);
00172 static void clear_debug_highlights() { debugHighlights_.clear(); }
00173
00174
00175 size_t viewing_team() const { return currentTeam_; }
00176
00177 size_t playing_team() const { return activeTeam_; }
00178
00179 bool team_valid() const { return currentTeam_ < teams_.size(); }
00180 const std::string current_team_name() const;
00181
00182 void add_observer(const std::string& name) { observers_.insert(name); }
00183 void remove_observer(const std::string& name) { observers_.erase(name); }
00184 const std::set<std::string>& observers() const { return observers_; }
00185
00186 enum MESSAGE_TYPE { MESSAGE_PUBLIC, MESSAGE_PRIVATE };
00187 void add_chat_message(const time_t& time, const std::string& speaker,
00188 int side, const std::string& msg, MESSAGE_TYPE type, bool bell);
00189 void clear_chat_messages() { prune_chat_messages(true); }
00190
00191 void begin_game();
00192
00193 virtual bool in_game() const { return in_game_; }
00194 void draw_bar(const std::string& image, int xpos, int ypos,
00195 const int drawing_order, size_t height, double filled, const SDL_Color& col, fixed_t alpha);
00196
00197
00198
00199
00200
00201
00202
00203
00204 enum tgame_mode {
00205 RUNNING,
00206 LINGER_SP,
00207 LINGER_MP };
00208
00209 void set_game_mode(const tgame_mode game_mode);
00210
00211 private:
00212 game_display(const game_display&);
00213 void operator=(const game_display&);
00214
00215 void draw_sidebar();
00216 void draw_game_status();
00217
00218
00219 surface get_flag(const gamemap::location& loc);
00220
00221 unit_map& units_;
00222
00223 unit *temp_unit_;
00224 gamemap::location temp_unit_loc_;
00225
00226
00227 gamemap::location attack_indicator_src_;
00228 gamemap::location attack_indicator_dst_;
00229
00230
00231
00232 const SDL_Rect& calculate_energy_bar(surface surf);
00233 std::map<surface,SDL_Rect> energy_bar_rects_;
00234
00235 paths::route route_;
00236
00237 const gamestatus& status_;
00238
00239 const std::vector<team>& teams_;
00240
00241 const config& level_;
00242
00243 void invalidate_route();
00244
00245 bool invalidateUnit_;
00246 gamemap::location displayedUnitHex_;
00247
00248 struct overlay {
00249 overlay(const std::string& img, const std::string& halo_img,
00250 int handle) : image(img), halo(halo_img),
00251 halo_handle(handle) {}
00252 std::string image;
00253 std::string halo;
00254 int halo_handle;
00255 };
00256
00257 typedef std::multimap<gamemap::location,overlay> overlay_map;
00258
00259 overlay_map overlays_;
00260
00261 size_t currentTeam_, activeTeam_;
00262
00263 double sidebarScaling_;
00264
00265 bool first_turn_, in_game_;
00266
00267 std::set<std::string> observers_;
00268
00269 struct chat_message
00270 {
00271 chat_message(int speaker, int h) : speaker_handle(speaker), handle(h), created_at(SDL_GetTicks())
00272 {}
00273
00274 int speaker_handle;
00275 int handle;
00276 Uint32 created_at;
00277 };
00278
00279 void prune_chat_messages(bool remove_all=false);
00280
00281 std::vector<chat_message> chat_messages_;
00282
00283
00284
00285 surface tod_hex_mask1, tod_hex_mask2;
00286
00287
00288 typedef std::map<gamemap::location,unsigned int> reach_map;
00289 reach_map reach_map_;
00290 reach_map reach_map_old_;
00291 bool reach_map_changed_;
00292 void process_reachmap_changes();
00293
00294 tgame_mode game_mode_;
00295
00296
00297 static std::map<gamemap::location,fixed_t> debugHighlights_;
00298
00299
00300 std::vector<animated<image::locator> > flags_;
00301
00302 static game_display * singleton_;
00303 };
00304
00305 #endif