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', '-', '_'"
97 // Do *not* perform an assignment or copy operation on a Player or
98 // RemotePlayer object! This will copy the lock held for HUD synchronization
103 Player(IGameDef *gamedef, const char *name);
104 virtual ~Player() = 0;
106 virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
108 virtual void move(f32 dtime, Environment *env, f32 pos_max_d,
109 std::vector<CollisionInfo> *collision_info)
117 void setSpeed(v3f speed)
122 void accelerateHorizontal(v3f target_speed, f32 max_increase);
123 void accelerateVertical(v3f target_speed, f32 max_increase);
130 v3s16 getLightPosition() const;
134 float eye_height = camera_barely_in_ceiling ? 1.5f : 1.625f;
135 return v3f(0, BS * eye_height, 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()
203 return m_collisionbox;
207 size_t size = hud.size();
208 for (size_t i = 0; i != size; i++) {
215 void setHotbarItemcount(s32 hotbar_itemcount)
217 hud_hotbar_itemcount = hotbar_itemcount;
220 s32 getHotbarItemcount()
222 return hud_hotbar_itemcount;
225 void setHotbarImage(const std::string &name)
227 hud_hotbar_image = name;
230 std::string getHotbarImage()
232 return hud_hotbar_image;
235 void setHotbarSelectedImage(const std::string &name)
237 hud_hotbar_selected_image = name;
240 std::string getHotbarSelectedImage() {
241 return hud_hotbar_selected_image;
244 void setSky(const video::SColor &bgcolor, const std::string &type,
245 const std::vector<std::string> ¶ms)
247 m_sky_bgcolor = bgcolor;
249 m_sky_params = params;
252 void getSky(video::SColor *bgcolor, std::string *type,
253 std::vector<std::string> *params)
255 *bgcolor = m_sky_bgcolor;
257 *params = m_sky_params;
260 void overrideDayNightRatio(bool do_override, float ratio)
262 m_day_night_ratio_do_override = do_override;
263 m_day_night_ratio = ratio;
266 void getDayNightRatio(bool *do_override, float *ratio)
268 *do_override = m_day_night_ratio_do_override;
269 *ratio = m_day_night_ratio;
272 void setLocalAnimations(v2s32 frames[4], float frame_speed)
274 for (int i = 0; i < 4; i++)
275 local_animations[i] = frames[i];
276 local_animation_speed = frame_speed;
279 void getLocalAnimations(v2s32 *frames, float *frame_speed)
281 for (int i = 0; i < 4; i++)
282 frames[i] = local_animations[i];
283 *frame_speed = local_animation_speed;
286 virtual bool isLocal() const
291 virtual PlayerSAO *getPlayerSAO()
296 virtual void setPlayerSAO(PlayerSAO *sao)
298 FATAL_ERROR("FIXME");
302 serialize() writes a bunch of text that can contain
303 any characters except a '\0', and such an ending that
304 deSerialize stops reading exactly at the right point.
306 void serialize(std::ostream &os);
307 void deSerialize(std::istream &is, std::string playername);
309 bool checkModified() const
311 return m_dirty || inventory.checkModified();
314 void setModified(const bool x)
318 inventory.setModified(x);
321 // Use a function, if isDead can be defined by other conditions
322 bool isDead() { return hp == 0; }
324 bool touching_ground;
325 // This oscillates so that the player jumps a bit above the surface
327 // This is more stable and defines the maximum speed of the player
328 bool in_liquid_stable;
329 // Gets the viscosity of water to calculate friction
332 bool swimming_vertical;
333 bool camera_barely_in_ceiling;
334 v3f eye_offset_first;
335 v3f eye_offset_third;
339 f32 movement_acceleration_default;
340 f32 movement_acceleration_air;
341 f32 movement_acceleration_fast;
342 f32 movement_speed_walk;
343 f32 movement_speed_crouch;
344 f32 movement_speed_fast;
345 f32 movement_speed_climb;
346 f32 movement_speed_jump;
347 f32 movement_liquid_fluidity;
348 f32 movement_liquid_fluidity_smooth;
349 f32 movement_liquid_sink;
350 f32 movement_gravity;
352 float physics_override_speed;
353 float physics_override_jump;
354 float physics_override_gravity;
355 bool physics_override_sneak;
356 bool physics_override_sneak_glitch;
358 v2s32 local_animations[4];
359 float local_animation_speed;
363 float hurt_tilt_timer;
364 float hurt_tilt_strength;
366 u16 protocol_version;
369 std::string inventory_formspec;
371 PlayerControl control;
372 PlayerControl getPlayerControl()
380 HudElement* getHud(u32 id);
381 u32 addHud(HudElement* hud);
382 HudElement* removeHud(u32 id);
389 s32 hud_hotbar_itemcount;
390 std::string hud_hotbar_image;
391 std::string hud_hotbar_selected_image;
395 char m_name[PLAYERNAME_SIZE];
401 core::aabbox3d<f32> m_collisionbox;
405 std::vector<HudElement *> hud;
407 std::string m_sky_type;
408 video::SColor m_sky_bgcolor;
409 std::vector<std::string> m_sky_params;
411 bool m_day_night_ratio_do_override;
412 float m_day_night_ratio;
414 // Protect some critical areas
415 // hud for example can be modified by EmergeThread
424 class RemotePlayer : public Player
427 RemotePlayer(IGameDef *gamedef, const char *name);
428 virtual ~RemotePlayer() {}
430 void save(std::string savedir);
432 PlayerSAO *getPlayerSAO()
434 void setPlayerSAO(PlayerSAO *sao)
436 void setPosition(const v3f &position);