]> git.lizzy.rs Git - minetest.git/blob - src/player.h
plant amount fix and ravine amount setting
[minetest.git] / src / player.h
1 /*
2 (c) 2010 Perttu Ahola <celeron55@gmail.com>
3 */
4
5 #ifndef PLAYER_HEADER
6 #define PLAYER_HEADER
7
8 #include "common_irrlicht.h"
9 #include "inventory.h"
10
11 #define PLAYERNAME_SIZE 20
12
13 class Map;
14
15 class Player
16 {
17 public:
18         Player();
19         virtual ~Player();
20
21         void move(f32 dtime, Map &map);
22
23         v3f getSpeed()
24         {
25                 return m_speed;
26         }
27
28         void setSpeed(v3f speed)
29         {
30                 m_speed = speed;
31         }
32         
33         // Y direction is ignored
34         void accelerate(v3f target_speed, f32 max_increase);
35
36         v3f getPosition()
37         {
38                 return m_position;
39         }
40
41         virtual void setPosition(v3f position)
42         {
43                 m_position = position;
44         }
45
46         void setPitch(f32 pitch)
47         {
48                 m_pitch = pitch;
49         }
50
51         virtual void setYaw(f32 yaw)
52         {
53                 m_yaw = yaw;
54         }
55
56         f32 getPitch()
57         {
58                 return m_pitch;
59         }
60
61         f32 getYaw()
62         {
63                 return m_yaw;
64         }
65
66         virtual void updateName(const char *name)
67         {
68                 snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
69         }
70
71         const char * getName()
72         {
73                 return m_name;
74         }
75
76         virtual bool isLocal() const = 0;
77
78         bool touching_ground;
79         
80         Inventory inventory;
81
82         u16 peer_id;
83
84 protected:
85         char m_name[PLAYERNAME_SIZE];
86         f32 m_pitch;
87         f32 m_yaw;
88         v3f m_speed;
89         v3f m_position;
90 };
91
92 class RemotePlayer : public Player, public scene::ISceneNode
93 {
94 public:
95         RemotePlayer(
96                 scene::ISceneNode* parent=NULL,
97                 IrrlichtDevice *device=NULL,
98                 s32 id=0);
99         
100         virtual ~RemotePlayer();
101
102         /*
103                 ISceneNode methods
104         */
105
106         virtual void OnRegisterSceneNode()
107         {
108                 if (IsVisible)
109                         SceneManager->registerNodeForRendering(this);
110
111                 ISceneNode::OnRegisterSceneNode();
112         }
113
114         virtual void render()
115         {
116                 // Do nothing
117         }
118         
119         virtual const core::aabbox3d<f32>& getBoundingBox() const
120         {
121                 return m_box;
122         }
123
124         void setPosition(v3f position)
125         {
126                 Player::setPosition(position);
127                 ISceneNode::setPosition(position);
128         }
129
130         virtual void setYaw(f32 yaw)
131         {
132                 Player::setYaw(yaw);
133                 ISceneNode::setRotation(v3f(0, -yaw, 0));
134         }
135
136         bool isLocal() const
137         {
138                 return false;
139         }
140
141         void updateName(const char *name);
142
143 private:
144         scene::ITextSceneNode* m_text;
145         core::aabbox3d<f32> m_box;
146 };
147
148 struct PlayerControl
149 {
150         PlayerControl()
151         {
152                 up = false;
153                 down = false;
154                 left = false;
155                 right = false;
156                 jump = false;
157                 superspeed = false;
158                 pitch = 0;
159                 yaw = 0;
160         }
161         PlayerControl(
162                 bool a_up,
163                 bool a_down,
164                 bool a_left,
165                 bool a_right,
166                 bool a_jump,
167                 bool a_superspeed,
168                 float a_pitch,
169                 float a_yaw
170         )
171         {
172                 up = a_up;
173                 down = a_down;
174                 left = a_left;
175                 right = a_right;
176                 jump = a_jump;
177                 superspeed = a_superspeed;
178                 pitch = a_pitch;
179                 yaw = a_yaw;
180         }
181         bool up;
182         bool down;
183         bool left;
184         bool right;
185         bool jump;
186         bool superspeed;
187         float pitch;
188         float yaw;
189 };
190
191 class LocalPlayer : public Player
192 {
193 public:
194         LocalPlayer();
195         virtual ~LocalPlayer();
196
197         bool isLocal() const
198         {
199                 return true;
200         }
201
202         void applyControl(float dtime);
203         
204         PlayerControl control;
205
206 private:
207 };
208
209 #endif
210