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 // This is at the height of the eyes of the current figure
134 // return v3f(0, BS*1.5, 0);
135 // This is more like in minecraft
136 if(camera_barely_in_ceiling)
137 return v3f(0,BS*1.5,0);
139 return v3f(0,BS*1.625,0);
144 return m_position + getEyeOffset();
147 virtual void setPosition(const v3f &position)
149 if (position != m_position)
151 m_position = position;
154 void setPitch(f32 pitch)
156 if (pitch != m_pitch)
161 virtual void setYaw(f32 yaw)
183 virtual void setBreath(u16 breath)
185 if (breath != m_breath)
192 return -1.0 * m_pitch * core::DEGTORAD;
197 return (m_yaw + 90.) * core::DEGTORAD;
200 const char * getName() const
205 core::aabbox3d<f32> getCollisionbox() {
206 return m_collisionbox;
210 size_t size = hud.size();
211 for (size_t i = 0; i != size; i++) {
218 void setHotbarItemcount(s32 hotbar_itemcount) {
219 hud_hotbar_itemcount = hotbar_itemcount;
221 s32 getHotbarItemcount() {
222 return hud_hotbar_itemcount;
224 void setHotbarImage(std::string name) {
225 hud_hotbar_image = name;
227 std::string getHotbarImage() {
228 return hud_hotbar_image;
230 void setHotbarSelectedImage(std::string name) {
231 hud_hotbar_selected_image = name;
233 std::string getHotbarSelectedImage() {
234 return hud_hotbar_selected_image;
237 void setSky(const video::SColor &bgcolor, const std::string &type,
238 const std::vector<std::string> ¶ms) {
239 m_sky_bgcolor = bgcolor;
241 m_sky_params = params;
243 void getSky(video::SColor *bgcolor, std::string *type,
244 std::vector<std::string> *params) {
245 *bgcolor = m_sky_bgcolor;
247 *params = m_sky_params;
249 void overrideDayNightRatio(bool do_override, float ratio) {
250 m_day_night_ratio_do_override = do_override;
251 m_day_night_ratio = ratio;
253 void getDayNightRatio(bool *do_override, float *ratio) {
254 *do_override = m_day_night_ratio_do_override;
255 *ratio = m_day_night_ratio;
257 void setLocalAnimations(v2s32 frames[4], float frame_speed) {
258 for (int i = 0; i < 4; i++)
259 local_animations[i] = frames[i];
260 local_animation_speed = frame_speed;
262 void getLocalAnimations(v2s32 *frames, float *frame_speed) {
263 for (int i = 0; i < 4; i++)
264 frames[i] = local_animations[i];
265 *frame_speed = local_animation_speed;
268 virtual bool isLocal() const
270 virtual PlayerSAO *getPlayerSAO()
272 virtual void setPlayerSAO(PlayerSAO *sao)
273 { FATAL_ERROR("FIXME"); }
276 serialize() writes a bunch of text that can contain
277 any characters except a '\0', and such an ending that
278 deSerialize stops reading exactly at the right point.
280 void serialize(std::ostream &os);
281 void deSerialize(std::istream &is, std::string playername);
283 bool checkModified() const
285 return m_dirty || inventory.checkModified();
288 void setModified(const bool x)
292 inventory.setModified(x);
295 // Use a function, if isDead can be defined by other conditions
296 bool isDead() { return hp == 0; }
298 bool touching_ground;
299 // This oscillates so that the player jumps a bit above the surface
301 // This is more stable and defines the maximum speed of the player
302 bool in_liquid_stable;
303 // Gets the viscosity of water to calculate friction
306 bool swimming_vertical;
307 bool camera_barely_in_ceiling;
308 v3f eye_offset_first;
309 v3f eye_offset_third;
313 f32 movement_acceleration_default;
314 f32 movement_acceleration_air;
315 f32 movement_acceleration_fast;
316 f32 movement_speed_walk;
317 f32 movement_speed_crouch;
318 f32 movement_speed_fast;
319 f32 movement_speed_climb;
320 f32 movement_speed_jump;
321 f32 movement_liquid_fluidity;
322 f32 movement_liquid_fluidity_smooth;
323 f32 movement_liquid_sink;
324 f32 movement_gravity;
326 float physics_override_speed;
327 float physics_override_jump;
328 float physics_override_gravity;
329 bool physics_override_sneak;
330 bool physics_override_sneak_glitch;
332 v2s32 local_animations[4];
333 float local_animation_speed;
337 float hurt_tilt_timer;
338 float hurt_tilt_strength;
342 std::string inventory_formspec;
344 PlayerControl control;
345 PlayerControl getPlayerControl()
353 HudElement* getHud(u32 id);
354 u32 addHud(HudElement* hud);
355 HudElement* removeHud(u32 id);
362 s32 hud_hotbar_itemcount;
363 std::string hud_hotbar_image;
364 std::string hud_hotbar_selected_image;
368 char m_name[PLAYERNAME_SIZE];
374 core::aabbox3d<f32> m_collisionbox;
378 std::vector<HudElement *> hud;
380 std::string m_sky_type;
381 video::SColor m_sky_bgcolor;
382 std::vector<std::string> m_sky_params;
384 bool m_day_night_ratio_do_override;
385 float m_day_night_ratio;
387 // Protect some critical areas
388 // hud for example can be modified by EmergeThread
397 class RemotePlayer : public Player
400 RemotePlayer(IGameDef *gamedef, const char *name):
401 Player(gamedef, name),
404 virtual ~RemotePlayer() {}
406 void save(std::string savedir);
408 PlayerSAO *getPlayerSAO()
410 void setPlayerSAO(PlayerSAO *sao)
412 void setPosition(const v3f &position);