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 void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
62 void setBonePosition(std::string bone, v3f position, v3f rotation);
63 void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
64 ObjectProperties* accessObjectProperties();
65 void notifyObjectPropertiesModified();
66 /* LuaEntitySAO-specific */
67 void setVelocity(v3f velocity);
69 void setAcceleration(v3f acceleration);
70 v3f getAcceleration();
71 void setYaw(float yaw);
73 void setTextureMod(const std::string &mod);
74 void setSprite(v2s16 p, int num_frames, float framelength,
75 bool select_horiz_by_yawpitch);
76 std::string getName();
77 bool getCollisionBox(aabb3f *toset);
78 bool collideWithObjects();
80 std::string getPropertyPacket();
81 void sendPosition(bool do_interpolate, bool is_movement_end);
83 std::string m_init_name;
84 std::string m_init_state;
86 struct ObjectProperties m_prop;
92 ItemGroupList m_armor_groups;
94 bool m_properties_sent;
95 float m_last_sent_yaw;
96 v3f m_last_sent_position;
97 v3f m_last_sent_velocity;
98 float m_last_sent_position_timer;
99 float m_last_sent_move_precision;
100 bool m_armor_groups_sent;
102 v2f m_animation_range;
103 float m_animation_speed;
104 float m_animation_blend;
105 bool m_animation_sent;
107 std::map<std::string, core::vector2d<v3f> > m_bone_position;
108 bool m_bone_position_sent;
110 int m_attachment_parent_id;
111 std::string m_attachment_bone;
112 v3f m_attachment_position;
113 v3f m_attachment_rotation;
114 bool m_attachment_sent;
118 PlayerSAO needs some internals exposed.
126 LagPool(): m_pool(15), m_max(15)
128 void setMax(float new_max)
134 void add(float dtime)
140 bool grab(float dtime)
144 if(m_pool + dtime > m_max)
151 class PlayerSAO : public ServerActiveObject
154 PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
155 const std::set<std::string> &privs, bool is_singleplayer);
157 ActiveObjectType getType() const
158 { return ACTIVEOBJECT_TYPE_PLAYER; }
159 ActiveObjectType getSendType() const
160 { return ACTIVEOBJECT_TYPE_GENERIC; }
161 std::string getDescription();
164 Active object <-> environment interface
167 void addedToEnvironment(u32 dtime_s);
168 void removingFromEnvironment();
169 bool isStaticAllowed() const;
170 std::string getClientInitializationData(u16 protocol_version);
171 std::string getStaticData();
173 void step(float dtime, bool send_recommended);
174 void setBasePosition(const v3f &position);
175 void setPos(v3f pos);
176 void moveTo(v3f pos, bool continuous);
178 void setPitch(float);
181 Interaction interface
185 const ToolCapabilities *toolcap,
186 ServerActiveObject *puncher,
187 float time_from_last_punch);
188 void rightClick(ServerActiveObject *clicker);
192 u16 getBreath() const;
193 void setBreath(u16 breath);
194 void setArmorGroups(const ItemGroupList &armor_groups);
195 void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
196 void setBonePosition(std::string bone, v3f position, v3f rotation);
197 void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
198 ObjectProperties* accessObjectProperties();
199 void notifyObjectPropertiesModified();
205 Inventory* getInventory();
206 const Inventory* getInventory() const;
207 InventoryLocation getInventoryLocation() const;
208 std::string getWieldList() const;
209 int getWieldIndex() const;
210 void setWieldIndex(int i);
222 u16 getPeerID() const
229 v3f getLastGoodPosition() const
231 return m_last_good_position;
233 float resetTimeFromLastPunch()
235 float r = m_time_from_last_punch;
236 m_time_from_last_punch = 0.0;
239 void noCheatDigStart(v3s16 p)
241 m_nocheat_dig_pos = p;
242 m_nocheat_dig_time = 0;
244 v3s16 getNoCheatDigPos()
246 return m_nocheat_dig_pos;
248 float getNoCheatDigTime()
250 return m_nocheat_dig_time;
254 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
256 LagPool& getDigPool()
260 // Returns true if cheated
261 bool checkMovementCheat();
265 void updatePrivileges(const std::set<std::string> &privs,
266 bool is_singleplayer)
269 m_is_singleplayer = is_singleplayer;
272 bool getCollisionBox(aabb3f *toset);
273 bool collideWithObjects();
276 std::string getPropertyPacket();
280 Inventory *m_inventory;
286 v3f m_last_good_position;
287 float m_time_from_last_punch;
288 v3s16 m_nocheat_dig_pos;
289 float m_nocheat_dig_time;
292 bool m_position_not_sent;
293 ItemGroupList m_armor_groups;
294 bool m_armor_groups_sent;
296 bool m_properties_sent;
297 struct ObjectProperties m_prop;
298 // Cached privileges for enforcement
299 std::set<std::string> m_privs;
300 bool m_is_singleplayer;
302 v2f m_animation_range;
303 float m_animation_speed;
304 float m_animation_blend;
305 bool m_animation_sent;
307 std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
308 bool m_bone_position_sent;
310 int m_attachment_parent_id;
311 std::string m_attachment_bone;
312 v3f m_attachment_position;
313 v3f m_attachment_rotation;
314 bool m_attachment_sent;
317 float m_physics_override_speed;
318 float m_physics_override_jump;
319 float m_physics_override_gravity;
320 bool m_physics_override_sneak;
321 bool m_physics_override_sneak_glitch;
322 bool m_physics_override_sent;