]> git.lizzy.rs Git - dragonfireclient.git/blob - src/localplayer.h
dc59c4179a09dd1a28ad3e818482f1464213d33f
[dragonfireclient.git] / src / localplayer.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #pragma once
21
22 #include "player.h"
23 #include "environment.h"
24 #include "constants.h"
25 #include "settings.h"
26 #include <list>
27
28 class Client;
29 class Environment;
30 class GenericCAO;
31 class ClientActiveObject;
32 class ClientEnvironment;
33 class IGameDef;
34
35 enum LocalPlayerAnimations
36 {
37         NO_ANIM,
38         WALK_ANIM,
39         DIG_ANIM,
40         WD_ANIM
41 }; // no local animation, walking, digging, both
42
43 class LocalPlayer : public Player
44 {
45 public:
46         LocalPlayer(Client *client, const char *name);
47         virtual ~LocalPlayer() = default;
48
49         ClientActiveObject *parent = nullptr;
50
51         // Initialize hp to 0, so that no hearts will be shown if server
52         // doesn't support health points
53         u16 hp = 0;
54         bool isAttached = false;
55         bool touching_ground = false;
56         // This oscillates so that the player jumps a bit above the surface
57         bool in_liquid = false;
58         // This is more stable and defines the maximum speed of the player
59         bool in_liquid_stable = false;
60         // Gets the viscosity of water to calculate friction
61         u8 liquid_viscosity = 0;
62         bool is_climbing = false;
63         bool swimming_vertical = false;
64
65         float physics_override_speed = 1.0f;
66         float physics_override_jump = 1.0f;
67         float physics_override_gravity = 1.0f;
68         bool physics_override_sneak = true;
69         bool physics_override_sneak_glitch = false;
70         // Temporary option for old move code
71         bool physics_override_new_move = true;
72
73         v3f overridePosition;
74
75         void move(f32 dtime, Environment *env, f32 pos_max_d);
76         void move(f32 dtime, Environment *env, f32 pos_max_d,
77                         std::vector<CollisionInfo> *collision_info);
78         // Temporary option for old move code
79         void old_move(f32 dtime, Environment *env, f32 pos_max_d,
80                         std::vector<CollisionInfo> *collision_info);
81
82         void applyControl(float dtime, Environment *env);
83
84         v3s16 getStandingNodePos();
85         v3s16 getFootstepNodePos();
86
87         // Used to check if anything changed and prevent sending packets if not
88         v3f last_position;
89         v3f last_speed;
90         float last_pitch = 0.0f;
91         float last_yaw = 0.0f;
92         unsigned int last_keyPressed = 0;
93         u8 last_camera_fov = 0;
94         u8 last_wanted_range = 0;
95
96         float camera_impact = 0.0f;
97
98         bool makes_footstep_sound = true;
99
100         int last_animation = NO_ANIM;
101         float last_animation_speed;
102
103         std::string hotbar_image = "";
104         std::string hotbar_selected_image = "";
105
106         video::SColor light_color = video::SColor(255, 255, 255, 255);
107
108         float hurt_tilt_timer = 0.0f;
109         float hurt_tilt_strength = 0.0f;
110
111         GenericCAO *getCAO() const { return m_cao; }
112
113         void setCAO(GenericCAO *toset)
114         {
115                 assert(!m_cao); // Pre-condition
116                 m_cao = toset;
117         }
118
119         u32 maxHudId() const { return hud.size(); }
120
121         u16 getBreath() const { return m_breath; }
122         void setBreath(u16 breath) { m_breath = breath; }
123
124         v3s16 getLightPosition() const;
125
126         void setYaw(f32 yaw) { m_yaw = yaw; }
127         f32 getYaw() const { return m_yaw; }
128
129         void setPitch(f32 pitch) { m_pitch = pitch; }
130         f32 getPitch() const { return m_pitch; }
131
132         inline void setPosition(const v3f &position)
133         {
134                 m_position = position;
135                 m_sneak_node_exists = false;
136         }
137
138         v3f getPosition() const { return m_position; }
139         v3f getEyePosition() const { return m_position + getEyeOffset(); }
140         v3f getEyeOffset() const;
141         void setEyeHeight(float eye_height) { m_eye_height = eye_height; }
142
143         void setCollisionbox(const aabb3f &box) { m_collisionbox = box; }
144
145         float getZoomFOV() const { return m_zoom_fov; }
146         void setZoomFOV(float zoom_fov) { m_zoom_fov = zoom_fov; }
147
148 private:
149         void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
150         void accelerateVertical(const v3f &target_speed, const f32 max_increase);
151         bool updateSneakNode(Map *map, const v3f &position, const v3f &sneak_max);
152         float getSlipFactor(Environment *env, const v3f &speedH);
153
154         v3f m_position;
155         v3s16 m_standing_node;
156
157         v3s16 m_sneak_node = v3s16(32767, 32767, 32767);
158         // Stores the top bounding box of m_sneak_node
159         aabb3f m_sneak_node_bb_top = aabb3f(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
160         // Whether the player is allowed to sneak
161         bool m_sneak_node_exists = false;
162         // Whether a "sneak ladder" structure is detected at the players pos
163         // see detectSneakLadder() in the .cpp for more info (always false if disabled)
164         bool m_sneak_ladder_detected = false;
165
166         // ***** Variables for temporary option of the old move code *****
167         // Stores the max player uplift by m_sneak_node
168         f32 m_sneak_node_bb_ymax = 0.0f;
169         // Whether recalculation of m_sneak_node and its top bbox is needed
170         bool m_need_to_get_new_sneak_node = true;
171         // Node below player, used to determine whether it has been removed,
172         // and its old type
173         v3s16 m_old_node_below = v3s16(32767, 32767, 32767);
174         std::string m_old_node_below_type = "air";
175         // ***** End of variables for temporary option *****
176
177         bool m_can_jump = false;
178         u16 m_breath = PLAYER_MAX_BREATH_DEFAULT;
179         f32 m_yaw = 0.0f;
180         f32 m_pitch = 0.0f;
181         bool camera_barely_in_ceiling = false;
182         aabb3f m_collisionbox = aabb3f(-BS * 0.30f, 0.0f, -BS * 0.30f, BS * 0.30f,
183                         BS * 1.75f, BS * 0.30f);
184         float m_eye_height = 1.625f;
185         float m_zoom_fov = 0.0f;
186
187         GenericCAO *m_cao = nullptr;
188         Client *m_client;
189 };