Small const cleanup
[supertux.git] / src / supertux / tile.hpp
1 //  SuperTux
2 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
3 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 //
5 //  This program is free software: you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation, either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 #ifndef HEADER_SUPERTUX_SUPERTUX_TILE_HPP
19 #define HEADER_SUPERTUX_SUPERTUX_TILE_HPP
20
21 #include <vector>
22 #include <stdint.h>
23
24 #include "math/rect.hpp"
25 #include "video/surface.hpp"
26 #include "util/reader_fwd.hpp"
27
28 class TileSet;
29 class DrawingContext;
30
31 class Tile
32 {
33 public:
34   friend class TileSetParser;
35   
36   /// bitset for tile attributes
37   enum {
38     /** solid tile that is indestructible by Tux */
39     SOLID     = 0x0001,
40     /** uni-directional solid tile */
41     UNISOLID  = 0x0002,
42     /** a brick that can be destroyed by jumping under it */
43     BRICK     = 0x0004,
44     /** the level should be finished when touching a goaltile.
45      * if data is 0 then the endsequence should be triggered, if data is 1
46      * then we can finish the level instantly.
47      */
48     GOAL      = 0x0008,
49     /** slope tile */
50     SLOPE     = 0x0010,
51     /** Bonusbox, content is stored in \a data */
52     FULLBOX   = 0x0020,
53     /** Tile is a coin */
54     COIN      = 0x0040,
55
56     /* interesting flags (the following are passed to gameobjects) */
57     FIRST_INTERESTING_FLAG = 0x0100,
58
59     /** an ice brick that makes tux sliding more than usual */
60     ICE       = 0x0100,
61     /** a water tile in which tux starts to swim */
62     WATER     = 0x0200,
63     /** a tile that hurts the player if he touches it */
64     HURTS     = 0x0400,
65     /** for lava: WATER, HURTS, FIRE */
66     FIRE      = 0x0800
67   };
68
69   /// worldmap flags
70   enum {
71     WORLDMAP_NORTH = 0x0001,
72     WORLDMAP_SOUTH = 0x0002,
73     WORLDMAP_EAST  = 0x0004,
74     WORLDMAP_WEST  = 0x0008,
75     WORLDMAP_DIR_MASK = 0x000f,
76
77     WORLDMAP_STOP  = 0x0010,
78
79     // convenience values ("C" stands for crossroads)
80     WORLDMAP_CNSE  = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST,
81     WORLDMAP_CNSW  = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_WEST,
82     WORLDMAP_CNEW  = WORLDMAP_NORTH | WORLDMAP_EAST  | WORLDMAP_WEST,
83     WORLDMAP_CSEW  = WORLDMAP_SOUTH | WORLDMAP_EAST  | WORLDMAP_WEST,
84     WORLDMAP_CNSEW = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST | WORLDMAP_WEST
85   };
86
87   struct ImageSpec {
88     ImageSpec(const std::string& newfile, const Rect& newrect)
89       : file(newfile), rect(newrect)
90     { }
91
92     std::string file;
93     Rect rect;
94   };
95
96 private:
97   const TileSet&         tileset;
98   std::vector<ImageSpec> imagespecs;
99   std::vector<Surface*>  images;
100
101   /// tile attributes
102   uint32_t attributes;
103
104   /** General purpose data attached to a tile (content of a box, type of coin)*/
105   int data;
106
107   float anim_fps;
108
109 public:
110   Tile(const TileSet& tileset);
111   Tile(const TileSet& tileset, const std::vector<std::string>& images, Rect rect,
112        uint32_t attributes, uint32_t data, float animfps);
113   ~Tile();
114
115   /** load Surfaces, if not already loaded */
116   void load_images();
117
118   /** Draw a tile on the screen */
119   void draw(DrawingContext& context, const Vector& pos, int z_pos) const;
120
121   uint32_t getAttributes() const
122   { return attributes; }
123
124   int getData() const
125   { return data; }
126
127   void print_debug(int id) const;
128
129 private:
130   //Correct small oddities in attributes that naive people
131   //might miss (and rebuke them for it)
132   void correct_attributes();
133
134 private:
135   Tile(const Tile&);
136   Tile& operator=(const Tile&);
137 };
138
139 #endif
140
141 /* EOF */