Entity.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <Model3D.h>
  3. #include <Either.h>
  4. #include <Critical.h>
  5. #include "EntityType.h"
  6. #include "Inventory.h"
  7. class Block;
  8. class ActionTarget
  9. {
  10. private:
  11. Framework::Vec3<int> blockPos;
  12. Direction targetBlockSide;
  13. int entityId;
  14. public:
  15. ActionTarget(Framework::Vec3<int> blockPos, Direction blockSide);
  16. ActionTarget(int entityId);
  17. static ActionTarget* load(Framework::StreamReader* zReader);
  18. bool isBlock() const;
  19. bool isEntity() const;
  20. int getEntityId() const;
  21. Framework::Vec3<int> getBlockPos() const;
  22. Direction getBlockSide() const;
  23. Framework::Either<Block*, Entity*> zTarget(int dimensionId) const;
  24. Framework::Either<Block*, Entity*> getTarget(int dimensionId) const;
  25. };
  26. class Entity : public Framework::Model3D, public Inventory
  27. {
  28. protected:
  29. float maxHP;
  30. float currentHP;
  31. float stamina;
  32. float maxStamina;
  33. float hunger;
  34. float maxHunger;
  35. float thirst;
  36. float maxThirst;
  37. float targetDistanceLimit;
  38. Framework::Vec3<float> speed;
  39. Framework::Vec3<float> faceDir;
  40. const EntityType* zEntityType;
  41. int currentDimensionId;
  42. float gravityMultiplier;
  43. int id;
  44. ActionTarget* target;
  45. Framework::Critical cs;
  46. public:
  47. Entity(const EntityType* zType, bool hasInventory);
  48. ~Entity();
  49. void api(char* message);
  50. virtual bool tick(double time) override;
  51. int getId() const;
  52. const EntityType* zType() const;
  53. int getCurrentDimension() const;
  54. void lock();
  55. void unlock();
  56. friend EntityType;
  57. };