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 void setInventoryModified();
209 std::string getWieldList() const;
210 int getWieldIndex() const;
211 void setWieldIndex(int i);
223 u16 getPeerID() const
230 v3f getLastGoodPosition() const
232 return m_last_good_position;
234 float resetTimeFromLastPunch()
236 float r = m_time_from_last_punch;
237 m_time_from_last_punch = 0.0;
240 void noCheatDigStart(v3s16 p)
242 m_nocheat_dig_pos = p;
243 m_nocheat_dig_time = 0;
245 v3s16 getNoCheatDigPos()
247 return m_nocheat_dig_pos;
249 float getNoCheatDigTime()
251 return m_nocheat_dig_time;
255 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
257 LagPool& getDigPool()
261 // Returns true if cheated
262 bool checkMovementCheat();
266 void updatePrivileges(const std::set<std::string> &privs,
267 bool is_singleplayer)
270 m_is_singleplayer = is_singleplayer;
273 bool getCollisionBox(aabb3f *toset);
274 bool collideWithObjects();
277 std::string getPropertyPacket();
281 Inventory *m_inventory;
287 v3f m_last_good_position;
288 float m_time_from_last_punch;
289 v3s16 m_nocheat_dig_pos;
290 float m_nocheat_dig_time;
293 bool m_position_not_sent;
294 ItemGroupList m_armor_groups;
295 bool m_armor_groups_sent;
297 bool m_properties_sent;
298 struct ObjectProperties m_prop;
299 // Cached privileges for enforcement
300 std::set<std::string> m_privs;
301 bool m_is_singleplayer;
303 v2f m_animation_range;
304 float m_animation_speed;
305 float m_animation_blend;
306 bool m_animation_sent;
308 std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
309 bool m_bone_position_sent;
311 int m_attachment_parent_id;
312 std::string m_attachment_bone;
313 v3f m_attachment_position;
314 v3f m_attachment_rotation;
315 bool m_attachment_sent;
318 // Some flags used by Server
320 bool m_inventory_not_sent;
322 bool m_breath_not_sent;
323 bool m_wielded_item_not_sent;
325 float m_physics_override_speed;
326 float m_physics_override_jump;
327 float m_physics_override_gravity;
328 bool m_physics_override_sneak;
329 bool m_physics_override_sneak_glitch;
330 bool m_physics_override_sent;