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
26 #include "jthread/jmutex.h"
29 #define PLAYERNAME_SIZE 20
31 #define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
99 Player(IGameDef *gamedef, const char *name);
100 virtual ~Player() = 0;
102 virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
104 virtual void move(f32 dtime, Environment *env, f32 pos_max_d,
105 std::list<CollisionInfo> *collision_info)
113 void setSpeed(v3f speed)
118 void accelerateHorizontal(v3f target_speed, f32 max_increase);
119 void accelerateVertical(v3f target_speed, f32 max_increase);
126 v3s16 getLightPosition() const;
130 // This is at the height of the eyes of the current figure
131 // return v3f(0, BS*1.5, 0);
132 // This is more like in minecraft
133 if(camera_barely_in_ceiling)
134 return v3f(0,BS*1.5,0);
136 return v3f(0,BS*1.625,0);
141 return m_position + getEyeOffset();
144 virtual void setPosition(const v3f &position)
146 if (position != m_position)
148 m_position = position;
151 void setPitch(f32 pitch)
153 if (pitch != m_pitch)
158 virtual void setYaw(f32 yaw)
180 virtual void setBreath(u16 breath)
182 if (breath != m_breath)
189 return -1.0 * m_pitch * core::DEGTORAD;
194 return (m_yaw + 90.) * core::DEGTORAD;
197 const char * getName() const
202 core::aabbox3d<f32> getCollisionbox() {
203 return m_collisionbox;
207 size_t size = hud.size();
208 for (size_t i = 0; i != size; i++) {
215 virtual bool isLocal() const
217 virtual PlayerSAO *getPlayerSAO()
219 virtual void setPlayerSAO(PlayerSAO *sao)
220 { FATAL_ERROR("FIXME"); }
223 serialize() writes a bunch of text that can contain
224 any characters except a '\0', and such an ending that
225 deSerialize stops reading exactly at the right point.
227 void serialize(std::ostream &os);
228 void deSerialize(std::istream &is, std::string playername);
230 bool checkModified() const
232 return m_dirty || inventory.checkModified();
235 void setModified(const bool x)
239 inventory.setModified(x);
242 // Use a function, if isDead can be defined by other conditions
243 bool isDead() { return hp == 0; }
245 bool touching_ground;
246 // This oscillates so that the player jumps a bit above the surface
248 // This is more stable and defines the maximum speed of the player
249 bool in_liquid_stable;
250 // Gets the viscosity of water to calculate friction
253 bool swimming_vertical;
254 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;
321 std::vector<HudElement *> hud;
323 // Protect some critical areas
324 // hud for example can be modified by EmergeThread
333 class RemotePlayer : public Player
336 RemotePlayer(IGameDef *gamedef, const char *name):
337 Player(gamedef, name),
340 virtual ~RemotePlayer() {}
342 void save(std::string savedir);
344 PlayerSAO *getPlayerSAO()
346 void setPlayerSAO(PlayerSAO *sao)
348 void setPosition(const v3f &position);