~ubuntu-branches/ubuntu/raring/lordsawar/raring

« back to all changes in this revision

Viewing changes to src/overviewmap.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese, Gonéri Le Bouder
  • Date: 2008-06-17 11:15:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617111526-yjyvu9df50zmpdo0
Tags: 0.0.9-1
[ Barry deFreese ]
* New upstream release.
  + Fixes gcc-4.3 builds so drop ftbfs_gcc-4.3_fix.diff.
  + Add new build-dependency for libgnet-dev.
* Add simple man page for new lordsawar-tile-editor.
* Add desktop file for lordsawar-tile-editor.
* Remove French translation on install.

[ Gonéri Le Bouder ]
* bump Debian Policy to 3.8.0. No change needed.
* fix wording in the 0.0.8-3 entry of the Debian changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2006 Ulf Lorenz
 
2
// Copyright (C) 2007, 2008 Ben Asselstine
 
3
// Copyright (C) 2007 Ole Laursen
 
4
//
1
5
//  This program is free software; you can redistribute it and/or modify
2
6
//  it under the terms of the GNU General Public License as published by
3
7
//  the Free Software Foundation; either version 2 of the License, or
10
14
//
11
15
//  You should have received a copy of the GNU General Public License
12
16
//  along with this program; if not, write to the Free Software
13
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 
18
//  02110-1301, USA.
14
19
 
15
20
#ifndef OVERVIEWMAP_H
16
21
#define OVERVIEWMAP_H
22
27
 
23
28
class Maptile;
24
29
 
25
 
/** A smaller version of the map that draws on its own SDL surface
26
 
  * 
27
 
  * This is a base class that draws the terrain, etc. Derived classes can add
28
 
  * their own stuff by overrriding after_draw.
29
 
  *
30
 
  */
 
30
//! Generates a miniature graphic of the game map.
 
31
/**
 
32
 * This is a base class that draws the terrain, ruins, temples, and roads 
 
33
 * onto an SDL_Surface.
 
34
 * This class is responsible for drawing terrain features using the correct
 
35
 * pattern, as specified in Tile::Pattern.  Ruins and Temples are drawn as 
 
36
 * white dots, and roads are drawn as brown lines.
 
37
 * If a tile on the game map is obscured due to fog of war on a hidden map,
 
38
 * it appears as black.
 
39
 * This class provides a method for optionally drawing cities onto the map.
 
40
 * Derived classes can add their own stuff to the map by overriding the 
 
41
 * after_draw method that is called by OverviewMap::draw.
 
42
 */
