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