Move RemotePlayer code to its own cpp/header
[oweals/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 *gamedef, const char *name);
39         virtual ~LocalPlayer();
40
41         bool isLocal() const
42         {
43                 return true;
44         }
45
46         ClientActiveObject *parent;
47
48         bool got_teleported;
49         bool isAttached;
50         bool touching_ground;
51         // This oscillates so that the player jumps a bit above the surface
52         bool in_liquid;
53         // This is more stable and defines the maximum speed of the player
54         bool in_liquid_stable;
55         // Gets the viscosity of water to calculate friction
56         u8 liquid_viscosity;
57         bool is_climbing;
58         bool swimming_vertical;
59
60         float physics_override_speed;
61         float physics_override_jump;
62         float physics_override_gravity;
63         bool physics_override_sneak;
64         bool physics_override_sneak_glitch;
65
66         v3f overridePosition;
67
68         void move(f32 dtime, Environment *env, f32 pos_max_d);
69         void move(f32 dtime, Environment *env, f32 pos_max_d,
70                         std::vector<CollisionInfo> *collision_info);
71
72         void applyControl(float dtime);
73
74         v3s16 getStandingNodePos();
75
76         // Used to check if anything changed and prevent sending packets if not
77         v3f last_position;
78         v3f last_speed;
79         float last_pitch;
80         float last_yaw;
81         unsigned int last_keyPressed;
82
83         float camera_impact;
84
85         int last_animation;
86         float last_animation_speed;
87
88         std::string hotbar_image;
89         std::string hotbar_selected_image;
90
91         video::SColor light_color;
92
93         float hurt_tilt_timer;
94         float hurt_tilt_strength;
95
96         GenericCAO* getCAO() const {
97                 return m_cao;
98         }
99
100         void setCAO(GenericCAO* toset) {
101                 assert( m_cao == NULL ); // Pre-condition
102                 m_cao = toset;
103         }
104
105         u32 maxHudId() const { return hud.size(); }
106
107 private:
108         void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
109         void accelerateVertical(const v3f &target_speed, const f32 max_increase);
110
111         // This is used for determining the sneaking range
112         v3s16 m_sneak_node;
113         // Whether the player is allowed to sneak
114         bool m_sneak_node_exists;
115         // Whether recalculation of the sneak node is needed
116         bool m_need_to_get_new_sneak_node;
117         // Stores the max player uplift by m_sneak_node and is updated
118         // when m_need_to_get_new_sneak_node == true
119         f32 m_sneak_node_bb_ymax;
120         // Node below player, used to determine whether it has been removed,
121         // and its old type
122         v3s16 m_old_node_below;
123         std::string m_old_node_below_type;
124         bool m_can_jump;
125
126         GenericCAO* m_cao;
127         Client *m_gamedef;
128 };
129
130 #endif
131