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
28 #define PLAYERNAME_SIZE 20
30 #define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
98 Player(IGameDef *gamedef);
99 virtual ~Player() = 0;
101 virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
103 virtual void move(f32 dtime, Environment *env, f32 pos_max_d,
104 std::list<CollisionInfo> *collision_info)
112 void setSpeed(v3f speed)
117 void accelerateHorizontal(v3f target_speed, f32 max_increase);
118 void accelerateVertical(v3f target_speed, f32 max_increase);
125 v3s16 getLightPosition() const;
129 // This is at the height of the eyes of the current figure
130 // return v3f(0, BS*1.5, 0);
131 // This is more like in minecraft
132 if(camera_barely_in_ceiling)
133 return v3f(0,BS*1.5,0);
135 return v3f(0,BS*1.625,0);
140 return m_position + getEyeOffset();
143 virtual void setPosition(const v3f &position)
145 m_position = position;
148 void setPitch(f32 pitch)
153 virtual void setYaw(f32 yaw)
173 virtual void setBreath(u16 breath)
180 return -1.0 * m_pitch * core::DEGTORAD;
185 return (m_yaw + 90.) * core::DEGTORAD;
188 void updateName(const char *name)
190 snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
193 const char * getName() const
198 core::aabbox3d<f32> getCollisionbox() {
199 return m_collisionbox;
202 u32 getFreeHudID() const {
203 size_t size = hud.size();
204 for (size_t i = 0; i != size; i++) {
211 virtual bool isLocal() const
213 virtual PlayerSAO *getPlayerSAO()
215 virtual void setPlayerSAO(PlayerSAO *sao)
219 serialize() writes a bunch of text that can contain
220 any characters except a '\0', and such an ending that
221 deSerialize stops reading exactly at the right point.
223 void serialize(std::ostream &os);
224 void deSerialize(std::istream &is, std::string playername);
228 if(m_last_hp != hp || m_last_pitch != m_pitch ||
229 m_last_pos != m_position || m_last_yaw != m_yaw ||
230 !(inventory == m_last_inventory))
233 m_last_pitch = m_pitch;
234 m_last_pos = m_position;
236 m_last_inventory = inventory;
243 bool touching_ground;
244 // This oscillates so that the player jumps a bit above the surface
246 // This is more stable and defines the maximum speed of the player
247 bool in_liquid_stable;
248 // Gets the viscosity of water to calculate friction
251 bool swimming_vertical;
252 bool camera_barely_in_ceiling;
258 f32 movement_acceleration_default;
259 f32 movement_acceleration_air;
260 f32 movement_acceleration_fast;
261 f32 movement_speed_walk;
262 f32 movement_speed_crouch;
263 f32 movement_speed_fast;
264 f32 movement_speed_climb;
265 f32 movement_speed_jump;
266 f32 movement_liquid_fluidity;
267 f32 movement_liquid_fluidity_smooth;
268 f32 movement_liquid_sink;
269 f32 movement_gravity;
271 float physics_override_speed;
272 float physics_override_jump;
273 float physics_override_gravity;
274 bool physics_override_sneak;
275 bool physics_override_sneak_glitch;
277 v2s32 local_animations[4];
278 float local_animation_speed;
282 float hurt_tilt_timer;
283 float hurt_tilt_strength;
287 std::string inventory_formspec;
289 PlayerControl control;
290 PlayerControl getPlayerControl()
298 HudElement* getHud(u32 id);
299 u32 addHud(HudElement* hud);
300 HudElement* removeHud(u32 id);
307 s32 hud_hotbar_itemcount;
311 char m_name[PLAYERNAME_SIZE];
317 core::aabbox3d<f32> m_collisionbox;
323 Inventory m_last_inventory;
325 std::vector<HudElement *> hud;
332 class RemotePlayer : public Player
335 RemotePlayer(IGameDef *gamedef): Player(gamedef), m_sao(0) {}
336 virtual ~RemotePlayer() {}
338 void save(std::string savedir);
340 PlayerSAO *getPlayerSAO()
342 void setPlayerSAO(PlayerSAO *sao)
344 void setPosition(const v3f &position);