1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #include <boost/foreach.hpp>
15 : type(NULL
), flags(0x0)
19 bool Tile::hasFlag(unsigned flag
) const
21 if (flags
& flag
|| (type
&& type
->flags
& flag
))
26 void Tile::onEnterScripts(Resourcer
* rc
, Entity
* triggeredBy
)
28 if (flags
& hasOnEnter
)
29 runScripts(rc
, triggeredBy
, onEnter
, events
);
30 if (type
&& type
->flags
& hasOnEnter
)
31 runScripts(rc
, triggeredBy
, onEnter
, type
->events
);
34 void Tile::onLeaveScripts(Resourcer
* rc
, Entity
* triggeredBy
)
36 if (type
&& type
->flags
& hasOnLeave
)
37 runScripts(rc
, triggeredBy
, onLeave
,
39 if (flags
& hasOnLeave
)
40 runScripts(rc
, triggeredBy
, onLeave
, events
);
43 void Tile::runScripts(Resourcer
*, Entity
*,
44 const TileEventTrigger trigger
,
45 const std::vector
<TileEvent
>& events
)
47 for (std::vector
<TileEvent
>::const_iterator i
= events
.begin(); i
!= events
.end(); i
++) {
48 // BOOST_FOREACH(const TileEvent& e, events) {
49 const TileEvent
& e
= *i
;
50 if (e
.trigger
== trigger
) {
51 /* FIXME: Redo scripts.
53 bindEntity(&s, entity, "entity");
54 // TODO bindTile(script, tile, "tile");
67 TileType::TileType(TiledImage
& img
)
70 anim
.addFrame(img
.front());
74 bool TileType::needsRedraw(const Area
& area
) const
76 const int millis
= GameWindow::getWindow().time();
77 return anim
.needsRedraw(millis
) &&
78 visibleIn(area
, area
.visibleTiles());
81 bool TileType::visibleIn(const Area
& area
, const icube_t
& tiles
) const
83 for (int z
= tiles
.z1
; z
!= tiles
.z2
; z
++) {
84 for (int y
= tiles
.y1
; y
!= tiles
.y2
; y
++) {
85 for (int x
= tiles
.x1
; x
!= tiles
.x2
; x
++) {
87 // Do this check before passing _tiles_ to fn.
88 if (area
.tileExists(pos
)) {
89 const Tile
& tile
= area
.getTile(pos
);
90 if (tile
.type
== this)