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 v3s16 getLightPosition() const
67 return floatToInt(m_position + v3f(0,BS+BS/2,0), BS);
70 virtual void setPosition(const v3f &position)
72 m_position = position;
75 void setPitch(f32 pitch)
80 virtual void setYaw(f32 yaw)
95 virtual void updateName(const char *name)
97 snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
100 const char * getName()
105 virtual bool isLocal() const = 0;
107 virtual void updateLight(u8 light_at_pos) {};
109 // NOTE: Use peer_id == 0 for disconnected
110 /*virtual bool isClientConnected() { return false; }
111 virtual void setClientConnected(bool) {}*/
114 serialize() writes a bunch of text that can contain
115 any characters except a '\0', and such an ending that
116 deSerialize stops reading exactly at the right point.
118 void serialize(std::ostream &os);
119 void deSerialize(std::istream &is);
121 bool touching_ground;
122 // This oscillates so that the player jumps a bit above the surface
124 // This is more stable and defines the maximum speed of the player
125 bool in_water_stable;
130 // Actual inventory is backed up here when creative mode is used
131 Inventory *inventory_backup;
133 bool craftresult_is_preview;
140 char m_name[PLAYERNAME_SIZE];
154 class ServerRemotePlayer : public Player
160 virtual ~ServerRemotePlayer()
164 virtual bool isLocal() const
169 virtual void move(f32 dtime, Map &map, f32 pos_max_d)
179 All the other players on the client are these
182 class RemotePlayer : public Player, public scene::ISceneNode
186 scene::ISceneNode* parent=NULL,
187 IrrlichtDevice *device=NULL,
190 virtual ~RemotePlayer();
196 virtual void OnRegisterSceneNode()
199 SceneManager->registerNodeForRendering(this);
201 ISceneNode::OnRegisterSceneNode();
204 virtual void render()
209 virtual const core::aabbox3d<f32>& getBoundingBox() const
214 void setPosition(const v3f &position)
216 m_oldpos = m_showpos;
218 if(m_pos_animation_time < 0.001 || m_pos_animation_time > 1.0)
219 m_pos_animation_time = m_pos_animation_time_counter;
221 m_pos_animation_time = m_pos_animation_time * 0.9
222 + m_pos_animation_time_counter * 0.1;
223 m_pos_animation_time_counter = 0;
224 m_pos_animation_counter = 0;
226 Player::setPosition(position);
227 //ISceneNode::setPosition(position);
230 virtual void setYaw(f32 yaw)
233 ISceneNode::setRotation(v3f(0, -yaw, 0));
241 void updateName(const char *name);
243 virtual void updateLight(u8 light_at_pos)
248 u8 li = decode_light(light_at_pos);
249 video::SColor color(255,li,li,li);
251 scene::IMesh *mesh = m_node->getMesh();
253 u16 mc = mesh->getMeshBufferCount();
254 for(u16 j=0; j<mc; j++)
256 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
257 video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
258 u16 vc = buf->getVertexCount();
259 for(u16 i=0; i<vc; i++)
261 vertices[i].Color = color;
266 void move(f32 dtime, Map &map, f32 pos_max_d);
269 scene::IMeshSceneNode *m_node;
270 scene::ITextSceneNode* m_text;
271 core::aabbox3d<f32> m_box;
274 f32 m_pos_animation_counter;
275 f32 m_pos_animation_time;
276 f32 m_pos_animation_time_counter;
330 class LocalPlayer : public Player
334 virtual ~LocalPlayer();
341 void move(f32 dtime, Map &map, f32 pos_max_d,
342 core::list<CollisionInfo> *collision_info);
343 void move(f32 dtime, Map &map, f32 pos_max_d);
345 void applyControl(float dtime);
347 PlayerControl control;
350 // This is used for determining the sneaking range
352 // Whether the player is allowed to sneak
353 bool m_sneak_node_exists;