3 Copyright (C) 2010 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.
21 (c) 2010 Perttu Ahola <celeron55@gmail.com>
27 #include "common_irrlicht.h"
28 #include "inventory.h"
30 #define PLAYERNAME_SIZE 20
32 #define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.,"
42 void resetInventory();
44 //void move(f32 dtime, Map &map);
45 virtual void move(f32 dtime, Map &map) = 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;
125 char m_name[PLAYERNAME_SIZE];
132 class ServerRemotePlayer : public Player
138 virtual ~ServerRemotePlayer()
142 virtual bool isLocal() const
147 virtual void move(f32 dtime, Map &map)
156 class RemotePlayer : public Player, public scene::ISceneNode
160 scene::ISceneNode* parent=NULL,
161 IrrlichtDevice *device=NULL,
164 virtual ~RemotePlayer();
170 virtual void OnRegisterSceneNode()
173 SceneManager->registerNodeForRendering(this);
175 ISceneNode::OnRegisterSceneNode();
178 virtual void render()
183 virtual const core::aabbox3d<f32>& getBoundingBox() const
188 void setPosition(v3f position)
190 m_oldpos = m_showpos;
192 if(m_pos_animation_time < 0.001 || m_pos_animation_time > 1.0)
193 m_pos_animation_time = m_pos_animation_time_counter;
195 m_pos_animation_time = m_pos_animation_time * 0.9
196 + m_pos_animation_time_counter * 0.1;
197 m_pos_animation_time_counter = 0;
198 m_pos_animation_counter = 0;
200 Player::setPosition(position);
201 //ISceneNode::setPosition(position);
204 virtual void setYaw(f32 yaw)
207 ISceneNode::setRotation(v3f(0, -yaw, 0));
215 void updateName(const char *name);
217 virtual void updateLight(u8 light_at_pos)
222 u8 li = decode_light(light_at_pos);
223 video::SColor color(255,li,li,li);
225 scene::IMesh *mesh = m_node->getMesh();
227 u16 mc = mesh->getMeshBufferCount();
228 for(u16 j=0; j<mc; j++)
230 scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
231 video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
232 u16 vc = buf->getVertexCount();
233 for(u16 i=0; i<vc; i++)
235 vertices[i].Color = color;
240 void move(f32 dtime, Map &map);
243 scene::IMeshSceneNode *m_node;
244 scene::ITextSceneNode* m_text;
245 core::aabbox3d<f32> m_box;
248 f32 m_pos_animation_counter;
249 f32 m_pos_animation_time;
250 f32 m_pos_animation_time_counter;
300 class LocalPlayer : public Player
304 virtual ~LocalPlayer();
311 void move(f32 dtime, Map &map);
313 void applyControl(float dtime);
315 PlayerControl control;