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

« back to all changes in this revision

Viewing changes to src/maptile.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
 
//  This program is free software; you can redistribute it and/or modify
2
 
//  it under the terms of the GNU General Public License as published by
3
 
//  the Free Software Foundation; either version 2 of the License, or
4
 
//  (at your option) any later version.
5
 
//
6
 
//  This program is distributed in the hope that it will be useful,
7
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9
 
//  GNU Library General Public License for more details.
10
 
//
11
 
//  You should have received a copy of the GNU General Public License
12
 
//  along with this program; if not, write to the Free Software
13
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
1
// Copyright (C) 2003 Michael Bartl
 
2
// Copyright (C) 2003, 2004, 2005, 2006 Ulf Lorenz
 
3
// Copyright (C) 2005 Andrea Paternesi
 
4
// Copyright (C) 2006, 2007, 2008 Ben Asselstine
14
5
 
15
6
#ifndef MAPTILE_H
16
7
#define MAPTILE_H
20
11
#include "tileset.h"
21
12
#include "Item.h"
22
13
 
23
 
/** A single tile on the map
24
 
  * 
25
 
  * The Maptile class encapsulates all information one may want to get about a
26
 
  * single maptile of the game map. Specifically, it stores the type of and the
27
 
  * buildings on the map tile.
28
 
  *
29
 
  * A remark concerning the type. A maptile has two types. First, the type value
30
 
  * is an index in the tileset which says which tile type this maptile has, e.g.
31
 
  * "This maptile is of the sort of the first tile in the tileset". The maptile
32
 
  * type says which terrain type this maptile has, e.g. grass or swamps.
33
 
  */
34
 
 
 
14
//! A single tile on the game map.
 
15
/** 
 
16
 * The Maptile class encapsulates all information one may want to get about a
 
17
 * single maptile of the game map.  Specifically, it stores the type of and the
 
18
 * buildings on the map tile.
 
19
 *
 
20
 * A remark concerning the type.  A maptile has two types. First, the type 
 
21
 * value is an index in the tileset which says which tile type this maptile 
 
22
 * has, e.g. "This maptile is of the sort of the first tile in the tileset". 
 
23
 * The maptile type says which terrain type this maptile has, 
 
24
 * e.g. grass or swamps.
 
25
 *
 
26
 * The GameMap contains on Maptile object for every cell of the map.
 
27
 *
 
28
 */
