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();
216 void setNametagColor(video::SColor color);
217 video::SColor getNametagColor();
223 Inventory* getInventory();
224 const Inventory* getInventory() const;
225 InventoryLocation getInventoryLocation() const;
226 std::string getWieldList() const;
227 int getWieldIndex() const;
228 void setWieldIndex(int i);
240 u16 getPeerID() const
247 v3f getLastGoodPosition() const
249 return m_last_good_position;
251 float resetTimeFromLastPunch()
253 float r = m_time_from_last_punch;
254 m_time_from_last_punch = 0.0;
257 void noCheatDigStart(v3s16 p)
259 m_nocheat_dig_pos = p;
260 m_nocheat_dig_time = 0;
262 v3s16 getNoCheatDigPos()
264 return m_nocheat_dig_pos;
266 float getNoCheatDigTime()
268 return m_nocheat_dig_time;
272 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
274 LagPool& getDigPool()
278 // Returns true if cheated
279 bool checkMovementCheat();
283 void updatePrivileges(const std::set<std::string> &privs,
284 bool is_singleplayer)
287 m_is_singleplayer = is_singleplayer;
290 bool getCollisionBox(aabb3f *toset);
291 bool collideWithObjects();
294 std::string getPropertyPacket();
298 Inventory *m_inventory;
304 v3f m_last_good_position;
305 float m_time_from_last_punch;
306 v3s16 m_nocheat_dig_pos;
307 float m_nocheat_dig_time;
310 bool m_position_not_sent;
311 ItemGroupList m_armor_groups;
312 bool m_armor_groups_sent;
314 bool m_properties_sent;
315 struct ObjectProperties m_prop;
316 // Cached privileges for enforcement
317 std::set<std::string> m_privs;
318 bool m_is_singleplayer;
320 v2f m_animation_range;
321 float m_animation_speed;
322 float m_animation_blend;
323 bool m_animation_loop;
324 bool m_animation_sent;
326 std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
327 bool m_bone_position_sent;
329 int m_attachment_parent_id;
330 std::set<int> m_attachment_child_ids;
331 std::string m_attachment_bone;
332 v3f m_attachment_position;
333 v3f m_attachment_rotation;
334 bool m_attachment_sent;
336 video::SColor m_nametag_color;
340 float m_physics_override_speed;
341 float m_physics_override_jump;
342 float m_physics_override_gravity;
343 bool m_physics_override_sneak;
344 bool m_physics_override_sneak_glitch;
345 bool m_physics_override_sent;