123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #include "Entity.h"
- #include "Globals.h"
- ActionTarget::ActionTarget(Framework::Vec3<int> 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<int> 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<int> ActionTarget::getBlockPos() const
- {
- return blockPos;
- }
- Direction ActionTarget::getBlockSide() const
- {
- return targetBlockSide;
- }
- Framework::Either<Block*, Entity*> ActionTarget::zTarget(int dimension) const
- {
- if (entityId >= 0)
- return currentGame->zEntity(entityId);
- else
- return currentGame->zBlockAt(blockPos, dimension);
- }
- Framework::Either<Block*, Entity*> 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();
- }
|