35
29
class Maptile
36
30
{
37
31
    public:
38
 
        //! Enum of possible buldings on the tile
39
 
        enum Building {NONE=0, CITY=1, RUIN=2, TEMPLE=3, SIGNPOST=4, ROAD=6, PORT=7, BRIDGE=8};
40
 
 
41
 
        /** Default constructor
42
 
          * 
43
 
          * @param tileSet          the tileset to use
44
 
          * @param x                the x position of the tile
45
 
          * @param y                the y position of the tile
46
 
          * @param type             the terrain type (index in the tileset)
47
 
          * @param tileStyle        the look of this tile to use
48
 
          */
49
 
        Maptile(Tileset* tileSet, int x, int y, Uint32 type, TileStyle *tileStyle);
 
32
        //! Enumeration of all possible constructed objects on the maptile.
 
33
        /**
 
34
         * Each member in the enumeration refers to a class that inherits 
 
35
         * the Location class.
 
36
         */
 
37
        enum Building {
 
38
          //! Bupkiss.  Nothing built here.
 
39
          NONE=0, 
 
40
          //! A City is built here.
 
41
          CITY=1, 
 
42
          //! A Ruin is built here.
 
43
          RUIN=2, 
 
44
          //! A Temple is built here.
 
45
          TEMPLE=3, 
 
46
          //! A Signpost is built here.
 
47
          SIGNPOST=4, 
 
48
          //! A Road is built here.
 
49
          ROAD=6, 
 
50
          //! A Port is built here.
 
51
          PORT=7, 
 
52
          //! A Bridge is built here.
 
53
          BRIDGE=8
 
54
        };
 
55
 
 
56
        //! Default constructor.
 
57
        /** 
 
58
         * Make a new Maptile.
 
59
         *
 
60
         * @param tileSet          The tileset to use.
 
61
         * @param x                The x position of the tile.
 
62
         * @param y                The y position of the tile.
 
63
         * @param type             The terrain type (index in the tileset).
 
64
         * @param tileStyle        The look of this tile to use.
 
65
         */
 
66
        Maptile(Tileset* tileSet, int x, int y, Uint32 type, 
 
67
                TileStyle *tileStyle);
 
68
 
 
69
        //! Slower constructor.
 
70
        /** 
 
71
         * Make a new Maptile, but this time using the Tile::Type.
 
72
         *
 
73
         * @param tileSet          The tileset to use.
 
74
         * @param x                The x position of the tile.
 
75
         * @param y                The y position of the tile.
 
76
         * @param type             The terrain type enumeration Tile::Type.
 
77
         * @param tileStyle        The look of this tile to use.
 
78
         */
 
79
        Maptile(Tileset* tileSet, int x, int y, Tile::Type type, 
 
80
                TileStyle *tileStyle);
 
81
 
 
82
        //! Destructor.
50
83
        ~Maptile();
51
84
 
52
 
        //! Set the type of the terrain (type is an index in the tileset)
 
85
        //! Set the type of the terrain (type is an index in the tileset).
53
86
        void setType(Uint32 index){d_index = index;}
54
87
 
55
 
        //! Set which building is on this maptile
 
88
        //! Set which kind of building is on this maptile.
56
89
        void setBuilding(Building building){d_building = building;}
57
90
 
58
 
        
59
 
        //! Get the index of the tile type in the tileset
 
91
        //! Get the index of the tile type in the tileset.
60
92
        Uint32 getType() const {return d_index;}
61
93
 
62
 
        //! Get which building is on the maptile
 
94
        //! Get which building is on the maptile.
63
95
        Building getBuilding() const {return d_building;}
64
96
 
65
 
        //! Get the number of moves needed to cross this maptile
 
97
        //! Get the number of moves needed to cross this maptile.
 
98
        /**
 
99
         * This method refers to the Tile::getMoves method, but then also 
 
100
         * takes into account the buildings on the tile.
 
101
         * 
 
102
         * @return The number of movement points required to cross this 
 
103
         *         Maptile.
 
104
         */
66
105
        Uint32 getMoves() const;
67
106
 
68
 
        //! Get the smallmap color of this maptile
69
 
        SDL_Color getColor() const;
70
 
 
71
 
        //! Get the pattern of this maptile on the smallmap
72
 
        Tile::Pattern getPattern() const;
73
 
 
74
 
        //! Get the associated colour with the pattern
75
 
        SDL_Color getSecondColor() const;
76
 
 
77
 
        //! Get the associated colour with the pattern
78
 
        SDL_Color getThirdColor() const;
79
 
 
80
 
        //! Get the tile type (the type of the underlying terrain)
81
 
        Tile::Type getMaptileType() const;
82
 
 
83
 
        //! Add an item to the maptile at a specific position in the list (<0 => to the end)
84
 
        void addItem(Item*, int position=-1);
85
 
 
86
 
        //! Remove an item from the maptile withut deleting it (!)
 
107
        //! Get the smallmap color of this maptile.
 
108
        SDL_Color getColor() const
 
109
          {return (*d_tileSet)[d_index]->getColor();}
 
110
 
 
111
        //! Get the pattern of this maptile on the smallmap.
 
112
        Tile::Pattern getPattern() const
 
113
          {return (*d_tileSet)[d_index]->getPattern();}
 
114
 
 
115
        //! Get the associated colour with the pattern.
 
116
        SDL_Color getSecondColor() const
 
117
          {return (*d_tileSet)[d_index]->getSecondColor();}
 
118
 
 
119
        //! Get the associated colour with the pattern.
 
120
        SDL_Color getThirdColor() const
 
121
          {return (*d_tileSet)[d_index]->getThirdColor();}
 
122
 
 
123
        //! Get the tile type (the type of the underlying terrain).
 
124
        Tile::Type getMaptileType() const
 
125
          {return (*d_tileSet)[d_index]->getType();}
 
126
 
 
127
        //! Add an Item to the maptile.
 
128
        /**
 
129
         * Put an Item on this spot.  If there are others, specify the
 
130
         * position among the list of other items. 
 
131
         *
 
132
         * @param item          The item to add to the maptile.
 
133
         * @param position      Where to add it in the list of items already
 
134
         *                      here.  -1 means add to the end.
 
135
         */
 
136
        void addItem(Item*, int position = -1);
 
137
 
 
138
        //! Remove an Item from the maptile without deleting it.
87
139
        void removeItem(Item* item);
88
140
 
89
 
        //! Get the items located at this maptile
 
141
        //! Get the list of Item objects on this maptile.
90
142
        std::list<Item*> getItems() const;
91
143
        
92
 
        //! is this map tile considered to be "open terrain".
93
 
        //! this is used for bonus calculations
 
144
        //! Whether or not this map tile considered to be "open terrain".
 
145
        /**
 
146
         *
 
147
         * This is used for battle bonus calculations.  An Army unit can
 
148
         * potentially have a bonus for being `out in the open' -- and this 
 
149
         * method defines if this maptile is `out in the open' or not.
 
150
         */
94
151
        bool isOpenTerrain();
95
152
 
96
 
        //! is this map tile considered to be "hilly terrain".
97
 
        //! this is used for bonus calculations
 
153
        //! Whether or not this map tile is considered to be "hilly terrain".
 
154
        /**
 
155
         *
 
156
         * This is used for battle bonus calculations.  An Army unit can 
 
157
         * potentially have a bonus for being `in the hills' -- and this method
 
158
         * defines if this maptile is `in the hills' or not.
 
159
         */
98
160
        bool isHillyTerrain();
99
161
 
100
 
        //! is this map tile considered to be "city terrain".
101
 
        //! this is used for bonus calculations
 
162
        //! Whether or not this map tile is considered to be "city terrain".
 
163
        /**
 
164
         * This is used for battle bonus calculations.  An Army unit can 
 
165
         * potentially have a bonus for being `in a city' -- and this method
 
166
         * defines if this maptile is `in a city' or not.
 
167
         */
102
168
        bool isCityTerrain();
103
169
 
104
 
        //prints some debug information
 
170
        //! Prints some debug information about this maptile.
105
171
        void printDebugInfo() const;
106
172
                
107
173
        bool d_blocked[8];
108
174
 
 
175
        //! Get the TileStyle associated with this Maptile.
109
176
        TileStyle * getTileStyle() const {return d_tileStyle;}
110
177
 
 
178
        //! Set the TileStyle associated with this Maptile.
111
179
        void setTileStyle(TileStyle *style) {d_tileStyle = style;}
112
180
 
113
181
    private:
 
182
        //! The index of the Tile within the Tileset (Maptile::d_tileSet).
 
183
        /**
 
184
         * The Maptile has a type, in the form of a Tile.  This Tile is
 
185
         * identified by it's index within Maptile::d_tileSet.
 
186
         */
 
187
        Uint32 d_index;
 
188
        //! The Tileset of the Tile referred to by Maptile::d_index.
114
189
        Tileset* d_tileSet;
115
 
        Uint32 d_index;
 
190
        //! The look of the maptile.
116
191
        TileStyle *d_tileStyle;
117
 
        Building d_building;    // which building is on this maptile
 
192
        //! The type of constructed object on this maptile.
 
193
        Building d_building;
 
194
        //! The list of pointers to items on this maptile.
118
195
        std::list<Item*> d_items;
119
196
};
120
197