]> git.localhorst.tv Git - l2e.git/blob - src/map/Map.h
better accessibility of map-related properties
[l2e.git] / src / map / Map.h
1 #ifndef MAP_MAP_H_
2 #define MAP_MAP_H_
3
4 namespace map {
5         class Area;
6         class Tile;
7         class Trigger;
8 }
9 namespace math {
10         template<class>
11         class Vector;
12 }
13
14 #include "Entity.h"
15
16 #include <SDL.h>
17
18 namespace map {
19
20 /// Represents a single map in the game.
21 /// Maps are made up of uniform areas of tiles.
22 /// The looks of a tile is defined by the Tileset() sprite with Tile::Offset()
23 /// as the column and row in the sprite.
24 /// Maps can be propulated with triggers and entities. Those are for use with
25 /// a MapState and are not handled by the map itself.
26 /// Positions are expressed either as pixel or tile coordinates depending on
27 /// function purpose with (0|0) being the top left corner and positive values
28 /// extending to the right and down respectively.
29 class Map {
30
31 public:
32         static const int TYPE_ID = 602;
33
34 public:
35         Map();
36         ~Map() { }
37
38 public:
39         /// The sprite used as the tileset.
40         const graphics::Sprite *Tileset() const { return tileset; }
41         /// Returns the Area at given pixel coordinates or 0 if off the map.
42         Area *AreaAt(const math::Vector<int> &);
43         const Area *AreaAt(const math::Vector<int> &) const;
44         /// Returns the Tile at given pixel coordinates or 0 if off the map.
45         Tile *TileAt(const math::Vector<int> &);
46         const Tile *TileAt(const math::Vector<int> &) const;
47         /// Returns the Trigger at given pixel coordinates or 0 if off the map.
48         /// Multiple triggers are not supported. The first one found is returned.
49         Trigger *TriggerAt(const math::Vector<int> &);
50         /// The battle background image for this map if neither the tile nor the
51         /// area has one specified.
52         SDL_Surface *BattleBackgroundAt(const math::Vector<int> &);
53         /// Convert coordinates from pixel to tile.
54         math::Vector<int> TileCoordinates(const math::Vector<int> &) const;
55         /// Convert coordinates from tile to pixel.
56         math::Vector<int> PixelCoordinates(const math::Vector<int> &) const;
57
58         Entity *EntitiesBegin() { return entities; }
59         Entity *EntitiesEnd() { return entities + numEntities; }
60
61         /// Render the map.
62         /// Entities are not rendered by this function.
63         void Render(
64                         SDL_Surface *dest,
65                         const math::Vector<int> &offset,
66                         unsigned int frame) const;
67         /// Render a debugging overlay that includes collision and trigger
68         /// information.
69         void RenderDebug(SDL_Surface *dest, const math::Vector<int> &offset) const;
70
71         static void CreateTypeDescription();
72         static void Construct(void *);
73
74 private:
75         const graphics::Sprite *tileset;
76         SDL_Surface *battlebg;
77         Area *areas;
78         int numAreas;
79         Trigger *triggers;
80         int numTriggers;
81         Entity *entities;
82         int numEntities;
83         int width;
84
85 };
86
87 }
88
89 #endif