3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "environment.h"
24 #include "constants.h"
31 class ClientActiveObject;
32 class ClientEnvironment;
34 struct collisionMoveResult;
36 enum LocalPlayerAnimations
42 }; // no local animation, walking, digging, both
44 class LocalPlayer : public Player
47 LocalPlayer(Client *client, const char *name);
48 virtual ~LocalPlayer() = default;
50 // Initialize hp to 0, so that no hearts will be shown if server
51 // doesn't support health points
53 bool touching_ground = false;
54 // This oscillates so that the player jumps a bit above the surface
55 bool in_liquid = false;
56 // This is more stable and defines the maximum speed of the player
57 bool in_liquid_stable = false;
58 // Gets the viscosity of water to calculate friction
59 u8 liquid_viscosity = 0;
60 bool is_climbing = false;
61 bool swimming_vertical = false;
62 bool swimming_pitch = false;
64 float physics_override_speed = 1.0f;
65 float physics_override_jump = 1.0f;
66 float physics_override_gravity = 1.0f;
67 bool physics_override_sneak = true;
68 bool physics_override_sneak_glitch = false;
69 // Temporary option for old move code
70 bool physics_override_new_move = true;
72 void move(f32 dtime, Environment *env, f32 pos_max_d);
73 void move(f32 dtime, Environment *env, f32 pos_max_d,
74 std::vector<CollisionInfo> *collision_info);
75 // Temporary option for old move code
76 void old_move(f32 dtime, Environment *env, f32 pos_max_d,
77 std::vector<CollisionInfo> *collision_info);
79 void applyControl(float dtime, Environment *env);
81 v3s16 getStandingNodePos();
82 v3s16 getFootstepNodePos();
84 // Used to check if anything changed and prevent sending packets if not
87 float last_pitch = 0.0f;
88 float last_yaw = 0.0f;
89 unsigned int last_keyPressed = 0;
90 u8 last_camera_fov = 0;
91 u8 last_wanted_range = 0;
93 float camera_impact = 0.0f;
95 bool makes_footstep_sound = true;
97 int last_animation = NO_ANIM;
98 float last_animation_speed = 0.0f;
100 std::string hotbar_image = "";
101 std::string hotbar_selected_image = "";
103 video::SColor light_color = video::SColor(255, 255, 255, 255);
105 float hurt_tilt_timer = 0.0f;
106 float hurt_tilt_strength = 0.0f;
108 GenericCAO *getCAO() const { return m_cao; }
110 ClientActiveObject *getParent() const;
112 void setCAO(GenericCAO *toset)
114 assert(!m_cao); // Pre-condition
118 u32 maxHudId() const { return hud.size(); }
120 u16 getBreath() const { return m_breath; }
121 void setBreath(u16 breath) { m_breath = breath; }
123 v3s16 getLightPosition() const;
125 void setYaw(f32 yaw) { m_yaw = yaw; }
126 f32 getYaw() const { return m_yaw; }
128 void setPitch(f32 pitch) { m_pitch = pitch; }
129 f32 getPitch() const { return m_pitch; }
131 inline void setPosition(const v3f &position)
133 m_position = position;
134 m_sneak_node_exists = false;
137 v3f getPosition() const { return m_position; }
139 // Non-transformed eye offset getters
140 // For accurate positions, use the Camera functions
141 v3f getEyePosition() const { return m_position + getEyeOffset(); }
142 v3f getEyeOffset() const;
143 void setEyeHeight(float eye_height) { m_eye_height = eye_height; }
145 void setCollisionbox(const aabb3f &box) { m_collisionbox = box; }
147 const aabb3f& getCollisionbox() const { return m_collisionbox; }
149 float getZoomFOV() const { return m_zoom_fov; }
150 void setZoomFOV(float zoom_fov) { m_zoom_fov = zoom_fov; }
152 bool getAutojump() const { return m_autojump; }
156 inline void addVelocity(const v3f &vel)
158 added_velocity += vel;
162 void accelerate(const v3f &target_speed, const f32 max_increase_H,
163 const f32 max_increase_V, const bool use_pitch);
164 bool updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max);
165 float getSlipFactor(Environment *env, const v3f &speedH);
166 void handleAutojump(f32 dtime, Environment *env,
167 const collisionMoveResult &result,
168 const v3f &position_before_move, const v3f &speed_before_move,
172 v3s16 m_standing_node;
174 v3s16 m_sneak_node = v3s16(32767, 32767, 32767);
175 // Stores the top bounding box of m_sneak_node
176 aabb3f m_sneak_node_bb_top = aabb3f(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
177 // Whether the player is allowed to sneak
178 bool m_sneak_node_exists = false;
179 // Whether a "sneak ladder" structure is detected at the players pos
180 // see detectSneakLadder() in the .cpp for more info (always false if disabled)
181 bool m_sneak_ladder_detected = false;
183 // ***** Variables for temporary option of the old move code *****
184 // Stores the max player uplift by m_sneak_node
185 f32 m_sneak_node_bb_ymax = 0.0f;
186 // Whether recalculation of m_sneak_node and its top bbox is needed
187 bool m_need_to_get_new_sneak_node = true;
188 // Node below player, used to determine whether it has been removed,
190 v3s16 m_old_node_below = v3s16(32767, 32767, 32767);
191 std::string m_old_node_below_type = "air";
192 // ***** End of variables for temporary option *****
194 bool m_can_jump = false;
195 bool m_disable_jump = false;
196 u16 m_breath = PLAYER_MAX_BREATH_DEFAULT;
199 bool camera_barely_in_ceiling = false;
200 aabb3f m_collisionbox = aabb3f(-BS * 0.30f, 0.0f, -BS * 0.30f, BS * 0.30f,
201 BS * 1.75f, BS * 0.30f);
202 float m_eye_height = 1.625f;
203 float m_zoom_fov = 0.0f;
204 bool m_autojump = false;
205 float m_autojump_time = 0.0f;
207 v3f added_velocity = v3f(0.0f); // cleared on each move()
208 // TODO: Rename to adhere to convention: added_velocity --> m_added_velocity
210 GenericCAO *m_cao = nullptr;