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 "irrlichttypes_bloated.h"
23 #include "inventory.h"
24 #include "constants.h"
25 #include "network/networkprotocol.h"
26 #include "util/basic_macros.h"
30 #define PLAYERNAME_SIZE 20
32 #define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
33 #define PLAYERNAME_ALLOWED_CHARS_USER_EXPL "'a' to 'z', 'A' to 'Z', '0' to '9', '-', '_'"
39 // Whether to multiply the client's FOV or to override it
42 // The time to be take to trasition to the new FOV value.
43 // Transition is instantaneous if omitted. Omitted by default.
49 PlayerControl() = default;
64 float a_sidew_move_joystick_axis
,
65 float a_forw_move_joystick_axis
80 sidew_move_joystick_axis
= a_sidew_move_joystick_axis
;
81 forw_move_joystick_axis
= a_forw_move_joystick_axis
;
95 float sidew_move_joystick_axis
= 0.0f
;
96 float forw_move_joystick_axis
= 0.0f
;
101 bool free_move
= false;
102 bool pitch_move
= false;
103 bool fast_move
= false;
104 bool freecam
= false;
105 bool continuous_forward
= false;
106 bool always_fly_fast
= false;
107 bool aux1_descends
= false;
109 bool autojump
= false;
111 const std::string setting_names
[9] = {
112 "free_move", "pitch_move", "fast_move", "freecam", "continuous_forward", "always_fly_fast",
113 "aux1_descends", "noclip", "autojump"
115 void readGlobalSettings();
119 struct CollisionInfo
;
127 Player(const char *name
, IItemDefManager
*idef
);
128 virtual ~Player() = 0;
130 DISABLE_CLASS_COPY(Player
);
132 virtual void move(f32 dtime
, Environment
*env
, f32 pos_max_d
)
134 virtual void move(f32 dtime
, Environment
*env
, f32 pos_max_d
,
135 std::vector
<CollisionInfo
> *collision_info
)
138 const v3f
&getSpeed() const
143 void setSpeed(const v3f
&speed
)
148 const char *getName() const { return m_name
; }
152 size_t size
= hud
.size();
153 for (size_t i
= 0; i
!= size
; i
++) {
160 v3f eye_offset_first
;
161 v3f eye_offset_third
;
165 f32 movement_acceleration_default
;
166 f32 movement_acceleration_air
;
167 f32 movement_acceleration_fast
;
168 f32 movement_speed_walk
;
169 f32 movement_speed_crouch
;
170 f32 movement_speed_fast
;
171 f32 movement_speed_climb
;
172 f32 movement_speed_jump
;
173 f32 movement_liquid_fluidity
;
174 f32 movement_liquid_fluidity_smooth
;
175 f32 movement_liquid_sink
;
176 f32 movement_gravity
;
178 v2s32 local_animations
[4];
179 float local_animation_speed
;
181 std::string inventory_formspec
;
182 std::string formspec_prepend
;
184 PlayerControl control
;
185 const PlayerControl
& getPlayerControl() { return control
; }
186 PlayerSettings
&getPlayerSettings() { return m_player_settings
; }
187 static void settingsChangedCallback(const std::string
&name
, void *data
);
189 // Returns non-empty `selected` ItemStack. `hand` is a fallback, if specified
190 ItemStack
&getWieldedItem(ItemStack
*selected
, ItemStack
*hand
) const;
191 void setWieldIndex(u16 index
);
192 u16
getWieldIndex() const { return m_wield_index
; }
194 void setFov(const PlayerFovSpec
&spec
)
196 m_fov_override_spec
= spec
;
199 const PlayerFovSpec
&getFov() const
201 return m_fov_override_spec
;
206 HudElement
* getHud(u32 id
);
207 u32
addHud(HudElement
* hud
);
208 HudElement
* removeHud(u32 id
);
212 s32 hud_hotbar_itemcount
;
215 char m_name
[PLAYERNAME_SIZE
];
217 u16 m_wield_index
= 0;
218 PlayerFovSpec m_fov_override_spec
= { 0.0f
, false, 0.0f
};
220 std::vector
<HudElement
*> hud
;
222 // Protect some critical areas
223 // hud for example can be modified by EmergeThread
226 PlayerSettings m_player_settings
;