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

« back to all changes in this revision

Viewing changes to src/Tile.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) 2001, 2002, 2003 Michael Bartl
 
2
// Copyright (C) 2001, 2002, 2004, 2005, 2006 Ulf Lorenz
 
3
// Copyright (C) 2007, 2008 Ben Asselstine
 
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 TILE_H
16
21
#define TILE_H
23
28
 
24
29
#include "tilestyleset.h"
25
30
 
26
 
/** Class which describes the terrain
27
 
  * 
28
 
  * Many tiles are put together to form a tileset. Thus, a tile describes a
29
 
  * single terrain type. It keeps the name, movement points, type (grass, water
30
 
  * etc.) as well as the images together.
31
 
  */
32
 
 
33
 
class Tile : public std::vector<TileStyleSet*>
 
31
//! Describes a kind of tile that a Stack can traverse.
 
32
/** 
 
33
 * Many tiles are put together to form a tileset. Thus, a tile describes a
 
34
 * single terrain type. It keeps the name, movement points, type (grass, water
 
35
 * etc.) and also keeps the images together.
 
36
 *
 
37
 * Each tile holds a list of TileStyleSet objects which hold a list of 
 
38
 * TileStyle objects.  Each TileStyleSet holds a bunch of pictures of
 
39
 * what this tile can look like.  A TileStyle is a single picture.
 
40
 * These TileStyle pictures are displayed on the BigMap using the MapRenderer.
 
41
 *
 
42
 * Tile objects are held in a Tileset object.
 
43
 * Maptile objects refer to Tile objects.
 
44
 */
 
