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