impl'd processObjectGroup
[Tsunagari.git] / src / area.h
blobdcd237864e055fc7c4452e8020c0767c25f20370
1 /******************************
2 ** Tsunagari Tile Engine **
3 ** area.h **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #ifndef AREA_H
8 #define AREA_H
10 #include <string>
11 #include <vector>
13 #include <Gosu/Gosu.hpp>
15 #include "common.h"
17 class Entity;
18 class GameWindow;
19 class Resourcer;
20 class Sprite;
22 //! Area Class
23 /*!
24 This class is responsible for each map, or area in a Tsunagari World.
26 class Area
28 public:
30 enum TileFlags {
31 nowalk,
32 player_nowalk,
33 npc_nowalk,
34 player_event,
35 npc_event,
36 temp_event
39 enum TileEventTriggers {
40 onUse,
41 onEnter,
42 onLeave,
43 door
46 //! TileEvent
47 /*!
48 Stores info for an event attached to a tile.
50 struct TileEvent {
51 TileEventTriggers trigger;
52 std::string argv; // Function name and arguments.
55 //! TileType
56 /*!
57 Contains the properties shared by all tiles of a certain type.
58 E.g.: all grass tiles have the same graphic, and all wall tiles
59 are unwalkable.
61 struct TileType {
62 std::vector<Gosu::Image*> graphics;
63 bool animated; // Is the tile animated?
64 double ani_speed; // Speed of animation in hertz
65 std::vector<TileEvent> events;
66 std::vector<TileFlags> flags;
69 //! Tile
70 /*!
71 Stores a tile, including its animation properties, and things
72 attached to it. This is later given to the Tile class
73 constructor through TileMatrix.
75 struct Tile {
76 TileType* type;
77 std::vector<TileEvent> events;
78 std::vector<TileFlags> flags;
82 //! Area Constructor
83 Area(Resourcer* rc, Entity* player, const std::string filename);
85 //! Area Destructor
86 ~Area();
88 bool init();
90 //! Gosu Callback
91 void buttonDown(const Gosu::Button btn);
93 //! Gosu Callback
94 void draw();
96 //! Gosu Callback
97 bool needsRedraw() const;
99 coord_t getDimensions() const;
100 Tile* getTile(coord_t c);
102 private:
103 //! Tileset
105 Stores info for a tileset, and global settings for tiles.
107 struct Tileset {
108 Gosu::Bitmap source;
109 coord_t tiledim; // Dimensions per tile
110 std::vector<TileType> defaults; // Global tile properties
113 //! Music
115 Stores info for the intro or main music files.
117 struct Music {
118 bool loop;
119 std::string filename;
122 bool processDescriptor();
123 bool processMapProperties(xmlNode* node);
124 TileType defaultTileType(const Gosu::Bitmap source, coord_t tiledim,
125 int id);
126 bool processTileset(xmlNode* node);
127 bool processTileType(xmlNode* node, Tileset& ts);
128 bool processLayer(xmlNode* node);
129 bool processLayerProperties(xmlNode* node);
130 bool processLayerData(xmlNode* node);
131 bool processObjectGroup(xmlNode* node);
132 bool processObjectGroupProperties(xmlNode* node, unsigned* zpos);
133 bool processObject(xmlNode* node, unsigned zpos);
136 Resourcer* rc;
137 Entity* player;
138 const std::string descriptor;
140 typedef std::vector<Tile*> row_t;
141 typedef std::vector<row_t> grid_t;
142 typedef std::vector<grid_t> tilematrix_t;
144 /* All layers in the map must be in the range of [0, n]. There cannot be
145 * any gaps.
147 tilematrix_t map;
148 coord_t dim;
150 std::string name;
151 std::string author;
152 std::vector<Tileset> tilesets;
153 Music intro;
154 Music main;
155 std::string scripts;
156 std::string onLoadEvents;
159 #endif