Entity.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #pragma once
  2. #include <Maybe.h>
  3. #include <Vec3.h>
  4. #include <Writer.h>
  5. #include <Zeit.h>
  6. #include "Inventory.h"
  7. #include "ItemSkill.h"
  8. #include "ModelInfo.h"
  9. #include "NetworkMessage.h"
  10. #include "UIObservable.h"
  11. class EntityType;
  12. class Dimension;
  13. class ActionTarget
  14. {
  15. private:
  16. Framework::Vec3<int> blockPos;
  17. Direction targetBlockSide;
  18. int entityId;
  19. public:
  20. ActionTarget(Framework::Vec3<int> blockPos, Direction blockSide);
  21. ActionTarget(int entityId);
  22. bool isBlock(Framework::Vec3<int> blockPos, Direction blockSide) const;
  23. bool isEntity(int entityId) const;
  24. bool useItemSkillOnTarget(
  25. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
  26. bool interactItemSkillOnTarget(
  27. Entity* zActor, ItemSkill* zItemSkill, Item* zUsedItem);
  28. bool placeBlock(Entity* zActor, Item* zItem);
  29. static void toMessage(
  30. const ActionTarget* zTarget, int dimensionId, NetworkMessage* zMsg);
  31. static void save(ActionTarget* zTarget, Framework::StreamWriter* zWriter);
  32. static ActionTarget* load(Framework::StreamReader* zReader);
  33. };
  34. class MovementFlags
  35. {
  36. public:
  37. static const int SNEAKING = 0x00001;
  38. static const int SPRINTING = 0x00002;
  39. static const int FLYING = 0x00004;
  40. static const int JUMPING = 0x00008;
  41. static const int WALK_FORWARD = 0x00010;
  42. static const int WALK_BACKWARD = 0x00020;
  43. static const int WALK_LEFT = 0x00040;
  44. static const int WALK_RIGHT = 0x00080;
  45. static const int ROTATE_LEFT = 0x00100;
  46. static const int ROTATE_RIGHT = 0x00200;
  47. static const int GROUND_CONTACT = 0x01000;
  48. static const int ROTATE_TO_FACE = 0x02000;
  49. };
  50. class Entity : public Inventory
  51. {
  52. private:
  53. UIObservable statusBarObservable;
  54. float stamina;
  55. float hunger;
  56. float currentHP;
  57. float thirst;
  58. int chatSecurityLevel;
  59. Framework::Punkt lastChunkCenter;
  60. int lastDimensionId;
  61. Framework::Maybe<Framework::Punkt> lastSavedChunkCenter;
  62. protected:
  63. float maxHP;
  64. float maxStamina;
  65. float maxHunger;
  66. float maxThirst;
  67. float targetDistanceLimit;
  68. float maxMovementSpeed;
  69. Framework::Vec3<float> speed;
  70. Framework::Vec3<float> faceDir;
  71. Framework::Vec3<float> faceOffset;
  72. Framework::RCArray<ItemSkill> skills;
  73. ActionTarget* target;
  74. int typeId;
  75. bool removed;
  76. float gravityMultiplier;
  77. float jumpSpeed;
  78. int id;
  79. double placeBlockCooldown;
  80. Framework::Critical cs;
  81. Framework::Vec3<float> boundingBox;
  82. float rotation;
  83. int movementFlags;
  84. virtual void onDeath(
  85. Entity* zActor, Item* zUsedItem, ItemSkill* zUsedSkill);
  86. virtual bool useItem(int typeId, ItemStack* zStack, bool left);
  87. Entity(int typeId,
  88. Framework::Vec3<float> location,
  89. int dimensionId,
  90. int entityId);
  91. void calculateTarget(const Item* zItem);
  92. void notifyStatusBarObservers(NetworkMessage* msg);
  93. ItemSkill* zSkill(int itemType);
  94. void calcBlockCollision(int& x, int& y, int& xl, int& yl, bool** map);
  95. bool isCollidingWithBlock(const Dimension* zDimension);
  96. bool isCollidingWithBlock(
  97. const Dimension* zDimension, int x, int y, int xl, int yl, bool* map);
  98. public:
  99. virtual void prepareTick(const Dimension* zDimension, double seconds);
  100. virtual void tick(const Dimension* zDimension, double seconds);
  101. virtual void api(Framework::StreamReader* zRequest,
  102. NetworkMessage* zResponse,
  103. Entity* zSource);
  104. virtual void onTargetChange();
  105. virtual bool interact(Item* zItem, Entity* zActor);
  106. virtual void onFall(float collisionSpeed);
  107. virtual Framework::XML::Element* getTargetUIML() const;
  108. void setChatSecurityLevel(int level);
  109. void setPosition(Framework::Vec3<float> pos);
  110. virtual void takeDamage(
  111. Entity* zSource, Item* zUsedItem, ItemSkill* zUsedSkill, float damage);
  112. void setHP(
  113. Entity* zActor, Item* zUsedItem, ItemSkill* zUsedSkill, float hp);
  114. void setStamina(float stamina);
  115. void setHunger(float hunger);
  116. void setThirst(float thirst);
  117. void setGravityMultiplier(float multiplier);
  118. void setJumpSpeed(float speed);
  119. float getMaxHP() const;
  120. float getCurrentHP() const;
  121. float getStamina() const;
  122. float getMaxStamina() const;
  123. float getHunger() const;
  124. float getMaxHunger() const;
  125. float getThirst() const;
  126. float getMaxThirst() const;
  127. Framework::Vec3<float> getSpeed() const;
  128. Framework::Vec3<float> getFaceDir() const;
  129. Framework::Vec3<float> getPosition() const;
  130. float getGravityMultiplier() const;
  131. float getJumpSpeed() const;
  132. bool isRemoved() const;
  133. const EntityType* zType() const;
  134. const ActionTarget* zTarget() const;
  135. int getId() const;
  136. virtual bool hasDefaultModel() const;
  137. virtual ModelInfo* zSpecialModel() const;
  138. float getMaxSpeed() const;
  139. bool isMoving() const;
  140. int getChatSecurityLevel() const;
  141. Framework::Maybe<Framework::Punkt> getLastSavedChunkCenter() const;
  142. void setLastSavedChunkCenter(Framework::Punkt pos);
  143. void setRemoved();
  144. double getHitDistance(Framework::Vec3<float> rayOrigin,
  145. Framework::Vec3<float> rayDirection) const;
  146. float getRotation() const;
  147. friend EntityType;
  148. };