3 Copyright (C) 2010-2013 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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser 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 "irrlichttypes_bloated.h"
24 #include "inventory.h"
25 #include "constants.h" // BS
27 #define PLAYERNAME_SIZE 20
29 #define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
96 Player(IGameDef *gamedef);
97 virtual ~Player() = 0;
99 virtual void move(f32 dtime, Map &map, f32 pos_max_d)
107 void setSpeed(v3f speed)
112 void accelerateHorizontal(v3f target_speed, f32 max_increase);
113 void accelerateVertical(v3f target_speed, f32 max_increase);
120 v3s16 getLightPosition() const;
124 // This is at the height of the eyes of the current figure
125 // return v3f(0, BS*1.5, 0);
126 // This is more like in minecraft
127 if(camera_barely_in_ceiling)
128 return v3f(0,BS*1.5,0);
130 return v3f(0,BS*1.625,0);
135 return m_position + getEyeOffset();
138 virtual void setPosition(const v3f &position)
140 m_position = position;
143 void setPitch(f32 pitch)
148 virtual void setYaw(f32 yaw)
165 return -1.0 * m_pitch * core::DEGTORAD;
170 return (m_yaw + 90.) * core::DEGTORAD;
173 void updateName(const char *name)
175 snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
178 const char * getName() const
183 core::aabbox3d<f32> getCollisionbox() {
184 return m_collisionbox;
187 virtual bool isLocal() const
189 virtual PlayerSAO *getPlayerSAO()
191 virtual void setPlayerSAO(PlayerSAO *sao)
195 serialize() writes a bunch of text that can contain
196 any characters except a '\0', and such an ending that
197 deSerialize stops reading exactly at the right point.
199 void serialize(std::ostream &os);
200 void deSerialize(std::istream &is, std::string playername);
204 if(m_last_hp != hp || m_last_pitch != m_pitch ||
205 m_last_pos != m_position || m_last_yaw != m_yaw ||
206 !(inventory == m_last_inventory))
209 m_last_pitch = m_pitch;
210 m_last_pos = m_position;
212 m_last_inventory = inventory;
219 bool touching_ground;
220 // This oscillates so that the player jumps a bit above the surface
222 // This is more stable and defines the maximum speed of the player
223 bool in_liquid_stable;
224 // Gets the viscosity of water to calculate friction
227 bool swimming_vertical;
228 bool camera_barely_in_ceiling;
234 f32 movement_acceleration_default;
235 f32 movement_acceleration_air;
236 f32 movement_acceleration_fast;
237 f32 movement_speed_walk;
238 f32 movement_speed_crouch;
239 f32 movement_speed_fast;
240 f32 movement_speed_climb;
241 f32 movement_speed_jump;
242 f32 movement_liquid_fluidity;
243 f32 movement_liquid_fluidity_smooth;
244 f32 movement_liquid_sink;
245 f32 movement_gravity;
247 float physics_override_speed;
248 float physics_override_jump;
249 float physics_override_gravity;
254 float hurt_tilt_timer;
255 float hurt_tilt_strength;
259 std::string inventory_formspec;
261 PlayerControl control;
262 PlayerControl getPlayerControl()
269 std::vector<HudElement *> hud;
271 s32 hud_hotbar_itemcount;
276 char m_name[PLAYERNAME_SIZE];
281 core::aabbox3d<f32> m_collisionbox;
287 Inventory m_last_inventory;
294 class RemotePlayer : public Player
297 RemotePlayer(IGameDef *gamedef): Player(gamedef), m_sao(0) {}
298 virtual ~RemotePlayer() {}
300 PlayerSAO *getPlayerSAO()
302 void setPlayerSAO(PlayerSAO *sao)
304 void setPosition(const v3f &position);