1 /***************************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011-2013 PariahSoft LLC **
5 ***************************************/
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
38 #include "animation.h"
39 #include "reader.h" // for TiledImage
47 //! List of possible flags that can be attached to a tile.
49 Flags are attached to tiles and denote special behavior for
50 the tile they are bound to.
52 see AreaTMX::splitTileFlags().
57 * Neither the player nor NPCs can walk here.
59 #define TILE_NOWALK 0x001
63 * The player cannot walk here. NPCs can, though.
65 #define TILE_NOWALK_PLAYER 0x002
69 * NPCs cannot walk here. The player can, though.
71 #define TILE_NOWALK_NPC 0x004
75 * This Tile is an Exit. Please take appropriate action when entering this Tile,
76 * usually by transferring to another Area.
78 * This flag is not carried by actual Tiles, but can instead be flipped in an
79 * Entity's "exempt" flag which will be read elsewhere in the engine.
81 #define TILE_NOWALK_EXIT 0x008
84 * TILE_NOWALK_AREA_BOUND
85 * This Tile is at the edge of an Area. If you step here, please handle it
88 * (Usually if one moves off a map bound, one will either transfer to another
89 * Area, or will be destroyed.)
91 * This flag is not carried by actual Tiles, but can instead be flipped in an
92 * Entity's "exempt" flag which will be read elsewhere in the engine.
94 #define TILE_NOWALK_AREA_BOUND 0x016
102 * An Exit that is taken upon arriving at the Tile.
106 * An Exit that is taken when leaving in the upwards
107 * direction from a Tile.
111 * An Exit that is taken when leaving in the downwards
112 * direction from a Tile.
116 * An Exit that is taken when leaving to the left from
121 * An Exit that is taken when leaving to the right from
129 * Independant object that can manipulate a Tile's flags.
134 FlagManip(unsigned* flags
);
136 bool isNowalk() const;
137 bool isNowalkPlayer() const;
138 bool isNowalkNPC() const;
139 bool isNowalkExit() const;
140 bool isNowalkAreaBound() const;
142 void setNowalk(bool nowalk
);
143 void setNowalkPlayer(bool nowalk
);
144 void setNowalkNPC(bool nowalk
);
145 void setNowalkExit(bool nowalk
);
146 void setNowalkAreaBound(bool nowalk
);
152 //! Convenience trigger for inter-area teleportation.
154 Tiles with a exit trigger attached can teleport the player to a
155 new area in the World. The Exit struct contains the destination
156 area and coordinates.
161 Exit(const std::string area
, int x
, int y
, double z
);
173 FlagManip
flagManip();
175 //! Determines whether this tile or one of its parent types embodies a
177 bool hasFlag(unsigned flag
) const;
179 TileType
* getType() const;
180 void setType(TileType
* type
);
182 void runEnterScript(Entity
* triggeredBy
);
183 void runLeaveScript(Entity
* triggeredBy
);
184 void runUseScript(Entity
* triggeredBy
);
187 void runScript(Entity
* triggeredBy
, ScriptRef
& script
);
192 ScriptRef enterScript
, leaveScript
, useScript
;
195 //! Contains properties unique to this tile.
197 This struct contains local tile properties for a single tile in
198 the area. As opposed to global properties which apply to all
199 tiles of the same type, these properties will only apply to one
202 class Tile
: public TileBase
205 Tile(); // Should not be used. Wanted by std::containers.
206 Tile(Area
* area
, int x
, int y
, int z
);
209 * Gets the correct destination for an Entity wanting to
210 * move off of this tile in <code>facing</code>
213 * This call is necessary to handle layermod.
215 * @param here area-space coordinate for this Tile
216 * @param facing facing vector
218 icoord
moveDest(icoord here
, ivec2 facing
) const;
219 Tile
* offset(int x
, int y
) const;
223 Exit
* getNormalExit() const;
224 void setNormalExit(Exit exit
);
226 Exit
* exitAt(ivec2 dir
) const;
227 double* layermodAt(ivec2 dir
) const;
233 * The grid-space coordinates of this Tile.
235 * Looping Areas utilize area-space components. These
236 * cannot be losslessly transformed into area-space.
239 Exit
* exits
[EXITS_LENGTH
];
240 double* layermods
[EXITS_LENGTH
];
241 int entCnt
; //!< Number of entities on this Tile.
244 //! Contains the properties shared by all tiles of a certain type.
246 This struct contains global tile properties for a tile of a
247 certain type. As opposed to local properties for a single tile,
248 all tiles of this type will share the defined characteristics.
250 class TileType
: public TileBase
254 TileType(ImageRef
& img
);
256 //! Returns true if onscreen and we need to update our animation.
257 bool needsRedraw() const;
260 Animation anim
; //! Graphics for tiles of this type.
261 std::vector
<Tile
*> allOfType
;
268 TileSet(int width
, int height
);
270 void add(TileType
* type
);
271 void set(int idx
, TileType
* type
);
272 TileType
* get(int x
, int y
);
273 int getWidth() const;
274 int getHeight() const;
277 size_t idx(int x
, int y
) const;
279 std::vector
<TileType
*> types
;