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 std::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_, Player *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);
238 u16 getPeerID() const
245 v3f getLastGoodPosition() const
247 return m_last_good_position;
249 float resetTimeFromLastPunch()
251 float r = m_time_from_last_punch;
252 m_time_from_last_punch = 0.0;
255 void noCheatDigStart(v3s16 p)
257 m_nocheat_dig_pos = p;
258 m_nocheat_dig_time = 0;
260 v3s16 getNoCheatDigPos()
262 return m_nocheat_dig_pos;
264 float getNoCheatDigTime()
266 return m_nocheat_dig_time;
270 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
272 LagPool& getDigPool()
276 // Returns true if cheated
277 bool checkMovementCheat();
281 void updatePrivileges(const std::set<std::string> &privs,
282 bool is_singleplayer)
285 m_is_singleplayer = is_singleplayer;
288 bool getCollisionBox(aabb3f *toset);
289 bool collideWithObjects();
292 std::string getPropertyPacket();
296 Inventory *m_inventory;
302 v3f m_last_good_position;
303 float m_time_from_last_punch;
304 v3s16 m_nocheat_dig_pos;
305 float m_nocheat_dig_time;
308 bool m_position_not_sent;
309 ItemGroupList m_armor_groups;
310 bool m_armor_groups_sent;
312 bool m_properties_sent;
313 struct ObjectProperties m_prop;
314 // Cached privileges for enforcement
315 std::set<std::string> m_privs;
316 bool m_is_singleplayer;
318 v2f m_animation_range;
319 float m_animation_speed;
320 float m_animation_blend;
321 bool m_animation_loop;
322 bool m_animation_sent;
324 std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
325 bool m_bone_position_sent;
327 int m_attachment_parent_id;
328 std::set<int> m_attachment_child_ids;
329 std::string m_attachment_bone;
330 v3f m_attachment_position;
331 v3f m_attachment_rotation;
332 bool m_attachment_sent;
336 float m_physics_override_speed;
337 float m_physics_override_jump;
338 float m_physics_override_gravity;
339 bool m_physics_override_sneak;
340 bool m_physics_override_sneak_glitch;
341 bool m_physics_override_sent;