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-_"
96 // Do *not* perform an assignment or copy operation on a Player or
97 // RemotePlayer object! This will copy the lock held for HUD synchronization
102 Player(IGameDef *gamedef, const char *name);
103 virtual ~Player() = 0;
105 virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
107 virtual void move(f32 dtime, Environment *env, f32 pos_max_d,
108 std::vector<CollisionInfo> *collision_info)
116 void setSpeed(v3f speed)
121 void accelerateHorizontal(v3f target_speed, f32 max_increase);
122 void accelerateVertical(v3f target_speed, f32 max_increase);
129 v3s16 getLightPosition() const;
133 float eye_height = camera_barely_in_ceiling ? 1.5f : 1.625f;
134 return v3f(0, BS * eye_height, 0);
139 return m_position + getEyeOffset();
142 virtual void setPosition(const v3f &position)
144 if (position != m_position)
146 m_position = position;
149 void setPitch(f32 pitch)
151 if (pitch != m_pitch)
156 virtual void setYaw(f32 yaw)
178 virtual void setBreath(u16 breath)
180 if (breath != m_breath)
187 return -1.0 * m_pitch * core::DEGTORAD;
192 return (m_yaw + 90.) * core::DEGTORAD;
195 const char *getName() const
200 core::aabbox3d<f32> getCollisionbox()
202 return m_collisionbox;
206 size_t size = hud.size();
207 for (size_t i = 0; i != size; i++) {
214 void setHotbarItemcount(s32 hotbar_itemcount)
216 hud_hotbar_itemcount = hotbar_itemcount;
219 s32 getHotbarItemcount()
221 return hud_hotbar_itemcount;
224 void setHotbarImage(const std::string &name)
226 hud_hotbar_image = name;
229 std::string getHotbarImage()
231 return hud_hotbar_image;
234 void setHotbarSelectedImage(const std::string &name)
236 hud_hotbar_selected_image = name;
239 std::string getHotbarSelectedImage() {
240 return hud_hotbar_selected_image;
243 void setSky(const video::SColor &bgcolor, const std::string &type,
244 const std::vector<std::string> ¶ms)
246 m_sky_bgcolor = bgcolor;
248 m_sky_params = params;
251 void getSky(video::SColor *bgcolor, std::string *type,
252 std::vector<std::string> *params)
254 *bgcolor = m_sky_bgcolor;
256 *params = m_sky_params;
259 void overrideDayNightRatio(bool do_override, float ratio)
261 m_day_night_ratio_do_override = do_override;
262 m_day_night_ratio = ratio;
265 void getDayNightRatio(bool *do_override, float *ratio)
267 *do_override = m_day_night_ratio_do_override;
268 *ratio = m_day_night_ratio;
271 void setLocalAnimations(v2s32 frames[4], float frame_speed)
273 for (int i = 0; i < 4; i++)
274 local_animations[i] = frames[i];
275 local_animation_speed = frame_speed;
278 void getLocalAnimations(v2s32 *frames, float *frame_speed)
280 for (int i = 0; i < 4; i++)
281 frames[i] = local_animations[i];
282 *frame_speed = local_animation_speed;
285 virtual bool isLocal() const
290 virtual PlayerSAO *getPlayerSAO()
295 virtual void setPlayerSAO(PlayerSAO *sao)
297 FATAL_ERROR("FIXME");
301 serialize() writes a bunch of text that can contain
302 any characters except a '\0', and such an ending that
303 deSerialize stops reading exactly at the right point.
305 void serialize(std::ostream &os);
306 void deSerialize(std::istream &is, std::string playername);
308 bool checkModified() const
310 return m_dirty || inventory.checkModified();
313 void setModified(const bool x)
317 inventory.setModified(x);
320 // Use a function, if isDead can be defined by other conditions
321 bool isDead() { return hp == 0; }
323 bool touching_ground;
324 // This oscillates so that the player jumps a bit above the surface
326 // This is more stable and defines the maximum speed of the player
327 bool in_liquid_stable;
328 // Gets the viscosity of water to calculate friction
331 bool swimming_vertical;
332 bool camera_barely_in_ceiling;
333 v3f eye_offset_first;
334 v3f eye_offset_third;
338 f32 movement_acceleration_default;
339 f32 movement_acceleration_air;
340 f32 movement_acceleration_fast;
341 f32 movement_speed_walk;
342 f32 movement_speed_crouch;
343 f32 movement_speed_fast;
344 f32 movement_speed_climb;
345 f32 movement_speed_jump;
346 f32 movement_liquid_fluidity;
347 f32 movement_liquid_fluidity_smooth;
348 f32 movement_liquid_sink;
349 f32 movement_gravity;
351 float physics_override_speed;
352 float physics_override_jump;
353 float physics_override_gravity;
354 bool physics_override_sneak;
355 bool physics_override_sneak_glitch;
357 v2s32 local_animations[4];
358 float local_animation_speed;
362 float hurt_tilt_timer;
363 float hurt_tilt_strength;
365 u16 protocol_version;
368 std::string inventory_formspec;
370 PlayerControl control;
371 PlayerControl getPlayerControl()
379 HudElement* getHud(u32 id);
380 u32 addHud(HudElement* hud);
381 HudElement* removeHud(u32 id);
388 s32 hud_hotbar_itemcount;
389 std::string hud_hotbar_image;
390 std::string hud_hotbar_selected_image;
394 char m_name[PLAYERNAME_SIZE];
400 core::aabbox3d<f32> m_collisionbox;
404 std::vector<HudElement *> hud;
406 std::string m_sky_type;
407 video::SColor m_sky_bgcolor;
408 std::vector<std::string> m_sky_params;
410 bool m_day_night_ratio_do_override;
411 float m_day_night_ratio;
413 // Protect some critical areas
414 // hud for example can be modified by EmergeThread
423 class RemotePlayer : public Player
426 RemotePlayer(IGameDef *gamedef, const char *name):
427 Player(gamedef, name),
430 virtual ~RemotePlayer() {}
432 void save(std::string savedir);
434 PlayerSAO *getPlayerSAO()
436 void setPlayerSAO(PlayerSAO *sao)
438 void setPosition(const v3f &position);