game_display.hpp

Go to the documentation of this file.
00001 /* $Id: game_display.hpp 26699 2008-05-18 15:08:29Z noyga $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 //! @file game_display.hpp
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 // This needs to be separate from display.h because of the static
00038 // singleton member, which will otherwise trigger link failure
00039 // when building the editor.
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     //! Update lighting settings.
00052     //! Should be called on every new turn,
00053     void new_turn();
00054 
00055     //! Add r,g,b to the colours for all images displayed on the map.
00056     //! Used for special effects like flashes.
00057     void adjust_colours(int r, int g, int b);
00058 
00059     //! Scrolls to the leader of a certain side.
00060     //! This will normally be the playing team.
00061     void scroll_to_leader(unit_map& units, int side, SCROLL_TYPE scroll_type = ONSCREEN);
00062 
00063     //! Draw for the game display has to know about units
00064     void draw(bool update=true,bool force=false);
00065 
00066     //! Function to display a location as selected.
00067     //! If a unit is in the location, and there is no unit
00068     //! in the currently highlighted hex,
00069     //! the unit will be displayed in the sidebar.
00070     virtual void select_hex(gamemap::location hex);
00071 
00072     //! Function to highlight a location.
00073     //! If a unit is in the location, it will be displayed in the sidebar.
00074     //! Selection is used when a unit has been clicked on,
00075     //! while highlighting is used when a location has been moused over.
00076     virtual void highlight_hex(gamemap::location hex);
00077 
00078     //! Change the unit to be displayed in the sidebar.
00079     //! This is used when selecting or highlighting is not wanted.
00080     void display_unit_hex(gamemap::location hex);
00081 
00082     //! Sets the paths that are currently displayed as available
00083     //! for the unit to move along.
00084     //! All other paths will be greyed out.
00085     void highlight_reach(const paths &paths_list);
00086 
00087     //! Add more paths to highlight.  Print numbers where they overlap.
00088     //! Used only by Show Enemy Moves.
00089     void highlight_another_reach(const paths &paths_list);
00090 
00091     //! Reset highlighting of paths.
00092     void unhighlight_reach();
00093 
00094     //! Sets the route along which footsteps are drawn to show movement of a unit.
00095     //! If NULL, no route is displayed. route does not have to remain valid after being set.
00096     void set_route(const paths::route* route);
00097 
00098     //! Function to float a label above a tile
00099     void float_label(const gamemap::location& loc, const std::string& text,
00100                      int red, int green, int blue);
00101 
00102     //! Function to return 2 half-hex footsteps images for the given location.
00103     //! Only loc is on the current route set by set_route.
00104     std::vector<surface> footsteps_images(const gamemap::location& loc);
00105 
00106     //! Draws the movement info (turns available) for a given location.
00107     void draw_movement_info(const gamemap::location& loc);
00108 
00109     //! Function to invalidate a specific tile for redrawing.
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     //! Function to invalidate that unit status displayed on the sidebar.
00116     void invalidate_unit() { invalidateUnit_ = true; }
00117 
00118     //! Same as invalidate_unit() if moving the displayed unit.
00119     void invalidate_unit_after_move(const gamemap::location& src, const gamemap::location& dst);
00120 
00121 private:
00122     //! Function to invalidate animated terrains which may have changed.
00123     void invalidate_animations();
00124 
00125     virtual void draw_minimap_units();
00126 
00127 public:
00128     //! Temporarily place a unit on map (moving: can overlap others).
00129     void place_temporary_unit(unit &u, const gamemap::location& loc);
00130     void remove_temporary_unit();
00131 
00132     //! Set the attack direction indicator
00133     void set_attack_indicator(const gamemap::location& src, const gamemap::location& dst);
00134     void clear_attack_indicator();
00135     //! Function to get attack direction suffix
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     //! Functions to add and remove overlays from locations.
00141     //! An overlay is an image that is displayed on top of the tile.
00142     //! One tile may have multiple overlays.
00143     void add_overlay(const gamemap::location& loc, const std::string& image, const std::string& halo="");
00144     //! remove_overlay will remove all overlays on a tile.
00145     void remove_overlay(const gamemap::location& loc);
00146     //! remove_single_overlay will remove a single overlay from a tile
00147     void remove_single_overlay(const gamemap::location& loc, const std::string& toDelete);
00148 
00149     //! Function to serialize overlay data.
00150     void write_overlays(config& cfg) const;
00151 
00152 
00153     // Functions used in the editor:
00154 
00155     //void draw_terrain_palette(int x, int y, terrain_type::TERRAIN selected);
00156     t_translation::t_terrain get_terrain_on(int palx, int paly, int x, int y);
00157 
00158     //! Sets the team controlled by the player using the computer.
00159     //! Data from this team will be displayed in the game status.
00160     //! set_playing_team sets the team whose turn it currently is
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     //! Draws a cross on a tile to emphasize something there.
00170     //! It is used in debug mode, typically to show AI plans.
00171     static void debug_highlight(const gamemap::location& loc, fixed_t amount);
00172     static void clear_debug_highlights() { debugHighlights_.clear(); }
00173 
00174     //! The viewing team is the team currently viewing the game.
00175     size_t viewing_team() const { return currentTeam_; }
00176     //! The playing team is the team whose turn it is.
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     //! Sets the linger mode for the display.
00198     //! There have been some discussions on what to do with fog and shroud
00199     //! the extra variables make it easier to modify the behaviour. There
00200     //! might even be a split between victory and defeat.
00201     //
00202     //! @todo if the current implementation is wanted we can change 
00203     //! the stuff back to a boolean
00204     enum tgame_mode { 
00205         RUNNING,         //!< no linger overlay, show fog and shroud
00206         LINGER_SP,       //!< linger overlay, show fog and shroud
00207         LINGER_MP };     //!< linger overlay, show fog and shroud
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     // This surface must be freed by the caller
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     // Locations of the attack direction indicator's parts
00227     gamemap::location attack_indicator_src_;
00228     gamemap::location attack_indicator_dst_;
00229 
00230     //! Finds the start and end rows on the energy bar image.
00231     //! White pixels are substituted for the colour of the energy
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     // If we're transitioning from one time of day to the next,
00284     // then we will use these two masks on top of all hexes when we blit.
00285     surface tod_hex_mask1, tod_hex_mask2;
00286 
00287     // Tiles lit for showing where unit(s) can reach
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     // For debug mode
00297     static std::map<gamemap::location,fixed_t> debugHighlights_;
00298 
00299     //! Animated flags for each team
00300     std::vector<animated<image::locator> > flags_;
00301 
00302     static game_display * singleton_;
00303 };
00304 
00305 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs