area.cpp: fix pointer dereference
[Tsunagari.git] / src / area.h
blob1e23e1e62e95a6053bf46e0b92da410b3b11de29
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>
14 #include <libxml/parser.h>
15 #include <libxml/tree.h>
17 #include "common.h"
19 class Entity;
20 class GameWindow;
21 class Resourcer;
22 class Sprite;
23 class World;
25 //! Area Class
26 /*!
27 This class is responsible for each map, or area in a Tsunagari World.
29 class Area
31 public:
33 // when changing TileFlags, be sure to make updates to Area::splitTileFlags()
34 enum TileFlags {
35 nowalk = 0x0001,
36 player_nowalk = 0x0002,
37 npc_nowalk = 0x0004,
38 player_event = 0x0008,
39 npc_event = 0x0010,
40 temp_event = 0x0020
43 enum TileEventTriggers {
44 onUse,
45 onEnter,
46 onLeave,
47 door
50 //! TileEvent
51 /*!
52 Stores info for an event attached to a tile.
54 struct TileEvent {
55 TileEventTriggers trigger;
56 std::string argv; // Function name and arguments.
59 //! Door
60 /*!
61 Some tiles can teleport you to a new area or a new position
62 in your current area.
64 struct Door {
65 std::string area;
66 coord_t coord;
69 //! TileType
70 /*!
71 Contains the properties shared by all tiles of a certain type.
72 E.g.: all grass tiles have the same graphic, and all wall tiles
73 are unwalkable.
75 struct TileType {
76 std::vector<Gosu::Image*> graphics;
77 bool animated; // Is the tile animated?
78 double ani_speed; // Speed of animation in hertz
79 std::vector<TileEvent> events;
80 unsigned flags; // bitflags for each option in TileFlags enum
81 // TODO: Door* door
84 //! Tile
85 /*!
86 Stores a tile, including its animation properties, and things
87 attached to it. This is later given to the Tile class
88 constructor through TileMatrix.
90 struct Tile {
91 TileType* type;
92 std::vector<TileEvent> events;
93 unsigned flags; // bitflags for each option in TileFlags enum
94 Door* door;
98 //! Area Constructor
99 Area(Resourcer* rc, World* world, Entity* player, const std::string& filename);
101 //! Area Destructor
102 ~Area();
104 bool init();
106 //! Gosu Callback
107 void buttonDown(const Gosu::Button btn);
109 //! Gosu Callback
110 void draw();
112 //! Gosu Callback
113 bool needsRedraw() const;
115 coord_t getDimensions() const;
116 Tile* getTile(coord_t c);
118 private:
119 //! Tileset
121 Stores info for a tileset, and global settings for tiles.
123 struct Tileset {
124 Gosu::Bitmap source;
125 coord_t tiledim; // Dimensions per tile
126 std::vector<TileType> defaults; // Global tile properties
129 //! Music
131 Stores info for the intro or main music files.
133 struct Music {
134 bool loop;
135 std::string filename;
138 bool processDescriptor();
139 bool processMapProperties(xmlNode* node);
140 TileType defaultTileType(const Gosu::Bitmap source, coord_t tiledim,
141 int id);
142 bool processTileset(xmlNode* node);
143 bool processTileType(xmlNode* node, Tileset& ts);
144 bool processLayer(xmlNode* node);
145 bool processLayerProperties(xmlNode* node);
146 bool processLayerData(xmlNode* node);
147 bool processObjectGroup(xmlNode* node);
148 bool processObjectGroupProperties(xmlNode* node, int* zpos);
149 bool processObject(xmlNode* node, int zpos);
150 unsigned splitTileFlags(const std::string strOfFlags);
151 Door* parseDoor(const std::string dest);
153 Gosu::Transform translateCoords();
156 Resourcer* rc;
157 World* world;
158 Entity* player;
159 const std::string descriptor;
161 typedef std::vector<Tile*> row_t;
162 typedef std::vector<row_t> grid_t;
163 typedef std::vector<grid_t> tilematrix_t;
165 /* All layers in the map must be in the range of [0, n]. There cannot be
166 * any gaps.
168 tilematrix_t map;
169 coord_t dim;
171 std::string name;
172 std::string author;
173 std::vector<Tileset> tilesets;
174 Music intro;
175 Music main;
176 std::string scripts;
177 std::string onLoadEvents;
180 #endif