localplayer.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "player.h"
  18. #include "environment.h"
  19. #include "constants.h"
  20. #include <list>
  21. class Client;
  22. class Environment;
  23. class GenericCAO;
  24. class ClientActiveObject;
  25. class ClientEnvironment;
  26. class IGameDef;
  27. enum LocalPlayerAnimations
  28. {
  29. NO_ANIM,
  30. WALK_ANIM,
  31. DIG_ANIM,
  32. WD_ANIM
  33. }; // no local animation, walking, digging, both
  34. class LocalPlayer : public Player
  35. {
  36. public:
  37. LocalPlayer(Client *client, const char *name);
  38. virtual ~LocalPlayer() = default;
  39. ClientActiveObject *parent = nullptr;
  40. // Initialize hp to 0, so that no hearts will be shown if server
  41. // doesn't support health points
  42. u16 hp = 0;
  43. bool isAttached = false;
  44. bool touching_ground = false;
  45. // This oscillates so that the player jumps a bit above the surface
  46. bool in_liquid = false;
  47. // This is more stable and defines the maximum speed of the player
  48. bool in_liquid_stable = false;
  49. // Gets the viscosity of water to calculate friction
  50. u8 liquid_viscosity = 0;
  51. bool is_climbing = false;
  52. bool swimming_vertical = false;
  53. bool is_slipping = false;
  54. float physics_override_speed = 1.0f;
  55. float physics_override_jump = 1.0f;
  56. float physics_override_gravity = 1.0f;
  57. bool physics_override_sneak = true;
  58. bool physics_override_sneak_glitch = false;
  59. // Temporary option for old move code
  60. bool physics_override_new_move = true;
  61. v3f overridePosition;
  62. void move(f32 dtime, Environment *env, f32 pos_max_d);
  63. void move(f32 dtime, Environment *env, f32 pos_max_d,
  64. std::vector<CollisionInfo> *collision_info);
  65. // Temporary option for old move code
  66. void old_move(f32 dtime, Environment *env, f32 pos_max_d,
  67. std::vector<CollisionInfo> *collision_info);
  68. void applyControl(float dtime, Environment *env);
  69. v3s16 getStandingNodePos();
  70. v3s16 getFootstepNodePos();
  71. // Used to check if anything changed and prevent sending packets if not
  72. v3f last_position;
  73. v3f last_speed;
  74. float last_pitch = 0.0f;
  75. float last_yaw = 0.0f;
  76. unsigned int last_keyPressed = 0;
  77. u8 last_camera_fov = 0;
  78. u8 last_wanted_range = 0;
  79. float camera_impact = 0.0f;
  80. bool makes_footstep_sound = true;
  81. int last_animation = NO_ANIM;
  82. float last_animation_speed;
  83. std::string hotbar_image = "";
  84. std::string hotbar_selected_image = "";
  85. video::SColor light_color = video::SColor(255, 255, 255, 255);
  86. float hurt_tilt_timer = 0.0f;
  87. float hurt_tilt_strength = 0.0f;
  88. GenericCAO *getCAO() const { return m_cao; }
  89. void setCAO(GenericCAO *toset)
  90. {
  91. assert(!m_cao); // Pre-condition
  92. m_cao = toset;
  93. }
  94. u32 maxHudId() const { return hud.size(); }
  95. u16 getBreath() const { return m_breath; }
  96. void setBreath(u16 breath) { m_breath = breath; }
  97. v3s16 getLightPosition() const;
  98. void setYaw(f32 yaw) { m_yaw = yaw; }
  99. f32 getYaw() const { return m_yaw; }
  100. void setPitch(f32 pitch) { m_pitch = pitch; }
  101. f32 getPitch() const { return m_pitch; }
  102. inline void setPosition(const v3f &position)
  103. {
  104. m_position = position;
  105. m_sneak_node_exists = false;
  106. }
  107. v3f getPosition() const { return m_position; }
  108. v3f getEyePosition() const { return m_position + getEyeOffset(); }
  109. v3f getEyeOffset() const;
  110. void setCollisionbox(const aabb3f &box) { m_collisionbox = box; }
  111. bool getCanZoom() const { return m_can_zoom; }
  112. void setCanZoom(bool can_zoom) { m_can_zoom = can_zoom; }
  113. private:
  114. void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
  115. void accelerateVertical(const v3f &target_speed, const f32 max_increase);
  116. bool updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max);
  117. float getSlipFactor(Environment *env, const v3f &speedH);
  118. v3f m_position;
  119. v3s16 m_standing_node;
  120. v3s16 m_sneak_node = v3s16(32767, 32767, 32767);
  121. // Stores the top bounding box of m_sneak_node
  122. aabb3f m_sneak_node_bb_top = aabb3f(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
  123. // Whether the player is allowed to sneak
  124. bool m_sneak_node_exists = false;
  125. // Whether a "sneak ladder" structure is detected at the players pos
  126. // see detectSneakLadder() in the .cpp for more info (always false if disabled)
  127. bool m_sneak_ladder_detected = false;
  128. // ***** Variables for temporary option of the old move code *****
  129. // Stores the max player uplift by m_sneak_node
  130. f32 m_sneak_node_bb_ymax = 0.0f;
  131. // Whether recalculation of m_sneak_node and its top bbox is needed
  132. bool m_need_to_get_new_sneak_node = true;
  133. // Node below player, used to determine whether it has been removed,
  134. // and its old type
  135. v3s16 m_old_node_below = v3s16(32767, 32767, 32767);
  136. std::string m_old_node_below_type = "air";
  137. // ***** End of variables for temporary option *****
  138. bool m_can_jump = false;
  139. u16 m_breath = PLAYER_MAX_BREATH_DEFAULT;
  140. f32 m_yaw = 0.0f;
  141. f32 m_pitch = 0.0f;
  142. bool camera_barely_in_ceiling = false;
  143. aabb3f m_collisionbox = aabb3f(-BS * 0.30f, 0.0f, -BS * 0.30f, BS * 0.30f,
  144. BS * 1.75f, BS * 0.30f);
  145. bool m_can_zoom = true;
  146. GenericCAO *m_cao = nullptr;
  147. Client *m_client;
  148. };