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, const char *name);
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 if (position != m_position)
147 m_position = position;
150 void setPitch(f32 pitch)
152 if (pitch != m_pitch)
157 virtual void setYaw(f32 yaw)
179 virtual void setBreath(u16 breath)
181 if (breath != m_breath)
188 return -1.0 * m_pitch * core::DEGTORAD;
193 return (m_yaw + 90.) * core::DEGTORAD;
196 const char * getName() const
201 core::aabbox3d<f32> getCollisionbox() {
202 return m_collisionbox;
205 u32 getFreeHudID() const {
206 size_t size = hud.size();
207 for (size_t i = 0; i != size; i++) {
214 virtual bool isLocal() const
216 virtual PlayerSAO *getPlayerSAO()
218 virtual void setPlayerSAO(PlayerSAO *sao)
222 serialize() writes a bunch of text that can contain
223 any characters except a '\0', and such an ending that
224 deSerialize stops reading exactly at the right point.
226 void serialize(std::ostream &os);
227 void deSerialize(std::istream &is, std::string playername);
229 bool checkModified() const
231 return m_dirty || inventory.checkModified();
234 void setModified(const bool x)
238 inventory.setModified(x);
241 bool touching_ground;
242 // This oscillates so that the player jumps a bit above the surface
244 // This is more stable and defines the maximum speed of the player
245 bool in_liquid_stable;
246 // Gets the viscosity of water to calculate friction
249 bool swimming_vertical;
250 bool camera_barely_in_ceiling;
256 f32 movement_acceleration_default;
257 f32 movement_acceleration_air;
258 f32 movement_acceleration_fast;
259 f32 movement_speed_walk;
260 f32 movement_speed_crouch;
261 f32 movement_speed_fast;
262 f32 movement_speed_climb;
263 f32 movement_speed_jump;
264 f32 movement_liquid_fluidity;
265 f32 movement_liquid_fluidity_smooth;
266 f32 movement_liquid_sink;
267 f32 movement_gravity;
269 float physics_override_speed;
270 float physics_override_jump;
271 float physics_override_gravity;
272 bool physics_override_sneak;
273 bool physics_override_sneak_glitch;
275 v2s32 local_animations[4];
276 float local_animation_speed;
280 float hurt_tilt_timer;
281 float hurt_tilt_strength;
285 std::string inventory_formspec;
287 PlayerControl control;
288 PlayerControl getPlayerControl()
296 HudElement* getHud(u32 id);
297 u32 addHud(HudElement* hud);
298 HudElement* removeHud(u32 id);
305 s32 hud_hotbar_itemcount;
309 char m_name[PLAYERNAME_SIZE];
315 core::aabbox3d<f32> m_collisionbox;
319 std::vector<HudElement *> hud;
326 class RemotePlayer : public Player
329 RemotePlayer(IGameDef *gamedef, const char *name):
330 Player(gamedef, name),
333 virtual ~RemotePlayer() {}
335 void save(std::string savedir);
337 PlayerSAO *getPlayerSAO()
339 void setPlayerSAO(PlayerSAO *sao)
341 void setPosition(const v3f &position);