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.
20 #ifndef CONTENT_SAO_HEADER
21 #define CONTENT_SAO_HEADER
23 #include "serverobject.h"
24 #include "itemgroup.h"
26 #include "object_properties.h"
29 LuaEntitySAO needs some internals exposed.
32 class LuaEntitySAO : public ServerActiveObject
35 LuaEntitySAO(ServerEnvironment *env, v3f pos,
36 const std::string &name, const std::string &state);
38 ActiveObjectType getType() const
39 { return ACTIVEOBJECT_TYPE_LUAENTITY; }
40 ActiveObjectType getSendType() const
41 { return ACTIVEOBJECT_TYPE_GENERIC; }
42 virtual void addedToEnvironment(u32 dtime_s);
43 static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
44 const std::string &data);
46 void step(float dtime, bool send_recommended);
47 std::string getClientInitializationData(u16 protocol_version);
48 std::string getStaticData();
50 const ToolCapabilities *toolcap=NULL,
51 ServerActiveObject *puncher=NULL,
52 float time_from_last_punch=1000000);
53 void rightClick(ServerActiveObject *clicker);
55 void moveTo(v3f pos, bool continuous);
56 float getMinimumSavedMovement();
57 std::string getDescription();
60 void setArmorGroups(const ItemGroupList &armor_groups);
61 ItemGroupList getArmorGroups();
62 void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
63 void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
64 void setBonePosition(const std::string &bone, v3f position, v3f rotation);
65 void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
66 void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
67 void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
68 void addAttachmentChild(int child_id);
69 void removeAttachmentChild(int child_id);
70 std::set<int> getAttachmentChildIds();
71 ObjectProperties* accessObjectProperties();
72 void notifyObjectPropertiesModified();
73 /* LuaEntitySAO-specific */
74 void setVelocity(v3f velocity);
76 void setAcceleration(v3f acceleration);
77 v3f getAcceleration();
78 void setYaw(float yaw);
80 void setTextureMod(const std::string &mod);
81 void setSprite(v2s16 p, int num_frames, float framelength,
82 bool select_horiz_by_yawpitch);
83 std::string getName();
84 bool getCollisionBox(aabb3f *toset);
85 bool collideWithObjects();
87 std::string getPropertyPacket();
88 void sendPosition(bool do_interpolate, bool is_movement_end);
90 std::string m_init_name;
91 std::string m_init_state;
93 struct ObjectProperties m_prop;
99 ItemGroupList m_armor_groups;
101 bool m_properties_sent;
102 float m_last_sent_yaw;
103 v3f m_last_sent_position;
104 v3f m_last_sent_velocity;
105 float m_last_sent_position_timer;
106 float m_last_sent_move_precision;
107 bool m_armor_groups_sent;
109 v2f m_animation_range;
110 float m_animation_speed;
111 float m_animation_blend;
112 bool m_animation_loop;
113 bool m_animation_sent;
115 UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
116 bool m_bone_position_sent;
118 int m_attachment_parent_id;
119 std::set<int> m_attachment_child_ids;
120 std::string m_attachment_bone;
121 v3f m_attachment_position;
122 v3f m_attachment_rotation;
123 bool m_attachment_sent;
127 PlayerSAO needs some internals exposed.
135 LagPool(): m_pool(15), m_max(15)
137 void setMax(float new_max)
143 void add(float dtime)
149 bool grab(float dtime)
153 if(m_pool + dtime > m_max)
160 class PlayerSAO : public ServerActiveObject
163 PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id_,
164 const std::set<std::string> &privs, bool is_singleplayer);
166 ActiveObjectType getType() const
167 { return ACTIVEOBJECT_TYPE_PLAYER; }
168 ActiveObjectType getSendType() const
169 { return ACTIVEOBJECT_TYPE_GENERIC; }
170 std::string getDescription();
173 Active object <-> environment interface
176 void addedToEnvironment(u32 dtime_s);
177 void removingFromEnvironment();
178 bool isStaticAllowed() const;
179 std::string getClientInitializationData(u16 protocol_version);
180 std::string getStaticData();
182 void step(float dtime, bool send_recommended);
183 void setBasePosition(const v3f &position);
184 void setPos(v3f pos);
185 void moveTo(v3f pos, bool continuous);
187 void setPitch(float);
190 Interaction interface
194 const ToolCapabilities *toolcap,
195 ServerActiveObject *puncher,
196 float time_from_last_punch);
197 void rightClick(ServerActiveObject *clicker);
201 u16 getBreath() const;
202 void setBreath(u16 breath);
203 void setArmorGroups(const ItemGroupList &armor_groups);
204 ItemGroupList getArmorGroups();
205 void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
206 void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
207 void setBonePosition(const std::string &bone, v3f position, v3f rotation);
208 void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
209 void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
210 void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
211 void addAttachmentChild(int child_id);
212 void removeAttachmentChild(int child_id);
213 std::set<int> getAttachmentChildIds();
214 ObjectProperties* accessObjectProperties();
215 void notifyObjectPropertiesModified();
221 Inventory* getInventory();
222 const Inventory* getInventory() const;
223 InventoryLocation getInventoryLocation() const;
224 std::string getWieldList() const;
225 int getWieldIndex() const;
226 void setWieldIndex(int i);
234 RemotePlayer* getPlayer() { return m_player; }
235 u16 getPeerID() const { return m_peer_id; }
239 v3f getLastGoodPosition() const
241 return m_last_good_position;
243 float resetTimeFromLastPunch()
245 float r = m_time_from_last_punch;
246 m_time_from_last_punch = 0.0;
249 void noCheatDigStart(v3s16 p)
251 m_nocheat_dig_pos = p;
252 m_nocheat_dig_time = 0;
254 v3s16 getNoCheatDigPos()
256 return m_nocheat_dig_pos;
258 float getNoCheatDigTime()
260 return m_nocheat_dig_time;
264 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
266 LagPool& getDigPool()
270 // Returns true if cheated
271 bool checkMovementCheat();
275 void updatePrivileges(const std::set<std::string> &privs,
276 bool is_singleplayer)
279 m_is_singleplayer = is_singleplayer;
282 bool getCollisionBox(aabb3f *toset);
283 bool collideWithObjects();
286 std::string getPropertyPacket();
288 RemotePlayer *m_player;
290 Inventory *m_inventory;
296 v3f m_last_good_position;
297 float m_time_from_last_punch;
298 v3s16 m_nocheat_dig_pos;
299 float m_nocheat_dig_time;
302 bool m_position_not_sent;
303 ItemGroupList m_armor_groups;
304 bool m_armor_groups_sent;
306 bool m_properties_sent;
307 struct ObjectProperties m_prop;
308 // Cached privileges for enforcement
309 std::set<std::string> m_privs;
310 bool m_is_singleplayer;
312 v2f m_animation_range;
313 float m_animation_speed;
314 float m_animation_blend;
315 bool m_animation_loop;
316 bool m_animation_sent;
318 // Stores position and rotation for each bone name
319 UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
320 bool m_bone_position_sent;
322 int m_attachment_parent_id;
323 std::set<int> m_attachment_child_ids;
324 std::string m_attachment_bone;
325 v3f m_attachment_position;
326 v3f m_attachment_rotation;
327 bool m_attachment_sent;
331 float m_physics_override_speed;
332 float m_physics_override_jump;
333 float m_physics_override_gravity;
334 bool m_physics_override_sneak;
335 bool m_physics_override_sneak_glitch;
336 bool m_physics_override_sent;