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 u32 getFreeHudID() const {
198 size_t size = hud.size();
199 for (size_t i = 0; i != size; i++) {
206 virtual bool isLocal() const
208 virtual PlayerSAO *getPlayerSAO()
210 virtual void setPlayerSAO(PlayerSAO *sao)
214 serialize() writes a bunch of text that can contain
215 any characters except a '\0', and such an ending that
216 deSerialize stops reading exactly at the right point.
218 void serialize(std::ostream &os);
219 void deSerialize(std::istream &is, std::string playername);
223 if(m_last_hp != hp || m_last_pitch != m_pitch ||
224 m_last_pos != m_position || m_last_yaw != m_yaw ||
225 !(inventory == m_last_inventory))
228 m_last_pitch = m_pitch;
229 m_last_pos = m_position;
231 m_last_inventory = inventory;
238 bool touching_ground;
239 // This oscillates so that the player jumps a bit above the surface
241 // This is more stable and defines the maximum speed of the player
242 bool in_liquid_stable;
243 // Gets the viscosity of water to calculate friction
246 bool swimming_vertical;
247 bool camera_barely_in_ceiling;
253 f32 movement_acceleration_default;
254 f32 movement_acceleration_air;
255 f32 movement_acceleration_fast;
256 f32 movement_speed_walk;
257 f32 movement_speed_crouch;
258 f32 movement_speed_fast;
259 f32 movement_speed_climb;
260 f32 movement_speed_jump;
261 f32 movement_liquid_fluidity;
262 f32 movement_liquid_fluidity_smooth;
263 f32 movement_liquid_sink;
264 f32 movement_gravity;
266 float physics_override_speed;
267 float physics_override_jump;
268 float physics_override_gravity;
272 float hurt_tilt_timer;
273 float hurt_tilt_strength;
277 std::string inventory_formspec;
279 PlayerControl control;
280 PlayerControl getPlayerControl()
287 std::vector<HudElement *> hud;
289 s32 hud_hotbar_itemcount;
294 char m_name[PLAYERNAME_SIZE];
300 core::aabbox3d<f32> m_collisionbox;
306 Inventory m_last_inventory;
313 class RemotePlayer : public Player
316 RemotePlayer(IGameDef *gamedef): Player(gamedef), m_sao(0) {}
317 virtual ~RemotePlayer() {}
319 PlayerSAO *getPlayerSAO()
321 void setPlayerSAO(PlayerSAO *sao)
323 void setPosition(const v3f &position);