45
class Tile : public std::list<TileStyleSet*>
34
46
{
35
47
    public:
36
 
        //! Describe terrain types
37
 
        enum Type { NONE = 0, GRASS = NONE, WATER = 1, FOREST = 2, HILLS = 4,
38
 
                    MOUNTAIN = 8, SWAMP = 16 };
39
 
        enum Pattern { SOLID = 0, STIPPLED = 1, RANDOMIZED = 2, SUNKEN = 3,
40
 
                       TABLECLOTH = 4};
 
48
        //! Enumerate the kinds of terrain that a Stack can potentially move on.
 
49
        enum Type { 
 
50
          //! Synomymous with GRASS.
 
51
          NONE = 0, 
 
52
          //! Grassy plain.  Flat.  Open.  Easy to pass through.
 
53
          GRASS = NONE, 
 
54
          //! Lake, ocean, river, puddle, moat, or anything else watery.
 
55
          WATER = 1, 
 
56
          //! Trees in great abundance, also includes shrubberies.
 
57
          FOREST = 2, 
 
58
          //! Hilly terrain, generally passable.
 
59
          HILLS = 4,
 
60
          //! Very hilly terrain, generally not passable except by flight.
 
61
          MOUNTAIN = 8, 
 
62
          //! Marshy terrain.
 
63
          SWAMP = 16 
 
64
        };
 
65
 
 
66
        //! The terrain tile's appearance as seen on the OverviewMap.
 
67
        enum Pattern { 
 
68
 
 
69
          //! The terrain feature is shown as a single solid colour.
 
70
          SOLID = 0, 
 
71
 
 
72
          //! The terrain feature is checkered with two alternating colours.
 
73
          /**
 
74
           * The stippled pattern looks something like this:
 
75
           * @verbatim
 
76
xoxoxoxo
 
77
oxoxoxox
 
78
xoxoxoxo
 
79
oxoxoxox
 
80
@endverbatim
 
81
           *
 
82
           * It is currently used for Type::FOREST, and Type::HILLS.
 
83
           */
 
84
          STIPPLED = 1, 
 
85
 
 
86
          //! The feature is random pixels with three different colours.
 
87
          /**
 
88
           * The random pattern looks something like this:
 
89
           * @verbatim
 
90
xoexooxo
 
91
exoxxeox
 
92
xoeoxoxx
 
93
eoxeooex
 
94
@endverbatim
 
95
           *
 
96
           * It is currently used for Type::MOUNTAINS.
 
97
           */
 
98
          RANDOMIZED = 2, 
 
99
 
 
100
          //! The feature is shaded on the bottom and on the left.
 
101
          /**
 
102
           * The sunken pattern looks something like this:
 
103
           * @verbatim
 
104
xxxxxxxo
 
105
xxxxxxxo
 
106
xxxxxxxo
 
107
oooooooo
 
108
@endverbatim
 
109
           *
 
110
           * It is currently used for Type::WATER.
 
111
           */
 
112
          SUNKEN = 3,
 
113
 
 
114
          //! The feature is shown as a 3 colour pattern.
 
115
          /**
 
116
           * The tablecloth pattern looks something like this:
 
117
           * @verbatim
 
118
xexexexe
 
119
eoeoeoeo
 
120
xexexexe
 
121
eoeoeoeo
 
122
@endverbatim
 
123
           *
 
124
           * It is currently used for Type::SWAMP.
 
125
           */
 
126
          TABLECLOTH = 4
 
127
        };
41
128
                    
42
 
        //! Loading constructor
 
129
 
 
130
        //! Default constructor.
 
131
        Tile();
 
132
 
 
133
        //! Loading constructor.
 
134
        /**
 
135
         * Loads the tileset.tile XML entities in the tileset configuration 
 
136
         * files.
 
137
         * */
43
138
        Tile(XML_Helper* helper);
44
139
 
 
140
        //! Destructor.
45
141
        ~Tile();
46
142
 
47
143
        //! Get the number of movement points needed to cross this tile
48
144
        Uint32 getMoves() const {return d_moves;}
49
145
 
50
 
        //! Get the color associated with this tile for the smallmap
 
146
        //! Get the colour associated with this tile for the smallmap.
51
147
        SDL_Color getColor() const {return d_color;}
52
 
        //! Set the color associated with this tile for the smallmap
 
148
 
 
149
        //! Set the colour associated with this tile for the smallmap.
53
150
        void setColor(SDL_Color clr) {d_color = clr;}
54
151
 
55
 
        //! Get the type (grass, hill,...) of this tile type
 
152
        //! Get the type (grass, hill,...) of this tile type.
56
153
        Type getType() const {return d_type;}
 
154
 
 
155
        void setType(Type type) {d_type = type;}
57
156
                
58
 
        //! Get the pattern (solid, stippled, random) of this type
 
157
        static int getTypeIndexForType(Tile::Type type);
 
158
 
 
159
        int getTypeIndex() {return getTypeIndexForType(d_type);}
 
160
 
 
161
        void setTypeByIndex(int idx);
 
162
        //! Get the pattern (solid, stippled, random) of this type.
59
163
        Pattern getPattern() const {return d_pattern;}
60
 
        //! set the pattern (solid, stippled, random) of this type
 
164
 
 
165
        //! set the pattern (solid, stippled, random) of this type.
61
166
        void setPattern(Pattern pattern) {d_pattern = pattern;}
62
167
 
 
168
        //! Get the name of this kind of tile (used in the editor).
63
169
        std::string getName() const {return d_name;}
64
170
 
65
 
        //! Get the alternate color associated with this tile's pattern 
66
 
        //!This "second" colour gets stippled, or randomized, or sunken
 
171
        //! Set the name of this kind of tile (used in the editor).
 
172
        void setName(std::string name) {d_name = name;}
 
173
 
 
174
        //! Get the alternate colour associated with this tile's pattern.
 
175
        /**
 
176
         * This "second" colour gets used when Tile::Pattern is
 
177
         * Tile::STIPPLED, Tile::RANDOMIZED, Tile::SUNKEN, or Tile::TABLECLOTH.
 
178
         */
67
179
        SDL_Color getSecondColor() const {return d_second_color;}
68
 
        //! set the alternate color associated with this tile's pattern 
 
180
 
 
181
        //! Set the alternate colour associated with this tile's pattern.
69
182
        void setSecondColor(SDL_Color color) {d_second_color = color;}
70
183
 
71
 
        //! Get another alternate color associated with this tile's pattern 
72
 
        //!This "third" colour gets randomized, or sunken
 
184
        //! Get another alternate colour associated with this tile's pattern.
 
185
        /**
 
186
         * This "third" colour gets used when Tile::Pattern is
 
187
         * Tile::RANDOMIZED, or Tile::TABLECLOTH.
 
188
         */
73
189
        SDL_Color getThirdColor() const {return d_third_color;}
74
 
        //! set another alternate color associated with this tile's pattern 
 
190
 
 
191
        //! Set another alternate colour associated with this tile's pattern.
75
192
        void setThirdColor(SDL_Color color) {d_third_color = color;}
76
193
 
 
194
        //! Load the pictures associated with this tile.
 
195
        /**
 
196
         * @param tileset   The name of the tileset to load pictures for.
 
197
         * @param tilesize  The expected size of the tiles in the image.
 
198
         */
77
199
        void instantiatePixmaps(std::string tileset, Uint32 tilesize);
78
200
 
 
201
 
 
202
        //! Save a Tile to an opened tile configuration file.
 
203
        /**
 
204
         * @param  The opened XML tile configuration file.
 
205
         */
 
206
        bool save(XML_Helper *helper);
 
207
 
 
208
        //! Lookup a random tile style for this tile.
 
209
        /**
 
210
         * Scan the TileStyles for this Tile for a TileStyle that matches 
 
211
         * the given style.  When there is more than one TileStyle to choose 
 
212
         * from, randomly pick one from all of the matching TileStyle objects.
 
213
         *
 
214
         * @param style  The kind of style we're looking for.
 
215
         *
 
216
         * @return A pointer to the matching TileStyle object, or NULL if no 
 
217
         *         TileStyle could be found with that given style.
 
218
         */
 
219
        TileStyle *getRandomTileStyle (TileStyle::Type style);
79
220
    private:
80
221
        // DATA
 
222
 
 
223
        //! The name of this kind of a tile.
 
224
        /**
 
225
         * The name is taken from the tileset configuration file.
 
226
         * This value doesn't change during gameplay.
 
227
         * It used in the scenario editor, but not used in the game.
 
228
         * Equates to the tileset.tile.d_name XML entities in the tileset
 
229
         * configuration file.
 
230
         */
81
231
        std::string d_name;
82
 
        Uint32 d_moves;                    // moves needed to walk over maptile
83
 
        SDL_Color d_color;                // color shown in the smallmap
 
232
 
 
233
        //! The number of movement points required to cross this tile.
 
234
        /**
 
235
         * If an Army unit cannot traverse the tile efficiently it pays
 
236
         * this number of movement points to walk over this tile.
 
237
         * This value doesn't change during gameplay.
 
238
         * Equates to the tileset.tile.d_moves XML entities in the tileset
 
239
         * configuration file.
 
240
         */
 
241
        Uint32 d_moves;
 
242
        
 
243
        //! The kind of terrain tile this instance represents.
 
244
        /**
 
245
         * Equates to the tileset.tile.d_type XML entities in the tileset
 
246
         * configuration file.
 
247
         */
84
248
        Type d_type;
 
249
 
 
250
        //! The general appearance of the terrain tile on the OverviewMap.
 
251
        /**
 
252
         * Equates to the tileset.tile.smallmap.d_pattern XML entities in the 
 
253
         * tileset configuration file.
 
254
         */
85
255
        Pattern d_pattern;
86
 
        SDL_Color d_second_color;         // the extra pattern-related color
87
 
        SDL_Color d_third_color;         // another pattern-related color
 
256
 
 
257
        //! First colour.
 
258
        /**
 
259
         * Equates to the following XML entities in the tileset configuration
 
260
         * file:
 
261
         * tileset.tile.smallmap.d_red 
 
262
         * tileset.tile.smallmap.d_green
 
263
         * tileset.tile.smallmap.d_blue
 
264
         */
 
265
        SDL_Color d_color;
 
266
 
 
267
        //! Second colour.
 
268
        /**
 
269
         * Only used when Tile::Pattern is one of: Tile::STIPPLED, 
 
270
         * Tile::RANDOMIZED, Tile::SUNKEN, or Tile::TABLECLOTH.
 
271
         *
 
272
         * Equates to the following XML entities in the tileset configuration
 
273
         * file:
 
274
         * tileset.tile.smallmap.d_2nd_red 
 
275
         * tileset.tile.smallmap.d_2nd_green
 
276
         * tileset.tile.smallmap.d_2nd_blue
 
277
         */
 
278
        SDL_Color d_second_color;
 
279
 
 
280
        //! Third colour.
 
281
        /**
 
282
         * Only used when Tile::Pattern is Tile::RANDOMIZED, or 
 
283
         * Tile::TABLECLOTH.
 
284
         *
 
285
         * Equates to the following XML entities in the tileset configuration
 
286
         * file:
 
287
         * tileset.tile.smallmap.d_3rd_red 
 
288
         * tileset.tile.smallmap.d_3rd_green
 
289
         * tileset.tile.smallmap.d_3rd_blue
 
290
         */
 
291
        SDL_Color d_third_color;
88
292
 
89
293
};
90
294