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):
34 peer_id(PEER_ID_INEXISTENT),
39 strlcpy(m_name, name, PLAYERNAME_SIZE);
42 inventory.addList("main", PLAYER_INVENTORY_SIZE);
43 inventory.addList("hand", 1);
44 InventoryList *craft = inventory.addList("craft", 9);
46 inventory.addList("craftpreview", 1);
47 inventory.addList("craftresult", 1);
48 inventory.setModified(false);
50 // Can be redefined via Lua
51 inventory_formspec = "size[8,7.5]"
52 //"image[1,0.6;1,2;player.png]"
53 "list[current_player;main;0,3.5;8,4;]"
54 "list[current_player;craft;3,0;3,3;]"
56 "list[current_player;craftpreview;7,1;1,1;]";
58 // Initialize movement settings at default values, so movement can work
59 // if the server fails to send them
60 movement_acceleration_default = 3 * BS;
61 movement_acceleration_air = 2 * BS;
62 movement_acceleration_fast = 10 * BS;
63 movement_speed_walk = 4 * BS;
64 movement_speed_crouch = 1.35 * BS;
65 movement_speed_fast = 20 * BS;
66 movement_speed_climb = 2 * BS;
67 movement_speed_jump = 6.5 * BS;
68 movement_liquid_fluidity = 1 * BS;
69 movement_liquid_fluidity_smooth = 0.5 * BS;
70 movement_liquid_sink = 10 * BS;
71 movement_gravity = 9.81 * BS;
72 local_animation_speed = 0.0;
75 HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE |
76 HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
77 HUD_FLAG_BREATHBAR_VISIBLE | HUD_FLAG_MINIMAP_VISIBLE;
79 hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;
87 u32 Player::addHud(HudElement *toadd)
89 MutexAutoLock lock(m_mutex);
91 u32 id = getFreeHudID();
101 HudElement* Player::getHud(u32 id)
103 MutexAutoLock lock(m_mutex);
111 HudElement* Player::removeHud(u32 id)
113 MutexAutoLock lock(m_mutex);
115 HudElement* retval = NULL;
116 if (id < hud.size()) {
123 void Player::clearHud()
125 MutexAutoLock lock(m_mutex);
127 while(!hud.empty()) {