1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #include <libxml/parser.h>
8 #include <libxml/tree.h>
15 Entity::Entity(Resourcer
* rc
,
17 const std::string
& descriptor
)
22 descriptor(descriptor
)
31 * Try to load in descriptor.
33 bool Entity::processDescriptor()
37 XMLDocRef doc
= rc
->getXMLDoc(descriptor
, "dtd/entity.dtd");
40 const xmlNode
* root
= xmlDocGetRootElement(doc
.get()); // <entity>
44 str
= xmlGetProp(const_cast<xmlNode
*>(root
), BAD_CAST("type")); // Entity type
45 if (!xmlStrncmp(str
, BAD_CAST("player"), 7)) {
47 if (!processPlayerDescriptor(root
))
51 Log::err(descriptor
, "unknown entity type");
57 bool Entity::processPlayerDescriptor(const xmlNode
* root
)
61 xmlNode
* node
= root
->xmlChildrenNode
; // children of <entity>
62 for (; node
!= NULL
; node
= node
->next
) {
63 if (!xmlStrncmp(node
->name
, BAD_CAST("sprite"), 7)) {
64 str
= xmlNodeGetContent(node
);
65 spriteDescriptor
= (char*)str
;
74 return processDescriptor() && sprite
.init(spriteDescriptor
);
83 bool Entity::needsRedraw() const
88 coord_t
Entity::getCoordsByPixel()
90 return sprite
.getCoordsByPixel();
93 coord_t
Entity::getCoordsByTile()
95 return sprite
.getCoordsByTile();
98 void Entity::moveByTile(coord_t delta
)
100 coord_t newCoord
= sprite
.getCoordsByTile();
101 newCoord
.x
+= delta
.x
;
102 newCoord
.y
+= delta
.y
;
103 newCoord
.z
+= delta
.z
;
104 Area::Tile
* dest
= area
->getTile(newCoord
);
105 if ((dest
->flags
& Area::nowalk
) != 0 ||
106 (dest
->type
->flags
& Area::nowalk
) != 0) {
107 // The tile we're trying to move onto is set as nowalk.
111 sprite
.moveByTile(delta
);
116 void Entity::setCoordsByTile(coord_t pos
)
118 sprite
.setCoordsByTile(pos
);
122 void Entity::setArea(Area
* area
)
127 void Entity::postMove()