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.
22 #include "threading/mutex_auto_lock.h"
23 #include "util/numeric.h"
25 #include "constants.h"
29 #include "porting.h" // strlcpy
32 Player::Player(const char *name, IItemDefManager *idef):
33 camera_barely_in_ceiling(false),
36 peer_id(PEER_ID_INEXISTENT),
39 m_breath(PLAYER_MAX_BREATH),
44 m_collisionbox(-BS*0.30,0.0,-BS*0.30,BS*0.30,BS*1.75,BS*0.30)
46 strlcpy(m_name, name, PLAYERNAME_SIZE);
49 inventory.addList("main", PLAYER_INVENTORY_SIZE);
50 InventoryList *craft = inventory.addList("craft", 9);
52 inventory.addList("craftpreview", 1);
53 inventory.addList("craftresult", 1);
54 inventory.setModified(false);
56 // Can be redefined via Lua
57 inventory_formspec = "size[8,7.5]"
58 //"image[1,0.6;1,2;player.png]"
59 "list[current_player;main;0,3.5;8,4;]"
60 "list[current_player;craft;3,0;3,3;]"
62 "list[current_player;craftpreview;7,1;1,1;]";
64 // Initialize movement settings at default values, so movement can work
65 // if the server fails to send them
66 movement_acceleration_default = 3 * BS;
67 movement_acceleration_air = 2 * BS;
68 movement_acceleration_fast = 10 * BS;
69 movement_speed_walk = 4 * BS;
70 movement_speed_crouch = 1.35 * BS;
71 movement_speed_fast = 20 * BS;
72 movement_speed_climb = 2 * BS;
73 movement_speed_jump = 6.5 * BS;
74 movement_liquid_fluidity = 1 * BS;
75 movement_liquid_fluidity_smooth = 0.5 * BS;
76 movement_liquid_sink = 10 * BS;
77 movement_gravity = 9.81 * BS;
78 local_animation_speed = 0.0;
81 HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE |
82 HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
83 HUD_FLAG_BREATHBAR_VISIBLE | HUD_FLAG_MINIMAP_VISIBLE;
85 hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;
93 v3s16 Player::getLightPosition() const
95 return floatToInt(m_position + v3f(0,BS+BS/2,0), BS);
98 u32 Player::addHud(HudElement *toadd)
100 MutexAutoLock lock(m_mutex);
102 u32 id = getFreeHudID();
107 hud.push_back(toadd);
112 HudElement* Player::getHud(u32 id)
114 MutexAutoLock lock(m_mutex);
122 HudElement* Player::removeHud(u32 id)
124 MutexAutoLock lock(m_mutex);
126 HudElement* retval = NULL;
127 if (id < hud.size()) {
134 void Player::clearHud()
136 MutexAutoLock lock(m_mutex);
138 while(!hud.empty()) {