]> git.lizzy.rs Git - dragonfireclient.git/blob - src/player.h
EnvRef:find_nodes_in_area(minp, maxp, nodenames)
[dragonfireclient.git] / src / player.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
14
15 You should have received a copy of the GNU 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 PLAYER_HEADER
21 #define PLAYER_HEADER
22
23 #include "irrlichttypes.h"
24 #include "inventory.h"
25
26 #define PLAYERNAME_SIZE 20
27
28 #define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
29
30 class Map;
31 class IGameDef;
32 struct CollisionInfo;
33 class PlayerSAO;
34
35 class Player
36 {
37 public:
38
39         Player(IGameDef *gamedef);
40         virtual ~Player() = 0;
41
42         virtual void move(f32 dtime, Map &map, f32 pos_max_d)
43         {}
44
45         v3f getSpeed()
46         {
47                 return m_speed;
48         }
49
50         void setSpeed(v3f speed)
51         {
52                 m_speed = speed;
53         }
54         
55         // Y direction is ignored
56         void accelerate(v3f target_speed, f32 max_increase);
57
58         v3f getPosition()
59         {
60                 return m_position;
61         }
62
63         v3s16 getLightPosition() const;
64
65         v3f getEyeOffset()
66         {
67                 // This is at the height of the eyes of the current figure
68                 // return v3f(0, BS*1.5, 0);
69                 // This is more like in minecraft
70                 if(camera_barely_in_ceiling)
71                         return v3f(0,BS*1.5,0);
72                 else
73                         return v3f(0,BS*1.625,0);
74         }
75
76         v3f getEyePosition()
77         {
78                 return m_position + getEyeOffset();
79         }
80
81         virtual void setPosition(const v3f &position)
82         {
83                 m_position = position;
84         }
85
86         void setPitch(f32 pitch)
87         {
88                 m_pitch = pitch;
89         }
90
91         virtual void setYaw(f32 yaw)
92         {
93                 m_yaw = yaw;
94         }
95
96         f32 getPitch()
97         {
98                 return m_pitch;
99         }
100
101         f32 getYaw()
102         {
103                 return m_yaw;
104         }
105
106         f32 getRadPitch()
107         {
108                 return -1.0 * m_pitch * core::DEGTORAD;
109         }
110
111         f32 getRadYaw()
112         {
113                 return (m_yaw + 90.) * core::DEGTORAD;
114         }
115
116         void updateName(const char *name)
117         {
118                 snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
119         }
120
121         const char * getName() const
122         {
123                 return m_name;
124         }
125
126         virtual bool isLocal() const
127         { return false; }
128         virtual PlayerSAO *getPlayerSAO()
129         { return NULL; }
130         virtual void setPlayerSAO(PlayerSAO *sao)
131         { assert(0); }
132
133         /*
134                 serialize() writes a bunch of text that can contain
135                 any characters except a '\0', and such an ending that
136                 deSerialize stops reading exactly at the right point.
137         */
138         void serialize(std::ostream &os);
139         void deSerialize(std::istream &is);
140
141         bool touching_ground;
142         // This oscillates so that the player jumps a bit above the surface
143         bool in_water;
144         // This is more stable and defines the maximum speed of the player
145         bool in_water_stable;
146         bool is_climbing;
147         bool swimming_up;
148         bool camera_barely_in_ceiling;
149         
150         u8 light;
151
152         // In creative mode, this is the invisible backup inventory
153         Inventory inventory;
154
155         u16 hp;
156
157         u16 peer_id;
158
159 protected:
160         IGameDef *m_gamedef;
161
162         char m_name[PLAYERNAME_SIZE];
163         f32 m_pitch;
164         f32 m_yaw;
165         v3f m_speed;
166         v3f m_position;
167 };
168
169 /*
170         Player on the server
171 */
172 class RemotePlayer : public Player
173 {
174 public:
175         RemotePlayer(IGameDef *gamedef): Player(gamedef), m_sao(0) {}
176         virtual ~RemotePlayer() {}
177
178         PlayerSAO *getPlayerSAO()
179         { return m_sao; }
180         void setPlayerSAO(PlayerSAO *sao)
181         { m_sao = sao; }
182         void setPosition(const v3f &position);
183
184 private:
185         PlayerSAO *m_sao;
186 };
187
188 #endif
189