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 "content_object.h"
25 #include "itemgroup.h"
27 #include "object_properties.h"
29 ServerActiveObject* createItemSAO(ServerEnvironment *env, v3f pos,
30 const std::string itemstring);
33 LuaEntitySAO needs some internals exposed.
36 class LuaEntitySAO : public ServerActiveObject
39 LuaEntitySAO(ServerEnvironment *env, v3f pos,
40 const std::string &name, const std::string &state);
43 { return ACTIVEOBJECT_TYPE_LUAENTITY; }
44 u8 getSendType() const
45 { return ACTIVEOBJECT_TYPE_GENERIC; }
46 virtual void addedToEnvironment(u32 dtime_s);
47 static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
48 const std::string &data);
50 void step(float dtime, bool send_recommended);
51 std::string getClientInitializationData(u16 protocol_version);
52 std::string getStaticData();
54 const ToolCapabilities *toolcap=NULL,
55 ServerActiveObject *puncher=NULL,
56 float time_from_last_punch=1000000);
57 void rightClick(ServerActiveObject *clicker);
59 void moveTo(v3f pos, bool continuous);
60 float getMinimumSavedMovement();
61 std::string getDescription();
64 void setArmorGroups(const ItemGroupList &armor_groups);
65 void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
66 void setBonePosition(std::string bone, v3f position, v3f rotation);
67 void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
68 ObjectProperties* accessObjectProperties();
69 void notifyObjectPropertiesModified();
70 /* LuaEntitySAO-specific */
71 void setVelocity(v3f velocity);
73 void setAcceleration(v3f acceleration);
74 v3f getAcceleration();
75 void setYaw(float yaw);
77 void setTextureMod(const std::string &mod);
78 void setSprite(v2s16 p, int num_frames, float framelength,
79 bool select_horiz_by_yawpitch);
80 std::string getName();
81 bool getCollisionBox(aabb3f *toset);
82 bool collideWithObjects();
84 std::string getPropertyPacket();
85 void sendPosition(bool do_interpolate, bool is_movement_end);
87 std::string m_init_name;
88 std::string m_init_state;
90 struct ObjectProperties m_prop;
96 ItemGroupList m_armor_groups;
98 bool m_properties_sent;
99 float m_last_sent_yaw;
100 v3f m_last_sent_position;
101 v3f m_last_sent_velocity;
102 float m_last_sent_position_timer;
103 float m_last_sent_move_precision;
104 bool m_armor_groups_sent;
106 v2f m_animation_range;
107 float m_animation_speed;
108 float m_animation_blend;
109 bool m_animation_sent;
111 std::map<std::string, core::vector2d<v3f> > m_bone_position;
112 bool m_bone_position_sent;
114 int m_attachment_parent_id;
115 std::string m_attachment_bone;
116 v3f m_attachment_position;
117 v3f m_attachment_rotation;
118 bool m_attachment_sent;
122 PlayerSAO needs some internals exposed.
130 LagPool(): pool(15), max(15)
132 void setMax(float new_max)
138 void add(float dtime)
144 bool grab(float dtime)
148 if(pool + dtime > max)
155 class PlayerSAO : public ServerActiveObject
158 PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
159 const std::set<std::string> &privs, bool is_singleplayer);
162 { return ACTIVEOBJECT_TYPE_PLAYER; }
163 u8 getSendType() const
164 { return ACTIVEOBJECT_TYPE_GENERIC; }
165 std::string getDescription();
168 Active object <-> environment interface
171 void addedToEnvironment(u32 dtime_s);
172 void removingFromEnvironment();
173 bool isStaticAllowed() const;
174 bool unlimitedTransferDistance() const;
175 std::string getClientInitializationData(u16 protocol_version);
176 std::string getStaticData();
178 void step(float dtime, bool send_recommended);
179 void setBasePosition(const v3f &position);
180 void setPos(v3f pos);
181 void moveTo(v3f pos, bool continuous);
183 void setPitch(float);
186 Interaction interface
190 const ToolCapabilities *toolcap,
191 ServerActiveObject *puncher,
192 float time_from_last_punch);
193 void rightClick(ServerActiveObject *clicker);
196 u16 getBreath() const;
197 void setBreath(u16 breath);
198 void setArmorGroups(const ItemGroupList &armor_groups);
199 void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
200 void setBonePosition(std::string bone, v3f position, v3f rotation);
201 void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
202 ObjectProperties* accessObjectProperties();
203 void notifyObjectPropertiesModified();
209 Inventory* getInventory();
210 const Inventory* getInventory() const;
211 InventoryLocation getInventoryLocation() const;
212 void setInventoryModified();
213 std::string getWieldList() const;
214 int getWieldIndex() const;
215 void setWieldIndex(int i);
227 u16 getPeerID() const
234 v3f getLastGoodPosition() const
236 return m_last_good_position;
238 float resetTimeFromLastPunch()
240 float r = m_time_from_last_punch;
241 m_time_from_last_punch = 0.0;
244 void noCheatDigStart(v3s16 p)
246 m_nocheat_dig_pos = p;
247 m_nocheat_dig_time = 0;
249 v3s16 getNoCheatDigPos()
251 return m_nocheat_dig_pos;
253 float getNoCheatDigTime()
255 return m_nocheat_dig_time;
259 m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
261 LagPool& getDigPool()
265 void checkMovementCheat();
269 void updatePrivileges(const std::set<std::string> &privs,
270 bool is_singleplayer)
273 m_is_singleplayer = is_singleplayer;
276 bool getCollisionBox(aabb3f *toset);
277 bool collideWithObjects();
280 std::string getPropertyPacket();
284 Inventory *m_inventory;
289 v3f m_last_good_position;
290 float m_time_from_last_punch;
291 v3s16 m_nocheat_dig_pos;
292 float m_nocheat_dig_time;
295 bool m_position_not_sent;
296 ItemGroupList m_armor_groups;
297 bool m_armor_groups_sent;
299 bool m_properties_sent;
300 struct ObjectProperties m_prop;
301 // Cached privileges for enforcement
302 std::set<std::string> m_privs;
303 bool m_is_singleplayer;
305 v2f m_animation_range;
306 float m_animation_speed;
307 float m_animation_blend;
308 bool m_animation_sent;
310 std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
311 bool m_bone_position_sent;
313 int m_attachment_parent_id;
314 std::string m_attachment_bone;
315 v3f m_attachment_position;
316 v3f m_attachment_rotation;
317 bool m_attachment_sent;
320 // Some flags used by Server
322 bool m_inventory_not_sent;
324 bool m_breath_not_sent;
325 bool m_wielded_item_not_sent;
327 float m_physics_override_speed;
328 float m_physics_override_jump;
329 float m_physics_override_gravity;
330 bool m_physics_override_sent;