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.
20 #ifndef LOCALPLAYER_HEADER
21 #define LOCALPLAYER_HEADER
24 #include "environment.h"
30 class ClientActiveObject;
33 enum LocalPlayerAnimations
39 }; // no local animation, walking, digging, both
41 class LocalPlayer : public Player
44 LocalPlayer(Client *client, const char *name);
45 virtual ~LocalPlayer();
47 ClientActiveObject *parent;
52 // This oscillates so that the player jumps a bit above the surface
54 // This is more stable and defines the maximum speed of the player
55 bool in_liquid_stable;
56 // Gets the viscosity of water to calculate friction
59 bool swimming_vertical;
61 float physics_override_speed;
62 float physics_override_jump;
63 float physics_override_gravity;
64 bool physics_override_sneak;
65 bool physics_override_sneak_glitch;
66 // Temporary option for old move code
67 bool physics_override_new_move;
71 void move(f32 dtime, Environment *env, f32 pos_max_d);
72 void move(f32 dtime, Environment *env, f32 pos_max_d,
73 std::vector<CollisionInfo> *collision_info);
74 // Temporary option for old move code
75 void old_move(f32 dtime, Environment *env, f32 pos_max_d,
76 std::vector<CollisionInfo> *collision_info);
78 void applyControl(float dtime);
80 v3s16 getStandingNodePos();
81 v3s16 getFootstepNodePos();
83 // Used to check if anything changed and prevent sending packets if not
88 unsigned int last_keyPressed;
94 bool makes_footstep_sound;
97 float last_animation_speed;
99 std::string hotbar_image;
100 std::string hotbar_selected_image;
102 video::SColor light_color;
104 float hurt_tilt_timer;
105 float hurt_tilt_strength;
107 GenericCAO *getCAO() const { return m_cao; }
109 void setCAO(GenericCAO *toset)
111 assert(m_cao == NULL); // Pre-condition
115 u32 maxHudId() const { return hud.size(); }
117 u16 getBreath() const { return m_breath; }
118 void setBreath(u16 breath) { m_breath = breath; }
120 v3s16 getLightPosition() const;
122 void setYaw(f32 yaw) { m_yaw = yaw; }
124 f32 getYaw() const { return m_yaw; }
126 void setPitch(f32 pitch) { m_pitch = pitch; }
128 f32 getPitch() const { return m_pitch; }
130 inline void setPosition(const v3f &position)
132 m_position = position;
133 m_sneak_node_exists = false;
136 v3f getPosition() const { return m_position; }
137 v3f getEyePosition() const { return m_position + getEyeOffset(); }
138 v3f getEyeOffset() const;
141 void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
142 void accelerateVertical(const v3f &target_speed, const f32 max_increase);
147 // Stores the max player uplift by m_sneak_node
148 // To support temporary option for old move code
149 f32 m_sneak_node_bb_ymax;
150 // Stores the top bounding box of m_sneak_node
151 aabb3f m_sneak_node_bb_top;
152 // Whether the player is allowed to sneak
153 bool m_sneak_node_exists;
154 // Whether recalculation of m_sneak_node and its top bbox is needed
155 bool m_need_to_get_new_sneak_node;
156 // Whether a "sneak ladder" structure is detected at the players pos
157 // see detectSneakLadder() in the .cpp for more info (always false if disabled)
158 bool m_sneak_ladder_detected;
159 // Whether a 2-node-up ledge is detected at the players pos,
160 // see detectLedge() in the .cpp for more info (always false if disabled).
161 bool m_ledge_detected;
163 // Node below player, used to determine whether it has been removed,
165 v3s16 m_old_node_below;
166 std::string m_old_node_below_type;
171 bool camera_barely_in_ceiling;
172 aabb3f m_collisionbox;