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