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;
64 float a_sidew_move_joystick_axis,
65 float a_forw_move_joystick_axis
79 sidew_move_joystick_axis = a_sidew_move_joystick_axis;
80 forw_move_joystick_axis = a_forw_move_joystick_axis;
93 float sidew_move_joystick_axis;
94 float forw_move_joystick_axis;
105 // Do *not* perform an assignment or copy operation on a Player or
106 // RemotePlayer object! This will copy the lock held for HUD synchronization
111 Player(IGameDef *gamedef, const char *name);
112 virtual ~Player() = 0;
114 virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
116 virtual void move(f32 dtime, Environment *env, f32 pos_max_d,
117 std::vector<CollisionInfo> *collision_info)
125 void setSpeed(v3f speed)
135 v3s16 getLightPosition() const;
139 float eye_height = camera_barely_in_ceiling ? 1.5f : 1.625f;
140 return v3f(0, BS * eye_height, 0);
145 return m_position + getEyeOffset();
148 virtual void setPosition(const v3f &position)
150 if (position != m_position)
152 m_position = position;
155 void setPitch(f32 pitch)
157 if (pitch != m_pitch)
162 virtual void setYaw(f32 yaw)
184 virtual void setBreath(u16 breath)
186 if (breath != m_breath)
193 return -1.0 * m_pitch * core::DEGTORAD;
198 return (m_yaw + 90.) * core::DEGTORAD;
201 const char *getName() const
206 aabb3f getCollisionbox()
208 return m_collisionbox;
212 size_t size = hud.size();
213 for (size_t i = 0; i != size; i++) {
220 void setHotbarItemcount(s32 hotbar_itemcount)
222 hud_hotbar_itemcount = hotbar_itemcount;
225 s32 getHotbarItemcount()
227 return hud_hotbar_itemcount;
230 void setHotbarImage(const std::string &name)
232 hud_hotbar_image = name;
235 std::string getHotbarImage()
237 return hud_hotbar_image;
240 void setHotbarSelectedImage(const std::string &name)
242 hud_hotbar_selected_image = name;
245 std::string getHotbarSelectedImage() {
246 return hud_hotbar_selected_image;
249 void setSky(const video::SColor &bgcolor, const std::string &type,
250 const std::vector<std::string> ¶ms)
252 m_sky_bgcolor = bgcolor;
254 m_sky_params = params;
257 void getSky(video::SColor *bgcolor, std::string *type,
258 std::vector<std::string> *params)
260 *bgcolor = m_sky_bgcolor;
262 *params = m_sky_params;
265 void overrideDayNightRatio(bool do_override, float ratio)
267 m_day_night_ratio_do_override = do_override;
268 m_day_night_ratio = ratio;
271 void getDayNightRatio(bool *do_override, float *ratio)
273 *do_override = m_day_night_ratio_do_override;
274 *ratio = m_day_night_ratio;
277 void setLocalAnimations(v2s32 frames[4], float frame_speed)
279 for (int i = 0; i < 4; i++)
280 local_animations[i] = frames[i];
281 local_animation_speed = frame_speed;
284 void getLocalAnimations(v2s32 *frames, float *frame_speed)
286 for (int i = 0; i < 4; i++)
287 frames[i] = local_animations[i];
288 *frame_speed = local_animation_speed;
291 virtual bool isLocal() const
296 virtual PlayerSAO *getPlayerSAO()
301 virtual void setPlayerSAO(PlayerSAO *sao)
303 FATAL_ERROR("FIXME");
307 serialize() writes a bunch of text that can contain
308 any characters except a '\0', and such an ending that
309 deSerialize stops reading exactly at the right point.
311 void serialize(std::ostream &os);
312 void deSerialize(std::istream &is, std::string playername);
314 bool checkModified() const
316 return m_dirty || inventory.checkModified();
319 void setModified(const bool x)
323 inventory.setModified(x);
326 // Use a function, if isDead can be defined by other conditions
327 bool isDead() { return hp == 0; }
330 bool touching_ground;
331 // This oscillates so that the player jumps a bit above the surface
333 // This is more stable and defines the maximum speed of the player
334 bool in_liquid_stable;
335 // Gets the viscosity of water to calculate friction
338 bool swimming_vertical;
339 bool camera_barely_in_ceiling;
340 v3f eye_offset_first;
341 v3f eye_offset_third;
345 f32 movement_acceleration_default;
346 f32 movement_acceleration_air;
347 f32 movement_acceleration_fast;
348 f32 movement_speed_walk;
349 f32 movement_speed_crouch;
350 f32 movement_speed_fast;
351 f32 movement_speed_climb;
352 f32 movement_speed_jump;
353 f32 movement_liquid_fluidity;
354 f32 movement_liquid_fluidity_smooth;
355 f32 movement_liquid_sink;
356 f32 movement_gravity;
358 float physics_override_speed;
359 float physics_override_jump;
360 float physics_override_gravity;
361 bool physics_override_sneak;
362 bool physics_override_sneak_glitch;
364 v2s32 local_animations[4];
365 float local_animation_speed;
369 float hurt_tilt_timer;
370 float hurt_tilt_strength;
372 u16 protocol_version;
375 std::string inventory_formspec;
377 PlayerControl control;
378 PlayerControl getPlayerControl()
386 HudElement* getHud(u32 id);
387 u32 addHud(HudElement* hud);
388 HudElement* removeHud(u32 id);
395 s32 hud_hotbar_itemcount;
396 std::string hud_hotbar_image;
397 std::string hud_hotbar_selected_image;
401 char m_name[PLAYERNAME_SIZE];
407 aabb3f m_collisionbox;
411 std::vector<HudElement *> hud;
413 std::string m_sky_type;
414 video::SColor m_sky_bgcolor;
415 std::vector<std::string> m_sky_params;
417 bool m_day_night_ratio_do_override;
418 float m_day_night_ratio;
420 // Protect some critical areas
421 // hud for example can be modified by EmergeThread
430 class RemotePlayer : public Player
433 RemotePlayer(IGameDef *gamedef, const char *name);
434 virtual ~RemotePlayer() {}
436 void save(std::string savedir);
438 PlayerSAO *getPlayerSAO()
440 void setPlayerSAO(PlayerSAO *sao)
442 void setPosition(const v3f &position);