#include "Entity.h" #include "Globals.h" ActionTarget::ActionTarget(Framework::Vec3 blockPos, Direction blockSide) : blockPos(blockPos), targetBlockSide(blockSide), entityId(-1) {} ActionTarget::ActionTarget(int entityId) : entityId(entityId) {} ActionTarget* ActionTarget::load(Framework::StreamReader* zReader) { char b; zReader->lese(&b, 1); if (b == 1) { int id; zReader->lese((char*)&id, 4); return new ActionTarget(id); } else if (b == 2) { Framework::Vec3 pos; Direction side; zReader->lese((char*)&pos.x, 4); zReader->lese((char*)&pos.y, 4); zReader->lese((char*)&pos.z, 4); zReader->lese((char*)&side, 4); return new ActionTarget(pos, side); } return 0; } bool ActionTarget::isBlock() const { return entityId == -1; } bool ActionTarget::isEntity() const { return entityId >= 0; } int ActionTarget::getEntityId() const { return entityId; } Framework::Vec3 ActionTarget::getBlockPos() const { return blockPos; } Direction ActionTarget::getBlockSide() const { return targetBlockSide; } Framework::Either ActionTarget::zTarget(int dimension) const { if (entityId >= 0) return currentGame->zEntity(entityId); else return currentGame->zBlockAt(blockPos, dimension); } Framework::Either ActionTarget::getTarget(int dimension) const { if (entityId >= 0) return currentGame->getEntity(entityId); else return currentGame->getBlockAt(blockPos, dimension); } Entity::Entity(const EntityType* zType, bool hasInventory) : Model3D(), Inventory({ 0.f, 0.f, 0.f }, hasInventory), zEntityType(zType), target(0) {} Entity::~Entity() { if (target) delete target; } void Entity::api(char* message) { // TODO: implement api } bool Entity::tick(double time) { setPosition(location); // TODO: calculate rotation based on faceDir return Model3D::tick(time); } int Entity::getId() const { return id; } const EntityType* Entity::zType() const { return zEntityType; } int Entity::getCurrentDimension() const { return currentDimensionId; } void Entity::lock() { cs.lock(); } void Entity::unlock() { cs.unlock(); }