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 "threading/mutex.h"
29 #define PLAYERNAME_SIZE 20
31 #define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
32 #define PLAYERNAME_ALLOWED_CHARS_USER_EXPL "'a' to 'z', 'A' to 'Z', '0' to '9', '-', '_'"
49 sidew_move_joystick_axis = .0f;
50 forw_move_joystick_axis = .0f;
66 float a_sidew_move_joystick_axis,
67 float a_forw_move_joystick_axis
82 sidew_move_joystick_axis = a_sidew_move_joystick_axis;
83 forw_move_joystick_axis = a_forw_move_joystick_axis;
97 float sidew_move_joystick_axis;
98 float forw_move_joystick_axis;
103 struct CollisionInfo;
109 // Do *not* perform an assignment or copy operation on a Player or
110 // RemotePlayer object! This will copy the lock held for HUD synchronization
115 Player(IGameDef *gamedef, const char *name);
116 virtual ~Player() = 0;
118 virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
120 virtual void move(f32 dtime, Environment *env, f32 pos_max_d,
121 std::vector<CollisionInfo> *collision_info)
129 void setSpeed(v3f speed)
139 v3s16 getLightPosition() const;
143 float eye_height = camera_barely_in_ceiling ? 1.5f : 1.625f;
144 return v3f(0, BS * eye_height, 0);
149 return m_position + getEyeOffset();
152 virtual void setPosition(const v3f &position)
154 if (position != m_position)
156 m_position = position;
159 void setPitch(f32 pitch)
161 if (pitch != m_pitch)
166 virtual void setYaw(f32 yaw)
188 virtual void setBreath(u16 breath)
190 if (breath != m_breath)
198 return -1.0 * m_pitch * core::DEGTORAD;
204 return (m_yaw + 90.) * core::DEGTORAD;
209 return m_pitch * core::DEGTORAD;
214 return m_yaw * core::DEGTORAD;
217 const char *getName() const
222 aabb3f getCollisionbox()
224 return m_collisionbox;
228 size_t size = hud.size();
229 for (size_t i = 0; i != size; i++) {
236 void setHotbarItemcount(s32 hotbar_itemcount)
238 hud_hotbar_itemcount = hotbar_itemcount;
241 s32 getHotbarItemcount()
243 return hud_hotbar_itemcount;
246 void setHotbarImage(const std::string &name)
248 hud_hotbar_image = name;
251 std::string getHotbarImage()
253 return hud_hotbar_image;
256 void setHotbarSelectedImage(const std::string &name)
258 hud_hotbar_selected_image = name;
261 std::string getHotbarSelectedImage() {
262 return hud_hotbar_selected_image;
265 void setSky(const video::SColor &bgcolor, const std::string &type,
266 const std::vector<std::string> ¶ms)
268 m_sky_bgcolor = bgcolor;
270 m_sky_params = params;
273 void getSky(video::SColor *bgcolor, std::string *type,
274 std::vector<std::string> *params)
276 *bgcolor = m_sky_bgcolor;
278 *params = m_sky_params;
281 void overrideDayNightRatio(bool do_override, float ratio)
283 m_day_night_ratio_do_override = do_override;
284 m_day_night_ratio = ratio;
287 void getDayNightRatio(bool *do_override, float *ratio)
289 *do_override = m_day_night_ratio_do_override;
290 *ratio = m_day_night_ratio;
293 void setLocalAnimations(v2s32 frames[4], float frame_speed)
295 for (int i = 0; i < 4; i++)
296 local_animations[i] = frames[i];
297 local_animation_speed = frame_speed;
300 void getLocalAnimations(v2s32 *frames, float *frame_speed)
302 for (int i = 0; i < 4; i++)
303 frames[i] = local_animations[i];
304 *frame_speed = local_animation_speed;
307 virtual bool isLocal() const
312 virtual PlayerSAO *getPlayerSAO()
317 virtual void setPlayerSAO(PlayerSAO *sao)
319 FATAL_ERROR("FIXME");
323 serialize() writes a bunch of text that can contain
324 any characters except a '\0', and such an ending that
325 deSerialize stops reading exactly at the right point.
327 void serialize(std::ostream &os);
328 void deSerialize(std::istream &is, std::string playername);
330 bool checkModified() const
332 return m_dirty || inventory.checkModified();
335 void setModified(const bool x)
339 inventory.setModified(x);
342 // Use a function, if isDead can be defined by other conditions
343 bool isDead() { return hp == 0; }
346 bool touching_ground;
347 // This oscillates so that the player jumps a bit above the surface
349 // This is more stable and defines the maximum speed of the player
350 bool in_liquid_stable;
351 // Gets the viscosity of water to calculate friction
354 bool swimming_vertical;
355 bool camera_barely_in_ceiling;
356 v3f eye_offset_first;
357 v3f eye_offset_third;
361 f32 movement_acceleration_default;
362 f32 movement_acceleration_air;
363 f32 movement_acceleration_fast;
364 f32 movement_speed_walk;
365 f32 movement_speed_crouch;
366 f32 movement_speed_fast;
367 f32 movement_speed_climb;
368 f32 movement_speed_jump;
369 f32 movement_liquid_fluidity;
370 f32 movement_liquid_fluidity_smooth;
371 f32 movement_liquid_sink;
372 f32 movement_gravity;
374 float physics_override_speed;
375 float physics_override_jump;
376 float physics_override_gravity;
377 bool physics_override_sneak;
378 bool physics_override_sneak_glitch;
380 v2s32 local_animations[4];
381 float local_animation_speed;
385 float hurt_tilt_timer;
386 float hurt_tilt_strength;
388 u16 protocol_version;
391 std::string inventory_formspec;
393 PlayerControl control;
394 PlayerControl getPlayerControl()
402 HudElement* getHud(u32 id);
403 u32 addHud(HudElement* hud);
404 HudElement* removeHud(u32 id);
411 s32 hud_hotbar_itemcount;
412 std::string hud_hotbar_image;
413 std::string hud_hotbar_selected_image;
417 char m_name[PLAYERNAME_SIZE];
423 aabb3f m_collisionbox;
427 std::vector<HudElement *> hud;
429 std::string m_sky_type;
430 video::SColor m_sky_bgcolor;
431 std::vector<std::string> m_sky_params;
433 bool m_day_night_ratio_do_override;
434 float m_day_night_ratio;
436 // Protect some critical areas
437 // hud for example can be modified by EmergeThread
446 class RemotePlayer : public Player
449 RemotePlayer(IGameDef *gamedef, const char *name);
450 virtual ~RemotePlayer() {}
452 void save(std::string savedir);
454 PlayerSAO *getPlayerSAO()
456 void setPlayerSAO(PlayerSAO *sao)
458 void setPosition(const v3f &position);