1 /*********************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011-2012 OmegaSDG **
5 *********************************/
13 #include <boost/optional.hpp>
15 #include "animation.h"
16 #include "resourcer.h" // for TiledImage
17 #include "scriptinst.h"
23 //! List of possible flags that can be attached to a tile.
25 Flags are attached to tiles and denote special behavior for
26 the tile they are bound to.
28 see AreaTMX::splitTileFlags().
33 * Neither the player nor NPCs can walk here.
35 #define TILE_NOWALK 0x001
39 * The player cannot walk here. NPCs can, though.
41 #define TILE_NOWALK_PLAYER 0x002
45 * NPCs cannot walk here. The player can, though.
47 #define TILE_NOWALK_NPC 0x004
51 * This Tile is an Exit. Please take appropriate action when entering this Tile,
52 * usually by transferring to another Area.
54 * This flag is not carried by actual Tiles, but can instead be flipped in an
55 * Entity's "exempt" flag which will be read elsewhere in the engine.
57 #define TILE_NOWALK_EXIT 0x008
60 * TILE_NOWALK_AREA_BOUND
61 * This Tile is at the edge of an Area. If you step here, please handle it
64 * (Usually if one moves off a map bound, one will either transfer to another
65 * Area, or will be destroyed.)
67 * This flag is not carried by actual Tiles, but can instead be flipped in an
68 * Entity's "exempt" flag which will be read elsewhere in the engine.
70 #define TILE_NOWALK_AREA_BOUND 0x016
78 * An Exit that is taken upon arriving at the Tile.
82 * An Exit that is taken when leaving in the upwards
83 * direction from a Tile.
87 * An Exit that is taken when leaving in the downwards
88 * direction from a Tile.
92 * An Exit that is taken when leaving to the left from
97 * An Exit that is taken when leaving to the right from
105 * Independant object that can manipulate a Tile's flags.
110 FlagManip(unsigned* flags
);
112 bool isNowalk() const;
113 bool isNowalkPlayer() const;
114 bool isNowalkNPC() const;
115 bool isNowalkExit() const;
116 bool isNowalkAreaBound() const;
118 void setNowalk(bool nowalk
);
119 void setNowalkPlayer(bool nowalk
);
120 void setNowalkNPC(bool nowalk
);
121 void setNowalkExit(bool nowalk
);
122 void setNowalkAreaBound(bool nowalk
);
128 //! Convenience trigger for inter-area teleportation.
130 Tiles with a exit trigger attached can teleport the player to a
131 new area in the World. The Exit struct contains the destination
132 area and coordinates.
137 Exit(const std::string area
, int x
, int y
, double z
);
149 FlagManip
flagManip();
151 //! Determines whether this tile or one of its parent types embodies a
153 bool hasFlag(unsigned flag
) const;
155 TileType
* getType() const;
156 void setType(TileType
* type
);
158 void runEnterScript(Entity
* triggeredBy
);
159 void runLeaveScript(Entity
* triggeredBy
);
160 void runUseScript(Entity
* triggeredBy
);
163 void runScript(Entity
* triggeredBy
, ScriptInst
& script
);
168 ScriptInst enterScript
, leaveScript
, useScript
;
171 //! Contains properties unique to this tile.
173 This struct contains local tile properties for a single tile in
174 the area. As opposed to global properties which apply to all
175 tiles of the same type, these properties will only apply to one
178 class Tile
: public TileBase
181 Tile(); // Should not be used. Wanted by std::containers.
182 Tile(Area
* area
, int x
, int y
, int z
);
185 * Gets the correct destination for an Entity wanting to
186 * move off of this tile in <code>facing</code>
189 * This call is necessary to handle layermod.
191 * @param here area-space coordinate for this Tile
192 * @param facing facing vector
194 icoord
moveDest(icoord here
, ivec2 facing
) const;
195 Tile
* offset(int x
, int y
) const;
199 Exit
* getNormalExit() const;
200 void setNormalExit(Exit exit
);
202 Exit
* exitAt(ivec2 dir
) const;
203 boost::optional
<double> layermodAt(ivec2 dir
) const;
209 * The grid-space coordinates of this Tile.
211 * Looping Areas utilize area-space components. These
212 * cannot be losslessly transformed into area-space.
215 Exit
* exits
[EXITS_LENGTH
];
216 boost::optional
<double> layermods
[EXITS_LENGTH
];
217 int entCnt
; //!< Number of entities on this Tile.
220 //! Contains the properties shared by all tiles of a certain type.
222 This struct contains global tile properties for a tile of a
223 certain type. As opposed to local properties for a single tile,
224 all tiles of this type will share the defined characteristics.
226 class TileType
: public TileBase
230 TileType(ImageRef
& img
);
232 //! Returns true if onscreen and we need to update our animation.
233 bool needsRedraw() const;
236 Animation anim
; //! Graphics for tiles of this type.
237 std::vector
<Tile
*> allOfType
;
244 TileSet(int width
, int height
);
246 void add(TileType
* type
);
247 void set(int idx
, TileType
* type
);
248 TileType
* get(int x
, int y
);
249 int getWidth() const;
250 int getHeight() const;
253 size_t idx(int x
, int y
) const;
255 std::vector
<TileType
*> types
;