3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
23 #include "common_irrlicht.h"
24 #include "inventory.h"
25 #include "collision.h"
27 #define PLAYERNAME_SIZE 20
29 #define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
42 void resetInventory();
44 //void move(f32 dtime, Map &map);
45 virtual void move(f32 dtime, Map &map, f32 pos_max_d) = 0;
52 void setSpeed(v3f speed)
57 // Y direction is ignored
58 void accelerate(v3f target_speed, f32 max_increase);
65 virtual void setPosition(v3f position)
67 m_position = position;
70 void setPitch(f32 pitch)
75 virtual void setYaw(f32 yaw)
90 virtual void updateName(const char *name)
92 snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
95 const char * getName()
100 virtual bool isLocal() const = 0;
102 virtual void updateLight(u8 light_at_pos) {};
104 // NOTE: Use peer_id == 0 for disconnected
105 /*virtual bool isClientConnected() { return false; }
106 virtual void setClientConnected(bool) {}*/
109 serialize() writes a bunch of text that can contain
110 any characters except a '\0', and such an ending that
111 deSerialize stops reading exactly at the right point.
113 void serialize(std::ostream &os);
114 void deSerialize(std::istream &is);
116 bool touching_ground;
117 // This oscillates so that the player jumps a bit above the surface
119 // This is more stable and defines the maximum speed of the player
120 bool in_water_stable;
125 bool craftresult_is_preview;
129 // Player's privileges - a bitmaps of PRIV_xxxx.
135 char m_name[PLAYERNAME_SIZE];
149 class ServerRemotePlayer : public Player
155 virtual ~ServerRemotePlayer()
159 virtual bool isLocal() const
164 virtual void move(f32 dtime, Map &map, f32 pos_max_d)
174 All the other players on the client are these
177 class RemotePlayer : public Player, public scene::ISceneNode
181 scene::ISceneNode* parent=NULL,
182 IrrlichtDevice *device=NULL,
185 virtual ~RemotePlayer();
191 virtual void OnRegisterSceneNode()
194 SceneManager->registerNodeForRendering(this);
196 ISceneNode::OnRegisterSceneNode();
199 virtual void render()
204 virtual const core::aabbox3d<f32>& getBoundingBox() const
209 void setPosition(v3f position)
211 m_oldpos = m_showpos;
213 if(m_pos_animation_time < 0.001 || m_pos_animation_time > 1.0)
214 m_pos_animation_time = m_pos_animation_time_counter;
216 m_pos_animation_time = m_pos_animation_time * 0.9
217 + m_pos_animation_time_counter * 0.1;
218 m_pos_animation_time_counter = 0;
219 m_pos_animation_counter = 0;
221 Player::setPosition(position);
222 //ISceneNode::setPosition(position);
225 virtual void setYaw(f32 yaw)
228 ISceneNode::setRotation(v3f(0, -yaw, 0));
236 void updateName(const char *name);
238 virtual void updateLight(u8 light_at_pos)
243 u8 li = decode_light(light_at_pos);
244 video::SColor color(255,li,li,li);
246 scene::IMesh *mesh = m_node->getMesh();
248 u16 mc = mesh->getMeshBufferCount();
249 for(u16 j=0; j<mc; j++)
251 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
252 video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
253 u16 vc = buf->getVertexCount();
254 for(u16 i=0; i<vc; i++)
256 vertices[i].Color = color;
261 void move(f32 dtime, Map &map, f32 pos_max_d);
264 scene::IMeshSceneNode *m_node;
265 scene::ITextSceneNode* m_text;
266 core::aabbox3d<f32> m_box;
269 f32 m_pos_animation_counter;
270 f32 m_pos_animation_time;
271 f32 m_pos_animation_time_counter;
325 class LocalPlayer : public Player
329 virtual ~LocalPlayer();
336 void move(f32 dtime, Map &map, f32 pos_max_d,
337 core::list<CollisionInfo> *collision_info);
338 void move(f32 dtime, Map &map, f32 pos_max_d);
340 void applyControl(float dtime);
342 PlayerControl control;
345 // This is used for determining the sneaking range
347 // Whether the player is allowed to sneak
348 bool m_sneak_node_exists;