]> git.lizzy.rs Git - dragonfireclient.git/blob - src/player.cpp
Implement GItlab CI daily builds for windows platform (32 & 64) (#5923)
[dragonfireclient.git] / src / player.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #include "player.h"
21
22 #include "threading/mutex_auto_lock.h"
23 #include "util/numeric.h"
24 #include "hud.h"
25 #include "constants.h"
26 #include "gamedef.h"
27 #include "settings.h"
28 #include "log.h"
29 #include "porting.h"  // strlcpy
30
31
32 Player::Player(const char *name, IItemDefManager *idef):
33         inventory(idef),
34         peer_id(PEER_ID_INEXISTENT),
35         keyPressed(0),
36 // protected
37         m_speed(0,0,0)
38 {
39         strlcpy(m_name, name, PLAYERNAME_SIZE);
40
41         inventory.clear();
42         inventory.addList("main", PLAYER_INVENTORY_SIZE);
43         inventory.addList("hand", 1);
44         InventoryList *craft = inventory.addList("craft", 9);
45         craft->setWidth(3);
46         inventory.addList("craftpreview", 1);
47         inventory.addList("craftresult", 1);
48         inventory.setModified(false);
49
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;]"
55                 "listring[]"
56                 "list[current_player;craftpreview;7,1;1,1;]";
57
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;
73
74         hud_flags =
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;
78
79         hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;
80 }
81
82 Player::~Player()
83 {
84         clearHud();
85 }
86
87 u32 Player::addHud(HudElement *toadd)
88 {
89         MutexAutoLock lock(m_mutex);
90
91         u32 id = getFreeHudID();
92
93         if (id < hud.size())
94                 hud[id] = toadd;
95         else
96                 hud.push_back(toadd);
97
98         return id;
99 }
100
101 HudElement* Player::getHud(u32 id)
102 {
103         MutexAutoLock lock(m_mutex);
104
105         if (id < hud.size())
106                 return hud[id];
107
108         return NULL;
109 }
110
111 HudElement* Player::removeHud(u32 id)
112 {
113         MutexAutoLock lock(m_mutex);
114
115         HudElement* retval = NULL;
116         if (id < hud.size()) {
117                 retval = hud[id];
118                 hud[id] = NULL;
119         }
120         return retval;
121 }
122
123 void Player::clearHud()
124 {
125         MutexAutoLock lock(m_mutex);
126
127         while(!hud.empty()) {
128                 delete hud.back();
129                 hud.pop_back();
130         }
131 }