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