31
43
class OverviewMap
32
44
{
33
45
 public:
34
 
    OverviewMap();
35
 
    virtual ~OverviewMap();
36
 
 
37
 
    // the map will keep its aspect ratio and resize itself to take up at most
38
 
    // max_dimensions space
 
46
     //! Default constructor.
 
47
     /**
 
48
      * Make a new overview map.  This constructor doesn't do anything, the
 
49
      * real work is done in the OverviewMap::resize and OverviewMap::draw
 
50
      * methods.
 
51
      * This constructor is not normally called by itself, usually it is
 
52
      * called by a derived class.
 
53
      */
 
54
     OverviewMap();
 
55
 
 
56
     //! Destructor.
 
57
     virtual ~OverviewMap();
 
58
 
 
59
    //! Draw and scale the miniature map graphic to the given size.
 
60
    /**
 
61
     * This method is responsible for drawing the terrain (e.g. grass, water, 
 
62
     * etc), but not the terrain features (roads, ruins, etc).
 
63
     * It will draw a map that is max_dimensions large, but will keep it's
 
64
     * aspect ratio.
 
65
     * This method should be called before the draw method.  
 
66
     *
 
67
     * @param max_dimensions  Two integers; the first of which dictates the
 
68
     *                        width of the map graphic, and the second dictates
 
69
     *                        the height.
 
70
     *
 
71
     */
39
72
    void resize(Vector<int> max_dimensions);
40
73
 
41
 
    // picks the best dimensions to resize to
 
74
    //! Draw and scale the mini map graphic to the correct size of the game map.
 
75
    /**
 
76
     * @note This method depends on the map being one of the 3 sizes as 
 
77
     * defined in the GamePreferencesDialog.
 
78
     * This method should be called before the draw method.
 
79
     */
42
80
    void resize();
43
81
 
44
 
    // draw the nonstatic stuff, won't redraw the terrain
 
82
    //! Draw the terrain features (roads, ruins, etc) on the map.
 
83
    /**
 
84
     * Draws the roads, cities, ruins, temples and roads onto the map in the
 
85
     * correct aspect ratio.
 
86
     *
 
87
     * The aspect ratio for the terrain features is governed by the dimensions 
 
88
     * passed to the OverviewMap::resize method.
 
89
     *
 
90
     * This method calls the after_draw method from the derived classes.
 
91
     */
45
92
    void draw();
46
93
 
47
 
    // redraw the specified tiles (also redraws the terrain)
 
94
    //! Redraw a portion of the map graphic.
 
95
    /**
 
96
     * This method draws the terrain (water, grass, etc) for the given 
 
97
     * portion of the screen.
 
98
     *
 
99
     * @note This method redraws all terrain features (roads, ruins, etc), 
 
100
     *       including the features outside of the given portion.
 
101
     *
 
102
     * @param tiles  The rectangle to redraw.
 
103
     */
48
104
    void redraw_tiles(Rectangle tiles);
49
105
 
50
 
    // returns the drawn map
 
106
    //! Returns the map graphic.
 
107
    /**
 
108
     * It only makes sense to get the surface after OverviewMap::resize and 
 
109
     * OverviewMap::draw have been called.
 
110
     */
51
111
    SDL_Surface *get_surface();
52
112
 
53
 
    //is this tile visible? (convenience function)
54
 
    bool isFogged(Vector<int>);
55
 
 
 
113
    static void draw_tile_pixel(SDL_Surface *surface, Tile::Pattern pattern,
 
114
                                SDL_Color first_color, SDL_Color second_color,
 
115
                                SDL_Color third_color,
 
116
                                int i, int j, bool shadowed);
56
117
 private:
57
 
     // the background, we keep it cached so it doesn't have to be drawn all
58
 
     // the time
 
118
    //! An SDL surface of the terrain without the features.
 
119
    /**
 
120
     * This is the cached surface after the resize method was called.
 
121
     * It is cached so that we don't have recalculate it.
 
122
     */
59
123
    SDL_Surface* static_surface;
 
124
 
 
125
    //! Returns whether or not the given pixel appears sunken (Tile::SUNKEN).
 
126
    /**
 
127
     * The leftmost and bottommost pixels of a sunken terrain type are shaded
 
128
     * in a different colour.  This method returns whether or not a given pixel
 
129
     * should be shaded.
 
130
     *
 
131
     * @param type  The tile associated with the pixel location must be of
 
132
     *              this type.  If not, then this method always returns false.
 
133
     * @param i     The pixel on the horizontal axis on the map graphic that 
 
134
     *              we're querying.
 
135
     * @param j     The pixel on the vertical axis on the map graphic that
 
136
     *              we're querying.
 
137
     *
 
138
     * @return True if the given pixel location should be shaded, false if not.
 
139
     */
60
140
    bool isShadowed(Uint32 type, int i, int j);
61
 
    void draw_tile_pixel(Maptile *, int, int);
 
141
 
 
142
    //! Draw the given tile at the given pixel location on the map.
 
143
    /**
 
144
     * This method draws a square that is Overviewmap::pixels_per_tile pixels
 
145
     * in height and width.  It draws it at position (i,j) on the graphic.
 
146
     * This method uses the pattern assocaited the given Maptile to know 
 
147
     * what this box should look like.
 
148
     *
 
149
     * @param tile  The tile of the game map we're trying to draw.
 
150
     * @param i     The pixel on the horizontal axis of the map graphic.  This
 
151
     *              value must be a multiple of OverviewMap::pixels_per_tile.
 
152
     * @param j     The pixel on the vertical axis of the map graphic.  This
 
153
     *              value must be a multiple of OverviewMap::pixels_per_tile.
 
154
     */
 
155
    void draw_tile_pixel(Maptile *tile, int i, int j);
62
156
 
63
157
 protected:
 
158
 
 
159
    //! Every pixel on the graphic is this wide and tall.
64
160
    double pixels_per_tile;
65
 
        
66
 
    //! Maps the given point in absolute screen coordinates to a map coordinate
 
161
 
 
162
    //! Maps the given point in graphic coordinates to a game map coordinate.
67
163
    Vector<int> mapFromScreen(Vector<int> pos);
68
 
        
69
 
    //! And (almost) the other way round. Map a map coordinate to a surface pixel.
 
164
 
 
165
    //! And the other way round. Map a map coordinate to a surface pixel.
70
166
    Vector<int> mapToSurface(Vector<int> pos);
71
167
 
72
 
    // hook for derived classes
 
168
    //! A hook method for derived classes to put features on the map.
73
169
    virtual void after_draw();
74
170
 
75
 
    //! draw cities on the map
 
171
    //! This method draws the cities onto the map.
 
172
    /**
 
173
     * Scan through all of the cities in the citylist, and draw each one with
 
174
     * a small shield graphic belonging to the owner of that city.
 
175
     *
 
176
     * Derived classes may call this method in their after_draw method.
 
177
     *
 
178
     * @param all_razed  Show each city as if it were razed.
 
179
     */
76
180
    void draw_cities(bool all_razed);
77
181
 
78
 
    // redraw the specified terrain pixels
 
182
    //! Redraw the specified region.
79
183
    void draw_terrain_pixels(Rectangle r);
80
184
 
 
185
    int calculateResizeFactor();
 
186
 
 
187
    //! The surface containing the drawn map.
81
188
    SDL_Surface* surface;
82
189
};
83
190