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)
168 virtual void setBreath(u16 breath)
175 return -1.0 * m_pitch * core::DEGTORAD;
180 return (m_yaw + 90.) * core::DEGTORAD;
183 void updateName(const char *name)
185 snprintf(m_name, PLAYERNAME_SIZE, "%s", name);
188 const char * getName() const
193 core::aabbox3d<f32> getCollisionbox() {
194 return m_collisionbox;
197 virtual bool isLocal() const
199 virtual PlayerSAO *getPlayerSAO()
201 virtual void setPlayerSAO(PlayerSAO *sao)
205 serialize() writes a bunch of text that can contain
206 any characters except a '\0', and such an ending that
207 deSerialize stops reading exactly at the right point.
209 void serialize(std::ostream &os);
210 void deSerialize(std::istream &is, std::string playername);
214 if(m_last_hp != hp || m_last_pitch != m_pitch ||
215 m_last_pos != m_position || m_last_yaw != m_yaw ||
216 !(inventory == m_last_inventory))
219 m_last_pitch = m_pitch;
220 m_last_pos = m_position;
222 m_last_inventory = inventory;
229 bool touching_ground;
230 // This oscillates so that the player jumps a bit above the surface
232 // This is more stable and defines the maximum speed of the player
233 bool in_liquid_stable;
234 // Gets the viscosity of water to calculate friction
237 bool swimming_vertical;
238 bool camera_barely_in_ceiling;
244 f32 movement_acceleration_default;
245 f32 movement_acceleration_air;
246 f32 movement_acceleration_fast;
247 f32 movement_speed_walk;
248 f32 movement_speed_crouch;
249 f32 movement_speed_fast;
250 f32 movement_speed_climb;
251 f32 movement_speed_jump;
252 f32 movement_liquid_fluidity;
253 f32 movement_liquid_fluidity_smooth;
254 f32 movement_liquid_sink;
255 f32 movement_gravity;
257 float physics_override_speed;
258 float physics_override_jump;
259 float physics_override_gravity;
263 float hurt_tilt_timer;
264 float hurt_tilt_strength;
268 std::string inventory_formspec;
270 PlayerControl control;
271 PlayerControl getPlayerControl()
278 std::vector<HudElement *> hud;
280 s32 hud_hotbar_itemcount;
285 char m_name[PLAYERNAME_SIZE];
291 core::aabbox3d<f32> m_collisionbox;
297 Inventory m_last_inventory;
304 class RemotePlayer : public Player
307 RemotePlayer(IGameDef *gamedef): Player(gamedef), m_sao(0) {}
308 virtual ~RemotePlayer() {}
310 PlayerSAO *getPlayerSAO()
312 void setPlayerSAO(PlayerSAO *sao)
314 void setPosition(const v3f &position);